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