]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Mach Operating System | |
3 | * Copyright (c) 1990 Carnegie-Mellon University | |
4 | * Copyright (c) 1989 Carnegie-Mellon University | |
5 | * All rights reserved. The CMU software License Agreement specifies | |
6 | * the terms and conditions for use and redistribution. | |
7 | */ | |
8 | ||
9 | AT386 Protected Mode Bootstrap Loader | |
10 | ===================================== | |
11 | ||
12 | 1. Overview of Startup | |
13 | ------------------- | |
14 | ||
15 | After the system is rebooted, the BIOS bootstrap routine reads Sector | |
16 | 1, Track 0 into memory at location 0000:7C00H. If location 0000:7DFEH | |
17 | (last two bytes of that sector) contains the value AA55H, the BIOS | |
18 | bootstrap routine will transfer control to 0000:7C00H. Otherwise, the | |
19 | boot code in that sector is bad and the boot routine stops. | |
20 | ||
21 | For DOS compatibility reason, one extra stage of boot is required if | |
22 | the boot device is a hard disk. The first sector of the hard disk will | |
23 | contain the MOS-DOS boot code and a boot record partition table. | |
24 | When this sector is loaded into 0000:7C00H, it will relocate itself | |
25 | to somewhere else and then load the first sector of the active | |
26 | partition into 0000:7C00H. Both UNIX and DOS use the command "fdisk" | |
27 | to install this first sector into the hard disk and to manipulate | |
28 | the hard disk partitions. | |
29 | ||
30 | ||
31 | ||
32 | 2. The First Stage Bootstrap Loader | |
33 | -------------------------------- | |
34 | ||
35 | After startup, the first stage boot is loaded at 0000:7C00H. This | |
36 | first stage boot will load itself and the second stage boot into | |
37 | memory at location 0000:1000H. For floppy disks, the first cylinder | |
38 | is reserved as the boot cylinder, and the boot code (first and second) | |
39 | will be loaded from there. Currently, only double sided, high density | |
40 | (15 sectors per track) floppies are supported. For hard disks, the | |
41 | first 29 sectors of the active partition is reserved for boot code | |
42 | which will be loaded by the first stage boot. All the disk types | |
43 | recognized by BIOS are supported by this bootstrap loader. | |
44 | ||
45 | ||
46 | ||
47 | 3. The Second Stage Bootstrap Loader | |
48 | -------------------------------- | |
49 | ||
50 | After the boot code is loaded, the control is passed to the second | |
51 | stage bootstrap loader "boot2()". In order to be able to load the | |
52 | big kernel image (bigger than 512K or 640K, depends on the memory | |
53 | configuration), the second stage boot loader will run on the protected | |
54 | mode. This bootstarp loader does not have any stand alone device | |
55 | drivers, all the I/O's are through the BIOS calls. Since the first | |
56 | stage boot code will no longer be used at this moment, the memory | |
57 | location of the first stage boot code (0000:1000H to 0000:1200H) will | |
58 | be used as an internal buffer for BIOS calls. Immediately after this | |
59 | internal buffer is the GDT table for the second stage boot loader. | |
60 | Since this boot loader needs to switch back and forth between protected | |
61 | and real mode in order to use BIOS calls, the limit of the boot code | |
62 | and boot data segments must not be greater than 64K. | |
63 | ||
64 | The boot loader loads the kernel image at memory location above 1 MB | |
65 | to skip the memory hole between 521K/640K and 1MB. After the kernel | |
66 | is loaded, the boot loader stores the information in the stack and | |
67 | then passes control to kernel. Currently, the three information passed | |
68 | fromm the boot loader to the kernel are type of the boot device, size | |
69 | of the base memory and size of the extended memory. | |
70 | ||
71 | ||
72 | 4. The UNIX Startup | |
73 | ---------------- | |
74 | ||
75 | Since the boot loader loads the kernel image at memory location above | |
76 | 1MB, the kernel has to start as protected mode. In addition, the | |
77 | link editor description file (vuifile) has to indicate that | |
78 | the text and data segments start above 1MB. Also, the boot loader | |
79 | passes the infomation to the kernel through the stack. | |
80 | ||
81 | ||
82 | 5. Disk Layout and Bad Block Handling | |
83 | --------------------------------- | |
84 | ||
85 | The System V/386 Release 3.2 (AT) disk layout will be used as the disk | |
86 | layout for the MACH System on the AT platform. | |
87 | ||
88 | This disk layout is as follows: | |
89 | ||
90 | * Reserve the first sector of cylinder 0 for the DOS boot record which | |
91 | contains the master boot code (446 bytes) and the partition table. | |
92 | (Refer to DOS Technical Reference Manual page 9-6 to 9-10). | |
93 | ||
94 | * Reserve the first 29 sectors of the UNIX partition for the first | |
95 | and the second stage bootstrap. | |
96 | ||
97 | * Reserve the 30th sector of the UNIX partition for the pdinfo and | |
98 | the vtoc tables. | |
99 | ||
100 | * Reserve the 31st to the 34th sectors of the UNIX partition for the | |
101 | bad track and the bad block mapping tables. | |
102 | ||
103 | * Reserve up to 253 consecutive tracks when required, beginning with | |
104 | the 35th sector of the UNIX partition, for alternate tracks. | |
105 | ||
106 | * Reserve up to 253 consecutive blocks, beginning with the first | |
107 | sector after the alternate tracks area, for alternate blocks. | |
108 | ||
109 | SEC | |
110 | 1 | |
111 | ---------------------------------------------------- | |
112 | | X | | CYL 0, TRK 0 | |
113 | ---------------- .......... -------------------- | |
114 | | .......... | | |
115 | ---------------- .......... -------------------- | |
116 | | .......... | | |
117 | =============================================================== | |
118 | ^ | BOOTSTRAP | CYL N, TRK M | |
119 | | ---------------------------------------------------- | |
120 | | | |30 |31 |32 |33 |34 | | |
121 | ---------------------------------------------------- --- | |
122 | U | .......... | ^ | |
123 | N ---------------- .......... --------------------- | | |
124 | I | .......... | Alternate Tracks | |
125 | X ---------------- .......... --------------------- | | |
126 | | .......... | V | |
127 | P ---------------------------------------------------- --- | |
128 | A | .......... | ^ | |
129 | R ---------------- .......... --------------------- | | |
130 | T | .......... | Alternate Blocks | |
131 | I ---------------- .......... -------------------- | | |
132 | T | .......... | V | |
133 | I ---------------------------------------------------- --- | |
134 | O | Unix root partition starts from here | | |
135 | N ---------------- ----------------- | |
136 | | | | |
137 | ---------------------------------------------------- | |
138 | | | | |
139 | ---------------------------------------------------- | |
140 | | | | |
141 | | --------------------------------------------------- | |
142 | | | | | |
143 | | ---------------------------------------------------- | |
144 | V | | | |
145 | =============================================================== | |
146 | | ........ | | |
147 | --------------- ........ -------------- | |
148 | | ........ | | |
149 | ---------------------------------------------------- | |
150 | ||
151 | ||
152 | The bad block handling mechanism is as follows: | |
153 | ||
154 | * Use the alternate track in the alternate tracks area if the | |
155 | track containing the target sector is bad. | |
156 | ||
157 | * Use the alternate block in the alternate blocks area if the | |
158 | target sector is bad. | |
159 | ||
160 | ||
161 | ||
162 | ||
163 | 6. How to make: | |
164 | ----------- | |
165 | ||
166 | Since the kernel image is loaded above 1 MB, the kernel must start | |
167 | as protected mode. This means that this bootstrap loader will work | |
168 | only when the corresponding changes on the kernel startup code are done. | |
169 | ||
170 | The make command to generate this bootstrap loader is: | |
171 | ||
172 | make -f boot.mk fdboot (floppy boot loader) | |
173 | make -f boot.mk hdboot (wini boot loader) |