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

Last change on this file since 320 was 292, checked in by gregli@…, 13 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
RevLine 
[150]1; Project name : XTIDE Universal BIOS
2; Description : Serial Device Command functions.
3
4; Section containing code
5SECTION .text
6
[292]7%define SERIALSERVER_AH_ALREADY_HAS_COMMAND_BYTE
8%define SERIALSERVER_NO_ZERO_SECTOR_COUNTS
9
[150]10;--------------------------------------------------------------------
[179]11; SerialCommand_OutputWithParameters
[150]12; Parameters:
[179]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
[150]20; Returns:
21; AH: INT 13h Error Code
[258]22; CX: Number of successfully transferred sectors (for transfer commands)
[150]23; CF: Cleared if success, Set if error
24; Corrupts registers:
[179]25; AL, BX, CX, DX, (ES:SI for data transfer commands)
[150]26;--------------------------------------------------------------------
27ALIGN JUMP_ALIGN
[179]28SerialCommand_OutputWithParameters:
[181]29
[277]30 mov ah,SerialServer_Command_Read
[181]31
[179]32 mov al,[bp+IDEPACK.bCommand]
[150]33
[179]34 cmp al,20h ; Read Sectors IDE command
35 jz .readOrWrite
[277]36 inc ah ; now SerialServer_Protocol_Write
[179]37 cmp al,30h ; Write Sectors IDE command
38 jz .readOrWrite
[181]39
[179]40; all other commands return success
41; including function 0ech which should return drive information, this is handled with the identify functions
[216]42;
[179]43 xor ah,ah ; also clears carry
44 ret
[181]45
46.readOrWrite:
[179]47 mov [bp+IDEPACK.bFeatures],ah ; store protocol command
[292]48
[233]49 mov dx, [di+DPT_SERIAL.wSerialPortAndBaud]
[181]50
[292]51ALIGN JUMP_ALIGN
52SerialCommand_FallThroughToSerialServer_SendReceive:
[150]53
[292]54%include "SerialServer.asm"
[181]55
[292]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
[150]65;--------------------------------------------------------------------
[179]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:
[203]79;
[223]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.
[203]83;
[223]84; But drive detection isn't the only case - we also need to get the right drive when called on int13h/25h.
[203]85;
86; The decision tree:
87;
88; Master:
[234]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)
[223]93;
[203]94; Slave:
[234]95; wSerialPortAndBaud Non-Zero:
96; previous serial drive not found: -> Error - Not Found (4)
[242]97; previous serial drive found: -> Continue with wSerialPackedAndBaud (5)
[234]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)
[203]101;
[223]102; (1) This was a port/baud that was explicitly set with the configurator. In the drive detection case, as this
[234]103; is the Master, we are checking out a new controller, and so don't care if we already have a serial drive.
[203]104; And as with the int13h/25h case, we just go off and get the needed information using the user's setting.
[223]105; (2) We are using the special .ideVarsSerialAuto structure. During drive detection, we would only be here
[242]106; if we hadn't already seen a serial drive (since we only scan if no explicit drives are set),
[234]107; so we go off to scan.
[223]108; (3) We are using the special .ideVarsSerialAuto structure. We won't get here during drive detection, but
[203]109; we might get here on an int13h/25h call. If we have scanned COM drives, they are the ONLY serial drives
[234]110; in use, and so we use the values from the previously seen serial drive DPT.
[223]111; (4) No master has been found yet, therefore no slave should be found. Avoiding the slave reduces boot time,
[203]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,
[223]114; we will do the slave scan, which isn't harmful, it just wastes time. But the most common case (by a wide
[203]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
[223]117; controller scenario being called with int13h/25h, we need to use the value in bSerialPackedPortAndBaud
[203]118; to make sure we get the proper drive.
[223]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
[203]122; master scan.
[223]123;
[233]124 mov dx,[cs:bp+IDEVARS.wSerialPortAndBaud]
125 xor ax,ax
[277]126
[233]127 push si
128 call FindDPT_ToDSDIforSerialDevice
129 pop si
[258]130%ifdef MODULE_SERIAL_FLOPPY
[262]131 jnc .founddpt
[258]132;
133; If not found above with FindDPT_ToDSDIforSerialDevice, DI will point to the DPT after the last hard disk DPT
[277]134; So, if there was a previously found floppy disk, DI will point to that DPT and we use that value for the slave.
[258]135;
136 cmp byte [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], 0
137 jz .notfounddpt
138.founddpt:
139%else
[277]140 jc .notfounddpt
[258]141%endif
[242]142 mov ax, [di+DPT_SERIAL.wSerialPortAndBaud]
143.notfounddpt:
[223]144
[203]145 test bh, FLG_DRVNHEAD_DRV
146 jz .master
[179]147
[233]148 test ax,ax ; Take care of the case that is different between master and slave.
[292]149 jz SerialCommand_ReturnError
[203]150
151; fall-through
[223]152.master:
[233]153 test dx,dx
154 jnz .identifyDeviceInDX
[179]155
[277]156 xchg dx, ax ; move ax to dx (move previously found serial drive to dx, could be zero)
[223]157
[292]158.identifyDeviceInDX:
[179]159
[292]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.