From 9a478aa4d47541237be89814ebe03b62b5394203 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Fri, 5 Sep 2025 16:28:01 -0400 Subject: [PATCH] added another __REFLAT variant --- include/cdecl16.inc | 29 +++++++++++++++++++++++++++-- src/stage2/stage2.nasm | 4 ++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/cdecl16.inc b/include/cdecl16.inc index 99fd44f..da585ec 100644 --- a/include/cdecl16.inc +++ b/include/cdecl16.inc @@ -69,6 +69,7 @@ %endmacro %endif +; set ds and es segments back to the base of the loader %ifnmacro __TINY_DS_ES %macro __TINY_DS_ES 0 mov ax, __STAGE2_SEGMENT @@ -77,6 +78,7 @@ %endmacro %endif +; for copying between locations in high memory %ifnmacro __REFLAT_DS_ES %macro __REFLAT_DS_ES 0 cli ; no interrupts @@ -88,8 +90,31 @@ jmp short $+2 ; i-cache flush mov ax, 0x10 ; select descriptor 2 - mov ds, ax ; 10h = 0001_0000b - mov es, ax ; es to big data + mov ds, ax + mov es, ax + + mov eax, cr0 + and eax, ~1 ; toggle bit 1 of cr0 + mov cr0, eax ; back to realmode + jmp short $+2 ; i-cache flush + sti + +%endmacro +%endif + +; for copying from low memory to high memory (ds on a real segment, es in flat mode) +%ifnmacro __REFLAT_ES +%macro __REFLAT_ES 0 + cli ; no interrupts + lgdt [((__STAGE2_SEGMENT << 4) + unreal_gdt_info)] ; load unreal gdt + + mov eax, cr0 + or eax, 1 ; set pmode bit + mov cr0, eax ; switch to pmode + jmp short $+2 ; i-cache flush + + mov ax, 0x10 ; select descriptor 2 + mov es, ax mov eax, cr0 and eax, ~1 ; toggle bit 1 of cr0 diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index 1af2838..1b87fac 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -224,9 +224,9 @@ EnterUnrealMode: jmp 0x0000:EnterUnrealMode.endp .endp: sti ; re-enable interupts - + ; set ds, es to the STAGE2_SEGMENT, for our model (generally) ds == es == cs - ; fs, gs & ss are all still huge data model, and the macro "__REFLAT_DS_ES" exists + ; fs, gs & ss are all still huge data model, and the macro(s) "__REFLAT_xxx" exists ; to easily access data outside of 64KiB boundries using ds/es addressing __TINY_DS_ES