source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm@ 315

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

Small optimization, moved around some serial code to avoid a few jumps and unnecessary number of sectors check.

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