diff options
author | Marvin Borner | 2020-04-16 19:06:33 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-16 19:06:33 +0200 |
commit | 4014a36377ff69f6433e7b0af2144bc3a7d29ca7 (patch) | |
tree | 9440ac3749d406c6df9917d4bb3a19de6ea99655 | |
parent | fc26e84ef8c6255926811fe639e3e466b756e581 (diff) |
Many fix attempts for the divide by zero exception
-rwxr-xr-x | run | 7 | ||||
-rw-r--r-- | src/kernel/acpi/acpi.c | 4 | ||||
-rw-r--r-- | src/kernel/fs/ata.c | 16 | ||||
-rw-r--r-- | src/kernel/fs/ata.h | 6 | ||||
-rw-r--r-- | src/kernel/fs/elf.c | 8 | ||||
-rw-r--r-- | src/kernel/fs/ext2.c (renamed from src/kernel/fs/ext2/ext2.c) | 29 | ||||
-rw-r--r-- | src/kernel/fs/ext2.h (renamed from src/kernel/fs/ext2/ext2.h) | 4 | ||||
-rw-r--r-- | src/kernel/fs/vfs.c (renamed from src/kernel/fs/vfs/vfs.c) | 11 | ||||
-rw-r--r-- | src/kernel/fs/vfs.h (renamed from src/kernel/fs/vfs/vfs.h) | 0 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 8 | ||||
-rw-r--r-- | src/kernel/kernel.c | 4 | ||||
-rw-r--r-- | src/kernel/net/rtl8139.c | 2 | ||||
-rw-r--r-- | src/kernel/pci/pci.c | 5 |
13 files changed, 51 insertions, 53 deletions
@@ -136,7 +136,6 @@ p 1 2048 199999 -a w EOF @@ -144,6 +143,12 @@ EOF cp ./build/ext2_hda.img ./build/ext2_hdc.img cp ./build/ext2_hda.img ./build/ext2_hdd.img + mkdir mnt/ + sudo mount ./build/ext2_hda.img mnt/ + echo "Bananenkuchen" | sudo tee -a mnt/test.txt + sudo umount mnt + rm -r mnt/ + printf "Build finshed successfully!\n\n" } diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c index 8eee5f1..8733987 100644 --- a/src/kernel/acpi/acpi.c +++ b/src/kernel/acpi/acpi.c @@ -184,7 +184,7 @@ void acpi_poweroff() { cli(); if (SCI_EN == 0) { - warn("ACPI shutdown is not supported\n"); + warn("ACPI shutdown is not supported"); return; } @@ -207,4 +207,4 @@ void reboot() good = inb(0x64); outb(0x64, 0xFE); halt_loop(); -}
\ No newline at end of file +} diff --git a/src/kernel/fs/ata.c b/src/kernel/fs/ata.c index 817bb98..ac42275 100644 --- a/src/kernel/fs/ata.c +++ b/src/kernel/fs/ata.c @@ -8,7 +8,7 @@ #include <kernel/pci/pci.h> #include <kernel/interrupts/interrupts.h> -uint32_t ata_device; +uint32_t ata_device = 0x00000000; ata_dev_t primary_master = { .slave = 0 }; ata_dev_t primary_slave = { .slave = 1 }; @@ -30,7 +30,7 @@ void software_reset(ata_dev_t *dev) outb(dev->control, CONTROL_ZERO); } -void ata_handler(struct regs *reg) +void ata_handler(struct regs *r) { inb(primary_master.status); inb(primary_master.BMR_STATUS); @@ -240,14 +240,14 @@ void ata_device_detect(ata_dev_t *dev, int primary) outb(dev->command, COMMAND_IDENTIFY); if (!inb(dev->status)) { - log("Device does not exist"); + warn("Device does not exist: %s", dev->mountpoint); return; } uint8_t lba_lo = inb(dev->lba_lo); uint8_t lba_hi = inb(dev->lba_high); if (lba_lo != 0 || lba_hi != 0) { - log("Device is not ata-compatible"); + warn("Device is not ata-compatible: %s", dev->mountpoint); return; } uint8_t drq = 0, err = 0; @@ -256,7 +256,7 @@ void ata_device_detect(ata_dev_t *dev, int primary) err = inb(dev->status) & STATUS_ERR; } if (err) { - log("Error while polling"); + warn("Error while polling: %s", dev->mountpoint); return; } @@ -283,10 +283,10 @@ void ata_init() { pci_scan(&ata_find, -1, &ata_device); - irq_install_handler(32 + 14, ata_handler); + irq_install_handler(14, ata_handler); ata_device_detect(&primary_master, 1); ata_device_detect(&primary_slave, 1); - ata_device_detect(&secondary_master, 0); - ata_device_detect(&secondary_slave, 0); + /* ata_device_detect(&secondary_master, 0); */ + /* ata_device_detect(&secondary_slave, 0); */ } diff --git a/src/kernel/fs/ata.h b/src/kernel/fs/ata.h index 72ded20..4a2951f 100644 --- a/src/kernel/fs/ata.h +++ b/src/kernel/fs/ata.h @@ -1,7 +1,7 @@ #ifndef ATA_DRIVER_H #define ATA_DRIVER_H -#include <kernel/fs/vfs/vfs.h> +#include <kernel/fs/vfs.h> #include <kernel/memory/paging.h> #include <kernel/interrupts/interrupts.h> @@ -56,7 +56,7 @@ typedef struct ata_dev { char mountpoint[32]; } __attribute__((packed)) ata_dev_t; -// ATA PCI info +// ATA PCI info of QEMU // TODO: Remove Qemu based device id #define ATA_VENDOR_ID 0x8086 #define ATA_DEVICE_ID 0x7010 @@ -116,4 +116,4 @@ void ata_device_detect(ata_dev_t *dev, int primary); void ata_init(); -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index b6d90c9..493bdac 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -40,16 +40,16 @@ uint32_t load_elf(char *elf_data) v_begin = p_entry->vaddr; v_end = p_entry->vaddr + p_entry->memsz; if (v_begin < USER_OFFSET) { - warn("load_elf(): can't load executable below %x\n", USER_OFFSET); + warn("load_elf(): can't load executable below %x", USER_OFFSET); return 0; } if (v_end > USER_STACK) { - warn("load_elf(): can't load executable above %x\n", USER_STACK); + warn("load_elf(): can't load executable above %x", USER_STACK); return 0; } - printf("ELF: entry flags: %x (%d)\n", p_entry->flags, p_entry->flags); + log("ELF: entry flags: %x (%d)", p_entry->flags, p_entry->flags); memcpy((uint8_t *)v_begin, (uint8_t *)(elf_data + p_entry->offset), p_entry->filesz); @@ -63,4 +63,4 @@ uint32_t load_elf(char *elf_data) } return hdr->entry; -}
\ No newline at end of file +} diff --git a/src/kernel/fs/ext2/ext2.c b/src/kernel/fs/ext2.c index b14d726..bc17db6 100644 --- a/src/kernel/fs/ext2/ext2.c +++ b/src/kernel/fs/ext2.c @@ -5,7 +5,7 @@ #include <kernel/lib/stdio.h> #include <kernel/lib/lib.h> #include <kernel/memory/alloc.h> -#include <kernel/fs/ext2/ext2.h> +#include <kernel/fs/ext2.h> uint32_t ext2_file_size(vfs_node_t *node) { @@ -259,7 +259,7 @@ void ext2_create_entry(vfs_node_t *parent, char *entry_name, uint32_t entry_inod if (curr_dir->name_len == entry_name_len) { memcpy(check, curr_dir->name, entry_name_len); if (curr_dir->inode != 0 && !strcmp(entry_name, check)) { - log("Entry by the same name %s already exist\n", check); + log("Entry by the same name %s already exist", check); return; } } @@ -570,8 +570,7 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx } b = a - p; if (b <= 0) { - alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS]), ext2fs, inode, - inode_idx, NULL, 0); + if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS]), ext2fs, inode, inode_idx, NULL, 0)); read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS], (void *)tmp); ((unsigned int *)tmp)[a] = disk_block; write_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS], (void *)tmp); @@ -582,11 +581,9 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx if (c <= 0) { c = b / p; d = b - c * p; - alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 1]), ext2fs, inode, - inode_idx, NULL, 0); + if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 1]), ext2fs, inode, inode_idx, NULL, 0)); read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS + 1], (void *)tmp); - alloc_inode_metadata_block(&(tmp[c]), ext2fs, inode, inode_idx, (void *)tmp, - inode->blocks[EXT2_DIRECT_BLOCKS + 1]); + if(!alloc_inode_metadata_block(&(tmp[c]), ext2fs, inode, inode_idx, (void*)tmp, inode->blocks[EXT2_DIRECT_BLOCKS + 1])); unsigned int temp = tmp[c]; read_disk_block(ext2fs, temp, (void *)tmp); tmp[d] = disk_block; @@ -598,14 +595,12 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx e = c / (p * p); f = (c - e * p * p) / p; g = (c - e * p * p - f * p); - alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 2]), ext2fs, inode, - inode_idx, NULL, 0); + if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 2]), ext2fs, inode, inode_idx, NULL, 0)); read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS + 2], (void *)tmp); - alloc_inode_metadata_block(&(tmp[e]), ext2fs, inode, inode_idx, (void *)tmp, - inode->blocks[EXT2_DIRECT_BLOCKS + 2]); + if(!alloc_inode_metadata_block(&(tmp[e]), ext2fs, inode, inode_idx, (void*)tmp, inode->blocks[EXT2_DIRECT_BLOCKS + 2])); unsigned int temp = tmp[e]; read_disk_block(ext2fs, tmp[e], (void *)tmp); - alloc_inode_metadata_block(&(tmp[f]), ext2fs, inode, inode_idx, (void *)tmp, temp); + if(!alloc_inode_metadata_block(&(tmp[f]), ext2fs, inode, inode_idx, (void*)tmp, temp)); temp = tmp[f]; read_disk_block(ext2fs, tmp[f], (void *)tmp); tmp[g] = disk_block; @@ -642,7 +637,7 @@ uint32_t ext2_alloc_block(ext2_fs_t *ext2fs) } } } - panic("We're out of blocks!\n"); + panic("We're out of blocks!"); return (uint32_t)-1; } @@ -707,7 +702,7 @@ uint32_t alloc_inode(ext2_fs_t *ext2fs) } } } - panic("We're out of inodes!\n"); + panic("We're out of inodes!"); return (uint32_t)-1; } @@ -762,10 +757,12 @@ void ext2_init(char *device_path, char *mountpoint) { ext2_fs_t *ext2fs = kcalloc(sizeof(ext2_fs_t), 1); ext2fs->disk_device = file_open(device_path, 0); + log("%s", ext2fs->disk_device->name); ext2fs->sb = kmalloc(SUPERBLOCK_SIZE); ext2fs->block_size = 1024; - read_disk_block(ext2fs, 1, (void *)ext2fs->sb); + read_disk_block(ext2fs, 1, (void *)ext2fs->sb); //! log("%x", ext2fs->sb->ext2_magic); + log("%x", ext2fs->sb->total_inodes); ext2fs->block_size = (1024 << ext2fs->sb->log2block_size); ext2fs->blocks_per_group = ext2fs->sb->blocks_per_group; ext2fs->inodes_per_group = ext2fs->sb->inodes_per_group; diff --git a/src/kernel/fs/ext2/ext2.h b/src/kernel/fs/ext2.h index 3996ba5..62105c7 100644 --- a/src/kernel/fs/ext2/ext2.h +++ b/src/kernel/fs/ext2.h @@ -2,7 +2,7 @@ #define MELVIX_EXT2_H #include <stdint.h> -#include <kernel/fs/vfs/vfs.h> +#include <kernel/fs/vfs.h> #define EXT2_DIRECT_BLOCKS 12 @@ -208,4 +208,4 @@ vfs_node_t *get_ext2_root(ext2_fs_t *ext2fs, inode_t *inode); void ext2_init(char *device_path, char *mountpoint); -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/fs/vfs/vfs.c b/src/kernel/fs/vfs.c index 10d3c21..9dc684c 100644 --- a/src/kernel/fs/vfs/vfs.c +++ b/src/kernel/fs/vfs.c @@ -1,6 +1,6 @@ #include <kernel/system.h> -#include <kernel/fs/ext2/ext2.h> -#include <kernel/fs/vfs/vfs.h> +#include <kernel/fs/ext2.h> +#include <kernel/fs/vfs.h> #include <kernel/lib/data/list.h> #include <kernel/lib/data/generic_tree.h> #include <kernel/memory/alloc.h> @@ -53,7 +53,7 @@ void print_vfstree_recur(gtreenode_t *node, int parent_offset) } else { log("%s(empty)", fnode->name); } - log("%s\n", tmp); + log("%s", tmp); len = strlen(fnode->name); kfree(tmp); foreach(child, node->children) @@ -259,6 +259,7 @@ vfs_node_t *get_mountpoint_recur(char **path, gtreenode_t *subroot) } return get_mountpoint_recur(path, subroot); } + vfs_node_t *get_mountpoint(char **path) { if (strlen(*path) > 1 && (*path)[strlen(*path) - 1] == '/') @@ -324,7 +325,7 @@ void vfs_mount_recur(char *path, gtreenode_t *subroot, vfs_node_t *fs_obj) if (curr_token == NULL || !strcmp(curr_token, "")) { struct vfs_entry *ent = (struct vfs_entry *)subroot->value; if (ent->file) { - log("The path is already mounted, plz unmount before mounting again\n"); + warn("The path is already mounted, please unmount before mounting again"); return; } if (!strcmp(ent->name, "/")) @@ -358,7 +359,7 @@ void vfs_mount(char *path, vfs_node_t *fs_obj) if (path[0] == '/' && strlen(path) == 1) { struct vfs_entry *ent = (struct vfs_entry *)vfs_tree->root->value; if (ent->file) { - log("The path is already mounted, plz unmount before mounting again\n"); + warn("The path is already mounted, please unmount before mounting again"); return; } vfs_root = fs_obj; diff --git a/src/kernel/fs/vfs/vfs.h b/src/kernel/fs/vfs.h index b31767e..b31767e 100644 --- a/src/kernel/fs/vfs/vfs.h +++ b/src/kernel/fs/vfs.h diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index 490c8ea..ca190ad 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -119,13 +119,9 @@ void set_optimal_resolution() continue; } - log("Found mode: (0x%x) %dx%dx%d", *mode, mode_info->width, mode_info->height, - mode_info->bpp); - if (mode_info->width > vbe_width || (mode_info->width == vbe_width && (mode_info->bpp >> 3) > vbe_bpl)) { // if (mode_info->bpp == 32) { // Force specific bpp for debugging - // (float) mode_info->width / (float) mode_info->height < 2.0 &&) { highest = *mode; vbe_width = mode_info->width; vbe_height = mode_info->height; @@ -139,7 +135,6 @@ void set_optimal_resolution() kfree(video_modes); if (highest == 0) { - log("Mode detection failed!\nTrying common modes..."); vga_log("Mode detection failed!"); vga_log("Trying common modes..."); struct vbe_mode_info *mode_info; @@ -211,7 +206,6 @@ void set_optimal_resolution() info("Successfully switched to video mode!"); log("Using mode: (0x%x) %dx%dx%d", highest, vbe_width, vbe_height, vbe_bpl << 3); - debug("Using mode: %dx%dx%d", vbe_width, vbe_height, vbe_bpl << 3); } const uint32_t default_text_color = vesa_white; @@ -375,4 +369,4 @@ void vesa_set_color(uint32_t color) { vesa_convert_color(terminal_color, color); vesa_convert_color(terminal_background, default_background_color); -}
\ No newline at end of file +} diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 08980cf..3339381 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -16,8 +16,8 @@ #include <kernel/fs/elf.h> #include <kernel/lib/stdio.h> #include <kernel/fs/ata.h> -#include <kernel/fs/ext2/ext2.h> -#include <kernel/fs/vfs/vfs.h> +#include <kernel/fs/ext2.h> +#include <kernel/fs/vfs.h> void kernel_main(uint32_t magic, multiboot_info_t *grub_header) { diff --git a/src/kernel/net/rtl8139.c b/src/kernel/net/rtl8139.c index a934e52..2a6a3e8 100644 --- a/src/kernel/net/rtl8139.c +++ b/src/kernel/net/rtl8139.c @@ -100,4 +100,4 @@ void rtl8139_install() if (rtl8139_init() == 0) info("Installed rtl8139 network driver"); -}
\ No newline at end of file +} diff --git a/src/kernel/pci/pci.c b/src/kernel/pci/pci.c index 7ba48ab..57bfe94 100644 --- a/src/kernel/pci/pci.c +++ b/src/kernel/pci/pci.c @@ -1,5 +1,6 @@ -#include <kernel/pci/pci.h> #include <stdint.h> +#include <kernel/system.h> +#include <kernel/pci/pci.h> #include <kernel/io/io.h> #include <kernel/lib/lib.h> @@ -136,4 +137,4 @@ int pci_get_interrupt(uint32_t device) } else { return (int)pci_read_field(device, PCI_INTERRUPT_LINE, 1); } -}
\ No newline at end of file +} |