kern

annotate src/intr-asm.S @ 50:1d8877d12de0

tidyed up the intr_ret bit, made it a bit more reasonably structured, and cleaned up some debugging things
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jul 2011 07:35:53 +0300
parents 50730d42d2d3
children 4eaecb14fe31
rev   line source
nuclear@11 1 .data
nuclear@11 2 .align 4
nuclear@11 3 .short 0
nuclear@11 4 /* memory reserved for set_idt */
nuclear@11 5 lim:.short 0
nuclear@11 6 addr:.long 0
nuclear@11 7
nuclear@11 8 .text
nuclear@11 9 /* set_idt(uint32_t addr, uint16_t limit)
nuclear@11 10 * loads the IDTR with the new address and limit for the IDT */
nuclear@11 11 .globl set_idt
nuclear@11 12 set_idt:
nuclear@11 13 movl 4(%esp), %eax
nuclear@11 14 movl %eax, (addr)
nuclear@11 15 movw 8(%esp), %ax
nuclear@11 16 movw %ax, (lim)
nuclear@11 17 lidt (lim)
nuclear@11 18 ret
nuclear@11 19
nuclear@25 20 /* get_intr_state()
nuclear@25 21 * returns 1 if interrutps are enabled, 0 if disabled */
nuclear@25 22 .globl get_intr_state
nuclear@25 23 get_intr_state:
nuclear@25 24 pushf
nuclear@25 25 popl %eax
nuclear@25 26 shr $9, %eax /* bit 9 of eflags is IF */
nuclear@25 27 andl $1, %eax
nuclear@25 28 ret
nuclear@25 29
nuclear@25 30 /* set_intr_state(int state)
nuclear@25 31 * enables interrupts if the argument is non-zero, disables them otherwise */
nuclear@25 32 .globl set_intr_state
nuclear@25 33 set_intr_state:
nuclear@25 34 cmpl $0, 4(%esp)
nuclear@25 35 jz 0f
nuclear@25 36 sti
nuclear@25 37 ret
nuclear@25 38 0: cli
nuclear@25 39 ret
nuclear@25 40
nuclear@25 41
nuclear@11 42 /* interrupt entry with error code macro
nuclear@11 43 * this macro generates an interrupt entry point for the
nuclear@11 44 * exceptions which include error codes in the stack frame
nuclear@11 45 */
nuclear@11 46 .macro ientry_err n name
nuclear@11 47 .globl intr_entry_\name
nuclear@11 48 intr_entry_\name:
nuclear@11 49 pushl $\n
nuclear@11 50 jmp intr_entry_common
nuclear@11 51 .endm
nuclear@11 52
nuclear@11 53 /* interrupt entry without error code macro
nuclear@11 54 * this macro generates an interrupt entry point for the interrupts
nuclear@11 55 * and exceptions which do not include error codes in the stack frame
nuclear@11 56 * it pushes a dummy error code (0), to make the stack frame identical
nuclear@11 57 */
nuclear@11 58 .macro ientry_noerr n name
nuclear@11 59 .globl intr_entry_\name
nuclear@11 60 intr_entry_\name:
nuclear@11 61 pushl $0
nuclear@11 62 pushl $\n
nuclear@11 63 jmp intr_entry_common
nuclear@11 64 .endm
nuclear@11 65
nuclear@11 66 /* common code used by all entry points. calls dispatch_intr()
nuclear@11 67 * defined in intr.c
nuclear@11 68 */
nuclear@11 69 .extern dispatch_intr
nuclear@11 70 intr_entry_common:
nuclear@11 71 pusha
nuclear@11 72 call dispatch_intr
nuclear@50 73 intr_ret_local:
nuclear@11 74 popa
nuclear@11 75 /* remove error code and intr num from stack */
nuclear@11 76 add $8, %esp
nuclear@11 77 iret
nuclear@11 78
nuclear@50 79 /* intr_ret is called by context_switch to return from the kernel
nuclear@50 80 * to userspace. The argument is a properly formed intr_frame
nuclear@50 81 * structure with the saved context of the new task.
nuclear@50 82 *
nuclear@50 83 * First thing to do is remove the return address pointing back
nuclear@50 84 * to context_switch, which then leaves us with a proper interrupt
nuclear@50 85 * stack frame, so we can jump right in the middle of the regular
nuclear@50 86 * interrupt return code above.
nuclear@50 87 */
nuclear@50 88 .globl intr_ret
nuclear@50 89 intr_ret:
nuclear@50 90 add $4, %esp
nuclear@50 91 jmp intr_ret_local
nuclear@50 92
nuclear@11 93 /* by including interrupts.h with ASM defined, the macros above
nuclear@11 94 * are expanded to generate all required interrupt entry points
nuclear@11 95 */
nuclear@11 96 #define ASM
nuclear@11 97 #include <interrupts.h>