Functional C stack discipline, i386. * Small allocation: ** Assign old ESP to EBP. ** Subtract from ESP the amount to be allocated (up to a page). ** Write to the word at the resulting address. *** Probably (XXX) a read operation may be used in place of a write, and the effect is the same. ** During this memory access, a fault handler may move memory and change ESP. ** In the case of a fault, the region above the fault address and below EBP moves as a block. ** If this region moves, ESP moves by an equal displacement. ** The displacement is a multiple of 16 bytes. XXX more? *** The ESP register need not contain a particular value at the time of allocation, but only through its value after the memory access relative to before may the application find the allocated block and the base of further allocation. ** If EBP is outside the page-sized region starting at the fault address, memory movement is unspecified. * Calling convention: ** Caller saves EAX EDX and ECX as per tradition. ** Callee saves EBX ESI EDI and EBP as per tradition. ** In contrast to tradition, Callee may change ESP by unspecified amounts. *** On return, ESP must be equal or less than the greater of ESP and EBP's value on entry, discounting adjustments by fault handlers during allocations. ** Caller must place callee address in ECX prior to transfer. *** Many functions in position-independent code (PIC) need a "GOT" register. Providing the function's own address does part of the work of finding the GOT. *** Many function calls are indirect (through a pointer) so it costs little to specify which register holds the pointer. ** Caller and callee need not align ESP to more than 4 bytes. *** Foreign code may require greater stack alignment. ** First argument in EAX. Remaining arguments start at ESP as per tradition, except without the return address slot. ** Callee owns the argument array and may pop or modify arguments. ** Maximum argument array size is 2048 bytes: 512 words. *** XXX rationale? ** Caller must point EBP to the top of the argument array, or ESP-4 if there are no arguments. *** This provides a convenient way for callee to allocate automatic storage without losing track of its arguments, in case the allocation triggers a frame movement. *** This provides a way for callee to count the arguments. *** EBP demarcates callee's frame, except in the zero-argument case. ** Caller (or prior code) shall have written to the page at ESP. *** This ensures that small allocations by callee do not bypass the guard page. ** Caller must place return address in EDX. *** "jmp *%edx" replaces "ret" as the canonical no-op function. *** Calls are typically made by a JMP instruction, not CALL, since CALL could fault and invalidate EBP. *** Returns are typically made by a JMP instruction, not RET, since ESP is not generally at the return address slot on function exit. ** 32-bit integer returns in EAX as per tradition. ** Floating point returns in ST(0) as per tradition. ** Aggregate returns XXX as per tradition. * Memory management: ** XXX