usb keyboard vs btx: an SMI theory




I am not a close-to-hardware guy, my knowledge of IA32 architecture and
IA32 assembly is very (very!) limited, so my reasoning can have some
glaring flaws. Also, I am quite fuzzy on the details of btx workings and
some other aspects.

Still I have a theory (or a "gut feeling") about the bad interaction
between "newer" loader and USB keyboard that I experienced. I believe
that a number other people had the same or similar issues.

It seems that i386 btx code contains routines, intx31/int_hw +
rret_tramp, to enter real mode, execute an interrupt handler and exit
real mode. It seems that this code can be invoked in two cases: (1) when
protected code wishes to execute a BIOS int function and calls into btx
via int 31h; (2) when a hardware interrupt happens while in protected mode.
It also looks that the routine saves and restores certain context before
entering and after exiting real mode. This is done in a special fixed
memory location (MEM_ESPR). This memory lcoation also seems to be used
as a stack base address for real mode.

Normally there can not be any shared/overlapping access to that
location. This is because in all cases interrupts are disabled and
machine is supposed to be uniprocessor mode still.

Now lets look at the other end - "USB legacy support". I think that BIOS
emulates PS/2 keyboard for real USB keyboard in the following way.
When a key is pressed a USB event is generated by the keyboard.
USB host controller generates an SMI upon the USB event.
SMM code checks if SMI was generated by USB, performs necessary USB
chores and then pretends as if the key press was made on an PS/2 keyboard.
This is something that I am very fuzzy about, but I think that SMM code
somehow invokes IRQ 1 handler.

And I think that because SMI is not maskable it can be "nested" inside
any other interrupt (software or hardware) and it is possible that IRQ1
handler for protected mode can be executed (and thus int_hw) while we
were already executing int_hw for some other reason - a "system call"
from protected mode code or hardware interrupt.
In this case the context data stored in memory would get corrupted.
I suspect that what I actually observe looks like interrupts never
getting re-enabled.

Again, I am very fuzzy about the exact details, but I think that this is
something that could be happening and I think that SMI is of primary
interest here. I also think that this might explain to a certain degree
the difference in behavior between "older" btx and "newer" btx.


--
Andriy Gapon
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: USB device just moves
    ... USB must be polled at regular intervals,... ... Interrupt and isochronous pipes must be polled at regular intervals. ... received then an SMI handler is invoked, ... The usb keyboard is the worst offender with a transaction going something like ...
    (comp.os.linux.development.system)
  • Re: Once more VIA VT6212 USB Chip Problem
    ... I checked the interrupt init and I can see they are all set. ... I tried my image on this board and USB works fine!! ... Bus 0, Device 1, Function 0 ... is found for following PCI Device ...
    (microsoft.public.windowsce.platbuilder)
  • USBEHCI.SYS bug with high-bandwidth interrupt endpoints
    ... I was investigating USB 2.0 high-bandwidth interrupt ... three transactions per microframe with a maximum packet size of 1024 ... bytes in the endpoint descriptor. ...
    (microsoft.public.development.device.drivers)
  • Re: R: hc12,can i return from interrupt and jump elsewhere?
    ... Control systems and communications consulting ... reception of an interrupt event, ... .I'm trying to implement an USB protocol using a 9s12 microcontroller,that i ... Well,being honest it should be better if any request could wake the uC from ...
    (comp.arch.embedded)
  • Re: Back to real mode from pmode (LIDT and PIC remap)
    ... In this case does your protected mode device driver ... get the IRQ or does the real mode handler try to deal with it? ... and you can't mask the IRQs (you'll lose IRQs that ... Disabling interrupt is also absolutely necessary in ...
    (comp.lang.asm.x86)