OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [sys/] [go32/] [crt0.S] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
 
2
/*
3
**      Called as start(argc, argv, envp)
4
*/
5
 
6
/*      gs:edx points to prog_info structure.  All other registers are OBSOLETE
7
**      but included for backwards compatibility
8
*/
9
 
10
/* These symbols are for global constructors and destructors */
11
#if 0
12
        .section        .ctor
13
        .globl          ___go32_first_ctor
14
___go32_first_ctor:
15
        .section        .dtor
16
        .globl          ___go32_last_ctor
17
___go32_last_ctor:
18
        .globl          ___go32_first_dtor
19
___go32_first_dtor:
20
        .data
21
        .globl          ___go32_last_dtor
22
___go32_last_dtor:
23
#endif
24
        .text
25
        .globl  _start
26
_start:
27
        .globl  start
28
start:
29
#ifdef EMU387
30
        pusha
31
        push    %gs
32
#endif
33
        movl    %eax,__hard_master
34
        movl    %esi,___pid
35
        movl    %edi,___transfer_buffer
36
        movl    %ebx,_ScreenPrimary
37
        movl    %ebp,_ScreenSecondary
38
 
39
        cmpl    $0, %edx
40
        je      Lcopy_none
41
        movw    %gs,%cx
42
        movw    %ds,%ax
43
        cmpw    %cx,%ax
44
        je      Lcopy_none
45
 
46
        movl    %gs:(%edx), %ecx
47
        cmpl    __go32_info_block, %ecx
48
        jbe     Lcopy_less
49
        movl    __go32_info_block, %ecx
50
Lcopy_less:
51
        movl    $__go32_info_block, %edi
52
        addl    $3, %ecx
53
        andl    $0xfffffffc, %ecx
54
        movl    %ecx, (%edi)
55
        addl    $4, %edi
56
        addl    $4, %edx
57
        subl    $4, %ecx
58
Lcopy_more:
59
        movl    %gs:(%edx), %eax
60
        movl    %eax, (%edi)
61
        addl    $4, %edx
62
        addl    $4, %edi
63
        subl    $4, %ecx
64
        jnz     Lcopy_more
65
 
66
        movl    __go32_info_block+4, %eax
67
        movl    %eax, _ScreenPrimary
68
        movl    __go32_info_block+8, %eax
69
        movl    %eax, _ScreenSecondary
70
/* Backward compatibility - do not copy this one!
71
**      movl    __go32_info_block+12, %eax
72
**      movl    %eax, ___transfer_buffer
73
*/
74
        movl    __go32_info_block+20, %eax
75
        movl    %eax, ___pid
76
        movl    __go32_info_block+24, %eax
77
        movl    %eax, __hard_master
78
 
79
        jmp     Lcopy_done
80
 
81
Lcopy_none:
82
        movl    %ebx,__go32_info_block+4
83
        movl    %ebp,__go32_info_block+8
84
        movl    %edi,__go32_info_block+12
85
        movl    $4096,__go32_info_block+16
86
        movl    %esi,__go32_info_block+20
87
        movl    %eax,__go32_info_block+24
88
        movl    $28, __go32_info_block
89
Lcopy_done:
90
 
91
#ifndef EMU387
92
        call    __setstack
93
#endif
94
        xorl    %esi,%esi
95
        xorl    %edi,%edi
96
        xorl    %ebp,%ebp
97
        xorl    %ebx,%ebx
98
 
99
        movl    %esp,%ebx
100
#ifdef MAKE_GCRT0
101
        call    mcount_init /* initialize the profiler */
102
#endif
103
        movl    8(%ebx),%eax
104
        pushl   %eax
105
        movl    %eax,_environ
106
        pushl   4(%ebx)
107
        pushl   (%ebx)
108
        call    ___main
109
        call    _main
110
        addl    $12,%esp
111
#ifdef EMU387
112
        pop     %gs
113
        popa
114
#else
115
        pushl   %eax
116
        call    _exit
117
 
118
exit_again:
119
        movl    $0x4c00,%eax
120
        int     $0x21
121
        jmp     exit_again
122
#endif
123
 
124
        ret
125
 
126
 
127
#ifdef MAKE_GCRT0
128
        .globl  __exit
129
__exit:
130
        call    mcount_write /* make sure we dump the output */
131
exit_again2:
132
        movb    4(%esp),%al
133
        movb    $0x4c,%ah
134
        int     $0x21
135
        jmp     exit_again2
136
 
137
/* Here is where we initialize the timer interrupt - specific to go32 */
138
/* In this case, the timer calls mcount_isr */
139
        .globl  mcount_isr_init
140
mcount_isr_init:
141
        movw    __go32_info_block+36, %ax       /* run mode */
142
        cmp     $1,%ax
143
        jb      skip_mcount
144
        cmp     $3,%ax
145
        ja      skip_mcount
146
 
147
        movw    $16,%ax
148
        movw    %ax,%gs
149
 
150
        movzbl  __hard_master,%eax      /* timer is on irq 0 */
151
        shll    $3,%eax /* times 8 bpv */
152
/*      movl    $960,%eax          vector 0x78 * 8 bpv */
153
        movw    %gs:(%eax),%cx
154
        movw    %cx,mc_chain
155
        movw    %gs:6(%eax),%cx
156
        movw    %cx,mc_chain_hi
157
        movw    %gs:2(%eax),%cx
158
        movw    %cx,mc_chain_sel
159
 
160
        movl    $mcount_isr,%ecx
161
        movw    %cx,%gs:(%eax)
162
        movw    $0xd8,%gs:2(%eax)       /* selector 27 == 32-bit code */
163
        movw    $0x8f00,%gs:4(%eax)
164
        rorl    $16,%ecx
165
        movw    %cx,%gs:6(%eax)
166
        movw    %ds,%ax
167
        movw    %ax,%gs
168
skip_mcount:
169
        movl    mcount_histogram,%eax
170
        movl    $1,(%eax)
171
        ret
172
 
173
/* Obtain the PC where we interrupted, and bump the histogram.  We should  */
174
/* do error checking here, but we don't.  This routine is specific to go32 */
175
/* in some spots */
176
mcount_isr:
177
        pushl   %eax
178
        cmpl    $1,mcount_skip
179
        je      L0
180
        movl    4(%esp),%eax /* get the PC */
181
        subl    $0x1020,%eax /* to fit in low..high */
182
        andl    $0xfffffffc,%eax
183
        shrl    $1,%eax /* now points to one 4-byte entry */
184
        addl    mcount_histogram,%eax
185
        incw    (%eax)
186
L0:
187
        popl    %eax
188
        ljmp    mc_chain /* chain to the next timer vector */
189
        iret
190
#endif
191
 
192
        .data
193
 
194
        .globl  _environ
195
_environ:
196
        .long   0
197
 
198
        .globl  ___pid
199
___pid:
200
        .long   42
201
 
202
        .globl  ___transfer_buffer
203
___transfer_buffer:
204
        .long   0
205
 
206
        .globl  _ScreenPrimary
207
_ScreenPrimary:
208
        .long   0
209
 
210
        .globl  _ScreenSecondary
211
_ScreenSecondary:
212
        .long   0
213
 
214
        .globl  __hard_master
215
        .globl  __hard_slave
216
        .globl  __core_select
217
__hard_master:
218
        .byte   0
219
__hard_slave:
220
        .byte   0
221
__core_select:
222
        .short  0
223
 
224
#ifdef MAKE_GCRT0
225
mc_chain:
226
        .short  0
227
mc_chain_hi:
228
        .short  0
229
mc_chain_sel:
230
        .short  0
231
#endif
232
 
233
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.