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|
|
File.open("#{tmpdir}/iso/boot/grub/grub.cfg", "wb") do |fh|
|
||||||
fh.write(<<EOF)
|
fh.write(<<EOF)
|
||||||
menuentry "HOS" {
|
menuentry "HOS" {
|
||||||
multiboot /hos.elf
|
multiboot2 /hos.elf
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
30
src/boot.S
30
src/boot.S
@ -1,10 +1,8 @@
|
|||||||
/* Declare constants for the multiboot header. */
|
/* Declare constants for the multiboot2 header. */
|
||||||
.set ALIGN, 1<<0 /* align loaded modules on page boundaries */
|
.set MAGIC, 0xE85250D6 /* 'magic number' lets bootloader find the header */
|
||||||
.set MEMINFO, 1<<1 /* provide memory map */
|
.set NTAGS, 1 /* including terminating tag */
|
||||||
.set VID, 1<<2
|
.set LENGTH, 4 * 4 + NTAGS
|
||||||
.set FLAGS, ALIGN | MEMINFO | VID /* this is the Multiboot 'flag' field */
|
.set CHECKSUM, -(MAGIC + LENGTH) /* checksum of above, to prove we are multiboot */
|
||||||
.set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
|
|
||||||
.set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above, to prove we are multiboot */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Declare a multiboot header that marks the program as a kernel. These are magic
|
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
|
.section .multiboot
|
||||||
.align 4
|
.align 4
|
||||||
.long MAGIC
|
.long MAGIC /* magic */
|
||||||
.long FLAGS
|
.long 0 /* architecture */
|
||||||
|
.long LENGTH /* header_length */
|
||||||
.long CHECKSUM
|
.long CHECKSUM
|
||||||
|
.short 5
|
||||||
|
.short 0
|
||||||
|
.long 20
|
||||||
.long 0
|
.long 0
|
||||||
.long 0
|
.long 0
|
||||||
.long 0
|
.long 0
|
||||||
.long 0
|
.long 0 /* padding */
|
||||||
.long 0
|
.short 0
|
||||||
.long 0
|
.short 0
|
||||||
.long 0
|
.long 8
|
||||||
.long 0
|
|
||||||
.long 0
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The multiboot standard does not define the value of the stack pointer register
|
The multiboot standard does not define the value of the stack pointer register
|
||||||
|
@ -1,12 +1,42 @@
|
|||||||
#include <stdint.h>
|
#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;
|
uint32_t type = mbinfo[0];
|
||||||
volatile uint32_t * fb = (volatile uint32_t *)mbi[88 / 4];
|
uint32_t size = mbinfo[1];
|
||||||
uint32_t pitch = mbi[96 / 4];
|
switch (type)
|
||||||
uint32_t width = mbi[100 / 4];
|
{
|
||||||
uint32_t height = mbi[104 / 4];
|
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 row = 0u; row < height; row++)
|
||||||
{
|
{
|
||||||
for (uint32_t col = 0u; col < width; col++)
|
for (uint32_t col = 0u; col < width; col++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user