next up previous contents
Next: Realtime Clock (RTC) Management Up: Hardware Abstraction Layer: Portable Previous: Bootstrap Debug Input/Output   Contents

Subsections

IRQ/Context Management

IRQ management requires a few data structures and macros which are portable across platforms, and which will be described up front:

The rest is handled through the function interface.

int irq_inside_int()

Returns non-zero if the caller is executing inside an interrupt handler.

void irq_force_return()

This is kind of a weird one. This assumes that you have interrupts disabled, but are not actually running inside an interrupt handler, and you want to pretend that you were in fact inside an interrupt handler and return from that interrupt. This can be used to, for example, force a context switch without actually switching into ``kernel'' mode. We don't really use this anymore (deprecated in favor of the syscall interface).

int irq_set_handler(irq_t source, irq_handler hnd)

Set a handler for the given interrupt. The definition of irq_handler may platform dependent, but is generally:

typedef void (*irq_handler)(irq_t source, irq_context_t * context);

int irq_set_global_handler(irq_handler hnd)

Set a global interrupt handler. This routine will receive all interrupts and exceptions in favor of any individual handlers. Use with caution.

void irq_set_context(irq_context_t *regbank)

Change our ``IRQ context''. This should never be done with interrupts enabled. Basically whenever an interrupt occurs, the program context is saved into the current IRQ context. This is usually part of the kthread_t structure. When the interrupt handler returns, the IRQ context is re-established and the program continues. You can use this function to swap contexts in an interrupt handler (the thread system does this).

irq_context_t * irq_get_context()

Return a pointer to the current IRQ context. Note that it's not valid behavior to get this pointer and then use CURRENT_xx() from above on it because the values aren't valid until an interrupt occurs. Thus it is mainly used inside an interrupt handler to see who got interrupted.

void irq_create_context(irq_context_t * context, uint32 stack_pointer, uint32 routine, uint32 * args, int usermode)

Creates an irq_context_t from scratch. This is used mainly for creating new threads. The new values will be written to context, which must be pre-allocated. The initialo stack location will be stack_pointer, the initial PC will be routine, and args will be available as arguments to the routine (though the number of arguments is platform dependent). The usermode flag is a leftover from an earlier adaptation of KOS and may be removed later, but if non-zero it essentially tells us to create a context which will run with reduced privelges and in a user-capable address space.

int irq_disable()

Disable all IRQs and return the original IRQ state.

void irq_enable()

Enable all IRQs.

void irq_restore(int v)

Restore an old IRQ state from what was returned from irq_disable.


next up previous contents
Next: Realtime Clock (RTC) Management Up: Hardware Abstraction Layer: Portable Previous: Bootstrap Debug Input/Output   Contents
Dan Potter 2002-07-29