⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copybs.asm

📁 Windows上的精简Linux系统
💻 ASM
字号:
; -*- fundamental -*- (asm-mode sucks); $Id: copybs.asm,v 1.3 1999/05/31 06:39:44 hpa Exp $; -----------------------------------------------------------------------;   ;   Copyright 1998 H. Peter Anvin - All Rights Reserved;;   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, Inc., 675 Mass Ave, Cambridge MA 02139,;   USA; either version 2 of the License, or (at your option) any later;   version; incorporated herein by reference.;; -----------------------------------------------------------------------;; copybs.asm;; Small DOS program to copy the boot sector from a drive; to a file;; Usage: copybs <drive>: <file>;		absolute 0pspInt20:		resw 1pspNextParagraph:	resw 1			resb 1		; reservedpspDispatcher:		resb 5pspTerminateVector:	resd 1pspControlCVector:	resd 1pspCritErrorVector:	resd 1			resw 11		; reservedpspEnvironment:		resw 1			resw 23		; reservedpspFCB_1:		resb 16pspFCB_2:		resb 16			resd 1		; reservedpspCommandLen:		resb 1pspCommandArg:		resb 127		section .text		org 100h			; .COM format_start:		mov ax,3000h			; Get DOS version		int 21h		xchg al,ah		mov [DOSVersion],ax		cmp ax,0200h			; DOS 2.00 minimum		jae dosver_ok		mov dx,msg_ancient_err		jmp die		section .bss		alignb 2DOSVersion:	resw 1		section .text;; Scan command line for a drive letter followed by a colon;dosver_ok:		xor cx,cx		mov si,pspCommandArg		mov cl,[pspCommandLen]		cmdscan1:	jcxz bad_usage			; End of command line?		lodsb				; Load character		dec cx		cmp al,' '			; White space		jbe cmdscan1		or al,020h			; -> lower case		cmp al,'a'			; Check for letter		jb bad_usage		cmp al,'z'		ja bad_usage		sub al,'a'			; Convert to zero-based index		mov [DriveNo],al		; Save away drive index		section .bssDriveNo:	resb 1		section .text;; Got the leading letter, now the next character must be a colon;got_letter:	jcxz bad_usage		lodsb		dec cx		cmp al,':'		jne bad_usage;; Got the colon; now we should have at least one whitespace; followed by a filename;got_colon:	jcxz bad_usage		lodsb		dec cx		cmp al,' '		ja bad_usageskipspace:	jcxz bad_usage		lodsb		dec cx		cmp al,' '		jbe skipspace		mov di,FileNamecopyfile:	stosb		jcxz got_cmdline		lodsb		dec cx		cmp al,' '		ja copyfile		jmp short got_cmdline		;; We end up here if the command line doesn't parse;bad_usage:	mov dx,msg_unfair		jmp die		section .datamsg_unfair:	db 'Usage: copybs <drive>: <filename>', 0Dh, 0Ah, '$'		section .bss		alignb 4FileName	resb 256;; Parsed the command line OK.  Get device parameter block to get the; sector size.;		struc DPBdpbDrive:	resb 1dpbUnit:	resb 1dpbSectorSize:	resw 1dpbClusterMask:	resb 1dpbClusterShift: resb 1dpbFirstFAT:	resw 1dpbFATCount:	resb 1dpbRootEntries:	resw 1dpbFirstSector:	resw 1dpbMaxCluster:	resw 1dpbFATSize:	resw 1dpbDirSector:	resw 1dpbDriverAddr:	resd 1dpbMedia:	resb 1dpbFirstAccess:	resb 1dpbNextDPB:	resd 1dpbNextFree:	resw 1dpbFreeCnt:	resw 1		endstruc		section .bss		alignb 2SectorSize	resw 1		section .textgot_cmdline:		xor al,al			; Zero-terminate filename		stosb		mov dl,[DriveNo]		inc dl				; 1-based		mov ah,32h		int 21h				; Get Drive Parameter Block				and al,al		jnz filesystem_error		mov dx,[bx+dpbSectorSize]	; Save sector size;; Read the boot sector.;		section .data		align 4, db 0DISKIO		equ $diStartSector:	dd 0				; Absolute sector 0diSectors:	dw 1				; One sectordiBuffer:	dw SectorBuffer			; Buffer offset		dw 0				; Buffer segment		section .textread_bootsect:		mov ax,cs			; Set DS <- CS		mov ds,ax		mov [SectorSize],dx		; Saved sector size from above		cmp word [DOSVersion],0400h	; DOS 4.00 has a new interface		jae .new.old:		mov bx,SectorBuffer		mov cx,1			; One sector		jmp short .common.new:		mov [diBuffer+2],ax		; == DS		mov bx,DISKIO		mov cx,-1.common:		xor dx,dx			; Absolute sector 0		mov al,[DriveNo]		int 25h				; DOS absolute disk read		pop ax				; Remove flags from stack		jc disk_read_error;; Open the file and write the boot sector to the file.;		mov dx,FileName		mov cx,0020h			; Attribute = ARCHIVE		mov ah,3Ch			; Create file		int 21h		jc file_write_error		mov bx,ax		push ax				; Handle		mov cx,[SectorSize]		mov dx,SectorBuffer		mov ah,40h			; Write file		int 21h		jc file_write_error		cmp ax,[SectorSize]		jne file_write_error		pop bx				; Handle		mov ah,3Eh			; Close file		int 21h		jc file_write_error;; We're done!;		mov ax,4C00h			; exit(0)		int 21h;; Error routine jump;filesystem_error:		mov dx,msg_filesystem_err		jmp short diedisk_read_error:		mov dx,msg_read_err		jmp short diefile_write_error:		mov dx,msg_write_errdie:		push cs		pop ds		push dx		mov dx,msg_error		mov ah,09h		int 21h		pop dx		mov ah,09h			; Write string		int 21h		mov ax,4C01h			; Exit error status		int 21h		section .datamsg_error:		db 'ERROR: $'msg_ancient_err:	db 'DOS version 2.00 or later required', 0Dh, 0Ah, '$'msg_filesystem_err:	db 'Filesystem not found on disk', 0Dh, 0Ah, '$'msg_read_err:		db 'Boot sector read failed', 0Dh, 0Ah, '$'msg_write_err:		db 'File write failed', 0Dh, 0Ah, '$'		section .bss		alignb 4SectorBuffer:	resb 4096

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -