This commit is contained in:
Adrien Bourmault 2019-05-14 14:39:44 +02:00
parent 3708519aae
commit e473d63728
4 changed files with 17 additions and 26 deletions

View File

@ -31,15 +31,15 @@
%include "boot/loader/cpu/cpu.inc" %include "boot/loader/cpu/cpu.inc"
%include "boot/loader/mem/structures.inc" %include "boot/loader/mem/structures.inc"
global MB_start global BtStartLoader
global MB_header global BtHeader
extern BtStartKern extern BtStartKern
[BITS 32] [BITS 32]
[section .multiboot] [section .multiboot]
;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;; ;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;;
MB_header: BtHeader:
ALIGN 4 ALIGN 4
dd MB_HEADER_MAGIC dd MB_HEADER_MAGIC
dd MB_HEADER_FLAGS dd MB_HEADER_FLAGS
@ -53,7 +53,7 @@ MB_header:
[section .text] [section .text]
;;MULTIBOOT POINT ENTRY FOR GRUB -------------------------------------------- ;; ;;MULTIBOOT POINT ENTRY FOR GRUB -------------------------------------------- ;;
MB_start: BtStartLoader:
mov esp, KERNEL_STACK ; Setup the stack mov esp, KERNEL_STACK ; Setup the stack
push 0 ; Reset EFLAGS push 0 ; Reset EFLAGS
popf popf

View File

@ -24,7 +24,7 @@
//----------------------------------------------------------------------------*/ //----------------------------------------------------------------------------*/
ENTRY(MB_start) /* the name of the entry label */ ENTRY(BtStartLoader) /* the name of the entry label */
SECTIONS { SECTIONS {
. = 0x00100000; /* the code should be loaded at 1 MB */ . = 0x00100000; /* the code should be loaded at 1 MB */

View File

@ -31,7 +31,7 @@
// //
void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg) void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
{ {
extern ulong MB_header; extern ulong BtHeader;
extern ulong newKernelEnd; extern ulong newKernelEnd;
extern ulong newStackEnd; extern ulong newStackEnd;
@ -43,7 +43,7 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name); BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name);
BtLoaderInfo.kernelAddr = (void*)&MB_header; BtLoaderInfo.kernelAddr = (void*)&BtHeader;
BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd; BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd;
BtLoaderInfo.stackEndAddr = (void*)newStackEnd; BtLoaderInfo.stackEndAddr = (void*)newStackEnd;
BtLoaderInfo.codeSegment = codeSeg; BtLoaderInfo.codeSegment = codeSeg;
@ -108,16 +108,11 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
} }
void BtDoSanityChecks(uint mbMagic) { void BtDoSanityChecks(uint mbMagic) {
uint tmp;
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC)) if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic); KeStartPanic("[Init]\tMagic number %x is incorrect\n", mbMagic);
tmp = (BtLoaderInfo.kernelEndAddr DebugLog("[Init]\tKernel successfully loaded at %p\n",
- BtLoaderInfo.kernelAddr) / KB; BtLoaderInfo.kernelAddr);
DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n"
" and it uses %dKB\n\n",
BtLoaderInfo.kernelAddr,
mbMagic, tmp);
} }

View File

@ -38,10 +38,11 @@ void MmInitMemoryMap(void)
{ {
error_t rc; error_t rc;
if ((rc = InitMemoryMap())) rc = InitMemoryMap();
KeStartPanic("[Init] The memory map failed to initialize. Error : %d",
rc if (rc)
); KeStartPanic("[Mm]\tThe memory map failed to initialize.\nError : %s",
strerror(rc) );
} }
static error_t InitMemoryMap(void) static error_t InitMemoryMap(void)
@ -84,9 +85,6 @@ static error_t InitMemoryMap(void)
i++; i++;
} }
DebugLog("[InitMemoryMap] %d entries detected in the memory map\n",
memoryMap.length);
// compute the free ram size // compute the free ram size
for (i = 0; i < memoryMap.length; i++) { for (i = 0; i < memoryMap.length; i++) {
if (memoryMap.entry[i].type == AVAILABLE_ZONE) { if (memoryMap.entry[i].type == AVAILABLE_ZONE) {
@ -100,10 +98,8 @@ static error_t InitMemoryMap(void)
if (memoryMap.freeRamSize < MINIMUM_RAM_SIZE) if (memoryMap.freeRamSize < MINIMUM_RAM_SIZE)
return ENOMEM; return ENOMEM;
DebugLog("[InitMemoryMap] Available Ram Size : %u Mio, Used Ram Size : %u Kio\n\n", KernLog("[Mm]\tAvailable Ram Size : %u Mio\n",
memoryMap.freeRamSize / MB, memoryMap.nonfreeRamSize / KB); memoryMap.freeRamSize / MB);
/*DebugLog("[InitMemoryMap] Physical Ram Size : %d Mio\n\n",
(memoryMap.freeRamSize + memoryMap.nonfreeRamSize) / MB);*/
// Magic value in memory to prevent smashing // Magic value in memory to prevent smashing
ulong * heapStart = BtLoaderInfo.stackEndAddr + 8; ulong * heapStart = BtLoaderInfo.stackEndAddr + 8;