2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1990 Carnegie-Mellon University
28 * Copyright (c) 1989 Carnegie-Mellon University
29 * All rights reserved. The CMU software License Agreement specifies
30 * the terms and conditions for use and redistribution.
34 * boot2() -- second stage boot.
36 * This function must be located at 0:BOOTER_ADDR and will be called
40 #include <architecture/i386/asm_help.h>
43 #define data32 .byte 0x66
44 #define retf .byte 0xcb
50 EXPORT(_chainbootdev) .byte 0x80
51 EXPORT(_chainbootflag) .byte 0x00
55 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 # Booter entry point. Called by boot1 or by the NBP.
57 # This routine must be the first in the TEXT segment.
65 pushl %ecx # Save general purpose registers
70 push %ds # Save DS, ES
73 mov %cs, %ax # Update segment registers.
74 mov %ax, %ds # Set DS and ES to match CS
78 call __switch_stack # Switch to new stack
81 call __real_to_prot # Enter protected mode.
85 # We are now in 32-bit protected mode.
86 # Transfer execution to C by calling boot().
91 testb $0xff, _chainbootflag
92 jnz start_chain_boot # Jump to a foreign booter
94 call __prot_to_real # Back to real mode.
97 call __switch_stack # Restore original stack
99 pop %es # Restore original ES and DS
101 popl %edi # Restore all general purpose registers
102 popl %esi # except EAX.
107 retf # Hardcode a far return
111 movb _chainbootdev, %dl # Setup DL with the BIOS device number
113 call __prot_to_real # Back to real mode.
116 call __switch_stack # Restore original stack
118 pop %es # Restore original ES and DS
120 popl %edi # Restore all general purpose registers
121 popl %esi # except EAX.
127 ljmp $0, $0x7c00 # Jump to boot code already in memory