📄 callconv.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.3 2002/01/17 21:47:47 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.@section Processor BackgroundThe MC68xxx architecture supports a simple yeteffective call and return mechanism. A subroutine is invokedvia the branch to subroutine (@code{XXX}) or the jump to subroutine(@code{XXX}) instructions. These instructions push the return addresson the current stack. The return from subroutine (@code{XXX})instruction pops the return address off the current stack andtransfers control to that instruction. It is is important tonote that the XXX call and return mechanism does notautomatically 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 using either a @code{XXX}or @code{XXX} instruction and return to the user application via the@code{XXX} instruction.@section Register UsageAs discussed above, the @code{XXX} and @code{XXX} instructions donot automatically save any registers. RTEMS uses the registers@b{D0}, @b{D1}, @b{A0}, and @b{A1} as scratch registers. These registers arenot preserved by RTEMS directives therefore, the contents ofthese registers should not be assumed upon return from any RTEMSdirective.@section Parameter PassingRTEMS assumes that arguments are placed on thecurrent stack before the directive is invoked via the @code{XXX} or @code{XXX}instruction. The first argument is assumed to be closest to thereturn address on the stack. This means that the first argumentof the C calling sequence is pushed last. The followingpseudo-code illustrates the typical sequence used to call aRTEMS directive with three (3) arguments:@example@grouppush third argumentpush second argumentpush first argumentinvoke directiveremove arguments from the stack@end group@end exampleThe arguments to RTEMS are typically pushed onto thestack using a move instruction with a pre-decremented stackpointer as the destination. These arguments must be removedfrom the stack after control is returned to the caller. Thisremoval is typically accomplished by adding the size of theargument list in bytes to the current stack pointer.@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 + -