xref: /386bsd/usr/src/bootstrap/config/srt0_i386.c (revision a2142627)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	$Id: srt0_i386.c,v 1.1 94/10/20 16:44:14 root Exp $
37  */
38 
39 /*
40  * Startup code for standalone system
41  * Non-relocating version -- for programs which are loaded by boot
42  * Relocating version for boot
43  * Small relocating version for "micro" boot
44  */
45 
46 	.globl	_end
47 	.globl	_edata
48 	.globl	_main
49 	.globl	__rtt
50 	.globl	_exit
51 	.globl	_bootdev
52 	.globl	_cyloffset
53 #define	NOP	inb $0x84,%al ; inb $0x84,%al
54 #define	COLORFB	0xb8000
55 #define	MONOFB	0xb0000
56 #define	FB	COLORFB
57 #if	DEBUG > 1
58 #define PUTC(s)	movw $ s ,(%ebp) ; incl %ebp ; incl %ebp
59 #else
60 #define PUTC(s)
61 #endif
62 
63 #ifdef SMALL
64 	/* where the disklabel goes if we have one */
65 	.globl	_disklabel
66 _disklabel:
67 	.space 512
68 	.globl _scsisn
69 	.set _scsisn, RELOC+0x60
70 #endif
71 
72 	.globl	entry
73 	.set entry,0
74 	.globl	start
75 
76 #if	defined(REL) && !defined(SMALL)
77 
78 	/* relocate program and enter at symbol "start" */
79 
80 	#movl	$entry-RELOC,%esi	# from beginning of ram
81 	movl	$0,%esi
82 	#movl	$entry,%edi		# to relocated area
83 	movl	$ RELOC,%edi		# to relocated area
84 	# movl	$_edata-RELOC,%ecx	# this much
85 	movl	$64*1024,%ecx
86 	cld
87 	rep
88 	movsb
89 	# relocate program counter to relocation base
90 	pushl	$start
91 	ret
92 #endif
93 
94 start:
95 #if DEBUG > 0
96 	movl	$ FB, %ebp
97 #endif
98 	PUTC(0x7041)
99 
100 	/* setup stack pointer */
101 
102 #ifdef REL
103 	leal	4(%esp),%eax	/* ignore old pc */
104 	movl	$ RELOC-3*4,%ebx
105 	/* copy boot parameters */
106 	pushl	$3*4
107 	pushl	%ebx
108 	pushl	%eax
109 	call	_bcopy
110 	movl	%ebx,%esp
111 #else
112 	/* save old stack state */
113 	movl	%esp,savearea
114 	movl	%ebp,savearea+4
115 	movl	$ RELOC-0x2400,%esp
116 #endif
117 
118 	/* clear memory as needed */
119 
120 	movl	%esp,%esi
121 #ifdef	REL
122 
123 	/*
124 	 * Clear Bss and up to 64K heap
125 	 */
126 	movl	$64*1024,%ebx
127 	movl	$_end,%eax	# should be movl $_end-_edata but ...
128 	subl	$_edata,%eax
129 	#addl	%ebx,%eax
130 	pushl	%eax
131 	pushl	$_edata
132 	call	_bzero
133 
134 	/*
135 	 * Clear 64K of stack
136 	 */
137 	movl	%esi,%eax
138 	subl	%ebx,%eax
139 	subl	$5*4,%ebx
140 	pushl	%ebx
141 	pushl	%eax
142 	call	_bzero
143 #else
144 	movl	$_edata,%edx
145 	movl	%esp,%eax
146 	subl	%edx,%eax
147 	pushl	%edx
148 	pushl	%esp
149 	call	_bzero
150 #endif
151 
152 	PUTC(0x7042)
153 	call	_kbdreset	/* resets keyboard and gatea20 brain damage */
154 	PUTC(0x7043)
155 	movl	%esi,%esp
156 	call	_main
157 	PUTC(0x7044)
158 	jmp	1f
159 
160 	.data
161 _bootdev:	.long	0
162 _cyloffset:	.long	0
163 savearea:	.long	0,0	# sp & bp to return to
164 	.text
165 	.globl _wait
166 
167 __rtt:
168 	PUTC(0x7045)
169 	pushl	$1000000
170 	call	_wait
171 	popl	%eax
172 	movl	$-7,%eax
173 	jmp	1f
174 
175 _exit:
176 	PUTC(0x7046)
177 	pushl	$1000000
178 	call	_wait
179 	popl	%eax
180 	movl	4(%esp),%eax
181 1:
182 #ifdef	REL
183 #ifndef SMALL
184 	call	_reset_cpu
185 #endif
186 	movw	$0x1234,%ax
187 	movw	%ax,0x472	# warm boot
188 	movl	$0,%esp		# segment violation
189 	ret
190 #else
191 	movl	savearea,%esp
192 	movl	savearea+4,%ebp
193 	ret
194 #endif
195 
196 	.globl	_inb
197 _inb:	movl	4(%esp),%edx
198 	subl	%eax,%eax	# clr eax
199 	NOP
200 	inb	%dx,%al
201 	ret
202 
203 	.globl	_outb
204 _outb:	movl	4(%esp),%edx
205 	NOP
206 	movl	8(%esp),%eax
207 	outb	%al,%dx
208 	ret
209 
210 	.globl ___udivsi3
211 ___udivsi3:
212 	movl 4(%esp),%eax
213 	xorl %edx,%edx
214 	divl 8(%esp)
215 	ret
216 
217 	.globl ___divsi3
218 ___divsi3:
219 	movl 4(%esp),%eax
220 	xorl %edx,%edx
221 	cltd
222 	idivl 8(%esp)
223 	ret
224 
225 	#
226 	# bzero (base,cnt)
227 	#
228 
229 	.globl _bzero
230 _bzero:
231 	pushl	%edi
232 	movl	8(%esp),%edi
233 	movl	12(%esp),%ecx
234 	movb	$0x00,%al
235 	cld
236 	rep
237 	stosb
238 	popl	%edi
239 	ret
240 
241 	#
242 	# bcopy (src,dst,cnt)
243 	# NOTE: does not (yet) handle overlapped copies
244 	#
245 
246 	.globl	_bcopy
247 _bcopy:
248 	pushl	%esi
249 	pushl	%edi
250 	movl	12(%esp),%esi
251 	movl	16(%esp),%edi
252 	movl	20(%esp),%ecx
253 	cld
254 	rep
255 	movsb
256 	popl	%edi
257 	popl	%esi
258 	ret
259 
260 	# insw(port,addr,cnt)
261 	.globl	_insw
262 _insw:
263 	pushl	%edi
264 	movw	8(%esp),%dx
265 	movl	12(%esp),%edi
266 	movl	16(%esp),%ecx
267 	NOP
268 	cld
269 	nop
270 	.byte 0x66,0xf2,0x6d	# rep insw
271 	nop
272 	movl	%edi,%eax
273 	popl	%edi
274 	ret
275 
276 	# outsw(port,addr,cnt)
277 	.globl	_outsw
278 _outsw:
279 	pushl	%esi
280 	movw	8(%esp),%dx
281 	movl	12(%esp),%esi
282 	movl	16(%esp),%ecx
283 	NOP
284 	cld
285 	nop
286 	.byte 0x66,0xf2,0x6f	# rep outsw
287 	nop
288 	movl	%esi,%eax
289 	popl	%esi
290 	ret
291