plum-umd / the-838e-compiler

Compiler for CMSC 838E
2 stars 0 forks source link

Calling convention: return address over args #46

Closed dvanhorn closed 3 years ago

dvanhorn commented 3 years ago

This changes the calling convention to place the return address above rather than below the arguments. This has the nice benefit of making it possible to eliminate the parity thing for reconstructing whether you were called in a padded stack or not. It also seems basically required to implement tail calls since a tail called function has to pop all of its local variables and arguments off, but previously these had a return pointer in the middle of it all. This simplifies the callee pop (no more saving/restoring return address), but it slightly complicates calls, since we have to put arguments below the return address it's not possible to use a Call instruction without violating the property that there's nothing below rsp. The solution is to simulate Call by labelling the returning point, pushing it, then the args, then jumping to the function.