]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/mem_layout-ia32-32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / 32 / mem_layout-ia32-32.cpp
1 INTERFACE [ia32]:
2
3 #include "types.h"
4 #include "config.h"
5 #include "linking.h"
6
7 EXTENSION class Mem_layout
8 {
9 public:
10   enum Flags
11   {
12     /// Is the adapter memory in the kernel image super page?
13     Adap_in_kernel_image = FIASCO_IMAGE_PHYS_START < Config::SUPERPAGE_SIZE,
14   };
15
16   enum
17   {
18     Utcb_addr         = 0xbff00000,    ///< % 4KB   UTCB map address
19     Kip_auto_map      = 0xbfff2000,    ///< % 4KB
20     User_max          = 0xc0000000,
21     Slabs_start       = 0xe0000000,    ///<         multipage slabs
22     Slabs_end         = 0xea000000,    ///<         slabs_start + 160MB
23     Space_index       = 0xea000000,    ///< % 4MB
24     Service_page      = 0xeac00000,    ///< % 4MB   global mappings
25     Local_apic_page   = Service_page + 0x0000,   ///< % 4KB
26     Kmem_tmp_page_1   = Service_page + 0x2000,   ///< % 4KB size 8KB
27     Kmem_tmp_page_2   = Service_page + 0x4000,   ///< % 4KB size 8KB
28     Tbuf_status_page  = Service_page + 0x6000,   ///< % 4KB
29     Tbuf_ustatus_page = Tbuf_status_page,
30     Jdb_bench_page    = Service_page + 0x8000,   ///< % 4KB
31     Jdb_bts_area      = Service_page + 0xf000,   ///< % 4KB size 0x81000
32     Utcb_ptr_page     = Service_page + 0xfd000,  ///< % 4KB
33     Utcb_ptr_offset   = 0,
34     Idt               = Service_page + 0xfe000,  ///< % 4KB
35     Syscalls          = Service_page + 0xff000,  ///< % 4KB syscall page
36     Tbuf_buffer_area  = Service_page + 0x200000, ///< % 2MB
37     Tbuf_ubuffer_area = Tbuf_buffer_area,
38     // 0xeb800000-0xec000000 (8MB) free
39     Io_map_area_start = 0xec000000,
40     Io_map_area_end   = 0xec800000,
41     __free_4          = 0xec880000,    ///< % 4MB
42     Jdb_debug_start   = 0xecc00000,    ///< % 4MB   JDB symbols/lines
43     Jdb_debug_end     = 0xee000000,    ///< % 4MB
44     // 0xee000000-0xef800000 (24MB) free
45     Kstatic           = 0xef800000,    ///< Io_bitmap - 4MB
46     Io_bitmap         = 0xefc00000,    ///< % 4MB
47     Vmem_end          = 0xf0000000,
48
49     Kernel_image        = FIASCO_IMAGE_VIRT_START, // usually 0xf0000000
50     Kernel_image_end    = Kernel_image + Config::SUPERPAGE_SIZE,
51
52     Adap_image           = Adap_in_kernel_image
53                            ? Kernel_image
54                            : Kernel_image + Config::SUPERPAGE_SIZE,
55
56     Adap_vram_mda_beg = Adap_image + 0xb0000, ///< % 8KB video RAM MDA memory
57     Adap_vram_mda_end = Adap_image + 0xb8000,
58     Adap_vram_cga_beg = Adap_image + 0xb8000, ///< % 8KB video RAM CGA memory
59     Adap_vram_cga_end = Adap_image + 0xc0000,
60
61     Caps_start        = 0xf0800000,    ///< % 4MB
62     Caps_end          = 0xf3000000,    ///< % 4MB == Caps_start + (1<<20) * 4
63     Physmem           = 0xfc400000,    ///< % 4MB   kernel memory
64   };
65
66   enum Offsets
67   {
68     Kernel_image_offset = FIASCO_IMAGE_PHYS_OFFSET,
69   };
70
71   enum Phys_addrs
72   {
73     Kernel_image_phys = FIASCO_IMAGE_PHYS_START & Config::SUPERPAGE_MASK,
74     Adap_image_phys   = 0,
75   };
76
77   template < typename T > static T* boot_data (T const *addr);
78
79   static Address pmem_size;
80 private:
81   static Address physmem_offs asm ("PHYSMEM_OFFS");
82 };
83
84 IMPLEMENTATION [ia32]:
85
86 #include <cassert>
87 #include <kdb_ke.h>
88
89 Address Mem_layout::physmem_offs;
90 Address Mem_layout::pmem_size;
91
92
93 PUBLIC static inline
94 void
95 Mem_layout::kphys_base (Address base)
96 {
97   physmem_offs = (Address)Physmem - base;
98 }
99
100 PUBLIC static inline NEEDS[<cassert>]
101 Address
102 Mem_layout::pmem_to_phys (Address addr)
103 {
104   assert (in_pmem(addr));
105   return addr - physmem_offs;
106 }
107
108 PUBLIC static inline NEEDS[<kdb_ke.h>]
109 Address
110 Mem_layout::pmem_to_phys (const void *ptr)
111 {
112   Address addr = reinterpret_cast<Address>(ptr);
113
114   assert_kdb (in_pmem(addr));
115   return addr - physmem_offs;
116 }
117
118 PUBLIC static inline
119 Address
120 Mem_layout::phys_to_pmem(Address addr)
121 {
122   return addr + physmem_offs;
123 }
124
125 PUBLIC static inline
126 Mword
127 Mem_layout::in_kernel_image(Address addr)
128 {
129   return addr >= Kernel_image && addr < Kernel_image_end;
130 }
131
132 PUBLIC static inline
133 Mword
134 Mem_layout::in_pmem(Address addr)
135 {
136   return addr >= Physmem;
137 }