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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
/*#######################################################################
# RDOS operating system
# Copyright (C) 1988-2006, Leif Ekblad
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The author of this program may be contacted at leif@rdos.net
#
# crt0.S
# GCC startupcode for RDOS
#
##########################################################################*/
#include "user.def"
KEY_ENTRIES = 256
.macro UserGate nr
.byte 0x9A
.long \nr
.word 2
.endm
.data
.align 8
_key_section:
.word 0
_key_ref_arr:
.long 0
_key_dtor_arr:
.long 0
.text
.align 4
/*##########################################################################
#
# Name : _start
#
# Purpose....: GCC startup-code
#
##########################################################################*/
.global _start
_start:
call get_impure_data_size
movl %eax,%ecx
UserGate allocate_app_mem_nr
xorl %eax,%eax
.byte 0x64
movl %edx,(%eax)
movl %edx,%edi
rep
stosb
pushl %edx
movl $(4 * KEY_ENTRIES),%eax
movl %eax,%ecx
UserGate allocate_app_mem_nr
movl $4,%eax
.byte 0x64
movl %edx,(%eax)
movl %edx,%edi
xorl %eax,%eax
rep
stosb
movl $(4 * KEY_ENTRIES),%eax
movl %eax,%ecx
UserGate allocate_app_mem_nr
movl %edx,_key_ref_arr
movl %edx,%edi
xorl %eax,%eax
rep
stosb
movl $(4 * KEY_ENTRIES),%eax
movl %eax,%ecx
UserGate allocate_app_mem_nr
movl %edx,_key_dtor_arr
movl %edx,%edi
xorl %eax,%eax
rep
stosb
UserGate create_user_section_nr
movw %bx,_key_section
call __init_rdos
add $4, %esp
movl $0x1000,%eax
UserGate allocate_app_mem_nr
pushl %edx
UserGate get_cmd_line_nr
xorl %ecx,%ecx
xorb %ah,%ah
arg_loop:
movl %edi,(%edx)
addl $4,%edx
movb (%edi),%al
orb %al,%al
je arg_done
arg_scan:
movb (%edi),%al
orb %al,%al
je next_arg
cmpb $0x22,%al
jne arg_no_quote
xorb $1,%ah
jmp arg_scan_next
arg_no_quote:
orb %ah,%ah
jnz arg_scan_next
cmpb $0x20,%al
je next_arg
cmpb $0x8,%al
je next_arg
arg_scan_next:
incl %edi
jmp arg_scan
next_arg:
incl %ecx
to_next_arg:
orb %al,%al
je arg_done
xorb %al,%al
movb %al,(%edi)
incl %edi
movb (%edi),%al
cmpb $0x20,%al
je to_next_arg
cmpb $0x8,%al
je to_next_arg
jmp arg_loop
arg_done:
int $3
pushl %ecx
call main
add $8, %esp
pushl %eax
call exit
/*##########################################################################
#
# Name : _exit
#
# Purpose....: GCC exit-code
#
##########################################################################*/
.global _exit
_exit:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
UserGate unload_exe_nr
/*##########################################################################
#
# Name : __getreent
#
# Purpose....: ?
#
##########################################################################*/
.global __getreent
__getreent:
xorl %eax,%eax
.byte 0x64
movl (%eax),%eax
ret
/*##########################################################################
#
# Name : __rdos_thread_key_create
#
# Purpose....: Emulate GCC pthread_key_create
#
# Parameters.: dtor
#
# Returns....: Key index
#
##########################################################################*/
.global __rdos_thread_key_create
__rdos_thread_key_create:
int $3
pushl %ebp
movl %esp,%ebp
pushl %ebx
pushl %ecx
mov _key_section,%bx
UserGate enter_user_section_nr
movl _key_ref_arr,%ebx
movl KEY_ENTRIES,%ecx
rtkc_scan_loop:
movl (%ebx), %eax
orl %eax, %eax
jz rtkc_entry_found
add $4, %ebx
loop rtkc_scan_loop
movl $-1, %eax
jmp rtkc_leave
rtkc_entry_found:
movb $255,3(%ebx)
subl _key_ref_arr,%ebx
addl _key_dtor_arr,%ebx
movl 8(%ebp),%eax
movl %eax,(%ebx)
subl _key_dtor_arr,%ebx
movl %ebx,%eax
rtkc_leave:
mov _key_section, %bx
UserGate leave_user_section_nr
popl %ecx
popl %ebx
leave
ret
/*##########################################################################
#
# Name : __rdos_thread_key_delete
#
# Purpose....: Emulate GCC pthread_key_delete
#
# Parameters.: index
#
# Returns....: result
#
##########################################################################*/
.global __rdos_thread_key_delete
__rdos_thread_key_delete:
int $3
pushl %ebp
movl %esp,%ebp
pushl %ebx
mov _key_section,%bx
UserGate enter_user_section_nr
movl 8(%ebp),%ebx
testb $3,%bl
jnz rtkd_fail
cmpl $(4 * KEY_ENTRIES),%ebx
jae rtkd_fail
addl _key_ref_arr,%ebx
movb $0,3(%ebx)
mov (%ebx),%eax
orl %eax,%eax
jz rtkd_ok
subl _key_ref_arr,%ebx
movl $0,(%ebx)
jmp rtkd_ok
rtkd_fail:
movl $1,%eax
jmp rtkd_leave
rtkd_ok:
xorl %eax,%eax
rtkd_leave:
mov _key_section, %bx
UserGate leave_user_section_nr
popl %ebx
leave
ret
/*##########################################################################
#
# Name : __rdos_thread_getspecific
#
# Purpose....: Emulate GCC pthread_getspecific
#
# Parameters.: index
#
# Returns....: value
#
##########################################################################*/
.global __rdos_thread_getspecific
__rdos_thread_getspecific:
int $3
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 8(%ebp),%ebx
testb $3,%bl
jnz rtg_fail
cmpl $(4 * KEY_ENTRIES),%ebx
jae rtg_fail
movl $4,%eax
.byte 0x64
movl (%eax),%eax
addl %eax,%ebx
movl (%ebx),%eax
jmp rtg_done
rtg_fail:
xorl %eax,%eax
rtg_done:
popl %ebx
leave
ret
/*##########################################################################
#
# Name : __rdos_thread_setspecific
#
# Purpose....: Emulate GCC pthread_setspecific
#
# Parameters.: index
# value
#
##########################################################################*/
.global __rdos_thread_setspecific
__rdos_thread_setspecific:
int $3
pushl %ebp
movl %esp,%ebp
pushl %ebx
pushl %ecx
movl 8(%ebp),%ebx
testb $3,%bl
jnz rts_fail
cmpl $(4 * KEY_ENTRIES),%ebx
jae rts_fail
movl $4,%eax
.byte 0x64
movl (%eax),%eax
addl %eax,%ebx
movl 12(%ebp),%eax
movl %eax,(%ebx)
xorl %eax,%eax
jmp rts_done
rts_fail:
movl $1,%eax
rts_done:
popl %ebx
leave
ret
|