source: trunk/libs/newlib/src/libgloss/sparc/libsys/syscallasm.h @ 656

Last change on this file since 656 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.5 KB
Line 
1#ifndef _SYSCALLASM_H_
2#define _SYSCALLASM_H_
3
4/*
5 * This file defines the system calls for SPARC for the assembler.
6 * Anything C-ish is not allowed in this file.
7 * C files should include syscall.h.
8 */
9
10#include "syscall.h"
11
12/* Some macros for writing assember syscall stubs.  */
13
14#ifdef SVR4
15#define TEXT_SECTION    .section ".text"
16#define DATA_SECTION    .section ".data"
17#define ALIGN(x)        .align x
18#define GLOBAL(sym)     .global sym
19#define WORD(x)         .long x
20#define ASM_SYMBOL(name) name
21#define ASM_PRIVATE_SYMBOL(name) _##name
22#define SYSCALL_TRAP    8
23#else
24#define TEXT_SECTION    .text
25#define DATA_SECTION    .data
26#define ALIGN(x)        .align x
27#define GLOBAL(sym)     .global sym
28#define WORD(x)         .word x
29#define ASM_SYMBOL(name) _##name
30#define ASM_PRIVATE_SYMBOL(name) name
31#define SYSCALL_TRAP    0
32#endif
33
34#define defsyscall(name, n) \
35        TEXT_SECTION ;                  \
36        ALIGN (4) ;                     \
37        GLOBAL (ASM_SYMBOL (name)) ;    \
38ASM_SYMBOL (name):                      \
39        mov     n,%g1 ;                 \
40        ta      SYSCALL_TRAP ;          \
41        bcc     noerr ;                 \
42        sethi   %hi (ASM_PRIVATE_SYMBOL (cerror)),%g1 ;         \
43        or      %g1,%lo (ASM_PRIVATE_SYMBOL (cerror)),%g1 ;     \
44        jmpl    %g1+%g0,%g0 ;           \
45        nop ;                           \
46noerr:                                  \
47        jmpl    %o7+8,%g0 ;             \
48        nop
49
50/* Support for reentrant syscalls.  The "struct _reent *" arg is always the
51   the first one.  After that we allow up to four additional args.  We could
52   allow more, but that's all we need for now.
53
54   It may seem inefficient to have the reent arg be the first one as it means
55   copying all the other args into place (as opposed to making the reent arg
56   the last one in which case there wouldn't be any copying).  I chose a clean
57   design over an extra four instructions in a system call.  All other
58   reentrant functions use the first arg this way.
59   ??? Of course this scheme breaks down if we need to support 6 or more args.
60
61   And of course the system calls aren't *really* reentrant.  The intent
62   is to exercise the reentrancy framework rather than provide/claim
63   real reentrancy for this port.
64*/
65
66#define defsyscall_r(name, n) \
67        TEXT_SECTION ;                  \
68        ALIGN (4) ;                     \
69        GLOBAL (ASM_SYMBOL (name)) ;    \
70ASM_SYMBOL (name):                      \
71        mov     n,%g1 ;                 \
72        mov     %o0,%o5 ;               \
73        mov     %o1,%o0 ;               \
74        mov     %o2,%o1 ;               \
75        mov     %o3,%o2 ;               \
76        mov     %o4,%o3 ;               \
77        ta      SYSCALL_TRAP ;          \
78        bcc     noerr ;                 \
79        sethi   %hi (ASM_PRIVATE_SYMBOL (cerror_r)),%g1 ;       \
80        or      %g1,%lo (ASM_PRIVATE_SYMBOL (cerror_r)),%g1 ;   \
81        jmpl    %g1+%g0,%g0 ;           \
82        mov     %o5,%o1 ;               \
83noerr:                                  \
84        jmpl    %o7+8,%g0 ;             \
85        nop
86
87#define seterrno() \
88        sethi   %hi (ASM_PRIVATE_SYMBOL (cerror)),%g1 ;         \
89        or      %g1,%lo (ASM_PRIVATE_SYMBOL (cerror)),%g1 ;     \
90        jmpl    %g1+%g0,%g0 ;           \
91        nop
92
93#endif /* _SYSCALLASM_H_ */
Note: See TracBrowser for help on using the repository browser.