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
|
.global _start
_start: // in the beginning...
//push %ebx // do we need to persist them???
//push %ecx
//cmp $0,_impure_ptr
//jne skipzero
//movl $0xf5000000, _impure_ptr
//mov $0xf5000000,%ebx
//allzero:
//movl $0, (%ebx)
//add $4, %ebx
//cmp $0xf5001000,%ebx
//jne allzero
//skipzero:
///////////////////////////////////////////////////////////////////////
// move impure pointer to our special page (todo: check if not htere already!)
mov _impure_ptr,%eax
mov $0xf5000000,%ebx
copy:
mov (%eax),%ecx
mov %ecx,(%ebx)
add $4, %ebx
add $4, %eax
cmp $0xf5001000,%ebx
jne copy
movl $0xf5000000, _impure_ptr
////////////////////////////////////////////////////////////////////////
call _init // constructors from .ctors
///////////////////////////////////////////////////////////////////////
// constructors from array_init ////////////////////////////
mov $__init_array_start,%eax
nextctor:
//cmp (__init_array_end),%eax
cmp $__init_array_end,%eax
je finctor
push %eax
call *(%eax)
pop %eax
add $4, %eax
jmp nextctor
finctor: // ready with global ctors
////////////////////////////////////////////////////////////////////////
//pop %ecx
//pop %ebx
###############################################
# environment adress was passed on stack
pop %eax
mov %eax, environ
###############################################
pop %ecx //argc
pop %ebx //& argv
and $-16,%esp //align stack
sub $8,%esp
push %ebx //argv
push %ecx //& argc
# call main (argc and argv are on the (realigned) tack)
call main
// ALIGN stack again (todo: do we need this!??!!)
and $-16,%esp
sub $4,%esp
push %eax
call _fini //desctructors from .dtors
// pop programmm return value
pop %eax
// ALIGN stack (???)
and $-16,%esp
sub $4,%esp
push stdout
call fflush
# push exit code and pass to _exit syscall
push %eax
call exit
# and this should never be reached!!
.wait:
hlt
jmp .wait
|