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 | mov dh, 40h ; Clear DH and make sure CF is set if error |
---|
56 | mov dl, [cs:di] |
---|
57 | eSHL_IM dx, 2 ; shift from one byte to two |
---|
58 | jz SHORT .error |
---|
59 | |
---|
60 | ; |
---|
61 | ; Test for COM port presence, write to and read from registers |
---|
62 | ; |
---|
63 | push dx |
---|
64 | add dl, Serial_UART_lineControl |
---|
65 | mov al, 9Ah |
---|
66 | out dx, al |
---|
67 | in al, dx |
---|
68 | pop dx |
---|
69 | cmp al, 9Ah |
---|
70 | jne SHORT .nextPort |
---|
71 | |
---|
72 | mov al, 0Ch |
---|
73 | out dx, al |
---|
74 | in al, dx |
---|
75 | cmp al, 0Ch |
---|
76 | jne SHORT .nextPort |
---|
77 | |
---|
78 | ; |
---|
79 | ; Begin baud rate scan on this port... |
---|
80 | ; |
---|
81 | ; On a scan, we support 6 baud rates, starting here and going higher by a factor of two each step, with a |
---|
82 | ; small jump between 9600 and 38800. These 6 were selected since we wanted to support 9600 baud and 115200, |
---|
83 | ; *on the server side* if the client side had a 4x clock multiplier, a 2x clock multiplier, or no clock multiplier. |
---|
84 | ; |
---|
85 | ; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0Ch (9600 baud), and |
---|
86 | ; 04h (28800 baud), 02h (57600 baud), 01h (115200 baud) |
---|
87 | ; |
---|
88 | ; Note: hardware baud multipliers (2x, 4x, 8x) will impact the final baud rate and are not known at this level |
---|
89 | ; |
---|
90 | mov dh, 30h * 2 ; multiply by 2 since we are about to divide by 2 |
---|
91 | mov dl, [cs:di] ; restore single byte port address for scan |
---|
92 | |
---|
93 | .nextBaud: |
---|
94 | shr dh, 1 |
---|
95 | jz SHORT .nextPort |
---|
96 | cmp dh, 6 ; skip from 6 to 4, to move from the top of the 9600 baud range |
---|
97 | jne SHORT .testBaud ; to the bottom of the 115200 baud range |
---|
98 | mov dh, 4 |
---|
99 | |
---|
100 | .testBaud: |
---|
101 | call SerialServerScan_CheckForServer_PortAndBaudInDX |
---|
102 | jc SHORT .nextBaud |
---|
103 | |
---|
104 | .error: |
---|
105 | ret |
---|
106 | |
---|
107 | .scanPortAddresses: db SERIAL_COM7_IOADDRESS >> 2 |
---|
108 | db SERIAL_COM6_IOADDRESS >> 2 |
---|
109 | db SERIAL_COM5_IOADDRESS >> 2 |
---|
110 | db SERIAL_COM4_IOADDRESS >> 2 |
---|
111 | db SERIAL_COM3_IOADDRESS >> 2 |
---|
112 | db SERIAL_COM2_IOADDRESS >> 2 |
---|
113 | db SERIAL_COM1_IOADDRESS >> 2 |
---|
114 | db 0 |
---|
115 | |
---|
116 | |
---|
117 | ;-------------------------------------------------------------------- |
---|
118 | ; SerialServer_CheckForServer_PortAndBaudInDX: |
---|
119 | ; Parameters: |
---|
120 | ; BH: Drive Select byte for Drive and Head Select Register |
---|
121 | ; 0xAx: Scan for drive, low nibble indicates drive |
---|
122 | ; 0x0: Scan for Server, independent of drives |
---|
123 | ; DX: Baud and Port |
---|
124 | ; CH: 1: We are doing a scan for the serial server |
---|
125 | ; 0: We are working off a specific port given by the user |
---|
126 | ; CL: 1, for one sector to read |
---|
127 | ; ES:SI: Ptr to buffer for return |
---|
128 | ; Returns: |
---|
129 | ; AH: INT 13h Error Code |
---|
130 | ; CF: Cleared if success, Set if error |
---|
131 | ; Corrupts registers: |
---|
132 | ; AL, BX |
---|
133 | ;-------------------------------------------------------------------- |
---|
134 | SerialServerScan_CheckForServer_PortAndBaudInDX: |
---|
135 | push bp ; setup fake SerialServer_Command |
---|
136 | push dx ; send port baud and rate, returned in inquire packet |
---|
137 | ; (and possibly returned in the drive identification string) |
---|
138 | push cx ; send number of sectors, and if it is on a scan or not |
---|
139 | mov bl, SerialServer_Command_Inquire ; protocol command onto stack with bh |
---|
140 | push bx |
---|
141 | |
---|
142 | mov bp, sp |
---|
143 | call SerialServer_SendReceive |
---|
144 | |
---|
145 | pop bx |
---|
146 | pop cx |
---|
147 | pop dx |
---|
148 | pop bp |
---|
149 | |
---|
150 | ret |
---|
151 | |
---|