diff options
author | Marvin Borner | 2020-01-20 23:12:54 +0100 |
---|---|---|
committer | Marvin Borner | 2020-01-20 23:12:54 +0100 |
commit | 391ed256d21a6ae2e2456d1809f357e6e96e15d1 (patch) | |
tree | 0fe9ffb3c59bbfeb3d8a04ab7fc6efba60d81e79 /src/kernel/fs | |
parent | d5d1749257ff8b9aa6b5ace4b4720b484a2860f3 (diff) |
Added pure awesomeness
Actually quite some days of work but ok
Diffstat (limited to 'src/kernel/fs')
-rw-r--r-- | src/kernel/fs/ata_pio.c | 46 | ||||
-rw-r--r-- | src/kernel/fs/atapi_pio.c | 1 | ||||
-rw-r--r-- | src/kernel/fs/install.c | 18 | ||||
-rw-r--r-- | src/kernel/fs/iso9660/iso9660.c | 2 | ||||
-rw-r--r-- | src/kernel/fs/marfs/directory.c | 11 | ||||
-rw-r--r-- | src/kernel/fs/marfs/new_file.c | 8 | ||||
-rw-r--r-- | src/kernel/fs/marfs/read_whole_file.c | 8 | ||||
-rw-r--r-- | src/kernel/fs/marfs/sectorlevel.c | 4 |
8 files changed, 50 insertions, 48 deletions
diff --git a/src/kernel/fs/ata_pio.c b/src/kernel/fs/ata_pio.c index 0134ee4..fef3a32 100644 --- a/src/kernel/fs/ata_pio.c +++ b/src/kernel/fs/ata_pio.c @@ -1,35 +1,35 @@ #include <kernel/io/io.h> -#include <kernel/lib/stdlib.h> #include <kernel/fs/ata_pio.h> +#include <kernel/memory/kheap.h> struct ata_interface *new_ata(uint8_t master, uint16_t port_base) { - struct ata_interface *ret = kmalloc(sizeof(struct ata_interface)); + struct ata_interface *ret = (struct ata_interface *) kmalloc(sizeof(struct ata_interface)); ret->master = master; ret->data_port = port_base; - ret->error_port = port_base + 0x1; - ret->sector_count_port = port_base + 0x2; - ret->lba_low_port = port_base + 0x3; - ret->lba_mid_port = port_base + 0x4; - ret->lba_high_port = port_base + 0x5; - ret->device_port = port_base + 0x6; - ret->command_port = port_base + 0x7; - ret->control_port = port_base + 0x206; + ret->error_port = (uint16_t) (port_base + 0x1); + ret->sector_count_port = (uint16_t) (port_base + 0x2); + ret->lba_low_port = (uint16_t) (port_base + 0x3); + ret->lba_mid_port = (uint16_t) (port_base + 0x4); + ret->lba_high_port = (uint16_t) (port_base + 0x5); + ret->device_port = (uint16_t) (port_base + 0x6); + ret->command_port = (uint16_t) (port_base + 0x7); + ret->control_port = (uint16_t) (port_base + 0x206); return ret; } uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data) { - outb(interface->device_port, interface->master ? 0xA0 : 0xB0); + outb(interface->device_port, (uint8_t) (interface->master ? 0xA0 : 0xB0)); outb(interface->control_port, 0); outb(interface->device_port, 0xA0); uint8_t status = inb(interface->command_port); if (status == 0xFF) return 1; - outb(interface->device_port, interface->master ? 0xA0 : 0xB0); + outb(interface->device_port, (uint8_t) (interface->master ? 0xA0 : 0xB0)); outb(interface->sector_count_port, 0); outb(interface->lba_low_port, 0); outb(interface->lba_mid_port, 0); @@ -53,7 +53,7 @@ uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector) { if (sector > 0x0FFFFFFF) return 0; - outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); + outb(interface->device_port, (uint8_t) ((interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24))); uint8_t status = 0; for (int i = 0; i < 5; i++) status = inb(interface->command_port); @@ -61,19 +61,19 @@ uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector) outb(interface->error_port, 0); outb(interface->sector_count_port, 1); - outb(interface->lba_low_port, sector & 0x000000FF); - outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8); - outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16); + outb(interface->lba_low_port, (uint8_t) (sector & 0x000000FF)); + outb(interface->lba_mid_port, (uint8_t) ((sector & 0x0000FF00) >> 8)); + outb(interface->lba_high_port, (uint8_t) ((sector & 0x00FF0000) >> 16)); outb(interface->command_port, 0x20); // Read command status = inb(interface->command_port); while ((status & 0x80) && !(status & 0x01)) status = inb(interface->command_port); - uint8_t *ret = kmalloc(BYTES_PER_SECTOR); + uint8_t *ret = (uint8_t *) kmalloc(BYTES_PER_SECTOR); for (int i = 0; i < BYTES_PER_SECTOR; i += 2) { uint16_t data = inw(interface->data_port); - ret[i] = data & 0xFF; - ret[i + 1] = (data >> 8) & 0xFF; + ret[i] = (uint8_t) (data & 0xFF); + ret[i + 1] = (uint8_t) ((data >> 8) & 0xFF); } return ret; } @@ -83,7 +83,7 @@ uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint if (sector > 0x0FFFFFFF) return 1; asm ("cli"); - outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); + outb(interface->device_port, (uint8_t) ((interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24))); uint8_t status = 0; for (int i = 0; i < 5; i++) status = inb(interface->command_port); @@ -91,9 +91,9 @@ uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint outb(interface->error_port, 0); outb(interface->sector_count_port, 1); - outb(interface->lba_low_port, sector & 0x000000FF); - outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8); - outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16); + outb(interface->lba_low_port, (uint8_t) (sector & 0x000000FF)); + outb(interface->lba_mid_port, (uint8_t) ((sector & 0x0000FF00) >> 8)); + outb(interface->lba_high_port, (uint8_t) ((sector & 0x00FF0000) >> 16)); outb(interface->command_port, 0x30); // Write command while ((status & 0x80) || !(status & 0x08)) status = inb(interface->command_port); diff --git a/src/kernel/fs/atapi_pio.c b/src/kernel/fs/atapi_pio.c index c2cdd8c..39f32b6 100644 --- a/src/kernel/fs/atapi_pio.c +++ b/src/kernel/fs/atapi_pio.c @@ -1,7 +1,6 @@ #include <stdint.h> #include <kernel/fs/atapi_pio.h> #include <kernel/system.h> -#include <kernel/paging/paging.h> void ATAPI_read(uint16_t nblocks, uint32_t lba) { diff --git a/src/kernel/fs/install.c b/src/kernel/fs/install.c index af148c8..daeb91b 100644 --- a/src/kernel/fs/install.c +++ b/src/kernel/fs/install.c @@ -3,10 +3,11 @@ #include <kernel/fs/marfs/marfs.h> #include <kernel/fs/iso9660/iso9660.h> #include <kernel/fs/atapi_pio.h> -#include <kernel/lib/stdlib.h> #include <kernel/acpi/acpi.h> #include <kernel/lib/stdio.h> #include <kernel/timer/timer.h> +#include <kernel/memory/kheap.h> +#include <kernel/graphics/font.h> void install_melvix() { @@ -27,6 +28,7 @@ void install_melvix() // Copy MBR info("Copying MBR... "); + serial_printf("Copying MBR... "); char *stage1_p[] = {"BOOT", "HDD1.BIN"}; struct iso9660_entity *stage1_e = ISO9660_get(stage1_p, 2); if (!stage1_e) @@ -37,10 +39,12 @@ void install_melvix() // Format disk info("Formatting disk..."); + serial_printf("Formatting disk..."); marfs_format(); // Copy second stage info("Copying second stage..."); + serial_printf("Copying second stage..."); char *stage2_p[] = {"BOOT", "HDD2.BIN"}; struct iso9660_entity *stage2_e = ISO9660_get(stage2_p, 2); if (!stage2_e) @@ -51,11 +55,12 @@ void install_melvix() // Copy the kernel info("Copying the kernel..."); + serial_printf("Copying the kernel..."); char *kernel_p[] = {"BOOT", "KERNEL.BIN"}; struct iso9660_entity *kernel_e = ISO9660_get(kernel_p, 2); if (!kernel_e) panic("WTH Kernel not found!?"); - uint8_t *kernel = kmalloc(kernel_e->length + 2048); + uint8_t *kernel = (uint8_t *) kmalloc(kernel_e->length + 2048); ATAPI_granular_read(1 + (kernel_e->length / 2048), kernel_e->lba, kernel); marfs_new_file(kernel_e->length, kernel, 0, 0, 0); kfree(kernel); @@ -63,6 +68,7 @@ void install_melvix() // Copy the userspace binary info("Copying userspace... "); + serial_printf("Copying userspace... "); char *userspace_p[] = {"USER.BIN"}; struct iso9660_entity *userspace_e = ISO9660_get(userspace_p, 1); if (!userspace_e) @@ -73,14 +79,10 @@ void install_melvix() // Copy the global font binary info("Copying font... "); + serial_printf("Copying font... "); char *font_p[] = {"FONT.BIN"}; struct iso9660_entity *font_e = ISO9660_get(font_p, 1); - if (!font_e) - panic("Font not found!"); - uint8_t *font = kmalloc(font_e->length + 2048); - ATAPI_granular_read(1 + (font_e->length / 2048), font_e->lba, font); - marfs_new_file(font_e->length, font, 0, 0, 0); - kfree(font); + marfs_new_file(font_e->length, (uint8_t *) font, 0, 0, 0); kfree(font_e); info("Installation successful!"); diff --git a/src/kernel/fs/iso9660/iso9660.c b/src/kernel/fs/iso9660/iso9660.c index 3c61d94..2262408 100644 --- a/src/kernel/fs/iso9660/iso9660.c +++ b/src/kernel/fs/iso9660/iso9660.c @@ -1,8 +1,8 @@ #include <stdint.h> -#include <kernel/lib/lib.h> #include <kernel/fs/atapi_pio.h> #include <kernel/fs/iso9660/iso9660.h> #include <kernel/lib/stdlib.h> +#include <kernel/memory/kheap.h> struct iso9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) { diff --git a/src/kernel/fs/marfs/directory.c b/src/kernel/fs/marfs/directory.c index d0a1bff..dce92b1 100644 --- a/src/kernel/fs/marfs/directory.c +++ b/src/kernel/fs/marfs/directory.c @@ -2,6 +2,7 @@ #include <kernel/fs/ata_pio.h> #include <kernel/lib/stdlib.h> #include <kernel/fs/marfs/marfs.h> +#include <kernel/memory/kheap.h> uint32_t marfs_new_dir(uint32_t uid) { @@ -17,7 +18,7 @@ void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba) uint8_t *old = marfs_allocate_and_read_whole_file(lba_inode); // Allocate memory - uint8_t *contents = kmalloc(inode->size + strlen(filename) + 1 + 4); + uint8_t *contents = (uint8_t *) kmalloc((uint32_t) (inode->size + strlen(filename) + 1 + 4)); // Copy the content uint8_t last_was_null = 0; @@ -26,16 +27,16 @@ void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba) if (old[i] == 0 && last_was_null) continue; contents[new_size++] = old[i]; - last_was_null = (old[i] == 0); + last_was_null = (uint8_t) (old[i] == 0); } kfree(old); // Append new file - for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = filename[i]; - for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (lba >> j) & 0xFF; + for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = (uint8_t) filename[i]; + for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (uint8_t) ((lba >> j) & 0xFF); // Free the blocks - uint32_t new_size_in_blocks = new_size / 512; + uint32_t new_size_in_blocks = (uint32_t) (new_size / 512); if (new_size % 512) new_size_in_blocks++; for (uint32_t i = 0; i < new_size_in_blocks; i++) marfs_mark_block_as_free(marfs_get_block(inode, i)); diff --git a/src/kernel/fs/marfs/new_file.c b/src/kernel/fs/marfs/new_file.c index 4fef3b9..ab1c241 100644 --- a/src/kernel/fs/marfs/new_file.c +++ b/src/kernel/fs/marfs/new_file.c @@ -1,7 +1,7 @@ #include <stdint.h> #include <kernel/fs/ata_pio.h> -#include <kernel/lib/stdlib.h> #include <kernel/fs/marfs/marfs.h> +#include <kernel/memory/kheap.h> static uint8_t last_max_level = 0; @@ -30,17 +30,17 @@ void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t rec_lba, uint32_ uint32_t contents_idx = contents[idx]; kfree(contents); if (level != 1) { - marfs_update_recursive(level - 1, i, contents_idx, real_lba); + marfs_update_recursive((uint8_t) (level - 1), i, contents_idx, real_lba); } last_max_level = 0; } uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir) { - struct marfs_inode *inode = (struct marfs_inode *) kcalloc(1, 512); + struct marfs_inode *inode = (struct marfs_inode *) kmalloc(512); inode->size = size; inode->creation_time = inode->last_mod_time = inode->last_access_time = 0; // TODO: POSIX time - inode->n_blocks = size / 512; + inode->n_blocks = (uint32_t) (size / 512); if (size % 512) inode->n_blocks++; inode->uid = uid; inode->is_app = exec; diff --git a/src/kernel/fs/marfs/read_whole_file.c b/src/kernel/fs/marfs/read_whole_file.c index 85f9bbb..dda5daf 100644 --- a/src/kernel/fs/marfs/read_whole_file.c +++ b/src/kernel/fs/marfs/read_whole_file.c @@ -1,7 +1,7 @@ #include <stdint.h> #include <kernel/fs/ata_pio.h> -#include <kernel/lib/stdlib.h> #include <kernel/fs/marfs/marfs.h> +#include <kernel/memory/kheap.h> static uint8_t last_max_level = 0; @@ -19,7 +19,7 @@ uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t rec_lba) kfree(contents); uint32_t toRet; - if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_rec_lba); + if (level > 1) toRet = marfs_get_recursive((uint8_t) (level - 1), i, next_rec_lba); else toRet = next_rec_lba; last_max_level = 0; return toRet; @@ -48,7 +48,7 @@ void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer) for (uint32_t i = 0; i < size_in_blocks; i++) { uint32_t this_block = marfs_get_block(inode, i); uint8_t *this_block_contents = ata_read28(interface, this_block); - uint16_t upper_bound = (i != size_in_blocks - 1) ? 512 : (inode->size % 512); + uint16_t upper_bound = (uint16_t) ((i != size_in_blocks - 1) ? 512 : (inode->size % 512)); for (uint16_t j = 0; j < upper_bound; j++) buffer[(i * 512) + j] = this_block_contents[j]; kfree(this_block_contents); } @@ -63,7 +63,7 @@ uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode) uint64_t size = inode->size; kfree(inode); - uint8_t *buffer = kmalloc(size); + uint8_t *buffer = (uint8_t *) kmalloc((uint32_t) size); marfs_read_whole_file(lba_inode, buffer); return buffer; } diff --git a/src/kernel/fs/marfs/sectorlevel.c b/src/kernel/fs/marfs/sectorlevel.c index d905315..8302054 100644 --- a/src/kernel/fs/marfs/sectorlevel.c +++ b/src/kernel/fs/marfs/sectorlevel.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/lib/stdlib.h> #include <kernel/fs/ata_pio.h> #include <kernel/fs/marfs/marfs.h> +#include <kernel/memory/kheap.h> uint8_t marfs_init(struct ata_interface *_interface) { @@ -62,7 +62,7 @@ static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode) { lba_sector -= 2; lba_sector -= sb_cache.s_first_chunk; - uint16_t block_in_chunk = lba_sector % 512; + uint16_t block_in_chunk = (uint16_t) (lba_sector % 512); lba_sector /= 512; lba_sector = 2 + sb_cache.s_first_chunk + (512 * lba_sector); |