Download presentation
Presentation is loading. Please wait.
1
Chapter 9 Using Disks and Files Objectives: The difference between Floppy and Hard Disks What the Boot Sector is for What the File Allocation Table is for How to access disk sectors trough BIOS INT 13H How to navigate trough DOS’s directory structure Using DOS INT 21H functions to access disk files EE314 Microprocessor Systems Based on "An Introduction to the Intel Family of Microprocessors" by James L. Antonakos
2
9.2 Organization of Floppy and Hard Disks sector 1 sector 2 sector 3 sector 4 sector 5 sector 6 sector 7 sector 8 sector 9 track 0 track 1 track 2 track 79 side (head) 1 side (head) 0 Bytes/sector = 512 Examples of Floppy Disks: Typical Hard-Drive construction Read/Write Heads head 0 head 1 Bytes/sector = 512 Examples of Hard Disks: Cylinder = all the tracks accessed at same time by all the heads. Capacity = heads X cylinders X sectors/track X bytes/sector. Spindle Platters
3
debug -l 100 0 0 1 -d 100 1AA5:0100 EB 3C 90 4D 53 44 4F 53-35 2E 30 00 02 02 01 00.<.MSDOS5.0..... 1AA5:0110 02 70 00 A0 05 F9 03 00-09 00 02 00 00 00 00 00.P.............. 1AA5:0120 00 00 00 00 00 00 29 56-66 46 12 4E 4F 20 4E 41......)VfF.NO NA 1AA5:0130 4D 45 20 20 20 20 46 41-54 31 32 20 20 20 FA 33 ME FAT12.3 1AA5:0140 C0 8E D0 BC 00 7C 16 07-BB 78 00 36 C5 37 1E 56.....|...x.6.7.V 1AA5:0150 16 53 BF 3E 7C B9 0B 00-FC F3 A4 06 1F C6 45 FE.S.>|.........E. 1AA5:0160 0F 8B 0E 18 7C 88 4D F9-89 47 02 C7 07 3E 7C FB....|.M..G...>|. 1AA5:0170 CD 13 72 79 33 C0 39 06-13 7C 74 08 8B 0E 13 7C..ry3.9..|t....| 9.2 Organization of Floppy and Hard Disks The Boot Sector (sector 0) load at address 100h from drive 0, starting at sector 0, 1 sector dump from address 100h
4
debug -l 100 0 7 1 -d 100 1AA5:0100 52 41 52 20 20 20 20 20-45 58 45 20 00 29 10 4F RAR EXE.).O 1AA5:0110 9E 24 9E 24 00 00 60 5B-AC 20 02 00 F7 68 01 00.$.$..`[....h.. 1AA5:0120 E5 53 44 4F 53 20 20 20-53 59 53 00 00 00 00 00.SDOS SYS..... 1AA5:0130 00 00 00 00 00 00 80 32-3E 1B BE 03 FA 94 00 00.......2>....... 1AA5:0140 E5 45 5A 41 20 20 20 20-5A 49 50 20 00 00 00 00.EZA ZIP.... 1AA5:0150 00 00 00 00 00 00 BD 8C-2B 23 6E 03 CE D6 06 00........+#n..... 1AA5:0160 E5 42 4C 53 50 41 43 45-42 49 4E 00 00 00 00 00.BLSPACEBIN..... 1AA5:0170 00 00 00 00 00 00 80 32-3E 1B 09 04 F6 FA 00 00.......2>....... 9.2 Organization of Floppy and Hard Disks The Directory (sector 7...) load at address 100h from drive 0, starting at sector 7 (directory), 1 sector
5
debug -l 100 0 1 1 -d 100 1ff 1AA5:0100 F0 FF FF 03 40 00 05 60-00 07 80 00 09 A0 00 0B....@..`........ 1AA5:0110 C0 00 0D E0 00 0F 00 01-11 20 01 13 40 01 15 60...........@..` 1AA5:0120 01 17 80 01 19 A0 01 1B-C0 01 1D E0 01 1F 00 02................ 1AA5:0130 21 20 02 23 40 02 25 60-02 27 80 02 29 A0 02 2B !.#@.%`.'..)..+ 1AA5:0140 C0 02 2D E0 02 2F 00 03-31 20 03 33 40 03 35 60..-../..1.3@.5` 1AA5:0150 03 37 80 03 FF 0F 00 00-00 00 00 00 00 00 00 00.7.............. 1AA5:0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00................ 1AA5:0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00................ 9.2 Organization of Floppy and Hard Disks The FAT (File Allocation Table) load at address 100h from drive 0, starting at sector 1, 1 sector dump from address 100h 00 40 03 3 bytes 2 FAT entries FAT entry for cluster 2 FAT entry for cluster 3 FAT entry for Floppy disk = 12 bit (HD 16 bit) 000: cluster available 002-FEF: number of next cluster in file or directory FF0-FF6: reserved FF7: Bad sector in cluster FF8-FFF: Last cluster in file or directory
6
9.3 Reading and Writing Disk Sectors BIOS INT 13, function 00H: Reset Disk System Specification: resets the specified disk drive. Relocates the disk head to track 0. Input: AH = 00 (function code), DL = the drive to be reset (0 =>A, 1 =>B,...) Output: CF = 0 if succeed, CF = 1 if failed, AH = error code: 00h No error 01h Invalid function request 02h Address mark not found 03h Write protect error 04h Sector not found 06h Disk change line active 08h DMA overrun operation 09h Data boundary error 0Ch Media type not found 10h Uncorrectable ECC or CRC error 20h General controller failure 40h Seek operation failed 80h Timeout BIOS INT 13, function 01H: Read Disk Status Specification: returns the specified disk drive status. Input and Output similar to function 00 (but AH = 01 (function code). BIOS INT 13, function 02H: Read Disk Sectors Specification: copies the content of specified sectors into DTA (Disk Transfer memory Area). BIOS INT 13, function 03H: Write Disk Sectors Specification: copies the content of DTA (Disk Transfer memory Area) into specified sectors. Input and Output similar to function 02 (but AH = 03 (function code). Constrain: does not update the FAT (higher level DOS INTs perform FAT housekeeping). Input: AH = 02 (function code), AL = Number of sectors to be read, CH = Track number, CL = First sector to be read, DH = Head number, DL = Drive number, BX pointer to DTA, ES = DTA’s segment Output: CF = 0 if succeed, CF = 1 if failed, AH = error code, AL = number of sectors read.
7
9.4 Directory Functions DOS INT 21, function 47H: Get current Directory Specification: returns the path of the current directory at DS:SI. Input: AH = 47h, DL = drive ID (0 => current drive, 1 =>A (!!!), 2 =>B,...), DS:SI = memory buffer address. Output: CF = 0 if succeed, CF = 1 if failed, AX = error code (see below), memory(DS:SI) = the ASCIIZ string representing the current directory path (an ASCIIZ string use the byte “0” as terminator (similar with “$” for display string function). 00h No error 01h Invalid function number02h File not found 03h Path not found 04h No more handles available05h Access denied 06h Invalid Handle 07h Bad memory control blocks08h Insufficient memory 09h Invalid memory block address0Ah Invalid environment 0Bh Invalid format 0Ch Invalid access code0Dh Invalid data 0Eh Reserved 0Fh Invalid drive specification10h Removing current directory 11h Not same device 12h Not more files to be found13h Disk is write protected 14h Unknown disk 15h Drive is not ready16h Unknown command 17h Data error (CRC) 18h Bad request length 19h Seek error 1Ah Unknown media type 1Bh Sector not found1Ch Printer out-of-paper 1Dh Write fault 1Eh Read fault1Fh General failure Example: MOV AH,47h MOV DL,0 MOV SI, 200h INT 21h 1C3F:0200 41 4C 50 5C 43 48 39 00-... Drive not specified, the current one is considered. String terminatorASCIIZ string
8
9.4 Directory Functions DOS INT 21, function 3BH: Set (Change) Current Directory Specification: sets the current directory to the path found in memory at address DS:DX. Input: AH = 3Bh (function code), DS:DX = pointer to ASCIIZ string, memory(DS:SI) = the ASCIIZ string representing the new directory path. DOS INT 21, function 39H: Create Subdirectory Specification: Creates a new directory, heaving the path found in memory at address DS:DX. Output: CF = 0 if succeed, CF = 1 if failed, AX = error code (similar to function 47h). DOS INT 21, function 3AH: Delete Subdirectory Specification: Deletes the directory heaving the path found in memory at address DS:DX. DOS INT 21, function 19H: Get Current Drive Specification: returns the ID for the current drive (0 =>A (!!!), 1 =>B,...(similar to INT13H) ). Note: The rules for path specifying are the known DOS rules. Ex: - A path beginning with a letter followed by ”:” specifies a new drive to be used. - A path beginning with ”\” is considered relative to the root directory. Input and output: Similar to function 3B (but AH = 39h). Input and output: Similar to function 3B (but AH = 3Ah). Input: AH = 19h (function code) Output: AL = The current drive ID. - A path beginning otherwise is considered relative to the current directory. Constrain: The directory must be empty to complete successfully.
9
9.4 Directory Functions ;Program PATHNAME.ASM: ;Display current directory path..MODEL SMALL.DATA PMSG DB ' Path for current directory: $ ' DRIVE DB ? DB ':\$' PATH DB 128 DUP(?) CRLF DB 0DH,0AH,'$' EMSG DB ' Error getting pathname. ',0DH,0AH,'$'.CODE.STARTUP MOV AH,19H ;get current drive function INT 21H ;DOS call ADD AL,41H ;add alpha bias MOV DRIVE,AL ;save for later LEA SI,PATH ;set pointer to pathname buffer SUB DL,DL ;current drive MOV AH,47H ;get current directory INT 21H ;DOS call JC EROR ;error if carry set LEA DX,PMSG ;set up pointer to dir message MOV AH,9 ;display string function INT 21H ;DOS call LEA DX,DRIVE ;set pointer to drive string MOV AH,9 ;display string function INT 21H ;DOS call LEA SI,PATH ;set up pointer to path SHPA: MOV DL,[SI] ;get path character OR DL,DL ;is it zero? JZ FIN MOV AH,2 ;display character function INT 21H ;DOS call INC SI ;advance to next position JMP SHPA FIN: LEA DX,CRLF ;set pointer to newline string MOV AH,9 ;display string function INT 21H ;DOS call JMP EXIT EROR: LEA DX,EMSG ;set pointer to error message MOV AH,9 ;display string function INT 21H ;DOS call EXIT:.EXIT END DL = 0=> the drive is not specified => the current drive is used. Function 09h could not be used because the string doesn’t ends with “$”.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.