source: trunk/hal/tsar_mips32/core/hal_exception.c @ 367

Last change on this file since 367 was 317, checked in by alain, 4 years ago

1) Introduce the TSAR hal_cpu_context_switch() function.
2) Introduce the generic vfs_kernel_move() function.

File size: 5.9 KB
Line 
1/*
2 * hal_exception.c - implementation of exception handler for TSAR-MIPS32.
3 *
4 * Author   Alain Greiner (2016, 2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_irqmask.h>
26#include <hal_exception.h>
27#include <thread.h>
28#include <printk.h>
29#include <vmm.h>
30#include <errno.h>
31#include <scheduler.h>
32#include <core.h>
33#include <signal.h>
34#include <syscalls.h>
35#include <do_exception.h>
36#include <remote_spinlock.h>
37#include <mips32_uzone.h>
38
39//////////////////////////////////////////////////////////////////////////////////////////
40//  Extern global variables
41//////////////////////////////////////////////////////////////////////////////////////////
42
43extern remote_spinlock_t  exception_lock;  // allocated in the do_exception.c file.
44
45//////////////////////////////////////////////////////////////////////////////////////////
46// This enum defines the relevant values for XCODE field in mips32 CP0_CR register.
47//////////////////////////////////////////////////////////////////////////////////////////
48
49typedef enum
50{
51    XCODE_ADEL = 0x4,        // Illegal address for data load
52    XCODE_ADES = 0x5,        // Illegal address for data store
53    XCODE_IBE  = 0x6,        // Instruction MMU exception       (can be NON-FATAL)
54    XCODE_DBE  = 0x7,        // Data MMU exception              (can be NON-FATAL)
55    XCODE_RI   = 0xA,        // Reserved instruction exception
56    XCODE_CPU  = 0xB,        // Coprocessor unusable exception  (can be NON-FATAl)
57    XCODE_OVR  = 0xC,        // Arithmetic Overflow exception
58}
59xcode_values_t;
60
61///////////////////////////////////////
62void hal_do_exception( thread_t * this, 
63                       reg_t    * regs_tbl )
64{
65        error_t             error;
66        uint32_t            excCode;                  // 4 bits XCODE from CP0_CR
67
68    // get 4 bits XCODE from CP0_CR register
69        excCode        = (regs_tbl[UZ_CR] >> 2) & 0xF;
70
71        switch(excCode)
72        {
73        case XCODE_DBE:     // can be non fatal
74            case XCODE_IBE:     // call generic excepton handler for a MMU exception
75        {
76                    error = do_exception( this , true );
77        }
78                break;
79
80            case XCODE_CPU:    // can be non fatal
81                           // call generic excepton handler for a FPU exception
82        {
83            if( ((regs_tbl[UZ_CR] >> 28) & 0x3) == 1 )  // unavailable FPU
84            {
85                error = do_exception( this , false );
86            }
87            else
88            {
89                        error = EXCP_USER_ERROR;
90            }
91        }
92                break;
93
94        case XCODE_OVR:   // user fatal error
95        case XCODE_RI:    // user fatal error
96        case XCODE_ADEL:  // user fatal error
97        case XCODE_ADES:  // kill process
98        {
99                    error = EXCP_USER_ERROR;
100        }
101            break;
102
103        default:
104        {
105                    error = EXCP_KERNEL_PANIC;
106        }
107        }
108   
109    // analyse error code
110        if( error == EXCP_USER_ERROR )          //  user error => kill user process
111        {
112        hal_exception_dump( this , regs_tbl );
113        sys_kill( this->process->pid , SIGKILL );
114        }
115    else if( error == EXCP_KERNEL_PANIC )   // kernel error => kernel panic
116    {
117        hal_exception_dump( this , regs_tbl );
118        hal_core_sleep();
119    }
120}  // end hal_do_exception()
121
122/////////////////////////////////////////
123void hal_exception_dump( thread_t * this,
124                         reg_t    * regs_tbl )
125{
126    // take the exception_lock located in io_cluster
127    remote_spinlock_lock( XPTR( LOCAL_CLUSTER->io_cxy , &exception_lock ) );
128
129    if( this->type == THREAD_USER )
130    printk("\n================= USER ERROR / cycle %d ====================\n",
131           hal_time_stamp() );
132    else
133    printk("\n================= KERNEL PANIC / cycle %d ==================\n",
134           hal_time_stamp() );
135
136        printk("  thread type = %s / trdid = %x / pid %x / core[%x,%d]\n"
137           "  local locks = %d / remote locks = %d / blocked_vector = %X\n\n",
138           thread_type_str(this->type), this->trdid, this->process->pid, local_cxy,
139           this->core->lid, this->local_locks, this->remote_locks, this->blocked );
140
141        printk("CR    %X  EPC   %X  SR    %X  SP     %X\n",
142                   regs_tbl[UZ_CR], regs_tbl[UZ_EPC], regs_tbl[UZ_SR], regs_tbl[UZ_SP]);
143
144    printk("at_1  %X  v0_2  %X  v1_3  %X  a0_4   %X  a1_5   %X\n",
145               regs_tbl[UZ_AT], regs_tbl[UZ_V0], regs_tbl[UZ_V1], regs_tbl[UZ_A0], regs_tbl[UZ_A1]);
146
147    printk("a2_6  %X  a3_7  %X  t0_8  %X  t1_9   %X  t2_10  %X\n",
148                   regs_tbl[UZ_A2],regs_tbl[UZ_A3],regs_tbl[UZ_T0],regs_tbl[UZ_T1],regs_tbl[UZ_T2]);
149 
150    printk("t3_11 %X  t4_12 %X  t5_13 %X  t6_14  %X  t7_15  %X\n",
151                   regs_tbl[UZ_T3],regs_tbl[UZ_T4],regs_tbl[UZ_T5],regs_tbl[UZ_T6],regs_tbl[UZ_T7]);
152
153    printk("t8_24 %X  t9_25 %X  gp_28 %X  c0_hi  %X  c0_lo  %X\n",
154                   regs_tbl[UZ_T8],regs_tbl[UZ_T9],regs_tbl[UZ_GP],regs_tbl[UZ_HI],regs_tbl[UZ_LO]);
155
156    printk("s0_16 %X  s1_17 %X  s2_18 %X  s3_19  %X  s4_20  %X\n",
157                   regs_tbl[UZ_S0],regs_tbl[UZ_S1],regs_tbl[UZ_S2],regs_tbl[UZ_S3],regs_tbl[UZ_S4]);
158 
159    printk("s5_21 %X  s6_22 %X  s7_23 %X  s8_30  %X  ra_31  %X\n",
160               regs_tbl[UZ_S5],regs_tbl[UZ_S6],regs_tbl[UZ_S7],regs_tbl[UZ_S8],regs_tbl[UZ_RA]);
161
162    // release the exception_lock
163    remote_spinlock_unlock( XPTR( LOCAL_CLUSTER->io_cxy , &exception_lock ) );
164
165}  // end hal_exception_dump()
166
Note: See TracBrowser for help on using the repository browser.