summaryrefslogblamecommitdiffstats
path: root/private/ntos/fw/mips/jxkbd.c
blob: dd1602f680f6fb186e0404f4f5e325b93b857d1d (plain) (tree)
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491










































































































































































































































































































































































































































































































                                                                                  
#if defined(JAZZ)


/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    jxkbd.c

Abstract:

    This module implements the keyboard boot driver for the Jazz system.

Author:

    David M. Robinson (davidro) 8-Aug-1991

Environment:

    Kernel mode.


Revision History:

--*/

#include "fwp.h"
#ifdef DUO
#include "duoint.h"
#else
#include "jazzint.h"
#endif
#include "iodevice.h"
#include "string.h"


ARC_STATUS
KeyboardClose (
    IN ULONG FileId
    );

ARC_STATUS
KeyboardMount (
    IN PCHAR MountPath,
    IN MOUNT_OPERATION Operation
    );

ARC_STATUS
KeyboardOpen (
    IN PCHAR OpenPath,
    IN OPEN_MODE OpenMode,
    IN OUT PULONG FileId
    );

ARC_STATUS
KeyboardRead (
    IN ULONG FileId,
    IN PVOID Buffer,
    IN ULONG Length,
    OUT PULONG Count
    );

ARC_STATUS
KeyboardGetReadStatus (
    IN ULONG FileId
    );

ARC_STATUS
KeyboardSeek (
    IN ULONG FileId,
    IN PLARGE_INTEGER Offset,
    IN SEEK_MODE SeekMode
    );

ARC_STATUS
KeyboardWrite (
    IN ULONG FileId,
    IN PVOID Buffer,
    IN ULONG Length,
    OUT PULONG Count
    );

ARC_STATUS
KeyboardGetFileInformation (
    IN ULONG FileId,
    OUT PFILE_INFORMATION Finfo
    );

//
// Define static data.
//
BL_DEVICE_ENTRY_TABLE KeyboardEntryTable = {
    KeyboardClose,
    KeyboardMount,
    KeyboardOpen,
    KeyboardRead,
    KeyboardGetReadStatus,
    KeyboardSeek,
    KeyboardWrite,
    KeyboardGetFileInformation,
    (PARC_SET_FILE_INFO_ROUTINE)NULL
    };

PCHAR KeyboardDevicePath = "multi(0)key(0)keyboard(0)";

KEYBOARD_BUFFER KbdBuffer;

BOOLEAN FwLeftShift;
BOOLEAN FwRightShift;
BOOLEAN FwControl;
BOOLEAN FwAlt;
BOOLEAN FwCapsLock;


//
// Define prototypes for all routines used by this module.
//

UCHAR
FwInputScanCode(
    VOID
    );


ARC_STATUS
KeyboardGetFileInformation (
    IN ULONG FileId,
    OUT PFILE_INFORMATION Finfo
    )

/*++

Routine Description:

    This function returns EINVAL as no FileInformation can be
    returned for the Keyboard driver.

Arguments:

    The arguments are not used.

Return Value:

    EINVAL is returned

--*/

{
    return EINVAL;
}


ARC_STATUS
KeyboardClose (
    IN ULONG FileId
    )

/*++

Routine Description:

    This function closes the file table entry specified by the file id.

Arguments:

    FileId - Supplies the file table index.

Return Value:

    ESUCCESS is returned

--*/

{

    BlFileTable[FileId].Flags.Open = 0;
    return ESUCCESS;
}

ARC_STATUS
KeyboardMount (
    IN PCHAR MountPath,
    IN MOUNT_OPERATION Operation
    )

/*++

Routine Description:


Arguments:


Return Value:


--*/

{
    return EINVAL;
}

ARC_STATUS
KeyboardOpen (
    IN PCHAR OpenPath,
    IN OPEN_MODE OpenMode,
    IN OUT PULONG FileId
    )
/*++

Routine Description:

    This is the open routine for the Keyboard device.

Arguments:

    OpenPath - Supplies the pathname of the device to open.

    OpenMode - Supplies the mode (read only, write only, or read write).

    FileId - Supplies a free file identifier to use.  If the device is already
             open this parameter can be used to return the file identifier
             already in use.

Return Value:

    If the open was successful, ESUCCESS is returned, otherwise an error code
    is returned.

--*/
{
    PCONSOLE_CONTEXT Context;

    Context = &BlFileTable[*FileId].u.ConsoleContext;
    if ( strstr(OpenPath, ")console(1)" ) != NULL ) {
        Context->ConsoleNumber = 1;
    } else {
        Context->ConsoleNumber = 0;
    }
    return ESUCCESS;
}

ARC_STATUS
KeyboardRead (
    IN ULONG FileId,
    IN PVOID Buffer,
    IN ULONG Length,
    OUT PULONG Count
    )
/*++

Routine Description:

    This routine reads keys from the keyboard and passes along either ascii
    or Unicode characters to the caller.

Arguments:

    FileId - Supplies a file id.

    Buffer - Supplies a pointer to a buffer to receive the characters.

    Length - Supplies the length of Buffer in bytes.

    Count - Returns the count of the bytes that were received.

Return Value:

    A value of ESUCCESS is returned.

--*/
{
    PCHAR OutputBuffer;
    PCONSOLE_CONTEXT Context;
    BOOLEAN Unicode;

    OutputBuffer = (PCHAR)Buffer;
    Context = &BlFileTable[FileId].u.ConsoleContext;

    if (Context->ConsoleNumber == 1) {
        if (Length & 1) {

            //
            // Length is not an even number of bytes, return an error.
            //

            return(EINVAL);
        }
        Unicode = TRUE;
    } else {
        Unicode = FALSE;
    }

    *Count = 0;
    while (*Count < Length) {
        *OutputBuffer++ = FwInputScanCode();
        (*Count)++;
        if (Unicode) {
            *OutputBuffer++ = 0;
            (*Count)++;
        }
    }
    return ESUCCESS;
}


ARC_STATUS
KeyboardGetReadStatus (
    IN ULONG FileId
    )
/*++

Routine Description:

    This routine checks to see if a character is available from the keyboard.

Arguments:

    FileId - Supplies a file identifier.

Return Value:

    Returns ESUCCESS is a byte is available, otherwise EAGAIN is returned.

--*/
{
    if (KbdBuffer.ReadIndex == KbdBuffer.WriteIndex) {
        return EAGAIN;
    } else {
        return ESUCCESS;
    }
}


ARC_STATUS
KeyboardWrite (
    IN ULONG FileId,
    IN PVOID Buffer,
    IN ULONG Length,
    OUT PULONG Count
    )

/*++

Routine Description:

Arguments:

Return Value:

    ESUCCESS is returned.

--*/

{
    return ESUCCESS;
}

ARC_STATUS
KeyboardSeek (
    IN ULONG FileId,
    IN PLARGE_INTEGER Offset,
    IN SEEK_MODE SeekMode
    )

/*++

Routine Description:

Arguments:

Return Value:

    ESUCCESS is returned.

--*/

{
    return ESUCCESS;
}

VOID
KeyboardInitialize (
    IN OUT PDRIVER_LOOKUP_ENTRY LookupTableEntry,
    IN ULONG Entries
    )

/*++

Routine Description:

    This routine initializes the keyboard control registers, clears the
    fifo, and initializes the keyboard entry in the driver lookup table.

Arguments:

    LookupTableEntry - Supplies a pointer to the first free location in the
                       driver lookup table.

    Entries - Supplies the number of free entries in the driver lookup table.

Return Value:

    None.

--*/

{
    UCHAR Byte;
    //
    // Initialize the driver lookup table.
    //

    LookupTableEntry->DevicePath = KeyboardDevicePath;
    LookupTableEntry->DispatchTable = &KeyboardEntryTable;

    //
    // Initialize static data.
    //

    FwLeftShift = FALSE;
    FwRightShift = FALSE;
    FwControl = FALSE;
    FwAlt = FALSE;
    FwCapsLock = FALSE;

    KbdBuffer.ReadIndex = KbdBuffer.WriteIndex = 0;

    //
    // Call the selftest keyboard initialization routine.
    //
    InitKeyboard();

    //
    // Enable kbd interrupts in the keyboard controller.
    //
    SendKbdCommand(KBD_CTR_READ_COMMAND);
    GetKbdData(&Byte,100);

    //
    // Clear translation mode and enable Kbd interrupt.
    //
    Byte = (Byte & 0xBF) | KbdCommandEnableKbdInt;
    SendKbdCommand(KBD_CTR_WRITE_COMMAND);
    SendKbdData(Byte);

    //
    // Enable keyboard interrupts in the interrupt enable register.
    //
    WRITE_REGISTER_USHORT(&((PINTERRUPT_REGISTERS)INTERRUPT_VIRTUAL_BASE)->Enable,
                          (1 << (KEYBOARD_VECTOR - DEVICE_VECTORS - 1)));


    return;
}

UCHAR
FwInputScanCode (
    VOID
    )

/*++

Routine Description:

    This routine reads a byte from the keyboard.  If no data is available,
    it blocks until a key is typed.

Arguments:

    None.

Return Value:

    Returns the character read from the keyboard.

--*/

{
    UCHAR ScanCode;

    while (KbdBuffer.ReadIndex == KbdBuffer.WriteIndex) {
    }
    KbdBuffer.ReadIndex = (KbdBuffer.ReadIndex+1) % KBD_BUFFER_SIZE;
    ScanCode = KbdBuffer.Buffer[KbdBuffer.ReadIndex];

    return ScanCode;
}
#endif