blob: 063ea42cd2bf31a022727fdf77c414d89682e502 [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
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 Russ9933d602008-12-07 10:29:01 +110025#include <asm/interrupt.h>
wdenk2262cfe2002-11-18 00:14:45 +000026
27
wdenk2262cfe2002-11-18 00:14:45 +000028struct idt_entry {
29 u16 base_low;
30 u16 selector;
31 u8 res;
32 u8 access;
33 u16 base_high;
34} __attribute__ ((packed));
35
36
37struct idt_entry idt[256];
38
39
Graeme Russabf0cd32009-02-24 21:13:40 +110040asm (".globl irq_return\n"
41 "irq_return:\n"
wdenk2262cfe2002-11-18 00:14:45 +000042 " addl $4, %esp\n"
43 " popa\n"
44 " iret\n");
45
wdenk8bde7f72003-06-27 21:31:46 +000046void __attribute__ ((regparm(0))) default_isr(void);
wdenk2262cfe2002-11-18 00:14:45 +000047asm ("default_isr: iret\n");
48
wdenk2262cfe2002-11-18 00:14:45 +000049asm ("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 Russabf0cd32009-02-24 21:13:40 +110054void set_vector(u8 intnum, void *routine)
wdenk2262cfe2002-11-18 00:14:45 +000055{
Graeme Russe17ee152009-02-24 21:14:56 +110056 idt[intnum].base_high = (u16)((u32)(routine + gd->reloc_off) >> 16);
57 idt[intnum].base_low = (u16)((u32)(routine + gd->reloc_off) & 0xffff);
wdenk2262cfe2002-11-18 00:14:45 +000058}
59
60
Graeme Russabf0cd32009-02-24 21:13:40 +110061int cpu_init_interrupts(void)
wdenk2262cfe2002-11-18 00:14:45 +000062{
63 int i;
wdenk8bde7f72003-06-27 21:31:46 +000064
wdenk2262cfe2002-11-18 00:14:45 +000065 /* Just in case... */
66 disable_interrupts();
wdenk8bde7f72003-06-27 21:31:46 +000067
wdenk2262cfe2002-11-18 00:14:45 +000068 /* Setup the IDT */
wdenk8bde7f72003-06-27 21:31:46 +000069 for (i=0;i<256;i++) {
wdenk2262cfe2002-11-18 00:14:45 +000070 idt[i].access = 0x8e;
wdenk8bde7f72003-06-27 21:31:46 +000071 idt[i].res = 0;
72 idt[i].selector = 0x10;
wdenk2262cfe2002-11-18 00:14:45 +000073 set_vector(i, default_isr);
wdenk8bde7f72003-06-27 21:31:46 +000074 }
75
wdenk2262cfe2002-11-18 00:14:45 +000076 asm ("cs lidt idt_ptr\n");
wdenk8bde7f72003-06-27 21:31:46 +000077
wdenk2262cfe2002-11-18 00:14:45 +000078 /* It is now safe to enable interrupts */
wdenk8bde7f72003-06-27 21:31:46 +000079 enable_interrupts();
80
wdenk2262cfe2002-11-18 00:14:45 +000081 return 0;
82}
83
84void enable_interrupts(void)
85{
86 asm("sti\n");
87}
88
89int disable_interrupts(void)
90{
91 long flags;
wdenk8bde7f72003-06-27 21:31:46 +000092
wdenk2262cfe2002-11-18 00:14:45 +000093 asm volatile ("pushfl ; popl %0 ; cli\n" : "=g" (flags) : );
wdenk8bde7f72003-06-27 21:31:46 +000094
wdenk2262cfe2002-11-18 00:14:45 +000095 return (flags&0x200); /* IE flags is bit 9 */
96}