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