summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/mips/jxport.c
blob: e23b401e7caf4a714c0829250b14b6f88a6b9ec3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#if defined(JAZZ)

/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    jxport.c

Abstract:

    This module implements the code that provides communication between
    the kernel debugger on a MIPS R3000 or R4000 Jazz system and the host
    system.

Author:

    David N. Cutler (davec) 28-Apr-1991

Environment:

    Kernel mode

Revision History:

--*/

#include "fwp.h"
#include "jazzserp.h"

// TEMPTEMP
#define KDPORT_ENTRY 4

extern BOOLEAN MctadrRev2;


//
// Temporarily, we use counter to do the timeout
//

#define TIMEOUT_COUNT 1024*512

PUCHAR KdComPortInUse=NULL;

//
// Define serial port read and write addresses.
//

#define SP_READ ((PSP_READ_REGISTERS)(SP_VIRTUAL_BASE))
#define SP_WRITE ((PSP_WRITE_REGISTERS)(SP_VIRTUAL_BASE))

BOOLEAN
KdPortInitialize (
    PDEBUG_PARAMETERS DebugParameters,
    PLOADER_PARAMETER_BLOCK LoaderBlock,
    BOOLEAN Initialize
    )

/*++

Routine Description:

    This routine initializes the serial port used by the kernel debugger
    and must be called during system initialization.

Arguments:

    DebugParameter - Supplies a pointer to the debug port parameters.

    LoaderBlock - Supplies a pointer to the loader parameter block.

    Initialize - Specifies a boolean value that determines whether the
        debug port is initialized or just the debug port parameters
        are captured.

Return Value:

    A value of TRUE is returned is the port was successfully initialized.
    Otherwise, a value of FALSE is returned.


--*/

{

    UCHAR DataByte;
    ENTRYLO Pte[2];

    //
    // Map the serial port into the system virtual address space by loading
    // a fixed TB entry.
    //

    Pte[0].PFN = SP_PHYSICAL_BASE >> PAGE_SHIFT;
    Pte[0].G = 1;
    Pte[0].V = 1;
    Pte[0].D = 1;

#if defined(R3000)

    Pte[0].N = 1;

#endif

#if defined(R4000)

    Pte[0].C = UNCACHED_POLICY;

    Pte[1].PFN = 0;
    Pte[1].G = 1;
    Pte[1].V = 0;
    Pte[1].D = 0;
    Pte[1].C = 0;

#endif

    KdComPortInUse=(PUCHAR)SERIAL0_PHYSICAL_BASE;
    KeFillFixedEntryTb((PHARDWARE_PTE)&Pte[0],
                       (PVOID)SP_VIRTUAL_BASE,
                       KDPORT_ENTRY);

    //
    // Clear the divisor latch, clear all interrupt enables, and reset and
    // disable the FIFO's.
    //

    WRITE_REGISTER_UCHAR(&SP_WRITE->LineControl, 0x0);
    WRITE_REGISTER_UCHAR(&SP_WRITE->InterruptEnable, 0x0);
    DataByte = 0;
    ((PSP_FIFO_CONTROL)(&DataByte))->ReceiveFifoReset = 1;
    ((PSP_FIFO_CONTROL)(&DataByte))->TransmitFifoReset = 1;
    WRITE_REGISTER_UCHAR(&SP_WRITE->FifoControl, DataByte);

    //
    // Set the divisor latch and set the baud rate to 19200 baud.
    //
    ((PSP_LINE_CONTROL)(&DataByte))->DivisorLatch = 1;
    WRITE_REGISTER_UCHAR(&SP_WRITE->LineControl, DataByte);

    //
    // ****** Temporary ******
    //
    // The following code temporarily decides how to load the baud rate
    // register based on whether a second level cache is present. This
    // information should be acquired from the configuration information.
    //
#ifdef DUO
    // 14 doesn't work
    DataByte = 26;
#else
    if (MctadrRev2) {
        DataByte = 26;
    } else {
        DataByte = BAUD_RATE_19200;
    }
#endif

    WRITE_REGISTER_UCHAR(&SP_WRITE->TransmitBuffer, DataByte);
    WRITE_REGISTER_UCHAR(&SP_WRITE->InterruptEnable, 0x0);

    //
    // Clear the divisor latch and set the character size to eight bits
    // with one stop bit and no parity checking.
    //

    DataByte = 0;
    ((PSP_LINE_CONTROL)(&DataByte))->CharacterSize = EIGHT_BITS;
    WRITE_REGISTER_UCHAR(&SP_WRITE->LineControl, DataByte);

    //
    // Set data terminal ready and request to send.
    //

    DataByte = 0;
    ((PSP_MODEM_CONTROL)(&DataByte))->DataTerminalReady = 1;
    ((PSP_MODEM_CONTROL)(&DataByte))->RequestToSend = 1;
    WRITE_REGISTER_UCHAR(&SP_WRITE->ModemControl, DataByte);
    return TRUE;
}

ULONG
KdPortGetByte (
    OUT PUCHAR Input
    )

/*++

Routine Description:

    This routine gets a byte from the serial port used by the kernel
    debugger.

    N.B. It is assumed that the IRQL has been raised to the highest
        level, and necessary multiprocessor synchronization has been
        performed before this routine is called.

Arguments:

    Input - Supplies a pointer to a variable that receives the input
        data byte.

Return Value:

    CP_GET_SUCCESS is returned if a byte is successfully read from the
        kernel debugger line.

    CP_GET_ERROR is returned if error encountered during reading.

    CP_GET_NODATA is returned if timeout.

--*/

{

    UCHAR DataByte;
    ULONG TimeoutCount;

    //
    // Wait until data is available in the receive buffer.
    //

    TimeoutCount = TIMEOUT_COUNT;
    do {
        KeStallExecutionProcessor(1);
        DataByte = READ_REGISTER_UCHAR(&SP_READ->LineStatus);
        if (TimeoutCount-- == 0) {
            return CP_GET_NODATA;
        }
    } while (((PSP_LINE_STATUS)(&DataByte))->DataReady == 0);

    //
    // Read input byte and store in callers buffer.
    //

    *Input = READ_REGISTER_UCHAR(&SP_READ->ReceiveBuffer);

    //
    // Return function value as the not of the error indicators.
    //

    if (((PSP_LINE_STATUS)(&DataByte))->ParityError ||
        ((PSP_LINE_STATUS)(&DataByte))->FramingError ||
        ((PSP_LINE_STATUS)(&DataByte))->OverrunError ||
        ((PSP_LINE_STATUS)(&DataByte))->BreakIndicator) {
        return CP_GET_ERROR;
    } else {
        return CP_GET_SUCCESS;
    }
}

ULONG
KdPortPollByte (
    OUT PUCHAR Input
    )

/*++

Routine Description:

    This routine gets a byte from the serial port used by the kernel
    debugger iff a byte is available.

    N.B. It is assumed that the IRQL has been raised to the highest
        level, and necessary multiprocessor synchronization has been
        performed before this routine is called.

Arguments:

    Input - Supplies a pointer to a variable that receives the input
        data byte.

Return Value:

    CP_GET_SUCCESS is returned if a byte is successfully read from the
        kernel debugger line.

    CP_GET_ERROR is returned if an error encountered during reading.

    CP_GET_NODATA is returned if timeout occurs.

--*/

{

    return KdPortGetByte(Input);

}

VOID
KdPortPutByte (
    IN UCHAR Output
    )

/*++

Routine Description:

    This routine puts a byte to the serial port used by the kernel debugger.

    N.B. It is assumed that the IRQL has been raised to the highest level,
        and necessary multiprocessor synchronization has been performed
        before this routine is called.

Arguments:

    Output - Supplies the output data byte.

Return Value:

    None.

--*/

{

    UCHAR DataByte;

    //
    // Wait for transmit ready.
    //

    do {
        DataByte = READ_REGISTER_UCHAR(&SP_READ->LineStatus);
    } while (((PSP_LINE_STATUS)(&DataByte))->TransmitHoldingEmpty == 0);

    //
    // Wait for data set ready.
    //

//    do {
//        DataByte = READ_REGISTER_UCHAR(&SP_READ->ModemStatus);
//    } while (((PSP_MODEM_STATUS)(&DataByte))->DataSetReady == 0);

    //
    // Transmit data.
    //

    WRITE_REGISTER_UCHAR(&SP_WRITE->TransmitBuffer, Output);
    return;
}

VOID
KdPortRestore (
    VOID
    )

/*++

Routine Description:

    This routine restores the state of the serial port after the kernel
    debugger has been active.

    N.B. This routine performs no function on the Jazz system.

Arguments:

    None.

Return Value:

    None.

--*/

{

    return;
}

VOID
KdPortSave (
    VOID
    )

/*++

Routine Description:

    This routine saves the state of the serial port and initializes the port
    for use by the kernel debugger.

    N.B. This routine performs no function on the Jazz system.

Arguments:

    None.

Return Value:

    None.

--*/

{

    return;
}

#endif