]> git.saurik.com Git - apple/boot.git/blame - i386/boot2/boot2.s
boot-93.tar.gz
[apple/boot.git] / i386 / boot2 / boot2.s
CommitLineData
14c7c974
A
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
14c7c974
A
45 .file "boot2.s"
46
75b89a82
A
47 .data
48
49EXPORT(_chainbootdev) .byte 0x80
50EXPORT(_chainbootflag) .byte 0x00
51
14c7c974
A
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#
63LABEL(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 # We are now in 32-bit protected mode.
83 # Transfer execution to C by calling boot().
84
85 pushl %edx # bootdev
86 call _boot
87
75b89a82
A
88 testb $0xff, _chainbootflag
89 jnz start_chain_boot # Jump to a foreign booter
90
14c7c974
A
91 call __prot_to_real # Back to real mode.
92
93 data32
94 call __switch_stack # Restore original stack
95
96 pop %es # Restore original ES and DS
97 pop %ds
98 popl %edi # Restore all general purpose registers
99 popl %esi # except EAX.
100 popl %ebp
101 popl %ebx
102 popl %ecx
103
104 retf # Hardcode a far return
105
75b89a82
A
106start_chain_boot:
107 xorl %edx, %edx
108 movb _chainbootdev, %dl # Setup DL with the BIOS device number
109
110 call __prot_to_real # Back to real mode.
111
112 data32
113 call __switch_stack # Restore original stack
114
115 pop %es # Restore original ES and DS
116 pop %ds
117 popl %edi # Restore all general purpose registers
118 popl %esi # except EAX.
119 popl %ebp
120 popl %ebx
121 popl %ecx
122
123 data32
124 ljmp $0, $0x7c00 # Jump to boot code already in memory