wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB, daniel@omicron.se. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
Graeme Russ | 9933d60 | 2008-12-07 10:29:01 +1100 | [diff] [blame] | 25 | #include <asm/interrupt.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 26 | |
| 27 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 28 | struct idt_entry { |
| 29 | u16 base_low; |
| 30 | u16 selector; |
| 31 | u8 res; |
| 32 | u8 access; |
| 33 | u16 base_high; |
| 34 | } __attribute__ ((packed)); |
| 35 | |
| 36 | |
| 37 | struct idt_entry idt[256]; |
| 38 | |
| 39 | |
Graeme Russ | abf0cd3 | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 40 | asm (".globl irq_return\n" |
| 41 | "irq_return:\n" |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | " addl $4, %esp\n" |
| 43 | " popa\n" |
| 44 | " iret\n"); |
| 45 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | void __attribute__ ((regparm(0))) default_isr(void); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | asm ("default_isr: iret\n"); |
| 48 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 49 | asm ("idt_ptr:\n" |
| 50 | ".word 0x800\n" /* size of the table 8*256 bytes */ |
| 51 | ".long idt\n" /* offset */ |
| 52 | ".word 0x18\n");/* data segment */ |
| 53 | |
Graeme Russ | abf0cd3 | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 54 | void set_vector(u8 intnum, void *routine) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 55 | { |
Graeme Russ | e17ee15 | 2009-02-24 21:14:56 +1100 | [diff] [blame^] | 56 | idt[intnum].base_high = (u16)((u32)(routine + gd->reloc_off) >> 16); |
| 57 | idt[intnum].base_low = (u16)((u32)(routine + gd->reloc_off) & 0xffff); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
Graeme Russ | abf0cd3 | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 61 | int cpu_init_interrupts(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | { |
| 63 | int i; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 64 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 65 | /* Just in case... */ |
| 66 | disable_interrupts(); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 68 | /* Setup the IDT */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | for (i=0;i<256;i++) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | idt[i].access = 0x8e; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | idt[i].res = 0; |
| 72 | idt[i].selector = 0x10; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | set_vector(i, default_isr); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | } |
| 75 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 76 | asm ("cs lidt idt_ptr\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | /* It is now safe to enable interrupts */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | enable_interrupts(); |
| 80 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | void enable_interrupts(void) |
| 85 | { |
| 86 | asm("sti\n"); |
| 87 | } |
| 88 | |
| 89 | int disable_interrupts(void) |
| 90 | { |
| 91 | long flags; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | asm volatile ("pushfl ; popl %0 ; cli\n" : "=g" (flags) : ); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 94 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 95 | return (flags&0x200); /* IE flags is bit 9 */ |
| 96 | } |