From 5dc8f48d6ca8d8a652d4aeeded4ae77a6a523b07 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 4 Mar 2021 12:29:59 +0100 Subject: [PATCH] limine-install: Make sure stage 2 chunks are sector aligned --- limine-install.c | 9 +++++++-- stage1/hdd/disk.asm | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) 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 #include +#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