From 21ba34f5263053ae11fc6ab1c9ffbc474c085a8d Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Sat, 17 Aug 2024 16:46:23 +0200 Subject: [PATCH] Fix stack growing direction in GDT being swapped In the GDT, the direction in which the stack grows in x86 has been ignored; for reserving space on the stack, the ESP register was added to and for cleaning up that space, ESP was subtracted from. That is obviously wrong and is fixed with this commit. --- i386/legacy-boot/src-asm/memory/gdt.asm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/i386/legacy-boot/src-asm/memory/gdt.asm b/i386/legacy-boot/src-asm/memory/gdt.asm index 3cf15f5..10933db 100755 --- a/i386/legacy-boot/src-asm/memory/gdt.asm +++ b/i386/legacy-boot/src-asm/memory/gdt.asm @@ -27,7 +27,7 @@ GDT_ENTRY_COUNT equ 3 make_regular_data_segment_in_gdt: .prolog: push esi - add esp, 64 + sub esp, 64 mov esi, esp mov [esi + (64 - 4)], eax @@ -98,7 +98,7 @@ make_regular_data_segment_in_gdt: mov ebx, [esi + (64 - 8)] mov eax, [esi + (64 - 4)] - sub esp, 64 + add esp, 64 pop esi ret @@ -134,7 +134,7 @@ make_regular_data_segment_in_gdt: make_code_segment_in_gdt: .prolog: push esi - add esp, 64 + sub esp, 64 mov esi, esp mov [esi + (64 - 4)], eax @@ -205,7 +205,7 @@ make_code_segment_in_gdt: mov ebx, [esi + (64 - 8)] mov eax, [esi + (64 - 4)] - sub esp, 64 + add esp, 64 pop esi ret @@ -224,7 +224,7 @@ make_code_segment_in_gdt: load_flat_gdt: .prolog: push esi - add esp, 64 + sub esp, 64 mov esi, esp mov [esi + (64 - 4)], eax