--- src/sys/boot/i386/cdboot/Attic/cdboot.S 2004/07/18 16:51:38 1.4 +++ src/sys/boot/i386/cdboot/Attic/cdboot.S 2004/07/18 23:40:07 1.5 @@ -1,72 +1,66 @@ -# -# Copyright (c) 2001 John Baldwin -# All rights reserved. -# -# Redistribution and use in source and binary forms are freely -# permitted provided that the above copyright notice and this -# paragraph and the following disclaimer are duplicated in all -# such forms. -# -# This software is provided "AS IS" and without any express or -# implied warranties, including, without limitation, the implied -# warranties of merchantability and fitness for a particular -# purpose. -# - -# $FreeBSD: src/sys/boot/i386/cdboot/cdboot.s,v 1.9 2001/11/07 01:20:33 jhb Exp $ -# $DragonFly$ - -# -# This program is a freestanding boot program to load an a.out binary -# from a CD-ROM booted with no emulation mode as described by the El -# Torito standard. Due to broken BIOSen that do not load the desired -# number of sectors, we try to fit this in as small a space as possible. -# -# Basically, we first create a set of boot arguments to pass to the loaded -# binary. Then we attempt to load /boot/loader from the CD we were booted -# off of. -# - -# -# Memory locations. -# - .set MEM_PAGE_SIZE,0x1000 # memory page size, 4k - .set MEM_ARG,0x900 # Arguments at start - .set MEM_ARG_BTX,0xa100 # Where we move them to so the - # BTX client can see them - .set MEM_ARG_SIZE,0x18 # Size of the arguments - .set MEM_BTX_ADDRESS,0x9000 # where BTX lives - .set MEM_BTX_ENTRY,0x9010 # where BTX starts to execute - .set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader - .set MEM_BTX_CLIENT,0xa000 # where BTX clients live -# -# a.out header fields -# +/* + * Copyright (c) 2001 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms are freely + * permitted provided that the above copyright notice and this + * paragraph and the following disclaimer are duplicated in all + * such forms. + * + * This software is provided "AS IS" and without any express or + * implied warranties, including, without limitation, the implied + * warranties of merchantability and fitness for a particular + * purpose. + * + * + * $FreeBSD: src/sys/boot/i386/cdboot/cdboot.s,v 1.9 2001/11/07 01:20:33 jhb Exp $ + * $DragonFly$ + */ + +/* + * This program is a freestanding boot program to load an a.out binary + * from a CD-ROM booted with no emulation mode as described by the El + * Torito standard. Due to broken BIOSen that do not load the desired + * number of sectors, we try to fit this in as small a space as possible. + * + * Basically, we first create a set of boot arguments to pass to the loaded + * binary. Then we attempt to load /boot/loader from the CD we were booted + * off of. + */ + +#include "../bootasm.h" + + /* + * a.out header fields + */ .set AOUT_TEXT,0x04 # text segment size .set AOUT_DATA,0x08 # data segment size - .set AOUT_BSS,0x0c # zero'd BSS size + .set AOUT_BSS,0x0c # zerod BSS size .set AOUT_SYMBOLS,0x10 # symbol table .set AOUT_ENTRY,0x14 # entry point .set AOUT_HEADER,MEM_PAGE_SIZE # size of the a.out header -# -# Flags for kargs->bootflags -# + + /* + * Flags for kargs->bootflags + */ .set KARGS_FLAGS_CD,0x1 # flag to indicate booting from # CD loader -# -# Segment selectors. -# + /* + * Segment selectors. + */ .set SEL_SDATA,0x8 # Supervisor data .set SEL_RDATA,0x10 # Real mode data .set SEL_SCODE,0x18 # PM-32 code .set SEL_SCODE16,0x20 # PM-16 code -# -# BTX constants -# + + /* + * BTX constants + */ .set INT_SYS,0x30 # BTX syscall interrupt -# -# Constants for reading from the CD. -# + + /* + * Constants for reading from the CD. + */ .set ERROR_TIMEOUT,0x80 # BIOS timeout on read .set NUM_RETRIES,3 # Num times to retry .set SECTOR_SIZE,0x800 # size of a sector @@ -87,16 +81,17 @@ .set DIR_SIZE,10 # Offset of 64-bit length .set DIR_NAMELEN,32 # Offset of 8-bit name len .set DIR_NAME,33 # Offset of dir name -# -# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry -# point) -# + + /* + * Program start. + * + * We expect to be loaded by the BIOS at 0x7c00 (standard + * boot loader entry point) + */ .code16 .globl start .org 0x0, 0x0 -# -# Program start. -# + start: cld # string ops inc xor %ax,%ax # zero %ax mov %ax,%ss # setup the @@ -106,9 +101,11 @@ start: cld # string ops inc mov %dl,drive # Save BIOS boot device mov $msg_welcome,%si # %ds:(%si) -> welcome message call putstr # display the welcome message -# -# Setup the arguments that the loader is expecting from boot[12] -# + + /* + * Setup the arguments that the loader is expecting from + * boot[12] + */ mov $msg_bootinfo,%si # %ds:(%si) -> boot args message call putstr # display the message mov $MEM_ARG,%bx # %ds:(%bx) -> boot args @@ -122,9 +119,9 @@ start: cld # string ops inc mov %dl,0x4(%bx) # in kargs->bootdev or $KARGS_FLAGS_CD,0x8(%bx) # kargs->bootflags |= # KARGS_FLAGS_CD -# -# Load Volume Descriptor -# + /* + * Load Volume Descriptor + */ mov $VOLDESC_LBA,%eax # Set LBA of first VD load_vd: mov $1,%dh # One sector @@ -138,15 +135,18 @@ load_vd: mov $msg_novd,%si # No VD jmp error # Halt have_vd: # Have Primary VD -# -# Lookup the loader binary. -# + + /* + * Lookup the loader binary. + */ mov $loader_path,%si # File to lookup call lookup # Try to find it -# -# Load the binary into the buffer. Due to real mode addressing limitations -# we have to read it in in 64k chunks. -# + + /* + * Load the binary into the buffer. Due to real mode + * addressing limitations we have to read it in in 64k + * chunks. + */ mov DIR_SIZE(%bx),%eax # Read file length add $SECTOR_SIZE-1,%eax # Convert length to sectors shr $11,%eax @@ -171,13 +171,15 @@ load_notrunc: sub %dh,%cl # Update cou jcxz load_done # Done? jmp load_loop # Keep going load_done: -# -# Turn on the A20 address line -# + /* + * Turn on the A20 address line. + */ call seta20 # Turn A20 on -# -# Relocate the loader and BTX using a very lazy protected mode -# + + /* + * Relocate the loader and BTX using a very lazy + * protected mode. + */ mov $msg_relocate,%si # Display the call putstr # relocation message mov MEM_READ_BUFFER+AOUT_ENTRY,%edi # %edi is the destination @@ -212,8 +214,8 @@ pm_start: mov $SEL_SDATA,%ax # Initiali rep # zero the stosl # bss mov MEM_READ_BUFFER+AOUT_ENTRY,%esi # %esi -> relocated loader - add $MEM_BTX_OFFSET,%esi # %esi -> BTX in the loader - mov $MEM_BTX_ADDRESS,%edi # %edi -> where BTX needs to go + add $MEM_BTX_LDR_OFF,%esi # %esi -> BTX in the loader + mov $MEM_BTX_ORG,%edi # %edi -> where BTX needs to go movzwl 0xa(%esi),%ecx # %ecx -> length of BTX rep # Relocate movsb # BTX @@ -228,44 +230,50 @@ pm_16: mov $SEL_RDATA,%ax # Initialize ljmp $0,$pm_end # Long jump to clear the # instruction pre-fetch queue pm_end: sti # Turn interrupts back on now -# -# Copy the BTX client to MEM_BTX_CLIENT -# + + /* + * Copy the BTX client to MEM_BTX_USR. + */ xor %ax,%ax # zero %ax and set mov %ax,%ds # %ds and %es mov %ax,%es # to segment 0 - mov $MEM_BTX_CLIENT,%di # Prepare to relocate + mov $MEM_BTX_USR,%di # Prepare to relocate mov $btx_client,%si # the simple btx client mov $(btx_client_end-btx_client),%cx # length of btx client rep # Relocate the movsb # simple BTX client -# -# Copy the boot[12] args to where the BTX client can see them -# + + /* + * Copy the boot[12] args to where the BTX client + * can see them. + */ mov $MEM_ARG,%si # where the args are at now - mov $MEM_ARG_BTX,%di # where the args are moving to + mov $MEM_BTX_USR_ARG,%di # where the args are moving to mov $(MEM_ARG_SIZE/4),%cx # size of the arguments in longs rep # Relocate movsl # the words -# -# Save the entry point so the client can get to it later on -# + + /* + * Save the entry point so the client can get to it + * later on + */ pop %eax # Restore saved entry point stosl # and add it to the end of # the arguments -# -# Now we just start up BTX and let it do the rest -# + /* + * Now we just start up BTX and let it do the rest + */ mov $msg_jump,%si # Display the call putstr # jump message ljmp $0,$MEM_BTX_ENTRY # Jump to the BTX entry point -# -# Lookup the file in the path at [SI] from the root directory. -# -# Trashes: All but BX -# Returns: BX = pointer to record -# + /* + * Lookup the file in the path at [SI] from the root + * directory. + * + * Trashes: All but BX + * Returns: BX = pointer to record + */ lookup: mov $VD_ROOTDIR+MEM_VOLDESC,%bx # Root directory record push %si mov $msg_lookup,%si # Display lookup message @@ -290,13 +298,17 @@ lookup_done: mov $msg_lookupok,%si # Su call putstr ret -# -# Lookup file at [SI] in directory whose record is at [BX]. -# -# Trashes: All but returns -# Returns: CF = 0 (success), BX = pointer to record, SX = next path item -# CF = 1 (not found), SI = preserved -# + /* + * Lookup file at [SI] in directory whose record is at [BX]. + * + * Trashes: All but returns + * + * Returns: CF = 0 (success) + * BX = pointer to record, + * SX = next path item + * CF = 1 (not found) + * SI = preserved + */ find_file: mov DIR_EXTENT(%bx),%eax # Load extent xor %edx,%edx mov DIR_EA_LEN(%bx),%dl @@ -371,11 +383,12 @@ ff.match: add $2,%sp # Discard saved % clc # Clear carry ret -# Load DH sectors starting at LBA EAX into [EBX]. No registers are destroyed. -# Don't trust the BIOS, especially with regards to the msb 16 bits of our -# registers. -# -read: pushal # don't screw around + /* + * Load DH sectors starting at LBA EAX into [EBX]. No + * registers are destroyed. Don't trust the BIOS, especially + * with regards to the msb 16 bits of our registers. + */ +read: pushal # dont screw around mov %eax,edd_lba # LBA to read from mov %ebx,%eax # Convert address shr $4,%eax # to segment @@ -398,18 +411,18 @@ read.error: mov %ah,%al # Save error call hex8 # as hex mov $msg_badread,%si # Display Read error message -# -# Display error message at [SI] and halt. -# + /* + * Display error message at [SI] and halt. + */ error: call putstr # Display message halt: hlt jmp halt # Spin -# -# Display a null-terminated string. -# -# Trashes: AX, SI -# + /* + * Display a null-terminated string. + * + * Trashes: AX, SI + */ putstr: putstr.load: lodsb # load %al from %ds:(%si) test %al,%al # stop at null @@ -418,8 +431,10 @@ putstr.load: lodsb # load %al from %d putstr.putc: call putc # output char jmp putstr.load # next char -# Display a single char(%al). Don't trust the bios to save our regs. -# + /* + * Display a single char(%al). Don't trust the bios to save + * our regs. + */ putc: pushal mov $0x7,%bx # attribute for output mov $0xe,%ah # BIOS: put_char @@ -427,9 +442,9 @@ putc: pushal popal ret # Return to caller -# -# Output the "twiddle" -# + /* + * Output the "twiddle" + */ twiddle: push %ax # Save push %bx # Save mov twiddle_index,%al # Load index @@ -445,9 +460,9 @@ twiddle: push %ax # Save pop %ax # Restore ret -# -# Enable A20 -# + /* + * Enable A20 + */ seta20: cli # Disable interrupts seta20.1: in $0x64,%al # Get status test $0x2,%al # Busy? @@ -462,9 +477,9 @@ seta20.2: in $0x64,%al # Get status sti # Enable interrupts ret # To caller -# -# Convert AL to hex, saving the result to [EDI]. -# + /* + * Convert AL to hex, saving the result to [EDI]. + */ hex8: pushl %eax # Save shrb $0x4,%al # Do upper call hex8.1 # 4 @@ -477,11 +492,11 @@ hex8.1: andb $0xf,%al # Get lower 4 stosb # Save char ret # (Recursive) -# -# BTX client to start btxldr -# + /* + * BTX client to start btxldr + */ .code32 -btx_client: mov $(MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE-4), %esi +btx_client: mov $(MEM_BTX_USR_ARG-MEM_BTX_USR+MEM_ARG_SIZE-4), %esi # %ds:(%esi) -> end # of boot[12] args mov $(MEM_ARG_SIZE/4),%ecx # Number of words to push @@ -490,32 +505,35 @@ push_arg: lodsl # Read argument push %eax # Push it onto the stack loop push_arg # Push all of the arguments cld # In case anyone depends on this - pushl MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE # Entry point of + pushl MEM_BTX_USR_ARG-MEM_BTX_USR+MEM_ARG_SIZE # Entry point of # the loader push %eax # Emulate a near call - mov $0x1,%eax # 'exec' system call + mov $0x1,%eax # "exec" system call int $INT_SYS # BTX system call btx_client_end: .code16 .p2align 4 -# -# Global descriptor table. -# + + /* + * Global descriptor table. + */ gdt: .word 0x0,0x0,0x0,0x0 # Null entry .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE (32-bit) .word 0xffff,0x0,0x9a00,0x8f # SEL_SCODE16 (16-bit) gdt.1: -# -# Pseudo-descriptors. -# + + /* + * Pseudo-descriptors. + */ gdtdesc: .word gdt.1-gdt-1 # Limit .long gdt # Base -# -# EDD Packet -# + + /* + * EDD Packet + */ edd_packet: .byte 0x10 # Length .byte 0 # Reserved edd_len: .byte 0x0 # Num to read @@ -525,9 +543,9 @@ edd_lba: .quad 0x0 # LBA drive: .byte 0 -# -# State for searching dir -# + /* + * State for searching dir + */ rec_lba: .long 0x0 # LBA (adjusted for EA) rec_size: .long 0x0 # File size name_len: .byte 0x0 # Length of current name