⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callconv.t

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 T
字号:
@c@c  COPYRIGHT (c) 1988-2002.@c  On-Line Applications Research Corporation (OAR).@c  All rights reserved.@c@c  $Id: callconv.t,v 1.6 2002/01/17 21:47:46 joel Exp $@c@chapter Calling Conventions@section IntroductionEach high-level language compiler generatessubroutine entry and exit code based upon a set of rules knownas the compiler's calling convention.   These rules address thefollowing issues:@itemize @bullet@item register preservation and usage@item parameter passing@item call and return mechanism@end itemizeA compiler's calling convention is of importance wheninterfacing to subroutines written in another language eitherassembly or high-level.  Even when the high-level language andtarget processor are the same, different compilers may usedifferent calling conventions.  As a result, calling conventionsare both processor and compiler dependent.This chapter describes the calling conventions usedby the GNU C and standard HP-UX compilers for the PA-RISCarchitecture.@section Processor BackgroundThe PA-RISC architecture supports a simple yeteffective call and return mechanism for subroutine calls wherethe caller and callee are both in the same address space.  Thecompiler will not automatically generate subroutine calls whichcross address spaces.  A subroutine is invoked via the branchand link (bl) or the branch and link register (blr).  Theseinstructions save the return address in a caller specifiedregister.  By convention, the return address is saved in r2.The callee is responsible for maintaining the return address soit can return to the correct address.  The branch vectored (bv)instruction is used to branch to the return address and thusreturn from the subroutine to the caller.  It is is important tonote that the PA-RISC subroutine call and return mechanism doesnot automatically save or restore any registers.  It is theresponsibility of the high-level language compiler to define theregister preservation and usage convention.@section Calling MechanismAll RTEMS directives are invoked as standardsubroutines via a bl or a blr instruction with the return addressassumed to be in r2 and return to the user application via thebv instruction.@section Register UsageAs discussed above, the bl and blr instructions donot automatically save any registers.  RTEMS uses the registersr1, r19 - r26, and r31 as scratch registers.  The PA-RISCcalling convention specifies that the first four (4) argumentsto subroutines are passed in registers r23 - r26.  After thearguments have been used, the contents of these registers may bealtered.  Register r31 is the millicode scratch register.Millicode is the set of routines which support high-levellanguages on the PA-RISC by providing routines which are eithertoo complex or too long for the compiler to generate inline codewhen these operations are needed.  For example, indirect callsutilize a millicode routine.  The scratch registers are notpreserved by RTEMS directives therefore, the contents of theseregisters should not be assumed upon return from any RTEMSdirective.Surprisingly, when using the GNU C compiler at leastinteger multiplies are performed using the floating pointregisters.  This is an important optimization because thePA-RISC does not have otherwise have hardware for multiplies.This has important ramifications in regards to the PA-RISC portof RTEMS.  On most processors, the floating point unit isignored if the code only performs integer operations.  Thismakes it easy for the application developer to predict whetheror not any particular task will require floating pointoperations.  This property is taken advantage of by RTEMS onother architectures to minimize the number of times the floatingpoint context is saved and restored.  However, on the PA-RISCarchitecture, every task is implicitly a floating point task.Additionally the state of the floating point unit must be savedand restored as part of the interrupt processing because for allpractical purposes it is impossible to avoid the use of thefloating point registers.  It is unknown if the HP-UX C compilershares this property.@itemize @code{ }@item @b{NOTE}: Later versions of the GNU C has a PA-RISC specificoption to disable use of the floating point registers.  RTEMScurrently assumes that this option is not turned on.  If the useof this option sets a built-in define, then it should bepossible to modify the PA-RISC specific code such that all tasksare considered floating point only when this option is not used.@end itemize@section Parameter PassingRTEMS assumes that the first four (4) arguments areplaced in the appropriate registers (r26, r25, r24, and r23)and, if needed, additional are placed on the current stackbefore the directive is invoked via the bl or blr instruction.The first argument is placed in r26, the second is placed inr25, and so forth.  The following pseudo-code illustrates thetypical sequence used to call a RTEMS directive with three (3)arguments:@exampleset r24 to the third argumentset r25 to the second argumentset r26 to the first argumentinvoke directive@end exampleThe stack on the PA-RISC grows upward -- i.e."pushing" onto the stack results in the address in the stackpointer becoming numerically larger.  By convention, r27 is usedas the stack pointer.  The standard stack frame consists of aminimum of sixty-four (64) bytes and is the responsibility ofthe callee to maintain.@section User-Provided RoutinesAll user-provided routines invoked by RTEMS, such asuser extensions, device drivers, and MPCI routines, must alsoadhere to these calling conventions.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -