put memory map detection into paging.c (grub_memory_map function)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define PAGING_H
|
||||
|
||||
#include "../include/stdio.h"
|
||||
#include "../include/multiboot.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define PAGE_OFFSET 0xC0000000
|
||||
@@ -26,6 +27,7 @@ extern uint32_t kernel_page_table[1024] __attribute__((aligned(4096)));
|
||||
extern uint32_t user_page_table[1024] __attribute__((aligned(4096)));
|
||||
|
||||
//paging.c
|
||||
void grub_memory_map(unsigned int magic, struct multiboot_info* mbi);
|
||||
void enablePaging();
|
||||
void loadPageDirectory(uint32_t* page_directory);
|
||||
void paging_init();
|
||||
|
||||
+1
-28
@@ -153,34 +153,7 @@ void kmain(unsigned int magic, unsigned int info)
|
||||
printf("bootloader: %s\n", mbi.boot_loader_name);
|
||||
}
|
||||
|
||||
/* Check bit 6 to see if we have a valid memory map */
|
||||
if(!(mbi.flags >> 6 & 0x1)) {
|
||||
printf("invalid memory map given by GRUB bootloader\n");
|
||||
while(1){}
|
||||
}
|
||||
|
||||
/* Loop through the memory map and display the values */
|
||||
int i;
|
||||
for(i = 0; i < mbi.mmap_length;
|
||||
i += sizeof(multiboot_memory_map_t))
|
||||
{
|
||||
multiboot_memory_map_t* mmmt =
|
||||
(multiboot_memory_map_t*) (mbi.mmap_addr + i);
|
||||
|
||||
printf("Start Addr: %x | Length: %x | Size: %x | Type: %x\n",
|
||||
mmmt->addr, mmmt->len, mmmt->size, mmmt->type);
|
||||
|
||||
if(mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
/*
|
||||
* Do something with this memory block!
|
||||
* BE WARNED that some of memory shown as availiable is actually
|
||||
* actively being used by the kernel! You'll need to take that
|
||||
* into account before writing to memory!
|
||||
*/
|
||||
printf("available\n");
|
||||
}
|
||||
}
|
||||
|
||||
grub_memory_map(magic, &mbi);
|
||||
|
||||
isr_install();
|
||||
pic_remap(0x20, 0x28);
|
||||
|
||||
+31
-1
@@ -1,6 +1,5 @@
|
||||
#include "../include/paging.h"
|
||||
#include <stdint.h>
|
||||
#include "../include/multiboot.h"
|
||||
#include "../include/string.h"
|
||||
|
||||
uint32_t kernel_page_directory[1024] __attribute__((aligned(4096)));
|
||||
@@ -63,6 +62,37 @@ uint32_t setup_tmp_pgdir(uint32_t magic, uint32_t info)
|
||||
return (uint32_t)kpage_dir - PAGE_OFFSET;
|
||||
}
|
||||
|
||||
void grub_memory_map(unsigned int magic, struct multiboot_info* mbi)
|
||||
{
|
||||
/* Check bit 6 to see if we have a valid memory map */
|
||||
if(!(mbi->flags >> 6 & 0x1)) {
|
||||
printf("invalid memory map given by GRUB bootloader\n");
|
||||
while(1){}
|
||||
}
|
||||
|
||||
/* Loop through the memory map and display the values */
|
||||
int i;
|
||||
for(i = 0; i < mbi->mmap_length;
|
||||
i += sizeof(multiboot_memory_map_t))
|
||||
{
|
||||
multiboot_memory_map_t* mmmt =
|
||||
(multiboot_memory_map_t*) (mbi->mmap_addr + i);
|
||||
|
||||
printf("Start Addr: %x | Length: %x | Size: %x | Type: %x\n",
|
||||
mmmt->addr, mmmt->len, mmmt->size, mmmt->type);
|
||||
|
||||
if(mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
/*
|
||||
* Do something with this memory block!
|
||||
* BE WARNED that some of memory shown as availiable is actually
|
||||
* actively being used by the kernel! You'll need to take that
|
||||
* into account before writing to memory!
|
||||
*/
|
||||
printf("available\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enablePaging() {
|
||||
asm volatile (
|
||||
"mov %%cr0, %%eax\n"
|
||||
|
||||
Reference in New Issue
Block a user