;//--------------------------------------------------------------- ;// bootdemo.s ;// ;// This program is designed as a replacement for the MS-DOS ;// 'boot' sector on a floppy diskette. It prints a sign-on ;// message, waits for the user to press any key, then loads ;// and executes the boot-strap loader program stored in the ;// 'Master Boot Record' of the machine's primary hard disk. ;// ;// assemble with: $ as86 bootdemo.s -b bootdemo.o ;// install using: $ dd if=bootdemo.o of=/dev/fd0 ;// ;// programmer: ALLAN CRUSE ;// written on: 26 OCT 2003 ;//--------------------------------------------------------------- .SECT .TEXT ;----------------------------------------------------------------- bsJump: jmp NEAR start ; jump beyond parameters ;----------------------------------------------------------------- bsOEMid: .ASCII "USFCAedu" ; our OEM Identification ;----------------------------------------------------------------- ;-------------------- BIOS Parameter Block --------------------- ;----------------------------------------------------------------- ; bsBytesPerSec: .WORD 512 ; sector-size (in bytes) bsSecPerClust: .BYTE 1 ; sectors-per-cluster bsResSectors: .WORD 1 ; reserved sectors bsFATs: .BYTE 2 ; number of FAT copies bsRootDirEnts: .WORD 224 ; number of root entries bsSectors: .WORD 2880 ; total number of sectors bsMedia: .BYTE 0xF0 ; media descriptor byte bsFATsecs: .WORD 9 ; number sectors per FAT bsSecPerTrack: .WORD 18 ; number sectors/track bsHeads: .WORD 2 ; number of heads bsHiddenSecs: .LONG 0 ; number of hidden sectors bsHugeSectors: .LONG 0 ; ext number of sectors bsReserved: .LONG 0 ; reserved -- do not use ; ;----------------------------------------------------------------- ; ; During bootup, this code executes at the ROM-BIOS BOOT_LOCN: ; ; CS:IP = 0000:7C00 ; start: ; initialize top-of-stack with memory-address CS:7C00 cli ; disable interrupts mov ax,cs ; setup stack at known mov ss,ax ; safe memory-offset mov sp,#0x7C00 ; in code-segment sti ; reenable interrupts ; setup this code-module's segment-address in AX call ahead ; push current IP-value ahead: pop dx ; to find where code is sub dx,#ahead-bsJump ; compute module origin mov cl,#4 ; set shift-count in CL shr dx,cl ; to compute paragraphs add ax,dx ; and get code-location ; move this code-module 512 bytes higher up in memory mov ds,ax xor si,si ; DS:SI = old location add ax,#0x20 mov es,ax xor di,di ; ES:DI = new location cld mov cx,#256 ; copy 512-byte sector rep movsw ; perform code copying ; transfer to new 'main' using a far-return instruction mov dx,#main-bsJump ; load procedure offset push ax ; push new value for CS push dx ; push new value for IP retf ; execute a "far" return ;----------------------------------------------------------------- message: .ASCII "\r\nCS630 BOOT-SECTOR DEMONSTRATION\r\n\n" MSGSIZE EQU * - message ; length of the message ;----------------------------------------------------------------- main: ; get current cursor-location mov ah,#0x0F ; get_display_page int 0x10 ; request BIOS service mov ah,#0x03 ; get_cursor_location int 0x10 ; request BIOS service ; show our sign-on message mov ax,cs ; address this segment mov es,ax ; with ES register mov bp,#message-bsJump ; point ES:BP to string mov cx,#MSGSIZE ; setup size of string mov bl,#0x02 ; setup display colors mov ax,#0x1301 ; write_tty_string int 0x10 ; request BIOS service ; wait for user to press a key xor ax,ax ; await_user_keypress int 0x16 ; request BIOS service ; setup ES:BX to address BOOT_LOCN xor ax,ax ; clear the accumulator mov es,ax ; address bottom memory mov bx,#0x7C00 ; set ES:BX = BOOT_LOCN ESEG mov [bx+0x1FE],ax ; erase prior signature ; read Master Boot Record from the hard disk mov cx,#0x0001 ; cymn 0, recd 1 mov dx,#0x0080 ; head 0, drive C: mov ax,#0x0201 ; read one sector int 0x13 ; request BIOS service ; verify that disk's boot-record was successfully read ESEG mov ax,[bx+0x1FE] ; sector's final word cmp ax,#0xAA55 ; is valid signature? freeze: jne freeze ; no, then freeze CPU ; if valid. perform a far return to the BOOT_LOCN push es ; push new CS-value push bx ; push new IP-value retf ; transfer to BOOT_LOCN ;----------------------------------------------------------------- .ORG 510 .WORD 0xAA55 ; boot-sector signature ;----------------------------------------------------------------- END