]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/drivers/sparc/processor-sparc.cpp
001d0c8f730af8d07f0a015cda453a097ecdae50
[l4.git] / kernel / fiasco / src / drivers / sparc / processor-sparc.cpp
1 #include "types.h"
2 #include "psr.h"
3 #include "processor.h"
4
5 IMPLEMENTATION [sparc]:
6
7 EXTENSION class Proc
8 {
9 public:
10   //disable power savings mode
11  static Mword wake(Mword);
12  static unsigned cpu_id();
13 };
14
15 /// Unblock external interrupts
16 IMPLEMENT static inline
17 void Proc::sti()
18 {
19   unsigned p = Psr::read();
20   p &= ~(0xF << Psr::Interrupt_lvl);
21   Psr::write(p);
22 }
23
24 /// Block external interrupts
25 IMPLEMENT static inline
26 void Proc::cli()
27 {
28   unsigned p = Psr::read();
29   p |= (0xF << Psr::Interrupt_lvl);
30   Psr::write(p);
31 }
32
33 /// Are external interrupts enabled ?
34 IMPLEMENT static inline
35 Proc::Status Proc::interrupts()
36 {
37   return Psr::read() & (0xF << Psr::Interrupt_lvl);
38 }
39
40 /// Block external interrupts and save the old state
41 IMPLEMENT static inline
42 Proc::Status Proc::cli_save()
43 {
44   Status ret = Psr::read();
45   Proc::cli();
46   return ret;
47 }
48
49 /// Conditionally unblock external interrupts
50 IMPLEMENT static inline
51 void Proc::sti_restore(Status status)
52 {
53   (void)status;
54   Psr::write(status);
55 }
56
57 IMPLEMENT static inline
58 void Proc::pause()
59 {
60   // XXX
61 }
62
63 IMPLEMENT static inline
64 void Proc::halt()
65 {
66   // XXX
67   asm volatile ("ta 0\n");
68 }
69
70 IMPLEMENT static inline
71 Mword Proc::wake(Mword srr1)
72 {
73   (void)srr1;
74   return 0; // XXX
75 }
76
77 IMPLEMENT static inline
78 void Proc::irq_chance()
79 {
80   // XXX?
81   asm volatile ("nop; nop;" : : :  "memory");
82 }
83
84 IMPLEMENT static inline
85 void Proc::stack_pointer(Mword sp)
86 {
87   (void)sp;
88   asm volatile ("mov %0, %%sp\n" : : "r"(sp));
89 }
90
91 IMPLEMENT static inline
92 Mword Proc::stack_pointer()
93 {
94   Mword sp = 0;
95   asm volatile ("mov %%sp, %0\n" : "=r" (sp));
96   return sp;
97 }
98
99 IMPLEMENT static inline
100 Mword Proc::program_counter()
101 {
102   Mword pc = 0;
103   asm volatile ("call 1\n\t"
104                 "nop\n\t" // delay instruction
105                 "1: mov %%o7, %0\n\t"
106                 : "=r" (pc) : : "o7");
107   return pc;
108 }
109
110 PUBLIC static inline
111 template <int ASI>
112 Mword Proc::read_alternative(Mword reg)
113 {
114         Mword ret;
115         asm volatile("lda [%1] %2, %0"
116                                   : "=r" (ret)
117                                   : "r" (reg),
118                                     "i" (ASI));
119         return ret;
120
121 }
122
123 PUBLIC static inline
124 template <int ASI>
125 void Proc::write_alternative(Mword reg, Mword value)
126 {
127         asm volatile ("sta %0, [%1] %2\n\t"
128                                   :
129                                   : "r"(value),
130                                     "r"(reg),
131                                     "i"(ASI));
132 }
133
134
135 IMPLEMENTATION [sparc && !mpcore]:
136
137 IMPLEMENT static inline
138 unsigned Proc::cpu_id()
139 { return 0; }
140
141