[f761f1eb] | 1 | #
|
---|
| 2 | # Copyright (C) 2001-2004 Jakub Jermar
|
---|
| 3 | # All rights reserved.
|
---|
| 4 | #
|
---|
| 5 | # Redistribution and use in source and binary forms, with or without
|
---|
| 6 | # modification, are permitted provided that the following conditions
|
---|
| 7 | # are met:
|
---|
| 8 | #
|
---|
| 9 | # - Redistributions of source code must retain the above copyright
|
---|
| 10 | # notice, this list of conditions and the following disclaimer.
|
---|
| 11 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | # documentation and/or other materials provided with the distribution.
|
---|
| 14 | # - The name of the author may not be used to endorse or promote products
|
---|
| 15 | # derived from this software without specific prior written permission.
|
---|
| 16 | #
|
---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | #
|
---|
| 28 |
|
---|
[da585a52] | 29 | ## very low and hardware-level functions
|
---|
[f761f1eb] | 30 |
|
---|
[78a95d6f] | 31 | # Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
|
---|
[76857d1] | 32 | # and 1 means interrupt with error word
|
---|
[59532eb] | 33 | #define ERROR_WORD_INTERRUPT_LIST 0x00027D00
|
---|
| 34 |
|
---|
[f761f1eb] | 35 | .text
|
---|
| 36 |
|
---|
| 37 | .global paging_on
|
---|
| 38 | .global enable_l_apic_in_msr
|
---|
| 39 | .global interrupt_handlers
|
---|
[da585a52] | 40 |
|
---|
| 41 | ## Turn paging on
|
---|
| 42 | #
|
---|
| 43 | # Enable paging and write-back caching in CR0.
|
---|
| 44 | #
|
---|
[f761f1eb] | 45 | paging_on:
|
---|
[24bd23a] | 46 | movl %cr0,%edx
|
---|
| 47 | orl $(1<<31),%edx # paging on
|
---|
| 48 | andl $~((1<<30)|(1<<29)),%edx # clear Cache Disable and not Write Though
|
---|
| 49 | movl %edx,%cr0
|
---|
[f761f1eb] | 50 | jmp 0f
|
---|
| 51 | 0:
|
---|
| 52 | ret
|
---|
| 53 |
|
---|
[da585a52] | 54 |
|
---|
| 55 | ## Enable local APIC
|
---|
| 56 | #
|
---|
| 57 | # Enable local APIC in MSR.
|
---|
| 58 | #
|
---|
[f761f1eb] | 59 | enable_l_apic_in_msr:
|
---|
[24bd23a] | 60 | push %eax
|
---|
| 61 |
|
---|
[f761f1eb] | 62 | movl $0x1b, %ecx
|
---|
| 63 | rdmsr
|
---|
| 64 | orl $(1<<11),%eax
|
---|
| 65 | orl $(0xfee00000),%eax
|
---|
| 66 | wrmsr
|
---|
[24bd23a] | 67 |
|
---|
| 68 | pop %eax
|
---|
[f761f1eb] | 69 | ret
|
---|
| 70 |
|
---|
[da585a52] | 71 |
|
---|
| 72 | ## Declare interrupt handlers
|
---|
| 73 | #
|
---|
| 74 | # Declare interrupt handlers for n interrupt
|
---|
| 75 | # vectors starting at vector i.
|
---|
| 76 | #
|
---|
| 77 | # The handlers setup data segment registers
|
---|
[fcfac420] | 78 | # and call exc_dispatch().
|
---|
[da585a52] | 79 | #
|
---|
[f761f1eb] | 80 | .macro handler i n
|
---|
[25d7709] | 81 |
|
---|
| 82 | /*
|
---|
[8e0eb63] | 83 | * This macro distinguishes between two versions of ia32 exceptions.
|
---|
| 84 | * One version has error word and the other does not have it.
|
---|
| 85 | * The latter version fakes the error word on the stack so that the
|
---|
| 86 | * handlers and istate_t can be the same for both types.
|
---|
[25d7709] | 87 | */
|
---|
| 88 |
|
---|
[8e0eb63] | 89 | .iflt \i-32
|
---|
| 90 | .if (1 << \i) & ERROR_WORD_INTERRUPT_LIST
|
---|
| 91 | /*
|
---|
| 92 | * Version with error word.
|
---|
| 93 | * Just take space equal to subl $4, %esp.
|
---|
| 94 | */
|
---|
| 95 | nop
|
---|
| 96 | nop
|
---|
| 97 | nop
|
---|
| 98 | .else
|
---|
| 99 | /*
|
---|
| 100 | * Version without error word,
|
---|
| 101 | */
|
---|
| 102 | subl $4, %esp
|
---|
| 103 | .endif
|
---|
| 104 | .else
|
---|
| 105 | /*
|
---|
| 106 | * Version without error word,
|
---|
| 107 | */
|
---|
| 108 | subl $4, %esp
|
---|
| 109 | .endif
|
---|
[25d7709] | 110 |
|
---|
| 111 | pusha
|
---|
| 112 | movl %esp, %ebp
|
---|
[f07bba5] | 113 | push %ds
|
---|
| 114 | push %es
|
---|
[0e30dec] | 115 | push %fs
|
---|
| 116 | push %gs
|
---|
[76cec1e] | 117 |
|
---|
[f761f1eb] | 118 | # we must fill the data segment registers
|
---|
| 119 | movw $16,%ax
|
---|
| 120 | movw %ax,%ds
|
---|
| 121 | movw %ax,%es
|
---|
[76cec1e] | 122 |
|
---|
[f761f1eb] | 123 | pushl %ebp
|
---|
[0e30dec] | 124 | pushl $(\i)
|
---|
[fcfac420] | 125 | call exc_dispatch
|
---|
[f761f1eb] | 126 | addl $8,%esp
|
---|
| 127 |
|
---|
[0e30dec] | 128 | pop %gs
|
---|
| 129 | pop %fs
|
---|
[f07bba5] | 130 | pop %es
|
---|
| 131 | pop %ds
|
---|
| 132 |
|
---|
[25d7709] | 133 | # Clear Nested Task flag.
|
---|
[24bd23a] | 134 | pushfl
|
---|
| 135 | pop %eax
|
---|
[0e30dec] | 136 | and $0xffffbfff,%eax
|
---|
[24bd23a] | 137 | push %eax
|
---|
| 138 | popfl
|
---|
[c192134] | 139 |
|
---|
[f761f1eb] | 140 | popa
|
---|
[8e0eb63] | 141 | addl $4,%esp # Skip error word, no matter whether real or fake.
|
---|
[76cec1e] | 142 | iret
|
---|
| 143 |
|
---|
[f761f1eb] | 144 | .if (\n-\i)-1
|
---|
| 145 | handler "(\i+1)",\n
|
---|
| 146 | .endif
|
---|
| 147 | .endm
|
---|
| 148 |
|
---|
| 149 | # keep in sync with pm.h !!!
|
---|
| 150 | IDT_ITEMS=64
|
---|
| 151 | interrupt_handlers:
|
---|
| 152 | h_start:
|
---|
| 153 | handler 0 64
|
---|
| 154 | # handler 64 128
|
---|
| 155 | # handler 128 192
|
---|
| 156 | # handler 192 256
|
---|
| 157 | h_end:
|
---|
| 158 |
|
---|
| 159 | .data
|
---|
| 160 | .global interrupt_handler_size
|
---|
| 161 |
|
---|
| 162 | interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS
|
---|