-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/#10 init simple memory map #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6565ae3
ae5db65
1390628
a5f5b1c
ebc1fcd
b940770
dafa889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| void idt_init(void); | ||
| void idt_set_gate(uint8_t num, uint32_t base, uint16_t selector, uint8_t flags); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #pragma once | ||
| #include <stdint.h> | ||
|
|
||
| void mmap_dump(uint32_t magic, void* mbinfo); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
|
|
||
| #define PAGE_SIZE 4096u | ||
|
|
||
| void pmm_init(uint32_t magic, void* mbinfo); | ||
| void* pmm_alloc_page(void); | ||
| void pmm_free_page(void* page); | ||
|
|
||
| uint32_t pmm_total_pages(void); | ||
| uint32_t pmm_free_pages(void); | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,209 @@ | ||||||||||||||||||||||||||||||
| #include "arch/x86/idt.h" | ||||||||||||||||||||||||||||||
| #include "drivers/console/console.h" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // IDT entry structure (8 bytes) | ||||||||||||||||||||||||||||||
| struct idt_entry { | ||||||||||||||||||||||||||||||
| uint16_t base_low; // offset bits 0-15 | ||||||||||||||||||||||||||||||
| uint16_t selector; // code segment selector | ||||||||||||||||||||||||||||||
| uint8_t zero; // reserved, always 0 | ||||||||||||||||||||||||||||||
| uint8_t flags; // flags: P, DPL, type | ||||||||||||||||||||||||||||||
| uint16_t base_high; // offset bits 16-31 | ||||||||||||||||||||||||||||||
| } __attribute__((packed)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // IDTR structure (6 bytes) | ||||||||||||||||||||||||||||||
| struct idt_ptr { | ||||||||||||||||||||||||||||||
| uint16_t limit; // IDT size - 1 | ||||||||||||||||||||||||||||||
| uint32_t base; // IDT base address | ||||||||||||||||||||||||||||||
| } __attribute__((packed)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // IDT with 256 entries (x86 supports 256 interrupts) | ||||||||||||||||||||||||||||||
| static struct idt_entry idt[256]; | ||||||||||||||||||||||||||||||
| static struct idt_ptr idtp; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // External assembly function to load IDTR | ||||||||||||||||||||||||||||||
| extern void idt_flush(uint32_t); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Interrupt handler stubs (will be called from assembly) | ||||||||||||||||||||||||||||||
| extern void isr0(); | ||||||||||||||||||||||||||||||
| extern void isr1(); | ||||||||||||||||||||||||||||||
| extern void isr2(); | ||||||||||||||||||||||||||||||
| extern void isr3(); | ||||||||||||||||||||||||||||||
| extern void isr4(); | ||||||||||||||||||||||||||||||
| extern void isr5(); | ||||||||||||||||||||||||||||||
| extern void isr6(); | ||||||||||||||||||||||||||||||
| extern void isr7(); | ||||||||||||||||||||||||||||||
| extern void isr8(); | ||||||||||||||||||||||||||||||
| extern void isr9(); | ||||||||||||||||||||||||||||||
| extern void isr10(); | ||||||||||||||||||||||||||||||
| extern void isr11(); | ||||||||||||||||||||||||||||||
| extern void isr12(); | ||||||||||||||||||||||||||||||
| extern void isr13(); | ||||||||||||||||||||||||||||||
| extern void isr14(); | ||||||||||||||||||||||||||||||
| extern void isr15(); | ||||||||||||||||||||||||||||||
| extern void isr16(); | ||||||||||||||||||||||||||||||
| extern void isr17(); | ||||||||||||||||||||||||||||||
| extern void isr18(); | ||||||||||||||||||||||||||||||
| extern void isr19(); | ||||||||||||||||||||||||||||||
| extern void isr20(); | ||||||||||||||||||||||||||||||
| extern void isr21(); | ||||||||||||||||||||||||||||||
| extern void isr22(); | ||||||||||||||||||||||||||||||
| extern void isr23(); | ||||||||||||||||||||||||||||||
| extern void isr24(); | ||||||||||||||||||||||||||||||
| extern void isr25(); | ||||||||||||||||||||||||||||||
| extern void isr26(); | ||||||||||||||||||||||||||||||
| extern void isr27(); | ||||||||||||||||||||||||||||||
| extern void isr28(); | ||||||||||||||||||||||||||||||
| extern void isr29(); | ||||||||||||||||||||||||||||||
| extern void isr30(); | ||||||||||||||||||||||||||||||
| extern void isr31(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // IRQ handlers | ||||||||||||||||||||||||||||||
| extern void irq0(); | ||||||||||||||||||||||||||||||
| extern void irq1(); | ||||||||||||||||||||||||||||||
| extern void irq2(); | ||||||||||||||||||||||||||||||
| extern void irq3(); | ||||||||||||||||||||||||||||||
| extern void irq4(); | ||||||||||||||||||||||||||||||
| extern void irq5(); | ||||||||||||||||||||||||||||||
| extern void irq6(); | ||||||||||||||||||||||||||||||
| extern void irq7(); | ||||||||||||||||||||||||||||||
| extern void irq8(); | ||||||||||||||||||||||||||||||
| extern void irq9(); | ||||||||||||||||||||||||||||||
| extern void irq10(); | ||||||||||||||||||||||||||||||
| extern void irq11(); | ||||||||||||||||||||||||||||||
| extern void irq12(); | ||||||||||||||||||||||||||||||
| extern void irq13(); | ||||||||||||||||||||||||||||||
| extern void irq14(); | ||||||||||||||||||||||||||||||
| extern void irq15(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Interrupt stack frame structure | ||||||||||||||||||||||||||||||
| // Stack layout (from top to bottom after pusha and segment registers): | ||||||||||||||||||||||||||||||
| // GS, FS, ES, DS (pushed manually) | ||||||||||||||||||||||||||||||
| // EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX (pusha) | ||||||||||||||||||||||||||||||
| // int_no, err_code (pushed manually) | ||||||||||||||||||||||||||||||
| // EIP, CS, EFLAGS (pushed by CPU) | ||||||||||||||||||||||||||||||
| // (useresp, ss only in user mode) | ||||||||||||||||||||||||||||||
| struct interrupt_frame { | ||||||||||||||||||||||||||||||
| uint32_t gs, fs, es, ds; // Segment registers (top of stack) | ||||||||||||||||||||||||||||||
| uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // pusha order | ||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
+87
|
||||||||||||||||||||||||||||||
| // EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX (pusha) | |
| // int_no, err_code (pushed manually) | |
| // EIP, CS, EFLAGS (pushed by CPU) | |
| // (useresp, ss only in user mode) | |
| struct interrupt_frame { | |
| uint32_t gs, fs, es, ds; // Segment registers (top of stack) | |
| uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // pusha order | |
| // EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI (pusha, from low to high address) | |
| // int_no, err_code (pushed manually) | |
| // EIP, CS, EFLAGS (pushed by CPU) | |
| // (useresp, ss only in user mode) | |
| struct interrupt_frame { | |
| uint32_t gs, fs, es, ds; // Segment registers (top of stack) | |
| uint32_t eax, ecx, edx, ebx, esp, ebp, esi, edi; // pusha order |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [bits 32] | ||
|
|
||
| ; IDT flush function | ||
| global idt_flush | ||
| idt_flush: | ||
| mov eax, [esp + 4] ; param idt_ptr address | ||
| lidt [eax] ; load into IDTR | ||
| ret | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the comment: "sturct" should be "struct".