1 | /** |
---|
2 | * \file cpu.h |
---|
3 | * \date March 10, 2014 |
---|
4 | * \author Cesar Fuguet |
---|
5 | * \brief MIPS32 processor core function definitions |
---|
6 | */ |
---|
7 | #ifndef _CPU_H |
---|
8 | #define _CPU_H |
---|
9 | |
---|
10 | #include <stdint.h> |
---|
11 | #include <hard_config.h> |
---|
12 | |
---|
13 | #define CLUSTER(x,y) (((x) << Y_WIDTH) | (y)) |
---|
14 | #define CLUSTER_ID_BITS (X_WIDTH + Y_WIDTH) |
---|
15 | #define CLUSTER_OFFSET_BITS (40-CLUSTER_ID_BITS) |
---|
16 | |
---|
17 | /* |
---|
18 | * Inline functions definition |
---|
19 | */ |
---|
20 | static inline unsigned int cpu_procid() |
---|
21 | { |
---|
22 | register uint32_t ret asm("v0"); |
---|
23 | asm volatile ("mfc0 %[ret], $15,1" : [ret] "=r"(ret)); |
---|
24 | return (ret & 0x3FF); |
---|
25 | } |
---|
26 | |
---|
27 | static inline unsigned int cpu_cluster() |
---|
28 | { |
---|
29 | return (cpu_procid() / NB_PROCS_MAX); |
---|
30 | } |
---|
31 | |
---|
32 | static inline unsigned int cpu_x() |
---|
33 | { |
---|
34 | return (cpu_cluster() >> Y_WIDTH); |
---|
35 | } |
---|
36 | |
---|
37 | static inline unsigned int cpu_y() |
---|
38 | { |
---|
39 | return (cpu_cluster() & ((1 << X_WIDTH) - 1)); |
---|
40 | } |
---|
41 | |
---|
42 | static inline unsigned int cpu_l() |
---|
43 | { |
---|
44 | return (cpu_procid() % NB_PROCS_MAX); |
---|
45 | } |
---|
46 | |
---|
47 | static inline unsigned int cpu_time() |
---|
48 | { |
---|
49 | register uint32_t ret asm("v0"); |
---|
50 | asm volatile ("mfc0 %[ret], $9,0" : [ret] "=r"(ret)); |
---|
51 | return ret; |
---|
52 | }; |
---|
53 | |
---|
54 | static inline unsigned int cpu_get_sp() |
---|
55 | { |
---|
56 | register unsigned int ret asm("v0"); |
---|
57 | asm volatile ("move %[ret], $29" : [ret] "=r"(ret)); |
---|
58 | return ret; |
---|
59 | } |
---|
60 | |
---|
61 | static inline void cpu_set_sp(uint32_t sp) |
---|
62 | { |
---|
63 | asm volatile ("move $29, %[addr] \n" |
---|
64 | : /* no output */ |
---|
65 | : [addr] "r"(sp) |
---|
66 | : "memory"); |
---|
67 | } |
---|
68 | |
---|
69 | static inline void cpu_wait() |
---|
70 | { |
---|
71 | asm volatile ("wait"); |
---|
72 | } |
---|
73 | |
---|
74 | static inline void cpu_sync() |
---|
75 | { |
---|
76 | asm volatile ("sync":::"memory"); |
---|
77 | } |
---|
78 | |
---|
79 | static inline void cpu_sleep(uint32_t cycles) |
---|
80 | { |
---|
81 | asm volatile (".set noreorder \n" |
---|
82 | "1: \n" |
---|
83 | "bnez %[c], 1b \n" |
---|
84 | "addiu %[c], %[c], -1 \n" |
---|
85 | ".set reorder \n" |
---|
86 | : /* no output */ |
---|
87 | : [c] "r"(cycles)); |
---|
88 | } |
---|
89 | |
---|
90 | static inline void cpu_set_ptpr(uint32_t ptpr) |
---|
91 | { |
---|
92 | asm volatile ("mtc2 %[ptpr], $0\n" |
---|
93 | : /* no output */ |
---|
94 | : [ptpr] "r"(ptpr) |
---|
95 | : "memory"); |
---|
96 | } |
---|
97 | |
---|
98 | static inline uint32_t cpu_get_ptpr() |
---|
99 | { |
---|
100 | register uint32_t ret asm("v0"); |
---|
101 | asm volatile ("mfc2 %[ret], $0\n" : [ret] "=r"(ret)); |
---|
102 | return ret; |
---|
103 | } |
---|
104 | |
---|
105 | static inline uint32_t cpu_get_mmu_detr() |
---|
106 | { |
---|
107 | register uint32_t ret asm("v0"); |
---|
108 | asm volatile ("mfc2 %[ret], $12\n" : [ret] "=r"(ret)); |
---|
109 | return ret; |
---|
110 | } |
---|
111 | |
---|
112 | static inline uint32_t cpu_get_cr_exccode() |
---|
113 | { |
---|
114 | register uint32_t ret asm("v0"); |
---|
115 | asm volatile ("mfc0 %[ret], $13\n" : [ret] "=r"(ret)); |
---|
116 | return ((ret >> 2) & 0x1F); |
---|
117 | } |
---|
118 | |
---|
119 | static inline void cpu_set_wdt_max(uint32_t max) |
---|
120 | { |
---|
121 | asm volatile ("mtc2 %[max], $26\n" |
---|
122 | : |
---|
123 | : [max] "r"(max) |
---|
124 | : "memory"); |
---|
125 | } |
---|
126 | |
---|
127 | static inline uint32_t cpu_get_wdt_max() |
---|
128 | { |
---|
129 | register uint32_t ret asm("v0"); |
---|
130 | asm volatile ("mfc2 %[ret], $12\n" : [ret] "=r"(ret)); |
---|
131 | return ret; |
---|
132 | } |
---|
133 | |
---|
134 | #endif /* _CPU_H */ |
---|
135 | |
---|
136 | /* |
---|
137 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
138 | */ |
---|