2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
34 * Revision 1.2 2000/05/23 23:01:11 lindak
35 * Merged PR-2309530 into Kodiak (liu i386 booter: does not support label-less
38 * Revision 1.1.1.2.4.1 2000/05/13 17:07:39 jliu
39 * New boot0 (boot1 has been deprecated). Booter must now reside in its own partition, no disk label required.
41 * Revision 1.1.1.2 1999/08/04 21:16:57 wsanchez
44 * Revision 1.3 1999/08/04 21:12:12 wsanchez
47 * Revision 1.2 1999/03/25 05:48:30 wsanchez
49 * Remove unused gzip code.
50 * Remove unused Adobe fonts.
52 * Revision 1.1.1.1.66.2 1999/03/16 16:08:54 wsanchez
55 * Revision 1.1.1.1.66.1 1999/03/16 07:33:21 wsanchez
58 * Revision 1.1.1.1 1997/12/05 21:57:57 wsanchez
59 * Import of boot-25 (~mwatson)
61 * Revision 2.1.1.2 90//03//22 17:59:50 rvb
62 * Added _sp() => where is the stack at. [kupfer]
64 * Revision 2.1.1.1 90//02//09 17:25:04 rvb
71 // INTEL CORPORATION PROPRIETARY INFORMATION
73 // This software is supplied under the terms of a license agreement or
74 // nondisclosure agreement with Intel Corporation and may not be copied
75 // nor disclosed except in accordance with the terms of that agreement.
77 // Copyright 1988 Intel Corporation
78 // Copyright 1988, 1989 by Intel Corporation
81 #include <architecture/i386/asm_help.h>
84 #define data32 .byte 0x66
85 #define addr32 .byte 0x67
92 CR0_PE_OFF = 0xfffffffe
102 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103 // Data area for __switch_stack.
105 save_sp: .long STACK_ADDR
111 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 // transfer from real mode to protected mode.
114 // preserves all registers except eax
116 LABEL(__real_to_prot)
117 // guarantee that interrupt is disabled when in prot mode
120 addr32 // load the gdtr
124 // set the PE bit of CR0 to go to protected mode
131 // make intrasegment jump to flush the processor pipeline and
132 // reload CS register
138 // we are in USE32 mode now
139 // set up the protected mode segment registers : DS, SS, ES
146 xorl %eax, %eax // clear garbage from upper word of esp
152 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 // transfer from protected mode to real mode
155 // preserves all registers except eax
157 LABEL(__prot_to_real)
159 ljmp $0x18, $x16 // change to USE16 mode
162 mov %cr0, %eax // clear the PE bit of CR0
164 and $CR0_PE_OFF, %eax
167 // make intersegment jmp to flush the processor pipeline
168 // and reload CS register
171 ljmp $BOOTSEG, $xreal
174 // we are in real mode now
175 // set up the real mode segment registers : DS, SS, ES
185 #if defined(DEFINE_INLINE_FUNCTIONS)
187 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
203 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219 #endif /* DEFINE_INLINE_FUNCTIONS */
221 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
230 // startprog(phyaddr)
231 // Start the program on protected mode where phyaddr is the entry point
237 mov 0x8(%ebp), %ecx // entry offset
238 mov $0x28, %ebx // segment
242 // set up %ds and %es
250 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
251 // Returns the current stack pointer.
257 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
258 // Returns the current stack pointer.
264 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
266 # Switches between registers SS:SP and memory save_ss:save_sp.
267 # Call this function from real mode only!!!
269 # AX, DI, and SI are modified.
271 LABEL(__switch_stack)
272 popl %eax # save return address
273 popl %edi # discard upper 16-bit
277 movl save_ss, %esi # copy new SS to ESI
281 movl save_sp, %edi # copy new SP to EDI
284 mov %ss, save_ss # save current SS
288 movl %esp, save_sp # Save current SP
291 mov %si, %ss # Perform stack switch
295 pushl %eax # push IP of caller onto the new stack
303 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304 # Issue a request to the network loader.
311 # Pass a far pointer to the command structure
312 # to the INT call through DI:CX.
314 # The command code is in BX.
317 movw 8(%ebp), %bx # 8[EBP] = command code
318 movw 12(%ebp), %cx # 12[EBP] = command structure offset
319 movw 14(%ebp), %di # 14[EBP] = command structure segment
321 call __prot_to_real # Revert to real mode
323 ###### Real Mode Begin ######
326 call __switch_stack # Switch to NBP stack
331 call __switch_stack # Restore stack
334 call __real_to_prot # Back to protected mode
336 ###### Real Mode End ######
343 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
344 // pcpy(src, dst, cnt)
345 // where src is a virtual address and dst is a physical address
357 // set %es to point at the flat segment
362 mov 0x8(%ebp), %esi // source
363 mov 0xc(%ebp), %edi // destination
364 mov 0x10(%ebp), %ecx // count