OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 6:13 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: AMD64 32-bit
PostPosted: Tue Dec 22, 2015 4:56 am 
Offline

Joined: Tue Dec 22, 2015 4:33 am
Posts: 2
Hi folks, I have a question about the PE executable file type, related to information that can be found in your wiki here.

Can a PeHeader with mMachine 0x8664 (AMD64) be combined with a Pe32OptionalHeader with mMagic 0x010b (32-bit/PE32)?

According to Kazinsal, who replied to my question in your IRC channel, this would be invalid, because a AMD64 machine basically says: "The code in this PE contains AMD64 instructions and is to be run in long mode."; that 64-bit datatypes cannot be contained in 32-bit data fields.

Assuming the latter is correct, then I'm wondering why the optional header even includes mMagic, because doesn't this mean that an AMD64 machine always uses the 64-bit architecture, and an i386 always 32-bit?


Top
 Profile  
 
 Post subject: Re: AMD64 32-bit
PostPosted: Tue Dec 22, 2015 5:20 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
A magic number need not just have identification as a role, it can also indicate presence - in particular when its predecessor didn't cover for extensions. PE has a long history from flat .COM files, DOS executables to DPMI and 16-bit Windows and even Windows CE. Somewhere in that history it's likely the architects have decided that a magic number was considered meaningful protection from misdiagnosing older files that just happened to have a few bytes in the right place.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: AMD64 32-bit
PostPosted: Wed Dec 23, 2015 5:41 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
I haven't done a lot of research on PE, but judging from the fact that 64-bit Windows executables cannot be executed on 32-bit Windows, my assumption is that your proposed header is invalid, as it specifies that the machine must be AMD64 but that the executable is 32-bit. If you want the executable to be 32-bit, then you need to specify a 32-bit machine in the header; 64-bit machines will run it in a compatibility mode.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
 Post subject: Re: AMD64 32-bit
PostPosted: Sun Dec 27, 2015 4:07 am 
Offline

Joined: Tue Dec 22, 2015 4:33 am
Posts: 2
All right, thanks for the information.


Top
 Profile  
 
 Post subject: Re: AMD64 32-bit
PostPosted: Sun Dec 27, 2015 9:12 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
An analogous situation exists in ELF: You can code
  • An ELF32 i386 object
  • An ELF64 i386 object
  • An ELF32 AMD64 object
  • An ELF64 AMD64 object

Now, the second of these is useless, since there is no 64-bit i386. The first of these is traditional i386 32-bit code.

The fourth of these is of course the "normal" 64-bit AMD64 code. And the third of these is x32. 32-bit pointers, AMD64 instructions.

This is not unusual: The same combinations exist for ARM AArch32/AArch64; you can encode an ELF32.ARM, an ELF32.AArch64, and an ELF64.AArch64, which correspond to traditional ARM AArch32, AArch64 ILP32 and AArch64 ILP64. Some architectures, like MIPS, are different: the 64-bit architecture is a straight and strict superset of the 32-bit architecture. There there is no separate architecture code for MIPS64, and therefore no special "MIPS64 ILP32" ABI could be defined, but such an ABI would be superfluous anyway.

You could envisage similar in a PE file. Of course, PE is primarily the executable format of Windows (and secondarily of UEFI), and Windows does not presently support ILP32 ABIs, so such use is not defined.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 89 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group