mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
32bit boot using multiboot2
This commit is contained in:
parent
961d7d7270
commit
3df98c7c8e
@ -1,43 +1,43 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
EXTERNC __attribute__((no_stack_protector, section(".multiboot.text"))) void Multiboot2Initializator()
|
#include <boot/protocols/multiboot2.h>
|
||||||
{
|
|
||||||
for (int i = 0; i < 2000; i++)
|
|
||||||
{
|
|
||||||
((unsigned int *)0xb8000)[i * 2] = ' ';
|
|
||||||
((unsigned int *)0xb8000)[i * 2 + 1] = 0;
|
|
||||||
}
|
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 2] = 'W';
|
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 1] = 6;
|
|
||||||
unsigned char *SMBIOSAddress = (unsigned char *)0xF0000;
|
|
||||||
while ((unsigned int)(unsigned long)SMBIOSAddress < 0x100000)
|
|
||||||
{
|
|
||||||
if (SMBIOSAddress[0] == '_' &&
|
|
||||||
SMBIOSAddress[1] == 'S' &&
|
|
||||||
SMBIOSAddress[2] == 'M' &&
|
|
||||||
SMBIOSAddress[3] == '_')
|
|
||||||
{
|
|
||||||
unsigned char Checksum = 0;
|
|
||||||
int Length = SMBIOSAddress[5];
|
|
||||||
for (int i = 0; i < Length; i++)
|
|
||||||
Checksum += SMBIOSAddress[i];
|
|
||||||
|
|
||||||
if (Checksum == 0)
|
struct multiboot_info
|
||||||
break;
|
|
||||||
}
|
|
||||||
SMBIOSAddress += 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((unsigned int)(unsigned long)SMBIOSAddress == 0x100000)
|
|
||||||
{
|
{
|
||||||
// No SMBIOS found
|
multiboot_uint32_t Size;
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 4] = 'S';
|
multiboot_uint32_t Reserved;
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 3] = 4;
|
struct multiboot_tag *Tag;
|
||||||
|
};
|
||||||
|
|
||||||
|
EXTERNC __attribute__((no_stack_protector, section(".mb2bootcode.text"))) void Multiboot2Initializator(multiboot_info *Info, unsigned int Magic)
|
||||||
|
{
|
||||||
|
if (Info == NULL || Magic == NULL)
|
||||||
|
{
|
||||||
|
if (Magic == NULL)
|
||||||
|
{
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 4] = 'E';
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 3] = 4;
|
||||||
|
}
|
||||||
|
if (Info == NULL)
|
||||||
|
{
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 2] = 'R';
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 1] = 4;
|
||||||
|
}
|
||||||
|
while (1)
|
||||||
|
asmv("hlt");
|
||||||
|
}
|
||||||
|
else if (Magic != MULTIBOOT2_BOOTLOADER_MAGIC)
|
||||||
|
{
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 2] = 'M';
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 1] = 4;
|
||||||
while (1)
|
while (1)
|
||||||
asmv("hlt");
|
asmv("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 10] = 'Y';
|
/* TODO */
|
||||||
((uint8_t *)0xb8000)[2 * (80) * (25) - 9] = 2;
|
|
||||||
return;
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 2] = 'Y';
|
||||||
|
((unsigned char *)0xb8000)[2 * (80) * (25) - 1] = 2;
|
||||||
|
while (1)
|
||||||
|
asmv("hlt");
|
||||||
}
|
}
|
||||||
|
@ -1,84 +1,33 @@
|
|||||||
KERNEL_VIRTUAL_BASE EQU 0xE0000000
|
KERNEL_VIRTUAL_BASE EQU 0xE0000000
|
||||||
|
|
||||||
section .multiboot2.data
|
section .multiboot2
|
||||||
align 8
|
align 8
|
||||||
HEADER_START:
|
HEADER_START:
|
||||||
dd 0xE85250D6
|
dd 0xE85250D6
|
||||||
dd 0
|
dd 0
|
||||||
dd (HEADER_END - HEADER_START)
|
dd (HEADER_END - HEADER_START)
|
||||||
dd -(0xE85250D6 + (HEADER_END - HEADER_START))
|
dd -(0xE85250D6 + 0 + (HEADER_END - HEADER_START))
|
||||||
|
|
||||||
align 8
|
align 8
|
||||||
|
MB2_TAG_START:
|
||||||
dw 0
|
dw 0
|
||||||
dw 0
|
dw 0
|
||||||
dd 8
|
dd MB2_TAG_END - MB2_TAG_START
|
||||||
|
MB2_TAG_END:
|
||||||
HEADER_END:
|
HEADER_END:
|
||||||
|
|
||||||
section .bss
|
|
||||||
STACK_BOTTOM: resb 16384
|
|
||||||
STACK_TOP:
|
|
||||||
|
|
||||||
align 4096
|
|
||||||
BOOT_PAGE_DIR0: resb 4096
|
|
||||||
BOOT_PAGE_TBL0: resb 4096
|
|
||||||
BOOT_PAGE_TBL1: resb 4096
|
|
||||||
|
|
||||||
section .multiboot2.text
|
|
||||||
extern x32Entry
|
|
||||||
extern Multiboot2Initializator
|
extern Multiboot2Initializator
|
||||||
extern _kernel_start
|
|
||||||
extern _kernel_end
|
|
||||||
global _start
|
global _start
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
mov word [0xb8000], 0x074C ; L
|
|
||||||
mov word [0xb8002], 0x076F ; o
|
|
||||||
mov word [0xb8004], 0x0761 ; a
|
|
||||||
mov word [0xb8006], 0x0764 ; d
|
|
||||||
mov word [0xb8008], 0x0769 ; i
|
|
||||||
mov word [0xb800a], 0x076E ; n
|
|
||||||
mov word [0xb800c], 0x0767 ; g
|
|
||||||
mov word [0xb800e], 0x072E ; .
|
|
||||||
mov word [0xb8010], 0x072E ; .
|
|
||||||
mov word [0xb8012], 0x072E ; .
|
|
||||||
mov esp, STACK_TOP - KERNEL_VIRTUAL_BASE
|
|
||||||
mov edi, BOOT_PAGE_TBL0 - KERNEL_VIRTUAL_BASE
|
|
||||||
mov esi, 0
|
|
||||||
mov ecx, 2048 - 301
|
|
||||||
.PagingLoop:
|
|
||||||
cmp esi, _kernel_start - KERNEL_VIRTUAL_BASE
|
|
||||||
jl .LoopInside
|
|
||||||
cmp esi, _kernel_end - KERNEL_VIRTUAL_BASE
|
|
||||||
jge .LoopEnd
|
|
||||||
mov eax, esi
|
|
||||||
or eax, 3
|
|
||||||
mov [edi], eax
|
|
||||||
.LoopInside:
|
|
||||||
add esi, 4096
|
|
||||||
add edi, 4
|
|
||||||
loop .PagingLoop
|
|
||||||
.LoopEnd:
|
|
||||||
call Multiboot2Initializator
|
|
||||||
push ebx
|
|
||||||
mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (000 * 4)], (BOOT_PAGE_TBL0 - KERNEL_VIRTUAL_BASE + 3)
|
|
||||||
mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (001 * 4)], (BOOT_PAGE_TBL1 - KERNEL_VIRTUAL_BASE + 3)
|
|
||||||
mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (896 * 4)], (BOOT_PAGE_TBL0 - KERNEL_VIRTUAL_BASE + 3)
|
|
||||||
mov dword [BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE + (897 * 4)], (BOOT_PAGE_TBL1 - KERNEL_VIRTUAL_BASE + 3)
|
|
||||||
mov ecx, BOOT_PAGE_DIR0 - KERNEL_VIRTUAL_BASE
|
|
||||||
mov cr3, ecx
|
|
||||||
mov ecx, cr0
|
|
||||||
or ecx, 0x80010000
|
|
||||||
mov cr0, ecx
|
|
||||||
add esp, KERNEL_VIRTUAL_BASE
|
|
||||||
mov eax, CallKernelMain
|
|
||||||
jmp eax
|
|
||||||
|
|
||||||
section .text
|
|
||||||
CallKernelMain:
|
|
||||||
push ebx
|
|
||||||
call x32Entry
|
|
||||||
cli
|
cli
|
||||||
.hang:
|
mov esp, STACK_TOP
|
||||||
|
push eax
|
||||||
|
push ebx
|
||||||
|
call Multiboot2Initializator
|
||||||
|
.Hang:
|
||||||
hlt
|
hlt
|
||||||
jmp .hang
|
jmp .Hang
|
||||||
|
|
||||||
|
section .mb2bootcode.bss
|
||||||
|
STACK_BOTTOM: resb 16384
|
||||||
|
STACK_TOP:
|
||||||
|
@ -3,24 +3,36 @@ OUTPUT_ARCH(i386)
|
|||||||
|
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
KERNEL_VIRTUAL_BASE = 0xE0000000;
|
KERNEL_VIRTUAL_BASE = 0xC0000000;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x00100000;
|
. = 1M;
|
||||||
_kernel_start = . + KERNEL_VIRTUAL_BASE;
|
|
||||||
|
|
||||||
.multiboot.data :
|
.boot :
|
||||||
{
|
{
|
||||||
*(.multiboot2.data)
|
*(.multiboot2 .multiboot2.*)
|
||||||
}
|
}
|
||||||
|
|
||||||
.multiboot.text :
|
.mb2bootcode.text :
|
||||||
{
|
{
|
||||||
*(.multiboot2.text)
|
*(.mb2bootcode.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mb2bootcode.data :
|
||||||
|
{
|
||||||
|
*(.mb2bootcode.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
.mb2bootcode.bss :
|
||||||
|
{
|
||||||
|
*(.mb2bootcode.bss)
|
||||||
|
}
|
||||||
|
|
||||||
|
. += ALIGN(4096);
|
||||||
. += KERNEL_VIRTUAL_BASE;
|
. += KERNEL_VIRTUAL_BASE;
|
||||||
|
_kernel_start = .;
|
||||||
|
|
||||||
.text ALIGN(4096) : AT(ADDR(.text) - KERNEL_VIRTUAL_BASE)
|
.text ALIGN(4096) : AT(ADDR(.text) - KERNEL_VIRTUAL_BASE)
|
||||||
{
|
{
|
||||||
*(.text .text.*)
|
*(.text .text.*)
|
||||||
@ -41,10 +53,8 @@ SECTIONS
|
|||||||
|
|
||||||
.bss ALIGN (4096) : AT(ADDR(.bss) - KERNEL_VIRTUAL_BASE)
|
.bss ALIGN (4096) : AT(ADDR(.bss) - KERNEL_VIRTUAL_BASE)
|
||||||
{
|
{
|
||||||
_sbss = .;
|
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
*(.bss .bss.*)
|
*(.bss .bss.*)
|
||||||
_ebss = .;
|
|
||||||
}
|
}
|
||||||
_kernel_end = .;
|
_kernel_end = .;
|
||||||
|
|
||||||
|
@ -1491,7 +1491,6 @@ namespace CPU
|
|||||||
: "memory");
|
: "memory");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user