; boot_ckdisk.asm -- (destructive) checkdisk bootstrap ; Copyright (C) 2004 Steffen Solyga ; asmsyntax=nasm ; compile (on linux) with: nasm boot_ckdisk.asm ; prepare disk with: dd if=boot_ckdisk of=/dev/hd* or ; dd if=boot_ckdisk of=/dev/fd0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; $Id: boot_ckdisk.asm,v 1.1 2005/07/23 00:55:25 solyga Exp $ ; This program resides within the mbr and WRITES a special pattern ; (0x00, 0x01, ...) with EBIOS int13... ; jmp 07c0h:start ; set cs to 0x07c0, see boot00.asm start: cli mov ax, cs mov ds, ax mov es, ax mov ss, ax mov sp, 7c00h sti cld mov [bdrive], dl ; save boot drive number ; fill write buffer with simple pattern mov ax, wb_seg mov es, ax mov di, wb_off xor ax, ax .bloop stosb ; [es:di]= al, di += 1 inc ax cmp ax, 0 ; 10000h = 128 (80h) sectors = 64 kBytes jne .bloop ; write to disk mov si, dap mov word [dap.lbaw0], 1 ; initial start lba (lsw) mov dl, 80h ; destination drive number mov word [dap.off], wb_off ; buffer offset mov word [dap.seg], wb_seg ; buffer segment mov word [dap.cnt], 80h ; number of blocks to write mov ax, 4300h int 13h jc error mov ax, [dap.cnt] call convert_ax mov si, hexword call print_string hang: hlt jmp hang error: mov si, err_msg call print_string jmp hang ; ----------------------------------------------------------------------------- convert_ax: mov cx, ax ; shift register mov bx, 0x0004 ; counter, 4 chars .loop: mov al, cl and al, 0x0f or al, 0x30 cmp al, 0x3a jc .nibble_done add al, 0x27 .nibble_done: mov [bx+hexword+1], al ; store ascii code shr cx, 4 ; next nibble dec bl jnz .loop ret ; ----------------------------------------------------------------------------- print_string: push es ; save es mov di, 0xb800 ; video segment address mov es, di ; see boot04.asm xor di, di mov ah, 0x07 ; white on black .loop: lodsb ; al= [ds:si], si+= 1 or al, al ; al= 0 ? jz .done stosw ; [es:di]= ax, di+= 2 jmp .loop .done: pop es ; restore es ret ; ----------------------------------------------------------------------------- wb_seg equ 1000h ; write buffer segment wb_off equ 0h ; write buffer offset err_msg db 'Error!', 0 hexword db '0x----', 0 dap dw 10h ; disk address packet size .cnt dw 0 ; number of blocks to transfer .off dw 0 ; buffer offset .seg dw 0 ; buffer segment .lbaw0 dw 0 ; LBA (LSDW) .lbaw1 dw 0 ; LBA (LSDW) .lbaw2 dw 0 ; LBA (MSDW) .lbaw3 dw 0 ; LBA (MSDW) ; ----------------------------------------------------------------------------- ; uninitialised data SECTION .bss bdrive resb 4 ; boot drive number