blob: 026a21bd21711cdd991b761fe23119d8e9e5de00 [file] [log] [blame]
wdenk591dda52002-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 Russ0c8c62e2008-12-07 10:29:01 +110025#include <asm/interrupt.h>
wdenk591dda52002-11-18 00:14:45 +000026
27
wdenk591dda52002-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 Russ77290ee2009-02-24 21:13:40 +110040asm (".globl irq_return\n"
41 "irq_return:\n"
wdenk591dda52002-11-18 00:14:45 +000042 " addl $4, %esp\n"
43 " popa\n"
44 " iret\n");
45
wdenk57b2d802003-06-27 21:31:46 +000046void __attribute__ ((regparm(0))) default_isr(void);
wdenk591dda52002-11-18 00:14:45 +000047asm ("default_isr: iret\n");
48
wdenk591dda52002-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 Russ77290ee2009-02-24 21:13:40 +110054void set_vector(u8 intnum, void *routine)
wdenk591dda52002-11-18 00:14:45 +000055{
wdenk57b2d802003-06-27 21:31:46 +000056 idt[intnum].base_high = (u16)((u32)(routine)>>16);
57 idt[intnum].base_low = (u16)((u32)(routine)&0xffff);
wdenk591dda52002-11-18 00:14:45 +000058}
59
60
Graeme Russ77290ee2009-02-24 21:13:40 +110061int cpu_init_interrupts(void)
wdenk591dda52002-11-18 00:14:45 +000062{
63 int i;
wdenk57b2d802003-06-27 21:31:46 +000064
wdenk591dda52002-11-18 00:14:45 +000065 /* Just in case... */
66 disable_interrupts();
wdenk57b2d802003-06-27 21:31:46 +000067
wdenk591dda52002-11-18 00:14:45 +000068 /* Setup the IDT */
wdenk57b2d802003-06-27 21:31:46 +000069 for (i=0;i<256;i++) {
wdenk591dda52002-11-18 00:14:45 +000070 idt[i].access = 0x8e;
wdenk57b2d802003-06-27 21:31:46 +000071 idt[i].res = 0;
72 idt[i].selector = 0x10;
wdenk591dda52002-11-18 00:14:45 +000073 set_vector(i, default_isr);
wdenk57b2d802003-06-27 21:31:46 +000074 }
75
wdenk591dda52002-11-18 00:14:45 +000076 asm ("cs lidt idt_ptr\n");
wdenk57b2d802003-06-27 21:31:46 +000077
wdenk591dda52002-11-18 00:14:45 +000078 /* It is now safe to enable interrupts */
wdenk57b2d802003-06-27 21:31:46 +000079 enable_interrupts();
80
wdenk591dda52002-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;
wdenk57b2d802003-06-27 21:31:46 +000092
wdenk591dda52002-11-18 00:14:45 +000093 asm volatile ("pushfl ; popl %0 ; cli\n" : "=g" (flags) : );
wdenk57b2d802003-06-27 21:31:46 +000094
wdenk591dda52002-11-18 00:14:45 +000095 return (flags&0x200); /* IE flags is bit 9 */
96}