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

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

Moved the bulk of the serial code to the assembly library, for inclusion in other utilities. Fixed a bug in int13h.asm when floppy support was not enabled that was preventing foreign drives from working properly.

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