📄 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.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.@section Processor BackgroundThe i386 architecture supports a simple yet effectivecall and return mechanism. A subroutine is invoked via the call(call) instruction. This instruction pushes the return addresson the stack. The return from subroutine (ret) instruction popsthe return address off the current stack and transfers controlto that instruction. It is is important to note that the i386call and return mechanism does not automatically save or restoreany registers. It is the responsibility of the high-levellanguage compiler to define the register preservation and usageconvention.@section Calling MechanismAll RTEMS directives are invoked using a callinstruction and return to the user application via the retinstruction.@section Register UsageAs discussed above, the call instruction does notautomatically save any registers. RTEMS uses the registers EAX,ECX, and EDX as scratch registers. These registers are notpreserved by RTEMS directives therefore, the contents of theseregisters 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 callinstruction. 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:@examplepush third argumentpush second argumentpush first argumentinvoke directiveremove arguments from the stack@end exampleThe arguments to RTEMS are typically pushed onto thestack using a push instruction. 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 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 + -