diff options
94 files changed, 1187 insertions, 1171 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ffab93..a72d698 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(CMAKE_ASM_LINKER_PREFERENCE ${CMAKE_LINKER}) set(CMAKE_C_LINKER_PREFERENCE ${CMAKE_LINKER}) # Compiler and linker flags -set(CMAKE_C_FLAGS "-Wall -Wno-int-conversion -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdlib -ffreestanding -std=gnu99 -g -ggdb -c") +set(CMAKE_C_FLAGS "-Wall -Wno-int-conversion -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdlib -nostdinc -ffreestanding -std=gnu99 -g -ggdb -c") set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -O2 -nostdlib -g -ggdb") set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> -o <OBJECT> -f elf32 -O0") set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") @@ -38,13 +38,14 @@ file(GLOB_RECURSE user_libgui_sources src/userspace/libgui/*.c) # KERNEL add_executable(kernel ${kernel_sources}) -target_include_directories(kernel PRIVATE "src") +target_include_directories(kernel PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/" "${CMAKE_CURRENT_SOURCE_DIR}/src/shared/") set_target_properties(kernel PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/kernel/kernel.bin") target_compile_options(kernel PRIVATE "-D ${NETWORK}") target_link_libraries(kernel PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/linker.ld") # RESOURCES add_executable(resources ${resources_sources}) +target_include_directories(resources PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/shared/") set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/res/font.o") target_compile_options(resources PRIVATE "-Os") # This is needed to preserve my fixed function order ig add_custom_command( @@ -55,7 +56,7 @@ add_custom_command( # USERSPACE LIBC add_library(userspace_libc ${user_libc_sources}) -target_include_directories(userspace_libc PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/") +target_include_directories(userspace_libc PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/" "${CMAKE_CURRENT_SOURCE_DIR}/src/shared/") # USERSPACE LIBGUI add_library(userspace_libgui ${user_libgui_sources}) @@ -66,7 +67,6 @@ target_include_directories(userspace_libgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ foreach(loop_file ${user_sources}) get_filename_component(testname ${loop_file} NAME_WE) add_executable(${testname} ${loop_file}) - target_compile_options(${testname} PRIVATE "-nostdinc") target_include_directories(${testname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/" "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libgui/") target_link_libraries(${testname} userspace_libc userspace_libgui "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld") set_target_properties(${testname} PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/user/${testname}") diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c index 1fced51..2f1c29f 100644 --- a/src/kernel/acpi/acpi.c +++ b/src/kernel/acpi/acpi.c @@ -2,15 +2,15 @@ // HPET: https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf #include <stddef.h> -#include <kernel/system.h> -#include <kernel/multiboot.h> -#include <kernel/io/io.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/stdlib.h> -#include <kernel/lib/stdio.h> -#include <kernel/acpi/acpi.h> -#include <kernel/memory/paging.h> -#include <kernel/memory/alloc.h> +#include <system.h> +#include <multiboot.h> +#include <io/io.h> +#include <lib/lib.h> +#include <lib/stdlib.h> +#include <lib/stdio.h> +#include <acpi/acpi.h> +#include <memory/paging.h> +#include <memory/alloc.h> struct rsdt *rsdt; struct fadt *fadt; @@ -19,9 +19,9 @@ struct madt *madt; int check_sum(struct sdt_header *header) { - uint8_t sum = 0; + u8 sum = 0; - for (uint32_t i = 0; i < header->length; i++) + for (u32 i = 0; i < header->length; i++) sum += ((char *)header)[i]; return sum == 0; @@ -44,11 +44,11 @@ void acpi_init(struct rsdp *rsdp) if (!check_sum((struct sdt_header *)rsdt)) { warn("Corrupted RSDT!"); } else { - uint32_t *pointer = (uint32_t *)(rsdt + 1); - uint32_t *end = (uint32_t *)((uint8_t *)rsdt + rsdt->header.length); + u32 *pointer = (u32 *)(rsdt + 1); + u32 *end = (u32 *)((u8 *)rsdt + rsdt->header.length); while (pointer < end) { - uint32_t address = *pointer++; + u32 address = *pointer++; memcpy(header, (void *)address, sizeof(struct sdt_header)); if (strncmp(header->signature, "FACP", 4) == 0) { @@ -103,7 +103,7 @@ void reboot() outb(fadt->reset_reg.address, fadt->reset_value); halt_loop(); } else { - uint8_t good = 0x02; + u8 good = 0x02; while (good & 0x02) good = inb(0x64); outb(0x64, 0xFE); diff --git a/src/kernel/acpi/acpi.h b/src/kernel/acpi/acpi.h index 0b98552..d487bdd 100644 --- a/src/kernel/acpi/acpi.h +++ b/src/kernel/acpi/acpi.h @@ -2,7 +2,7 @@ #define MELVIX_ACPI_H #include <stdint.h> -#include <kernel/multiboot.h> +#include <multiboot.h> /** * Initialize the ACP interface @@ -21,38 +21,38 @@ void reboot(); void acpi_poweroff(); struct address_structure { - uint8_t address_space_id; - uint8_t register_bit_width; - uint8_t register_bit_offset; - uint8_t reserved; - uint64_t address; + u8 address_space_id; + u8 register_bit_width; + u8 register_bit_offset; + u8 reserved; + u64 address; }; // p. 138 struct fadt_flags { - uint8_t WBINVD : 1; - uint8_t WBINVD_flush : 1; - uint8_t C1_support : 1; - uint8_t C2_mp_support : 1; - uint8_t power_button : 1; // 1 if not present - uint8_t sleep_button : 1; // 1 if not present - uint8_t rtc_fix_reg : 1; - uint8_t rtc_wakes_S4 : 1; - uint8_t timer_32 : 1; - uint8_t dock_support : 1; - uint8_t reset_support : 1; - uint8_t sealed_case : 1; - uint8_t headless : 1; - uint8_t slp_instruction : 1; - uint8_t pci_wake_support : 1; - uint8_t use_platform_clock : 1; - uint8_t rtc_valid_S4 : 1; - uint8_t remote_on_support : 1; - uint8_t force_apic_cluster : 1; - uint8_t force_apic_physical : 1; - uint8_t hw_reduced_acpi : 1; - uint8_t low_power_S0_support : 1; - uint16_t reserved : 10; + u8 WBINVD : 1; + u8 WBINVD_flush : 1; + u8 C1_support : 1; + u8 C2_mp_support : 1; + u8 power_button : 1; // 1 if not present + u8 sleep_button : 1; // 1 if not present + u8 rtc_fix_reg : 1; + u8 rtc_wakes_S4 : 1; + u8 timer_32 : 1; + u8 dock_support : 1; + u8 reset_support : 1; + u8 sealed_case : 1; + u8 headless : 1; + u8 slp_instruction : 1; + u8 pci_wake_support : 1; + u8 use_platform_clock : 1; + u8 rtc_valid_S4 : 1; + u8 remote_on_support : 1; + u8 force_apic_cluster : 1; + u8 force_apic_physical : 1; + u8 hw_reduced_acpi : 1; + u8 low_power_S0_support : 1; + u16 reserved : 10; }; struct rsdp { @@ -60,76 +60,76 @@ struct rsdp { char checksum; char oem_id[6]; char revision; - uint32_t *rsdt_address; + u32 *rsdt_address; }; struct sdt_header { char signature[4]; - uint32_t length; - uint8_t revision; - uint8_t checksum; + u32 length; + u8 revision; + u8 checksum; char oem_id[6]; char oem_table_id[8]; - uint32_t oem_revision; - uint32_t creator_id; - uint32_t creator_revision; + u32 oem_revision; + u32 creator_id; + u32 creator_revision; }; struct rsdt { struct sdt_header header; - uint32_t sdt_pointer[]; + u32 sdt_pointer[]; }; struct xsdt { struct sdt_header header; - uint32_t sdt_pointer[]; + u32 sdt_pointer[]; }; struct fadt { struct sdt_header header; - uint32_t firmware_ctl; - uint32_t dsdt; - uint8_t reserved; - uint8_t preferred_power_management; - uint16_t sci_interrupt; - uint32_t smi_commandPort; - uint8_t acpi_enable; - uint8_t acpi_disable; - uint8_t S4BIOS_req; - uint8_t PSTATE_control; - uint32_t PM1a_event_block; - uint32_t PM1b_event_block; - uint32_t PM1a_control_block; - uint32_t PM1b_control_block; - uint32_t PM2_control_block; - uint32_t PM_timer_block; - uint32_t GPE0_block; - uint32_t GPE1_block; - uint8_t PM1_event_length; - uint8_t PM1_control_length; - uint8_t PM2_control_length; - uint8_t PM_timer_length; - uint8_t GPE0_length; - uint8_t GPE1_length; - uint8_t GPE1_base; - uint8_t C_state_control; - uint16_t worst_C2_latency; - uint16_t worst_C3_latency; - uint16_t flush_size; - uint16_t flush_stride; - uint8_t duty_offset; - uint8_t duty_width; - uint8_t day_alarm; - uint8_t month_alarm; - uint8_t century; - uint16_t boot_architecture_flags; // Reserved in 1.0 - uint8_t reserved2; + u32 firmware_ctl; + u32 dsdt; + u8 reserved; + u8 preferred_power_management; + u16 sci_interrupt; + u32 smi_commandPort; + u8 acpi_enable; + u8 acpi_disable; + u8 S4BIOS_req; + u8 PSTATE_control; + u32 PM1a_event_block; + u32 PM1b_event_block; + u32 PM1a_control_block; + u32 PM1b_control_block; + u32 PM2_control_block; + u32 PM_timer_block; + u32 GPE0_block; + u32 GPE1_block; + u8 PM1_event_length; + u8 PM1_control_length; + u8 PM2_control_length; + u8 PM_timer_length; + u8 GPE0_length; + u8 GPE1_length; + u8 GPE1_base; + u8 C_state_control; + u16 worst_C2_latency; + u16 worst_C3_latency; + u16 flush_size; + u16 flush_stride; + u8 duty_offset; + u8 duty_width; + u8 day_alarm; + u8 month_alarm; + u8 century; + u16 boot_architecture_flags; // Reserved in 1.0 + u8 reserved2; struct fadt_flags flags; struct address_structure reset_reg; - uint8_t reset_value; - uint8_t reserved3[3]; - uint64_t x_firmware_control; // Reserved in 1.0 - uint64_t x_dsdt; // Reserved in 1.0 + u8 reset_value; + u8 reserved3[3]; + u64 x_firmware_control; // Reserved in 1.0 + u64 x_dsdt; // Reserved in 1.0 struct address_structure x_PM1a_event_block; struct address_structure x_PM1b_event_block; struct address_structure x_PM1a_control_block; @@ -142,22 +142,22 @@ struct fadt { struct hpet { struct sdt_header header; - uint8_t hardware_rev_id; - uint8_t comparator_count : 5; - uint8_t counter_size : 1; - uint8_t reserved : 1; - uint8_t legacy_replacement : 1; - uint16_t pci_vendor_id; + u8 hardware_rev_id; + u8 comparator_count : 5; + u8 counter_size : 1; + u8 reserved : 1; + u8 legacy_replacement : 1; + u16 pci_vendor_id; struct address_structure address; - uint8_t hpet_number; - uint16_t minimum_tick; - uint8_t page_protection; + u8 hpet_number; + u16 minimum_tick; + u8 page_protection; }; struct madt { struct sdt_header header; - uint32_t address; - uint32_t flags; + u32 address; + u32 flags; // Interrupt devices... }; diff --git a/src/kernel/cmos/rtc.c b/src/kernel/cmos/rtc.c index 6488d34..d6b0849 100644 --- a/src/kernel/cmos/rtc.c +++ b/src/kernel/cmos/rtc.c @@ -1,14 +1,14 @@ -#include <kernel/system.h> -#include <kernel/io/io.h> -#include <kernel/acpi/acpi.h> -#include <kernel/lib/stdio.h> +#include <system.h> +#include <io/io.h> +#include <acpi/acpi.h> +#include <lib/stdio.h> -uint8_t second; -uint8_t minute; -uint8_t hour; -uint8_t day; -uint8_t month; -uint32_t year; +u8 second; +u8 minute; +u8 hour; +u8 day; +u8 month; +u32 year; int get_update_in_progress_flag() { @@ -16,23 +16,23 @@ int get_update_in_progress_flag() return (inb(0x71) & 0x80); } -uint8_t get_rtc_register(int reg) +u8 get_rtc_register(int reg) { - outb(0x70, (uint8_t)reg); + outb(0x70, (u8)reg); return inb(0x71); } void read_rtc() { - uint32_t century = 20; - uint8_t last_second; - uint8_t last_minute; - uint8_t last_hour; - uint8_t last_day; - uint8_t last_month; - uint8_t last_year; - uint8_t last_century; - uint8_t registerB; + u32 century = 20; + u8 last_second; + u8 last_minute; + u8 last_hour; + u8 last_day; + u8 last_month; + u8 last_year; + u8 last_century; + u8 registerB; while (get_update_in_progress_flag()) { }; @@ -51,8 +51,8 @@ void read_rtc() last_hour = hour; last_day = day; last_month = month; - last_year = (uint8_t)year; - last_century = (uint8_t)century; + last_year = (u8)year; + last_century = (u8)century; while (get_update_in_progress_flag()) { }; @@ -70,11 +70,11 @@ void read_rtc() registerB = get_rtc_register(0x0B); if (!(registerB & 0x04)) { - second = (uint8_t)((second & 0x0F) + ((second / 16) * 10)); - minute = (uint8_t)((minute & 0x0F) + ((minute / 16) * 10)); - hour = (uint8_t)(((hour & 0x0F) + (((hour & 0x70) / 16) * 10)) | (hour & 0x80)); - day = (uint8_t)((day & 0x0F) + ((day / 16) * 10)); - month = (uint8_t)((month & 0x0F) + ((month / 16) * 10)); + second = (u8)((second & 0x0F) + ((second / 16) * 10)); + minute = (u8)((minute & 0x0F) + ((minute / 16) * 10)); + hour = (u8)(((hour & 0x0F) + (((hour & 0x70) / 16) * 10)) | (hour & 0x80)); + day = (u8)((day & 0x0F) + ((day / 16) * 10)); + month = (u8)((month & 0x0F) + ((month / 16) * 10)); year = (year & 0x0F) + ((year / 16) * 10); century = (century & 0x0F) + ((century / 16) * 10); } @@ -83,7 +83,7 @@ void read_rtc() // Convert to 24h if necessary if (!(registerB & 0x02) && (hour & 0x80)) { - hour = (uint8_t)(((hour & 0x7F) + 12) % 24); + hour = (u8)(((hour & 0x7F) + 12) % 24); } } diff --git a/src/kernel/cmos/rtc.h b/src/kernel/cmos/rtc.h index 6c2ba81..3e52793 100644 --- a/src/kernel/cmos/rtc.h +++ b/src/kernel/cmos/rtc.h @@ -3,11 +3,11 @@ #include <stdint.h> -uint8_t second; -uint8_t minute; -uint8_t hour; -uint8_t day; -uint8_t month; +u8 second; +u8 minute; +u8 hour; +u8 day; +u8 month; unsigned int year; void read_rtc(); diff --git a/src/kernel/fs/ata.c b/src/kernel/fs/ata.c index 2146822..c7c7dc1 100644 --- a/src/kernel/fs/ata.c +++ b/src/kernel/fs/ata.c @@ -1,16 +1,16 @@ #include <stdint.h> #include <stddef.h> #include <stdbool.h> -#include <kernel/fs/ata.h> -#include <kernel/system.h> -#include <kernel/io/io.h> +#include <fs/ata.h> +#include <system.h> +#include <io/io.h> -static uint16_t sel_base_port = 0; -static uint8_t sel_master_or_slave = 0; +static u16 sel_base_port = 0; +static u8 sel_master_or_slave = 0; -static uint32_t max_sector; +static u32 max_sector; -static uint8_t read_stat(uint16_t base) +static u8 read_stat(u16 base) { inb(base + COM_STAT); inb(base + COM_STAT); @@ -20,7 +20,7 @@ static uint8_t read_stat(uint16_t base) return inb(base + COM_STAT); } -static void check_drive(uint16_t base, uint8_t master_or_slave) +static void check_drive(u16 base, u8 master_or_slave) { if (sel_base_port != 0) return; @@ -33,7 +33,7 @@ static void check_drive(uint16_t base, uint8_t master_or_slave) outb(base + LBA_HIGH, 0); outb(base + COM_STAT, IDENTIFY); - uint8_t stat = read_stat(base); + u8 stat = read_stat(base); if (stat == 0) return; @@ -47,8 +47,8 @@ static void check_drive(uint16_t base, uint8_t master_or_slave) if ((stat & ERR) != 0) return; - uint16_t drive_data[256]; - for (size_t i = 0; i < 256; i++) + u16 drive_data[256]; + for (u32 i = 0; i < 256; i++) drive_data[i] = inw(base + DATA); max_sector = drive_data[MAX_28LBA_SECTORS] | drive_data[MAX_28LBA_SECTORS + 1] << 16; @@ -59,8 +59,8 @@ static void check_drive(uint16_t base, uint8_t master_or_slave) void ata_init() { - uint8_t pri_status = inb(PRIMARY_BASE + COM_STAT); - uint8_t sec_status = inb(SECONDARY_BASE + COM_STAT); + u8 pri_status = inb(PRIMARY_BASE + COM_STAT); + u8 sec_status = inb(SECONDARY_BASE + COM_STAT); bool primary_floating = false; bool secondary_floating = false; if (pri_status == 0xFF) @@ -90,14 +90,14 @@ void ata_init() static void poll() { - uint8_t stat; + u8 stat; do stat = read_stat(sel_base_port); while ((stat & BSY) != 0); } -void read_abs_sectors(uint32_t lba, uint8_t sector_count, uint16_t buf[]) +void read_abs_sectors(u32 lba, u8 sector_count, u16 buf[]) { assert(lba >> LBA_BITS == 0); @@ -110,7 +110,7 @@ void read_abs_sectors(uint32_t lba, uint8_t sector_count, uint16_t buf[]) outb(sel_base_port + COM_STAT, READ_SECTORS); - size_t i = 0; + u32 i = 0; for (; sector_count > 0; sector_count--) { poll(); diff --git a/src/kernel/fs/ata.h b/src/kernel/fs/ata.h index b3774e1..0422fe3 100644 --- a/src/kernel/fs/ata.h +++ b/src/kernel/fs/ata.h @@ -40,6 +40,6 @@ void ata_init(); -void read_abs_sectors(uint32_t lba, uint8_t sector_count, uint16_t buf[]); +void read_abs_sectors(u32 lba, u8 sector_count, u16 buf[]); #endif
\ No newline at end of file diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index 37cc606..bee53c9 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -1,14 +1,14 @@ #include <stdint.h> #include <stddef.h> -#include <kernel/system.h> -#include <kernel/fs/elf.h> -#include <kernel/lib/stdio.h> -#include <kernel/memory/alloc.h> -#include <kernel/lib/lib.h> -#include <kernel/memory/paging.h> -#include <kernel/fs/ext2.h> -#include <kernel/gdt/gdt.h> -#include <kernel/tasks/process.h> +#include <system.h> +#include <fs/elf.h> +#include <lib/stdio.h> +#include <memory/alloc.h> +#include <lib/lib.h> +#include <memory/paging.h> +#include <fs/ext2.h> +#include <gdt/gdt.h> +#include <tasks/process.h> int is_elf(struct elf_header *header) { @@ -23,7 +23,7 @@ int is_elf(struct elf_header *header) struct process *elf_load(char *path) { - uint8_t *file = read_file(path); + u8 *file = read_file(path); if (!file) { warn("File or directory not found: %s", path); return NULL; @@ -44,7 +44,7 @@ struct process *elf_load(char *path) proc->registers.eip = header->entry; paging_switch_directory(proc->cr3); - uint32_t stk = (uint32_t)kmalloc_a(PAGE_S); + u32 stk = (u32)kmalloc_a(PAGE_S); proc->registers.useresp = 0x40000000 - (PAGE_S / 2); proc->registers.ebp = proc->registers.useresp; proc->registers.esp = proc->registers.useresp; @@ -56,10 +56,10 @@ struct process *elf_load(char *path) break; case 1: debug("Allocating space for ELF binary section..."); - uint32_t loc = (uint32_t)kmalloc_a(PAGE_S); + u32 loc = (u32)kmalloc_a(PAGE_S); paging_map_user(proc->cr3, loc, program_header->vaddr); memcpy((void *)program_header->vaddr, - ((void *)((uint32_t)file) + program_header->offset), + ((void *)((u32)file) + program_header->offset), program_header->filesz); if (program_header->filesz > PAGE_S) panic("ELF binary section too large"); diff --git a/src/kernel/fs/elf.h b/src/kernel/fs/elf.h index 8c7d38a..f9a3562 100644 --- a/src/kernel/fs/elf.h +++ b/src/kernel/fs/elf.h @@ -2,7 +2,7 @@ #define MELVIX_ELF_H #include <stdint.h> -#include <kernel/tasks/process.h> +#include <tasks/process.h> #define ELF_MAG 0x7F // 0 #define ELF_32 (1) // 4: 32-bit Architecture @@ -29,48 +29,48 @@ #define PF_R 0x4 struct elf_priv_data { - uint32_t sig; + u32 sig; }; struct elf_header { - uint8_t ident[16]; - uint16_t type; - uint16_t machine; - uint32_t version; - uint32_t entry; - uint32_t phoff; - uint32_t shoff; - uint32_t flags; - uint16_t ehsize; - uint16_t phentsize; - uint16_t phnum; - uint16_t shentsize; - uint16_t shnum; - uint16_t shstrndx; + u8 ident[16]; + u16 type; + u16 machine; + u32 version; + u32 entry; + u32 phoff; + u32 shoff; + u32 flags; + u16 ehsize; + u16 phentsize; + u16 phnum; + u16 shentsize; + u16 shnum; + u16 shstrndx; }; struct elf_section_header { - uint32_t name; - uint32_t type; - uint32_t flags; - uint32_t addr; - uint32_t offset; - uint32_t size; - uint32_t link; - uint32_t info; - uint32_t addralign; - uint32_t entsize; + u32 name; + u32 type; + u32 flags; + u32 addr; + u32 offset; + u32 size; + u32 link; + u32 info; + u32 addralign; + u32 entsize; }; struct elf_program_header { - uint32_t type; - uint32_t offset; - uint32_t vaddr; - uint32_t paddr; - uint32_t filesz; - uint32_t memsz; - uint32_t flags; - uint32_t align; + u32 type; + u32 offset; + u32 vaddr; + u32 paddr; + u32 filesz; + u32 memsz; + u32 flags; + u32 align; }; int is_elf(struct elf_header *header); diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c index b4f81a8..78d1dc4 100644 --- a/src/kernel/fs/ext2.c +++ b/src/kernel/fs/ext2.c @@ -1,21 +1,21 @@ #include <stddef.h> #include <stdint.h> #include <stdbool.h> -#include <kernel/fs/ata.h> -#include <kernel/fs/ext2.h> -#include <kernel/system.h> -#include <kernel/memory/alloc.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/stdlib.h> +#include <fs/ata.h> +#include <fs/ext2.h> +#include <system.h> +#include <memory/alloc.h> +#include <lib/lib.h> +#include <lib/stdlib.h> static struct ext2_superblock superblock; static struct bgd *bgdt; -static size_t block_size; -static size_t num_groups; -static void read_block(uint32_t block_num, void *buf); +static u32 block_size; +static u32 num_groups; +static void read_block(u32 block_num, void *buf); static void load_superblock(); static void load_bgdt(); -static void read_inode(struct ext2_inode *inode, uint32_t inode_num); +static void read_inode(struct ext2_inode *inode, u32 inode_num); void ext2_init_fs() { @@ -38,17 +38,17 @@ void ext2_init_fs() debug("Inode %d, name '%s'", dirent.inode_num, dirent.name); } -static void read_block(uint32_t block_num, void *buf) +static void read_block(u32 block_num, void *buf) { - uint32_t lba = block_num * block_size / SECTOR_SIZE; - size_t sectors = block_size / SECTOR_SIZE; + u32 lba = block_num * block_size / SECTOR_SIZE; + u32 sectors = block_size / SECTOR_SIZE; read_abs_sectors(lba, sectors, buf); } static void load_superblock() { - uint16_t buf[SUPERBLOCK_LENGTH / 2]; + u16 buf[SUPERBLOCK_LENGTH / 2]; read_abs_sectors(SUPERBLOCK_LBA, SUPERBLOCK_SECTORS, buf); memcpy(&superblock, buf, sizeof(struct ext2_superblock)); @@ -70,38 +70,38 @@ static void load_superblock() static void load_bgdt() { - size_t bgdt_sectors = (sizeof(struct bgd) * num_groups) / SECTOR_SIZE + 1; - size_t bgdt_block = (SUPERBLOCK_OFFSET + SUPERBLOCK_LENGTH) / block_size + 1; - uint32_t bgdt_lba = bgdt_block * block_size / SECTOR_SIZE; + u32 bgdt_sectors = (sizeof(struct bgd) * num_groups) / SECTOR_SIZE + 1; + u32 bgdt_block = (SUPERBLOCK_OFFSET + SUPERBLOCK_LENGTH) / block_size + 1; + u32 bgdt_lba = bgdt_block * block_size / SECTOR_SIZE; - uint16_t buf[bgdt_sectors * SECTOR_SIZE / 2]; + u16 buf[bgdt_sectors * SECTOR_SIZE / 2]; read_abs_sectors(bgdt_lba, bgdt_sectors, buf); - size_t bgdt_size = sizeof(struct bgd) * num_groups; + u32 bgdt_size = sizeof(struct bgd) * num_groups; bgdt = kmalloc(bgdt_size); memcpy(bgdt, buf, bgdt_size); } -static void read_inode(struct ext2_inode *inode, uint32_t inode_num) +static void read_inode(struct ext2_inode *inode, u32 inode_num) { inode_num--; - size_t block_group = inode_num / superblock.inodes_per_group; + u32 block_group = inode_num / superblock.inodes_per_group; struct bgd *bgd = &bgdt[block_group]; - uint32_t i_table_block = bgd->inode_table_addr; + u32 i_table_block = bgd->inode_table_addr; - size_t index = inode_num % superblock.inodes_per_group; - size_t block_offset = (index * INODE_SIZE) / block_size; - size_t offset_in_block = (index * INODE_SIZE) % block_size; - size_t block = i_table_block + block_offset; + u32 index = inode_num % superblock.inodes_per_group; + u32 block_offset = (index * INODE_SIZE) / block_size; + u32 offset_in_block = (index * INODE_SIZE) % block_size; + u32 block = i_table_block + block_offset; - size_t num_sectors = sizeof(struct ext2_inode) / SECTOR_SIZE + 1; - uint16_t buf[num_sectors * SECTOR_SIZE / 2]; + u32 num_sectors = sizeof(struct ext2_inode) / SECTOR_SIZE + 1; + u16 buf[num_sectors * SECTOR_SIZE / 2]; read_abs_sectors(block * block_size / SECTOR_SIZE, num_sectors, buf); memcpy(inode, &buf[offset_in_block / 2], sizeof(struct ext2_inode)); } -void ext2_open_inode(uint32_t inode_num, struct ext2_file *file) +void ext2_open_inode(u32 inode_num, struct ext2_file *file) { read_inode(&file->inode, inode_num); file->pos = 0; @@ -112,15 +112,15 @@ void ext2_open_inode(uint32_t inode_num, struct ext2_file *file) read_block(file->inode.dbp[0], file->buf); } -size_t ext2_read(struct ext2_file *file, uint8_t *buf, size_t count) +u32 ext2_read(struct ext2_file *file, u8 *buf, u32 count) { if (file->pos + count > file->inode.size) count = file->inode.size - file->pos; - size_t bytes_left = count; + u32 bytes_left = count; while (bytes_left > 0) { - size_t to_copy = bytes_left; + u32 to_copy = bytes_left; bool new_block = file->curr_block_pos + to_copy >= block_size; if (new_block) @@ -136,7 +136,7 @@ size_t ext2_read(struct ext2_file *file, uint8_t *buf, size_t count) file->block_index++; if (file->block_index >= 12) { // TODO: Add triple block pointer support - uint32_t *tmp = kmalloc(block_size); + u32 *tmp = kmalloc(block_size); read_block(file->inode.ibp, tmp); read_block(tmp[file->block_index - 12], file->buf); } else { @@ -148,36 +148,36 @@ size_t ext2_read(struct ext2_file *file, uint8_t *buf, size_t count) return count; } -#define READ_SIZE (sizeof(struct ext2_dirent) - sizeof(uint8_t *)) +#define READ_SIZE (sizeof(struct ext2_dirent) - sizeof(u8 *)) bool ext2_next_dirent(struct ext2_file *file, struct ext2_dirent *dir) { - uint8_t buf[READ_SIZE]; + u8 buf[READ_SIZE]; if (ext2_read(file, buf, READ_SIZE) != READ_SIZE) return false; memcpy(dir, buf, READ_SIZE); - size_t size = dir->name_len + 1; - uint8_t *name = kmalloc(size); + u32 size = dir->name_len + 1; + u8 *name = kmalloc(size); if (ext2_read(file, name, size - 1) != size - 1) return false; dir->name = name; dir->name[size - 1] = '\0'; - size_t bytes_left = dir->total_len - (READ_SIZE + size - 1); + u32 bytes_left = dir->total_len - (READ_SIZE + size - 1); if (bytes_left > 0) { - uint8_t dummy[bytes_left]; + u8 dummy[bytes_left]; ext2_read(file, dummy, bytes_left); } return true; } -uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name) +u32 ext2_find_in_dir(u32 dir_inode, const char *name) { - uint32_t inode; + u32 inode; struct ext2_file dir; struct ext2_dirent dirent; @@ -196,16 +196,16 @@ cleanup: return inode; } -uint32_t ext2_look_up_path(char *path) +u32 ext2_look_up_path(char *path) { if (path[0] != '/') return 0; path++; - uint32_t curr_dir_inode = ROOT_INODE; + u32 curr_dir_inode = ROOT_INODE; while (1) { - size_t j; + u32 j; for (j = 0; path[j] != '/' && path[j] != '\0'; j++) ; @@ -222,7 +222,7 @@ uint32_t ext2_look_up_path(char *path) path += j + 1; } - uint32_t inode = ext2_find_in_dir(curr_dir_inode, path); + u32 inode = ext2_find_in_dir(curr_dir_inode, path); if (inode == 0) return 0; diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h index f63b8b6..e5c26fe 100644 --- a/src/kernel/fs/ext2.h +++ b/src/kernel/fs/ext2.h @@ -17,71 +17,71 @@ #define SUPERBLOCK_SECTORS (SUPERBLOCK_LENGTH / SECTOR_SIZE) struct ext2_superblock { - uint32_t total_inodes; - uint32_t total_blocks; - uint32_t su_res_blocks; // Superuser reserved - uint32_t free_blocks; - uint32_t free_inodes; - uint32_t superblock_block_num; - uint32_t log2_block_size; - uint32_t log2_frag_size; - uint32_t blocks_per_group; - uint32_t frags_per_group; - uint32_t inodes_per_group; - uint32_t last_mount_time; - uint32_t last_write_time; - uint16_t mounts_since_fsck; - uint16_t max_mounts_since_fsck; - uint16_t signature; - uint16_t state; // 1 clean; 2 errors - uint16_t error_action; - uint16_t minor_version; - uint32_t last_fsck_time; - uint32_t max_time_since_fsck; - uint32_t creator_os_id; - uint32_t major_version; - uint16_t res_block_uid; - uint16_t res_block_gid; + u32 total_inodes; + u32 total_blocks; + u32 su_res_blocks; // Superuser reserved + u32 free_blocks; + u32 free_inodes; + u32 superblock_block_num; + u32 log2_block_size; + u32 log2_frag_size; + u32 blocks_per_group; + u32 frags_per_group; + u32 inodes_per_group; + u32 last_mount_time; + u32 last_write_time; + u16 mounts_since_fsck; + u16 max_mounts_since_fsck; + u16 signature; + u16 state; // 1 clean; 2 errors + u16 error_action; + u16 minor_version; + u32 last_fsck_time; + u32 max_time_since_fsck; + u32 creator_os_id; + u32 major_version; + u16 res_block_uid; + u16 res_block_gid; } __attribute__((packed)); // Block group descriptor struct bgd { - uint32_t block_bitmap_addr; - uint32_t inode_bitmap_addr; - uint32_t inode_table_addr; - uint16_t free_blocks; - uint16_t free_inodes; - uint16_t used_dirs; - uint16_t pad; - uint8_t bg_reserved[12]; + u32 block_bitmap_addr; + u32 inode_bitmap_addr; + u32 inode_table_addr; + u16 free_blocks; + u16 free_inodes; + u16 used_dirs; + u16 pad; + u8 bg_reserved[12]; } __attribute__((packed)); struct ext2_inode { - uint16_t mode; - uint16_t uid; - uint32_t size; - - uint32_t last_access_time; - uint32_t creation_time; - uint32_t last_modification_time; - uint32_t deletion_time; - - uint16_t gid; - uint16_t link_count; - uint32_t sectors_used; - uint32_t flags; - uint32_t os_specific_val1; - uint32_t dbp[12]; - uint32_t ibp; - uint32_t dibp; - uint32_t tibp; - uint32_t gen_number; - - uint32_t reserved1; - uint32_t reserved2; - - uint32_t fragment_addr; - uint8_t os_specific_val2[12]; + u16 mode; + u16 uid; + u32 size; + + u32 last_access_time; + u32 creation_time; + u32 last_modification_time; + u32 deletion_time; + + u16 gid; + u16 link_count; + u32 sectors_used; + u32 flags; + u32 os_specific_val1; + u32 dbp[12]; + u32 ibp; + u32 dibp; + u32 tibp; + u32 gen_number; + + u32 reserved1; + u32 reserved2; + + u32 fragment_addr; + u8 os_specific_val2[12]; } __attribute__((packed)); #define S_IFIFO 0x1000 @@ -125,29 +125,29 @@ struct ext2_inode { struct fs_node *ext2_root; struct ext2_dirent { - uint32_t inode_num; - uint16_t total_len; - uint8_t name_len; - uint8_t type_indicator; - uint8_t *name; + u32 inode_num; + u16 total_len; + u8 name_len; + u8 type_indicator; + u8 *name; } __attribute__((packed)); struct ext2_file { struct ext2_inode inode; - size_t pos; - uint8_t block_index; - uint8_t *buf; - size_t curr_block_pos; + u32 pos; + u8 block_index; + u8 *buf; + u32 curr_block_pos; }; void ext2_init_fs(); -void ext2_open_inode(uint32_t inode_num, struct ext2_file *file); -size_t ext2_read(struct ext2_file *file, uint8_t *buf, size_t count); +void ext2_open_inode(u32 inode_num, struct ext2_file *file); +u32 ext2_read(struct ext2_file *file, u8 *buf, u32 count); bool ext2_next_dirent(struct ext2_file *file, struct ext2_dirent *dir); -uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name); -uint32_t ext2_look_up_path(char *path); +u32 ext2_find_in_dir(u32 dir_inode, const char *name); +u32 ext2_look_up_path(char *path); -uint8_t *read_file(char *path); +u8 *read_file(char *path); void ext2_node_init(struct fs_node *node); void ext2_mount(struct fs_node *mountpoint); diff --git a/src/kernel/fs/fs.c b/src/kernel/fs/fs.c index 1553113..a57a83e 100644 --- a/src/kernel/fs/fs.c +++ b/src/kernel/fs/fs.c @@ -1,11 +1,11 @@ #include <stdint.h> -#include <kernel/fs/ext2.h> -#include <kernel/system.h> -#include <kernel/memory/alloc.h> +#include <fs/ext2.h> +#include <system.h> +#include <memory/alloc.h> -uint32_t get_file_size(char *path) +u32 get_file_size(char *path) { - uint32_t inode = ext2_look_up_path(path); + u32 inode = ext2_look_up_path(path); struct ext2_file file; ext2_open_inode(inode, &file); if (inode != 0) { @@ -17,9 +17,9 @@ uint32_t get_file_size(char *path) } // TODO: Implement offset -uint32_t read(char *path, uint32_t offset, uint32_t count, uint8_t *buf) +u32 read(char *path, u32 offset, u32 count, u8 *buf) { - uint32_t inode = ext2_look_up_path(path); + u32 inode = ext2_look_up_path(path); struct ext2_file file; ext2_open_inode(inode, &file); if (inode != 0) { @@ -35,21 +35,21 @@ uint32_t read(char *path, uint32_t offset, uint32_t count, uint8_t *buf) } // TODO: Implement writing -uint32_t write(char *path, uint32_t offset, uint32_t count, uint8_t *buf) +u32 write(char *path, u32 offset, u32 count, u8 *buf) { warn("Writing is not supported!"); return -1; } -uint8_t *read_file(char *path) +u8 *read_file(char *path) { - uint32_t inode = ext2_look_up_path(path); + u32 inode = ext2_look_up_path(path); struct ext2_file file; ext2_open_inode(inode, &file); if (inode != 0) { - size_t size = file.inode.size; + u32 size = file.inode.size; debug("Reading %s: %dKiB", path, size >> 10); - uint8_t *buf = kmalloc(size); + u8 *buf = kmalloc(size); ext2_read(&file, buf, size); kfree(file.buf); buf[size - 1] = '\0'; diff --git a/src/kernel/fs/fs.h b/src/kernel/fs/fs.h index 88dcd95..58b23db 100644 --- a/src/kernel/fs/fs.h +++ b/src/kernel/fs/fs.h @@ -3,9 +3,9 @@ #include <stdint.h> -uint32_t get_file_size(char *path); -uint32_t read(char *path, uint32_t offset, uint32_t count, uint8_t *buf); -uint32_t write(char *path, uint32_t offset, uint32_t count, uint8_t *buf); -uint8_t *read_file(char *path); // Only for temp kernel reads +u32 get_file_size(char *path); +u32 read(char *path, u32 offset, u32 count, u8 *buf); +u32 write(char *path, u32 offset, u32 count, u8 *buf); +u8 *read_file(char *path); // Only for temp kernel reads #endif
\ No newline at end of file diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c index f3e46ed..0170f26 100644 --- a/src/kernel/fs/load.c +++ b/src/kernel/fs/load.c @@ -1,8 +1,8 @@ -#include <kernel/fs/load.h> -#include <kernel/system.h> -#include <kernel/lib/stdio.h> -#include <kernel/lib/lib.h> -#include <kernel/fs/ext2.h> +#include <fs/load.h> +#include <system.h> +#include <lib/stdio.h> +#include <lib/lib.h> +#include <fs/ext2.h> void load_binaries() { diff --git a/src/kernel/fs/load.h b/src/kernel/fs/load.h index d03b0ec..b2376be 100644 --- a/src/kernel/fs/load.h +++ b/src/kernel/fs/load.h @@ -6,10 +6,10 @@ struct font *font; struct font { - uint16_t font_32[758][32]; - uint16_t font_24[758][24]; - uint8_t font_16[758][16]; - uint16_t cursor[19]; + u16 font_32[758][32]; + u16 font_24[758][24]; + u8 font_16[758][16]; + u16 cursor[19]; }; void load_binaries(); diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c index 4e8428f..616fb25 100644 --- a/src/kernel/gdt/gdt.c +++ b/src/kernel/gdt/gdt.c @@ -1,8 +1,8 @@ #include <stdint.h> -#include <kernel/gdt/gdt.h> -#include <kernel/system.h> -#include <kernel/lib/lib.h> -#include <kernel/memory/alloc.h> +#include <gdt/gdt.h> +#include <system.h> +#include <lib/lib.h> +#include <memory/alloc.h> struct gdt_entry { unsigned short limit_low; @@ -22,40 +22,40 @@ struct gdt_entry gdt[6]; struct gdt_ptr gp; struct tss_entry_struct { - uint32_t prev_tss; - uint32_t esp0; - uint32_t ss0; - uint32_t esp1; - uint32_t ss1; - uint32_t esp2; - uint32_t ss2; - uint32_t cr3; - uint32_t eip; - uint32_t eflags; - uint32_t eax; - uint32_t ecx; - uint32_t edx; - uint32_t ebx; - uint32_t esp; - uint32_t ebp; - uint32_t esi; - uint32_t edi; - uint32_t es; - uint32_t cs; - uint32_t ss; - uint32_t ds; - uint32_t fs; - uint32_t gs; - uint32_t ldt; - uint16_t trap; - uint16_t iomap_base; + u32 prev_tss; + u32 esp0; + u32 ss0; + u32 esp1; + u32 ss1; + u32 esp2; + u32 ss2; + u32 cr3; + u32 eip; + u32 eflags; + u32 eax; + u32 ecx; + u32 edx; + u32 ebx; + u32 esp; + u32 ebp; + u32 esi; + u32 edi; + u32 es; + u32 cs; + u32 ss; + u32 ds; + u32 fs; + u32 gs; + u32 ldt; + u16 trap; + u16 iomap_base; } __attribute__((packed)); struct tss_entry_struct tss_entry; extern void gdt_flush(); -void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) +void gdt_set_gate(s32 num, u32 base, u32 limit, u8 access, u8 gran) { // Set descriptor base address gdt[num].base_low = (unsigned short)(base & 0xFFFF); @@ -71,7 +71,7 @@ void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, ui gdt[num].access = access; } -extern uint32_t stack_hold; +extern u32 stack_hold; void gdt_install() { @@ -107,10 +107,10 @@ void gdt_install() info("Installed Global Descriptor Table"); } -void tss_write(int32_t num, uint16_t ss0, uint32_t esp0) +void tss_write(s32 num, u16 ss0, u32 esp0) { - uint32_t base = (uint32_t)&tss_entry; - uint32_t limit = base + sizeof(tss_entry); + u32 base = (u32)&tss_entry; + u32 limit = base + sizeof(tss_entry); gdt_set_gate(num, base, limit, 0xE9, 0x00); @@ -127,7 +127,7 @@ void tss_flush() asm volatile("ltr %%ax" : : "a"(0x2B)); } -void set_kernel_stack(uintptr_t stack) +void set_kernel_stack(u32 stack) { tss_entry.esp0 = stack; }
\ No newline at end of file diff --git a/src/kernel/gdt/gdt.h b/src/kernel/gdt/gdt.h index 5c6ae61..36d6744 100644 --- a/src/kernel/gdt/gdt.h +++ b/src/kernel/gdt/gdt.h @@ -1,15 +1,17 @@ #ifndef MELVIX_GDT_H #define MELVIX_GDT_H +#include <stdint.h> + /** * Installs the Global Descriptor Table */ void gdt_install(); -void tss_write(int32_t num, uint16_t ss0, uint32_t esp0); +void tss_write(s32 num, u16 ss0, u32 esp0); void tss_flush(); -void set_kernel_stack(uintptr_t stack); +void set_kernel_stack(u32 stack); #endif
\ No newline at end of file diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index cf31d76..176b46f 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -1,10 +1,10 @@ -#include <kernel/graphics/vesa.h> -#include <kernel/fs/load.h> -#include <kernel/system.h> -#include <kernel/lib/stdlib.h> -#include <kernel/lib/stdio.h> -#include <kernel/memory/alloc.h> -#include <kernel/memory/paging.h> +#include <graphics/vesa.h> +#include <fs/load.h> +#include <system.h> +#include <lib/stdlib.h> +#include <lib/stdio.h> +#include <memory/alloc.h> +#include <memory/paging.h> void vbe_error() { @@ -25,7 +25,7 @@ void vbe_set_mode(unsigned short mode) vbe_error(); } -uint16_t *vbe_get_modes() +u16 *vbe_get_modes() { char *info_address = (char *)0x7E00; strcpy(info_address, "VBE2"); @@ -44,19 +44,19 @@ uint16_t *vbe_get_modes() vbe_error(); // Get number of modes - uint16_t *mode_ptr = (uint16_t *)info->video_modes; - size_t number_modes = 1; - for (uint16_t *p = mode_ptr; *p != 0xFFFF; p++) + u16 *mode_ptr = (u16 *)info->video_modes; + u32 number_modes = 1; + for (u16 *p = mode_ptr; *p != 0xFFFF; p++) number_modes++; - uint16_t *ret = (uint16_t *)kmalloc(sizeof(uint16_t) * number_modes); - for (size_t i = 0; i < number_modes; i++) - ret[i] = ((uint16_t *)info->video_modes)[i]; + u16 *ret = (u16 *)kmalloc(sizeof(u16) * number_modes); + for (u32 i = 0; i < number_modes; i++) + ret[i] = ((u16 *)info->video_modes)[i]; return ret; } -struct vbe_mode_info *vbe_get_mode_info(uint16_t mode) +struct vbe_mode_info *vbe_get_mode_info(u16 mode) { regs16_t regs; regs.ax = 0x4F01; @@ -81,21 +81,15 @@ struct vbe_mode_info *vbe_get_mode_info(uint16_t mode) return ret; } -uint32_t fb_write(struct fs_node *node, uint32_t offset, uint32_t size, uint8_t *buffer) -{ - log("FB WRITE!"); - return 0; -} - void set_optimal_resolution() { log("Switching to graphics mode"); log("Trying to detect available modes"); - uint16_t *video_modes = vbe_get_modes(); + u16 *video_modes = vbe_get_modes(); - uint16_t highest = 0; + u16 highest = 0; - for (uint16_t *mode = video_modes; *mode != 0xFFFF; mode++) { + for (u16 *mode = video_modes; *mode != 0xFFFF; mode++) { struct vbe_mode_info *mode_info = vbe_get_mode_info(*mode); if (mode_info == 0 || (mode_info->attributes & 0x90) != 0x90 || @@ -141,8 +135,8 @@ void set_optimal_resolution() 271, 270, 269, // 320x200 }; - for (size_t i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) { - mode_info = vbe_get_mode_info((uint16_t)modes[i]); + for (u32 i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) { + mode_info = vbe_get_mode_info((u16)modes[i]); if (mode_info == 0 || (mode_info->attributes & 0x90) != 0x90 || (mode_info->memory_model != 4 && mode_info->memory_model != 6)) { kfree(mode_info); @@ -151,7 +145,7 @@ void set_optimal_resolution() if ((mode_info->width > vbe_width || (mode_info->width == vbe_width && (mode_info->bpp >> 3) > vbe_bpl))) { - highest = (uint16_t)modes[i]; + highest = (u16)modes[i]; vbe_width = mode_info->width; vbe_height = mode_info->height; vbe_pitch = mode_info->pitch; @@ -170,10 +164,10 @@ void set_optimal_resolution() vbe_set_mode(highest); - uint32_t fb_size = vbe_width * vbe_height * vbe_bpl; + u32 fb_size = vbe_width * vbe_height * vbe_bpl; /* cursor_buffer = kmalloc(fb_size); */ - for (uint32_t z = 0; z < fb_size; z += PAGE_S) { - paging_map_user(paging_root_directory, (uint32_t)fb + z, (uint32_t)fb + z); + for (u32 z = 0; z < fb_size; z += PAGE_S) { + paging_map_user(paging_root_directory, (u32)fb + z, (u32)fb + z); } /* dev_make("fb", NULL, (write)fb_write); */ @@ -200,12 +194,12 @@ void set_optimal_resolution() log("Using mode: (0x%x) %dx%dx%d", highest, vbe_width, vbe_height, vbe_bpl << 3); } -const uint32_t default_text_color = vesa_white; -const uint32_t default_background_color = vesa_black; -uint32_t terminal_color[3] = { 0xab, 0xb2, 0xbf }; -uint32_t terminal_background[3] = { 0x1d, 0x1f, 0x24 }; -uint16_t terminal_x = 0; -uint16_t terminal_y = 0; +const u32 default_text_color = vesa_white; +const u32 default_background_color = vesa_black; +u32 terminal_color[3] = { 0xab, 0xb2, 0xbf }; +u32 terminal_background[3] = { 0x1d, 0x1f, 0x24 }; +u16 terminal_x = 0; +u16 terminal_y = 0; int font_width; int font_height; @@ -215,16 +209,16 @@ void vesa_set_font(int height) font_height = height; } -void vesa_set_pixel(uint16_t x, uint16_t y, const uint32_t color[3]) +void vesa_set_pixel(u16 x, u16 y, const u32 color[3]) { - uint8_t pos = (uint8_t)(x * vbe_bpl + y * vbe_pitch); + u8 pos = (u8)(x * vbe_bpl + y * vbe_pitch); char *draw = (char *)&fb[pos]; draw[pos] = (char)color[2]; draw[pos + 1] = (char)color[1]; draw[pos + 2] = (char)color[0]; } -void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const uint32_t color[3]) +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) { int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; char *draw = (char *)&fb[pos1]; @@ -251,7 +245,7 @@ void vesa_draw_char(char ch) if (ch >= ' ') { int pos = terminal_x * vbe_bpl + terminal_y * vbe_pitch; char *draw = (char *)&fb[pos]; - uint16_t bitmap = 0; + u16 bitmap = 0; for (int cy = 0; cy <= font_height; cy++) { if (font_height == 16) diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index cdbd45a..c557e95 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -2,7 +2,7 @@ #define MELVIX_VESA_H #include <stdint.h> -#include <kernel/system.h> +#include <system.h> /** * The CPUs response to the 0x4F00 call @@ -10,15 +10,15 @@ */ struct vbe_info { char signature[4]; - uint16_t version; - uint32_t oem; - uint32_t capabilities; - uint32_t video_modes; - uint16_t video_memory; - uint16_t software_rev; - uint32_t vendor; - uint32_t product_name; - uint32_t product_rev; + u16 version; + u32 oem; + u32 capabilities; + u32 video_modes; + u16 video_memory; + u16 software_rev; + u32 vendor; + u32 product_name; + u32 product_rev; char reserved[222]; char oem_data[256]; } __attribute__((packed)); @@ -28,51 +28,51 @@ struct vbe_info { * Used to get information about a specific video mode code */ struct vbe_mode_info_all { - uint16_t attributes; - uint8_t window_a; - uint8_t window_b; - uint16_t granularity; - uint16_t window_size; - uint16_t segment_a; - uint16_t segment_b; - uint32_t win_func_ptr; - uint16_t pitch; - uint16_t width; - uint16_t height; - uint8_t w_char; - uint8_t y_char; - uint8_t planes; - uint8_t bpp; - uint8_t banks; - uint8_t memory_model; - uint8_t bank_size; - uint8_t image_pages; - uint8_t reserved0; - - uint8_t red_mask; - uint8_t red_position; - uint8_t green_mask; - uint8_t green_position; - uint8_t blue_mask; - uint8_t blue_position; - uint8_t reserved_mask; - uint8_t reserved_position; - uint8_t direct_color_attributes; - - uint32_t framebuffer; - uint32_t off_screen_mem_off; - uint16_t off_screen_mem_size; - uint8_t reserved1[206]; + u16 attributes; + u8 window_a; + u8 window_b; + u16 granularity; + u16 window_size; + u16 segment_a; + u16 segment_b; + u32 win_func_ptr; + u16 pitch; + u16 width; + u16 height; + u8 w_char; + u8 y_char; + u8 planes; + u8 bpp; + u8 banks; + u8 memory_model; + u8 bank_size; + u8 image_pages; + u8 reserved0; + + u8 red_mask; + u8 red_position; + u8 green_mask; + u8 green_position; + u8 blue_mask; + u8 blue_position; + u8 reserved_mask; + u8 reserved_position; + u8 direct_color_attributes; + + u32 framebuffer; + u32 off_screen_mem_off; + u16 off_screen_mem_size; + u8 reserved1[206]; } __attribute__((packed)); struct vbe_mode_info { - uint16_t attributes; - uint16_t pitch; - uint16_t width; - uint16_t height; - uint8_t bpp; - uint8_t memory_model; - uint32_t framebuffer; + u16 attributes; + u16 pitch; + u16 width; + u16 height; + u8 bpp; + u8 memory_model; + u32 framebuffer; } __attribute__((packed)); /** @@ -129,7 +129,7 @@ void vesa_draw_cursor(int x, int y); * Sets the color using a rgb number * @param color The color */ -void vesa_set_color(uint32_t color); +void vesa_set_color(u32 color); /** * An enum with vesa colors @@ -157,12 +157,12 @@ enum vesa_color { /** * The default text color */ -const uint32_t default_text_color; +const u32 default_text_color; /** * The current text color (as normalized array) */ -uint32_t terminal_color[3]; +u32 terminal_color[3]; /** * The current input @@ -197,8 +197,8 @@ int vbe_bpl; /** * The framebuffer interface */ -uint8_t *fb; +u8 *fb; -uint8_t *cursor_buffer; +u8 *cursor_buffer; #endif
\ No newline at end of file diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c index cc0e03d..dceba05 100644 --- a/src/kernel/input/ps2/keyboard.c +++ b/src/kernel/input/ps2/keyboard.c @@ -1,11 +1,11 @@ -#include <kernel/interrupts/interrupts.h> -#include <kernel/io/io.h> -#include <kernel/graphics/vesa.h> -#include <kernel/input/input.h> -#include <kernel/lib/string.h> -#include <kernel/memory/alloc.h> +#include <interrupts/interrupts.h> +#include <io/io.h> +#include <graphics/vesa.h> +#include <input/input.h> +#include <lib/string.h> +#include <memory/alloc.h> -uint8_t scancode; +u8 scancode; void keyboard_handler(struct regs *r) { diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c index bf3cbf6..c1e39ba 100644 --- a/src/kernel/input/ps2/mouse.c +++ b/src/kernel/input/ps2/mouse.c @@ -1,7 +1,7 @@ -#include <kernel/interrupts/interrupts.h> -#include <kernel/io/io.h> -#include <kernel/graphics/vesa.h> -#include <kernel/lib/stdio.h> +#include <interrupts/interrupts.h> +#include <io/io.h> +#include <graphics/vesa.h> +#include <lib/stdio.h> char mouse_cycle = 0; char mouse_byte[3]; diff --git a/src/kernel/interrupts/idt.c b/src/kernel/interrupts/idt.c index 4be3d7c..532435a 100644 --- a/src/kernel/interrupts/idt.c +++ b/src/kernel/interrupts/idt.c @@ -1,12 +1,12 @@ -#include <kernel/lib/lib.h> -#include <kernel/system.h> +#include <lib/lib.h> +#include <system.h> struct idt_entry { - uint16_t base_low; - uint16_t sel; // Kernel segment - uint8_t always0; // Always 0 - uint8_t flags; - uint16_t base_high; + u16 base_low; + u16 sel; // Kernel segment + u8 always0; // Always 0 + u8 flags; + u16 base_high; } __attribute__((packed)); struct idt_ptr { @@ -24,13 +24,13 @@ extern void idt_load(); void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) { // Specify the interrupt routine's base address - idt[num].base_low = (uint16_t)(base & 0xFFFF); - idt[num].base_high = (uint16_t)((base >> 16) & 0xFFFF); + idt[num].base_low = (u16)(base & 0xFFFF); + idt[num].base_high = (u16)((base >> 16) & 0xFFFF); // Set selector/segment of IDT entry idt[num].sel = sel; idt[num].always0 = 0; - idt[num].flags = (uint8_t)(flags | 0x60); + idt[num].flags = (u8)(flags | 0x60); } // Install IDT diff --git a/src/kernel/interrupts/interrupts.h b/src/kernel/interrupts/interrupts.h index 6651cfd..f7b5846 100644 --- a/src/kernel/interrupts/interrupts.h +++ b/src/kernel/interrupts/interrupts.h @@ -40,13 +40,13 @@ void isrs_install(); */ typedef void (*irq_handler_t)(struct regs *); -void isr_install_handler(size_t isr, irq_handler_t handler); +void isr_install_handler(u32 isr, irq_handler_t handler); /** * Uninstall a handler by index * @param irq The index of the IRQ routine that should be removed */ -void isr_uninstall_handler(size_t isr); +void isr_uninstall_handler(u32 isr); /** * Initialize the Interrupt Requests by mapping the ISRs to the correct diff --git a/src/kernel/interrupts/irq.c b/src/kernel/interrupts/irq.c index ad35346..4c34d15 100644 --- a/src/kernel/interrupts/irq.c +++ b/src/kernel/interrupts/irq.c @@ -1,6 +1,6 @@ -#include <kernel/io/io.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/system.h> +#include <io/io.h> +#include <interrupts/interrupts.h> +#include <system.h> extern void irq0(); diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c index 880c23a..54584b4 100644 --- a/src/kernel/interrupts/isr.c +++ b/src/kernel/interrupts/isr.c @@ -1,12 +1,12 @@ #include <stdint.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/system.h> -#include <kernel/lib/string.h> -#include <kernel/lib/stdio.h> -#include <kernel/lib/lib.h> -#include <kernel/graphics/vesa.h> -#include <kernel/tasks/process.h> -#include <kernel/io/io.h> +#include <interrupts/interrupts.h> +#include <system.h> +#include <lib/string.h> +#include <lib/stdio.h> +#include <lib/lib.h> +#include <graphics/vesa.h> +#include <tasks/process.h> +#include <io/io.h> // Install ISRs in IDT void isrs_install() @@ -55,13 +55,13 @@ void isrs_install() irq_handler_t isr_routines[256] = { 0 }; // Install custom IRQ handler -void isr_install_handler(size_t isr, irq_handler_t handler) +void isr_install_handler(u32 isr, irq_handler_t handler) { isr_routines[isr] = handler; } // Remove the custom IRQ handler -void isr_uninstall_handler(size_t isr) +void isr_uninstall_handler(u32 isr) { isr_routines[isr] = 0; } @@ -111,7 +111,7 @@ void fault_handler(struct regs *r) handler(r); } else { cli(); - uint32_t faulting_address; + u32 faulting_address; asm("mov %%cr2, %0" : "=r"(faulting_address)); log("\n[DEBUG]\nEIP: 0x%x\nEAX: 0x%x\nEBX: 0x%x\nECX: 0x%x\nEDX: 0x%x\nESP: 0x%x\nFault addr: 0x%x\nErr flag: 0x%x\nErr code: 0x%x\nINT code: 0x%x\nINT msg: %s", @@ -133,7 +133,7 @@ void fault_handler(struct regs *r) scheduler(r); sti(); } else { - if (faulting_address != (uint32_t)fb) { + if (faulting_address != (u32)fb) { panic("Page fault before multitasking started!"); } else { debug(RED "Fatal video error!" RES); diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c index fb95464..ad63c88 100644 --- a/src/kernel/io/io.c +++ b/src/kernel/io/io.c @@ -1,23 +1,23 @@ #include <stdint.h> -#include <kernel/system.h> +#include <system.h> -uint8_t inb(uint16_t port) +u8 inb(u16 port) { - uint8_t value; + u8 value; asm volatile("inb %1, %0" : "=a"(value) : "Nd"(port)); return value; } -uint16_t inw(uint16_t port) +u16 inw(u16 port) { - uint16_t value; + u16 value; asm volatile("inw %1, %0" : "=a"(value) : "Nd"(port)); return value; } -uint32_t inl(uint16_t port) +u32 inl(u16 port) { - uint32_t value; + u32 value; asm volatile("inl %1, %0" : "=a"(value) : "Nd"(port)); return value; } @@ -37,17 +37,17 @@ void hlt() asm volatile("hlt"); } -void outb(uint16_t port, uint8_t data) +void outb(u16 port, u8 data) { asm volatile("outb %0, %1" ::"a"(data), "Nd"(port)); } -void outw(uint16_t port, uint16_t data) +void outw(u16 port, u16 data) { asm volatile("outw %0, %1" ::"a"(data), "Nd"(port)); } -void outl(uint16_t port, uint32_t data) +void outl(u16 port, u32 data) { asm volatile("outl %0, %1" ::"a"(data), "Nd"(port)); } @@ -73,5 +73,5 @@ void serial_put(char ch) { while (is_transmit_empty() == 0) ; - outb(0x3f8, (uint8_t)ch); + outb(0x3f8, (u8)ch); }
\ No newline at end of file diff --git a/src/kernel/io/io.h b/src/kernel/io/io.h index 50e9c6f..8b3dd2f 100644 --- a/src/kernel/io/io.h +++ b/src/kernel/io/io.h @@ -8,21 +8,21 @@ * @param port The hardware port * @return The hardware response */ -uint8_t inb(uint16_t port); +u8 inb(u16 port); /** * Receive from specified hardware port * @param port The hardware port * @return The hardware response */ -uint16_t inw(uint16_t port); +u16 inw(u16 port); /** * Receive from specified hardware port * @param port The hardware port * @return The hardware response */ -uint32_t inl(uint16_t port); +u32 inl(u16 port); void cli(); void sti(); @@ -33,21 +33,21 @@ void hlt(); * @param port The hardware port * @param data The data that should be sent */ -void outb(uint16_t port, uint8_t data); +void outb(u16 port, u8 data); /** * Send data to the specified hardware port * @param port The hardware port * @param data The data that should be sent */ -void outw(uint16_t port, uint16_t data); +void outw(u16 port, u16 data); /** * Send data to the specified hardware port * @param port The hardware port * @param data The data that should be sent */ -void outl(uint16_t port, uint32_t data); +void outl(u16 port, u32 data); /** * Initialize the serial conenction diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index c940e55..1928d20 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,28 +1,28 @@ -#include <kernel/multiboot.h> -#include <kernel/graphics/vesa.h> -#include <kernel/gdt/gdt.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/io/io.h> -#include <kernel/timer/timer.h> -#include <kernel/memory/paging.h> -#include <kernel/input/input.h> -#include <kernel/acpi/acpi.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/stdlib.h> -#include <kernel/syscall/syscall.h> -#include <kernel/pci/pci.h> -#include <kernel/net/network.h> -#include <kernel/fs/load.h> -#include <kernel/fs/elf.h> -#include <kernel/lib/stdio.h> -#include <kernel/fs/ata.h> -#include <kernel/fs/ext2.h> -#include <kernel/cmos/rtc.h> -#include <kernel/memory/alloc.h> +#include <multiboot.h> +#include <graphics/vesa.h> +#include <gdt/gdt.h> +#include <interrupts/interrupts.h> +#include <io/io.h> +#include <timer/timer.h> +#include <memory/paging.h> +#include <input/input.h> +#include <acpi/acpi.h> +#include <lib/lib.h> +#include <lib/stdlib.h> +#include <syscall/syscall.h> +#include <pci/pci.h> +#include <net/network.h> +#include <fs/load.h> +#include <fs/elf.h> +#include <lib/stdio.h> +#include <fs/ata.h> +#include <fs/ext2.h> +#include <cmos/rtc.h> +#include <memory/alloc.h> -uint32_t stack_hold; +u32 stack_hold; -void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) +void kernel_main(u32 magic, u32 multiboot_address, u32 esp) { stack_hold = esp; diff --git a/src/kernel/lib/data.h b/src/kernel/lib/data.h index d0eaaf5..709ca6f 100644 --- a/src/kernel/lib/data.h +++ b/src/kernel/lib/data.h @@ -14,14 +14,14 @@ struct list_node { struct list { struct list_node *head; struct list_node *tail; - uint32_t size; + u32 size; }; #define foreach(t, list) for (struct list_node *t = list->head; t != NULL; t = t->next) struct list *list_create(); -uint32_t list_size(struct list *list); +u32 list_size(struct list *list); struct list_node *list_insert_front(struct list *list, void *val); @@ -55,7 +55,7 @@ struct list_node *list_get_node_by_index(struct list *list, int index); void *list_remove_by_index(struct list *list, int index); -struct list *str_split(const char *str, const char *delim, uint32_t *numtokens); +struct list *str_split(const char *str, const char *delim, u32 *numtokens); char *list_to_str(struct list *list, const char *delim); // Tree diff --git a/src/kernel/lib/data/list.c b/src/kernel/lib/data/list.c index 788b4ab..41f812f 100644 --- a/src/kernel/lib/data/list.c +++ b/src/kernel/lib/data/list.c @@ -1,9 +1,9 @@ #include <stdint.h> #include <stddef.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/stdlib.h> -#include <kernel/lib/data.h> -#include <kernel/memory/alloc.h> +#include <lib/lib.h> +#include <lib/stdlib.h> +#include <lib/data.h> +#include <memory/alloc.h> struct list *list_create() { @@ -11,7 +11,7 @@ struct list *list_create() return list; } -uint32_t list_size(struct list *list) +u32 list_size(struct list *list) { if (!list) return 0; @@ -182,7 +182,7 @@ void listnode_destroy(struct list_node *node) // Conversion -struct list *str_split(const char *str, const char *delim, uint32_t *numtokens) +struct list *str_split(const char *str, const char *delim, u32 *numtokens) { struct list *ret_list = list_create(); char *s = strdup(str); diff --git a/src/kernel/lib/data/tree.c b/src/kernel/lib/data/tree.c index 514e2cd..2726a11 100644 --- a/src/kernel/lib/data/tree.c +++ b/src/kernel/lib/data/tree.c @@ -1,6 +1,6 @@ #include <stdint.h> -#include <kernel/lib/data.h> -#include <kernel/memory/alloc.h> +#include <lib/data.h> +#include <memory/alloc.h> struct tree *tree_create() { diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index b08904f..4308af4 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -3,7 +3,7 @@ #include <stddef.h> #include <stdint.h> -#include <kernel/multiboot.h> +#include <multiboot.h> /** * Copy n data from src to dest @@ -12,7 +12,7 @@ * @param count The number of bytes to be copied (src) * @return The modified dest pointer */ -void *memcpy(void *dest, const void *src, size_t count); +void *memcpy(void *dest, const void *src, u32 count); /** * Replace n bytes of dest by val @@ -21,7 +21,7 @@ void *memcpy(void *dest, const void *src, size_t count); * @param count The number of times val should replace dest entry * @return The modified dest pointer */ -void *memset(void *dest, char val, size_t count); +void *memset(void *dest, char val, u32 count); /** * Compare the first n bytes of a and b @@ -30,7 +30,7 @@ void *memset(void *dest, char val, size_t count); * @param size The number of bytes to be compared * @return -1 if a < b, 0 if a = b and 1 if a > b */ -int memcmp(const void *a_ptr, const void *b_ptr, size_t size); +int memcmp(const void *a_ptr, const void *b_ptr, u32 size); void memory_info_init(struct multiboot_tag_basic_meminfo *tag); @@ -38,6 +38,6 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag); void memory_print(); -uint32_t memory_get_all(); +u32 memory_get_all(); #endif
\ No newline at end of file diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index bda3c1b..d990e6b 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -1,11 +1,11 @@ #include <stddef.h> #include <stdint.h> -#include <kernel/system.h> -#include <kernel/lib/stdio.h> -#include <kernel/memory/paging.h> -#include <kernel/multiboot.h> +#include <system.h> +#include <lib/stdio.h> +#include <memory/paging.h> +#include <multiboot.h> -void *memcpy(void *dest, const void *src, size_t count) +void *memcpy(void *dest, const void *src, u32 count) { const char *sp = (const char *)src; char *dp = (char *)dest; @@ -14,7 +14,7 @@ void *memcpy(void *dest, const void *src, size_t count) return dest; } -void *memset(void *dest, char val, size_t count) +void *memset(void *dest, char val, u32 count) { char *temp = (char *)dest; for (; count != 0; count--) @@ -22,11 +22,11 @@ void *memset(void *dest, char val, size_t count) return dest; } -int memcmp(const void *a_ptr, const void *b_ptr, size_t size) +int memcmp(const void *a_ptr, const void *b_ptr, u32 size) { const unsigned char *a = (const unsigned char *)a_ptr; const unsigned char *b = (const unsigned char *)b_ptr; - for (size_t i = 0; i < size; i++) { + for (u32 i = 0; i < size; i++) { if (a[i] < b[i]) return -1; else if (b[i] < a[i]) @@ -35,10 +35,10 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size) return 0; } -uint32_t total = 0; +u32 total = 0; struct multiboot_tag_basic_meminfo *meminfo = NULL; -uint32_t memory_get_all() +u32 memory_get_all() { if (total != 0) { return total; @@ -50,7 +50,7 @@ uint32_t memory_get_all() } } -uint32_t memory_get_free() +u32 memory_get_free() { return memory_get_all() /*- paging_get_used_pages() * 4*/; } @@ -73,12 +73,12 @@ void memory_info_init(struct multiboot_tag_basic_meminfo *tag) void memory_mmap_init(struct multiboot_tag_mmap *tag) { - uint32_t sum = 0; + u32 sum = 0; struct multiboot_mmap_entry *mmap; for (mmap = ((struct multiboot_tag_mmap *)tag)->entries; - (multiboot_uint8_t *)mmap < (multiboot_uint8_t *)tag + tag->size; - mmap = (multiboot_memory_map_t *)((uint32_t)mmap + + (multiboot_u8 *)mmap < (multiboot_u8 *)tag + tag->size; + mmap = (multiboot_memory_map_t *)((u32)mmap + ((struct multiboot_tag_mmap *)tag)->entry_size)) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { debug("Found free memory"); diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c index 0942d49..a96d73a 100644 --- a/src/kernel/lib/stdio/debug.c +++ b/src/kernel/lib/stdio/debug.c @@ -1,19 +1,19 @@ #include <stdarg.h> #include <stdint.h> -#include <kernel/lib/string.h> -#include <kernel/lib/stdlib.h> -#include <kernel/io/io.h> -#include <kernel/memory/alloc.h> +#include <lib/string.h> +#include <lib/stdlib.h> +#include <io/io.h> +#include <memory/alloc.h> void serial_print(const char *data) { - for (size_t i = 0; i < strlen(data); i++) + for (u32 i = 0; i < strlen(data); i++) serial_put(data[i]); } void serial_vprintf(const char *fmt, va_list args) { - uint8_t readyToFormat = 0; + u8 readyToFormat = 0; char buff = 0; @@ -31,7 +31,7 @@ void serial_vprintf(const char *fmt, va_list args) serial_print(str); readyToFormat = 0; } else if (buff == 'x') { - char *p = htoa((uint32_t)va_arg(args, int)); + char *p = htoa((u32)va_arg(args, int)); serial_print(p); kfree(p); readyToFormat = 0; diff --git a/src/kernel/lib/stdio/printf.c b/src/kernel/lib/stdio/printf.c index 5c3eb8e..cc65463 100644 --- a/src/kernel/lib/stdio/printf.c +++ b/src/kernel/lib/stdio/printf.c @@ -1,5 +1,5 @@ #include <stdarg.h> -#include <kernel/lib/stdio.h> +#include <lib/stdio.h> void printf(const char *fmt, ...) { diff --git a/src/kernel/lib/stdio/putch.c b/src/kernel/lib/stdio/putch.c index f7e0248..2689ac7 100644 --- a/src/kernel/lib/stdio/putch.c +++ b/src/kernel/lib/stdio/putch.c @@ -1,4 +1,4 @@ -#include <kernel/graphics/vesa.h> +#include <graphics/vesa.h> void putch(char c) { diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c index 2431a48..15d210a 100644 --- a/src/kernel/lib/stdio/vprintf.c +++ b/src/kernel/lib/stdio/vprintf.c @@ -1,19 +1,19 @@ #include <stdarg.h> #include <stdint.h> -#include <kernel/lib/stdio.h> -#include <kernel/lib/string.h> -#include <kernel/lib/stdlib.h> -#include <kernel/memory/alloc.h> +#include <lib/stdio.h> +#include <lib/string.h> +#include <lib/stdlib.h> +#include <memory/alloc.h> void _puts(const char *data) { - for (size_t i = 0; i < strlen(data); i++) + for (u32 i = 0; i < strlen(data); i++) putch(data[i]); } void vprintf(const char *fmt, va_list args) { - uint8_t readyToFormat = 0; + u8 readyToFormat = 0; char buff = 0; @@ -31,7 +31,7 @@ void vprintf(const char *fmt, va_list args) _puts(str); readyToFormat = 0; } else if (buff == 'x') { - char *p = htoa((uint32_t)va_arg(args, int)); + char *p = htoa((u32)va_arg(args, int)); _puts(p); kfree(p); readyToFormat = 0; diff --git a/src/kernel/lib/stdlib.h b/src/kernel/lib/stdlib.h index 18d933d..62bd51c 100644 --- a/src/kernel/lib/stdlib.h +++ b/src/kernel/lib/stdlib.h @@ -5,7 +5,7 @@ #ifndef MELVIX_STRING_H -#include <kernel/lib/string.h> +#include <lib/string.h> #endif @@ -13,7 +13,7 @@ char *itoa(int n); int atoi(char *str); -char *htoa(uint32_t n); +char *htoa(u32 n); int htoi(char *str); diff --git a/src/kernel/lib/stdlib/atoi.c b/src/kernel/lib/stdlib/atoi.c index 2d58d84..cd855ab 100644 --- a/src/kernel/lib/stdlib/atoi.c +++ b/src/kernel/lib/stdlib/atoi.c @@ -1,19 +1,19 @@ -#include <kernel/lib/math.h> +#include <lib/math.h> #include <stddef.h> #include <stdint.h> -#include <kernel/lib/string.h> +#include <lib/string.h> int atoi(char *str) { - size_t s_str = strlen(str); + u32 s_str = strlen(str); if (!s_str) return 0; - uint8_t negative = 0; + u8 negative = 0; if (str[0] == '-') negative = 1; - size_t i = 0; + u32 i = 0; if (negative) i++; diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c index ee639ec..7a535dd 100644 --- a/src/kernel/lib/stdlib/htoa.c +++ b/src/kernel/lib/stdlib/htoa.c @@ -1,10 +1,10 @@ #include <stdint.h> -#include <kernel/lib/string.h> -#include <kernel/memory/alloc.h> +#include <lib/string.h> +#include <memory/alloc.h> static const char HTOA_TABLE[] = "0123456789ABCDEF"; -char *htoa(uint32_t n) +char *htoa(u32 n) { char *ret = (char *)kmalloc(10); diff --git a/src/kernel/lib/stdlib/htoi.c b/src/kernel/lib/stdlib/htoi.c index dcc4b63..7d05239 100644 --- a/src/kernel/lib/stdlib/htoi.c +++ b/src/kernel/lib/stdlib/htoi.c @@ -1,12 +1,12 @@ -#include <kernel/lib/math.h> +#include <lib/math.h> #include <stddef.h> -#include <kernel/lib/string.h> +#include <lib/string.h> int htoi(char *str) { - size_t s_str = strlen(str); + u32 s_str = strlen(str); - size_t i = 0; + u32 i = 0; int ret = 0; for (; i < s_str; i++) { char c = str[i]; diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c index 5bb3359..165e260 100644 --- a/src/kernel/lib/stdlib/itoa.c +++ b/src/kernel/lib/stdlib/itoa.c @@ -1,8 +1,8 @@ -#include <kernel/lib/math.h> +#include <lib/math.h> #include <stdint.h> -#include <kernel/lib/string.h> -#include <kernel/memory/alloc.h> -#include <kernel/memory/paging.h> +#include <lib/string.h> +#include <memory/alloc.h> +#include <memory/paging.h> static const char ITOA_TABLE[] = "0123456789"; @@ -14,7 +14,7 @@ char *itoa(int n) ret[1] = 0; return ret; } - uint8_t negative = (uint8_t)(n < 0); + u8 negative = (u8)(n < 0); if (negative) n *= -1; @@ -22,7 +22,7 @@ char *itoa(int n) for (sz = 0; n % pow(10, sz) != n; sz++) { } - char *ret = (char *)kmalloc((uint32_t)(sz + 1)); + char *ret = (char *)kmalloc((u32)(sz + 1)); for (int i = 0; i < sz; i++) { int digit = (n % pow(10, i + 1)) / pow(10, i); @@ -31,7 +31,7 @@ char *itoa(int n) ret[sz] = 0; if (negative) { - char *aux = (char *)kmalloc((uint32_t)(sz + 2)); + char *aux = (char *)kmalloc((u32)(sz + 2)); strcpy(aux, ret); aux[sz] = '-'; aux[sz + 1] = 0; diff --git a/src/kernel/lib/string.h b/src/kernel/lib/string.h index 3a8dc07..bd412d7 100644 --- a/src/kernel/lib/string.h +++ b/src/kernel/lib/string.h @@ -1,9 +1,10 @@ #ifndef MELVIX_STRING_H #define MELVIX_STRING_H +#include <stdint.h> #include <stddef.h> -size_t strlen(const char *str); +u32 strlen(const char *str); void strcpy(char *dest, const char *orig); diff --git a/src/kernel/lib/string/strcat.c b/src/kernel/lib/string/strcat.c index 4328f87..3ae8ea0 100644 --- a/src/kernel/lib/string/strcat.c +++ b/src/kernel/lib/string/strcat.c @@ -1,11 +1,11 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> void strcat(char *dest, const char *orig) { - size_t s_dest = strlen(dest); - size_t s_orig = strlen(orig); + u32 s_dest = strlen(dest); + u32 s_orig = strlen(orig); - for (size_t i = 0; i < s_orig; i++) + for (u32 i = 0; i < s_orig; i++) dest[s_dest + i] = orig[i]; dest[s_dest + s_orig] = 0; }
\ No newline at end of file diff --git a/src/kernel/lib/string/strcati.c b/src/kernel/lib/string/strcati.c index 5dab283..2fda46c 100644 --- a/src/kernel/lib/string/strcati.c +++ b/src/kernel/lib/string/strcati.c @@ -1,9 +1,9 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> void strcati(char *dest, const char *orig) { - size_t s_orig = strlen(orig); + u32 s_orig = strlen(orig); strdisp(dest, (int)s_orig); - for (size_t i = 0; i < s_orig; i++) + for (u32 i = 0; i < s_orig; i++) dest[i] = orig[i]; }
\ No newline at end of file diff --git a/src/kernel/lib/string/strcmp.c b/src/kernel/lib/string/strcmp.c index 89f77a0..7a273ac 100644 --- a/src/kernel/lib/string/strcmp.c +++ b/src/kernel/lib/string/strcmp.c @@ -1,11 +1,11 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> char strcmp(const char *a, const char *b) { if (strlen(a) != strlen(b)) return 1; - for (size_t i = 0; i < strlen(a); i++) + for (u32 i = 0; i < strlen(a); i++) if (a[i] != b[i]) return 1; diff --git a/src/kernel/lib/string/strcpy.c b/src/kernel/lib/string/strcpy.c index 6117e7c..5d7f194 100644 --- a/src/kernel/lib/string/strcpy.c +++ b/src/kernel/lib/string/strcpy.c @@ -1,10 +1,10 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> void strcpy(char *dest, const char *orig) { - size_t s_orig = strlen(orig); + u32 s_orig = strlen(orig); - for (size_t i = 0; i < s_orig; i++) + for (u32 i = 0; i < s_orig; i++) dest[i] = orig[i]; dest[s_orig] = 0; }
\ No newline at end of file diff --git a/src/kernel/lib/string/strdisp.c b/src/kernel/lib/string/strdisp.c index e63f038..dada5d0 100644 --- a/src/kernel/lib/string/strdisp.c +++ b/src/kernel/lib/string/strdisp.c @@ -1,8 +1,8 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> void strdisponce(char *str) { - for (size_t i = sizeof(str) + 2; i > 0; i--) + for (u32 i = sizeof(str) + 2; i > 0; i--) str[i] = str[i - 1]; str[0] = 0; } diff --git a/src/kernel/lib/string/strdup.c b/src/kernel/lib/string/strdup.c index 82d14ef..00bb863 100644 --- a/src/kernel/lib/string/strdup.c +++ b/src/kernel/lib/string/strdup.c @@ -1,9 +1,9 @@ -#include <kernel/lib/string.h> -#include <kernel/memory/alloc.h> +#include <lib/string.h> +#include <memory/alloc.h> char *strdup(const char *orig) { - size_t s_orig = strlen(orig); + u32 s_orig = strlen(orig); char *ret = (char *)kmalloc(s_orig + 1); strcpy(ret, orig); return ret; diff --git a/src/kernel/lib/string/strinv.c b/src/kernel/lib/string/strinv.c index 071a99d..90cb581 100644 --- a/src/kernel/lib/string/strinv.c +++ b/src/kernel/lib/string/strinv.c @@ -1,8 +1,8 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> void strinv(char *str) { - size_t s_str = strlen(str); + u32 s_str = strlen(str); int iterations = (int)s_str / 2; for (int i = 0; i < iterations; i++) { diff --git a/src/kernel/lib/string/strlen.c b/src/kernel/lib/string/strlen.c index 9e7e448..520ab92 100644 --- a/src/kernel/lib/string/strlen.c +++ b/src/kernel/lib/string/strlen.c @@ -1,8 +1,8 @@ -#include <kernel/lib/string.h> +#include <lib/string.h> -size_t strlen(const char *str) +u32 strlen(const char *str) { - size_t len = 0; + u32 len = 0; while (str[len]) len++; return len; diff --git a/src/kernel/lib/string/strstr.c b/src/kernel/lib/string/strstr.c index d58b4d5..bcf1539 100644 --- a/src/kernel/lib/string/strstr.c +++ b/src/kernel/lib/string/strstr.c @@ -1,10 +1,10 @@ #include <stdint.h> -#include <kernel/lib/stdlib.h> +#include <lib/stdlib.h> char *strstr(const char *in, const char *str) { char c; - uint32_t len; + u32 len; c = *str++; if (!c) diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index 825c639..da03d8c 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -1,12 +1,12 @@ #include <stddef.h> #include <stdint.h> -#include <kernel/memory/paging.h> -#include <kernel/memory/alloc.h> -#include <kernel/system.h> -#include <kernel/lib/lib.h> +#include <memory/paging.h> +#include <memory/alloc.h> +#include <system.h> +#include <lib/lib.h> -extern uint32_t end; -uint32_t placement_address; +extern u32 end; +u32 placement_address; struct heap_header *kheap = NULL; struct heap_header *uheap = NULL; @@ -21,37 +21,36 @@ void kheap_init() // Make user heap uheap = (struct heap_header *)kmalloc_a(UHEAP_SIZE); init_heap(uheap, UHEAP_SIZE); - paging_map_user(paging_root_directory, (uint32_t)&uheap, (uint32_t)&uheap); + paging_map_user(paging_root_directory, (u32)&uheap, (u32)&uheap); } -void *fmalloc(uint32_t size) +void *fmalloc(u32 size) { assert(placement_address + size < MEM_END); - uint32_t hold = placement_address; + u32 hold = placement_address; memset((void *)hold, 0, size); placement_address += size; return (void *)hold; } -void *kmalloc_a(uint32_t size) +void *kmalloc_a(u32 size) { assert(((placement_address & 0xFFFFF000) + 0x1000) + size < MEM_END); placement_address &= 0xFFFFF000; placement_address += 0x1000; - uint32_t hold = placement_address; + u32 hold = placement_address; placement_address += size; return (void *)hold; } -struct heap_header *find_sized_heap(struct heap_header *heap, size_t size) +struct heap_header *find_sized_heap(struct heap_header *heap, u32 size) { while ((heap->size < HEAP_FIND_SIZE + size) || (heap->free != true)) { assert(heap->magic == KHEAP_MAGIC); assert(heap->magic2 == KHEAP_MAGIC2); - struct heap_footer *foot = - (struct heap_footer *)((uint32_t)heap + HEAP_S + heap->size); + struct heap_footer *foot = (struct heap_footer *)((u32)heap + HEAP_S + heap->size); assert(foot->magic == KHEAP_MAGIC); assert(foot->magic2 == KHEAP_MAGIC2); @@ -61,29 +60,29 @@ struct heap_header *find_sized_heap(struct heap_header *heap, size_t size) if (foot->size != heap->size) panic("Heap footer/header mismatch"); - heap = (struct heap_header *)((uint32_t)foot + sizeof(struct heap_footer)); + heap = (struct heap_header *)((u32)foot + sizeof(struct heap_footer)); } return heap; } -void split_heap(struct heap_header *heap, size_t size) +void split_heap(struct heap_header *heap, u32 size) { - struct heap_footer *foot = (struct heap_footer *)((uint32_t)heap + HEAP_S + size); + struct heap_footer *foot = (struct heap_footer *)((u32)heap + HEAP_S + size); foot->magic = KHEAP_MAGIC; foot->magic2 = KHEAP_MAGIC2; foot->size = size; - size_t new_size = heap->size - HEAP_TOTAL - size; + u32 new_size = heap->size - HEAP_TOTAL - size; heap->size = size; - heap = (struct heap_header *)((uint32_t)foot + sizeof(struct heap_footer)); + heap = (struct heap_header *)((u32)foot + sizeof(struct heap_footer)); heap->size = new_size; heap->free = true; heap->magic = KHEAP_MAGIC; heap->magic2 = KHEAP_MAGIC2; - foot = (struct heap_footer *)((uint32_t)heap + HEAP_S + heap->size); + foot = (struct heap_footer *)((u32)heap + HEAP_S + heap->size); if ((foot->magic != KHEAP_MAGIC) || (foot->magic2 != KHEAP_MAGIC2)) { warn("Invalid footer in split"); } @@ -94,7 +93,7 @@ void split_heap(struct heap_header *heap, size_t size) void free_internal(struct heap_header *heap, void *address) { - struct heap_header *head = (struct heap_header *)((uint32_t)address - HEAP_S); + struct heap_header *head = (struct heap_header *)((u32)address - HEAP_S); if (head == heap) { //warn("Can't collapse top of heap"); // TODO: Fix "can't collapse top of heap" at start head->free = true; @@ -106,11 +105,11 @@ void free_internal(struct heap_header *heap, void *address) return; } - struct heap_footer *foot = (struct heap_footer *)((uint32_t)head + HEAP_S + head->size); + struct heap_footer *foot = (struct heap_footer *)((u32)head + HEAP_S + head->size); if ((foot->magic != KHEAP_MAGIC) || (foot->magic2 != KHEAP_MAGIC2)) panic("Bad heap call"); - foot = (struct heap_footer *)((uint32_t)head - sizeof(struct heap_footer)); + foot = (struct heap_footer *)((u32)head - sizeof(struct heap_footer)); if ((foot->magic != KHEAP_MAGIC) || (foot->magic2 != KHEAP_MAGIC2)) { warn("Invalid footer in heap"); return; @@ -119,14 +118,13 @@ void free_internal(struct heap_header *heap, void *address) if (foot->size == KHEAP_END) panic("Impossible condition for heap"); - heap = (struct heap_header *)((uint32_t)foot - foot->size - HEAP_S); + heap = (struct heap_header *)((u32)foot - foot->size - HEAP_S); if ((heap->magic != KHEAP_MAGIC) || (heap->magic2 != KHEAP_MAGIC2)) { warn("Invalid parent in heap"); return; } - foot = (struct heap_footer *)((uint32_t)heap + (heap->size + head->size + HEAP_TOTAL) + - HEAP_S); + foot = (struct heap_footer *)((u32)heap + (heap->size + head->size + HEAP_TOTAL) + HEAP_S); if ((foot->magic != KHEAP_MAGIC) || (foot->magic2 != KHEAP_MAGIC2)) { panic("Fatal arithmetic error in free() call"); return; @@ -136,28 +134,28 @@ void free_internal(struct heap_header *heap, void *address) foot->size = heap->size; } -void *malloc_internal(struct heap_header *heap, size_t size) +void *malloc_internal(struct heap_header *heap, u32 size) { heap = find_sized_heap(heap, size + 8); heap->free = false; split_heap(heap, size); - return (void *)((uint32_t)heap + HEAP_S); + return (void *)((u32)heap + HEAP_S); } -void init_heap(struct heap_header *heap, size_t size) +void init_heap(struct heap_header *heap, u32 size) { heap->magic = KHEAP_MAGIC; heap->magic2 = KHEAP_MAGIC2; heap->free = true; heap->size = size - HEAP_TOTAL; - struct heap_footer *foot = (struct heap_footer *)((uint32_t)heap + HEAP_S + heap->size); + struct heap_footer *foot = (struct heap_footer *)((u32)heap + HEAP_S + heap->size); foot->magic = KHEAP_MAGIC; foot->magic2 = KHEAP_MAGIC2; foot->size = KHEAP_END; } -void *kmalloc(uint32_t size) +void *kmalloc(u32 size) { if (kheap == NULL) return fmalloc(size); @@ -165,7 +163,7 @@ void *kmalloc(uint32_t size) return malloc_internal(kheap, size); } -void *kcalloc(uint32_t num, uint32_t size) +void *kcalloc(u32 num, u32 size) { void *ptr = kmalloc(num * size); memset(ptr, 0, num * size); @@ -180,12 +178,12 @@ void kfree(void *address) free_internal(kheap, address); } -void *umalloc(size_t size) +void *umalloc(u32 size) { return malloc_internal(uheap, size); } -void *ucalloc(uint32_t num, uint32_t size) +void *ucalloc(u32 num, u32 size) { void *ptr = umalloc(num * size); memset(ptr, 0, num * size); diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h index 6739eeb..5e51195 100644 --- a/src/kernel/memory/alloc.h +++ b/src/kernel/memory/alloc.h @@ -1,8 +1,8 @@ #ifndef MELVIX_ALLOC_H #define MELVIX_ALLOC_H -#include <stddef.h> #include <stdint.h> +#include <stddef.h> #include <stdbool.h> #define KHEAP_MAGIC 0x04206969 @@ -11,31 +11,31 @@ #define MEM_END 0x8000000 struct heap_header { - uint32_t magic; + u32 magic; bool free; - uint32_t size; - uint32_t magic2; + u32 size; + u32 magic2; }; struct heap_footer { - uint32_t magic; - uint32_t size; - uint32_t magic2; + u32 magic; + u32 size; + u32 magic2; }; void kheap_init(); -void *fmalloc(uint32_t size); -void *kcalloc(uint32_t num, uint32_t size); -void *kmalloc(uint32_t size); -void *kmalloc_a(uint32_t size); +void *fmalloc(u32 size); +void *kcalloc(u32 num, u32 size); +void *kmalloc(u32 size); +void *kmalloc_a(u32 size); void kfree(void *ptr); -void *umalloc(size_t size); -void *ucalloc(uint32_t num, uint32_t size); +void *umalloc(u32 size); +void *ucalloc(u32 num, u32 size); void ufree(void *address); -void init_heap(struct heap_header *heap, size_t size); +void init_heap(struct heap_header *heap, u32 size); #define KHEAP_SIZE 0xFFFFF #define UHEAP_SIZE 0xFFFFF diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 67c471f..7a98563 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -1,44 +1,44 @@ #include <stdint.h> -#include <kernel/memory/paging.h> -#include <kernel/memory/alloc.h> -#include <kernel/system.h> -#include <kernel/lib/lib.h> -#include <kernel/io/io.h> -#include <kernel/acpi/acpi.h> -#include <kernel/tasks/process.h> -#include <kernel/interrupts/interrupts.h> +#include <memory/paging.h> +#include <memory/alloc.h> +#include <system.h> +#include <lib/lib.h> +#include <io/io.h> +#include <acpi/acpi.h> +#include <tasks/process.h> +#include <interrupts/interrupts.h> struct page_directory *paging_current_directory = NULL; struct page_directory *paging_root_directory = NULL; -/* void paging_install(uint32_t multiboot_address) */ +/* void paging_install(u32 multiboot_address) */ /* { */ /* if (!memory_init(multiboot_address)) */ /* paging_set_present(0, memory_get_all() >> 3); // /4 */ -/* paging_set_used(0, ((uint32_t)ASM_KERNEL_END >> 12) + 1); // /4096 */ +/* paging_set_used(0, ((u32)ASM_KERNEL_END >> 12) + 1); // /4096 */ /* } */ struct page_table *get_cr3() { - uint32_t cr3; + u32 cr3; asm volatile("movl %%cr3, %%eax" : "=a"(cr3)); return (struct page_table *)cr3; } -uint32_t get_cr0() +u32 get_cr0() { - uint32_t cr0; + u32 cr0; asm volatile("movl %%cr0, %%eax" : "=a"(cr0)); return cr0; } void set_cr3(struct page_directory *dir) { - uint32_t addr = (uint32_t)&dir->tables[0]; + u32 addr = (u32)&dir->tables[0]; asm volatile("movl %%eax, %%cr3" ::"a"(addr)); } -void set_cr0(uint32_t cr0) +void set_cr0(u32 cr0) { asm volatile("movl %%eax, %%cr0" ::"a"(cr0)); } @@ -83,12 +83,12 @@ struct page_table *paging_make_table() return tab; } -void paging_map(struct page_directory *dir, uint32_t phys, uint32_t virt) +void paging_map(struct page_directory *dir, u32 phys, u32 virt) { short id = virt >> 22; struct page_table *tab = paging_make_table(); - dir->tables[id] = ((struct page_table *)((uint32_t)tab | 3)); // RW + dir->tables[id] = ((struct page_table *)((u32)tab | 3)); // RW for (int i = 0; i < 1024; i++) { tab->pages[i].frame = phys >> 12; @@ -97,12 +97,12 @@ void paging_map(struct page_directory *dir, uint32_t phys, uint32_t virt) } } -void paging_map_user(struct page_directory *dir, uint32_t phys, uint32_t virt) +void paging_map_user(struct page_directory *dir, u32 phys, u32 virt) { short id = virt >> 22; struct page_table *tab = paging_make_table(); - dir->tables[id] = ((struct page_table *)((uint32_t)tab | 3 | 4)); // RW + usermode + dir->tables[id] = ((struct page_table *)((u32)tab | 3 | 4)); // RW + usermode for (int i = 0; i < 1024; i++) { tab->pages[i].frame = phys >> 12; @@ -113,11 +113,11 @@ void paging_map_user(struct page_directory *dir, uint32_t phys, uint32_t virt) } // Hmm -uint32_t paging_get_phys(uint32_t virt) +u32 paging_get_phys(u32 virt) { - uint32_t pdi = virt >> 22; - uint32_t pti = (virt >> 12) & 0x03FF; - return (*(uint32_t *)&paging_current_directory->tables[pdi]->pages[pti]) & 0xFFFFF000; + u32 pdi = virt >> 22; + u32 pti = (virt >> 12) & 0x03FF; + return (*(u32 *)&paging_current_directory->tables[pdi]->pages[pti]) & 0xFFFFF000; } void paging_install() @@ -127,17 +127,17 @@ void paging_install() paging_current_directory = paging_make_directory(); paging_root_directory = paging_current_directory; - for (uint32_t i = 0; i < 0xF0000000; i += PAGE_S) + for (u32 i = 0; i < 0xF0000000; i += PAGE_S) paging_map(paging_root_directory, i, i); paging_switch_directory(paging_root_directory); info("Installed paging"); // Test mallocing - uintptr_t a = (uintptr_t)kmalloc(4096); - uintptr_t b = (uintptr_t)kmalloc(4096); + u32 a = (u32)kmalloc(4096); + u32 b = (u32)kmalloc(4096); kfree((void *)b); kfree((void *)a); - uintptr_t c = (uintptr_t)kmalloc(2048); + u32 c = (u32)kmalloc(2048); assert(a == c); info("kmalloc test succeeded!"); } @@ -145,9 +145,9 @@ void paging_install() void paging_convert_page(struct page_directory *kdir) { for (int i = 0; i < 1024; i++) { - kdir->tables[i] = (struct page_table *)((uint32_t)kdir->tables[i] | 4); // Usermode + kdir->tables[i] = (struct page_table *)((u32)kdir->tables[i] | 4); // Usermode - if (((uint32_t)kdir->tables[i]) & 1) { // Is present + if (((u32)kdir->tables[i]) & 1) { // Is present for (int j = 0; j < 1024; j++) kdir->tables[i]->pages[j].user = 1; // Usermode } @@ -159,14 +159,14 @@ struct page_directory *paging_copy_user_directory(struct page_directory *dir) struct page_directory *copy = paging_make_directory(); memcpy(copy, paging_root_directory, sizeof(struct page_directory)); - for (uint32_t i = 0; i < 1024; i++) { - if (((uint32_t)dir->tables[i]) & 4) { + for (u32 i = 0; i < 1024; i++) { + if (((u32)dir->tables[i]) & 4) { struct page_table *tab = - (struct page_table *)((uint32_t)dir->tables[i] & 0xFFFFF000); + (struct page_table *)((u32)dir->tables[i] & 0xFFFFF000); void *buffer = kmalloc_a(PAGE_S); memcpy(buffer, (void *)(tab->pages[0].frame << 12), PAGE_S); - paging_map_user(copy, (uint32_t)buffer, (uint32_t)i << 22); + paging_map_user(copy, (u32)buffer, (u32)i << 22); } } diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h index a2ea396..a9aef92 100644 --- a/src/kernel/memory/paging.h +++ b/src/kernel/memory/paging.h @@ -4,13 +4,13 @@ #include <stdint.h> struct page { - uint32_t present : 1; - uint32_t rw : 1; - uint32_t user : 1; - uint32_t accessed : 1; - uint32_t dirty : 1; - uint32_t unused : 7; - uint32_t frame : 20; + u32 present : 1; + u32 rw : 1; + u32 user : 1; + u32 accessed : 1; + u32 dirty : 1; + u32 unused : 7; + u32 frame : 20; }; struct page_table { @@ -24,10 +24,10 @@ struct page_directory { struct page_directory *paging_root_directory; struct page_table *get_cr3(); -uint32_t get_cr0(); +u32 get_cr0(); void set_cr3(struct page_directory *dir); -void set_cr0(uint32_t new_cr0); +void set_cr0(u32 new_cr0); void paging_disable(); void paging_enable(); @@ -36,11 +36,11 @@ void paging_switch_directory(struct page_directory *dir); struct page_directory *paging_make_directory(); struct page_table *paging_make_table(); -uint32_t paging_get_phys(uint32_t virt); +u32 paging_get_phys(u32 virt); void paging_install(); -void paging_map(struct page_directory *cr3, uint32_t virt, uint32_t phys); -void paging_map_user(struct page_directory *cr3, uint32_t virt, uint32_t phys); +void paging_map(struct page_directory *cr3, u32 virt, u32 phys); +void paging_map_user(struct page_directory *cr3, u32 virt, u32 phys); void paging_convert_page(struct page_directory *kdir); diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c index a39c661..04db300 100644 --- a/src/kernel/multiboot.c +++ b/src/kernel/multiboot.c @@ -1,19 +1,19 @@ #include <stdint.h> -#include <kernel/graphics/vesa.h> -#include <kernel/system.h> -#include <kernel/multiboot.h> -#include <kernel/smbios/smbios.h> -#include <kernel/acpi/acpi.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/stdio.h> +#include <graphics/vesa.h> +#include <system.h> +#include <multiboot.h> +#include <smbios/smbios.h> +#include <acpi/acpi.h> +#include <lib/lib.h> +#include <lib/stdio.h> -void multiboot_parse(uint32_t multiboot_address) +void multiboot_parse(u32 multiboot_address) { struct multiboot_tag *tag; for (tag = (struct multiboot_tag *)(multiboot_address + 8); tag->type != MULTIBOOT_TAG_TYPE_END; - tag = (struct multiboot_tag *)((multiboot_uint8_t *)tag + ((tag->size + 7) & ~7))) { + tag = (struct multiboot_tag *)((multiboot_u8 *)tag + ((tag->size + 7) & ~7))) { switch (tag->type) { case MULTIBOOT_TAG_TYPE_CMDLINE: // TODO: Add cmdline config support diff --git a/src/kernel/multiboot.h b/src/kernel/multiboot.h index b82b457..19ca504 100644 --- a/src/kernel/multiboot.h +++ b/src/kernel/multiboot.h @@ -88,183 +88,183 @@ #ifndef ASM_FILE -typedef unsigned char multiboot_uint8_t; -typedef unsigned short multiboot_uint16_t; -typedef unsigned int multiboot_uint32_t; -typedef unsigned long long multiboot_uint64_t; +typedef unsigned char multiboot_u8; +typedef unsigned short multiboot_u16; +typedef unsigned int multiboot_u32; +typedef unsigned long long multiboot_u64; struct multiboot_header { /* Must be MULTIBOOT_MAGIC - see above. */ - multiboot_uint32_t magic; + multiboot_u32 magic; /* ISA */ - multiboot_uint32_t architecture; + multiboot_u32 architecture; /* Total header length. */ - multiboot_uint32_t header_length; + multiboot_u32 header_length; /* The above fields plus this one must equal 0 mod 2^32. */ - multiboot_uint32_t checksum; + multiboot_u32 checksum; }; struct multiboot_header_tag { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; }; struct multiboot_header_tag_information_request { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t requests[0]; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 requests[0]; }; struct multiboot_header_tag_address { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t header_addr; - multiboot_uint32_t load_addr; - multiboot_uint32_t load_end_addr; - multiboot_uint32_t bss_end_addr; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 header_addr; + multiboot_u32 load_addr; + multiboot_u32 load_end_addr; + multiboot_u32 bss_end_addr; }; struct multiboot_header_tag_entry_address { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t entry_addr; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 entry_addr; }; struct multiboot_header_tag_console_flags { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t console_flags; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 console_flags; }; struct multiboot_header_tag_framebuffer { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t width; - multiboot_uint32_t height; - multiboot_uint32_t depth; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 width; + multiboot_u32 height; + multiboot_u32 depth; }; struct multiboot_header_tag_module_align { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; }; struct multiboot_header_tag_relocatable { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t min_addr; - multiboot_uint32_t max_addr; - multiboot_uint32_t align; - multiboot_uint32_t preference; + multiboot_u16 type; + multiboot_u16 flags; + multiboot_u32 size; + multiboot_u32 min_addr; + multiboot_u32 max_addr; + multiboot_u32 align; + multiboot_u32 preference; }; struct multiboot_color { - multiboot_uint8_t red; - multiboot_uint8_t green; - multiboot_uint8_t blue; + multiboot_u8 red; + multiboot_u8 green; + multiboot_u8 blue; }; struct multiboot_mmap_entry { - multiboot_uint64_t addr; - multiboot_uint64_t len; + multiboot_u64 addr; + multiboot_u64 len; #define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_BADRAM 5 - multiboot_uint32_t type; - multiboot_uint32_t zero; + multiboot_u32 type; + multiboot_u32 zero; }; typedef struct multiboot_mmap_entry multiboot_memory_map_t; struct multiboot_tag { - multiboot_uint32_t type; - multiboot_uint32_t size; + multiboot_u32 type; + multiboot_u32 size; }; struct multiboot_tag_string { - multiboot_uint32_t type; - multiboot_uint32_t size; + multiboot_u32 type; + multiboot_u32 size; char string[0]; }; struct multiboot_tag_module { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t mod_start; - multiboot_uint32_t mod_end; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 mod_start; + multiboot_u32 mod_end; char cmdline[0]; }; struct multiboot_tag_basic_meminfo { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t mem_lower; - multiboot_uint32_t mem_upper; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 mem_lower; + multiboot_u32 mem_upper; }; struct multiboot_tag_bootdev { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t biosdev; - multiboot_uint32_t slice; - multiboot_uint32_t part; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 biosdev; + multiboot_u32 slice; + multiboot_u32 part; }; struct multiboot_tag_mmap { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t entry_size; - multiboot_uint32_t entry_version; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 entry_size; + multiboot_u32 entry_version; struct multiboot_mmap_entry entries[0]; }; struct multiboot_vbe_info_block { - multiboot_uint8_t external_specification[512]; + multiboot_u8 external_specification[512]; }; struct multiboot_vbe_mode_info_block { - multiboot_uint8_t external_specification[256]; + multiboot_u8 external_specification[256]; }; struct multiboot_tag_vbe { - multiboot_uint32_t type; - multiboot_uint32_t size; + multiboot_u32 type; + multiboot_u32 size; - multiboot_uint16_t vbe_mode; - multiboot_uint16_t vbe_interface_seg; - multiboot_uint16_t vbe_interface_off; - multiboot_uint16_t vbe_interface_len; + multiboot_u16 vbe_mode; + multiboot_u16 vbe_interface_seg; + multiboot_u16 vbe_interface_off; + multiboot_u16 vbe_interface_len; struct multiboot_vbe_info_block vbe_control_info; struct multiboot_vbe_mode_info_block vbe_mode_info; }; struct multiboot_tag_framebuffer_common { - multiboot_uint32_t type; - multiboot_uint32_t size; - - multiboot_uint64_t framebuffer_addr; - multiboot_uint32_t framebuffer_pitch; - multiboot_uint32_t framebuffer_width; - multiboot_uint32_t framebuffer_height; - multiboot_uint8_t framebuffer_bpp; + multiboot_u32 type; + multiboot_u32 size; + + multiboot_u64 framebuffer_addr; + multiboot_u32 framebuffer_pitch; + multiboot_u32 framebuffer_width; + multiboot_u32 framebuffer_height; + multiboot_u8 framebuffer_bpp; #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 - multiboot_uint8_t framebuffer_type; - multiboot_uint16_t reserved; + multiboot_u8 framebuffer_type; + multiboot_u16 reserved; }; struct multiboot_tag_framebuffer { @@ -272,106 +272,106 @@ struct multiboot_tag_framebuffer { union { struct { - multiboot_uint16_t framebuffer_palette_num_colors; + multiboot_u16 framebuffer_palette_num_colors; struct multiboot_color framebuffer_palette[0]; }; struct { - multiboot_uint8_t framebuffer_red_field_position; - multiboot_uint8_t framebuffer_red_mask_size; - multiboot_uint8_t framebuffer_green_field_position; - multiboot_uint8_t framebuffer_green_mask_size; - multiboot_uint8_t framebuffer_blue_field_position; - multiboot_uint8_t framebuffer_blue_mask_size; + multiboot_u8 framebuffer_red_field_position; + multiboot_u8 framebuffer_red_mask_size; + multiboot_u8 framebuffer_green_field_position; + multiboot_u8 framebuffer_green_mask_size; + multiboot_u8 framebuffer_blue_field_position; + multiboot_u8 framebuffer_blue_mask_size; }; }; }; struct multiboot_tag_elf_sections { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t num; - multiboot_uint32_t entsize; - multiboot_uint32_t shndx; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 num; + multiboot_u32 entsize; + multiboot_u32 shndx; char sections[0]; }; struct multiboot_tag_apm { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint16_t version; - multiboot_uint16_t cseg; - multiboot_uint32_t offset; - multiboot_uint16_t cseg_16; - multiboot_uint16_t dseg; - multiboot_uint16_t flags; - multiboot_uint16_t cseg_len; - multiboot_uint16_t cseg_16_len; - multiboot_uint16_t dseg_len; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u16 version; + multiboot_u16 cseg; + multiboot_u32 offset; + multiboot_u16 cseg_16; + multiboot_u16 dseg; + multiboot_u16 flags; + multiboot_u16 cseg_len; + multiboot_u16 cseg_16_len; + multiboot_u16 dseg_len; }; -struct multiboot_tag_efi32 { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t pointer; +struct multiboot_tag_efs32 { + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 pointer; }; struct multiboot_tag_efi64 { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t pointer; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u64 pointer; }; struct multiboot_tag_smbios { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t major; - multiboot_uint8_t minor; - multiboot_uint8_t reserved[6]; - multiboot_uint8_t tables[0]; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u8 major; + multiboot_u8 minor; + multiboot_u8 reserved[6]; + multiboot_u8 tables[0]; }; struct multiboot_tag_old_acpi { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u8 rsdp[0]; }; struct multiboot_tag_new_acpi { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u8 rsdp[0]; }; struct multiboot_tag_network { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t dhcpack[0]; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u8 dhcpack[0]; }; struct multiboot_tag_efi_mmap { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t descr_size; - multiboot_uint32_t descr_vers; - multiboot_uint8_t efi_mmap[0]; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 descr_size; + multiboot_u32 descr_vers; + multiboot_u8 efi_mmap[0]; }; -struct multiboot_tag_efi32_ih { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t pointer; +struct multiboot_tag_efs32_ih { + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 pointer; }; struct multiboot_tag_efi64_ih { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t pointer; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u64 pointer; }; struct multiboot_tag_load_base_addr { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t load_base_addr; + multiboot_u32 type; + multiboot_u32 size; + multiboot_u32 load_base_addr; }; void multiboot_parse(); diff --git a/src/kernel/net/rtl8139.c b/src/kernel/net/rtl8139.c index a934e52..08efc0e 100644 --- a/src/kernel/net/rtl8139.c +++ b/src/kernel/net/rtl8139.c @@ -1,33 +1,33 @@ -#include <kernel/io/io.h> -#include <kernel/pci/pci.h> -#include <kernel/system.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/lib/stdio.h> -#include <kernel/memory/alloc.h> +#include <io/io.h> +#include <pci/pci.h> +#include <system.h> +#include <interrupts/interrupts.h> +#include <lib/stdio.h> +#include <memory/alloc.h> int rtl_irq = 0; -uint8_t mac[6]; -uint8_t *rtl_rx_buffer; -uint32_t rtl_iobase = 0; -uint32_t rtl_device_pci = 0x00000000; +u8 mac[6]; +u8 *rtl_rx_buffer; +u32 rtl_iobase = 0; +u32 rtl_device_pci = 0x00000000; -void find_rtl(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra) +void find_rtl(u32 device, u16 vendor_id, u16 device_id, void *extra) { if ((vendor_id == 0x10ec) && (device_id == 0x8139)) { - *((uint32_t *)extra) = device; + *((u32 *)extra) = device; } } void rtl8139_irq_handler(struct regs *r) { log("RTL INT!"); - uint16_t status = inw((uint16_t)(rtl_iobase + 0x3E)); + u16 status = inw((u16)(rtl_iobase + 0x3E)); if (!status) return; - outw((uint16_t)(rtl_iobase + 0x3E), status); + outw((u16)(rtl_iobase + 0x3E), status); if (status & 0x01 || status & 0x02) { - while ((inw((uint16_t)(rtl_iobase + 0x37)) & 0x01) == 0) { + while ((inw((u16)(rtl_iobase + 0x37)) & 0x01) == 0) { log("RECEIVE"); // RECEIVE } @@ -37,7 +37,7 @@ void rtl8139_irq_handler(struct regs *r) int rtl8139_init(void) { if (rtl_device_pci) { - uint16_t command_reg = (uint16_t)pci_read_field(rtl_device_pci, PCI_COMMAND, 4); + u16 command_reg = (u16)pci_read_field(rtl_device_pci, PCI_COMMAND, 4); if (command_reg & (1 << 2)) { } else { @@ -48,8 +48,8 @@ int rtl8139_init(void) rtl_irq = pci_get_interrupt(rtl_device_pci); irq_install_handler(rtl_irq, rtl8139_irq_handler); - uint32_t rtl_bar0 = pci_read_field(rtl_device_pci, PCI_BAR0, 4); - // uint32_t rtl_bar1 = pci_read_field(rtl_device_pci, PCI_BAR1, 4); + u32 rtl_bar0 = pci_read_field(rtl_device_pci, PCI_BAR0, 4); + // u32 rtl_bar1 = pci_read_field(rtl_device_pci, PCI_BAR1, 4); rtl_iobase = 0x00000000; @@ -60,30 +60,30 @@ int rtl8139_init(void) // Get mac address for (int i = 0; i < 6; ++i) - mac[i] = inb((uint16_t)(rtl_iobase + 0x00 + i)); + mac[i] = inb((u16)(rtl_iobase + 0x00 + i)); debug("Mac address: %2x:%2x:%2x:%2x:%2x:%2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); // Activate (turn on) - outb((uint16_t)(rtl_iobase + 0x52), 0x0); + outb((u16)(rtl_iobase + 0x52), 0x0); // Reset - outb((uint16_t)(rtl_iobase + 0x37), 0x10); - while ((inb((uint16_t)(rtl_iobase + 0x37)) & 0x10) != 0) { + outb((u16)(rtl_iobase + 0x37), 0x10); + while ((inb((u16)(rtl_iobase + 0x37)) & 0x10) != 0) { } // Set receive buffer - rtl_rx_buffer = (uint8_t *)kmalloc(8192 + 16); - outl((uint16_t)(rtl_iobase + 0x30), (uintptr_t)rtl_rx_buffer); + rtl_rx_buffer = (u8 *)kmalloc(8192 + 16); + outl((u16)(rtl_iobase + 0x30), (u32)rtl_rx_buffer); // Enable ISR - outw((uint16_t)(rtl_iobase + 0x3C), 0x0005); + outw((u16)(rtl_iobase + 0x3C), 0x0005); // Accept packets - outl((uint16_t)(rtl_iobase + 0x44), 0xf | (1 << 7)); + outl((u16)(rtl_iobase + 0x44), 0xf | (1 << 7)); // Enable receive and transmitter - outb((uint16_t)(rtl_iobase + 0x37), 0x0C); + outb((u16)(rtl_iobase + 0x37), 0x0C); } else { return -1; } diff --git a/src/kernel/pci/pci.c b/src/kernel/pci/pci.c index 6e660b7..14881b1 100644 --- a/src/kernel/pci/pci.c +++ b/src/kernel/pci/pci.c @@ -1,49 +1,49 @@ #include <stdint.h> -#include <kernel/system.h> -#include <kernel/pci/pci.h> -#include <kernel/io/io.h> -#include <kernel/lib/lib.h> +#include <system.h> +#include <pci/pci.h> +#include <io/io.h> +#include <lib/lib.h> -void pci_write_field(uint32_t device, int field, uint32_t value) +void pci_write_field(u32 device, int field, u32 value) { outl(PCI_ADDRESS_PORT, pci_get_addr(device, field)); outl(PCI_VALUE_PORT, value); } -uint32_t pci_read_field(uint32_t device, int field, int size) +u32 pci_read_field(u32 device, int field, int size) { outl(PCI_ADDRESS_PORT, pci_get_addr(device, field)); if (size == 4) { - uint32_t t = inl(PCI_VALUE_PORT); + u32 t = inl(PCI_VALUE_PORT); return t; } else if (size == 2) { - uint16_t t = inw((uint16_t)(PCI_VALUE_PORT + (field & 2))); + u16 t = inw((u16)(PCI_VALUE_PORT + (field & 2))); return t; } else if (size == 1) { - uint8_t t = inb((uint16_t)(PCI_VALUE_PORT + (field & 3))); + u8 t = inb((u16)(PCI_VALUE_PORT + (field & 3))); return t; } return 0xFFFF; } -uint16_t pci_find_type(uint32_t dev) +u16 pci_find_type(u32 dev) { - return (uint16_t)((pci_read_field(dev, PCI_CLASS, 1) << 8) | - pci_read_field(dev, PCI_SUBCLASS, 1)); + return (u16)((pci_read_field(dev, PCI_CLASS, 1) << 8) | + pci_read_field(dev, PCI_SUBCLASS, 1)); } -void pci_scan_hit(pci_func_t f, uint32_t dev, void *extra) +void pci_scan_hit(pci_func_t f, u32 dev, void *extra) { int dev_vend = (int)pci_read_field(dev, PCI_VENDOR_ID, 2); int dev_dvid = (int)pci_read_field(dev, PCI_DEVICE_ID, 2); - f(dev, (uint16_t)dev_vend, (uint16_t)dev_dvid, extra); + f(dev, (u16)dev_vend, (u16)dev_dvid, extra); } void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void *extra) { - uint32_t dev = pci_box_device(bus, slot, func); + u32 dev = pci_box_device(bus, slot, func); if (type == -1 || type == pci_find_type(dev)) pci_scan_hit(f, dev, extra); if (pci_find_type(dev) == PCI_TYPE_BRIDGE) @@ -52,7 +52,7 @@ void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void *ex void pci_scan_slot(pci_func_t f, int type, int bus, int slot, void *extra) { - uint32_t dev = pci_box_device(bus, slot, 0); + u32 dev = pci_box_device(bus, slot, 0); if (pci_read_field(dev, PCI_VENDOR_ID, 2) == PCI_NONE) return; pci_scan_func(f, type, bus, slot, 0, extra); @@ -79,7 +79,7 @@ void pci_scan(pci_func_t f, int type, void *extra) } for (int func = 0; func < 8; ++func) { - uint32_t dev = pci_box_device(0, 0, func); + u32 dev = pci_box_device(0, 0, func); if (pci_read_field(dev, PCI_VENDOR_ID, 2) != PCI_NONE) pci_scan_bus(f, type, func, extra); else @@ -87,35 +87,35 @@ void pci_scan(pci_func_t f, int type, void *extra) } } -static void find_isa_bridge(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra) +static void find_isa_bridge(u32 device, u16 vendor_id, u16 device_id, void *extra) { if (vendor_id == 0x8086 && (device_id == 0x7000 || device_id == 0x7110)) - *((uint32_t *)extra) = device; + *((u32 *)extra) = device; } -static uint32_t pci_isa = 0; -static uint8_t pci_remaps[4] = { 0 }; +static u32 pci_isa = 0; +static u8 pci_remaps[4] = { 0 }; void pci_remap() { pci_scan(&find_isa_bridge, -1, &pci_isa); if (pci_isa) { for (int i = 0; i < 4; ++i) { - pci_remaps[i] = (uint8_t)pci_read_field(pci_isa, 0x60 + i, 1); + pci_remaps[i] = (u8)pci_read_field(pci_isa, 0x60 + i, 1); if (pci_remaps[i] == 0x80) { - pci_remaps[i] = (uint8_t)(10 + (i % 1)); + pci_remaps[i] = (u8)(10 + (i % 1)); } } - uint32_t out = 0; + u32 out = 0; memcpy(&out, &pci_remaps, 4); pci_write_field(pci_isa, 0x60, out); } } -int pci_get_interrupt(uint32_t device) +int pci_get_interrupt(u32 device) { if (pci_isa) { - uint32_t irq_pin = pci_read_field(device, 0x3D, 1); + u32 irq_pin = pci_read_field(device, 0x3D, 1); if (irq_pin == 0) return (int)pci_read_field(device, PCI_INTERRUPT_LINE, 1); int pirq = (int)(irq_pin + pci_extract_slot(device) - 2) % 4; @@ -124,10 +124,10 @@ int pci_get_interrupt(uint32_t device) if (pci_remaps[pirq] >= 0x80) { if (int_line == 0xFF) { int_line = 10; - pci_write_field(device, PCI_INTERRUPT_LINE, (uint32_t)int_line); + pci_write_field(device, PCI_INTERRUPT_LINE, (u32)int_line); } - pci_remaps[pirq] = (uint8_t)int_line; - uint32_t out = 0; + pci_remaps[pirq] = (u8)int_line; + u32 out = 0; memcpy(&out, &pci_remaps, 4); pci_write_field(pci_isa, 0x60, out); return int_line; diff --git a/src/kernel/pci/pci.h b/src/kernel/pci/pci.h index e358076..369f2d2 100644 --- a/src/kernel/pci/pci.h +++ b/src/kernel/pci/pci.h @@ -39,59 +39,59 @@ #define PCI_NONE 0xFFFF -typedef void (*pci_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra); +typedef void (*pci_func_t)(u32 device, u16 vendor_id, u16 device_id, void *extra); struct pci_device_descriptor { - uint32_t port_base; - uint32_t interrupt; + u32 port_base; + u32 interrupt; - uint8_t bus; - uint8_t slot; - uint8_t function; + u8 bus; + u8 slot; + u8 function; - uint16_t vendor_id; - uint16_t device_id; + u16 vendor_id; + u16 device_id; - uint8_t class_id; - uint8_t subclass_id; - uint8_t interface_id; + u8 class_id; + u8 subclass_id; + u8 interface_id; - uint8_t revision; + u8 revision; }; -static inline int pci_extract_bus(uint32_t device) +static inline int pci_extract_bus(u32 device) { - return (uint8_t)((device >> 16)); + return (u8)((device >> 16)); } -static inline int pci_extract_slot(uint32_t device) +static inline int pci_extract_slot(u32 device) { - return (uint8_t)((device >> 8)); + return (u8)((device >> 8)); } -static inline int pci_extract_func(uint32_t device) +static inline int pci_extract_func(u32 device) { - return (uint8_t)(device); + return (u8)(device); } -static inline uint32_t pci_get_addr(uint32_t device, int field) +static inline u32 pci_get_addr(u32 device, int field) { return 0x80000000 | (pci_extract_bus(device) << 16) | (pci_extract_slot(device) << 11) | (pci_extract_func(device) << 8) | ((field)&0xFC); } -static inline uint32_t pci_box_device(int bus, int slot, int func) +static inline u32 pci_box_device(int bus, int slot, int func) { - return (uint32_t)((bus << 16) | (slot << 8) | func); + return (u32)((bus << 16) | (slot << 8) | func); } -uint32_t pci_read_field(uint32_t device, int field, int size); +u32 pci_read_field(u32 device, int field, int size); -void pci_write_field(uint32_t device, int field, uint32_t value); +void pci_write_field(u32 device, int field, u32 value); -uint16_t pci_find_type(uint32_t dev); +u16 pci_find_type(u32 dev); -void pci_scan_hit(pci_func_t f, uint32_t dev, void *extra); +void pci_scan_hit(pci_func_t f, u32 dev, void *extra); void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void *extra); @@ -103,6 +103,6 @@ void pci_scan(pci_func_t f, int type, void *extra); void pci_remap(); -int pci_get_interrupt(uint32_t device); +int pci_get_interrupt(u32 device); #endif
\ No newline at end of file diff --git a/src/kernel/smbios/smbios.c b/src/kernel/smbios/smbios.c index b99f83b..7b275eb 100644 --- a/src/kernel/smbios/smbios.c +++ b/src/kernel/smbios/smbios.c @@ -1,7 +1,7 @@ #include <stddef.h> -#include <kernel/multiboot.h> -#include <kernel/system.h> -#include <kernel/smbios/smbios.h> +#include <multiboot.h> +#include <system.h> +#include <smbios/smbios.h> void smbios_init(struct multiboot_tag_smbios *tag) { diff --git a/src/kernel/smbios/smbios.h b/src/kernel/smbios/smbios.h index c6ce0d5..0df4b6d 100644 --- a/src/kernel/smbios/smbios.h +++ b/src/kernel/smbios/smbios.h @@ -2,15 +2,15 @@ #define MELVIX_SMBIOS_H #include <stdint.h> -#include <kernel/multiboot.h> +#include <multiboot.h> struct smbios_0 { char *vendor; char *bios_version; - uint16_t bios_start; + u16 bios_start; char *bios_release_data; - uint8_t bios_size; - uint64_t bios_characteristics; + u8 bios_size; + u64 bios_characteristics; }; struct smbios_1 { @@ -18,8 +18,8 @@ struct smbios_1 { char *product_name; char *version; char *serial_number; - uint8_t uuid[16]; - uint8_t wakeup_type; + u8 uuid[16]; + u8 wakeup_type; }; void smbios_init(struct multiboot_tag_smbios *tag); diff --git a/src/kernel/sound/frequency.c b/src/kernel/sound/frequency.c index 772df10..c485955 100644 --- a/src/kernel/sound/frequency.c +++ b/src/kernel/sound/frequency.c @@ -1,32 +1,32 @@ #include <stdint.h> -#include <kernel/io/io.h> -#include <kernel/timer/timer.h> +#include <io/io.h> +#include <timer/timer.h> -void play_sound(uint32_t frequency) +void play_sound(u32 frequency) { - uint32_t divided; - uint8_t tmp; + u32 divided; + u8 tmp; divided = 1193180 / frequency; outb(0x43, 0xb6); - outb(0x42, (uint8_t)(divided)); - outb(0x42, (uint8_t)(divided >> 8)); + outb(0x42, (u8)(divided)); + outb(0x42, (u8)(divided >> 8)); tmp = inb(0x61); if (tmp != (tmp | 3)) { - outb(0x61, (uint8_t)(tmp | 3)); + outb(0x61, (u8)(tmp | 3)); } } static void shut_up() { - uint8_t tmp = (uint8_t)(inb(0x61) & 0xFC); + u8 tmp = (u8)(inb(0x61) & 0xFC); outb(0x61, tmp); } // Make a beep -void beep(uint32_t frequency, uint32_t ticks) +void beep(u32 frequency, u32 ticks) { play_sound(frequency); timer_wait((int)ticks); diff --git a/src/kernel/sound/sound.h b/src/kernel/sound/sound.h index 44ec6f5..001ef92 100644 --- a/src/kernel/sound/sound.h +++ b/src/kernel/sound/sound.h @@ -8,6 +8,6 @@ * @param frequency The frequency of the beep * @param ticks The duration in ticks */ -void beep(uint32_t frequency, uint32_t ticks); +void beep(u32 frequency, u32 ticks); #endif
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_exec.c b/src/kernel/syscall/actions/sys_exec.c index 000d185..049d085 100644 --- a/src/kernel/syscall/actions/sys_exec.c +++ b/src/kernel/syscall/actions/sys_exec.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/tasks/process.h> +#include <tasks/process.h> -uint32_t sys_exec(char *path) +u32 sys_exec(char *path) { return uexec(path); }
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_exit.c b/src/kernel/syscall/actions/sys_exit.c index e2761fd..98e0c34 100644 --- a/src/kernel/syscall/actions/sys_exit.c +++ b/src/kernel/syscall/actions/sys_exit.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/tasks/process.h> +#include <tasks/process.h> -uint32_t sys_exit(uint32_t code) +u32 sys_exit(u32 code) { current_proc->state = PROC_ASLEEP; return code; diff --git a/src/kernel/syscall/actions/sys_fork.c b/src/kernel/syscall/actions/sys_fork.c index 5e2ee80..f0a5711 100644 --- a/src/kernel/syscall/actions/sys_fork.c +++ b/src/kernel/syscall/actions/sys_fork.c @@ -1,11 +1,11 @@ #include <stdint.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/memory/paging.h> -#include <kernel/tasks/process.h> -#include <kernel/lib/lib.h> -#include <kernel/system.h> +#include <interrupts/interrupts.h> +#include <memory/paging.h> +#include <tasks/process.h> +#include <lib/lib.h> +#include <system.h> -uint32_t sys_fork(struct regs *r) +u32 sys_fork(struct regs *r) { struct page_directory *dir = paging_copy_user_directory(current_proc->cr3); struct process *proc = process_make_new(); diff --git a/src/kernel/syscall/actions/sys_free.c b/src/kernel/syscall/actions/sys_free.c index 480cd53..a7daf2f 100644 --- a/src/kernel/syscall/actions/sys_free.c +++ b/src/kernel/syscall/actions/sys_free.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/memory/alloc.h> +#include <memory/alloc.h> -uint32_t sys_free(uint32_t ptr) +u32 sys_free(u32 ptr) { ufree((void *)ptr); return 0; diff --git a/src/kernel/syscall/actions/sys_get_pid.c b/src/kernel/syscall/actions/sys_get_pid.c index 7631230..1184ce7 100644 --- a/src/kernel/syscall/actions/sys_get_pid.c +++ b/src/kernel/syscall/actions/sys_get_pid.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/tasks/process.h> +#include <tasks/process.h> -uint32_t sys_get_pid() +u32 sys_get_pid() { return current_proc->pid; }
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_malloc.c b/src/kernel/syscall/actions/sys_malloc.c index 8adc362..da21a2d 100644 --- a/src/kernel/syscall/actions/sys_malloc.c +++ b/src/kernel/syscall/actions/sys_malloc.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/memory/alloc.h> +#include <memory/alloc.h> -uint32_t sys_malloc(uint32_t count) +u32 sys_malloc(u32 count) { - return (uint32_t)umalloc(count); + return (u32)umalloc(count); }
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c index 492e5fd..8b16064 100644 --- a/src/kernel/syscall/actions/sys_read.c +++ b/src/kernel/syscall/actions/sys_read.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/fs/fs.h> +#include <fs/fs.h> -uint32_t sys_read(char *path, uint32_t offset, uint32_t count, uint8_t *buf) +u32 sys_read(char *path, u32 offset, u32 count, u8 *buf) { return read(path, offset, count, buf); }
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c index b9b30f3..4d4275a 100644 --- a/src/kernel/syscall/actions/sys_write.c +++ b/src/kernel/syscall/actions/sys_write.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/fs/fs.h> +#include <fs/fs.h> -uint32_t sys_write(char *path, uint32_t offset, uint32_t count, uint8_t *buf) +u32 sys_write(char *path, u32 offset, u32 count, u8 *buf) { return write(path, offset, count, buf); }
\ No newline at end of file diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index 53f94cd..92c0dbe 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -1,22 +1,23 @@ #include <stdint.h> -#include <kernel/syscall/syscall.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/system.h> -#include <kernel/lib/stdio.h> -#include <kernel/io/io.h> -#include <kernel/tasks/process.h> - -typedef uint32_t (*syscall_func)(uint32_t, ...); - -uint32_t (*syscalls[])() = { [0] = (uint32_t(*)())halt_loop, // DEBUG! - [1] = sys_exit, - [2] = sys_fork, - [3] = sys_read, - [4] = sys_write, - [5] = sys_exec, - [6] = sys_get_pid, - [7] = sys_malloc, - [8] = sys_free }; +#include <common.h> +#include <syscall/syscall.h> +#include <interrupts/interrupts.h> +#include <system.h> +#include <lib/stdio.h> +#include <io/io.h> +#include <tasks/process.h> + +typedef u32 (*syscall_func)(u32, ...); + +u32 (*syscalls[])() = { [SYS_HALT] = (u32(*)())halt_loop, // DEBUG! + [SYS_EXIT] = sys_exit, + [SYS_FORK] = sys_fork, + [SYS_READ] = sys_read, + [SYS_WRITE] = sys_write, + [SYS_EXEC] = sys_exec, + [SYS_GET_PID] = sys_get_pid, + [SYS_MALLOC] = sys_malloc, + [SYS_FREE] = sys_free }; void syscall_handler(struct regs *r) { diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h index 9af18e8..7261afc 100644 --- a/src/kernel/syscall/syscall.h +++ b/src/kernel/syscall/syscall.h @@ -2,26 +2,26 @@ #define MELVIX_SYSCALL_H #include <stdint.h> -#include <kernel/interrupts/interrupts.h> +#include <interrupts/interrupts.h> extern void idt_syscall(); void syscalls_install(); -uint32_t sys_exit(uint32_t code); +u32 sys_exit(u32 code); -uint32_t sys_fork(struct regs *r); +u32 sys_fork(struct regs *r); -uint32_t sys_read(char *path, uint32_t offset, uint32_t count, uint8_t *buf); +u32 sys_read(char *path, u32 offset, u32 count, u8 *buf); -uint32_t sys_write(char *path, uint32_t offset, uint32_t count, uint8_t *buf); +u32 sys_write(char *path, u32 offset, u32 count, u8 *buf); -uint32_t sys_exec(char *path); +u32 sys_exec(char *path); -uint32_t sys_get_pid(); +u32 sys_get_pid(); -uint32_t sys_malloc(uint32_t count); +u32 sys_malloc(u32 count); -uint32_t sys_free(uint32_t ptr); +u32 sys_free(u32 ptr); #endif
\ No newline at end of file diff --git a/src/kernel/system.c b/src/kernel/system.c index 103522f..6d326da 100644 --- a/src/kernel/system.c +++ b/src/kernel/system.c @@ -1,10 +1,10 @@ -#include <kernel/timer/timer.h> -#include <kernel/io/io.h> -#include <kernel/graphics/vesa.h> -#include <kernel/lib/string.h> -#include <kernel/lib/stdlib.h> -#include <kernel/memory/paging.h> -#include <kernel/lib/stdio.h> +#include <timer/timer.h> +#include <io/io.h> +#include <graphics/vesa.h> +#include <lib/string.h> +#include <lib/stdlib.h> +#include <memory/paging.h> +#include <lib/stdio.h> #include <stdarg.h> void _debug(const char *f, const char *fmt, ...) @@ -87,7 +87,7 @@ loop: goto loop; } -void v86(uint8_t code, regs16_t *regs) +void v86(u8 code, regs16_t *regs) { paging_disable(); int32(code, regs); diff --git a/src/kernel/system.h b/src/kernel/system.h index 2e4786d..4c2673d 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -3,7 +3,7 @@ #include <stdint.h> #include <stddef.h> -#include <kernel/multiboot.h> +#include <multiboot.h> /** * The ASM registers as packed structure @@ -72,7 +72,7 @@ void halt_loop(); * @param code The interrupt code * @param regs The registers */ -void v86(uint8_t code, regs16_t *regs); +void v86(u8 code, regs16_t *regs); // Colors #define RED "\x1B[31m" diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index 87a6ec9..efacc1f 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -1,22 +1,22 @@ #include <stdint.h> #include <stddef.h> -#include <kernel/tasks/process.h> -#include <kernel/tasks/userspace.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/system.h> -#include <kernel/lib/lib.h> -#include <kernel/memory/paging.h> -#include <kernel/memory/alloc.h> -#include <kernel/timer/timer.h> -#include <kernel/fs/elf.h> - -uint32_t pid = 0; +#include <tasks/process.h> +#include <tasks/userspace.h> +#include <interrupts/interrupts.h> +#include <system.h> +#include <lib/lib.h> +#include <memory/paging.h> +#include <memory/alloc.h> +#include <timer/timer.h> +#include <fs/elf.h> + +u32 pid = 0; struct process *root; struct process *current_proc = NULL; struct regs hold_root; -extern uint32_t stack_hold; +extern u32 stack_hold; void scheduler(struct regs *regs) { @@ -54,7 +54,7 @@ void process_init(struct process *proc) userspace_enter(proc); } -void process_kill(uint32_t pid) +void process_kill(u32 pid) { struct process *proc = process_from_pid(pid); @@ -71,7 +71,7 @@ void process_kill(uint32_t pid) } } -uint32_t process_spawn(struct process *process) +u32 process_spawn(struct process *process) { process->next = root->next; root->next = process; @@ -84,7 +84,7 @@ uint32_t process_spawn(struct process *process) return process->pid; } -int process_wait_gid(uint32_t gid, int *status) +int process_wait_gid(u32 gid, int *status) { struct process *i = root; @@ -101,7 +101,7 @@ int process_wait_gid(uint32_t gid, int *status) return WAIT_OKAY; } -int process_wait_pid(uint32_t pid, int *status) +int process_wait_pid(u32 pid, int *status) { struct process *i = current_proc->next; @@ -120,7 +120,7 @@ int process_wait_pid(uint32_t pid, int *status) return WAIT_ERROR; } -void process_suspend(uint32_t pid) +void process_suspend(u32 pid) { struct process *proc = process_from_pid(pid); @@ -132,7 +132,7 @@ void process_suspend(uint32_t pid) proc->state = PROC_ASLEEP; } -void process_wake(uint32_t pid) +void process_wake(u32 pid) { struct process *proc = process_from_pid(pid); @@ -142,7 +142,7 @@ void process_wake(uint32_t pid) proc->state = PROC_RUNNING; } -uint32_t process_child(struct process *child, uint32_t pid) +u32 process_child(struct process *child, u32 pid) { process_suspend(pid); @@ -157,7 +157,7 @@ uint32_t process_child(struct process *child, uint32_t pid) return process_spawn(child); } -uint32_t process_fork(uint32_t pid) +u32 process_fork(u32 pid) { warn("Fork is not implemented"); @@ -173,7 +173,7 @@ uint32_t process_fork(uint32_t pid) return 0; //pid++; } -struct process *process_from_pid(uint32_t pid) +struct process *process_from_pid(u32 pid) { struct process *proc = root; @@ -205,7 +205,7 @@ struct process *process_make_new() return proc; } -uint32_t kexec(char *path) +u32 kexec(char *path) { struct process *proc = elf_load(path); if (proc == NULL) @@ -219,7 +219,7 @@ uint32_t kexec(char *path) return 0; } -uint32_t uexec(char *path) +u32 uexec(char *path) { process_suspend(current_proc->pid); diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h index b138f60..bd6a6e7 100644 --- a/src/kernel/tasks/process.h +++ b/src/kernel/tasks/process.h @@ -2,33 +2,33 @@ #define MELVIX_PROCESS_H #include <stdint.h> -#include <kernel/memory/paging.h> -#include <kernel/interrupts/interrupts.h> +#include <memory/paging.h> +#include <interrupts/interrupts.h> struct mmap { - uint32_t text; - uint32_t bss; - uint32_t data; - uint32_t stack; + u32 text; + u32 bss; + u32 data; + u32 stack; }; struct process { struct page_directory *cr3; struct regs registers; - uint32_t pid; - uint32_t gid; + u32 pid; + u32 gid; char *name; int state; int thread; - uint32_t stdin; - uint32_t stdout; - uint32_t stderr; + u32 stdin; + u32 stdout; + u32 stderr; - uint32_t brk; - uint32_t handlers[6]; + u32 brk; + u32 handlers[6]; struct process *parent; struct process *next; @@ -36,31 +36,31 @@ struct process { void scheduler(struct regs *regs); -void process_kill(uint32_t pid); +void process_kill(u32 pid); -uint32_t process_spawn(struct process *process); +u32 process_spawn(struct process *process); -void process_suspend(uint32_t pid); -void process_wake(uint32_t pid); -uint32_t process_child(struct process *process, uint32_t pid); -uint32_t process_fork(uint32_t pid); +void process_suspend(u32 pid); +void process_wake(u32 pid); +u32 process_child(struct process *process, u32 pid); +u32 process_fork(u32 pid); -int process_wait_gid(uint32_t gid, int *status); -int process_wait_pid(uint32_t pid, int *status); +int process_wait_gid(u32 gid, int *status); +int process_wait_pid(u32 pid, int *status); -struct process *process_from_pid(uint32_t pid); +struct process *process_from_pid(u32 pid); void process_init(struct process *proc); struct process *process_make_new(); -uint32_t kexec(char *path); +u32 kexec(char *path); -uint32_t uexec(char *path); +u32 uexec(char *path); extern struct process *current_proc; -extern uint32_t stack_hold; +extern u32 stack_hold; #define PID_NOT_FOUND ((struct process *)0xFFFFFFFF) diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c index 696a9e9..9457b7e 100644 --- a/src/kernel/tasks/userspace.c +++ b/src/kernel/tasks/userspace.c @@ -1,22 +1,22 @@ #include <stdint.h> #include <stddef.h> -#include <kernel/system.h> -#include <kernel/tasks/userspace.h> -#include <kernel/tasks/process.h> -#include <kernel/memory/paging.h> -#include <kernel/io/io.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/lib/lib.h> +#include <system.h> +#include <tasks/userspace.h> +#include <tasks/process.h> +#include <memory/paging.h> +#include <io/io.h> +#include <interrupts/interrupts.h> +#include <lib/lib.h> struct process *proc_bottom = NULL; -uint32_t hl_cr3; -uint32_t hl_eip; -uint32_t hl_esp; +u32 hl_cr3; +u32 hl_eip; +u32 hl_esp; -uint32_t spawn_child(struct process *child) +u32 spawn_child(struct process *child) { - return (uint32_t)-1; + return (u32)-1; } void userspace_enter(struct process *proc) @@ -48,12 +48,12 @@ void single_yield(struct process *proc, struct regs *regs) paging_switch_directory(proc->cr3); } -uint32_t single_exit(struct regs *regs) +u32 single_exit(struct regs *regs) { //close(current_proc->stdout); //close(current_proc->stderr); - uint32_t hold = regs->ebx; + u32 hold = regs->ebx; proc_bottom = proc_bottom->next; if (proc_bottom == NULL) diff --git a/src/kernel/tasks/userspace.h b/src/kernel/tasks/userspace.h index 90b64bf..208476a 100644 --- a/src/kernel/tasks/userspace.h +++ b/src/kernel/tasks/userspace.h @@ -2,15 +2,15 @@ #define MELVIX_USERSPACE_H #include <stdint.h> -#include <kernel/tasks/process.h> -#include <kernel/interrupts/interrupts.h> +#include <tasks/process.h> +#include <interrupts/interrupts.h> -uint32_t spawn_child(struct process *child); +u32 spawn_child(struct process *child); void userspace_enter(struct process *proc); void single_yield(struct process *proc, struct regs *regs); -uint32_t single_exit(struct regs *regs); +u32 single_exit(struct regs *regs); extern void jump_userspace(); diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c index 29017a5..dac1371 100644 --- a/src/kernel/timer/timer.c +++ b/src/kernel/timer/timer.c @@ -1,7 +1,7 @@ #include <stdint.h> -#include <kernel/interrupts/interrupts.h> -#include <kernel/io/io.h> -#include <kernel/system.h> +#include <interrupts/interrupts.h> +#include <io/io.h> +#include <system.h> unsigned long timer_ticks = 0; @@ -9,8 +9,8 @@ void timer_phase(int hz) { int divisor = (int)(3579545.0 / 3.0 / (double)hz); outb(0x43, 0x36); // 01 10 11 0b // CTR, RW, MODE, BCD - outb(0x40, (uint8_t)(divisor & 0xFF)); - outb(0x40, (uint8_t)(divisor >> 8)); + outb(0x40, (u8)(divisor & 0xFF)); + outb(0x40, (u8)(divisor >> 8)); } // Executed 1000 times per second @@ -22,7 +22,7 @@ void timer_handler(struct regs *r) // "Delay" function with CPU sleep void timer_wait(int ticks) { - uint32_t eticks; + u32 eticks; eticks = timer_ticks + ticks; while (timer_ticks < eticks) { @@ -30,7 +30,7 @@ void timer_wait(int ticks) } } -uint32_t get_time() +u32 get_time() { return timer_ticks; } diff --git a/src/kernel/timer/timer.h b/src/kernel/timer/timer.h index 2315b62..7b80b75 100644 --- a/src/kernel/timer/timer.h +++ b/src/kernel/timer/timer.h @@ -2,7 +2,7 @@ #define MELVIX_TIMER_H #include <stdint.h> -#include <kernel/interrupts/interrupts.h> +#include <interrupts/interrupts.h> void timer_handler(struct regs *r); @@ -21,6 +21,6 @@ void timer_wait(int ticks); * Get the current timer ticks * @return The current timer ticks (1000 ticks = 1 second) */ -uint32_t get_time(); +u32 get_time(); #endif
\ No newline at end of file diff --git a/src/resources/conv.sh b/src/resources/conv.sh index 36a17d0..f7848f1 100755 --- a/src/resources/conv.sh +++ b/src/resources/conv.sh @@ -4,13 +4,13 @@ printf "// Generated using the Spleen font and the bdf2c converter (modified using the conv.sh script)\n// Spleen font: (c) 2018-2019, Frederic Cambus, License: MIT\n // bdf2c: (c) 2009-2010 Lutz Sammer, License: AGPLv3\n\n" >font.c -printf "#include <stdint.h>\n\nuint16_t cursor[19]={0b100000000000,0b110000000000,0b111000000000,0b111100000000,0b111110000000,0b111111000000,0b111111100000,0b111111110000,0b111111111000,0b111111111100,0b111111111110,0b111111111111,0b111111111111,0b111111110000,0b111101111000,0b111001111000,0b110000111100,0b000000111100,0b000000011000};\n" >>font.c +printf "#include <stdint.h>\n\nu16 cursor[19]={0b100000000000,0b110000000000,0b111000000000,0b111100000000,0b111110000000,0b111111000000,0b111111100000,0b111111110000,0b111111111000,0b111111111100,0b111111111110,0b111111111111,0b111111111111,0b111111110000,0b111101111000,0b111001111000,0b110000111100,0b000000111100,0b000000011000};\n" >>font.c generate() { font_url="https://raw.githubusercontent.com/fcambus/spleen/master/spleen-$1x$2.bdf" character_count=758 font_height=$2 - top_lines="\nuint$1_t font_$font_height\[$character_count][$font_height] = {" + top_lines="\nu$1 font_$font_height\[$character_count][$font_height] = {" mkdir -p font cd font || exit @@ -30,7 +30,7 @@ generate() { sed -i -z 's/\n\n/\n/g' final.h # Remove all double new lines sed -i -z 's/\,\n/,/g' final.h # Aaand into single lines sed -i 's/\,0x//g' final.h # Fix bytes - sed -i 's/uint12/uint16/g' final.h # Fix non-existent 12 bit bound + sed -i 's/u12/u16/g' final.h # Fix non-existent 12 bit bound mv final.h "font_$2.c" rm font.h diff --git a/src/resources/font.c b/src/resources/font.c index de5dda1..5fcc66e 100644 --- a/src/resources/font.c +++ b/src/resources/font.c @@ -4,13 +4,12 @@ #include <stdint.h> -uint16_t cursor[19] = { 0b100000000000, 0b110000000000, 0b111000000000, 0b111100000000, - 0b111110000000, 0b111111000000, 0b111111100000, 0b111111110000, - 0b111111111000, 0b111111111100, 0b111111111110, 0b111111111111, - 0b111111111111, 0b111111110000, 0b111101111000, 0b111001111000, - 0b110000111100, 0b000000111100, 0b000000011000 }; +u16 cursor[19] = { 0b100000000000, 0b110000000000, 0b111000000000, 0b111100000000, 0b111110000000, + 0b111111000000, 0b111111100000, 0b111111110000, 0b111111111000, 0b111111111100, + 0b111111111110, 0b111111111111, 0b111111111111, 0b111111110000, 0b111101111000, + 0b111001111000, 0b110000111100, 0b000000111100, 0b000000011000 }; -uint8_t font_16[758][16] = { +u8 font_16[758][16] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, @@ -1530,7 +1529,7 @@ uint8_t font_16[758][16] = { 0x01 } }; -uint16_t font_24[758][24] = { +u16 font_24[758][24] = { { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -3808,7 +3807,7 @@ uint16_t font_24[758][24] = { 0x0C00, 0x0600, 0x0300, 0x0180, 0x00C0, 0x0060, 0x0030, 0x0010 } }; -uint16_t font_32[758][32] = { +u16 font_32[758][32] = { { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, diff --git a/src/shared/common.h b/src/shared/common.h new file mode 100644 index 0000000..aa9b281 --- /dev/null +++ b/src/shared/common.h @@ -0,0 +1,19 @@ +#ifndef MELVIX_COMMON_H +#define MELVIX_COMMON_H + +// Syscalls +#define SYS_HALT 0 +#define SYS_EXIT 1 +#define SYS_FORK 2 +#define SYS_READ 3 +#define SYS_WRITE 4 +#define SYS_EXEC 5 +#define SYS_GET_PID 6 +#define SYS_MALLOC 7 +#define SYS_FREE 8 + +// Registration +#define REG_KEYBOARD 0 +#define REG_MOUSE 1 + +#endif
\ No newline at end of file diff --git a/src/userspace/libc/stdarg.h b/src/shared/stdarg.h index 2f45f23..2f45f23 100644 --- a/src/userspace/libc/stdarg.h +++ b/src/shared/stdarg.h diff --git a/src/userspace/libc/stdbool.h b/src/shared/stdbool.h index 337ca9b..733ec28 100644 --- a/src/userspace/libc/stdbool.h +++ b/src/shared/stdbool.h @@ -1,6 +1,8 @@ #ifndef MELVIX_STDBOOL_H #define MELVIX_STDBOOL_H +typedef int bool; + #define true 1 #define false 0 diff --git a/src/userspace/libc/stddef.h b/src/shared/stddef.h index 09dc508..f4bd1a2 100644 --- a/src/userspace/libc/stddef.h +++ b/src/shared/stddef.h @@ -1,7 +1,7 @@ #ifndef MELVIX_STDDEF_H #define MELVIX_STDDEF_H -// size_t +// u32 #define NULL ((void *)0) diff --git a/src/userspace/libc/stdint.h b/src/shared/stdint.h index 63f29f4..8ed1198 100644 --- a/src/userspace/libc/stdint.h +++ b/src/shared/stdint.h @@ -1,8 +1,6 @@ #ifndef MELVIX_STDINT_H #define MELVIX_STDINT_H -// TODO: Use shorter fixed length integers as stdint in kernel - typedef signed char s8; typedef unsigned char u8; diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c index fc0e09a..cf9dc89 100644 --- a/src/userspace/libc/syscall.c +++ b/src/userspace/libc/syscall.c @@ -1,22 +1,24 @@ +#include <stdint.h> +#include <common.h> #include <syscall.h> /** * DEFINITIONS */ -DEFN_SYSCALL0(halt, 0); +DEFN_SYSCALL0(halt, SYS_HALT); -DEFN_SYSCALL1(exit, 1, u32); +DEFN_SYSCALL1(exit, SYS_EXIT, u32); -DEFN_SYSCALL0(fork, 2); +DEFN_SYSCALL0(fork, SYS_FORK); -DEFN_SYSCALL4(read, 3, char *, u32, u32, u8 *); +DEFN_SYSCALL4(read, SYS_READ, char *, u32, u32, u8 *); -DEFN_SYSCALL4(write, 4, char *, u32, u32, u8 *); +DEFN_SYSCALL4(write, SYS_WRITE, char *, u32, u32, u8 *); -DEFN_SYSCALL1(exec, 5, char *); +DEFN_SYSCALL1(exec, SYS_EXEC, char *); -DEFN_SYSCALL0(get_pid, 6); +DEFN_SYSCALL0(get_pid, SYS_GET_PID); -DEFN_SYSCALL1(malloc, 7, u32); +DEFN_SYSCALL1(malloc, SYS_MALLOC, u32); -DEFN_SYSCALL1(free, 8, u32);
\ No newline at end of file +DEFN_SYSCALL1(free, SYS_FREE, u32);
\ No newline at end of file diff --git a/src/userspace/libc/unistd.h b/src/userspace/libc/unistd.h index f9644f1..ac0bacf 100644 --- a/src/userspace/libc/unistd.h +++ b/src/userspace/libc/unistd.h @@ -11,8 +11,8 @@ u32 fork(); u32 get_pid(); -u32 read(char *path, u32 offset, u32 count, char *buf); +u32 read(char *path, u32 offset, u32 count, u8 *buf); -u32 write(char *path, u32 offset, u32 count, char *buf); +u32 write(char *path, u32 offset, u32 count, u8 *buf); #endif
\ No newline at end of file diff --git a/src/userspace/libc/unistd/read.c b/src/userspace/libc/unistd/read.c index 0f8b914..7ae2626 100644 --- a/src/userspace/libc/unistd/read.c +++ b/src/userspace/libc/unistd/read.c @@ -1,7 +1,7 @@ #include <stdint.h> #include <syscall.h> -u32 read(char *path, u32 offset, u32 count, char *buf) +u32 read(char *path, u32 offset, u32 count, u8 *buf) { return syscall_read(path, offset, count, buf); }
\ No newline at end of file diff --git a/src/userspace/libc/unistd/write.c b/src/userspace/libc/unistd/write.c index 7cae9cd..cd1a0f6 100644 --- a/src/userspace/libc/unistd/write.c +++ b/src/userspace/libc/unistd/write.c @@ -1,7 +1,7 @@ #include <stdint.h> #include <syscall.h> -u32 write(char *path, u32 offset, u32 count, char *buf) +u32 write(char *path, u32 offset, u32 count, u8 *buf) { return syscall_write(path, offset, count, buf); }
\ No newline at end of file |