source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Prepare.asm@ 402

Last change on this file since 402 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 5.3 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for preparing data buffer for transfer.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Prepare_ByLoadingDapToESSIandVerifyingForTransfer
25; Parameters:
26; SI: Offset to DAP
27; DS:DI: Ptr to DPT
28; SS:BP: Ptr to IDEPACK
29; Parameters on INTPACK:
30; DS:SI: Ptr to Disk Address Packet
31; Returns:
32; BX: Index to command lookup table
33; ES:SI: Ptr to Disk Address Packet (DAP)
34; Exits from INT 13h if invalid DAP
35; Corrupts registers:
36; AX, DX
37;--------------------------------------------------------------------
38%ifdef MODULE_EBIOS
39ALIGN JUMP_ALIGN
40Prepare_ByLoadingDapToESSIandVerifyingForTransfer:
41 ; Load pointer to DAP to ES:SI and make sure it is valid
42 mov es, [bp+IDEPACK.intpack+INTPACK.ds] ; ES:SI to point Disk Address Packet
43 cmp BYTE [es:si+DAP.bSize], MINIMUM_DAP_SIZE
44 jb SHORT InvalidDAP
45
46 ; Make sure that sector count is valid
47 mov ax, [es:si+DAP.wSectorCount]
48 test ax, ax
49 jz SHORT ZeroSectorsRequestedSoNoErrors
50 cmp ax, BYTE 127
51 ja SHORT InvalidNumberOfSectorsRequested
52
53 ; Get EBIOS command index to BX
54 ; LBA28 or LBA48 command
55 cwd
56 mov al, [es:si+DAP.qwLBA+3] ; Load LBA48 byte 3 (bits 24...31)
57 and al, 0F0h ; Clear LBA28 bits 24...27
58 or ax, [es:si+DAP.qwLBA+4] ; Set bits from LBA bytes 4 and 5
59 cmp dx, ax ; Set CF if any of bits 28...47 set
60 rcl dx, 1 ; DX = 0 for LBA28, DX = 1 for LBA48
61 call Prepare_GetOldInt13hCommandIndexToBX
62 or bx, dx ; Set block mode / single sector bit
63 ret
64%endif
65
66
67;--------------------------------------------------------------------
68; Prepare_GetOldInt13hCommandIndexToBX
69; Parameters:
70; DS:DI: Ptr to DPT
71; Returns:
72; BX: Index to command lookup table
73; Corrupts registers:
74; Nothing
75;--------------------------------------------------------------------
76ALIGN JUMP_ALIGN
77Prepare_GetOldInt13hCommandIndexToBX:
78 ; Block mode or single sector
79 mov bl, [di+DPT.bFlagsHigh]
80 and bx, BYTE FLGH_DPT_BLOCK_MODE_SUPPORTED ; Bit 1
81 ret
82
83
84;---------------------------------------------------------------------
85; Prepare_BufferToESSIforOldInt13hTransfer
86; Parameters:
87; AL: Number of sectors to transfer
88; SS:BP: Ptr to IDEPACK
89; Parameters on INTPACK:
90; ES:BX: Ptr to data buffer
91; Returns:
92; ES:SI: Ptr to normalized data buffer
93; Exits INT 13h if error
94; Corrupts registers:
95; BX
96;--------------------------------------------------------------------
97ALIGN JUMP_ALIGN
98Prepare_BufferToESSIforOldInt13hTransfer:
99 ; Normalize buffer pointer
100 mov bx, [bp+IDEPACK.intpack+INTPACK.bx] ; Load offset
101 mov si, bx
102 eSHR_IM bx, 4 ; Divide offset by 16
103 add bx, [bp+IDEPACK.intpack+INTPACK.es]
104 mov es, bx ; Segment normalized
105 and si, BYTE 0Fh ; Offset normalized
106 ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h
107
108
109;---------------------------------------------------------------------
110; Prepare_ByValidatingSectorsInALforOldInt13h
111; Parameters:
112; AL: Number of sectors to transfer
113; Returns:
114; Exits INT 13h if invalid number of sectors in AL
115; Corrupts registers:
116; Nothing
117;--------------------------------------------------------------------
118ALIGN JUMP_ALIGN
119Prepare_ByValidatingSectorsInALforOldInt13h:
120 test al, al
121 js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more
122 jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h
123 ret ; Continue with transfer
124
125ALIGN JUMP_ALIGN
126.CheckZeroOffsetFor128Sectors:
127 cmp al, 128
128 ja SHORT InvalidNumberOfSectorsRequested
129 test si, si ; Offset must be zero to xfer 128 sectors
130 jnz SHORT CannotAlignPointerProperly
131 ret ; Continue with transfer
132
133InvalidDAP:
134InvalidNumberOfSectorsRequested:
135Prepare_ReturnFromInt13hWithInvalidFunctionError:
136 mov ah, RET_HD_INVALID
137 SKIP2B f
138CannotAlignPointerProperly:
139 mov ah, RET_HD_BOUNDARY
140ZeroSectorsRequestedSoNoErrors:
141 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
142
143
144
145; Command lookup tables
146g_rgbReadCommandLookup:
147 db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector
148 db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector
149 db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode
150 db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode
151
152g_rgbWriteCommandLookup:
153 db COMMAND_WRITE_SECTORS
154 db COMMAND_WRITE_SECTORS_EXT
155 db COMMAND_WRITE_MULTIPLE
156 db COMMAND_WRITE_MULTIPLE_EXT
157
158g_rgbVerifyCommandLookup:
159 db COMMAND_VERIFY_SECTORS
160 db COMMAND_VERIFY_SECTORS_EXT
161 db COMMAND_VERIFY_SECTORS
162 db COMMAND_VERIFY_SECTORS_EXT
Note: See TracBrowser for help on using the repository browser.