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