Properly print out the e820 entry types. Make kernel_directory and kernel_page_tables available to all. Add a memory unmap function. Update Makefile.
This commit is contained in:
parent
b117dee07b
commit
2dcf083763
4
Makefile
4
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 $@
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -44,3 +44,22 @@ void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_dir
|
||||
for (int i=0; i<count; i++)
|
||||
map_4k_phys_to_virt(physical + 4096*i, virtual + 4096*i, page_directory, page_tables);
|
||||
}
|
||||
|
||||
void unmap_4k_virt(uint32_t virtual, PDE* page_directory, PTE** page_tables) {
|
||||
split_addr* split = (split_addr*)&virtual;
|
||||
|
||||
((PTE*)((uint32_t)page_tables[split->pd_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
|
||||
};
|
||||
}
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user