The Pedigree Project  0.1
mips_common/Processor.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_MIPS_COMMON_PROCESSOR_H
21 #define KERNEL_PROCESSOR_MIPS_COMMON_PROCESSOR_H
22 
23 #define CP0_INDEX 0
24 #define CP0_RANDOM 1
25 #define CP0_ENTRYLO0 2
26 #define CP0_ENTRYLO1 3
27 #define CP0_CONTEXT 4
28 #define CP0_PAGEMASK 5
29 #define CP0_WIRED 6
30 // 7 N'existe pas.
31 #define CP0_BADVADDR 8
32 #define CP0_COUNT 9
33 #define CP0_ENTRYHI 10
34 #define CP0_COMPARE 11
35 #define CP0_SR 12
36 #define CP0_CAUSE 13
37 #define CP0_EPC 14
38 #define CP0_PRID 15
39 #define CP0_CONFIG 16
40 #define CP0_LLADDR 17
41 #define CP0_WATCHLO 18
42 #define CP0_WATCHHI 19
43 #define CP0_ECC 26
44 #define CP0_CACHEERR 27
45 #define CP0_TAGLO 28
46 #define CP0_TAGHI 29
47 #define CP0_ERROREPC 30
48 
49 #define CP0_WRITE_INDEX(val) asm volatile("mtc0 %0, $0; nop" : : "r"(val));
50 #define CP0_WRITE_RANDOM(val) asm volatile("mtc0 %0, $1; nop" : : "r"(val));
51 #define CP0_WRITE_ENTRYLO0(val) asm volatile("mtc0 %0, $2; nop" : : "r"(val));
52 #define CP0_WRITE_ENTRYLO1(val) asm volatile("mtc0 %0, $3; nop" : : "r"(val));
53 #define CP0_WRITE_CONTEXT(val) asm volatile("mtc0 %0, $4; nop" : : "r"(val));
54 #define CP0_WRITE_PAGEMASK(val) asm volatile("mtc0 %0, $5; nop" : : "r"(val));
55 #define CP0_WRITE_WIRED(val) asm volatile("mtc0 %0, $6; nop" : : "r"(val));
56 #define CP0_WRITE_BADVADDR(val) asm volatile("mtc0 %0, $8; nop" : : "r"(val));
57 #define CP0_WRITE_COUNT(val) asm volatile("mtc0 %0, $9; nop" : : "r"(val));
58 #define CP0_WRITE_ENTRYHI(val) asm volatile("mtc0 %0, $10; nop" : : "r"(val));
59 #define CP0_WRITE_COMPARE(val) asm volatile("mtc0 %0, $11; nop" : : "r"(val));
60 #define CP0_WRITE_SR(val) asm volatile("mtc0 %0, $12; nop" : : "r"(val));
61 #define CP0_WRITE_CAUSE(val) asm volatile("mtc0 %0, $13; nop" : : "r"(val));
62 #define CP0_WRITE_EPC(val) asm volatile("mtc0 %0, $14; nop" : : "r"(val));
63 #define CP0_WRITE_PRID(val) asm volatile("mtc0 %0, $15; nop" : : "r"(val));
64 #define CP0_WRITE_CONFIG(val) asm volatile("mtc0 %0, $16; nop" : : "r"(val));
65 #define CP0_WRITE_LLADDR(val) asm volatile("mtc0 %0, $17; nop" : : "r"(val));
66 #define CP0_WRITE_WATCHLO(val) asm volatile("mtc0 %0, $18; nop" : : "r"(val));
67 #define CP0_WRITE_WATCHHI(val) asm volatile("mtc0 %0, $19; nop" : : "r"(val));
68 #define CP0_WRITE_ECC(val) asm volatile("mtc0 %0, $26; nop" : : "r"(val));
69 #define CP0_WRITE_CACHEERR(val) asm volatile("mtc0 %0, $27; nop" : : "r"(val));
70 #define CP0_WRITE_TAGLO(val) asm volatile("mtc0 %0, $28; nop" : : "r"(val));
71 #define CP0_WRITE_TAGHI(val) asm volatile("mtc0 %0, $29; nop" : : "r"(val));
72 #define CP0_WRITE_ERROREPC(val) asm volatile("mtc0 %0, $30; nop" : : "r"(val));
73 
74 #define CP0_READ_INDEX(val) asm volatile("mfc0 %0, $0; nop" : "=r"(val));
75 #define CP0_READ_RANDOM(val) asm volatile("mfc0 %0, $1; nop" : "=r"(val));
76 #define CP0_READ_ENTRYLO0(val) asm volatile("mfc0 %0, $2; nop" : "=r"(val));
77 #define CP0_READ_ENTRYLO1(val) asm volatile("mfc0 %0, $3; nop" : "=r"(val));
78 #define CP0_READ_CONTEXT(val) asm volatile("mfc0 %0, $4; nop" : "=r"(val));
79 #define CP0_READ_PAGEMASK(val) asm volatile("mfc0 %0, $5; nop" : "=r"(val));
80 #define CP0_READ_WIRED(val) asm volatile("mfc0 %0, $6; nop" : "=r"(val));
81 #define CP0_READ_BADVADDR(val) asm volatile("mfc0 %0, $8; nop" : "=r"(val));
82 #define CP0_READ_COUNT(val) asm volatile("mfc0 %0, $9; nop" : "=r"(val));
83 #define CP0_READ_ENTRYHI(val) asm volatile("mfc0 %0, $10; nop" : "=r"(val));
84 #define CP0_READ_COMPARE(val) asm volatile("mfc0 %0, $11; nop" : "=r"(val));
85 #define CP0_READ_SR(val) asm volatile("mfc0 %0, $12; nop" : "=r"(val));
86 #define CP0_READ_CAUSE(val) asm volatile("mfc0 %0, $13; nop" : "=r"(val));
87 #define CP0_READ_EPC(val) asm volatile("mfc0 %0, $14; nop" : "=r"(val));
88 #define CP0_READ_PRID(val) asm volatile("mfc0 %0, $15; nop" : "=r"(val));
89 #define CP0_READ_CONFIG(val) asm volatile("mfc0 %0, $16; nop" : "=r"(val));
90 #define CP0_READ_LLADDR(val) asm volatile("mfc0 %0, $17; nop" : "=r"(val));
91 #define CP0_READ_WATCHLO(val) asm volatile("mfc0 %0, $18; nop" : "=r"(val));
92 #define CP0_READ_WATCHHI(val) asm volatile("mfc0 %0, $19; nop" : "=r"(val));
93 #define CP0_READ_ECC(val) asm volatile("mfc0 %0, $26; nop" : "=r"(val));
94 #define CP0_READ_CACHEERR(val) asm volatile("mfc0 %0, $27; nop" : "=r"(val));
95 #define CP0_READ_TAGLO(val) asm volatile("mfc0 %0, $28; nop" : "=r"(val));
96 #define CP0_READ_TAGHI(val) asm volatile("mfc0 %0, $29; nop" : "=r"(val));
97 #define CP0_READ_ERROREPC(val) asm volatile("mfc0 %0, $30; nop" : "=r"(val));
98 
99 #define SR_IE (1 << 0)
100 #define SR_EXL (1 << 1)
101 #define SR_ERL (1 << 2)
102 // TODO The rest...
103 
105 {
106  asm volatile("break");
107 }
108 
109 void Processor::halt()
110 {
111  // TODO: gcc will most certainly optimize this away in -O1/2/3 so please
112  // replace it with some unoptimizable mighty magic
113  for (;;)
114  ;
115 }
116 
117 #endif
static void halt()
static void breakpoint()