Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBR bootloader: fix 15/16 MB kernel limit #248

Open
stapelberg opened this issue Feb 11, 2024 · 1 comment
Open

MBR bootloader: fix 15/16 MB kernel limit #248

stapelberg opened this issue Feb 11, 2024 · 1 comment

Comments

@stapelberg
Copy link
Contributor

Platform

I’m using: gokrazy/apu2c4, gokrazy/x86-64

Observed behavior

The bootloader that gokrazy is currently shipping has a limit (16 MB architecturally, 15 MB in practice) for the kernel size:

https://michael.stapelberg.ch/posts/2024-02-11-minimal-linux-bootloader-debugging-story/

Options

  1. Investigate using syslinux
  2. Attempt to fix the issue in Minimal Linux Bootloader (probably won’t work on this)
@stapelberg
Copy link
Contributor Author

From https://lobste.rs/s/kaj3c2/minimal_linux_bootloader_debugging#c_ybraf4, someone (with the nick name abbeyj, thank you!) suggested that the fix is to add a adc byte [gdt.dest+5], 0 instruction where the number of bytes is written to the GDT, and indeed this diff seems to work:

diff --git i/mbr/bootloader.asm w/mbr/bootloader.asm
index 58aa030..eb3dfd5 100644
--- i/mbr/bootloader.asm
+++ w/mbr/bootloader.asm
@@ -119,6 +119,7 @@ read_protected_mode_kernel:
 	sub	edx, 0xfe00			; update the number of bytes to load
 	add	word [gdt.dest], 0xfe00
 	adc	byte [gdt.dest+2], 0
+	adc	byte [gdt.dest+5], 0
 	jmp	short read_protected_mode_kernel.loop
 
 read_protected_mode_kernel_2:
@@ -186,18 +187,14 @@ do_move:
 	ret
 
 error:
-
 	mov	si, error_msg
 
 msg_loop:
 
-	lodsb
-	and	al, al
 	jz	reboot
 	mov	ah, 0xe
 	mov	bx, 7
 	int	0x10
-	jmp	short msg_loop
 
 reboot:
 

I’ll properly remove the error function (instead making the code just reboot) to make space for the extra instruction, then add padding so that we end up at 440 bytes again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant