-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharm.c
More file actions
127 lines (99 loc) · 2.42 KB
/
Copy patharm.c
File metadata and controls
127 lines (99 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// BSP support routine
#include "types.h"
#include "defs.h"
#include "param.h"
#include "memlayout.h"
#include "proc.h"
#include "arm.h"
#include "mmu.h"
void cli (void)
{
uint val;
// ok, enable paging using read/modify/write
asm("MRS %[v], cpsr": [v]"=r" (val)::);
val |= DIS_INT;
asm("MSR cpsr_cxsf, %[v]": :[v]"r" (val):);
}
void sti (void)
{
uint val;
// ok, enable paging using read/modify/write
asm("MRS %[v], cpsr": [v]"=r" (val)::);
val &= ~DIS_INT;
asm("MSR cpsr_cxsf, %[v]": :[v]"r" (val):);
}
// return the cpsr used for user program
uint spsr_usr ()
{
uint val;
// ok, enable paging using read/modify/write
asm("MRS %[v], cpsr": [v]"=r" (val)::);
val &= ~MODE_MASK;
val |= USR_MODE;
return val;
}
// return whether interrupt is currently enabled
int int_enabled ()
{
uint val;
// ok, enable paging using read/modify/write
asm("MRS %[v], cpsr": [v]"=r" (val)::);
return !(val & DIS_INT);
}
// Pushcli/popcli are like cli/sti except that they are matched:
// it takes two popcli to undo two pushcli. Also, if interrupts
// are off, then pushcli, popcli leaves them off.
void pushcli (void)
{
int enabled;
enabled = int_enabled();
cli();
if (cpu->ncli++ == 0) {
cpu->intena = enabled;
}
}
void popcli (void)
{
if (int_enabled()) {
panic("popcli - interruptible");
}
if (--cpu->ncli < 0) {
cprintf("cpu (%d)->ncli: %d\n", cpu, cpu->ncli);
panic("popcli -- ncli < 0");
}
if ((cpu->ncli == 0) && cpu->intena) {
sti();
}
}
// Record the current call stack in pcs[] by following the call chain.
// In ARM ABI, the function prologue is as:
// push {fp, lr}
// add fp, sp, #4
// so, fp points to lr, the return address
void getcallerpcs (void * v, uint pcs[])
{
uint *fp;
int i;
fp = (uint*) v;
for (i = 0; i < N_CALLSTK; i++) {
if ((fp == 0) || (fp < (uint*) KERNBASE) || (fp == (uint*) 0xffffffff)) {
break;
}
fp = fp - 1; // points fp to the saved fp
pcs[i] = fp[1]; // saved lr
fp = (uint*) fp[0]; // saved fp
}
for (; i < N_CALLSTK; i++) {
pcs[i] = 0;
}
}
void show_callstk (char *s)
{
int i;
uint pcs[N_CALLSTK];
cprintf("%s\n", s);
getcallerpcs(get_fp(), pcs);
for (i = N_CALLSTK - 1; i >= 0; i--) {
cprintf("%d: 0x%x\n", i + 1, pcs[i]);
}
}