-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlibcgc.s
236 lines (207 loc) · 2.92 KB
/
libcgc.s
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
.macro sys_call n
movl $\n, %eax
.endm
.macro do_syscall
int $0x80
.endm
.macro syscall_arg_1
pushl %ebx
movl 8(%esp), %ebx
do_syscall
popl %ebx
ret
.endm
.macro syscall_arg_2
pushl %ebx
pushl %ecx
movl 12(%esp), %ebx
movl 16(%esp), %ecx
do_syscall
popl %ecx
popl %ebx
ret
.endm
.macro syscall_arg_3
pushl %ebx
pushl %ecx
pushl %edx
movl 16(%esp), %ebx
movl 20(%esp), %ecx
movl 24(%esp), %edx
do_syscall
popl %edx
popl %ecx
popl %ebx
ret
.endm
.macro syscall_arg_4
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
movl 20(%esp), %ebx
movl 24(%esp), %ecx
movl 28(%esp), %edx
movl 32(%esp), %esi
do_syscall
popl %esi
popl %edx
popl %ecx
popl %ebx
ret
.endm
.macro syscall_arg_5
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
movl 24(%esp), %ebx
movl 28(%esp), %ecx
movl 32(%esp), %edx
movl 36(%esp), %esi
movl 40(%esp), %edi
do_syscall
popl %edi
popl %esi
popl %edx
popl %ecx
popl %ebx
ret
.endm
.macro syscall_arg_6
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
pushl %ebp
movl 28(%esp), %ebx
movl 32(%esp), %ecx
movl 36(%esp), %edx
movl 40(%esp), %esi
movl 44(%esp), %edi
movl 48(%esp), %ebp
do_syscall
popl %ebp
popl %edi
popl %esi
popl %edx
popl %ecx
popl %ebx
ret
.endm
.macro ENTER base
.global \base
.type \base, @function
\base:
.endm
.macro SENTER base
.type \base, @function
\base:
.endm
.macro END base
.size \base, . - \base
.endm
ENTER _start
call _crcx
call main
pushl %eax
call _terminate
END _start
ENTER _terminate
sys_call 1
syscall_arg_1
END _terminate
ENTER transmit
sys_call 2
syscall_arg_4
END transmit
ENTER receive
sys_call 3
syscall_arg_4
END receive
ENTER fdwait
sys_call 4
syscall_arg_5
END fdwait
ENTER allocate
sys_call 5
syscall_arg_3
END allocate
ENTER deallocate
sys_call 6
syscall_arg_2
END deallocate
ENTER random
sys_call 7
syscall_arg_3
END random
ENTER setjmp
movl 4(%esp), %ecx
movl 0(%esp), %edx
movl %edx, 0(%ecx)
movl %ebx, 4(%ecx)
movl %esp, 8(%ecx)
movl %ebp, 12(%ecx)
movl %esi, 16(%ecx)
movl %edi, 20(%ecx)
xorl %eax, %eax
ret
END setjmp
ENTER longjmp
movl 4(%esp), %edx
movl 8(%esp), %eax
movl 0(%edx), %ecx
movl 4(%edx), %ebx
movl 8(%edx), %esp
movl 12(%edx), %ebp
movl 16(%edx), %esi
movl 20(%edx), %edi
testl %eax, %eax
jnz 1f
incl %eax
1: movl %ecx, 0(%esp)
ret
END longjmp
.macro push_crc_arg n
.weak \n
pushl $\n
.endm
SENTER _crcx
pushl $0
push_crc_arg _binary_build_release_dpkg_o_txt_start
push_crc_arg _binary_build_release_dpkg_o_txt_end
call _crcx_docrc
addl $12, %esp
pushl $0
pushl $0
pushl $0
pushl $0
pushl $0
pushl $0
addl $6*4, %esp
pushfl
popl %eax
andl $~0xc4, %eax
pushl %eax
popfl
pushl $0
popl %eax
ret
END _crcx
SENTER _crcx_docrc
pushl %esi
pushl %ecx
movl 12(%esp), %ecx
movl 16(%esp), %esi
movl 20(%esp), %eax
subl %esi, %ecx
jz 2f
1: xorb (%esi), %al
inc %esi
loop 1b
2: popl %ecx
popl %esi
ret
END _crcx_docrc