]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/continuation-ia32-32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / 32 / continuation-ia32-32.cpp
1 INTERFACE[ia32]:
2
3 #include "entry_frame.h"
4 #include "gdt.h"
5 #include "member_offs.h"
6 #include "regdefs.h"
7 #include "types.h"
8
9 class Continuation
10 {
11   MEMBER_OFFSET();
12
13 private:
14   Address _ip;
15   Mword   _flags;
16
17 public:
18   Continuation() : _ip(~0UL) {}
19
20   typedef Return_frame User_return_frame;
21
22   bool valid() const
23   { return _ip != ~0UL; }
24
25   Address ip() const { return _ip; }
26   void ip(Address ip) { _ip = ip; }
27
28   Mword flags(Return_frame const *) const { return _flags; }
29   void flags(Return_frame *, Mword flags) { _flags = flags; }
30
31   Mword sp(Return_frame const *o) const { return o->sp(); }
32   void sp(Return_frame *o, Mword sp) { o->sp(sp); }
33
34   void save(Return_frame const *regs)
35   {
36     _ip  = regs->ip();
37     _flags = regs->flags();
38     // LOG_MSG_3VAL(current(), "sav", _ip, _flags, 0);
39   }
40
41   void activate(Return_frame *regs, void *cont_func)
42   {
43     save(regs);
44     regs->ip(Mword(cont_func));
45     // interrupts must stay off, do not singlestep in kernel code
46     regs->flags(regs->flags() & ~(EFLAGS_TF | EFLAGS_IF));
47     regs->cs(Gdt::gdt_code_kernel | Gdt::Selector_kernel);
48     // LOG_MSG_3VAL(current(), "act", regs->ip(), regs->flags(), regs->cs());
49   }
50
51   void set(Return_frame *dst, User_return_frame const *src)
52   {
53     _ip = src->ip();
54     _flags = src->flags();
55     dst->sp(src->sp());
56   }
57
58   void get(User_return_frame *dst, Return_frame const *src) const
59   {
60     dst->ip(_ip);
61     dst->flags(_flags);
62     dst->sp(src->sp());
63   }
64
65   void clear() { _ip = ~0UL; }
66
67   void restore(Return_frame *regs)
68   {
69     // LOG_MSG_3VAL(current(), "rst", _ip, _flags, 0);
70     regs->ip(_ip);
71     regs->flags(_flags);
72     regs->cs(Gdt::gdt_code_user | Gdt::Selector_user);
73     clear();
74   }
75
76 };
77