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 9.5) and /hwcore/exception.c (Article 3)


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

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