sched: move preempted_by() to <ukernel/sched.h>

As an inline function. This changeset actually removes more lines than it
adds!
lib: remove unused code from computchar()
remove old debug things from exception.c
thread: add TF_PRE_RECV to record halt from R_RECV

And to avoid clearing wakeup_time in thread_resume().

This changeset forbids thread_halt() from kernel threads. Their termination
should be rethought, if it's at all desirable -- both sigma0's pager and the
scheduler thread are perpetual loops, and I'd think the former would support
sigma1 (a trusted process) just as well.

Conflicts:
	include/ukernel/thread.h
	thread.c
testbench: add test of the PC-style keyboard interrupt

... not like other architectures have I/O ports and a PC-style keyboard mapped
at those particular ones, anyway...
add interrupt registration, handling, and clearing

Changes:
  - IRQ gates in isr-32.S, idt.c
  - add interrupt_ctl() in thread.c, callsite from sys_threadcontrol()
  - add int_{trigger,clear,poll,kick}() to thread.c, export first three in
    <ukernel/interrupt.h>
  - export set_ipc_return_regs() from ipc.c, for int_trigger()'s use
  - add TF_INTR to <struct thread>.flags
  - call int_clear() from ipc_send_half()
  - call int_poll() from ipc_recv_half()
  - call int_trigger() from isr_irq_bottom_soft()
  - (unrelated) ThreadControl: only fill ErrorCode when result == 0

The testbench keyboard thread demonstrates that interrupts are being received,
delivered, and cleared as appropriate. However, in the absence of a reliable
interrupt source, things such as interrupt unregistration and the various IPC
interactions are going untested.
irq: handle exactly one interrupt at a time

None of that recursion wack.
defer interrupts that happen while the CPU is in kernel code

Now, interrupts sent in response to an ISR being invoked on the kernel stack
will use deferred signaling unless received during the "hlt" instruction. This
just leaves the "exit syscall to preemption winner" mechanism, and testing.

This aggregate changeset had a long and sordid history. Hopefully wackness
such as it represented will not be seen in the future.
add return_from_exn() for latent interrupt signaling

It goes at the end of syscall and other exception handlers' C halves, and in
return_to_other() and return_to_scheduler(). It's got two effects: first, it
processes deferred interrupts (though see below); and second, it returns in a
condition where interrupts are disabled and kernel_irq_deferred is false; so
afterward, the kernel is in a state where deferred signals have been processed
and won't occur until the CPU transitions from user mode back to supervisor
mode again.

As of right now, return_from_exn() has no affordance for pre-emptions due to
interrupt signaling. It should. (int_trigger(), too.)

Interrupt handlers that don't re-enable interrupts should not call
return_from_exn(). Ones that do may disable interrupts with it (but in the
future it'll be a pre-emption path) to neatly avoid lost interrupts.
testbench: add interrupt suite with API test

Next: causing and catching an interrupt
testbench: interrupt: add serial port interrupt flow test

Four test points of varying deliciousness.
testbench: interrupt: add context test case

I.e. interrupts from different CPU contexts. int_from_wait is supposed to have
the interrupt occur in the "hlt" instruction; int_from_user, in the middle of
nsleep(); and int_under_other in the middle of another thread's nsleep()
(which should cause an immediate preemption).

Alas, it appears that a serial port is not an adequate interrupt source, at
least not under KVM -- which makes total sense given the I/O virtualization.
x86: idt: don't enter syscalls and traps with interrupts masked

The fact that they were called on the system call stack is enough; interrupts
will from then on happen on the kernel stack which tells the int_trigger()
path to not interfere with in-kernel stuff.
x86: minor cleanups

Document with assert()s that interrupts are enabled when the syscall handlers
are entered. Rejigger x86_get_eflags() to that effect (and remove its
redundant sibling, x86_clear_eflags(), while we're at it).

Also clean up the CR2 read in isr_exn_pf_bottom().
thread: mask pending interrupts, remove buffering

Each interrupt is re-enabled at clear. This makes the interrupt "request"
field redundant, which is fine. How it'll interact with the LAPIC's buffering
of edge-triggered interrupts, I have no idea.
pic: make sure calls to pic_*() have interrupts disabled
testbench: interrupt: fix no-fork setting, fixture checkedness