Fix GDT length being insufficient

The value of the GDTR register was set to be 8 bytes too small, with
the effect that an accurate emulation software would error out because
of trying to read over the buffer size, as was noticed when using KVM.

This was due to the perception that the 0th index wouldn't be taken
into account; for that reason, the length of the GDTR was one index
short of what it should've been.
This commit is contained in:
Eric-Paul Ickhorn 2024-08-06 13:20:40 +02:00
parent fd8b5bd57e
commit 5ba30e5f8b
Signed by: epickh
GPG Key ID: 1358818BAA38B104
1 changed files with 21 additions and 17 deletions

View File

@ -239,28 +239,40 @@ load_flat_gdt:
.set_segments: .set_segments:
push ebp push ebp
mov ebp, esp mov ebp, esp
push dword 2 ; Segment Index push dword 2 ; Segment Index
push dword 0 ; Start Offset push dword 0 ; Start Offset
push dword 0xfffff ; Page Count push dword 0x000fffff ; Page Count
push dword 0 ; Required privilege level push dword 0 ; Required privilege level
call make_regular_data_segment_in_gdt call make_regular_data_segment_in_gdt
mov esp, ebp mov esp, ebp
pop ebp pop ebp
push ebp push ebp
mov ebp, esp mov ebp, esp
push dword 1 ; Segment Index push dword 1 ; Segment Index
push dword 0x0000 ; Start Offset push dword 0x0000 ; Start Offset
push dword 0xfffff ; Page Count push dword 0x000fffff ; Page Count
push dword 0 ; Required privilege level push dword 0 ; Required privilege level
call make_code_segment_in_gdt call make_code_segment_in_gdt
mov esp, ebp mov esp, ebp
pop ebp pop ebp
mov bx, 0 mov bx, 0
mov ds, bx mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
mov ss, bx
lgdt [.gdtr] lgdt [.gdtr]
mov ebx, cr0
or ebx, 1
mov cr0, ebx
jmp dword (1 << 3):.epilog
bits 32
.epilog:
mov bx, (2 << 3) mov bx, (2 << 3)
mov ds, bx mov ds, bx
mov es, bx mov es, bx
@ -268,14 +280,6 @@ load_flat_gdt:
mov gs, bx mov gs, bx
mov ss, bx mov ss, bx
mov ebx, cr0
or ebx, 1
mov cr0, ebx
jmp dword 0x08:.epilog
bits 32
.epilog:
mov edi, [esi + (64 - 20)] mov edi, [esi + (64 - 20)]
mov edx, [esi + (64 - 16)] mov edx, [esi + (64 - 16)]
mov ecx, [esi + (64 - 12)] mov ecx, [esi + (64 - 12)]
@ -287,7 +291,7 @@ bits 32
align 16 align 16
.gdtr: .gdtr:
.gdtr.length: .gdtr.length:
dw 15 dw 23
.gdtr.pointer: .gdtr.pointer:
dd GDT_MEMORY_AREA dd GDT_MEMORY_AREA