SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /hwcore/exception.c (Article 6.5) and /hwcore/exception.c (Article 9.5)


001 /* Copyright (C) 2004  David Decotigny            001 /* Copyright (C) 2004  David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
017 */                                                017 */
018 #include "idt.h"                                  018 #include "idt.h"
019 #include "irq.h"                                  019 #include "irq.h"
020                                                   020 
021 #include <sos/assert.h>                           021 #include <sos/assert.h>
                                                   >> 022 #include <drivers/bochs.h>
                                                   >> 023 #include <sos/thread.h>
                                                   >> 024 
022 #include "exception.h"                            025 #include "exception.h"
023                                                   026 
024 /* array of exception wrappers, defined in exc    027 /* array of exception wrappers, defined in exception_wrappers.S */
025 extern sos_vaddr_t sos_exception_wrapper_array    028 extern sos_vaddr_t sos_exception_wrapper_array[SOS_EXCEPT_NUM];
026                                                   029 
027 /* arrays of exception handlers, shared with e    030 /* arrays of exception handlers, shared with exception_wrappers.S */
028 sos_exception_handler_t sos_exception_handler_    031 sos_exception_handler_t sos_exception_handler_array[SOS_EXCEPT_NUM] =
029   { NULL, };                                      032   { NULL, };
030                                                   033 
031 /* List of exception names for the x86 archite    034 /* List of exception names for the x86 architecture */
032 static const char * sos_x86_exnames[] = {         035 static const char * sos_x86_exnames[] = {
033   [SOS_EXCEPT_DIVIDE_ERROR]                = "    036   [SOS_EXCEPT_DIVIDE_ERROR]                = "Division by zero",
034   [SOS_EXCEPT_DEBUG]                       = "    037   [SOS_EXCEPT_DEBUG]                       = "Debug",
035   [SOS_EXCEPT_NMI_INTERRUPT]               = "    038   [SOS_EXCEPT_NMI_INTERRUPT]               = "Non Maskable Interrupt",
036   [SOS_EXCEPT_BREAKPOINT]                  = "    039   [SOS_EXCEPT_BREAKPOINT]                  = "Breakpoint",
037   [SOS_EXCEPT_OVERFLOW]                    = "    040   [SOS_EXCEPT_OVERFLOW]                    = "Overflow",
038   [SOS_EXCEPT_BOUND_RANGE_EXCEDEED]        = "    041   [SOS_EXCEPT_BOUND_RANGE_EXCEDEED]        = "Bound Range Exceeded",
039   [SOS_EXCEPT_INVALID_OPCODE]              = "    042   [SOS_EXCEPT_INVALID_OPCODE]              = "Invalid Opcode",
040   [SOS_EXCEPT_DEVICE_NOT_AVAILABLE]        = "    043   [SOS_EXCEPT_DEVICE_NOT_AVAILABLE]        = "Device Unavailable",
041   [SOS_EXCEPT_DOUBLE_FAULT]                = "    044   [SOS_EXCEPT_DOUBLE_FAULT]                = "Double Fault",
042   [SOS_EXCEPT_COPROCESSOR_SEGMENT_OVERRUN] = "    045   [SOS_EXCEPT_COPROCESSOR_SEGMENT_OVERRUN] = "Coprocessor Segment Overrun",
043   [SOS_EXCEPT_INVALID_TSS]                 = "    046   [SOS_EXCEPT_INVALID_TSS]                 = "Invalid TSS",
044   [SOS_EXCEPT_SEGMENT_NOT_PRESENT]         = "    047   [SOS_EXCEPT_SEGMENT_NOT_PRESENT]         = "Segment Not Present",
045   [SOS_EXCEPT_STACK_SEGMENT_FAULT]         = "    048   [SOS_EXCEPT_STACK_SEGMENT_FAULT]         = "Stack Segfault",
046   [SOS_EXCEPT_GENERAL_PROTECTION]          = "    049   [SOS_EXCEPT_GENERAL_PROTECTION]          = "General Protection",
047   [SOS_EXCEPT_PAGE_FAULT]                  = "    050   [SOS_EXCEPT_PAGE_FAULT]                  = "Page Fault",
048   [SOS_EXCEPT_INTEL_RESERVED_1]            = "    051   [SOS_EXCEPT_INTEL_RESERVED_1]            = "INTEL1",
049   [SOS_EXCEPT_FLOATING_POINT_ERROR]        = "    052   [SOS_EXCEPT_FLOATING_POINT_ERROR]        = "FP Error",
050   [SOS_EXCEPT_ALIGNEMENT_CHECK]            = "    053   [SOS_EXCEPT_ALIGNEMENT_CHECK]            = "Alignment Check",
051   [SOS_EXCEPT_MACHINE_CHECK]               = "    054   [SOS_EXCEPT_MACHINE_CHECK]               = "Machine Check",
052   [SOS_EXCEPT_INTEL_RESERVED_2]            = "    055   [SOS_EXCEPT_INTEL_RESERVED_2]            = "INTEL2",
053   [SOS_EXCEPT_INTEL_RESERVED_3]            = "    056   [SOS_EXCEPT_INTEL_RESERVED_3]            = "INTEL3",
054   [SOS_EXCEPT_INTEL_RESERVED_4]            = "    057   [SOS_EXCEPT_INTEL_RESERVED_4]            = "INTEL4",
055   [SOS_EXCEPT_INTEL_RESERVED_5]            = "    058   [SOS_EXCEPT_INTEL_RESERVED_5]            = "INTEL5",
056   [SOS_EXCEPT_INTEL_RESERVED_6]            = "    059   [SOS_EXCEPT_INTEL_RESERVED_6]            = "INTEL6",
057   [SOS_EXCEPT_INTEL_RESERVED_7]            = "    060   [SOS_EXCEPT_INTEL_RESERVED_7]            = "INTEL7",
058   [SOS_EXCEPT_INTEL_RESERVED_8]            = "    061   [SOS_EXCEPT_INTEL_RESERVED_8]            = "INTEL8",
059   [SOS_EXCEPT_INTEL_RESERVED_9]            = "    062   [SOS_EXCEPT_INTEL_RESERVED_9]            = "INTEL9",
060   [SOS_EXCEPT_INTEL_RESERVED_10]           = "    063   [SOS_EXCEPT_INTEL_RESERVED_10]           = "INTEL10",
061   [SOS_EXCEPT_INTEL_RESERVED_11]           = "    064   [SOS_EXCEPT_INTEL_RESERVED_11]           = "INTEL11",
062   [SOS_EXCEPT_INTEL_RESERVED_12]           = "    065   [SOS_EXCEPT_INTEL_RESERVED_12]           = "INTEL12",
063   [SOS_EXCEPT_INTEL_RESERVED_13]           = "    066   [SOS_EXCEPT_INTEL_RESERVED_13]           = "INTEL13",
064   [SOS_EXCEPT_INTEL_RESERVED_14]           = "    067   [SOS_EXCEPT_INTEL_RESERVED_14]           = "INTEL14"
065 };                                                068 };
066                                                   069 
067                                                   070 
068 /* Catch-all exception handler */                 071 /* Catch-all exception handler */
069 static void sos_generic_ex(int exid, const str !! 072 static void sos_generic_ex(int exid, struct sos_cpu_state *ctxt)
                                                   >> 073      __attribute__((noreturn));
                                                   >> 074 static void sos_generic_ex(int exid, struct sos_cpu_state *ctxt)
070 {                                                 075 {
071   const char *exname = sos_exception_get_name(    076   const char *exname = sos_exception_get_name(exid);
072                                                   077 
073   sos_display_fatal_error("Exception %s in Ker !! 078   if (sos_cpu_context_is_in_user_mode(ctxt))
074                           exname,              !! 079     {
075                           sos_cpu_context_get_ !! 080       /* Exception while in user mode */
076                           (unsigned)sos_cpu_co !! 081       sos_bochs_printf("Exception %s in User mode at instruction 0x%x (info=%x)!\n",
                                                   >> 082                        exname,
                                                   >> 083                        sos_cpu_context_get_PC(ctxt),
                                                   >> 084                        (unsigned)sos_cpu_context_get_EX_info(ctxt));
                                                   >> 085       sos_bochs_printf("Terminating User thread\n");
                                                   >> 086       sos_thread_exit();
                                                   >> 087     }
                                                   >> 088   else
                                                   >> 089     sos_display_fatal_error("Exception %s in Kernel at instruction 0x%x (info=%x)!\n",
                                                   >> 090                             exname,
                                                   >> 091                             sos_cpu_context_get_PC(ctxt),
                                                   >> 092                             (unsigned)sos_cpu_context_get_EX_info(ctxt));
077 }                                                 093 }
078                                                   094 
079                                                   095 
080 sos_ret_t sos_exception_subsystem_setup(void)     096 sos_ret_t sos_exception_subsystem_setup(void)
081 {                                                 097 {
082   sos_ret_t retval;                               098   sos_ret_t retval;
083   int exid;                                       099   int exid;
084                                                   100 
085   /* Setup the generic exception handler by de    101   /* Setup the generic exception handler by default for everybody
086      except for the double fault exception */     102      except for the double fault exception */
087   for (exid = 0 ; exid < SOS_EXCEPT_NUM ; exid    103   for (exid = 0 ; exid < SOS_EXCEPT_NUM ; exid ++)
088     {                                             104     {
089       /* Skip double fault (see below) */         105       /* Skip double fault (see below) */
090       if (exid == SOS_EXCEPT_DOUBLE_FAULT)        106       if (exid == SOS_EXCEPT_DOUBLE_FAULT)
091         continue;                                 107         continue;
092                                                   108 
093       retval = sos_exception_set_routine(exid,    109       retval = sos_exception_set_routine(exid, sos_generic_ex);
094       if (SOS_OK != retval)                       110       if (SOS_OK != retval)
095         return retval;                            111         return retval;
096     }                                             112     }
097                                                   113 
098                                                   114 
099   /* We inidicate that the double fault except    115   /* We inidicate that the double fault exception handler is defined,
100      and give its address. this handler is a d    116      and give its address. this handler is a do-nothing handler (see
101      exception_wrappers.S), and it can NOT be     117      exception_wrappers.S), and it can NOT be overriden by the
102      functions below */                           118      functions below */
103   return sos_idt_set_handler(SOS_EXCEPT_BASE +    119   return sos_idt_set_handler(SOS_EXCEPT_BASE + SOS_EXCEPT_DOUBLE_FAULT,
104                             (sos_vaddr_t) sos_    120                             (sos_vaddr_t) sos_exception_wrapper_array[SOS_EXCEPT_DOUBLE_FAULT],
105                             0 /* CPL0 routine     121                             0 /* CPL0 routine */);
106 }                                                 122 }
107                                                   123 
108                                                   124 
109 sos_ret_t sos_exception_set_routine(int except    125 sos_ret_t sos_exception_set_routine(int exception_number,
110                                     sos_except    126                                     sos_exception_handler_t routine)
111 {                                                 127 {
112   sos_ret_t retval;                               128   sos_ret_t retval;
113   sos_ui32_t flags;                               129   sos_ui32_t flags;
114                                                   130   
115   if ((exception_number < 0) || (exception_num    131   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
116     return -SOS_EINVAL;                           132     return -SOS_EINVAL;
117                                                   133 
118   /* Double fault not supported */                134   /* Double fault not supported */
119   if (exception_number == SOS_EXCEPT_DOUBLE_FA    135   if (exception_number == SOS_EXCEPT_DOUBLE_FAULT)
120     return -SOS_ENOSUP;                           136     return -SOS_ENOSUP;
121                                                   137   
122   sos_disable_IRQs(flags);                        138   sos_disable_IRQs(flags);
123                                                   139 
124   retval = SOS_OK;                                140   retval = SOS_OK;
125                                                   141 
126   /* Set the exception routine to be called by    142   /* Set the exception routine to be called by the exception wrapper */
127   sos_exception_handler_array[exception_number    143   sos_exception_handler_array[exception_number] = routine;
128                                                   144 
129   /* If the exception is to be enabled, update    145   /* If the exception is to be enabled, update the IDT with the exception
130      wrapper */                                   146      wrapper */
131   if (routine != NULL)                            147   if (routine != NULL)
132     retval                                        148     retval
133       = sos_idt_set_handler(SOS_EXCEPT_BASE +     149       = sos_idt_set_handler(SOS_EXCEPT_BASE + exception_number,
134                             (sos_vaddr_t) sos_    150                             (sos_vaddr_t) sos_exception_wrapper_array[exception_number],
135                             0 /* CPL0 routine     151                             0 /* CPL0 routine */);
136   else /* Disable the IDT entry */                152   else /* Disable the IDT entry */
137     retval                                        153     retval
138       = sos_idt_set_handler(SOS_EXCEPT_BASE +     154       = sos_idt_set_handler(SOS_EXCEPT_BASE + exception_number,
139                             (sos_vaddr_t)NULL     155                             (sos_vaddr_t)NULL /* No routine => disable IDTE */,
140                             0 /* don't care */    156                             0 /* don't care */);
141                                                   157 
142   sos_restore_IRQs(flags);                        158   sos_restore_IRQs(flags);
143   return retval;                                  159   return retval;
144 }                                                 160 }
145                                                   161 
146                                                   162 
147 sos_exception_handler_t sos_exception_get_rout    163 sos_exception_handler_t sos_exception_get_routine(int exception_number)
148 {                                                 164 {
149   if ((exception_number < 0) || (exception_num    165   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
150     return NULL;                                  166     return NULL;
151                                                   167 
152   /* Double fault not supported */                168   /* Double fault not supported */
153   if (exception_number == SOS_EXCEPT_DOUBLE_FA    169   if (exception_number == SOS_EXCEPT_DOUBLE_FAULT)
154     return NULL;                                  170     return NULL;
155                                                   171   
156   /* Expected to be atomic */                     172   /* Expected to be atomic */
157   return sos_exception_handler_array[exception    173   return sos_exception_handler_array[exception_number];
158 }                                                 174 }
159                                                   175 
160                                                   176 
161 const char * sos_exception_get_name(int except    177 const char * sos_exception_get_name(int exception_number)
162 {                                                 178 {
163   if ((exception_number < 0) || (exception_num    179   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
164     return NULL;                                  180     return NULL;
165                                                   181 
166   return sos_x86_exnames[exception_number];       182   return sos_x86_exnames[exception_number];
167 }                                                 183 }
                                                      

source navigation ] diff markup ] identifier search ] general search ]