FreeNOS
ARMCore.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <Log.h>
19 #include <String.h>
20 #include "ARMCore.h"
21 
22 void ARMCore::logException(CPUState *state) const
23 {
24  logState(state);
25 }
26 
27 void ARMCore::logState(CPUState *state) const
28 {
29  ARMControl ctrl;
30 
31  logRegister("cpsr", state->cpsr);
32  logRegister("sp", state->sp);
33  logRegister("lr", state->lr);
34  logRegister("pc", state->pc);
37 
38  u32 ifsr = ctrl.read(ARMControl::InstructionFaultStatus) & 0xf;
39  const char *ifsrText = "unknown";
40  switch (ifsr)
41  {
42  case 0: ifsrText = "no function"; break;
43  case 1: ifsrText = "alignment fault"; break;
44  case 2: ifsrText = "instruction debug event fault"; break;
45  case 3: ifsrText = "access bit fault on section"; break;
46  case 4: ifsrText = "no function"; break;
47  case 5: ifsrText = "translation section fault"; break;
48  case 6: ifsrText = "access bit fault on page"; break;
49  case 7: ifsrText = "translation page fault"; break;
50  case 8: ifsrText = "precise external abort"; break;
51  case 9: ifsrText = "domain section fault"; break;
52  case 10: ifsrText = "no function"; break;
53  case 11: ifsrText = "domain page fault"; break;
54  case 12: ifsrText = "external abort on translation first level"; break;
55  case 13: ifsrText = "permission section fault"; break;
56  case 14: ifsrText = "external abort on translation second level"; break;
57  case 15: ifsrText = "permission page fault"; break;
58  }
59  logRegister("ifsr", ifsr, ifsrText);
60 
61  u32 dfsr = ctrl.read(ARMControl::DataFaultStatus) & 0xf;
62  const char *dfsrText = "unknown";
63  if (ctrl.read(ARMControl::DataFaultStatus) & (1 << 10))
64  {
65  dfsrText = (dfsr == 6 ? "imprecise external abort" : "no function");
66  }
67  else
68  {
69  switch (dfsr)
70  {
71  case 0: dfsrText = "no function"; break;
72  case 1: dfsrText = "alignment fault"; break;
73  case 2: dfsrText = "instruction debug event fault"; break;
74  case 3: dfsrText = "access bit fault on section"; break;
75  case 4: dfsrText = "instruction cache maintenance operation fault"; break;
76  case 5: dfsrText = "translation section fault"; break;
77  case 6: dfsrText = "access bit fault on page"; break;
78  case 7: dfsrText = "translation page fault"; break;
79  case 8: dfsrText = "precise external abort"; break;
80  case 9: dfsrText = "domain section fault"; break;
81  case 10: dfsrText = "no function"; break;
82  case 11: dfsrText = "domain page fault"; break;
83  case 12: dfsrText = "external abort on translation first level"; break;
84  case 13: dfsrText = "permission section fault"; break;
85  case 14: dfsrText = "external abort on translation second level"; break;
86  case 15: dfsrText = "permission page fault"; break;
87  }
88  }
89  logRegister("dfsr", dfsr, dfsrText);
90 
91  logRegister("r0", state->r0);
92  logRegister("r1", state->r1);
93  logRegister("r2", state->r2);
94  logRegister("r3", state->r3);
95  logRegister("r4", state->r4);
96  logRegister("r5", state->r5);
97  logRegister("r6", state->r6);
98  logRegister("r7", state->r7);
99  logRegister("r8", state->r8);
100  logRegister("r9", state->r9);
101  logRegister("r10", state->r10);
102  logRegister("r11", state->r11);
103  logRegister("r12", state->r12);
104 }
105 
106 void ARMCore::logRegister(const char *name, u32 reg, const char *text) const
107 {
108  String s;
109  s << Number::Hex << name << " = " << reg << Number::Dec << " (" << reg << ") " << text;
110  ERROR(*s);
111 }
ARMCore::logException
void logException(CPUState *state) const
Log a CPU exception.
Definition: ARMCore.cpp:22
CPUState::r12
u32 r12
Definition: ARMCore.h:248
ARMControl::DataFaultAddress
@ DataFaultAddress
Definition: ARMControl.h:74
CPUState::r9
u32 r9
Definition: ARMCore.h:248
CPUState::sp
u32 sp
Definition: ARMCore.h:247
String
Abstraction of strings.
Definition: String.h:41
CPUState::r6
u32 r6
Definition: ARMCore.h:248
ARMCore.h
ARMCore::logRegister
void logRegister(const char *name, u32 reg, const char *text="") const
Log a register.
Definition: ARMCore.cpp:106
Number::Dec
@ Dec
Definition: Types.h:170
ARMControl::InstructionFaultAddress
@ InstructionFaultAddress
Definition: ARMControl.h:72
CPUState::cpsr
u32 cpsr
Definition: ARMCore.h:246
CPUState::r0
u32 r0
Definition: ARMCore.h:248
ARMControl::InstructionFaultStatus
@ InstructionFaultStatus
Definition: ARMControl.h:73
Log.h
CPUState::r5
u32 r5
Definition: ARMCore.h:248
ARMControl
ARM System Control Coprocessor (CP15).
Definition: ARMControl.h:47
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
CPUState::r11
u32 r11
Definition: ARMCore.h:248
CPUState::pc
u32 pc
Definition: ARMCore.h:249
CPUState
Contains all the CPU registers.
Definition: ARMCore.h:243
CPUState::r7
u32 r7
Definition: ARMCore.h:248
CPUState::lr
u32 lr
Definition: ARMCore.h:247
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
CPUState::r1
u32 r1
Definition: ARMCore.h:248
String.h
ARMControl::DataFaultStatus
@ DataFaultStatus
Definition: ARMControl.h:75
CPUState::r8
u32 r8
Definition: ARMCore.h:248
CPUState::r3
u32 r3
Definition: ARMCore.h:248
CPUState::r2
u32 r2
Definition: ARMCore.h:248
CPUState::r4
u32 r4
Definition: ARMCore.h:248
ARMCore::logState
void logState(CPUState *state) const
Log the CPU state.
Definition: ARMCore.cpp:27
Number::Hex
@ Hex
Decimal: 0-10.
Definition: Types.h:171
CPUState::r10
u32 r10
Definition: ARMCore.h:248
ARMControl::read
u32 read(Register reg) const
Read a register from the CP15.
Definition: ARMControl.cpp:29