AT&T code like this, you mean? No idea if it's right. It assembles.
;/* ISO-9660 boot sector
;* --------------------
;*
;* Copyright (c) 2008-2009 Frédéric Feret
;* All rights reserved.
;*
;* Features:
;* - supports ISO-9660 filesystem ("El Torito")
;* - supports multiples burning session
;* - no floppy emulation
;*
;* Limitations:
;* - supports only Joliet format
;*/
BITS 16
ORG 0x00
;/*
; * This is the main function of the boot sector, which loads the OS image
;* into memory at 1000:0000.
;*
;* Parameters:
;* DL = boot disk number.
;*/
;MISMATCH: " .global _start"
;_start:
cli
; /* The BIOS has loaded our boot sector at 0000:7C00. We move the code
; of this boot sector at 9000:0000. */
xor ax,ax
mov ds,ax
mov si,07C00h ; /* DS:SI = 0000:7C00. */
mov ax,09000h
mov es,ax
xor di,di ; /* ES:DI = 9000:0000. */
mov cx,00800h ; /* 2048 bytes. */
rep movsb ; /* do the relocation. */
;/* Jump to the new address. */
;MISMATCH: " ljmp $0x9000, $1f"
jmp 0x9000:here
here:
; /* Setup segment registers. */
mov ax,cs
mov ds,ax ; /* DS = CS = 9000. */
xor ax,ax
mov es,ax
mov ss,ax ;/* SS = ES = 0000. */
mov sp,07C00h ;/* SS:SP = 0000:7C00. */
; /* Save the boot disk number. */
mov [drive_number],dl
; /* Clear the screen. */
mov ax,003h
int 010h
mov si, msg_loading
call print_string
sti
; /* Check if the processor is a 386. */
pushf
pop ax ; /* FLAGS -> AX */
or ax,03000h ; /* try to set IOPL bits. */
push ax
popf ;/* AX -> FLAGS */
pushf
pop ax ;/* FLAGS -> AX */
test ax,03000h ;/* check if IOPL bits are always set */
jnz short .l1 ;/* it's a 386, or a higher model. */
;/* The processor is a 286 or even older model. We display an error message on the
; screen and then prompts the user to press a key on the keyboard to restart
; the computer. */
mov si, msg_no_386
call print_string
jmp reboot
.l1:
;/* Get the size in bytes of a sector from the BIOS. Normally, the size of
; a sector on a CD-ROM is 2048 bytes. */
mov word [disk_packet],01Ah
mov ah,048h
xor al,al
mov si, disk_packet
mov dl, [drive_number]
int 013h
jc assume_2k_sector
mov ax, disk_packet + 0x18
mov [bytes_per_sect],ax
jmp .l1
assume_2k_sector:
;/* An error occured while retrieving the size of a sector. We will display
; a warning message on the screen, then we assume that a sector on the
; disk makes 2 kilobytes. */
mov word [bytes_per_sect],00800h
mov si, msg_assume_2k_sector
call print_string
.l1:
;/* To load the OS image (which is located at the root directory of the disk),
; we have to look at all sessions of the disk. We will retrieve information
; on the root directory (its size and location) of each session, load the
;directory into memory and see if the OS image filename is in this directory.
;If the file isn't found, we move on to the next session. If all sessions
;were covered and that the filename wasn't found, we conclude that the OS
;image isn't on the disk. The first volume descriptor is the 17th sector of
;the disk. */
mov eax,16
get_next_desc:
;/* Read the sector in memory at 0000:1000. */
mov [desc_sector],eax
mov bx,01000h
mov cx,1
call read_sectors
;/* Check for the signature "\2CD001" at the beginning of the descriptor. */
mov si, cd_signature
mov di,01000h
mov cx,6
cmpsb
je found_desc
;/* Check if we have looked in all the descriptors of volume. */
cmp byte [es:0x1000],0FFh
jne next_desc
;/* We looked in all sessions of the disk, and the OS image wasn't found.
; We display an error message on the screen and then prompts the user to
; press a key to restart the computer. */
mov si, msg_file_not_found
call print_string
jmp reboot
next_desc:
;/* Compute the next sector number to load. */
mov eax, [desc_sector]
inc eax
jmp get_next_desc
found_desc:
;/* We have to load a volume descriptor of a session in memory. We will check
; if the session supports the Joliet format for storing filenames and
; directories. Otherwise, the session is unknown. */
mov di,01058h
mov si, joliet_signature
mov cx,3
cmpsb
jne next_desc
;/* We found a session that supports Joliet format. We can find the size and
; the location of the root directory. */
mov eax, [es:0x109E]
mov [root_dir_start],eax
mov eax, [es:0x10A6]
mov [root_dir_size],eax
;/* Compute the number of sectors to load. */
movzx ebx,word [bytes_per_sect]
div ebx
cmp edx,0
je .l1
inc eax
.l1:
mov [root_dir_sectors],ax
;/* Read the root directory in memory at 0000:1000. */
mov eax, [root_dir_start]
mov bx,01000h
mov cx, [root_dir_sectors]
call read_sectors
;/* We will look into the root directory the OS image filename. If the file has
; been found, we save the sector number where that file ans its size in bytes.
; Otherwise, we move to the next session. */
mov di,01000h
search_file:
add di,25
;/* Check if this entry refers to a file. */
cmp byte [es:+di],0
jne next_entry
push di
add di,8
mov si, osimage
mov cx,14
cmpsb
pop di
je found_file ; /* file found? */
next_entry:
add di,7
movzx ax,byte [es:+di]
add di,ax
.l1:
inc di
cmp byte [es:+di],0
je 1b
;/* Check if we have check all the entries of the root directory. */
mov eax, [root_dir_size]
add eax,01000h
cmp di,ax
jb search_file
;/* The OS image wasn't found in the root directory. We go to the next
; session of the disk. */
jmp next_desc
found_file:
sub di,25
;/* Get the location of this file. */
mov eax, [es:2+di]
mov [file_start],eax
;/* Get the size of this file. */
mov eax, [es:10+di]
mov [file_size],eax
;/* Compute the number of sectors to load. */
movzx ebx,word [bytes_per_sect]
div ebx
cmp edx,0
je .l1
inc eax
.l1:
mov [file_sectors],ax
;/* Read the OS image in memory at 1000:0000. */
mov eax, [file_start]
mov bx,01000h
mov es,bx
xor bx,bx
mov cx, [file_sectors]
call read_sectors
mov dl, [drive_number]
xor si,si
;/* Run the OS loader... */
jmp 0x1000:0x0000
;/*
; * This function loads one or more sectors in memory.
; *
; * Parmaeters:
; * EAX first sector to load.
; * CX number of sectors to load.
; * ES:BX destination address.
; */
read_sectors:
; /* To request the BIOS to load the sectors, we need to build a data
; packet that contains the number or sectors to load, the first
; logical sector to load and destination address. The address of
; this packet will then be given to the BIOS, which loads these
; sectors into memory. */
mov byte [disk_packet],010h
; /* We don't read one single sector at a time. */
mov [disk_packet + 2], word 0x01
; /* Write the destination address. */
mov [disk_packet + 4], bx
mov [disk_packet + 6], es
;/* Write the logical sector to load. */
mov [disk_packet + 8], eax
mov [disk_packet + 12], dword 0x0
read_one_sector:
;/* Read the sector into memory. */
mov ah,042h
xor al,al
mov si, disk_packet
mov dl, [drive_number]
int 013h
jnc short .l1 ; /* read error? */
mov si, msg_read_error
call print_string
jmp reboot
.l1:
; /* Updates the next sector to load. */
inc dword [disk_packet + 8]
; /* Updates the destination address. Rather than incrementing the offset, we
; will increase the segment. */
mov ax, [bytes_per_sect]
shr ax,4
add [disk_packet + 6], ax
loop read_one_sector
ret
;/*
;* This function displays a string to the screen, at the current cursor
;* position.
;*
;* Parameters:
;* DS:SI null-terminated string.
;*/
print_string:
; /* Read a character. */
repe lodsb
; /* Check if we reached the end of the string. */
cmp al,0
je short .l1
; /* Displays the character on screen. */
mov ah,00Eh
mov bx,007h
int 010h
jmp print_string
.l1:
ret
;/*
; * This function reboots the computer.
; */
reboot:
mov si, msg_reboot
call print_string
; /* Wait for a key. */
xor ax,ax
int 016h
; /* Rebooting... */
int 019h
;/*
; * Messages
; */
msg_loading: db `\n\rLoading...\n\n\r`, 0
msg_no_386: db `Error: 386 or higher processor required.\n\r`, 0
msg_assume_2k_sector: db `Error: failed to get sector size, assume 2 Kb.\n\r`, 0
msg_file_not_found: db `Error: OS image not found.\n\r`, 0
msg_read_error: db `Error: cannot read on disk.\n\r`, 0
msg_reboot: db `Press any key to restart your computer.\n\r`, 0
;/*
; * Datas
; */
cd_signature: db 002h
db 'CD001'
joliet_signature: db 025h,02Fh,045h
osimage: db 0, 'o', 0, 's', 0, 'i', 0, 'm', 0, 'a', 0, 'g', 0, 'e'
drive_number: db 0
bytes_per_sect: dw 0
root_dir_size: dd 0
root_dir_sectors: dw 0
root_dir_start: dd 0
file_size: dd 0
file_sectors: dw 0
file_start: dd 0
desc_sector: dd 0
disk_packet: times 020h db 0
;/*
;* Boot sector signature
;*/
; ORG 2046
times 2046 - ($ - $$) db 0
dw 0AA55h
Best,
Frank