diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2025-07-27 19:34:35 +0200 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2025-07-27 19:34:35 +0200 |
commit | ca84afb315e813f08d725082320d40969b9f93e4 (patch) | |
tree | 4ec276592ba85a0163bf759e3d614f56d39c2de7 /src | |
parent | 0e14cad65fafc22ac319f0a7ed4f08f00f76c81a (diff) |
Small tweaks
Diffstat (limited to 'src')
-rw-r--r-- | src/aplos.h | 5 | ||||
-rw-r--r-- | src/boot.c | 20 | ||||
-rw-r--r-- | src/descriptors.c | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/nasty.S | 5 | ||||
-rw-r--r-- | src/paging.c | 8 |
6 files changed, 37 insertions, 7 deletions
diff --git a/src/aplos.h b/src/aplos.h index d9d6cdb..7d3fce0 100644 --- a/src/aplos.h +++ b/src/aplos.h @@ -22,8 +22,11 @@ struct memmap struct boot_info { struct framebuffer framebuffer; + uint64_t memmap_count; struct memmap *memmaps; + + uint64_t physbase; }; /* boot.c */ @@ -50,9 +53,11 @@ void enable_interrupts(void); void set_gdt(struct table_reg *, uint64_t, uint64_t, uint64_t); void set_idt(struct table_reg *); uint64_t get_cr2(void); +uint64_t get_cr3(void); extern void (*isr_stubs[32])(void); /* paging.c */ +void setup_paging(struct boot_info *); bool page_fault_handler(uint32_t); /* panic.c */ @@ -41,6 +41,11 @@ REQUEST struct limine_entry_point_request entry_point_request = { .entry = bootmain }; +REQUEST struct limine_hhdm_request hhdm_request = { + .id = LIMINE_HHDM_REQUEST, + .revision = 0 +}; + LIMINE(".limine_requests_start") LIMINE_REQUESTS_START_MARKER LIMINE(".limine_requests_end") LIMINE_REQUESTS_END_MARKER @@ -60,6 +65,7 @@ bootmain(void) assert(memmap_request.response); assert(paging_request.response); assert(mp_request.response); + assert(hhdm_request.response); assert(framebuffer_request.response->framebuffer_count >= 1); @@ -76,14 +82,16 @@ bootmain(void) struct memmap *m = memmaps; for(uint64_t i = 0; i < memmap_request.response->entry_count; i++){ struct limine_memmap_entry *e = memmap_request.response->entries[i]; - if(e->type != LIMINE_MEMMAP_USABLE) - continue; - m->start = e->base; - m->size = e->length; - m++; - info.memmap_count++; + switch(e->type){ + case LIMINE_MEMMAP_USABLE: + m->start = e->base; + m->size = e->length; + m++; + info.memmap_count++; + } } info.memmaps = memmaps; + info.physbase = hhdm_request.response->offset; main(&info); halt(); diff --git a/src/descriptors.c b/src/descriptors.c index 82b8709..7df3a9e 100644 --- a/src/descriptors.c +++ b/src/descriptors.c @@ -84,6 +84,8 @@ setup_descriptors(void) { struct table_reg reg; + print(u8"Setting up GDT and IDT\n"); + disable_interrupts(); encode_descriptors(®, GDT_START, GDT_END); set_gdt(®, DESCRIPTOR_SIZE*KERNEL_CODE_SEGMENT, DESCRIPTOR_SIZE*KERNEL_DATA_SEGMENT, DESCRIPTOR_SIZE*TASK_STATE_SEGMENT); @@ -7,11 +7,13 @@ static void print_size(uint64_t); void main(struct boot_info *info) { - setup_descriptors(); screen_init(&info->framebuffer); welcome(); print(u8"CPU count: %u64\n", cpu_count()); print_memmap(info); + + setup_descriptors(); + setup_paging(info); } static void diff --git a/src/nasty.S b/src/nasty.S index ac9fc91..9fdab5f 100644 --- a/src/nasty.S +++ b/src/nasty.S @@ -42,6 +42,11 @@ get_cr2: mov rax, cr2 ret +.global get_cr3 +get_cr3: + mov rax, cr3 + ret + #define DEFINE_ISRS \ ISR(0) \ ISR(1) \ diff --git a/src/paging.c b/src/paging.c index 539b26a..0728178 100644 --- a/src/paging.c +++ b/src/paging.c @@ -1,5 +1,13 @@ #include "aplos.h" +void +setup_paging(struct boot_info *info) +{ + print(u8"Setting up paging. All usable physical memory is mapped starting at %p\n", info->physbase); + uint64_t cr3 = get_cr3(); + print(u8"CR3: %p\n", cr3); +} + bool page_fault_handler(uint32_t code) { |