source: xtideuniversalbios/tags/v2.0.0_beta_3/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm@ 529

Last change on this file since 529 was 490, checked in by gregli@…, 12 years ago

Fixed a bug in the virtual serial drive code, where AX was being corrupted by IdeTransfer_NormalizePointerInESSI.

File size: 8.0 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Serial Device Command functions.
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%define SERIALSERVER_AH_ALREADY_HAS_COMMAND_BYTE
24%define SERIALSERVER_NO_ZERO_SECTOR_COUNTS
25
26;--------------------------------------------------------------------
27; SerialCommand_OutputWithParameters
28; Parameters:
29; BH: Non-zero if 48-bit addressing used
30; (ignored at present as 48-bit addressing is not supported)
31; BL: IDE Status Register bit to poll after command
32; (ignored at present, since there is no IDE status register to poll)
33; ES:SI: Ptr to buffer (for data transfer commands)
34; DS:DI: Ptr to DPT (in RAMVARS segment)
35; SS:BP: Ptr to IDEREGS_AND_INTPACK
36; Returns:
37; AH: INT 13h Error Code
38; CX: Number of successfully transferred sectors (for transfer commands)
39; CF: Cleared if success, Set if error
40; Corrupts registers:
41; AL, BX, CX, DX, (ES:SI for data transfer commands)
42;--------------------------------------------------------------------
43ALIGN JUMP_ALIGN
44SerialCommand_OutputWithParameters:
45
46 mov ah,SerialServer_Command_Read
47
48 mov al,[bp+IDEPACK.bCommand]
49
50 cmp al,20h ; Read Sectors IDE command
51 jz .readOrWrite
52 inc ah ; now SerialServer_Protocol_Write
53 cmp al,30h ; Write Sectors IDE command
54 jz .readOrWrite
55
56; all other commands return success
57; including function 0ech which should return drive information, this is handled with the identify functions
58;
59 xor ah,ah ; also clears carry
60 ret
61
62.readOrWrite:
63 mov [bp+IDEPACK.bFeatures],ah ; store protocol command
64 call IdeTransfer_NormalizePointerInESSI
65
66 mov dx, [di+DPT_SERIAL.wSerialPortAndBaud]
67
68; fall through to SerialCommand_FallThroughToSerialServer_SendReceive
69
70ALIGN JUMP_ALIGN
71SerialCommand_FallThroughToSerialServer_SendReceive:
72
73; fall through to SerialServer_SendReceive
74
75%include "SerialServer.asm"
76
77%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
78 %if SerialCommand_FallThroughToSerialServer_SendReceive <> SerialServer_SendReceive
79 %error "SerialServer_SendReceive must be the first routine at the top of SerialServer.asm in the Assembly_Library"
80 %endif
81%endif
82
83ALIGN JUMP_ALIGN
84SerialCommand_ReturnError:
85 stc
86 ret
87
88;--------------------------------------------------------------------
89; SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
90; Parameters:
91; BH: Drive Select byte for Drive and Head Select Register
92; DS: Segment to RAMVARS
93; ES:SI: Ptr to buffer to receive 512-byte IDE Information
94; CS:BP: Ptr to IDEVARS
95; Returns:
96; CF: Cleared if success, Set if error
97; Corrupts registers:
98; AL, BL, CX, DX, SI, DI, ES
99;--------------------------------------------------------------------
100ALIGN JUMP_ALIGN
101SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
102;
103; To improve boot time, we do our best to avoid looking for slave serial drives when we already know the results
104; from the looking for a master. This is particularly true when doing a COM port scan, as we will end up running
105; through all the COM ports and baud rates a second time.
106;
107; But drive detection isn't the only case - we also need to get the right drive when called on int13h/25h.
108;
109; The decision tree:
110;
111; Master:
112; wSerialPortAndBaud Non-Zero: -> Continue with wSerialPortAndBaud (1)
113; wSerialPortAndBaud Zero:
114; previous serial drive not found: -> Scan (2)
115; previous serial drive found: -> Continue with previous serial drive info (3)
116;
117; Slave:
118; wSerialPortAndBaud Non-Zero:
119; previous serial drive not found: -> Error - Not Found (4)
120; previous serial drive found: -> Continue with wSerialPackedAndBaud (5)
121; wSerialPortAndBaud Zero:
122; previous serial drive not found: -> Error - Not Found (4)
123; previous serial drive found: -> Continue with previous serial drive info (6)
124;
125; (1) This was a port/baud that was explicitly set with the configurator. In the drive detection case, as this
126; is the Master, we are checking out a new controller, and so don't care if we already have a serial drive.
127; And as with the int13h/25h case, we just go off and get the needed information using the user's setting.
128; (2) We are using the special .ideVarsSerialAuto structure. During drive detection, we would only be here
129; if we hadn't already seen a serial drive (since we only scan if no explicit drives are set),
130; so we go off to scan.
131; (3) We are using the special .ideVarsSerialAuto structure. We won't get here during drive detection, but
132; we might get here on an int13h/25h call. If we have scanned COM drives, they are the ONLY serial drives
133; in use, and so we use the values from the previously seen serial drive DPT.
134; (4) No master has been found yet, therefore no slave should be found. Avoiding the slave reduces boot time,
135; especially in the full COM port scan case. Note that this is different from the hardware IDE, where we
136; will scan for a slave even if a master is not present. Note that if ANY master had been previously found,
137; we will do the slave scan, which isn't harmful, it just wastes time. But the most common case (by a wide
138; margin) will be just one serial controller.
139; (5) A COM port scan for a master had been previously completed, and a drive was found. In a multiple serial
140; controller scenario being called with int13h/25h, we need to use the value in bSerialPackedPortAndBaud
141; to make sure we get the proper drive.
142; (6) A COM port scan for a master had been previously completed, and a drive was found. We would only get here
143; if no serial drive was explicitly set by the user in the configurator or that drive had not been found.
144; Instead of performing the full COM port scan for the slave, use the port/baud value stored during the
145; master scan.
146;
147 mov dx,[cs:bp+IDEVARS.wSerialPortAndBaud]
148 xor ax,ax
149
150 push si
151 call FindDPT_ToDSDIforSerialDevice
152 pop si
153%ifdef MODULE_SERIAL_FLOPPY
154 jnc .founddpt
155;
156; If not found above with FindDPT_ToDSDIforSerialDevice, DI will point to the DPT after the last hard disk DPT
157; So, if there was a previously found floppy disk, DI will point to that DPT and we use that value for the slave.
158;
159 cmp byte [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], 0
160 jz .notfounddpt
161.founddpt:
162%else
163 jc .notfounddpt
164%endif
165 mov ax, [di+DPT_SERIAL.wSerialPortAndBaud]
166.notfounddpt:
167
168 test bh, FLG_DRVNHEAD_DRV
169 jz .master
170
171 test ax,ax ; Take care of the case that is different between master and slave.
172 jz SerialCommand_ReturnError
173
174; fall-through
175.master:
176 test dx,dx
177 jnz .identifyDeviceInDX
178
179 xchg dx, ax ; move ax to dx (move previously found serial drive to dx, could be zero)
180
181.identifyDeviceInDX:
182
183; fall through to SerialCommand_FallThroughToSerialServerScan_ScanForServer
184
185ALIGN JUMP_ALIGN
186SerialCommand_FallThroughToSerialServerScan_ScanForServer:
187
188; fall through to SerialServerScan_ScanForServer
189
190%include "SerialServerScan.asm"
191
192%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
193 %if SerialCommand_FallThroughToSerialServerScan_ScanForServer <> SerialServerScan_ScanForServer
194 %error "SerialServerScan_ScanForServer must be the first routine at the top of SerialServerScan.asm in the Assembly_Library"
195 %endif
196%endif
197
198
Note: See TracBrowser for help on using the repository browser.