Adding a skeleton for the memory management code
Moved the PMM away from being object orientated as it is just plain annoying renamed src folder to source Set timeout to 5 seconds in the grub config
This commit is contained in:
139
source/kernel/KernelLauncher/boot.s
Normal file
139
source/kernel/KernelLauncher/boot.s
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Multiboot
|
||||
*/
|
||||
.set ALIGN, 1<<0 /* align loaded modules on page boundaries */
|
||||
.set MEMINFO, 1<<1 /* provide memory map */
|
||||
.set FLAGS, ALIGN | MEMINFO /* this is the Multiboot 'flag' field */
|
||||
.set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
|
||||
.set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above, to prove we are multiboot */
|
||||
|
||||
.section .multiboot.data, "aw"
|
||||
.align 4
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long CHECKSUM
|
||||
|
||||
/*
|
||||
* Allocate initial stack
|
||||
*/
|
||||
.section .bootstrap_stack, "aw", @nobits
|
||||
stack_bottom:
|
||||
.skip 16384 # 16 KiB
|
||||
stack_top:
|
||||
|
||||
/*
|
||||
* Preallocate a couple pages to get us bootstrapped
|
||||
* Being carefull to not use any address the bootloader might
|
||||
* be using for its multiboot structures
|
||||
*/
|
||||
.section .bss, "aw", @nobits
|
||||
.align 4096
|
||||
.globl boot_page_directory
|
||||
boot_page_directory:
|
||||
.skip 4096
|
||||
boot_page_table:
|
||||
.skip 4096
|
||||
.globl multiboot_page_table
|
||||
multiboot_page_table:
|
||||
.skip 4096
|
||||
# More page tables may be required
|
||||
|
||||
# Entry point
|
||||
.section .multiboot.text, "a"
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
# Get physical address of the boot_page_table
|
||||
movl $(boot_page_table - 0xC0000000), %edi
|
||||
# Map address 0
|
||||
movl $0, %esi
|
||||
1:
|
||||
cmpl $(_kernel_end - 0xC0000000), %esi
|
||||
jge 3f
|
||||
|
||||
# Map physical address as "present and writable"
|
||||
movl %esi, %edx
|
||||
orl $0x003, %edx
|
||||
movl %edx, (%edi)
|
||||
|
||||
2: # Size of page is 4096 bytes
|
||||
addl $4096, %esi
|
||||
# Size of entries in boot_page_table is 4 bytes
|
||||
addl $4, %edi
|
||||
# Loop to the next entry if we haven't finished.
|
||||
loop 1b
|
||||
|
||||
3: # Map VGA video memory to 0xC03FF00 as "present, writable"
|
||||
movl $(0x000B8000 | 0x003), boot_page_table - 0xC0000000 + 1023 * 4
|
||||
|
||||
|
||||
# IMPORTANT NOTE FROM WIKI.OSDEV.ORG/HIGHER_HALF_X86_BARE_BONES
|
||||
|
||||
# The page table is used at both page directory entry 0 (virtually from 0x0
|
||||
# to 0x3FFFFF) (thus identity mapping the kernel) and page directory entry
|
||||
# 768 (virtually from 0xC0000000 to 0xC03FFFFF) (thus mapping it in the
|
||||
# higher half). The kernel is identity mapped because enabling paging does
|
||||
# not change the next instruction, which continues to be physical. The CPU
|
||||
# would instead page fault if there was no identity mapping.\
|
||||
|
||||
# Map the page table to both virtual addresss 0x00000000 and 0xC0000000
|
||||
movl $(boot_page_table - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 0
|
||||
movl $(boot_page_table - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 768 * 4
|
||||
|
||||
# Set cr3 to the address of the boot_page_directory
|
||||
movl $(boot_page_directory - 0xC0000000), %ecx
|
||||
movl %ecx, %cr3
|
||||
|
||||
# Enable paging and the write-protect bit
|
||||
movl %cr0, %ecx
|
||||
orl $0x80010000, %ecx
|
||||
movl %ecx, %cr0
|
||||
|
||||
# Jump to higher half with an absolute jump
|
||||
lea 4f, %ecx
|
||||
jmp *%ecx
|
||||
|
||||
.section .text
|
||||
4:
|
||||
# At this point, paging is fully set up and enabled
|
||||
isPaging:
|
||||
# Unmap the identity mapping as it is now unnecessary
|
||||
movl $0, boot_page_directory + 0
|
||||
|
||||
# Reload cr3 to force tlb flush
|
||||
movl %cr3, %ecx
|
||||
movl %ecx, %cr3
|
||||
|
||||
/*Setup the stack pointer to point to the beginning of our stack */
|
||||
/* I believe its a high address growing down to lower adress for the stack on x86*/
|
||||
mov $stack_top, %esp
|
||||
|
||||
/*Reset EFLAGS*/
|
||||
pushl $0
|
||||
popf
|
||||
|
||||
/* push the pointer to the Multiboot information structure*/
|
||||
pushl %ebx
|
||||
|
||||
/* push the magic value */
|
||||
pushl %eax
|
||||
|
||||
call early_main
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cli
|
||||
1: hlt
|
||||
jmp 1b
|
||||
|
||||
|
||||
.include "./src/kernel/Memory/GDT/gdt.s"
|
||||
.include "./src/kernel/irs_table.s"
|
||||
.include "./src/kernel/irq_table.s"
|
||||
.include "./src/kernel/Interrupts/idt/idt.s"
|
||||
.include "./src/kernel/Memory/paging.s"
|
||||
.include "./src/kernel/cpu.s"
|
||||
|
||||
|
91
source/kernel/KernelLauncher/bootcheck.h
Normal file
91
source/kernel/KernelLauncher/bootcheck.h
Normal file
@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
#include "../multiboot.h"
|
||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||
#define __VERBOSE__
|
||||
#include "../Terminal/kterm.h"
|
||||
|
||||
|
||||
|
||||
void CheckMBT ( multiboot_info_t* mbt ){
|
||||
/* Set MBI to the addresss of the multiboot information structure*/
|
||||
multiboot_info_t * mbi = (multiboot_info_t *) mbt;
|
||||
|
||||
#ifdef __VERBOSE__
|
||||
/* Print out the flags */
|
||||
printf("flags = 0x%x\n", (unsigned) mbi->flags);
|
||||
#endif
|
||||
/* Are mem_* valid? */
|
||||
if ( CHECK_FLAG(mbi->flags,0)){
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/* is boot device valid ? */
|
||||
if (CHECK_FLAG (mbi->flags, 1))
|
||||
{
|
||||
#ifdef __VERBOSE__
|
||||
printf("boot_device = 0x0%x\n", (unsigned) mbi->boot_device);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* is the command line passed? */
|
||||
if (CHECK_FLAG ( mbi->flags,2))
|
||||
{
|
||||
#ifdef __VERBOSE__
|
||||
printf("cmdline = %s\n", (char *) (mbi->cmdline + 0xC0000000));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Are mods_* valid? */
|
||||
if(CHECK_FLAG ( mbi->flags, 3)){
|
||||
multiboot_module_t *mod;
|
||||
uint32_t i;
|
||||
#ifdef __VERBOSE__
|
||||
printf("mods count = %d, mods_addr = 0x%x\n", (int) mbi->mods_count, (int) mbi->mods_addr);
|
||||
|
||||
for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
|
||||
printf(" mod start = 0x%x, mod_end = 0x%x, cmdline = %s\n", (unsigned) mod->mod_start, (unsigned) mod->mod_end, (char*) mod->cmdline);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Bits 4 and 5 are mutually exclusive! */
|
||||
if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5))
|
||||
{
|
||||
#ifdef __VERBOSE__
|
||||
printf("Both bits 4 and 5 are set.\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* Is the symbol table of a.out valid? */
|
||||
if (CHECK_FLAG(mbi->flags, 4)){
|
||||
multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym);
|
||||
#ifdef __VERBOSE__
|
||||
printf( "multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n",
|
||||
(unsigned) multiboot_aout_sym->tabsize,
|
||||
(unsigned) multiboot_aout_sym->strsize,
|
||||
(unsigned) multiboot_aout_sym->addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Is the section header table of ELF valid? */
|
||||
if (CHECK_FLAG(mbi->flags, 5)){
|
||||
multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec);
|
||||
#ifdef __VERBOSE__
|
||||
printf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shnd = 0x%x\n",
|
||||
|
||||
(unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size,
|
||||
(unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* Draw diagonal blue line */
|
||||
if (CHECK_FLAG (mbt->flags, 12)){
|
||||
#ifdef __VERBOSE__
|
||||
printf("Can draw!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
14
source/kernel/KernelLauncher/crti.s
Normal file
14
source/kernel/KernelLauncher/crti.s
Normal file
@ -0,0 +1,14 @@
|
||||
.section .init
|
||||
.global _init
|
||||
.type _init, @function
|
||||
_init:
|
||||
push %ebp
|
||||
movl %esp, %ebp
|
||||
/* gcc will nicely put the contents of crtbegin.o's .init section here. */
|
||||
|
||||
.section .fini
|
||||
.global _fini
|
||||
.type _fini, @function
|
||||
_fini:
|
||||
push %ebp
|
||||
movl %esp, %ebp
|
7
source/kernel/KernelLauncher/crtn.s
Normal file
7
source/kernel/KernelLauncher/crtn.s
Normal file
@ -0,0 +1,7 @@
|
||||
.section .init
|
||||
popl %ebp
|
||||
ret
|
||||
|
||||
.section .fini
|
||||
popl %ebp
|
||||
ret
|
28
source/kernel/KernelLauncher/launcher.cpp
Normal file
28
source/kernel/KernelLauncher/launcher.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void put_char(char ch, size_t x, size_t y ){
|
||||
*((uint16_t*)0xb8000+(y * 80 + x)) = ch | ((7 | 0 << 4) << 8);
|
||||
}
|
||||
|
||||
void write_ln(char* s, size_t length, size_t x , size_t y)
|
||||
{
|
||||
// Because read only data is linked at a virtual address we'll need to convert
|
||||
// the string adddres from virtual to phys.
|
||||
s = s - 0xC0000000;
|
||||
size_t column , row;
|
||||
column = x;
|
||||
row = y;
|
||||
for(int i = 0; i < length ; i ++)
|
||||
{
|
||||
|
||||
put_char(s[i] , column,row );
|
||||
column ++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" void testLauncher () {
|
||||
write_ln("hello", 5 ,0,0);
|
||||
}
|
Reference in New Issue
Block a user