diff --git a/Makefile b/Makefile index c2afc3e..02933ca 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ CFLAGS = -std=gnu11 -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector -Wno-pointer-to-int-cast +CXXFLAGS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore LDFLAGS = DISK_IMG_FILES = build/kernel/kernel.bin @@ -50,6 +51,9 @@ build/boot_stage2/stage2.o: src/boot_stage2/main.c build/kernel/%.o: src/kernel/%.c gcc $(CFLAGS) -o $@ -c $< +build/kernel/%.o: src/kernel/%.cpp + g++ $(CFLAGS) -o $@ -c $< + build/kernel/%.o: src/kernel/%.asm nasm -felf32 $< -o $@ diff --git a/src/boot_stage2/main.c b/src/boot_stage2/main.c index 1d6cb02..e8de959 100644 --- a/src/boot_stage2/main.c +++ b/src/boot_stage2/main.c @@ -47,6 +47,21 @@ void mark_unavailble(uint32_t address, uint32_t size) { } } +char* stringify_type(uint32_t type) { + switch (type) { + case 1: + return "Usable"; + case 3: + return "ACPI Reclaimable"; + case 4: + return "ACPI NVS"; + case 5: + return "Bad memory"; + default: + return "Reserved"; + } +} + void main() { init_term(); init_atapio(); @@ -64,7 +79,7 @@ void main() { for (int i=0; e820_entries[i].length_low != 0 || e820_entries[i].length_high != 0; i++) { e820entry entry = e820_entries[i]; - printf("BIOS-e820: Starting %x%x, length %x%x is %s\n", entry.base_high, entry.base_low, entry.length_high, entry.length_low, entry.type == 1 ? "Available" : "Reserved"); + printf("BIOS-e820: Starting %x%x, length %x%x is %s\n", entry.base_high, entry.base_low, entry.length_high, entry.length_low, stringify_type(entry.type)); if (entry.type != 1) continue; diff --git a/src/kernel/allocate.h b/src/kernel/allocate.h index 945d215..1c293aa 100644 --- a/src/kernel/allocate.h +++ b/src/kernel/allocate.h @@ -4,6 +4,10 @@ #include "paging.h" //void init_allocator(); +extern uint8_t* bitmap; +extern PDE* kernel_page_directory; +extern PTE** kernel_page_tables; + void set_bit(uint32_t offset, uint8_t* buffer); void unset_bit(uint32_t offset, uint8_t* buffer); uint8_t get_bit(uint32_t offset, uint8_t* buffer); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d64fdab..f59ea08 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -6,6 +6,8 @@ #include "strings.h" #include "atapio.h" #include "gdt.h" +#include "paging.h" +#include "allocate.h" int main() { init_gdt(); @@ -16,6 +18,8 @@ int main() { printf("KERNEL OK!\n"); + unmap_4k_virt(0x8000, kernel_page_directory, kernel_page_tables); + init_keyboard(); enable_idt(); diff --git a/src/kernel/paging.c b/src/kernel/paging.c index 016fc8b..21e8b57 100644 --- a/src/kernel/paging.c +++ b/src/kernel/paging.c @@ -43,4 +43,23 @@ void map_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_director void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables, uint32_t count) { for (int i=0; ipd_index] + 0xbffe0000))[split->pt_index] = (PTE){ + .address = 0, + .available = 0, + .global = 0, + .accessed = 0, + .disable_cache = 0, + .dirty = 0, + .write_through_cache = 0, + .privilege = 0, + .present = 0, + .read_write = 0, + + .ignored = 0 + }; } \ No newline at end of file diff --git a/src/kernel/paging.h b/src/kernel/paging.h index 1978218..d489bba 100644 --- a/src/kernel/paging.h +++ b/src/kernel/paging.h @@ -34,4 +34,6 @@ typedef struct { void map_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables); void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables, uint32_t count); + +void unmap_4k_virt(uint32_t virtual, PDE* page_directory, PTE** page_tables); #endif \ No newline at end of file