]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/mem_layout-ia32.cpp
update
[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   static Address _io_map_ptr;
9 };
10
11 IMPLEMENTATION [ia32 || amd64 || ux]:
12
13 #include "static_assert.h"
14
15 Address Mem_layout::_io_map_ptr = Mem_layout::Io_map_area_end;
16
17 PUBLIC static inline
18 Address
19 Mem_layout::alloc_io_vmem(unsigned long bytes)
20 {
21   bytes = (bytes + Config::PAGE_SIZE - 1) & ~(Config::PAGE_SIZE - 1);
22   if (_io_map_ptr - bytes < Io_map_area_start)
23     return 0;
24
25   _io_map_ptr -= bytes;
26   return _io_map_ptr;
27 }
28
29 PUBLIC static inline NEEDS["static_assert.h"]
30 template< typename V >
31 bool
32 Mem_layout::read_special_safe(V const *address, V &v)
33 {
34   static_assert(sizeof(v) <= sizeof(Mword), "wrong sized argument");
35   Mword value;
36   bool res;
37   asm volatile ("clc; mov (%[adr]), %[val]; setnc %b[ex] \n"
38       : [val] "=acd" (value), [ex] "=r" (res)
39       : [adr] "acdbSD" (address)
40       : "cc");
41   v = V(value);
42   return res;
43 }
44
45 PUBLIC static inline NEEDS["static_assert.h"]
46 template< typename T >
47 T
48 Mem_layout::read_special_safe(T const *a)
49 {
50   static_assert(sizeof(T) <= sizeof(Mword), "wrong sized return type");
51   Mword res;
52   asm volatile ("mov (%1), %0 \n\t"
53       : "=acd" (res) : "acdbSD" (a) : "cc");
54   return T(res);
55
56 }
57
58 PUBLIC static inline
59 bool
60 Mem_layout::is_special_mapped(void const *a)
61 {
62   // Touch the state to page in the TCB. If we get a pagefault here,
63   // the handler doesn't handle it but returns immediatly after
64   // setting eax to 0xffffffff
65   Mword pagefault_if_0;
66   asm volatile (
67       "clc; mov (%2), %0 \n\t"
68       "setnc %b0         \n\t"
69       : "=acd" (pagefault_if_0)
70       : "0"(0UL), "acdbSD"(a)
71       : "cc");
72   return pagefault_if_0;
73 }
74