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