Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / arch / i386 / include / io.h
blob55fbca1f159ea52d21159eb3be9d23c7a6dd1b37
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef _X86_H
21 #define _X86_H
23 #include <system.h>
24 #include <build.h>
26 #define M_PIC 0x20 /* I/O for master PIC */
27 #define M_IMR 0x21 /* I/O for master IMR */
28 #define S_PIC 0xA0 /* I/O for slave PIC */
29 #define S_IMR 0xA1 /* I/O for slace IMR */
31 #define EOI 0x20 /* EOI command */
33 #define ICW1 0x11 /* Cascade, Edge triggered */
34 /* ICW2 is vector */
35 /* ICW3 is slave bitmap or number */
36 #define ICW4 0x01 /* 8088 mode */
38 #define M_VEC 0x68 /* Vector for master */
39 #define S_VEC 0x70 /* Vector for slave */
41 #define OCW3_IRR 0x0A /* Read IRR */
42 #define OCW3_ISR 0x0B /* Read ISR */
45 #ifdef ARCH_i386
47 #define inw(port) ({ \
48 unsigned short _v; \
49 __asm__ volatile ("inw %%dx, %%ax":"=a" (_v):"dN" (port)); \
50 _v; \
53 /*#define outw(value, port) \
54 __asm__ ("outw %%ax, %%dx"::"a" (value),"dN" (port))*/
56 #define outb_p(value, port) \
57 __asm__ ("outb %%al, %%dx\n" \
58 "\tjmp 1f\n" \
59 "1:\tjmp 1f\n" \
60 "1:"::"a" (value),"d" (port))
62 #define outw_p(value,port) \
63 __asm__ ("outw %%ax,%%dx\n" \
64 "\tjmp 1f\n" \
65 "1:\tjmp 1f\n" \
66 "1:"::"a" (value),"dN" (port))
68 #define inb_p(port) ({ \
69 unsigned char _v; \
70 __asm__ volatile ("inb %%dx,%%al\n" \
71 "\tjmp 1f\n" \
72 "1:\tjmp 1f\n" \
73 "1:":"=a" (_v):"d" (port)); \
74 _v; \
78 /* This defines what the stack looks like after an ISR was running */
79 struct regs
81 unsigned int ds, es, fs, gs;
82 unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
83 unsigned int int_no, err_code;
84 unsigned int eip, cs, eflags, useresp, ss;
87 /* registers pushed on the stack by exceptions or interrupts that
88 switch from user privilege to kernel privilege
89 *** WARNING ***
90 The layout of this struct must agree with the order in which
91 registers are pushed and popped in the assembly-language
92 interrupt handler code. */
93 typedef struct
95 unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; /* PUSHA/POP */
96 unsigned ds, es, fs, gs;
97 unsigned which_int, err_code;
98 unsigned eip, cs, eflags, user_esp, user_ss; /* INT nn/IRET */
99 unsigned v_es, v_ds, v_fs, v_gs; /* V86 mode only */
100 } uregs_t;
102 #define _set_gate(gate_addr, type, dpl, addr) \
103 __asm__ ("movw %%dx,%%ax\n\t" \
104 "movw %0,%%dx\n\t" \
105 "movl %%eax,%1\n\t" \
106 "movl %%edx,%2" \
108 : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
109 "o" (*((char *) (gate_addr))), \
110 "o" (*(4+(char *) (gate_addr))), \
111 "d" ((char *) (addr)),"a" (0x00080000))
113 void dma_xfer (unsigned char channel, unsigned long address, unsigned int length, unsigned char read);
115 void enable_irq (unsigned short irq_num);
116 void disable_irq (unsigned short irq_num);
118 extern void outb (unsigned port, unsigned val);
120 extern void init_v86_regs(uregs_t *regs);
121 extern void do_v86_int(uregs_t *regs, unsigned int_num);
123 /* gtd.c */
124 extern void gdt_set_gate (int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
125 extern unsigned int gdt_install ();
127 /* idt.c */
128 extern void idt_set_gate (unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
129 extern unsigned int idt_install ();
131 /* isrs.c */
132 extern unsigned int isrs_install ();
134 /* irq.c */
135 extern void irq_install_handler (int irq, void (*handler)(struct regs *r));
136 extern void irq_uninstall_handler (int irq);
137 extern unsigned int irq_install ();
139 /* timer.c */
140 extern void timer_wait (int ticks);
141 extern unsigned int timer_install ();
143 #endif
145 #endif