source: rtems/doc/supplements/hppa1_1/callconv.t @ 139b2e4a

4.104.114.84.95
Last change on this file since 139b2e4a was 139b2e4a, checked in by Joel Sherrill <joel.sherrill@…>, on 06/04/97 at 18:32:07

added CVS Id string

  • Property mode set to 100644
File size: 6.8 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-1997.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@ifinfo
10@node Calling Conventions, Calling Conventions Introduction, CPU Model Dependent Features CPU Model Name, Top
11@end ifinfo
12@chapter Calling Conventions
13@ifinfo
14@menu
15* Calling Conventions Introduction::
16* Calling Conventions Processor Background::
17* Calling Conventions Calling Mechanism::
18* Calling Conventions Register Usage::
19* Calling Conventions Parameter Passing::
20* Calling Conventions User-Provided Routines::
21@end menu
22@end ifinfo
23
24@ifinfo
25@node Calling Conventions Introduction, Calling Conventions Processor Background, Calling Conventions, Calling Conventions
26@end ifinfo
27@section Introduction
28
29Each high-level language compiler generates
30subroutine entry and exit code based upon a set of rules known
31as the compiler's calling convention.   These rules address the
32following issues:
33
34@itemize @bullet
35@item register preservation and usage
36
37@item parameter passing
38
39@item call and return mechanism
40@end itemize
41
42A compiler's calling convention is of importance when
43interfacing to subroutines written in another language either
44assembly or high-level.  Even when the high-level language and
45target processor are the same, different compilers may use
46different calling conventions.  As a result, calling conventions
47are both processor and compiler dependent.
48
49This chapter describes the calling conventions used
50by the GNU C and standard HP-UX compilers for the PA-RISC
51architecture.
52
53@ifinfo
54@node Calling Conventions Processor Background, Calling Conventions Calling Mechanism, Calling Conventions Introduction, Calling Conventions
55@end ifinfo
56@section Processor Background
57
58The PA-RISC architecture supports a simple yet
59effective call and return mechanism for subroutine calls where
60the caller and callee are both in the same address space.  The
61compiler will not automatically generate subroutine calls which
62cross address spaces.  A subroutine is invoked via the branch
63and link (bl) or the branch and link register (blr).  These
64instructions save the return address in a caller specified
65register.  By convention, the return address is saved in r2.
66The callee is responsible for maintaining the return address so
67it can return to the correct address.  The branch vectored (bv)
68instruction is used to branch to the return address and thus
69return from the subroutine to the caller.  It is is important to
70note that the PA-RISC subroutine call and return mechanism does
71not automatically save or restore any registers.  It is the
72responsibility of the high-level language compiler to define the
73register preservation and usage convention.
74
75@ifinfo
76@node Calling Conventions Calling Mechanism, Calling Conventions Register Usage, Calling Conventions Processor Background, Calling Conventions
77@end ifinfo
78@section Calling Mechanism
79
80All RTEMS directives are invoked as standard
81subroutines via a bl or a blr instruction with the return address
82assumed to be in r2 and return to the user application via the
83bv instruction.
84
85@ifinfo
86@node Calling Conventions Register Usage, Calling Conventions Parameter Passing, Calling Conventions Calling Mechanism, Calling Conventions
87@end ifinfo
88@section Register Usage
89
90As discussed above, the bl and blr instructions do
91not automatically save any registers.  RTEMS uses the registers
92r1, r19 - r26, and r31 as scratch registers.  The PA-RISC
93calling convention specifies that the first four (4) arguments
94to subroutines are passed in registers r23 - r26.  After the
95arguments have been used, the contents of these registers may be
96altered.  Register r31 is the millicode scratch register.
97Millicode is the set of routines which support high-level
98languages on the PA-RISC by providing routines which are either
99too complex or too long for the compiler to generate inline code
100when these operations are needed.  For example, indirect calls
101utilize a millicode routine.  The scratch registers are not
102preserved by RTEMS directives therefore, the contents of these
103registers should not be assumed upon return from any RTEMS
104directive.
105
106Surprisingly, when using the GNU C compiler at least
107integer multiplies are performed using the floating point
108registers.  This is an important optimization because the
109PA-RISC does not have otherwise have hardware for multiplies.
110This has important ramifications in regards to the PA-RISC port
111of RTEMS.  On most processors, the floating point unit is
112ignored if the code only performs integer operations.  This
113makes it easy for the application developer to predict whether
114or not any particular task will require floating point
115operations.  This property is taken advantage of by RTEMS on
116other architectures to minimize the number of times the floating
117point context is saved and restored.  However, on the PA-RISC
118architecture, every task is implicitly a floating point task.
119Additionally the state of the floating point unit must be saved
120and restored as part of the interrupt processing because for all
121practical purposes it is impossible to avoid the use of the
122floating point registers.  It is unknown if the HP-UX C compiler
123shares this property.
124
125@itemize @code{ }
126@item @b{NOTE}: Later versions of the GNU C has a PA-RISC specific
127option to disable use of the floating point registers.  RTEMS
128currently assumes that this option is not turned on.  If the use
129of this option sets a built-in define, then it should be
130possible to modify the PA-RISC specific code such that all tasks
131are considered floating point only when this option is not used.
132@end itemize
133
134@ifinfo
135@node Calling Conventions Parameter Passing, Calling Conventions User-Provided Routines, Calling Conventions Register Usage, Calling Conventions
136@end ifinfo
137@section Parameter Passing
138
139RTEMS assumes that the first four (4) arguments are
140placed in the appropriate registers (r26, r25, r24, and r23)
141and, if needed, additional are placed on the current stack
142before the directive is invoked via the bl or blr instruction.
143The first argument is placed in r26, the second is placed in
144r25, and so forth.  The following pseudo-code illustrates the
145typical sequence used to call a RTEMS directive with three (3)
146arguments:
147
148
149@example
150set r24 to the third argument
151set r25 to the second argument
152set r26 to the first argument
153invoke directive
154@end example
155
156The stack on the PA-RISC grows upward -- i.e.
157"pushing" onto the stack results in the address in the stack
158pointer becoming numerically larger.  By convention, r27 is used
159as the stack pointer.  The standard stack frame consists of a
160minimum of sixty-four (64) bytes and is the responsibility of
161the callee to maintain.
162
163@ifinfo
164@node Calling Conventions User-Provided Routines, Memory Model, Calling Conventions Parameter Passing, Calling Conventions
165@end ifinfo
166@section User-Provided Routines
167
168All user-provided routines invoked by RTEMS, such as
169user extensions, device drivers, and MPCI routines, must also
170adhere to these calling conventions.
171
172
173
174
Note: See TracBrowser for help on using the repository browser.