]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/cpu_lock-pic.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / cpu_lock-pic.cpp
1 INTERFACE[ia32,amd64]:
2
3 /**
4  * A special CPU lock, that disables IRQ's via the PIC.
5  */
6 EXTENSION class Cpu_lock
7 {
8 private:
9   Unsigned32 pic_status; ///< The save PIC mask.
10   Status _is_set;        ///< The current state of the lock.
11 };
12
13
14 IMPLEMENTATION[ia32,amd64]:
15
16 #include "config.h"
17 #include "pic.h"
18 #include "processor.h"
19
20 // 
21 // Cpu_lock inlines
22 // 
23
24 IMPLEMENT inline
25 Cpu_lock::Cpu_lock() 
26   : _is_set(0)
27 {
28 }
29
30 IMPLEMENT inline NEEDS ["config.h","processor.h","pic.h"]
31 void Cpu_lock::lock()
32 {
33   // When profiling, we use a sligtly different strategy: Instead of
34   // disabling interrupts in the CPU, we disable all interrupts but the
35   // profiling timer interrupt in the PIC.
36   Proc::cli();
37   if (! _is_set)
38     {
39       // mask out all irqs except the profiling timer interrupt
40       pic_status = Pic::disable_all_save();
41       if(Config::profiling)
42         Pic::enable_locked(Config::profile_irq);
43       _is_set = 1;
44     }
45   Proc::sti();
46   Proc::irq_chance();   // last chance for an irq to be delivered
47 }
48
49
50 /** 
51  * (IA32 only) Clear the kernel lock, but disable interrupts.
52  * There is a difference betweeen ``kernel lock'' and ``disabled interrupts''
53  * if the kernel lock is not implemented using CPU-interrupt disabling
54  * (but, for example, IRQ disabling in the PIC).
55  */
56 PUBLIC inline NEEDS ["processor.h", "pic.h"]
57 void Cpu_lock::clear_irqdisable()
58 {
59   Proc::cli();
60   if (_is_set)
61     {
62       Pic::restore_all(pic_status);
63       _is_set = 0;
64     }
65 }
66
67 IMPLEMENT inline NEEDS ["processor.h",Cpu_lock::clear_irqdisable]
68 void Cpu_lock::clear()
69 {
70   clear_irqdisable();
71   Proc::sti();
72 }
73
74 IMPLEMENT inline 
75 Cpu_lock::Status Cpu_lock::test() const
76 {
77   return _is_set;
78 }