File: syscall.S

package info (click to toggle)
libc-sparc 5.3.12-3
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 17,608 kB
  • ctags: 44,718
  • sloc: ansic: 163,548; asm: 5,080; makefile: 3,340; lex: 521; sh: 439; yacc: 401; awk: 28
file content (256 lines) | stat: -rw-r--r-- 6,180 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	.file	"syscall.S"

#ifdef __ELF__
#if defined(__i486__) || defined(i486)
#define ALIGN 16
#else
#define ALIGN 4
#endif
#else
#if defined(__i486__) || defined(i486)
#define ALIGN 4
#else
#define ALIGN 2
#endif
#endif

#ifdef __ELF__
#define SYMBOL_NAME(X) X
#define SYMBOL_NAME_LABEL(X) X##:
#else
#define SYMBOL_NAME(X) _##X
#define SYMBOL_NAME_LABEL(X) _##X##:
#endif

#ifdef __ELF__
#define	ENTRY(name)							      \
  .globl SYMBOL_NAME(name);						      \
  .align ALIGN;								      \
  SYMBOL_NAME_LABEL(name)
#else
#define	ENTRY(name)							      \
  .globl _##name##;							      \
  .align ALIGN;								      \
  SYMBOL_NAME_LABEL(name)
#endif

/* Use this for the different syntaxes for local assembler labels */
#ifdef __ELF__
#define L(X) .L##X
#define LF(X) .L##X
#define LL(X) .L##X##:
#else
#define L(X) X
#define LF(X) X##f
#define LL(X) X##:
#endif

#ifndef SYS_syscall
#define SYS_syscall	0
#endif

#ifdef PTHREAD_KERNEL

#ifdef __SVR4_I386_ABI_L1__

/* I don't know if it will work or not. IBCS doesn't say anything
 * about syscall. H.J. */
#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    movl $(SYS_syscall),%eax						      \
    lcall $0x7,$0

#else /* __SVR4_I386_ABI_L1__ */

#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    pushl %ebp;								      \
    movl %esp,%ebp;							      \
    PUSH_##args								      \
    MOVE_##args								      \
    int $0x80;								      \
    POP_##args								      \
    movl %ebp,%esp;							      \
    popl %ebp;
 
#endif /* __SVR4_I386_ABI_L1__ */

#else /* PTHREAD_KERNEL */

#define ERRNO_LOCATION SYMBOL_NAME(__errno_location)

#if defined(__PIC__) || defined (__pic__)

#ifdef __SVR4_I386_ABI_L1__

/* I don't know if it will work or not. IBCS doesn't say anything
 * about syscall. H.J. */
#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    movl $(SYS_syscall),%eax						      \
    lcall $0x7,$0							      \
    movl %eax,%edx;							      \
    test %edx,%edx;							      \
    jge	L(Lexit);							      \
    negl %edx;								      \
    pushl %edx;								      \
    call L(L4);								      \
   LL(L4)								      \
    popl %ebx;								      \
    addl $_GLOBAL_OFFSET_TABLE_+[.-L(L4)],%ebx;				      \
    call ERRNO_LOCATION@PLT;						      \
    popl %edx;								      \
    movl %edx,(%eax);							      \
    movl $-1,%eax;							      \
   LL(Lexit)

#else /* __SVR4_I386_ABI_L1__ */

#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    pushl %ebp;								      \
    movl %esp,%ebp;							      \
    PUSH_##args								      \
    MOVE_##args								      \
    int $0x80;								      \
    movl %eax,%edx;							      \
    test %edx,%edx;							      \
    jge	L(Lexit);							      \
    negl %edx;								      \
    pushl %edx;								      \
    call L(L4);								      \
   LL(L4)								      \
    popl %ebx;								      \
    addl $_GLOBAL_OFFSET_TABLE_+[.-L(L4)],%ebx;				      \
    call ERRNO_LOCATION@PLT;						      \
    popl %edx;								      \
    movl %edx,(%eax);							      \
    movl $-1,%eax;							      \
   LL(Lexit)								      \
    POP_##args 								      \
    movl %ebp,%esp;							      \
    popl %ebp;

#endif /* __SVR4_I386_ABI_L1__ */

#else /* PIC */

#ifdef __SVR4_I386_ABI_L1__

/* I don't know if it will work or not. IBCS doesn't say anything
 * about syscall. H.J. */
#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    movl $(SYS_syscall),%eax						      \
    lcall $0x7,$0							      \
    movl %eax,%edx;							      \
    test %edx,%edx;							      \
    jge	L(Lexit);							      \
    negl %edx;								      \
    pushl %edx;								      \
    call ERRNO_LOCATION;						      \
    popl %edx;								      \
    movl %edx,(%eax);							      \
    movl $-1,%eax;							      \
   LL(Lexit)

#else /* __SVR4_I386_ABI_L1__ */

#define	PSEUDO(name, args)						      \
  .text;								      \
  ENTRY (name)								      \
    pushl %ebp;								      \
    movl %esp,%ebp;							      \
    PUSH_##args								      \
    MOVE_##args								      \
    int $0x80;								      \
    movl %eax,%edx;							      \
    test %edx,%edx;							      \
    jge	L(Lexit);							      \
    negl %edx;								      \
    pushl %edx;								      \
    call ERRNO_LOCATION;						      \
    popl %edx;								      \
    movl %edx,(%eax);							      \
    movl $-1,%eax;							      \
   LL(Lexit)								      \
    POP_##args								      \
    movl %ebp,%esp;							      \
    popl %ebp;
 
#endif /* __SVR4_I386_ABI_L1__ */

#endif /* PIC */

#endif /* PTHREAD_KERNEL */

/* Linux takes system call arguments in registers:
	0: %eax	This is the system call number.
   	1: %ebx This is the first argument.
	2: %ecx
	3: %edx
	4: %esi
	5: %edi
 */

#if defined(__PIC__) || defined (__pic__)
#define PUSH_0	pushl %ebx;
#else
#define PUSH_0	/* No arguments to push.  */
#endif
#define PUSH_1	pushl %ebx;
#define PUSH_2	PUSH_1
#define PUSH_3	PUSH_1
#define PUSH_4	pushl %esi; PUSH_3
#define PUSH_5	pushl %edi; PUSH_4

#define	MOVE_0	movl 8(%ebp),%eax;
#define	MOVE_1	MOVE_0 movl 12(%ebp),%ebx;
#define	MOVE_2	MOVE_1 movl 16(%ebp),%ecx;
#define	MOVE_3	MOVE_2 movl 20(%ebp),%edx;
#define	MOVE_4	MOVE_3 movl 24(%ebp),%esi;
#define	MOVE_5	MOVE_4 movl 28(%ebp),%edi;

#if defined(__PIC__) || defined (__pic__)
#define POP_0	popl %ebx;
#else
#define POP_0	/* No arguments to pop.  */
#endif
#define POP_1	popl %ebx;
#define POP_2	POP_1
#define POP_3	POP_1
#define POP_4	POP_3 popl %esi;
#define POP_5	POP_4 popl %edi;

#ifdef PTHREAD_KERNEL

PSEUDO(__machdep_syscall, 5)
	ret
#ifdef __ELF__
	.type __machdep_syscall,@function
.L_machdep_syscall_end:
	.size __machdep_syscall,.L_machdep_syscall_end - __machdep_syscall
#endif

#else /* PTHREAD_KERNEL */

/* No weak syscall?. */
#undef _POSIX_THREADS

PSEUDO (syscall, 5)
	ret
#ifdef __ELF__
#ifdef _POSIX_THREADS
	.weak syscall
#endif
	.type syscall,@function
.L_syscall_end:
	.size syscall,.L_syscall_end - syscall
#endif

#endif /* PTHREAD_KERNEL */