Commit Graph

73 Commits

Author SHA1 Message Date
Gerd Hoffmann 90fa511527 kbd: make enqueue_key public, add ascii_to_keycode
serial console wants queue key events and needs to map ascii chars to
the keycode, so make enqueue_key public and also exports a helper
function so sercon can use the scan_to_keycode mapping table.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2017-09-22 11:13:22 -04:00
Kevin O'Connor 8d8d483d52 kbd: Move extended and release events out of special key detection switch
Move checking for extended scancodes and key release to the top of
__process_key().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 11:39:04 -04:00
Kevin O'Connor 1bdc9aeeae kbd: Generate interrupt events for SysReq, PrtScr, and Break
Generate the appropriate interrupt events for the given keys.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor 6cd69b75ea kbd: Ignore fake shift keys
AT keyboards can produce "fake" shift keys on some extended events.
It's not necessary to process these artificial events as the actual
extended keys are detected directly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor fec2140c86 kbd: Move checking for special keys in __process_keys() into switch
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor e8c0c6195c kbd: Extract out shift flag setting into new function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor 632ebf5b90 kbd: Merge bda->kbd_flag0 and bda->kbd_flag1
Merge the two consecutive u8 fields into a single u16 field.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor da90e73300 kbd: Suppress keys without mappings
Don't warn if a key without a mapping is pressed - it's known that
some keys aren't mapped to keycodes.  Suppress these keys instead of
sending 0x0000 to the keyboard buffer - as 0x0000 can confuse some
programs.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor b47c6e3f70 kbd: Implement extended keycode mappings for keypad-enter and keypad-/
On a 101-key keyboard the keypad enter and keypad '/' keys have unique
BIOS keycodes that are distinct from the main keyboard enter and '/'
keys.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:22:10 -04:00
Kevin O'Connor 2490327b79 kbd: Implement 101-key keyboard keycode mapping
The current keyboard code only supports the keycode mappings for
83-key keyboards (plus handling for alt-esc and f11/f12).  Add a more
complete mapping of keycodes for 101-key keyboards.  This adds more
alt key and ctrl key mappings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-12 10:17:21 -04:00
Kevin O'Connor 9720484aec kbd: Refactor capslock and numlock handling
Simplify the scan_to_keycode[] table by implementing numlock and
capslock checking in the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-01-14 14:02:06 -05:00
Kevin O'Connor ea5d60a154 kbd: Don't treat scancode and asciicode as separate values
The scancode/asciicode pair can be more easily handled as a single
16bit value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-01-14 13:58:51 -05:00
Kevin O'Connor 1208543956 Revert "Use the extra stack for 16bit USB and PS2 keyboard/mouse commands."
It's not valid to pass a pointer to a stack variable through the
stack_hop() call (because the call changes the stack segment).  This
bug was probably not noticed before because by default
(CONFIG_ENTRY_EXTRASTACK) SeaBIOS uses the extra stack on all 16bit
entry points, and the internal stack_hop() with that config option is
effectively a no-op.

This reverts commit d488a7683d.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-09-30 09:42:54 -04:00
Kevin O'Connor 43197a2aec Abstract reset call (and possible 16bit mode switch) into reset() function.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-06-06 13:49:33 -04:00
Kevin O'Connor 2d2fa31b37 Move function definitions for output.c from util.h to new file output.h.
Also, sort the order of include files in the c files.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor 3df600bbdf Move stacks.c definitions from util.h to new file stacks.h.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor fa9c66a656 Rename util.c to string.c and introduce string.h.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor 5d369d8d9e Move code centered around specific hardware devices to src/hw/
Move many C files from the src/ directory to the new src/hw/ directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-02 20:48:46 -04:00
Kevin O'Connor d83c87bb20 Normalize POST initialization function name suffixes.
The POST phase has to invoke many initialization functions, and these
functions can have complex inter-dependencies.  Try to categorize the
functions into 4 classes:

preinit - functions called very early in POST where function ordering
    is very important and the code has limited access to other
    interfaces.

init - functions that initialize internal interfaces and standard
    external interfaces.  This code is generally not dependent on
    particular hardware and typically does not communicate directly
    with any hardware devices.

setup - functions which access hardware or are dependent on particular
    hardware or platform devices.

prepboot - functions that finalize internal interfaces and that
    prepare for the boot phase.

This patch attempts to normalize the suffixes - functions that used
_init(), _setup(), _finalize(), or similar that did not follow the
above pattern were renamed.  Other than function name changes, there
should be no code impact to this patch.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-02-05 20:00:29 -05:00
Kevin O'Connor 8ab4a7de12 Set noinline on kbd.c interface functions that take stack variable pointers.
Some versions of gcc have been found to inline these funcions and then
cause the calling functions to use very large stack usage.  Since
these functions are called from 16bit mode, their stack space usage is
very sensitive.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-30 21:05:24 -04:00
Kevin O'Connor ac7eb5eb54 Remove "noinline" declarations from keyboard/mouse driver code.
Now that the extra stack is used for keyboard and mouse driver code,
there is no reason to set noinline (which was done to try and conserve
stack space).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-30 21:05:18 -04:00
Kevin O'Connor d488a7683d Use the extra stack for 16bit USB and PS2 keyboard/mouse commands.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-30 21:05:12 -04:00
Kevin O'Connor ecdc655a86 Run all hardware irq handlers on the extra stack.
Jump into the extra stack for all hardware irq handlers.  This reduces
the overall stack requirements of SeaBIOS.

Replace all users of call16_simpint with call16_int.  Only the
hardware irq handlers used the old call, and they need to use the new
call to ensure the extra stack is properly re-entrant.

Also, pass in a 'struct bregs' to the hardware irq handlers now.  It
was not done previously to save stack space.  Now that the extra stack
is used, that is no longer an issue.

Note that should an old OS invoke a hardware irq in 16bit protected
mode, then this patch could break that OS.  However, the chances of
this causing a regression seem small as several existing hardware irq
handlers already do not work in 16bit protected mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-30 21:04:52 -04:00
Kevin O'Connor 94c749c34b Rename wait_irq to yield_toirq.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-28 23:21:43 -04:00
Kevin O'Connor dd5a8a6b0d When USB keyboard active, don't send keyboard commands to ps2 port.
Route keyboard commands to a USB handler when USB keyboard is active.

Add a GETID handler for USB keyboards.
2010-05-01 19:59:34 -04:00
Kevin O'Connor 68c51390e3 Enable irqs in kbd/clock calls that caller might "spin" on.
Some old programs will spin on a clock/keyboard call with irqs
disabled.  They assume the BIOS will enable irqs and allow key events
and clock events to occur.

So, enable irqs in those functions that a caller might "spin" on.
2010-03-13 22:23:44 -05:00
Kevin O'Connor 6704cf9aa1 Revert "Rework disabling of ps2 port irqs."
This reverts commit 6f702dd698.

That patch introduced a regression by enabling mouse interrupts by
default.  It also appears that disabling interrupts by software alone
will not work well with some old DOS programs that hook the keyboard
irq.
2010-03-13 18:51:46 -05:00
Kevin O'Connor 6f702dd698 Rework disabling of ps2 port irqs.
Disable the ps2 port irqs in software instead of hardware.  This
prevents a race where an irq could get queued and later called when
not desired.
2010-01-28 20:35:21 -05:00
Kevin O'Connor 1ca05b0f39 Be sure to add "void" to all function prototypes that take no args.
Omitting "void" leads to a K&R style declaration which was not intended.
2010-01-03 17:43:37 -05:00
Kevin O'Connor dfefeb5438 Distinguish between debug reports for unimplemented vs invalid calls.
Don't use "fail" in the debug output - as this confuses users.
When reporting on an invalid parameter - use the word "invalid".
When reporting on an unimplemented call - state it is unimplemented.
Add separate debug levels for unimplemented vs invalid calls.
Also, increase the debug level of several entry points.
2009-12-13 13:04:17 -05:00
Kevin O'Connor 5787748248 Move ps2 specific keyboard and mouse code to ps2port.c. 2009-12-09 21:00:41 -05:00
Kevin O'Connor a5826b5ad4 Add simple cooperative threading scheme to allow parallel hw init.
Enable system for running hardware initialization in parallel.
The yield() call can now round-robin between "threads".
Rework ata controller init to use a thread per controller.
Make sure internal drives are registered in a defined order.
Run keyboard initialization in a thread.
Rework usb init to use a thread per controller.
2009-10-24 17:57:29 -04:00
Kevin O'Connor 10ad799ff4 Replace irq_enable() regions with explicit calls to check for irqs.
Add new function yield() which will permit irqs to trigger.
The yield() call enables irqs to occur in 32bit mode.
Add [num]sleep calls that yield instead of just spinning.
Rename existing int 1586 usleep call to biosusleep.
Convert many calls to mdelay to msleep.
2009-10-24 11:06:08 -04:00
Kevin O'Connor 114592f000 Initial support for USB, UHCI, and USB Keyboards.
This adds preliminary support for USB controllers and keyboards.
Add support for UHCI controllers.
Add support for "HID" USB keyboards.
Also, fix bug in hexdump() - len need not be power of 4.
2009-09-28 21:32:08 -04:00
Kevin O'Connor ee2efa7303 Support sleeping until an irq fires, and use where applicable.
Add wait_irq() - it's more efficient than looping with cpu_relax().
Also, move kbd irq enables down - only kbd_command needs it.
Also, make some minor code layout improvements to kbd.c.
2009-09-20 15:33:08 -04:00
Kevin O'Connor b532d72c20 Separate out pause key processing in process_key(). 2009-09-11 17:00:31 -04:00
Kevin O'Connor 40c0e481fa Define bit names for keyboard shift flags.
Also, move setting of bit flags to the end of process_key().
2009-09-11 02:06:02 -04:00
Kevin O'Connor 885e2dd9bc Minor enhancement - kbd reset should set 0x1234 in BDA reset flag. 2009-01-21 19:14:20 -05:00
Kevin O'Connor b44a852635 Cleanup keyboard reset handling.
Use custom timeouts when issuing a reset.
Handle 1-byte returns from reset in ps2 code.
Do full keyboard reset even in coreboot mode.
Send set scan mode command during reset.
2009-01-17 23:30:01 -05:00
Kevin O'Connor b1b7c2a1c3 Change license from GPLv3 to LGPLv3.
Change license of contributions from Kevin O'Connor from GPLv3 to
LGPLv3 (or later).  Since the work as a whole is based on Kevin's
contributions and the "bochs bios" which has a license of LGPL (v2 or
later), this effectively makes the work as a whole available under
LGPLv3 (or later).
2009-01-15 20:52:58 -05:00
Kevin O'Connor 0234cd90be Make sure ps2 port command reads are from the desired device.
Discard reads from real-time events or from a different device.
Also, improve the kbd/mouse diagnostic messages.
2009-01-04 12:20:02 -05:00
Kevin O'Connor 8c0e372c2a The BDA is at segment 0x0040 not 0x0000.
The interrupt vector table is technically at 0x0000.
2009-01-02 14:19:43 -05:00
Kevin O'Connor a83ff550b4 Reduce stack usage of hw irq handlers.
Avoid using call16_int() -- it consumes too much stack space.
    Instead, use a new function (call16_simpint).  This assumes that
    the handler wont corrupt regs - which should be a safe assumption,
    because if they did corrupt regs they wouldn't work on any bios.
Avoid enabling irqs in the hw irq handlers - there are no loops in the
    handlers that could cause any notable latency.
2009-01-01 21:00:59 -05:00
Kevin O'Connor 92f95b0fec Add more linker protections around variables accessed from 16bit mode.
Rename VAR16 to VAR16_32 -- that macro supports accesses from both
    16bit and 32bit mode.
Introduce a new macro VAR16 that must be present on all global
    variables accessed from 16bit mode.
2008-12-29 20:42:40 -05:00
Kevin O'Connor fb630a9fa8 Fix bug in dequeue_key() refactor.
Clearing of Z_FL occurs on the !incr path.
2008-12-21 17:38:37 -05:00
Kevin O'Connor 993f9d3a48 Refactor dequeue_key() in keyboard code.
All 4 callers of dequeue_key are very similar - move the redundant
    logic into dequeue_key() itself.
2008-12-16 23:47:37 -05:00
Kevin O'Connor 15157a3c6d Implement GET/SET_GLOBAL(...) instead of using GET/SET_VAR(CS, ...) 2008-12-13 11:10:37 -05:00
Kevin O'Connor 18e38b2923 Improve support for old 16bit resume handlers.
Detect a non-standard CMOS shutdown code during post and run a
    separate resume handler.
Set aside space in the EBDA for the resume handler stack.
Add support for several of the code supported in bochs bios.
2008-12-10 20:40:13 -05:00
Kevin O'Connor 3f168b6c7c Detect keyboard ctrl-alt-delete and try to reset machine. 2008-11-29 13:22:29 -05:00
Kevin O'Connor d21c089acf Enable a default hw irq handler.
Also, only route hw irqs to their handlers when they are enabled.
    (This ensures that if a subsystem is disabled that the default
    hwirq handler will be used.)
Add helper macros to declare the extern asm handlers.
Always enable the RTC hwirq at startup (as opposed to when it is first
    used).
Fix bug in default handler - wrong bit was used for checking the
    cascaded irq.
2008-11-26 17:02:43 -05:00