Compare commits

..

No commits in common. "6261af8e3aedbc9539410a94fd6351496e18152f" and "20357559c195787345078e10f2b2e737a0730212" have entirely different histories.

6 changed files with 15 additions and 28 deletions

View file

@ -10,6 +10,5 @@
void outb(uint16_t port, uint8_t data); void outb(uint16_t port, uint8_t data);
uint8_t inb(uint16_t port); uint8_t inb(uint16_t port);
void cr3_reload();
#endif #endif

View file

@ -1,11 +0,0 @@
#ifndef VIRTMEM_H
#define VIRTMEM_H
#include <stdint.h>
extern uint32_t global_page_dir;
extern uint32_t kernel_pagetable;
#endif

View file

@ -1,4 +1,4 @@
global outb, inb, invlpg global outb, inb
section .text section .text
outb: outb:
mov dx, [esp+4] mov dx, [esp+4]
@ -11,8 +11,3 @@ section .text
mov dx, [esp+4] mov dx, [esp+4]
in al, dx in al, dx
ret ret
cr3_reload:
mov eax, cr3
mov cr3, eax
ret

View file

@ -40,8 +40,6 @@ void kern_main(uint32_t multiboot_magic, mb_info_t* multiboot_info)
//AND OUR DEFAULT OUTPUT IS: //AND OUR DEFAULT OUTPUT IS:
default_output = default_COM; default_output = default_COM;
printf(default_output, "Output schemes loaded!\n");
printf(default_output, "currently executing in kern_main() at %X\n",kern_main);
printf(default_output, "Entry eax:%X\n", multiboot_magic); printf(default_output, "Entry eax:%X\n", multiboot_magic);
if(multiboot_magic != 0x2BADB002) { if(multiboot_magic != 0x2BADB002) {
println(default_output, "Bootloader not multiboot1 compliant! Needed for mmap, etc. Can't work without it, kthxbye!"); println(default_output, "Bootloader not multiboot1 compliant! Needed for mmap, etc. Can't work without it, kthxbye!");
@ -60,8 +58,10 @@ void kern_main(uint32_t multiboot_magic, mb_info_t* multiboot_info)
return; return;
} }
/* This is broken while i implement virtual memory/paging
unsigned int pages_allocated = build_bitmap((mb_mmap_entry_t*)multiboot_info->mmap_addr, multiboot_info->mmap_length); unsigned int pages_allocated = build_bitmap((mb_mmap_entry_t*)multiboot_info->mmap_addr, multiboot_info->mmap_length);
printf(default_output, "Available mem:%d Pages | %dK", pages_allocated, pages_allocated * 4); printf(default_output, "Available mem:%d Pages | %dK", pages_allocated, pages_allocated * 4);
*/
} }

View file

@ -19,13 +19,17 @@ void free_page(void* addr) {
unsigned int build_bitmap(mb_mmap_entry_t* mmap, int mmap_size) { unsigned int build_bitmap(mb_mmap_entry_t* mmap, int mmap_size) {
//rather important global pointer to the bitmap //rather important global pointer to the bitmap
pmem_bitmap = (&_kernel_end); pmem_bitmap = &_kernel_end;
//some variables //some variables
int mmap_end = (uint32_t)mmap + mmap_size; int mmap_end = (uint32_t)mmap + mmap_size;
unsigned int pages_allocated = 0; unsigned int pages_allocated = 0;
uint32_t max_memory = 0; uint32_t max_memory = 0;
//How much memory do we even have? Find the highest usable mmap region, and that'll be our bitmap size. //How much memory do we even have? Find the highest usable mmap region, and that'll be our bitmap size.
for(mb_mmap_entry_t* mmap_walk = mmap; for(mb_mmap_entry_t* mmap_walk = mmap;
(int)mmap_walk < mmap_end; (int)mmap_walk < mmap_end;

View file

@ -25,9 +25,9 @@ section .tss align=16 nobits
resb 104 resb 104
section .bootstrap_tables nobits align=4096 section .bootstrap_tables nobits align=4096
global_page_dir: bootstrap_PD:
resb 4096 resb 4096
kernel_pagetable: bootstrap_PT:
resb 4096 resb 4096
;Actual code. Entry point goes here! ;Actual code. Entry point goes here!
@ -60,7 +60,7 @@ section .lower_text exec
mov ecx, 0x0 mov ecx, 0x0
;edi = our pointer to the current page table entry. Array of 4byte entries. It's at, of course, where we put it earlier. ;edi = our pointer to the current page table entry. Array of 4byte entries. It's at, of course, where we put it earlier.
;Worth noting that it's actually physically at ~1M with the kernel. The pointer, however, is virtually inclined. So we need to adjust. ;Worth noting that it's actually physically at ~1M with the kernel. The pointer, however, is virtually inclined. So we need to adjust.
mov edi, kernel_pagetable - 0xC0000000 mov edi, bootstrap_PT - 0xC0000000
page_alloc_loop: page_alloc_loop:
;If we're lower than our kernel, skip this page. If we've passed our kernel, we're done mapping. ;If we're lower than our kernel, skip this page. If we've passed our kernel, we're done mapping.
@ -87,15 +87,15 @@ section .lower_text exec
page_alloc_done: page_alloc_done:
;By now we've mapped the kernel in a page table! Let's map VGA too, we'll need that address later. ;By now we've mapped the kernel in a page table! Let's map VGA too, we'll need that address later.
mov dword [kernel_pagetable - 0xC0000000 + 1023 * 4], 0x000B8000 | 0x27 mov dword [bootstrap_PT - 0xC0000000 + 1023 * 4], 0x000B8000 | 0x27
;We have our page tables mapped to the phys addr of kernel + VGA. Time to add them to our page directory! ;We have our page tables mapped to the phys addr of kernel + VGA. Time to add them to our page directory!
;First identity maps, second maps to higher half. ;First identity maps, second maps to higher half.
mov dword [global_page_dir - 0xC0000000], kernel_pagetable - 0xC0000000 + 0x003 mov dword [bootstrap_PD - 0xC0000000], bootstrap_PT - 0xC0000000 + 0x003
mov dword [global_page_dir - 0xC0000000 + 4 * (0xC0000000 >> 22)], kernel_pagetable - 0xC0000000 + 0x003 mov dword [bootstrap_PD - 0xC0000000 + 4 * (0xC0000000 >> 22)], bootstrap_PT - 0xC0000000 + 0x003
;Let's set it! You do this with cr3. ;Let's set it! You do this with cr3.
mov ecx, global_page_dir - 0xC0000000 mov ecx, bootstrap_PD - 0xC0000000
mov cr3, ecx mov cr3, ecx
;Enable paging in cr0 ;Enable paging in cr0