limine-install: Make sure stage 2 chunks are sector aligned
diff --git a/bootsect/disk.inc b/bootsect/disk.inc
index 716cb19b..06506d0c 100644
--- a/bootsect/disk.inc
+++ b/bootsect/disk.inc
@@ -55,7 +55,7 @@ read_sectors:
; EBP:EAX address to EAX LBA sector
div ebp
mov dword [si+8], eax
- mov dword [si+12], edx
+ mov dword [si+12], 0
pop dx
diff --git a/limine-install.c b/limine-install.c
index 73d10333..d1d1db12 100644
--- a/limine-install.c
+++ b/limine-install.c
@@ -10,6 +10,8 @@
#include <fcntl.h>
#include <unistd.h>
+#define DIV_ROUNDUP(a, b) (((a) + ((b) - 1)) / (b))
+
struct gpt_table_header {
// the head
char signature[8];
@@ -327,8 +329,11 @@ int main(int argc, char *argv[]) {
}
size_t stage2_size = bootloader_file_size - 512;
- uint16_t stage2_size_a = stage2_size / 2 + stage2_size % 2;
- uint16_t stage2_size_b = stage2_size / 2;
+
+ size_t stage2_sects = DIV_ROUNDUP(stage2_size, 512);
+
+ uint16_t stage2_size_a = (stage2_sects / 2) * 512 + (stage2_sects % 2 ? 512 : 0);
+ uint16_t stage2_size_b = (stage2_sects / 2) * 512;
// Default split of stage2 for MBR (consecutive in post MBR gap)
uint64_t stage2_loc_a = 512;
diff --git a/limine.bin b/limine.bin
index f4d8be52..2c71298e 100644
Binary files a/limine.bin and b/limine.bin differ
