From mboxrd@z Thu Jan 1 00:00:00 1970 From: dds@aueb.gr (Diomidis Spinellis) Date: Tue, 5 Jan 2016 19:33:24 +0200 Subject: [TUHS] Early Unix function calls: expensive? In-Reply-To: <20160105164642.GA20786@mercury.ccil.org> References: <20160103233543.GA10102@minnie.tuhs.org> <76BC99D5-A8C4-4F8B-8D7D-C621CBD18238@tfeb.org> <20160104000113.GD1602@mercury.ccil.org> <328D91D8-FF74-46EE-A281-5432716E6206@ieee.org> <418F9945-C1BC-4EA1-85F3-981342A9BDD6@ronnatalie.com> <20160105164642.GA20786@mercury.ccil.org> Message-ID: <568BFE64.7080906@aueb.gr> On 05/01/2016 18:46, John Cowan wrote: > Clem Cole scripsit: > >> On Mon, Jan 4, 2016 at 9:00 PM, Ronald Natalie wrote: >> >>> Just never figured out how to make good use of the MARK instruction on the >>> PDP-11. >> >> If I understand it correctly, few if anyone did. > > My guess would be that it was intended to support the antiquated Fortran > feature of "multiple returns" Digital's handbook presents a reasonable (if unusual for Unix) calling convention that uses MARK. It terms the convention "the standard PDP-11 subroutine return convention". https://pdos.csail.mit.edu/6.828/2005/readings/pdp11-40.pdf#page=107 This convention pushes a tailored MARK instruction onto the stack, and then has the called routine return to the address of the pushed MARK instruction. MARK will in turn clean up the stack and restore R5. If I understand things correctly, this saves one instruction over doing the same things through other explicit instructions. Interestingly, many years before the invention of stack smashing attacks, we had a calling convention that was based on executing code placed on the stack.