-
Notifications
You must be signed in to change notification settings - Fork 4
/
thread.h
209 lines (186 loc) · 7.1 KB
/
thread.h
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (c) 2016 Leonid Yegoshin
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _THREAD_H
#define _THREAD_H
//#include "mips.h"
#include "vmdev.h"
struct exception_frame {
// SP/FP: common block
struct exception_frame *next;
// CP0 - insert by pairs, for double alignment
unsigned int cp0_context;
unsigned int cp0_cause;
unsigned int cp0_epc;
unsigned int cp0_srsctl;
unsigned int cp0_guestctl0;
unsigned int cp0_status;
unsigned int cp0_badvaddr;
unsigned int cp0_badinst;
unsigned int cp0_badinstp;
unsigned int cp0_nested_epc;
unsigned int cp0_nested_exc;
unsigned int lo;
unsigned int hi;
unsigned int gpr[32];
};
struct thread {
struct exception_frame exfr;
double fpr[32];
unsigned int fcr31;
unsigned int dspcontrol;
unsigned long dspr[6];
unsigned int gid;
unsigned int srs;
unsigned int tid;
unsigned int thread_flags;
unsigned int preempt_count;
unsigned int reschedule_count;
unsigned int waiting_irq_number;
int injected_irq;
unsigned int injected_ipl;
int interrupted_irq;
unsigned int last_interrupted_irq;
unsigned int interrupted_ipl;
int exception_cause;
int exception_gcause;
unsigned int cp0_entryhi;
unsigned int cp0_guestctl0ext;
unsigned int cp0_guestctl1;
unsigned int cp0_guestctl2;
unsigned int cp0_guestctl3;
unsigned int cp0_gtoffset;
struct vmdev vmdev;
unsigned int g_cp0_index;
//// unsigned int g_cp0_random;
unsigned int g_cp0_entrylo0;
unsigned int g_cp0_entrylo1;
unsigned int g_cp0_context;
//unsigned int g_cp0_contextconfig;
unsigned int g_cp0_userlocal;
//// unsigned int g_cp0_xcontextconfig;
unsigned int g_cp0_pagemask;
unsigned int g_cp0_pagegrain;
//unsigned int g_cp0_segctl0;
//unsigned int g_cp0_segctl1;
//unsigned int g_cp0_segctl2;
//unsigned int g_cp0_pwbase;
//unsigned int g_cp0_pwfield;
//unsigned int g_cp0_pwsize;
unsigned int g_cp0_wired;
//unsigned int g_cp0_pwctl;
unsigned int g_cp0_hwrena;
unsigned int g_cp0_badvaddr;
unsigned int g_cp0_badinst;
unsigned int g_cp0_badinstp;
unsigned int g_cp0_count;
unsigned int g_cp0_entryhi;
unsigned int g_cp0_compare;
unsigned int g_cp0_status;
unsigned int g_cp0_intctl;
unsigned int g_cp0_srsctl;
unsigned int g_cp0_srsmap;
unsigned int g_cp0_srsmap2;
unsigned int g_cp0_cause;
unsigned int g_cp0_nested_exc;
unsigned int g_cp0_epc;
unsigned int g_cp0_nested_epc;
unsigned int g_cp0_prid;
unsigned int g_cp0_ebase;
unsigned int g_cp0_cdmmbase;
//unsigned int g_cp0_cmgcrbase;
unsigned int g_cp0_config;
unsigned int g_cp0_config1;
unsigned int g_cp0_config2;
unsigned int g_cp0_config3;
unsigned int g_cp0_config4;
unsigned int g_cp0_config5;
unsigned int g_cp0_config6;
unsigned int g_cp0_config7;
// unsigned int g_cp0_lladdr;
// unsigned int g_cp0_maar[6];
// unsigned int g_cp0_maari;
// unsigned int g_cp0_watchlo;
// unsigned int g_cp0_watchhi;
//// unsigned int g_cp0_xcontext;
// ... security ???
unsigned int g_cp0_debug;
unsigned int g_cp0_depc;
unsigned int g_cp0_perfcnt[7];
unsigned int g_cp0_errctl;
unsigned int g_cp0_cacherr;
unsigned int g_cp0_tagdatalo[4];
unsigned int g_cp0_tagdatahi[4];
unsigned int g_cp0_errorepc;
unsigned int g_cp0_desave;
unsigned int g_cp0_kscratch0;
unsigned int g_cp0_kscratch1;
//unsigned int g_cp0_kscratch[4];
unsigned int g_cp0_wired_hi[63];
unsigned int g_cp0_wired_lo0[63];
unsigned int g_cp0_wired_lo1[63];
unsigned int g_cp0_wired_pm[63];
unsigned int time_late_counter;
unsigned long long last_used_lcount;
unsigned long long lcompare;
unsigned long long lcount2read;
};
#define THREAD_FRAME_SIZE ((sizeof(struct thread) + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE-1))
//#define VM_FRAME_SIZE ((sizeof(struct thread) + 0x7ff) & ~0x7ff)
#define THREAD_FLAGS_RUNNING 0x00000001
#define THREAD_FLAGS_STOPPED 0x00000002
#define THREAD_FLAGS_DEBUG 0x00000004
#define THREAD_FLAGS_EXCTRACE 0x00000008
#define THREAD_FLAGS_INTTRACE 0x00000010
#define THREAD_FLAGS_TIMETRACE 0x00000020
#define THREAD_FLAGS_CHRONIC 0x00000040
#define is_exc_trace() ((current->thread_flags & (THREAD_FLAGS_DEBUG|THREAD_FLAGS_EXCTRACE)) == \
(THREAD_FLAGS_DEBUG|THREAD_FLAGS_EXCTRACE))
#define is_int_trace() ((current->thread_flags & (THREAD_FLAGS_DEBUG|THREAD_FLAGS_INTTRACE)) == \
(THREAD_FLAGS_DEBUG|THREAD_FLAGS_INTTRACE))
#define is_time_trace() ((current->thread_flags & (THREAD_FLAGS_DEBUG|THREAD_FLAGS_TIMETRACE)) == \
(THREAD_FLAGS_DEBUG|THREAD_FLAGS_TIMETRACE))
register struct thread * current __asm__("$30");
static void inline preempt_disable(void)
{
current->preempt_count++;
}
static void inline preempt_enable(void)
{
current->preempt_count--;
}
extern unsigned int fpu_owner;
extern unsigned int dsp_owner;
#define is_fpu_owner() (fpu_owner == current->tid)
#define fpu_get_fcr31() read_cp1_fcr31()
extern unsigned const vm_sp[];
extern unsigned const vm_list[];
extern unsigned const vm_options[];
#define VM_OPTION_POLLING 0x00000001
#define VM_OPTION_KSU 0x00000018
extern unsigned long vm0_thread;
#define get_thread_fp(tid) ((struct thread *)(vm0_thread - ((tid) * THREAD_FRAME_SIZE)))
extern void IRQ_nonexc_exit(void);
extern unsigned int reschedule_flag;
extern unsigned int reschedule_thread;
extern void switch_to_thread(struct exception_frame *exfr, unsigned int tid);
#endif