adding GNU dc ("desk calculator")
[unix-history] / sys / i386 / boot / asm.s
CommitLineData
15637ed4
RG
1/*
2 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
3 *
4 * Mach Operating System
5 * Copyright (c) 1992, 1991 Carnegie Mellon University
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
27 */
28
29/*
30 * HISTORY
31 * $Log: asm.s,v $
32 * Revision 2.2 92/04/04 11:34:13 rpd
33 * Fix Intel Copyright as per B. Davies authorization.
34 * [92/04/03 rvb]
35 * From 2.5 boot: pruned inb(), outb(), and pzero().
36 * [92/03/30 rvb]
37 *
38 * Revision 2.2 91/04/02 14:35:10 mbj
39 * Added _sp() => where is the stack at. [kupfer]
40 * Add Intel copyright
41 * [90/02/09 rvb]
42 *
43 */
44
45/*
46 Copyright 1988, 1989, 1990, 1991, 1992
47 by Intel Corporation, Santa Clara, California.
48
49 All Rights Reserved
50
51Permission to use, copy, modify, and distribute this software and
52its documentation for any purpose and without fee is hereby
53granted, provided that the above copyright notice appears in all
54copies and that both the copyright notice and this permission notice
55appear in supporting documentation, and that the name of Intel
56not be used in advertising or publicity pertaining to distribution
57of the software without specific, written prior permission.
58
59INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
60INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
61IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
62CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
63LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
64NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
65WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
66*/
67
68 .file "asm.s"
69
70#include "asm.h"
71
72
73CR0_PE_ON = 0x1
74CR0_PE_OFF = 0xfffffffe
75
76.globl _ouraddr
77 .text
78
79/*
80#
81# real_to_prot()
82# transfer from real mode to protected mode.
83*/
84
85ENTRY(real_to_prot)
86 # guarantee that interrupt is disabled when in prot mode
87 cli
88
89 # load the gdtr
90 addr16
91 data32
92 lgdt EXT(Gdtr)
93
94 # set the PE bit of CR0
95 mov %cr0, %eax
96
97 data32
98 or $CR0_PE_ON, %eax
99 mov %eax, %cr0
100
101 # make intrasegment jump to flush the processor pipeline and
102 # reload CS register
103 data32
104 ljmp $0x18, $xprot
105
106xprot:
107 # we are in USE32 mode now
108 # set up the protective mode segment registers : DS, SS, ES
109 mov $0x20, %eax
110 movw %ax, %ds
111 movw %ax, %ss
112 movw %ax, %es
113
114 ret
115
116/*
117#
118# prot_to_real()
119# transfer from protected mode to real mode
120#
121*/
122
123ENTRY(prot_to_real)
124
125 # set up a dummy stack frame for the second seg change.
126 movl _ouraddr, %eax
127 sarl $4, %eax
128 pushw %ax
129 pushw $xreal
130
131 # Change to use16 mode.
132 ljmp $0x28, $x16
133
134x16:
135 # clear the PE bit of CR0
136 mov %cr0, %eax
137 data32
138 and $CR0_PE_OFF, %eax
139 mov %eax, %cr0
140
141
142 # make intersegment jmp to flush the processor pipeline
143 # using the fake stack frame set up earlier
144 # and reload CS register
145 lret
146
147
148xreal:
149 # we are in real mode now
150 # set up the real mode segment registers : DS, SS, ES
151 movw %cs, %ax
152 movw %ax, %ds
153 movw %ax, %ss
154 movw %ax, %es
155
156 data32
157 ret
158
159/*
160#
161# startprog(phyaddr)
162# start the program on protected mode where phyaddr is the entry point
163#
164*/
165
166ENTRY(startprog)
167 push %ebp
168 mov %esp, %ebp
169
170
171
172 # get things we need into registers
173 movl 0x8(%ebp), %ecx # entry offset
174 movl 0x0c(%ebp), %eax # &argv
175
176 # make a new stack at 0:0xa0000 (big segs)
177 mov $0x10, %ebx
178 movw %bx, %ss
179 movl $0xa0000,%ebx
180 movl %ebx,%esp
181
182
183 # push some number of args onto the stack
184 pushl $0 # nominally a cyl offset in the boot.
185 pushl 0x8(%eax) # argv[2] = bootdev
186 pushl 0x4(%eax) # argv[1] = howto
187 pushl $0 # dummy 'return' address
188
189 # push on our entry address
190 mov $0x08, %ebx # segment
191 pushl %ebx
192 pushl %ecx
193
194 # convert over the other data segs
195 mov $0x10, %ebx
196 movw %bx, %ds
197 movw %bx, %es
198
199 # convert the PC (and code seg)
200 lret
201/*
202#
203# pbzero( dst, cnt)
204# where src is a virtual address and dst is a physical address
205*/
206
207ENTRY(pbzero)
208 push %ebp
209 mov %esp, %ebp
210 push %es
211 push %esi
212 push %edi
213 push %ecx
214
215 cld
216
217 # set %es to point at the flat segment
218 mov $0x10, %eax
219 movw %ax, %es
220
221 mov 0x8(%ebp), %edi # destination
222 mov 0xc(%ebp), %ecx # count
223 mov $0x0,%eax # value
224
225 rep
226 stosb
227
228 pop %ecx
229 pop %edi
230 pop %esi
231 pop %es
232 pop %ebp
233
234 ret
235/*
236#
237# pcpy(src, dst, cnt)
238# where src is a virtual address and dst is a physical address
239#
240*/
241
242ENTRY(pcpy)
243 push %ebp
244 mov %esp, %ebp
245 push %es
246 push %esi
247 push %edi
248 push %ecx
249
250 cld
251
252 # set %es to point at the flat segment
253 mov $0x10, %eax
254 movw %ax, %es
255
256 mov 0x8(%ebp), %esi # source
257 mov 0xc(%ebp), %edi # destination
258 mov 0x10(%ebp), %ecx # count
259
260 rep
261 movsb
262
263 pop %ecx
264 pop %edi
265 pop %esi
266 pop %es
267 pop %ebp
268
269 ret
270