2005-06-12

Sane ABI for Mac OS X86

I was a bit worried when Apple decided to switch to the IA32 architecture. Three reasons I had for this:
  1. To few visible registers
  2. No Open Firmware
  3. Brain dead calling conventions in System V ABI

Item 1 will be addressed in the EMT64 extensions. Item 2 is a lost cause. Item 3 was addressed by Apple when they defined their own ABI, differing from the Sys V ABI that GNU/Linux use.

Important here is that Apple mandates that the stack pointer is 16 byte aligned at call site boundaries, this implies that the base pointer will also be 16 byte aligned. So, for all 8 (or less) byte variables, the compiler can guarantee that they are aligned properly by the natural alignment.

Further more, in order to ensure minimal performance loss due to miss-aligned access, the ABI enforces a strict 4 byte stack element size, everything including chars are 4 byte aligned on the stack.

This also mean that you will put elements on the stack in the same way as on the PowerPC, i.e. modify stack pointer, place elements with offset from the stack pointer.

Thank you Apple, some hope in the darkness. Now, I only hope that you don't let the new machines be BIOS based, I grieve Open Firmware.

No comments: