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 7) and /hwcore/exception.c (Article 6.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                                                << 
025 #include "exception.h"                            022 #include "exception.h"
026                                                   023 
027 /* array of exception wrappers, defined in exc    024 /* array of exception wrappers, defined in exception_wrappers.S */
028 extern sos_vaddr_t sos_exception_wrapper_array    025 extern sos_vaddr_t sos_exception_wrapper_array[SOS_EXCEPT_NUM];
029                                                   026 
030 /* arrays of exception handlers, shared with e    027 /* arrays of exception handlers, shared with exception_wrappers.S */
031 sos_exception_handler_t sos_exception_handler_    028 sos_exception_handler_t sos_exception_handler_array[SOS_EXCEPT_NUM] =
032   { NULL, };                                      029   { NULL, };
033                                                   030 
034 /* List of exception names for the x86 archite    031 /* List of exception names for the x86 architecture */
035 static const char * sos_x86_exnames[] = {         032 static const char * sos_x86_exnames[] = {
036   [SOS_EXCEPT_DIVIDE_ERROR]                = "    033   [SOS_EXCEPT_DIVIDE_ERROR]                = "Division by zero",
037   [SOS_EXCEPT_DEBUG]                       = "    034   [SOS_EXCEPT_DEBUG]                       = "Debug",
038   [SOS_EXCEPT_NMI_INTERRUPT]               = "    035   [SOS_EXCEPT_NMI_INTERRUPT]               = "Non Maskable Interrupt",
039   [SOS_EXCEPT_BREAKPOINT]                  = "    036   [SOS_EXCEPT_BREAKPOINT]                  = "Breakpoint",
040   [SOS_EXCEPT_OVERFLOW]                    = "    037   [SOS_EXCEPT_OVERFLOW]                    = "Overflow",
041   [SOS_EXCEPT_BOUND_RANGE_EXCEDEED]        = "    038   [SOS_EXCEPT_BOUND_RANGE_EXCEDEED]        = "Bound Range Exceeded",
042   [SOS_EXCEPT_INVALID_OPCODE]              = "    039   [SOS_EXCEPT_INVALID_OPCODE]              = "Invalid Opcode",
043   [SOS_EXCEPT_DEVICE_NOT_AVAILABLE]        = "    040   [SOS_EXCEPT_DEVICE_NOT_AVAILABLE]        = "Device Unavailable",
044   [SOS_EXCEPT_DOUBLE_FAULT]                = "    041   [SOS_EXCEPT_DOUBLE_FAULT]                = "Double Fault",
045   [SOS_EXCEPT_COPROCESSOR_SEGMENT_OVERRUN] = "    042   [SOS_EXCEPT_COPROCESSOR_SEGMENT_OVERRUN] = "Coprocessor Segment Overrun",
046   [SOS_EXCEPT_INVALID_TSS]                 = "    043   [SOS_EXCEPT_INVALID_TSS]                 = "Invalid TSS",
047   [SOS_EXCEPT_SEGMENT_NOT_PRESENT]         = "    044   [SOS_EXCEPT_SEGMENT_NOT_PRESENT]         = "Segment Not Present",
048   [SOS_EXCEPT_STACK_SEGMENT_FAULT]         = "    045   [SOS_EXCEPT_STACK_SEGMENT_FAULT]         = "Stack Segfault",
049   [SOS_EXCEPT_GENERAL_PROTECTION]          = "    046   [SOS_EXCEPT_GENERAL_PROTECTION]          = "General Protection",
050   [SOS_EXCEPT_PAGE_FAULT]                  = "    047   [SOS_EXCEPT_PAGE_FAULT]                  = "Page Fault",
051   [SOS_EXCEPT_INTEL_RESERVED_1]            = "    048   [SOS_EXCEPT_INTEL_RESERVED_1]            = "INTEL1",
052   [SOS_EXCEPT_FLOATING_POINT_ERROR]        = "    049   [SOS_EXCEPT_FLOATING_POINT_ERROR]        = "FP Error",
053   [SOS_EXCEPT_ALIGNEMENT_CHECK]            = "    050   [SOS_EXCEPT_ALIGNEMENT_CHECK]            = "Alignment Check",
054   [SOS_EXCEPT_MACHINE_CHECK]               = "    051   [SOS_EXCEPT_MACHINE_CHECK]               = "Machine Check",
055   [SOS_EXCEPT_INTEL_RESERVED_2]            = "    052   [SOS_EXCEPT_INTEL_RESERVED_2]            = "INTEL2",
056   [SOS_EXCEPT_INTEL_RESERVED_3]            = "    053   [SOS_EXCEPT_INTEL_RESERVED_3]            = "INTEL3",
057   [SOS_EXCEPT_INTEL_RESERVED_4]            = "    054   [SOS_EXCEPT_INTEL_RESERVED_4]            = "INTEL4",
058   [SOS_EXCEPT_INTEL_RESERVED_5]            = "    055   [SOS_EXCEPT_INTEL_RESERVED_5]            = "INTEL5",
059   [SOS_EXCEPT_INTEL_RESERVED_6]            = "    056   [SOS_EXCEPT_INTEL_RESERVED_6]            = "INTEL6",
060   [SOS_EXCEPT_INTEL_RESERVED_7]            = "    057   [SOS_EXCEPT_INTEL_RESERVED_7]            = "INTEL7",
061   [SOS_EXCEPT_INTEL_RESERVED_8]            = "    058   [SOS_EXCEPT_INTEL_RESERVED_8]            = "INTEL8",
062   [SOS_EXCEPT_INTEL_RESERVED_9]            = "    059   [SOS_EXCEPT_INTEL_RESERVED_9]            = "INTEL9",
063   [SOS_EXCEPT_INTEL_RESERVED_10]           = "    060   [SOS_EXCEPT_INTEL_RESERVED_10]           = "INTEL10",
064   [SOS_EXCEPT_INTEL_RESERVED_11]           = "    061   [SOS_EXCEPT_INTEL_RESERVED_11]           = "INTEL11",
065   [SOS_EXCEPT_INTEL_RESERVED_12]           = "    062   [SOS_EXCEPT_INTEL_RESERVED_12]           = "INTEL12",
066   [SOS_EXCEPT_INTEL_RESERVED_13]           = "    063   [SOS_EXCEPT_INTEL_RESERVED_13]           = "INTEL13",
067   [SOS_EXCEPT_INTEL_RESERVED_14]           = "    064   [SOS_EXCEPT_INTEL_RESERVED_14]           = "INTEL14"
068 };                                                065 };
069                                                   066 
070                                                   067 
071 /* Catch-all exception handler */                 068 /* Catch-all exception handler */
072 static void sos_generic_ex(int exid, struct so !! 069 static void sos_generic_ex(int exid, const struct sos_cpu_state *ctxt)
073 {                                                 070 {
074   const char *exname = sos_exception_get_name(    071   const char *exname = sos_exception_get_name(exid);
075                                                   072 
076   if (sos_cpu_context_is_in_user_mode(ctxt))   !! 073   sos_display_fatal_error("Exception %s in Kernel at instruction 0x%x (info=%x)!\n",
077     {                                          !! 074                           exname,
078       /* Exception while in user mode */       !! 075                           sos_cpu_context_get_PC(ctxt),
079       sos_bochs_printf("Exception %s in User m !! 076                           (unsigned)sos_cpu_context_get_EX_info(ctxt));
080                        exname,                 << 
081                        sos_cpu_context_get_PC( << 
082                        (unsigned)sos_cpu_conte << 
083       sos_bochs_printf("Terminating User threa << 
084       sos_thread_exit();                       << 
085     }                                          << 
086   else                                         << 
087     sos_display_fatal_error("Exception %s in K << 
088                             exname,            << 
089                             sos_cpu_context_ge << 
090                             (unsigned)sos_cpu_ << 
091 }                                                 077 }
092                                                   078 
093                                                   079 
094 sos_ret_t sos_exception_subsystem_setup(void)     080 sos_ret_t sos_exception_subsystem_setup(void)
095 {                                                 081 {
096   sos_ret_t retval;                               082   sos_ret_t retval;
097   int exid;                                       083   int exid;
098                                                   084 
099   /* Setup the generic exception handler by de    085   /* Setup the generic exception handler by default for everybody
100      except for the double fault exception */     086      except for the double fault exception */
101   for (exid = 0 ; exid < SOS_EXCEPT_NUM ; exid    087   for (exid = 0 ; exid < SOS_EXCEPT_NUM ; exid ++)
102     {                                             088     {
103       /* Skip double fault (see below) */         089       /* Skip double fault (see below) */
104       if (exid == SOS_EXCEPT_DOUBLE_FAULT)        090       if (exid == SOS_EXCEPT_DOUBLE_FAULT)
105         continue;                                 091         continue;
106                                                   092 
107       retval = sos_exception_set_routine(exid,    093       retval = sos_exception_set_routine(exid, sos_generic_ex);
108       if (SOS_OK != retval)                       094       if (SOS_OK != retval)
109         return retval;                            095         return retval;
110     }                                             096     }
111                                                   097 
112                                                   098 
113   /* We inidicate that the double fault except    099   /* We inidicate that the double fault exception handler is defined,
114      and give its address. this handler is a d    100      and give its address. this handler is a do-nothing handler (see
115      exception_wrappers.S), and it can NOT be     101      exception_wrappers.S), and it can NOT be overriden by the
116      functions below */                           102      functions below */
117   return sos_idt_set_handler(SOS_EXCEPT_BASE +    103   return sos_idt_set_handler(SOS_EXCEPT_BASE + SOS_EXCEPT_DOUBLE_FAULT,
118                             (sos_vaddr_t) sos_    104                             (sos_vaddr_t) sos_exception_wrapper_array[SOS_EXCEPT_DOUBLE_FAULT],
119                             0 /* CPL0 routine     105                             0 /* CPL0 routine */);
120 }                                                 106 }
121                                                   107 
122                                                   108 
123 sos_ret_t sos_exception_set_routine(int except    109 sos_ret_t sos_exception_set_routine(int exception_number,
124                                     sos_except    110                                     sos_exception_handler_t routine)
125 {                                                 111 {
126   sos_ret_t retval;                               112   sos_ret_t retval;
127   sos_ui32_t flags;                               113   sos_ui32_t flags;
128                                                   114   
129   if ((exception_number < 0) || (exception_num    115   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
130     return -SOS_EINVAL;                           116     return -SOS_EINVAL;
131                                                   117 
132   /* Double fault not supported */                118   /* Double fault not supported */
133   if (exception_number == SOS_EXCEPT_DOUBLE_FA    119   if (exception_number == SOS_EXCEPT_DOUBLE_FAULT)
134     return -SOS_ENOSUP;                           120     return -SOS_ENOSUP;
135                                                   121   
136   sos_disable_IRQs(flags);                        122   sos_disable_IRQs(flags);
137                                                   123 
138   retval = SOS_OK;                                124   retval = SOS_OK;
139                                                   125 
140   /* Set the exception routine to be called by    126   /* Set the exception routine to be called by the exception wrapper */
141   sos_exception_handler_array[exception_number    127   sos_exception_handler_array[exception_number] = routine;
142                                                   128 
143   /* If the exception is to be enabled, update    129   /* If the exception is to be enabled, update the IDT with the exception
144      wrapper */                                   130      wrapper */
145   if (routine != NULL)                            131   if (routine != NULL)
146     retval                                        132     retval
147       = sos_idt_set_handler(SOS_EXCEPT_BASE +     133       = sos_idt_set_handler(SOS_EXCEPT_BASE + exception_number,
148                             (sos_vaddr_t) sos_    134                             (sos_vaddr_t) sos_exception_wrapper_array[exception_number],
149                             0 /* CPL0 routine     135                             0 /* CPL0 routine */);
150   else /* Disable the IDT entry */                136   else /* Disable the IDT entry */
151     retval                                        137     retval
152       = sos_idt_set_handler(SOS_EXCEPT_BASE +     138       = sos_idt_set_handler(SOS_EXCEPT_BASE + exception_number,
153                             (sos_vaddr_t)NULL     139                             (sos_vaddr_t)NULL /* No routine => disable IDTE */,
154                             0 /* don't care */    140                             0 /* don't care */);
155                                                   141 
156   sos_restore_IRQs(flags);                        142   sos_restore_IRQs(flags);
157   return retval;                                  143   return retval;
158 }                                                 144 }
159                                                   145 
160                                                   146 
161 sos_exception_handler_t sos_exception_get_rout    147 sos_exception_handler_t sos_exception_get_routine(int exception_number)
162 {                                                 148 {
163   if ((exception_number < 0) || (exception_num    149   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
164     return NULL;                                  150     return NULL;
165                                                   151 
166   /* Double fault not supported */                152   /* Double fault not supported */
167   if (exception_number == SOS_EXCEPT_DOUBLE_FA    153   if (exception_number == SOS_EXCEPT_DOUBLE_FAULT)
168     return NULL;                                  154     return NULL;
169                                                   155   
170   /* Expected to be atomic */                     156   /* Expected to be atomic */
171   return sos_exception_handler_array[exception    157   return sos_exception_handler_array[exception_number];
172 }                                                 158 }
173                                                   159 
174                                                   160 
175 const char * sos_exception_get_name(int except    161 const char * sos_exception_get_name(int exception_number)
176 {                                                 162 {
177   if ((exception_number < 0) || (exception_num    163   if ((exception_number < 0) || (exception_number >= SOS_EXCEPT_NUM))
178     return NULL;                                  164     return NULL;
179                                                   165 
180   return sos_x86_exnames[exception_number];       166   return sos_x86_exnames[exception_number];
181 }                                                 167 }
                                                      

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