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

📄 callconv.t

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 T
字号:
@c@c  COPYRIGHT (c) 1988-1999.@c  On-Line Applications Research Corporation (OAR).@c  All rights reserved.@c@c  $Id: callconv.t,v 1.1 2003/01/24 13:57:31 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.The GNU Compiler Suite follows the same calling conventionsas the Texas Instruments toolset.@section Processor BackgroundThe TI C3x and C4x processors support 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 important tonote that the call and return mechanism for the C3x/C4x does notautomatically save or restore any registers.  It is theresponsibility of the high-level language compiler to define theregister preservation and usage convention.XXX other supplements may have "is is".@section Calling MechanismAll subroutines are invoked using either a @code{XXX}or @code{XXX} instruction and return to the user application via the@code{XXX} instruction.@section Register UsageXXXAs discussed above, the @code{XXX} and @code{XXX} instructions donot automatically save any registers.  Subroutines use the registers@b{D0}, @b{D1}, @b{A0}, and @b{A1} as scratch registers.  These registers arenot preserved by subroutines therefore, the contents ofthese registers should not be assumed upon return from any subroutinecall including but not limited to an RTEMS directive.The GNU and Texas Instruments compilers follow the same conventionsfor register usage.@section Parameter PassingBoth the GNU and Texas Instruments compilers support two conventionsfor passing parameters to subroutines.  Arguments may be passed inmemory on the stack or in registers.@subsection Parameters Passed in MemoryWhen passing parameters on the stack, the calling convention assumesthat arguments are placed on the current stack before the subroutineis invoked via the @code{XXX} instruction.  The first argument isassumed to be closest to the return address on the stack.  This meansthat the first argument of the C calling sequence is pushed last.  Thefollowing pseudo-code illustrates the typical sequence used to call asubroutine with three (3) arguments:@example@grouppush third argumentpush second argumentpush first argumentinvoke subroutineremove arguments from the stack@end group@end exampleThe arguments to RTEMS are typically pushed onto thestack using a @code{sti} instruction with a pre-incremented stackpointer as the destination.  These arguments must be removedfrom the stack after control is returned to the caller.  Thisremoval is typically accomplished by subtracting the size of theargument list in words from the current stack pointer.@c XXX XXX instruction .. XXX should be code format.With the GNU Compiler Suite, parameter passing via the stack is selected by invoking the compiler with the@code{-mmemparm XXX} argument.  This argument must beincluded when linking the application in order toensure that support libraries also compiled assumingparameter passing via the stack are used.  The defaultparameter passing mechanism is XXX.When this parameter passing mecahanism is selected, the @code{XXX}symbol is predefined by the C and C++ compilersand the @code{XXX} symbol is predefined by the assembler.This behavior is the same for the GNU and Texas Instrumentstoolsets.  RTEMS uses these predefines to determine howparameters are passed in to those C3x/C4x specific routinesthat were written in assembly language.@subsection Parameters Passed in RegistersWhen passing parameters via registers, the calling convention assumesthat the arguments are placed in particular registers based upontheir position and data type before the subroutine is invoked viathe @code{XXX} instruction.  The following pseudo-code illustratesthe typical sequence used to call a subroutine with three (3) arguments:@example@groupmove third argument to XXXmove second argument to XXXmove first argument to XXXinvoke subroutine@end group@end exampleWith the GNU Compiler Suite, parameter passing via registers is selected by invoking the compiler with the@code{-mregparm XXX} argument.  This argument must beincluded when linking the application in order toensure that support libraries also compiled assumingparameter passing via the stack are used.  The defaultparameter passing mechanism is XXX.When this parameter passing mecahanism is selected, the @code{XXX}symbol is predefined by the C and C++ compilersand the @code{XXX} symbol is predefined by the assembler.This behavior is the same for the GNU and Texas Instrumentstoolsets.  RTEMS uses these predefines to determine howparameters are passed in to those C3x/C4x specific routinesthat were written in assembly language.@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 + -