[edk2-devel] Access 64bit address space in 32bit mode

Andrew Fish via groups.io afish=apple.com at groups.io
Wed Nov 9 17:20:53 UTC 2022


> On Nov 7, 2022, at 7:16 PM, Yoshinoya <yoshinoyatoko at 163.com> wrote:
> 
> Hello
> Is it possible to access 64bit address space in 32bit mode?
> 

I assume you are talking about x86?


> For example, opcode prefix 0x66/67 could let code running in 16bit mode to access 32bit data/address.
> 

This is more complex than just instruction prefix. You need the CPU to be setup in big real mode via the GDT, so you basically have a 32-bit environment setup via GDT etc. Also the prefix opcodes have different meaning in different modes. I don’t think there is a way to make 32-bit code access 64-bit data via instruction prefix even if a 64-bit GDT was setup with paging enabled.  

> Or, establishing page table is a must requirement for accessing 64bit address space.
> 

For x86 you have to have 64-bit versions of the IDT, GDT, and you need to enable paging to enter 64-bit Long Mode. 

In a 32-bit x86 world you can access up to 64 GB of physical memory via using 32-bit page table using PAE [1]. PAE is a 32-bit virtual address space, but with support for a 36-bit physical address. I think in the olden days of 32-bit x86 EFI servers would have custom EFI code that enabled paging in 32-bit and carved out a chunk of the 32-bit memory space that could be mapped to 36-bit physical addresses. I think this was platform specific code and I don’t know of any open source version. The 32-bit Long Mode EFI does not have paging enabled, so adding PAE means enabling paging yourself. 

The edk2 has the opposite version of this code so you can call 16-bit really mode (Legacy BIOS) from 32-bit Protected mode, or 64-bit Long Mode. This is the code to Thunk for 32-bit/64-bit mode to 16-bit code [2]/ 

[1] https://en.wikipedia.org/wiki/Physical_Address_Extensio <https://en.wikipedia.org/wiki/Physical_Address_Extension>n <https://en.wikipedia.org/wiki/Physical_Address_Extension>
[2] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X86Thunk.c
https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X64/Thunk16.nasm
edk2/Thunk16.nasm at master · tianocore/edk2
github.com
https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/Ia32/Thunk16.nasm
edk2/Thunk16.nasm at master · tianocore/edk2
github.com

Thanks,

Andrew Fish


> Thanks
>  
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#96144): https://edk2.groups.io/g/devel/message/96144
Mute This Topic: https://groups.io/mt/94885261/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20221109/78e84f2a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: edk2.png
Type: image/png
Size: 70276 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20221109/78e84f2a/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: edk2.png
Type: image/png
Size: 70276 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20221109/78e84f2a/attachment-0003.png>


More information about the edk2-devel-archive mailing list