[277] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Serial Server Support, Scan for Server
|
---|
[601] | 3 |
|
---|
[277] | 4 | ;
|
---|
| 5 | ; This functionality is broken out from SerialServer as it may only be needed during
|
---|
| 6 | ; initialization to find a server, and then could be discarded, (for example the case
|
---|
| 7 | ; of a TSR).
|
---|
| 8 |
|
---|
[376] | 9 | ;
|
---|
[526] | 10 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 11 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 12 | ;
|
---|
| 13 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 14 | ; it under the terms of the GNU General Public License as published by
|
---|
| 15 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | ; (at your option) any later version.
|
---|
[526] | 17 | ;
|
---|
[376] | 18 | ; This program is distributed in the hope that it will be useful,
|
---|
| 19 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[526] | 21 | ; GNU General Public License for more details.
|
---|
[376] | 22 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 23 | ;
|
---|
| 24 |
|
---|
[526] | 25 |
|
---|
[277] | 26 | %include "SerialServer.inc"
|
---|
[526] | 27 |
|
---|
[277] | 28 | ; Section containing code
|
---|
| 29 | SECTION .text
|
---|
[526] | 30 |
|
---|
[277] | 31 | ;--------------------------------------------------------------------
|
---|
[526] | 32 | ; SerialServerScan_ScanForServer:
|
---|
[277] | 33 | ; Parameters:
|
---|
[567] | 34 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
| 35 | ; 0xAx: Scan for drive, low nibble indicates drive
|
---|
| 36 | ; 0x0: Scan for Server, independent of drives
|
---|
[277] | 37 | ; DX: Port and Baud to Scan for
|
---|
| 38 | ; 0: Scan a known set of ports and bauds
|
---|
| 39 | ; ES:SI: Ptr to buffer for return
|
---|
| 40 | ; Returns:
|
---|
| 41 | ; CF: Cleared if success, Set if error
|
---|
| 42 | ; Corrupts registers:
|
---|
| 43 | ; AL, BX, CX, DX, DI
|
---|
| 44 | ;--------------------------------------------------------------------
|
---|
[526] | 45 | SerialServerScan_ScanForServer:
|
---|
[601] | 46 | mov cx, 1 ; one sector, not scanning (default)
|
---|
[277] | 47 |
|
---|
[601] | 48 | test dx, dx
|
---|
| 49 | jnz SHORT SerialServerScan_CheckForServer_PortAndBaudInDX
|
---|
[277] | 50 |
|
---|
[601] | 51 | mov di, .scanPortAddresses-1
|
---|
| 52 | mov ch, 1 ; tell server that we are scanning
|
---|
[277] | 53 |
|
---|
| 54 | .nextPort:
|
---|
[601] | 55 | inc di ; load next port address
|
---|
| 56 | mov dh, 40h ; Clear DH and make sure CF is set if error
|
---|
| 57 | mov dl, [cs:di]
|
---|
| 58 | eSHL_IM dx, 2 ; shift from one byte to two
|
---|
| 59 | jz SHORT .error
|
---|
[277] | 60 |
|
---|
| 61 | ;
|
---|
| 62 | ; Test for COM port presence, write to and read from registers
|
---|
| 63 | ;
|
---|
[601] | 64 | push dx
|
---|
| 65 | add dl, Serial_UART_lineControl
|
---|
| 66 | mov al, 9Ah
|
---|
| 67 | out dx, al
|
---|
| 68 | in al, dx
|
---|
| 69 | pop dx
|
---|
| 70 | cmp al, 9Ah
|
---|
| 71 | jne SHORT .nextPort
|
---|
[277] | 72 |
|
---|
[601] | 73 | mov al, 0Ch
|
---|
| 74 | out dx, al
|
---|
| 75 | in al, dx
|
---|
| 76 | cmp al, 0Ch
|
---|
| 77 | jne SHORT .nextPort
|
---|
[277] | 78 |
|
---|
| 79 | ;
|
---|
| 80 | ; Begin baud rate scan on this port...
|
---|
| 81 | ;
|
---|
| 82 | ; On a scan, we support 6 baud rates, starting here and going higher by a factor of two each step, with a
|
---|
| 83 | ; small jump between 9600 and 38800. These 6 were selected since we wanted to support 9600 baud and 115200,
|
---|
| 84 | ; *on the server side* if the client side had a 4x clock multiplier, a 2x clock multiplier, or no clock multiplier.
|
---|
| 85 | ;
|
---|
[589] | 86 | ; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0Ch (9600 baud), and
|
---|
[277] | 87 | ; 04h (28800 baud), 02h (57600 baud), 01h (115200 baud)
|
---|
| 88 | ;
|
---|
[589] | 89 | ; Note: hardware baud multipliers (2x, 4x, 8x) will impact the final baud rate and are not known at this level
|
---|
[277] | 90 | ;
|
---|
[601] | 91 | mov dh, 30h * 2 ; multiply by 2 since we are about to divide by 2
|
---|
| 92 | mov dl, [cs:di] ; restore single byte port address for scan
|
---|
[277] | 93 |
|
---|
| 94 | .nextBaud:
|
---|
[601] | 95 | shr dh, 1
|
---|
| 96 | jz SHORT .nextPort
|
---|
| 97 | cmp dh, 6 ; skip from 6 to 4, to move from the top of the 9600 baud range
|
---|
| 98 | jne SHORT .testBaud ; to the bottom of the 115200 baud range
|
---|
| 99 | mov dh, 4
|
---|
[277] | 100 |
|
---|
| 101 | .testBaud:
|
---|
[601] | 102 | call SerialServerScan_CheckForServer_PortAndBaudInDX
|
---|
| 103 | jc SHORT .nextBaud
|
---|
[277] | 104 |
|
---|
[526] | 105 | .error:
|
---|
[601] | 106 | ret
|
---|
[277] | 107 |
|
---|
[601] | 108 | .scanPortAddresses:
|
---|
| 109 | db SERIAL_COM7_IOADDRESS >> 2
|
---|
| 110 | db SERIAL_COM6_IOADDRESS >> 2
|
---|
| 111 | db SERIAL_COM5_IOADDRESS >> 2
|
---|
| 112 | db SERIAL_COM4_IOADDRESS >> 2
|
---|
| 113 | db SERIAL_COM3_IOADDRESS >> 2
|
---|
| 114 | db SERIAL_COM2_IOADDRESS >> 2
|
---|
| 115 | db SERIAL_COM1_IOADDRESS >> 2
|
---|
| 116 | db 0
|
---|
[277] | 117 |
|
---|
[526] | 118 |
|
---|
[277] | 119 | ;--------------------------------------------------------------------
|
---|
| 120 | ; SerialServer_CheckForServer_PortAndBaudInDX:
|
---|
| 121 | ; Parameters:
|
---|
[567] | 122 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
| 123 | ; 0xAx: Scan for drive, low nibble indicates drive
|
---|
| 124 | ; 0x0: Scan for Server, independent of drives
|
---|
[277] | 125 | ; DX: Baud and Port
|
---|
| 126 | ; CH: 1: We are doing a scan for the serial server
|
---|
[567] | 127 | ; 0: We are working off a specific port given by the user
|
---|
[277] | 128 | ; CL: 1, for one sector to read
|
---|
| 129 | ; ES:SI: Ptr to buffer for return
|
---|
| 130 | ; Returns:
|
---|
| 131 | ; AH: INT 13h Error Code
|
---|
| 132 | ; CF: Cleared if success, Set if error
|
---|
| 133 | ; Corrupts registers:
|
---|
| 134 | ; AL, BX
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
| 136 | SerialServerScan_CheckForServer_PortAndBaudInDX:
|
---|
[601] | 137 | push bp ; setup fake SerialServer_Command
|
---|
| 138 | push dx ; send port baud and rate, returned in inquire packet
|
---|
| 139 | ; (and possibly returned in the drive identification string)
|
---|
| 140 | push cx ; send number of sectors, and if it is on a scan or not
|
---|
| 141 | mov bl, SerialServer_Command_Inquire ; protocol command onto stack with bh
|
---|
| 142 | push bx
|
---|
[277] | 143 |
|
---|
[601] | 144 | mov bp, sp
|
---|
| 145 | call SerialServer_SendReceive
|
---|
[277] | 146 |
|
---|
[601] | 147 | pop bx
|
---|
| 148 | pop cx
|
---|
| 149 | pop dx
|
---|
| 150 | pop bp
|
---|
[277] | 151 |
|
---|
[601] | 152 | ret
|
---|
[277] | 153 |
|
---|