]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/sparc/cpu-sparc.cpp
c3c1f66fc43614627f203a808fda72b986294a13
[l4.git] / kernel / fiasco / src / kern / sparc / cpu-sparc.cpp
1 INTERFACE [sparc]:
2
3 #include "per_cpu_data.h"
4 #include "types.h"
5
6 EXTENSION class Cpu
7 {
8 public:
9   void init(bool is_boot_cpu = false);
10   static void early_init();
11
12   static Per_cpu<Cpu> cpus;
13   static Cpu *boot_cpu() { return _boot_cpu; }
14
15   Cpu(unsigned cpu) { set_id(cpu); }
16
17 private:
18   static Cpu *_boot_cpu;
19   unsigned _phys_id;
20   static unsigned long _ns_per_cycle;
21
22 };
23
24 namespace Segment
25 {
26   enum Attribs_enum
27   {
28     Ks = 1UL << 30,
29     Kp = 1UL << 29,
30     N  = 1UL << 28,
31     Default_attribs = Kp //Ks | Kp,
32   };
33 };
34 //------------------------------------------------------------------------------
35 IMPLEMENTATION [sparc]:
36
37 #include "panic.h"
38 #include "boot_info.h"
39 #include "psr.h"
40
41 #include <cstdio>
42
43 DEFINE_PER_CPU Per_cpu<Cpu> Cpu::cpus(true);
44 Cpu *Cpu::_boot_cpu;
45 unsigned long Cpu::_ns_per_cycle;
46
47 IMPLEMENT
48 void
49 Cpu::init(bool is_boot_cpu)
50 {
51   if (is_boot_cpu)
52     {
53       _boot_cpu = this;
54       set_online(1);
55     }
56   _phys_id = 0; //Proc::cpu_id();
57   _ns_per_cycle = 0; //1000000000 / Boot_info::get_time_base();
58   //printf("Timebase: %lu\n", Boot_info::get_time_base());
59 }
60
61 PUBLIC inline
62 unsigned
63 Cpu::phys_id() const
64 { return _phys_id; }
65
66 IMPLEMENT
67 void
68 Cpu::early_init()
69 {
70 }
71
72 PUBLIC static inline
73 Mword
74 Cpu::read_vsid(unsigned sr = 0)
75 {
76   Mword vsid;
77   (void)sr;
78
79   return (vsid & 0xffffff);
80 }
81
82 /* set segment register 0-15 */
83 PUBLIC static inline //NEEDS["paging.h"]
84 void
85 Cpu::set_vsid(Mword vsid)
86 {
87   vsid |= Segment::Default_attribs;
88 }
89
90 PUBLIC static inline
91 Mword
92 Cpu::stack_align(Mword stack)
93 { return stack & ~0xf; }
94
95 PUBLIC static inline
96 bool
97 Cpu::have_superpages()
98 { return true; }
99
100 //------------------------------------------------------------------------------
101 /* Time functions */
102
103 /**
104  * Read time base registers 
105  */
106 PUBLIC static inline
107 Unsigned64
108 Cpu::rdtsc()
109 {
110   Unsigned32 tb_upper, tb_lower;
111   Unsigned64 tb;
112   tb = tb_upper;
113   return (tb << 32) | tb_lower;
114 }
115
116 PUBLIC static inline
117 void
118 Cpu::busy_wait_ns(Unsigned64 ns)
119 {
120   Unsigned64 stop = rdtsc() + ns_to_tsc(ns);
121
122   while(rdtsc() <  stop) 
123     ;
124 }
125
126 PUBLIC static inline
127 Unsigned64
128 Cpu::ns_to_tsc(Unsigned64 ns)
129 {
130   return ns / _ns_per_cycle;
131 }
132
133 PUBLIC static inline
134 Unsigned64
135 Cpu::tsc_to_ns(Unsigned64 tsc)
136 {
137   return tsc * _ns_per_cycle;
138 }
139
140 PUBLIC static inline
141 Unsigned32
142 Cpu::get_scaler_tsc_to_ns()
143 { return 0; }
144
145 PUBLIC static inline
146 Unsigned32
147 Cpu::get_scaler_tsc_to_us() 
148 { return 0; }
149
150 PUBLIC static inline
151 Unsigned32 
152 Cpu::get_scaler_ns_to_tsc() 
153 { return 0; }
154
155 PUBLIC static inline
156 bool
157 Cpu::tsc()
158 { return 0; }
159
160 //------------------------------------------------------------------------------
161 /* Unimplemented */
162
163 PUBLIC static inline
164 void
165 Cpu::debugctl_enable()
166 {}
167
168 PUBLIC static inline
169 void
170 Cpu::debugctl_disable()
171 {}
172