POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/include/arch/x86/interrupt.h
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #ifndef __POK_INTERRUPT_H__
00019 #define __POK_INTERRUPT_H__
00020 
00021 
00022 #include <types.h>
00023 
00024 typedef struct
00025 {
00026   uint32_t es;
00027   uint32_t ds;
00028   uint32_t edi;
00029   uint32_t esi;
00030   uint32_t ebp;
00031   uint32_t __esp;
00032   uint32_t ebx;
00033   uint32_t edx;
00034   uint32_t ecx;
00035   uint32_t eax;
00036 
00037   /* These are pushed by interrupt */
00038   uint32_t error;       /* Error code or padding */
00039   uint32_t eip;
00040   uint32_t cs;
00041   uint32_t eflags;
00042 
00043   /* Only pushed with privilege switch */
00044   /* (Check cs content to have original CPL) */
00045   uint32_t esp;
00046   uint32_t ss;
00047 } interrupt_frame;
00048 
00049 extern uint32_t pok_tss;
00050 
00051 void update_tss (interrupt_frame* frame);
00052 
00053 #define INTERRUPT_HANDLER(name)                                         \
00054 void name (void);                                                       \
00055 void name##_handler(interrupt_frame* frame);                            \
00056   asm (                                                                 \
00057       ".global "#name "                 \n"                             \
00058       "\t.type "#name",@function        \n"                             \
00059       #name":                           \n"                             \
00060       "cli                      \n"                             \
00061       "subl $4, %esp                    \n"                             \
00062       "pusha                            \n"                             \
00063       "push %ds                         \n"                             \
00064       "push %es                         \n"                             \
00065       "push %esp                        \n"                             \
00066       "mov $0x10, %ax                   \n"                             \
00067       "mov %ax, %ds                     \n"                             \
00068       "mov %ax, %es                     \n"                             \
00069       "call " #name"_handler            \n"                             \
00070       "call update_tss                  \n"                             \
00071       "addl $4, %esp                    \n"                             \
00072       "pop %es                          \n"                             \
00073       "pop %ds                          \n"                             \
00074       "popa                             \n"                             \
00075       "addl $4, %esp                    \n"                             \
00076       "sti                      \n"                             \
00077       "iret                             \n"                             \
00078       );                                                                \
00079 void name##_handler(interrupt_frame* frame)
00080 
00081 #define INTERRUPT_HANDLER_errorcode(name)                               \
00082 void name (void);                                                       \
00083 void name##_handler(interrupt_frame* frame);                    \
00084   asm (                                                                 \
00085       ".global "#name "                 \n"                             \
00086       "\t.type "#name",@function        \n"                             \
00087       #name":                           \n"                             \
00088       "cli                      \n"                             \
00089       "pusha                            \n"                             \
00090       "push %ds                         \n"                             \
00091       "push %es                         \n"                             \
00092       "push %esp                        \n"                             \
00093       "mov $0x10, %ax                   \n"                             \
00094       "mov %ax, %ds                     \n"                             \
00095       "mov %ax, %es                     \n"                             \
00096       "call " #name"_handler            \n"                             \
00097       "call update_tss                  \n"                             \
00098       "addl $4, %esp                    \n"                             \
00099       "pop %es                          \n"                             \
00100       "pop %ds                          \n"                             \
00101       "popa                             \n"                             \
00102       "addl $4, %esp                    \n"                             \
00103       "sti                      \n"                             \
00104       "iret                             \n"                             \
00105       );                                                                \
00106 void name##_handler(interrupt_frame* frame)
00107 
00108 #define INTERRUPT_HANDLER_syscall(name)                                         \
00109 int name (void);                                                        \
00110 void name##_handler(interrupt_frame* frame);                            \
00111   asm (                                                                 \
00112       ".global "#name "                 \n"                             \
00113       "\t.type "#name",@function        \n"                             \
00114       #name":                           \n"                             \
00115       "cli                      \n"                             \
00116       "subl $4, %esp                    \n"                             \
00117       "pusha                            \n"                             \
00118       "push %ds                         \n"                             \
00119       "push %es                         \n"                             \
00120       "push %esp                        \n"                             \
00121       "mov $0x10, %ax                   \n"                             \
00122       "mov %ax, %ds                     \n"                             \
00123       "mov %ax, %es                     \n"                             \
00124       "call " #name"_handler            \n"                             \
00125       "movl %eax, 40(%esp)         \n" /* return value */  \
00126       "call update_tss                  \n"                             \
00127       "addl $4, %esp                    \n"                             \
00128       "pop %es                          \n"                             \
00129       "pop %ds                          \n"                             \
00130       "popa                             \n"                             \
00131       "addl $4, %esp                    \n"                             \
00132       "sti                      \n"                             \
00133       "iret                             \n"                             \
00134       );                                                                \
00135 void name##_handler(interrupt_frame* frame)
00136 
00137 
00138 #endif /* !__POK_INTERRUPT_H__ */