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
|
#
# $Id: prt0.as,v 1.2 2004/01/04 01:13:23 marco Exp $
# This file is part of the Free Pascal run time library.
# Copyright (c) 1999-2000 by Marco van de Voort, Michael Van Canneyt
# and Peter Vreman
# members of the Free Pascal development team.
#
# See the file COPYING.FPC, included in this distribution,
# for details about the copyright.
#
# This program 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.
#
#**********************************************************************}
#
# NetBSD standard (static) ELF/i386 startup code for Free Pascal
#
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/i386/crt0.c?rev=1.33&content-type=text/x-cvsweb-markup
.file "prt0.s"
.version "01.01"
gcc2_compiled.:
.globl __progname
.section .rodata
.LC0:
.ascii "\0"
.data
.align 4
.type __progname,@object
.size __progname,4
__progname:
.long .LC0
.globl __ps_strings
.align 4
.type __ps_strings,@object
.size __ps_strings,4
__ps_strings:
.long 0
.align 4
.ifdef CPREFIX
___fpucw:
.else
__fpucw:
.endif
.long 0x1332
.globl ___fpc_brk_addr /* heap management */
.type ___fpc_brk_addr,@object
.size ___fpc_brk_addr,4
___fpc_brk_addr:
.long 0
#APP
.text
.align 4
.globl __start
.globl _start
_start:
__start:
pushl %ebx # ps_strings
pushl %ecx # obj
pushl %edx # cleanup
movl 12(%esp),%eax
leal 20(%esp,%eax,4),%ecx
leal 16(%esp),%edx
pushl %ecx
pushl %edx
pushl %eax
call ___start
#NO_APP
.text
.align 4
.globl ___start
.type ___start,@function
___start:
pushl %ebp
movl %esp,%ebp
movl 16(%ebp),%eax
movl %eax,environ
movl %eax,operatingsystem_parameter_envp
movl 8(%ebp),%eax
movl %eax,operatingsystem_parameter_argc
movl 12(%ebp),%eax
movl %eax,operatingsystem_parameter_argv
movl (%eax),%edx
movl %edx,__progname
testl %edx,%edx
je .L2
movl __progname,%edx
// Increase until 0 found
movl $0,%ebx
.LL1:
movb (%edx,%ebx),%al
orb %al,%al
je .LL2
incl %ebx
.LL2:
decl %ebx
movb (%edx,%ebx),%al
cmpb $47,%al
je .LL3
cmpl $0,%ebx
je .LL4
.LL3: // slash found
incl %ebx
leal (%edx,%ebx),%eax
movl %eax,__progname
.LL4:
cmpl $0,__progname
jne .L3
movl 12(%ebp),%eax
movl (%eax),%edx
movl %edx,__progname
jmp .L2
.align 4
.L3:
incl __progname
.L4:
.L2:
cmpl $0,28(%ebp)
je .L5
movl 28(%ebp),%eax
movl %eax,__ps_strings
.L5:
# pushl $_fini
# call atexit
# addl $4,%esp
# call _init
# copied from linux
finit /* initialize fpu */
fwait
.ifdef CPREFIX
fldcw ___fpucw
.else
fldcw __fpucw
.endif
xorl %ebp,%ebp
.ifdef CPREFIX
call _main
.else
call main
.endif
pushl %eax
jmp _haltproc
.p2align 2,0x90
.globl _haltproc
.type _haltproc,@function
_haltproc:
mov $1,%eax
movzwl operatingsystem_result,%ebx
pushl %ebx
call _actualsyscall
addl $4,%esp
jmp _haltproc
_actualsyscall:
int $0x80
jb .LErrorcode
xor %ebx,%ebx
ret
.LErrorcode:
mov %eax,%ebx
mov $-1,%eax
ret
.p2align 2,0x90
# This section is needed for NetBSD to recognize a NetBSD binary as such.
# otherwise it will be startup in Linux emulation mode.
.section ".note.netbsd.ident","a"
.p2align 2
.long 7
.long 4
# ELF NOTE TYPE NETBSD TAG
.long 1
.ascii "NetBSD\0\0"
.long 199905
.comm environ,4,4
.comm operatingsystem_parameter_envp,4,4
.comm operatingsystem_parameter_argc,4,4
.comm operatingsystem_parameter_argv,4,4
|