switch from multiboot to multiboot2
This commit is contained in:
parent
21afa93c4b
commit
412925a790
@ -24,7 +24,7 @@ build do
|
||||
File.open("#{tmpdir}/iso/boot/grub/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
menuentry "HOS" {
|
||||
multiboot /hos.elf
|
||||
multiboot2 /hos.elf
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
30
src/boot.S
30
src/boot.S
@ -1,10 +1,8 @@
|
||||
/* Declare constants for the multiboot header. */
|
||||
.set ALIGN, 1<<0 /* align loaded modules on page boundaries */
|
||||
.set MEMINFO, 1<<1 /* provide memory map */
|
||||
.set VID, 1<<2
|
||||
.set FLAGS, ALIGN | MEMINFO | VID /* 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 */
|
||||
/* Declare constants for the multiboot2 header. */
|
||||
.set MAGIC, 0xE85250D6 /* 'magic number' lets bootloader find the header */
|
||||
.set NTAGS, 1 /* including terminating tag */
|
||||
.set LENGTH, 4 * 4 + NTAGS
|
||||
.set CHECKSUM, -(MAGIC + LENGTH) /* checksum of above, to prove we are multiboot */
|
||||
|
||||
/*
|
||||
Declare a multiboot header that marks the program as a kernel. These are magic
|
||||
@ -15,18 +13,20 @@ forced to be within the first 8 KiB of the kernel file.
|
||||
*/
|
||||
.section .multiboot
|
||||
.align 4
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long MAGIC /* magic */
|
||||
.long 0 /* architecture */
|
||||
.long LENGTH /* header_length */
|
||||
.long CHECKSUM
|
||||
.short 5
|
||||
.short 0
|
||||
.long 20
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0
|
||||
.long 0 /* padding */
|
||||
.short 0
|
||||
.short 0
|
||||
.long 8
|
||||
|
||||
/*
|
||||
The multiboot standard does not define the value of the stack pointer register
|
||||
|
@ -1,12 +1,42 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void kernel_main(uint32_t mbinfo)
|
||||
uint32_t * fb;
|
||||
uint32_t pitch;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
static uint32_t * process_mbinfo_tag(uint32_t * mbinfo)
|
||||
{
|
||||
volatile uint32_t * mbi = (volatile uint32_t *)mbinfo;
|
||||
volatile uint32_t * fb = (volatile uint32_t *)mbi[88 / 4];
|
||||
uint32_t pitch = mbi[96 / 4];
|
||||
uint32_t width = mbi[100 / 4];
|
||||
uint32_t height = mbi[104 / 4];
|
||||
uint32_t type = mbinfo[0];
|
||||
uint32_t size = mbinfo[1];
|
||||
switch (type)
|
||||
{
|
||||
case 0u:
|
||||
return 0u;
|
||||
|
||||
case 8u:
|
||||
fb = (uint32_t *)mbinfo[2];
|
||||
pitch = mbinfo[4];
|
||||
width = mbinfo[5];
|
||||
height = mbinfo[6];
|
||||
break;
|
||||
}
|
||||
return (uint32_t *)(((uint32_t)mbinfo + size + 7u) & 0xFFFFFFF8u);
|
||||
}
|
||||
|
||||
static void process_mbinfo(uint32_t * mbinfo)
|
||||
{
|
||||
/* Skip multiboot2 boot information header. */
|
||||
mbinfo += 2u;
|
||||
do
|
||||
{
|
||||
mbinfo = process_mbinfo_tag(mbinfo);
|
||||
} while (mbinfo != (uint32_t *)0u);
|
||||
}
|
||||
|
||||
void kernel_main(uint32_t * mbinfo)
|
||||
{
|
||||
process_mbinfo(mbinfo);
|
||||
for (uint32_t row = 0u; row < height; row++)
|
||||
{
|
||||
for (uint32_t col = 0u; col < width; col++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user