wip: multiboot struct is now in the page directory/page table
This commit is contained in:
parent
719c615c92
commit
11ef629a3a
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "multiboot.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -17,16 +19,16 @@
|
|||||||
#define PT_START 256
|
#define PT_START 256
|
||||||
|
|
||||||
#define GET_PAGE_ADDR(pd_index, pt_index) \
|
#define GET_PAGE_ADDR(pd_index, pt_index) \
|
||||||
(((pd_index * 1024) + pt_index) * 4096)
|
((((uint32_t)pd_index * 1024) + (uint32_t)pt_index) * 4096)
|
||||||
|
|
||||||
extern uint32_t _kernel_end;
|
extern uint32_t _kernel_end;
|
||||||
extern uint32_t boot_page_directory;
|
extern uint32_t boot_page_directory;
|
||||||
extern uint32_t *page_directory;
|
extern uint32_t *page_directory;
|
||||||
extern uint32_t page_table_default[1024];
|
extern uint32_t page_table_default[1024];
|
||||||
extern uint64_t mem_size;
|
extern uint32_t mem_size;
|
||||||
|
|
||||||
uint32_t *virt_to_phys(uint32_t *virt_addr);
|
uint32_t *virt_to_phys(uint32_t *virt_addr);
|
||||||
void init_memory(void);
|
void init_memory(multiboot_info_t *mbd, uint32_t magic);
|
||||||
void *alloc_frames(size_t size);
|
void *alloc_frames(size_t size);
|
||||||
int free_frames(void *frame_ptr, size_t size);
|
int free_frames(void *frame_ptr, size_t size);
|
||||||
void *alloc_pages(size_t size);
|
void *alloc_pages(size_t size);
|
||||||
|
@ -34,7 +34,6 @@ boot_page_table1:
|
|||||||
# The kernel entry point.
|
# The kernel entry point.
|
||||||
.section .multiboot.text, "a"
|
.section .multiboot.text, "a"
|
||||||
.global _start
|
.global _start
|
||||||
.global end_mem
|
|
||||||
.type _start, @function
|
.type _start, @function
|
||||||
_start:
|
_start:
|
||||||
# Physical address of boot_page_table1.
|
# Physical address of boot_page_table1.
|
||||||
@ -90,10 +89,6 @@ _start:
|
|||||||
movl $(boot_page_directory - 0xC0000000), %ecx
|
movl $(boot_page_directory - 0xC0000000), %ecx
|
||||||
movl %ecx, %cr3
|
movl %ecx, %cr3
|
||||||
|
|
||||||
jmp set_mem_size
|
|
||||||
|
|
||||||
end_mem:
|
|
||||||
|
|
||||||
# Enable paging and the write-protect bit.
|
# Enable paging and the write-protect bit.
|
||||||
movl %cr0, %ecx
|
movl %cr0, %ecx
|
||||||
orl $0x80000000, %ecx
|
orl $0x80000000, %ecx
|
||||||
@ -118,6 +113,9 @@ end_mem:
|
|||||||
# Set up the stack.
|
# Set up the stack.
|
||||||
mov $stack_top, %esp
|
mov $stack_top, %esp
|
||||||
|
|
||||||
|
push %eax
|
||||||
|
push %ebx
|
||||||
|
|
||||||
# Enter the high-level kernel.
|
# Enter the high-level kernel.
|
||||||
call kernel_main
|
call kernel_main
|
||||||
|
|
||||||
|
@ -55,14 +55,13 @@ static void set_mem_size(multiboot_info_t *mbd, uint32_t magic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kernel_main(void)
|
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||||
{
|
{
|
||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
init_gdt();
|
init_gdt();
|
||||||
init_idt();
|
init_idt();
|
||||||
init_memory();
|
init_memory(mbd, magic);
|
||||||
load_drivers();
|
load_drivers();
|
||||||
/* set_mem_size(mbd, magic); */
|
|
||||||
kprintf(KERN_ALERT
|
kprintf(KERN_ALERT
|
||||||
"I see no way to confuse an array of 256 seg:off pairs with a "
|
"I see no way to confuse an array of 256 seg:off pairs with a "
|
||||||
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||||
|
@ -1,18 +1,59 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t *page_directory = &boot_page_directory;
|
uint32_t *page_directory = &boot_page_directory;
|
||||||
uint32_t page_table_default[1024] __attribute__((aligned(4096)));
|
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||||
uint64_t mem_size;
|
uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||||
|
uint32_t mem_size;
|
||||||
|
multiboot_uint32_t *mmap_addr;
|
||||||
|
multiboot_uint32_t mmap_length;
|
||||||
|
|
||||||
void init_memory(void)
|
static void init_multiboot(multiboot_info_t *mbd, uint32_t magic)
|
||||||
|
{
|
||||||
|
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
|
||||||
|
kpanic("invalid magic number! (git good skill issue)");
|
||||||
|
|
||||||
|
init_page_table(multiboot_page_table, 0);
|
||||||
|
page_directory[1023] =
|
||||||
|
((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
|
||||||
|
const size_t mbd_size = CEIL(
|
||||||
|
(uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
|
||||||
|
|
||||||
|
kprintf("cramptes0\n");
|
||||||
|
// Index multiboot_info_t struct
|
||||||
|
for (uint32_t i = 0; i < mbd_size; i++)
|
||||||
|
multiboot_page_table[i] =
|
||||||
|
((uint32_t)mbd + PAGE_SIZE * i) & PAGE_MASK;
|
||||||
|
multiboot_info_t *mbd_virt =
|
||||||
|
(multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) +
|
||||||
|
(uint32_t)mbd % PAGE_SIZE);
|
||||||
|
|
||||||
|
kprintf("cramptes1\n");
|
||||||
|
PRINT_PTR(mbd_virt);
|
||||||
|
/* PRINT_UINT(mbd_virt->mmap_length); */
|
||||||
|
// Index mbd->mmap_addr pointers
|
||||||
|
for (uint32_t i = 0; i < mbd_virt->mmap_length; i++)
|
||||||
|
multiboot_page_table[i + mbd_size] =
|
||||||
|
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||||
|
INIT_FLAGS;
|
||||||
|
kprintf("cramptes2\n");
|
||||||
|
mmap_addr =
|
||||||
|
(multiboot_uint32_t *)(GET_PAGE_ADDR(1023, mbd_size) +
|
||||||
|
(uint32_t)mbd_virt->mmap_addr % PAGE_SIZE);
|
||||||
|
kprintf("cramptes3\n");
|
||||||
|
mmap_length = mbd_virt->mmap_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_memory(multiboot_info_t *mbd, uint32_t magic)
|
||||||
{
|
{
|
||||||
assert(page_directory);
|
assert(page_directory);
|
||||||
for (uint16_t i = 0; i < 0x300; i++)
|
for (uint16_t i = 0; i < 0x300; i++)
|
||||||
page_directory[i] = 0x02;
|
page_directory[i] = 0x02;
|
||||||
init_page_table(page_table_default, 0);
|
init_page_table(page_table_default, 0);
|
||||||
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
|
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
|
||||||
|
init_multiboot(mbd, magic);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
.intel_syntax noprefix
|
|
||||||
|
|
||||||
.section .text
|
|
||||||
.global set_mem_size
|
|
||||||
|
|
||||||
set_mem_size:
|
|
||||||
jmp end_mem
|
|
||||||
xor ebx, ebx // i = 0
|
|
||||||
.L1:
|
|
||||||
// loop condition
|
|
||||||
cmp ebx, [eax + 44] // mbd->mmap_length
|
|
||||||
jge end_mem
|
|
||||||
|
|
||||||
// declare mmmt
|
|
||||||
mov ecx, [eax + 48] // mbd->mmap_addr
|
|
||||||
add ecx, ebx // + i
|
|
||||||
|
|
||||||
// check if the mmmt->type is available (1)
|
|
||||||
mov edx, [ecx + 20]
|
|
||||||
cmp edx, 1
|
|
||||||
jne .L2
|
|
||||||
|
|
||||||
// add the size of the block
|
|
||||||
mov edx, [ecx + 0] // mmmt->size
|
|
||||||
add mem_size, edx
|
|
||||||
.L2:
|
|
||||||
add ebx, 24 // i += sizeof(multiboot_memory_map_t)
|
|
||||||
jmp .L1
|
|
Loading…
Reference in New Issue
Block a user