]> git.saurik.com Git - apple/boot.git/blob - i386/boot2/boot2.s
5ed8ad52a4a2d0b2e1d12f9e7b77fb5791fe593a
[apple/boot.git] / i386 / boot2 / boot2.s
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
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.
31 */
32
33 /*
34 * boot2() -- second stage boot.
35 *
36 * This function must be located at 0:BOOTER_ADDR and will be called
37 * by boot1 or by NBP.
38 */
39
40 #include <architecture/i386/asm_help.h>
41 #include "memory.h"
42
43 #define data32 .byte 0x66
44 #define retf .byte 0xcb
45
46 .file "boot2.s"
47
48 .data
49
50 EXPORT(_chainbootdev) .byte 0x80
51 EXPORT(_chainbootflag) .byte 0x00
52
53 .text
54
55 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 # Booter entry point. Called by boot1 or by the NBP.
57 # This routine must be the first in the TEXT segment.
58 #
59 # Arguments:
60 # DX = Boot device
61 #
62 # Returns:
63 #
64 LABEL(boot2)
65 pushl %ecx # Save general purpose registers
66 pushl %ebx
67 pushl %ebp
68 pushl %esi
69 pushl %edi
70 push %ds # Save DS, ES
71 push %es
72
73 mov %cs, %ax # Update segment registers.
74 mov %ax, %ds # Set DS and ES to match CS
75 mov %ax, %es
76
77 data32
78 call __switch_stack # Switch to new stack
79
80 data32
81 call __real_to_prot # Enter protected mode.
82
83 fninit # FPU init
84
85 # We are now in 32-bit protected mode.
86 # Transfer execution to C by calling boot().
87
88 pushl %edx # bootdev
89 call _boot
90
91 testb $0xff, _chainbootflag
92 jnz start_chain_boot # Jump to a foreign booter
93
94 call __prot_to_real # Back to real mode.
95
96 data32
97 call __switch_stack # Restore original stack
98
99 pop %es # Restore original ES and DS
100 pop %ds
101 popl %edi # Restore all general purpose registers
102 popl %esi # except EAX.
103 popl %ebp
104 popl %ebx
105 popl %ecx
106
107 retf # Hardcode a far return
108
109 start_chain_boot:
110 xorl %edx, %edx
111 movb _chainbootdev, %dl # Setup DL with the BIOS device number
112
113 call __prot_to_real # Back to real mode.
114
115 data32
116 call __switch_stack # Restore original stack
117
118 pop %es # Restore original ES and DS
119 pop %ds
120 popl %edi # Restore all general purpose registers
121 popl %esi # except EAX.
122 popl %ebp
123 popl %ebx
124 popl %ecx
125
126 data32
127 ljmp $0, $0x7c00 # Jump to boot code already in memory