1 ; Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 ; @APPLE_LICENSE_HEADER_START@
5 ; Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
6 ; Reserved. This file contains Original Code and/or Modifications of
7 ; Original Code as defined in and that are subject to the Apple Public
8 ; Source License Version 2.0 (the "License"). You may not use this file
9 ; except in compliance with the License. Please obtain a copy of the
10 ; License at http://www.apple.com/publicsource and read it before using
13 ; The Original Code and all software distributed under the License are
14 ; distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 ; EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 ; INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 ; FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
18 ; License for the specific language governing rights and limitations
21 ; @APPLE_LICENSE_HEADER_END@
25 %macro DebugCharMacro 1
31 %macro DebugPauseMacro 0
38 %define DebugChar(x) DebugCharMacro x
39 %define DebugPause(x) DebugPauseMacro
45 kBoot2Sectors EQU 126 ; sectors to load for boot2
46 kBoot2Address EQU 0x0200 ; boot2 load address
47 kBoot2Segment EQU 0x2000 ; boot2 load segment
49 kBoot0Stack EQU 0xFFF0 ; boot0 stack pointer
51 kReadBuffer EQU 0x1000 ; disk data buffer address
53 kVolSectorOffset EQU 0x47 ; offset in buffer of sector number
54 ; in volume descriptor
55 kBootSectorOffset EQU 0x28 ; offset in boot catalog
56 ; of sector number to load boot file
57 kBootCountOffset EQU 0x26 ; offset in boot catalog
58 ; of number of sectors to read
69 times 8-($-$$) nop ; Put boot information table at offset 8
71 ; El Torito boot information table, filled in by the
72 ; mkisofs -boot-info-table option, if used.
73 bi_pvd: dd 0 ; LBA of primary volume descriptor
74 bi_file: dd 0 ; LBA of boot file
75 bi_length: dd 0 ; Length of boot file
76 bi_csum: dd 0 ; Checksum of boot file
77 bi_reserved: times 10 dd 0 ; Reserved
81 mov ss, ax ; setup the
82 mov sp, kBoot0Stack ; stack
84 cld ; increment SI after each lodsb call
85 mov ds, ax ; setup the
86 mov es, ax ; data segments
87 ;; BIOS boot drive is in DL
93 mov eax, [kBoot2LoadAddr]
99 ;; The BIOS likely didn't load the rest of the booter,
100 ;; so we have to fetch it ourselves.
112 mov ecx, [kReadBuffer + kVolSectorOffset]
122 ;; Now we have the boot catalog in the buffer.
123 ;; Really we should look at the validation entry, but oh well.
127 mov ecx, [kReadBuffer + kBootSectorOffset]
128 inc ecx ; skip the first sector which is what we are in
135 mov ax, kBoot2Segment
138 mov al, kBoot2Sectors / 4
139 mov bx, kBoot2Address
145 mov eax, [es:kBoot2Address]
156 ;; Jump to newly-loaded booter
157 jmp kBoot2Segment:kBoot2Address
168 ;--------------------------------------------------------------------------
169 ; read_lba - Read sectors from CD using LBA addressing.
172 ; AL = number of 2048-byte sectors to read (valid from 1-127).
173 ; ES:BX = pointer to where the sectors should be stored.
174 ; ECX = sector offset in partition
175 ; DL = drive number (0x80 + unit number)
182 pushad ; save all registers
183 mov bp, sp ; save current SP
186 ; Create the Disk Address Packet structure for the
187 ; INT13/F42 (Extended Read Sectors) on the stack.
190 ; push DWORD 0 ; offset 12, upper 32-bit LBA
191 push ds ; For sake of saving memory,
192 push ds ; push DS register, which is 0.
196 push es ; offset 6, memory segment
198 push bx ; offset 4, memory offset
200 xor ah, ah ; offset 3, must be 0
201 push ax ; offset 2, number of sectors
203 push WORD 16 ; offset 0-1, packet size
206 ; INT13 Func 42 - Extended Read Sectors
210 ; DL = drive number (80h + drive unit)
211 ; DS:SI = pointer to Disk Address Packet
214 ; AH = return status (sucess is 0)
218 ; Packet offset 2 indicates the number of sectors read
227 DebugChar('R') ; indicate INT13/F42 error
230 ; Issue a disk reset on error.
231 ; Should this be changed to Func 0xD to skip the diskette controller
236 stc ; set carry to indicate error
239 mov sp, bp ; restore SP
244 ;; Display a single character from AL.
247 mov bx, 0x1 ; attribute for output
248 mov ah, 0xe ; BIOS: put_char
249 int 0x10 ; call BIOS, print char in %al
254 ;; Get a character from the keyboard and return it in AL.
261 ;--------------------------------------------------------------------------
262 ; Write the 4-byte value to the console in hex.
265 ; EAX = Value to be displayed in hex.
274 call print_nibble ; display upper nibble
276 call print_nibble ; display lower nibble
280 mov al, 10 ; carriage return
292 add al, 'A' - '9' - 1
301 ;; Pad this file to a size of 2048 bytes (one CD sector).
303 times 2048-($-$$) db 0
305 ;; Location of loaded boot2 code.