diff options
author | Danny Holman <dholman@gymli.org> | 2024-03-28 21:30:12 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2024-03-28 21:30:12 -0500 |
commit | cbe2690cd5d1b290633c466ebb4df7b64b09b037 (patch) | |
tree | 99f77ef19f303c42c028be11cbb4210245b8a583 /arch/i386/include/kernel | |
parent | 891f1010bbdc1351bda8d2a6139094a14bdfd5e1 (diff) |
arch: i386: kernel: add mostly finished PFA and paging system
Add the mostly finished physical memory allocator and expose its
functions to the paging system.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'arch/i386/include/kernel')
-rw-r--r-- | arch/i386/include/kernel/asm.h | 24 | ||||
-rw-r--r-- | arch/i386/include/kernel/paging.h | 5 | ||||
-rw-r--r-- | arch/i386/include/kernel/pmem.h | 28 |
3 files changed, 52 insertions, 5 deletions
diff --git a/arch/i386/include/kernel/asm.h b/arch/i386/include/kernel/asm.h index 615da74..cf394e1 100644 --- a/arch/i386/include/kernel/asm.h +++ b/arch/i386/include/kernel/asm.h @@ -3,6 +3,23 @@ #include <stdint.h> +extern uintptr_t _kernel_start; +extern uintptr_t _kernel_end; +#define KSTART ((uintptr_t)&_kernel_start) +#define KEND ((uintptr_t)&_kernel_end - 0xC0000000) + +#define HIMEM_START 0x00100000 +#define PAGE_SIZE 4096 + +struct thread_block { + uint32_t esp; + uint32_t cr3; + unsigned int tid; + unsigned int tgid; + unsigned int state; + struct thread_block *next; +}; + struct regs { uint32_t cr4; uint32_t cr3; @@ -87,17 +104,18 @@ static inline uint8_t inb(uint16_t port) { static inline void enable_ints(void) { __asm__ volatile("sti"); - return; } static inline void disable_ints(void) { __asm__ volatile("cli"); - return; } static inline void flush_tss(void) { __asm__ volatile("movw $0x28, %ax; ltr %ax"); - return; +} + +static inline void invlpg(void *addr) { + __asm__ volatile("invlpg (%0)" : : "b"(addr) : "memory"); } #endif diff --git a/arch/i386/include/kernel/paging.h b/arch/i386/include/kernel/paging.h index 7f820e8..e949e32 100644 --- a/arch/i386/include/kernel/paging.h +++ b/arch/i386/include/kernel/paging.h @@ -23,9 +23,10 @@ #define ERR_RESERVED 0x8 #define ERR_INST 0x10 -#define PAGE_SIZE 4096 +#define PGROUNDUP(size) (((size)+PAGE_SIZE-1) & ~(PAGE_SIZE-1)) +#define PGROUNDDN(size) (((size)) & ~(PAGE_SIZE-1)) -uint32_t* init_page_table(uint32_t flags); +int init_page_directory(uintptr_t *pd, int user); void enable_paging(uintptr_t pd_addr); void paging_init(void); diff --git a/arch/i386/include/kernel/pmem.h b/arch/i386/include/kernel/pmem.h new file mode 100644 index 0000000..ddd9c8b --- /dev/null +++ b/arch/i386/include/kernel/pmem.h @@ -0,0 +1,28 @@ +#ifndef I386_PMEM_H +#define I386_PMEM_H + +#include <kernel/multiboot.h> +#include <stdint.h> + +#define PFA_BLOCK_FREE 1 +#define PFA_BLOCK_ALLOC 3 + +#define PFA_ALLOC_ERR 0xFFFFFFFF + +struct pfa_page { + struct pfa_page *next; +}; + +struct pfa_zone { + uintptr_t start; + uintptr_t size; + struct pfa_page *freelist; +}; + +int pfa_init(struct mboot_info *header); + +uintptr_t pfa_alloc(void); +void pfa_free(struct pfa_zone *zone, uintptr_t paddr); +void pfa_free_range(struct pfa_zone *zone, uintptr_t pstart, uintptr_t pend); + +#endif |