1 ; Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 ; @APPLE_LICENSE_HEADER_START@
5 ; Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 ; This file contains Original Code and/or Modifications of Original Code
8 ; as defined in and that are subject to the Apple Public Source License
9 ; Version 2.0 (the 'License'). You may not use this file except in
10 ; compliance with the License. Please obtain a copy of the License at
11 ; http://www.opensource.apple.com/apsl/ and read it before using this
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, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 ; Please see the License for the specific language governing rights and
20 ; limitations under the License.
22 ; @APPLE_LICENSE_HEADER_END@
26 %macro DebugCharMacro 1
32 %macro DebugPauseMacro 0
39 %define DebugChar(x) DebugCharMacro x
40 %define DebugPause(x) DebugPauseMacro
46 kBoot2Sectors EQU 112 ; sectors to load for boot2
47 kBoot2Address EQU 0x0200 ; boot2 load address
48 kBoot2Segment EQU 0x2000 ; boot2 load segment
50 kBoot0Stack EQU 0xFFF0 ; boot0 stack pointer
52 kReadBuffer EQU 0x1000 ; disk data buffer address
54 kVolSectorOffset EQU 0x47 ; offset in buffer of sector number
55 ; in volume descriptor
56 kBootSectorOffset EQU 0x28 ; offset in boot catalog
57 ; of sector number to load boot file
58 kBootCountOffset EQU 0x26 ; offset in boot catalog
59 ; of number of sectors to read
70 times 8-($-$$) nop ; Put boot information table at offset 8
72 ; El Torito boot information table, filled in by the
73 ; mkisofs -boot-info-table option, if used.
74 bi_pvd: dd 0 ; LBA of primary volume descriptor
75 bi_file: dd 0 ; LBA of boot file
76 bi_length: dd 0 ; Length of boot file
77 bi_csum: dd 0 ; Checksum of boot file
78 bi_reserved: times 10 dd 0 ; Reserved
82 mov ss, ax ; setup the
83 mov sp, kBoot0Stack ; stack
85 cld ; increment SI after each lodsb call
86 mov ds, ax ; setup the
87 mov es, ax ; data segments
88 ;; BIOS boot drive is in DL
94 mov eax, [kBoot2LoadAddr]
100 ;; The BIOS likely didn't load the rest of the booter,
101 ;; so we have to fetch it ourselves.
113 mov ecx, [kReadBuffer + kVolSectorOffset]
123 ;; Now we have the boot catalog in the buffer.
124 ;; Really we should look at the validation entry, but oh well.
128 mov ecx, [kReadBuffer + kBootSectorOffset]
129 inc ecx ; skip the first sector which is what we are in
136 mov ax, kBoot2Segment
139 mov al, kBoot2Sectors / 4
140 mov bx, kBoot2Address
146 mov eax, [es:kBoot2Address]
157 ;; Jump to newly-loaded booter
158 jmp kBoot2Segment:kBoot2Address
169 ;--------------------------------------------------------------------------
170 ; read_lba - Read sectors from CD using LBA addressing.
173 ; AL = number of 2048-byte sectors to read (valid from 1-127).
174 ; ES:BX = pointer to where the sectors should be stored.
175 ; ECX = sector offset in partition
176 ; DL = drive number (0x80 + unit number)
183 pushad ; save all registers
184 mov bp, sp ; save current SP
187 ; Create the Disk Address Packet structure for the
188 ; INT13/F42 (Extended Read Sectors) on the stack.
191 ; push DWORD 0 ; offset 12, upper 32-bit LBA
192 push ds ; For sake of saving memory,
193 push ds ; push DS register, which is 0.
197 push es ; offset 6, memory segment
199 push bx ; offset 4, memory offset
201 xor ah, ah ; offset 3, must be 0
202 push ax ; offset 2, number of sectors
204 push WORD 16 ; offset 0-1, packet size
207 ; INT13 Func 42 - Extended Read Sectors
211 ; DL = drive number (80h + drive unit)
212 ; DS:SI = pointer to Disk Address Packet
215 ; AH = return status (sucess is 0)
219 ; Packet offset 2 indicates the number of sectors read
228 DebugChar('R') ; indicate INT13/F42 error
231 ; Issue a disk reset on error.
232 ; Should this be changed to Func 0xD to skip the diskette controller
237 stc ; set carry to indicate error
240 mov sp, bp ; restore SP
245 ;; Display a single character from AL.
248 mov bx, 0x1 ; attribute for output
249 mov ah, 0xe ; BIOS: put_char
250 int 0x10 ; call BIOS, print char in %al
255 ;; Get a character from the keyboard and return it in AL.
262 ;--------------------------------------------------------------------------
263 ; Write the 4-byte value to the console in hex.
266 ; EAX = Value to be displayed in hex.
275 call print_nibble ; display upper nibble
277 call print_nibble ; display lower nibble
281 mov al, 10 ; carriage return
293 add al, 'A' - '9' - 1
302 ;; Pad this file to a size of 2048 bytes (one CD sector).
304 times 2048-($-$$) db 0
306 ;; Location of loaded boot2 code.