![](http://datasheet.mmic.net.cn/260000/PPSMMANUAL_datasheet_15946768/PPSMMANUAL_180.png)
35-6
Trap UTrap Usage in PPSM
Programmer’s Manual
overhead induces during a system call.
35.2.1
Application
Applications are written in ANSI C. All PPSM system tools use ANSI C procedure
calling convention. Because SingleStep C compiler allows assembly language in
C source code, it is also allowed in PPSM applications.
35.2.2
Stub Library
The Stub Library provides an interface between application code and system
routines. Its main function is for parameter passing and calling TRAP instructigeneral code layout for a TRAP service handler.
with the correct arguments. It is written in a ANSI C with 68K assembly language
embedded format. Each function in the stub library has the general layout as
shown below:
int
simplification( int a, int b)
#define NO_OF_ARGUMENT2
#define FUNC_NUMBER5
#define TRAP_NUMBER3
int
asm(
rv;
/* return value */
“
“
“
“
“
LEA
MOVE.W #NO_OF_ARGUMENT,D1”,
MOVE.W #FUNC_NUMBER,D0”,
TRAP
#TRAP_NUMBER”,
MOVE.L D0,{rv}”,
8(A6),A0”,
);
return (rv);
}
The first instruction that SingleStep C compiler generates for the start of a ‘C’
procedure is a “LINK” instruction. This instruction sets the frame pointer, A6, to
points to the stack that is used by the procedure caller. To access the first
argument, an offset of 8 is added to A6, see
Figure 34-2
. The Stub Library passes
System Call
Stub Call
TRAP Call
System Code
Figure 34-1 PPSM Tools Calling Structure
‘C’
Written in
Written in
‘C’ and
Written in
Assembly
Language
Written in
‘C’
Assembly
RAM
ROM
Application
Stub Library
TRAP Handler
Actual Tool
Personal Portable System Manager
Programmer’s Manual
35-7
the caller’s argument list to the TRAP instruction via the address register A0 and
the PPSM tools function number via D0.
The TRAP Service Handler routines are implemented in 68K assembly language.
There are 7 jump tables, one for each TRAP service handler (See
The jump table consists of an array of PPSM tool addresses. These addresses
are used as the PPSM system function procedure addresses by the TRAP service
handler when it receives a call from the Stub Library. The listing below shows the
).
.FREF _Func_1,2
.FREF _Func_2,8
JMPTABLE:
DC.L
_Func_1, _Func_2
Trap_1:
LSL.W #2,D1 ; Multiply no of arg by 4
ADD.L D1,A0 ; Move A0 to end of arg list
LSR.W #2,D1 ; Move D1 back to no of arg
loop_1:
TST.W D1
; Any parameter left
BEQ
loop_2 ; If not, goto loop_2
MOVE.L -(A0),-(A7); Move parameter to stack
SUBQ.W #1,D1 ; Decrement D1
BRA
loop_1 ;
loop_2:
LEA
JMPTABLE,A0; Get jump table address
LSL
#2,D0 ; Get function offset
ADD.L D0,A0 ; Find function address
MOVEA.L(A0),A1; Move address to A1
JSR
(A1)
; Jump to system routine
RTE
A6
(-4)
(+4)
(+8)
(+12)
Figure 34-2 Frame Pointer Location in Stack Layout
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.