Core commit. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-core / src / r4300 / exception.c
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus - exception.c                                             *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2002 Hacktarux                                          *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22 #include "api/m64p_types.h"
23 #include "api/callbacks.h"
24 #include "memory/memory.h"
25
26 #include "exception.h"
27 #include "r4300.h"
28 #include "macros.h"
29 #include "recomph.h"
30
31 void TLB_refill_exception(unsigned int address, int w)
32 {
33    int usual_handler = 0, i;
34
35    if (r4300emu != CORE_DYNAREC && w != 2) update_count();
36    if (w == 1) Cause = (3 << 2);
37    else Cause = (2 << 2);
38    BadVAddr = address;
39    Context = (Context & 0xFF80000F) | ((address >> 9) & 0x007FFFF0);
40    EntryHi = address & 0xFFFFE000;
41    if (Status & 0x2) // Test de EXL
42      {
43     generic_jump_to(0x80000180);
44     if(delay_slot==1 || delay_slot==3) Cause |= 0x80000000;
45     else Cause &= 0x7FFFFFFF;
46      }
47    else
48      {
49     if (r4300emu != CORE_PURE_INTERPRETER) 
50       {
51          if (w!=2)
52            EPC = PC->addr;
53          else
54            EPC = address;
55       }
56     else EPC = PC->addr;
57          
58     Cause &= ~0x80000000;
59     Status |= 0x2; //EXL=1
60     
61     if (address >= 0x80000000 && address < 0xc0000000)
62       usual_handler = 1;
63     for (i=0; i<32; i++)
64       {
65          if (/*tlb_e[i].v_even &&*/ address >= tlb_e[i].start_even &&
66          address <= tlb_e[i].end_even)
67            usual_handler = 1;
68          if (/*tlb_e[i].v_odd &&*/ address >= tlb_e[i].start_odd &&
69          address <= tlb_e[i].end_odd)
70            usual_handler = 1;
71       }
72     if (usual_handler)
73       {
74          generic_jump_to(0x80000180);
75       }
76     else
77       {
78          generic_jump_to(0x80000000);
79       }
80      }
81    if(delay_slot==1 || delay_slot==3)
82      {
83     Cause |= 0x80000000;
84     EPC-=4;
85      }
86    else
87      {
88     Cause &= 0x7FFFFFFF;
89      }
90    if(w != 2) EPC-=4;
91    
92    last_addr = PC->addr;
93    
94    if (r4300emu == CORE_DYNAREC) 
95      {
96     dyna_jump();
97     if (!dyna_interp) delay_slot = 0;
98      }
99    
100    if (r4300emu != CORE_DYNAREC || dyna_interp)
101      {
102     dyna_interp = 0;
103     if (delay_slot)
104       {
105          skip_jump = PC->addr;
106          next_interupt = 0;
107       }
108      }
109 }
110
111 void exception_general(void)
112 {
113    update_count();
114    Status |= 2;
115    
116    EPC = PC->addr;
117    
118    if(delay_slot==1 || delay_slot==3)
119      {
120     Cause |= 0x80000000;
121     EPC-=4;
122      }
123    else
124      {
125     Cause &= 0x7FFFFFFF;
126      }
127    generic_jump_to(0x80000180);
128    last_addr = PC->addr;
129    if (r4300emu == CORE_DYNAREC)
130      {
131     dyna_jump();
132     if (!dyna_interp) delay_slot = 0;
133      }
134    if (r4300emu != CORE_DYNAREC || dyna_interp)
135      {
136     dyna_interp = 0;
137     if (delay_slot)
138       {
139          skip_jump = PC->addr;
140          next_interupt = 0;
141       }
142      }
143 }
144