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 d488a7683d90bf8fae7ceb8c3ad9e95fbbd92079.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
pmm: Fix entry point to support non-zero %ss

If the pmm entry point was called with a non-zero stack segment, the
pointer to the arguments on the stack would not be valid once the
code transitioned to 32bit mode.  Fix by adding the stack segment
offset into the args pointer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move stack hop code below call32/call16 code in stacks.c

This change is a just code movement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add need_hop_back() call that determines if stack_hop_back is needed

Also, use need_hop_back() instead of on_extra_stack() in code that
determines whether or not to call stack_hop_back().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update invoke_mouse_handler() to use need_hop_back()

Make the mouse handler stack_hop_back() code similar to the other
users that use need_stack_hop().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update stack_hop_back() to jump to 16bit mode if called in 32bit mode.

Also, update callers to rely on this feature.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Track when entering via call32() and use the same mode for stack_hop_back()

If 32bit mode is entered directly via transition32, then use a simple
call16() when hopping back to 16bit mode.  Use only call16big() when
entering 32bit mode via call32().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Simplify farcall16 code

With this change, farcall16() is only used for external API calls and
is only invoked from a 32bit mode entered directly via transition32.
farcall16big() is also only used for external API calls and is only
invoked from a 32bit mode entered directly via transition32.

call16_int() now calls _farcall16() directly, and it will use normal
16bit mode or big real mode as required.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update reset() to use call16_back()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
build: Support declaring 32bit C functions that must reside in the f-segment

Add support for a FUNCFSEG macro that will force a "32bit flat" C
function to be located in the f-segment.  This is useful for 32bit
code with inline assembler that thunks to 16bit mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move call16() functions from romlayout.S to inline assembler in stacks.c

Use inline assembler in call16 type functions instead of using
__call16() in romlayout.S.

Since call16() and call16big() are now only called with %ss==0 they do
not need to update the stack pointer.  Only call16_sloppy() requires
the stack manipulation code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Break up call32() into call32() and call32_sloppy()

This separates the call32() into two functions.  It also moves the
call16_sloppy() code next to the call32_sloppy() code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Fully restore 16bit state during call16_sloppy()

When transitioning back to 16bit mode from within call32(), restore
the full state (cmos index, gdt, fs/gs) in addition to restoring the
original stack.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement call32 mechanism using SMIs.

Add support for jumping into 32bit mode using a System Management Mode
(SMM) handler.  When available, this allows SeaBIOS to transition to
32bit mode even when called in vm86 mode.  It will also prevent the
clobbering of the segment registers.

Currently, the SMM mode is only supported in QEMU when running in TCG
mode.  Also, QEMU v2.1 (or later) is needed for it to work when in
vm86 mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Run all hard drive ops in 32 bit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Run keyboard and mouse commands always in 32bit mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Run all hardware interrupt handlers in 32bit mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>