xref: /original-bsd/sys/i386/stand/srt0.c (revision 3705696b)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)srt0.c	8.1 (Berkeley) 06/11/93
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
17  * Small relocating version for "micro" boot
18  */
19 
20 	.globl	_end
21 	.globl	_edata
22 	.globl	_main
23 	.globl	__rtt
24 	.globl	_exit
25 	.globl	_bootdev
26 	.globl	_cyloffset
27 
28 #ifdef SMALL
29 	/* where the disklabel goes if we have one */
30 	.globl	_disklabel
31 _disklabel:
32 	.space 512
33 #endif
34 
35 entry:	.globl	entry
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
43 	movl	$0,%esi
44 	#movl	$entry,%edi		# to relocated area
45 	movl	$ RELOC,%edi		# to relocated area
46 	# movl	$_edata-RELOC,%ecx	# this much
47 	movl	$64*1024,%ecx
48 	cld
49 	rep
50 	movsb
51 	# relocate program counter to relocation base
52 	pushl	$start
53 	ret
54 #endif
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 
112 	pushl	$0
113 	popf
114 
115 #ifndef	SMALL
116 	call	_kbdreset	/* resets keyboard and gatea20 brain damage */
117 #endif
118 
119 	call	_main
120 	jmp	1f
121 
122 	.data
123 _bootdev:	.long	0
124 _cyloffset:	.long	0
125 savearea:	.long	0,0	# sp & bp to return to
126 	.text
127 #ifndef	SMALL
128 	.globl _getchar
129 #endif
130 	.globl _wait
131 
132 __rtt:
133 #ifndef	SMALL
134 	call	_getchar
135 #else
136 _exit:
137 	pushl	$1000000
138 	call	_wait
139 	popl	%eax
140 #endif
141 	movl	$-7,%eax
142 	jmp	1f
143 #ifndef	SMALL
144 _exit:
145 	call	_getchar
146 #endif
147 	movl	4(%esp),%eax
148 1:
149 #ifdef	REL
150 #ifndef SMALL
151 	call	_reset_cpu
152 #endif
153 	movw	$0x1234,%ax
154 	movw	%ax,0x472	# warm boot
155 	movl	$0,%esp		# segment violation
156 	ret
157 #else
158 	movl	savearea,%esp
159 	movl	savearea+4,%ebp
160 	ret
161 #endif
162 
163 	.globl	_inb
164 _inb:	movl	4(%esp),%edx
165 	subl	%eax,%eax	# clr eax
166 	inb	%dx,%al
167 	ret
168 
169 	.globl	_outb
170 _outb:	movl	4(%esp),%edx
171 	movl	8(%esp),%eax
172 	outb	%al,%dx
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 
255