]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/drivers/ppc32/processor-ppc32.cpp
1b04dbf8081d6ab9f31f74110e27efa597286ca2
[l4.git] / kernel / fiasco / src / drivers / ppc32 / processor-ppc32.cpp
1 #include "types.h"
2 #include "msr.h"
3
4 IMPLEMENTATION [ppc32]:
5
6 EXTENSION class Proc
7 {
8 public:
9   //disable power savings mode
10  static Mword wake(Mword);
11  static unsigned cpu_id();
12 };
13
14 /// Unblock external inetrrupts
15 IMPLEMENT static inline
16 void Proc::sti()
17 {
18   Msr::set_msr_bit(Msr::Msr_ee);
19 }
20
21 /// Block external interrupts
22 IMPLEMENT static inline
23 void Proc::cli()
24 {
25   Msr::clear_msr_bit(Msr::Msr_ee);
26 }
27
28 /// Are external interrupts enabled ?
29 IMPLEMENT static inline
30 Proc::Status Proc::interrupts()
31 {
32   return (Status)Msr::read_msr() & Msr::Msr_ee;
33 }
34
35 /// Block external interrupts and save the old state
36 IMPLEMENT static inline
37 Proc::Status Proc::cli_save()
38 {
39   Status ret = Msr::read_msr();
40   Proc::cli();
41   return ret;
42 }
43
44 /// Conditionally unblock external interrupts
45 IMPLEMENT static inline
46 void Proc::sti_restore(Status status)
47 {
48   asm volatile ( "  mtmsr  %[status]                \n"
49                  :
50                  : [status] "r" (status)
51                  );
52 }
53
54 IMPLEMENT static inline
55 void Proc::pause()
56 {
57 }
58
59 IMPLEMENT static inline
60 void Proc::halt()
61 {
62   //enable interrupt and power saving mode in msr and wait for timer
63   //exception
64   Msr::set_msr_bit(Msr::Msr_ee | Msr::Msr_pow);
65   while(Msr::read_msr() & Msr::Msr_pow)
66     ;
67 }
68
69 IMPLEMENT static inline
70 Mword Proc::wake(Mword srr1)
71 {
72   return srr1 & ~(Msr::Msr_ee | Msr::Msr_pow);
73 }
74
75 IMPLEMENT static inline
76 void Proc::irq_chance()
77 {
78   asm volatile ("nop; nop;" : : :  "memory");
79 }
80
81 IMPLEMENT static inline
82 void Proc::stack_pointer(Mword sp)
83 {
84   asm volatile ( " mr %%r1, %0 \n"
85                  : : "r" (sp)
86                  );
87 }
88
89 IMPLEMENT static inline
90 Mword Proc::stack_pointer()
91 {
92   Mword sp;
93   asm volatile ( " mr %0, %%r1  \n"
94                  : "=r" (sp)
95                  );
96   return sp;
97 }
98
99 IMPLEMENT static inline
100 Mword Proc::program_counter()
101 {
102   Mword pc;
103   asm volatile ( " mflr %%r5 \n"
104                  " bl   1f   \n"
105                  "  1:       \n"
106                  " mflr %0   \n"
107                  " mtlr %%r5 \n"
108                  : "=r" (pc) : : "r5");
109   return pc;
110 }
111
112 IMPLEMENTATION [ppc32 && !mpcore]:
113
114 IMPLEMENT static inline
115 unsigned Proc::cpu_id()
116 { return 0; }
117
118