Syndicate the Cosmos Blog Feed.

Function Calling Convention

x86 registers are used in this manner:

RegisterUsageFunction Entry
Function Return
Function Code
espStack pointer. Used for local variables and arguments.
Pointer to arguments.
Pointer to return location
Local stack usage
ebp

Contains a copy of esp after function entry.
Arguments are above ebp, and locals are below ebp.

ignoredRestored by function before return to caller.
Holds pointer to arguments and locals.
eip
n/an/an/a

eax
not usedReturn value
General usage
ebx
not usedReturn value for 8 byte returns.
General usage
ecx not usedFunction return flags
General usage
edx
not usednot usedGeneral usage





esi
not usednot usedGeneral usage
edi
not usednot usedGeneral usage

Arguments

Arguments are passed right to left. So if foo(int a, int b) then:

EBP is used because it is initialized to ESP on function entry and ESP is further used for stack work in each method. Objects are stored on the stack as pointers. All pointers are 32 bit as currently we only support x86. In the future we will support x64.

Registers

Registers marked as general usage may be used in the function, however their values will not be preserved when other functions are called as they can make use of these registers as well.

Design Goals and Thoughts

Currently we use a fairly standard calling convention for x86 processors. However initial tests show that it is extremely inefficient and we believe large gains can be made by creating a custom calling convention, beyond even possible register call semantics which we may also use.

Overhead for exceptions is acceptable when exceptions are active, but exception checking code that must occur when no exceptions occur should be minimal.

Function Return Flags

BitMeaning
All bits = 0
No action required.
Bit 0
0 = No action required. If this bit is 0, all other bits should be 0 to allow more efficient testing of the value without the need to check the individual bit.
1 = Remaining bits contain values in need of attention. This bit is used so that if all other bits happen to be 0, but 0 is meaningful this flag can be set to trigger their inspection.
Bit 1

0 = No exception is active
1 = An exception is active and is stored in the exception variable.