:: commit 5dc8f48d6ca8d8a652d4aeeded4ae77a6a523b07

mintsuki <mintsuki@protonmail.com> — 2021-03-04 11:29

parents: f26b6045a7

limine-install: Make sure stage 2 chunks are sector aligned

diff --git a/limine-install.c b/limine-install.c
index dfe053d2..0dca4e0a 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];
@@ -318,8 +320,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/stage1/hdd/disk.asm b/stage1/hdd/disk.asm
index 716cb19b..06506d0c 100644
--- a/stage1/hdd/disk.asm
+++ b/stage1/hdd/disk.asm
@@ -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
 
tab: 248 wrap: offon