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
|
/
/ File: ithread.s
/ Author: John van Groningen
/ Machine: Intel 386
#define d0 %eax
#define d1 %ebx
#define a0 %ecx
#define a1 %edx
#define a2 %ebp
#define a3 %esi
#define a4 %edi
#define sp %esp
#define d0w %ax
#define d1w %bx
#define a0w %cx
#define a1w %dx
#define a2w %bp
#define a3w %si
#define a4w %di
#define d0b %al
#define d1b %bl
#define a0b %cl
#define a1b %dl
#define d0lb %al
#define d0hb %ah
#define d1lb %bl
#define d1hb %bh
.text
.globl @GetProcessHeap?0
.globl @HeapAlloc?12
.globl @clean_new_thread
@clean_new_thread:
call @GetProcessHeap?0
pushl $256
pushl $0
push d0
call @HeapAlloc?12
movl d0,a4
movl tlsp_tls_index,d0
movl a4,%fs:0x0e10(,d0,4)
movl 4(sp),a0
movl 4(a0),d1
test d1,d1
jne clean_new_thread_1
movl main_thread_local_storage+heap_size_offset,d1
clean_new_thread_1:
movl d1,heap_size_offset(a4)
movl 8(a0),d1
test d1,d1
jne clean_new_thread_2
movl main_thread_local_storage+a_stack_size_offset,d1
clean_new_thread_2:
movl d1,a_stack_size_offset(a4)
call init_thread
movl a3,saved_a_stack_p_offset(a4)
movl sp,halt_sp_offset (a4)
movl 4(sp),d0
push d0
call *(d0)
addl $4,sp
movl tlsp_tls_index,a4
movl %fs:0x0e10(,a4,4),a4
jmp exit_thread
init_thread:
movl heap_size_offset(a4),d0
#ifdef PREFETCH2
sub $63,d0
#else
sub $3,d0
#endif
xorl a1,a1
mov $33,d1
div d1
movl d0,heap_size_33_offset(a4)
movl heap_size_offset(a4),d0
sub $3,d0
xorl a1,a1
mov $129,d1
div d1
mov d0,heap_size_129_offset(a4)
add $3,d0
andl $-4,d0
movl d0,heap_copied_vector_size_offset(a4)
movl $0,heap_end_after_copy_gc_offset(a4)
movl heap_size_offset(a4),d0
add $7,d0
push d0
#ifdef USE_CLIB
call @malloc
#else
call @allocate_memory
#endif
add $4,sp
test d0,d0
je init_thread_no_memory_2
mov d0,heap_mbp_offset(a4)
addl $3,d0
and $-4,d0
mov d0,free_heap_offset(a4)
mov d0,heap_p_offset(a4)
movl a_stack_size_offset(a4),a2
add $3,a2
push a2
#ifdef STACK_OVERFLOW_EXCEPTION_HANDLER
call @allocate_memory_with_guard_page_at_end
#else
# ifdef USE_CLIB
call @malloc
# else
call @allocate_memory
# endif
#endif
add $4,sp
test d0,d0
je init_thread_no_memory_3
mov d0,stack_mbp_offset(a4)
#ifdef STACK_OVERFLOW_EXCEPTION_HANDLER
addl a_stack_size_offset(a4),d0
addl $3+4095,d0
andl $-4096,d0
movl d0,a_stack_guard_page
subl a_stack_size_offset(a4),d0
#endif
add $3,d0
andl $-4,d0
mov d0,a3
mov d0,stack_p_offset(a4)
/ lea caf_list+4,a0
/ movl a0,caf_listp
/ #ifdef FINALIZERS
/ movl $__Nil-4,finalizer_list
/ movl $__Nil-4,free_finalizer_list
/ #endif
mov free_heap_offset(a4),a1
mov a1,heap_p1_offset(a4)
movl heap_size_129_offset(a4),a2
shl $4,a2
lea (a1,a2,4),d0
mov d0,heap_copied_vector_offset(a4)
add heap_copied_vector_size_offset(a4),d0
mov d0,heap_p2_offset(a4)
movb $0,garbage_collect_flag_offset(a4)
# ifdef MARK_AND_COPY_GC
testb $64,@flags
je init_thread_no_mark1
# endif
# if defined (MARK_GC) || defined (COMPACT_GC_ONLY)
movl heap_size_33_offset(a4),d0
movl a1,heap_vector_offset(a4)
addl d0,a1
# ifdef PREFETCH2
addl $63,a1
andl $-64,a1
# else
addl $3,a1
andl $-4,a1
# endif
movl a1,free_heap_offset(a4)
movl a1,heap_p3_offset(a4)
lea (,d0,8),a2
movb $-1,garbage_collect_flag_offset(a4)
# endif
# ifdef MARK_AND_COPY_GC
init_thread_no_mark1:
# endif
# ifdef ADJUST_HEAP_SIZE
movl @initial_heap_size,d0
# ifdef MARK_AND_COPY_GC
movl $(MINIMUM_HEAP_SIZE_2),d1
testb $64,@flags
jne init_thread_no_mark9
addl d1,d1
init_thread_no_mark9:
# else
# if defined (MARK_GC) || defined (COMPACT_GC_ONLY)
movl $(MINIMUM_HEAP_SIZE),d1
# else
movl $(MINIMUM_HEAP_SIZE_2),d1
# endif
# endif
cmpl d1,d0
jle init_thread_too_large_or_too_small
shr $2,d0
cmpl a2,d0
jge init_thread_too_large_or_too_small
movl d0,a2
init_thread_too_large_or_too_small:
# endif
lea (a1,a2,4),d0
mov d0,heap_end_after_gc_offset(a4)
subl $32,d0
movl d0,end_heap_offset(a4)
# ifdef MARK_AND_COPY_GC
testb $64,@flags
je init_thread_no_mark2
# endif
# if defined (MARK_GC) && defined (ADJUST_HEAP_SIZE)
movl a2,bit_vector_size_offset(a4)
# endif
# ifdef MARK_AND_COPY_GC
init_thread_no_mark2:
# endif
movl $0,bit_counter_offset(a4)
movl $0,zero_bits_before_mark_offset(a4)
xor %eax,%eax
ret
init_thread_no_memory_2:
movl $1,%eax
ret
init_thread_no_memory_3:
push heap_mbp_offset(a4)
#ifdef USE_CLIB
call @free
#else
call @free_memory
#endif
add $4,sp
movl $1,%eax
ret
exit_thread:
call add_execute_time
push stack_mbp_offset(a4)
#ifdef USE_CLIB
call @free
#else
call @free_memory
#endif
add $4,sp
push heap_mbp_offset(a4)
#ifdef USE_CLIB
call @free
#else
call @free_memory
#endif
add $4,sp
call @GetProcessHeap?0
pushl a4
pushl $0
push d0
call @HeapFree?12
ret
|