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