Commit | Line | Data |
---|---|---|
db72cd09 | 1 | /*- |
2ae79493 KB |
2 | * Copyright (c) 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
db72cd09 WN |
4 | * |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * William Jolitz. | |
7 | * | |
4b25475a | 8 | * %sccs.include.redist.c% |
db72cd09 | 9 | * |
2ae79493 | 10 | * @(#)srt0.c 8.1 (Berkeley) %G% |
db72cd09 WN |
11 | */ |
12 | ||
13 | /* | |
14 | * Startup code for standalone system | |
15 | * Non-relocating version -- for programs which are loaded by boot | |
16 | * Relocating version for boot | |
ab3a4516 | 17 | * Small relocating version for "micro" boot |
db72cd09 WN |
18 | */ |
19 | ||
20 | .globl _end | |
21 | .globl _edata | |
22 | .globl _main | |
23 | .globl __rtt | |
24 | .globl _exit | |
db72cd09 | 25 | .globl _bootdev |
ab3a4516 | 26 | .globl _cyloffset |
db72cd09 | 27 | |
ab3a4516 WN |
28 | #ifdef SMALL |
29 | /* where the disklabel goes if we have one */ | |
30 | .globl _disklabel | |
31 | _disklabel: | |
32 | .space 512 | |
33 | #endif | |
db72cd09 WN |
34 | |
35 | entry: .globl entry | |
ab3a4516 WN |
36 | .globl start |
37 | ||
38 | #if defined(REL) && !defined(SMALL) | |
39 | ||
40 | /* relocate program and enter at symbol "start" */ | |
41 | ||
42 | #movl $entry-RELOC,%esi # from beginning of ram | |
db72cd09 | 43 | movl $0,%esi |
ab3a4516 WN |
44 | #movl $entry,%edi # to relocated area |
45 | movl $ RELOC,%edi # to relocated area | |
db72cd09 WN |
46 | # movl $_edata-RELOC,%ecx # this much |
47 | movl $64*1024,%ecx | |
48 | cld | |
49 | rep | |
50 | movsb | |
ab3a4516 WN |
51 | # relocate program counter to relocation base |
52 | pushl $start | |
db72cd09 | 53 | ret |
db72cd09 | 54 | #endif |
ab3a4516 WN |
55 | |
56 | start: | |
57 | ||
58 | /* setup stack pointer */ | |
59 | ||
60 | #ifdef REL | |
61 | leal 4(%esp),%eax /* ignore old pc */ | |
62 | movl $ RELOC-4*4,%esp | |
63 | /* copy down boot parameters */ | |
64 | movl %esp,%ebx | |
65 | pushl $3*4 | |
66 | pushl %ebx | |
67 | pushl %eax | |
68 | call _bcopy | |
69 | movl %ebx,%esp | |
70 | #else | |
71 | /* save old stack state */ | |
72 | movl %esp,savearea | |
73 | movl %ebp,savearea+4 | |
74 | movl $ RELOC-0x2400,%esp | |
75 | #endif | |
76 | ||
77 | /* clear memory as needed */ | |
78 | ||
79 | movl %esp,%esi | |
80 | #ifdef REL | |
81 | ||
82 | /* | |
83 | * Clear Bss and up to 64K heap | |
84 | */ | |
85 | movl $64*1024,%ebx | |
86 | movl $_end,%eax # should be movl $_end-_edata but ... | |
87 | subl $_edata,%eax | |
88 | addl %ebx,%eax | |
89 | pushl %eax | |
90 | pushl $_edata | |
91 | call _bzero | |
92 | ||
93 | /* | |
94 | * Clear 64K of stack | |
95 | */ | |
96 | movl %esi,%eax | |
97 | subl %ebx,%eax | |
98 | subl $5*4,%ebx | |
99 | pushl %ebx | |
100 | pushl %eax | |
101 | call _bzero | |
102 | #else | |
103 | movl $_edata,%edx | |
104 | movl %esp,%eax | |
105 | subl %edx,%eax | |
106 | pushl %edx | |
107 | pushl %esp | |
108 | call _bzero | |
109 | #endif | |
110 | movl %esi,%esp | |
111 | ||
db72cd09 WN |
112 | pushl $0 |
113 | popf | |
ab3a4516 WN |
114 | |
115 | #ifndef SMALL | |
116 | call _kbdreset /* resets keyboard and gatea20 brain damage */ | |
117 | #endif | |
118 | ||
db72cd09 | 119 | call _main |
db72cd09 | 120 | jmp 1f |
db72cd09 WN |
121 | |
122 | .data | |
db72cd09 | 123 | _bootdev: .long 0 |
ab3a4516 | 124 | _cyloffset: .long 0 |
db72cd09 WN |
125 | savearea: .long 0,0 # sp & bp to return to |
126 | .text | |
ab3a4516 | 127 | #ifndef SMALL |
db72cd09 | 128 | .globl _getchar |
ab3a4516 | 129 | #endif |
db72cd09 WN |
130 | .globl _wait |
131 | ||
132 | __rtt: | |
ab3a4516 | 133 | #ifndef SMALL |
db72cd09 | 134 | call _getchar |
ab3a4516 WN |
135 | #else |
136 | _exit: | |
db72cd09 WN |
137 | pushl $1000000 |
138 | call _wait | |
139 | popl %eax | |
ab3a4516 | 140 | #endif |
db72cd09 WN |
141 | movl $-7,%eax |
142 | jmp 1f | |
ab3a4516 | 143 | #ifndef SMALL |
db72cd09 WN |
144 | _exit: |
145 | call _getchar | |
ab3a4516 WN |
146 | #endif |
147 | movl 4(%esp),%eax | |
db72cd09 WN |
148 | 1: |
149 | #ifdef REL | |
ab3a4516 WN |
150 | #ifndef SMALL |
151 | call _reset_cpu | |
152 | #endif | |
db72cd09 WN |
153 | movw $0x1234,%ax |
154 | movw %ax,0x472 # warm boot | |
155 | movl $0,%esp # segment violation | |
156 | ret | |
db72cd09 WN |
157 | #else |
158 | movl savearea,%esp | |
159 | movl savearea+4,%ebp | |
160 | ret | |
161 | #endif | |
db72cd09 WN |
162 | |
163 | .globl _inb | |
164 | _inb: movl 4(%esp),%edx | |
165 | subl %eax,%eax # clr eax | |
db72cd09 | 166 | inb %dx,%al |
db72cd09 WN |
167 | ret |
168 | ||
169 | .globl _outb | |
170 | _outb: movl 4(%esp),%edx | |
171 | movl 8(%esp),%eax | |
db72cd09 | 172 | outb %al,%dx |
db72cd09 WN |
173 | ret |
174 | ||
175 | .globl ___udivsi3 | |
176 | ___udivsi3: | |
177 | movl 4(%esp),%eax | |
178 | xorl %edx,%edx | |
179 | divl 8(%esp) | |
180 | ret | |
181 | ||
182 | .globl ___divsi3 | |
183 | ___divsi3: | |
184 | movl 4(%esp),%eax | |
185 | xorl %edx,%edx | |
186 | cltd | |
187 | idivl 8(%esp) | |
188 | ret | |
189 | ||
190 | # | |
191 | # bzero (base,cnt) | |
192 | # | |
193 | ||
194 | .globl _bzero | |
195 | _bzero: | |
196 | pushl %edi | |
197 | movl 8(%esp),%edi | |
198 | movl 12(%esp),%ecx | |
199 | movb $0x00,%al | |
200 | cld | |
201 | rep | |
202 | stosb | |
203 | popl %edi | |
204 | ret | |
205 | ||
206 | # | |
207 | # bcopy (src,dst,cnt) | |
208 | # NOTE: does not (yet) handle overlapped copies | |
209 | # | |
210 | ||
211 | .globl _bcopy | |
212 | _bcopy: | |
213 | pushl %esi | |
214 | pushl %edi | |
215 | movl 12(%esp),%esi | |
216 | movl 16(%esp),%edi | |
217 | movl 20(%esp),%ecx | |
218 | cld | |
219 | rep | |
220 | movsb | |
221 | popl %edi | |
222 | popl %esi | |
223 | ret | |
224 | ||
225 | # insw(port,addr,cnt) | |
226 | .globl _insw | |
227 | _insw: | |
228 | pushl %edi | |
229 | movw 8(%esp),%dx | |
230 | movl 12(%esp),%edi | |
231 | movl 16(%esp),%ecx | |
232 | cld | |
233 | nop | |
234 | .byte 0x66,0xf2,0x6d # rep insw | |
235 | nop | |
236 | movl %edi,%eax | |
237 | popl %edi | |
238 | ret | |
239 | ||
240 | # outsw(port,addr,cnt) | |
241 | .globl _outsw | |
242 | _outsw: | |
243 | pushl %esi | |
244 | movw 8(%esp),%dx | |
245 | movl 12(%esp),%esi | |
246 | movl 16(%esp),%ecx | |
247 | cld | |
248 | nop | |
249 | .byte 0x66,0xf2,0x6f # rep outsw | |
250 | nop | |
251 | movl %esi,%eax | |
252 | popl %esi | |
253 | ret | |
254 |