Procedure Calling Convention

General discussions about working with the Astrobe IDE and programming ARM Cortex-M0, M3, M4 and M7 microcontrollers.
Post Reply
gray
Posts: 121
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

Procedure Calling Convention

Post by gray » Fri May 03, 2024 1:44 am

The ARM Architecture Procedure Call Standard (AAPCS) stipulates that, upon calling a procedure
1) registers r0 to r3, and r12, are "caller saved", ie. the called procedure is free to mutate them.
2) registers r4 to r11 are "callee saved", ie. the called procedure must save and restore these registers in case it mutates them.
Parameters are passed via r0 to r3, and the stack if needed.

The Astrobe compiler saves all register before calling a procedure, ie. all registers are "caller saved", and passes all parameters in registers.[1]

Just out of interest: is there a rule or convention, explicit or tacit, regarding this behaviour for Oberon programs?

[1] Exception handlers behave like the above standard regarding register saving and restoring, based on the exception handler implementation in the Cortex-M MCUs (stacking of r0 to r3 and r12).

cfbsoftware
Site Admin
Posts: 502
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Procedure Calling Convention

Post by cfbsoftware » Sat May 04, 2024 2:34 am

"An Oberon Compiler for the ARM Processor" is a detailed description of the architecture of Niklaus Wirth's ARM Oberon compiler that we used as the basis for our first Astrobe (a.k.a Armaide) ARM compilers in 2008. You can download a copy from:

https://people.inf.ethz.ch/wirth/Oberon ... mpiler.pdf

Note that the parameter passing convention is dependent on whether a procedure is declared as a "leaf" procedure or not. Refer to Chapter 22 for details.

The register allocation and parameter passing convention that is described was used in Astrobe for Cortex-M3, M4 and M7 until Aug 2023 when v9 was released. With the introduction of Astrobe for Cortex-M0 the register allocation, and consequently, the parameter passing convention was changed as summarised in the latest Whats New in Astrobe notes.

Recommended related further reading is Wirth's Compiler Construction book which you can download from:

https://people.inf.ethz.ch/wirth/Compil ... index.html

Post Reply