]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/mem_layout-ia32.cpp
a2152b0319fbaa7eee93eba0f47b417fd383d32e
[l4.git] / kernel / fiasco / src / kern / ia32 / mem_layout-ia32.cpp
1 INTERFACE [ia32 || amd64 || ux]:
2
3 EXTENSION class Mem_layout
4 {
5 public:
6   enum { Io_port_max = (1UL << 16) };
7 };
8
9 IMPLEMENTATION [ia32 || amd64 || ux]:
10
11 #include "static_assert.h"
12
13 PUBLIC static inline NEEDS["static_assert.h"]
14 template< typename V >
15 bool
16 Mem_layout::read_special_safe(V const *address, V &v)
17 {
18   static_assert(sizeof(v) <= sizeof(Mword), "wrong sized argument");
19   Mword value;
20   bool res;
21   asm volatile ("clc; mov (%[adr]), %[val]; setnc %b[ex] \n"
22       : [val] "=acd" (value), [ex] "=r" (res)
23       : [adr] "acdbSD" (address)
24       : "cc");
25   v = V(value);
26   return res;
27 }
28
29 PUBLIC static inline NEEDS["static_assert.h"]
30 template< typename T >
31 T
32 Mem_layout::read_special_safe(T const *a)
33 {
34   static_assert(sizeof(T) <= sizeof(Mword), "wrong sized return type");
35   Mword res;
36   asm volatile ("mov (%1), %0 \n\t"
37       : "=acd" (res) : "acdbSD" (a) : "cc");
38   return T(res);
39
40 }
41
42 PUBLIC static inline
43 bool
44 Mem_layout::is_special_mapped(void const *a)
45 {
46   // Touch the state to page in the TCB. If we get a pagefault here,
47   // the handler doesn't handle it but returns immediatly after
48   // setting eax to 0xffffffff
49   Mword pagefault_if_0;
50   asm volatile (
51       "clc; mov (%2), %0 \n\t"
52       "setnc %b0         \n\t"
53       : "=acd" (pagefault_if_0)
54       : "0"(0UL), "acdbSD"(a)
55       : "cc");
56   return pagefault_if_0;
57 }
58