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.
33 * boot2() -- second stage boot.
35 * This function must be located at 0:BOOTER_ADDR and will be called
39 #include <architecture/i386/asm_help.h>
42 #define data32 .byte 0x66
43 #define retf .byte 0xcb
49 EXPORT(_chainbootdev) .byte 0x80
50 EXPORT(_chainbootflag) .byte 0x00
54 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 # Booter entry point. Called by boot1 or by the NBP.
56 # This routine must be the first in the TEXT segment.
64 pushl %ecx # Save general purpose registers
69 push %ds # Save DS, ES
72 mov %cs, %ax # Update segment registers.
73 mov %ax, %ds # Set DS and ES to match CS
77 call __switch_stack # Switch to new stack
80 call __real_to_prot # Enter protected mode.
84 # We are now in 32-bit protected mode.
85 # Transfer execution to C by calling boot().
90 testb $0xff, _chainbootflag
91 jnz start_chain_boot # Jump to a foreign booter
93 call __prot_to_real # Back to real mode.
96 call __switch_stack # Restore original stack
98 pop %es # Restore original ES and DS
100 popl %edi # Restore all general purpose registers
101 popl %esi # except EAX.
106 retf # Hardcode a far return
110 movb _chainbootdev, %dl # Setup DL with the BIOS device number
112 call __prot_to_real # Back to real mode.
115 call __switch_stack # Restore original stack
117 pop %es # Restore original ES and DS
119 popl %edi # Restore all general purpose registers
120 popl %esi # except EAX.
126 ljmp $0, $0x7c00 # Jump to boot code already in memory