]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/boot_info-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / boot_info-ia32.cpp
1 /* IA32/AMD64 Specific Boot info */
2 INTERFACE[ia32,ux,amd64]:
3
4 #include "multiboot.h"
5 #include "types.h"
6
7
8 EXTENSION class Boot_info
9 {
10 public:
11
12   static Address mbi_phys();
13
14   static Multiboot_info *mbi_virt();
15 };
16
17
18 //-------------------------------------------------------------------------
19 INTERFACE[ia32,amd64]:
20
21 EXTENSION class Boot_info
22 {
23 private:
24   static Address  _mbi_pa;
25   static unsigned _flag;
26   static unsigned _checksum_ro;
27   static unsigned _checksum_rw;
28   static Multiboot_info _kmbi;
29 };
30
31
32 //-------------------------------------------------------------------------
33 IMPLEMENTATION[ux]:
34
35 #include "config.h"
36 #include "koptions.h"
37 #include "mem_layout.h"
38
39 PUBLIC static
40 Address
41 Boot_info::kmem_start(Address mem_max)
42 {
43   Address end_addr = (mbi_virt()->mem_upper + 1024) << 10;
44   Address size, base;
45
46   if (end_addr > mem_max)
47     end_addr = mem_max;
48
49   size = Koptions::o()->kmemsize << 10;
50   if (!size)
51     {
52       size = end_addr / 100 * Config::kernel_mem_per_cent;
53       if (size > Config::kernel_mem_max)
54         size = Config::kernel_mem_max;
55     }
56
57   base = end_addr - size & Config::PAGE_MASK;
58   if (Mem_layout::phys_to_pmem(base) < Mem_layout::Physmem)
59     base = Mem_layout::pmem_to_phys(Mem_layout::Physmem);
60
61   return base;
62 }
63
64
65 //-----------------------------------------------------------------------------
66 IMPLEMENTATION[ia32,amd64]:
67
68 #include <cassert>
69 #include <cstring>
70 #include <cstdlib>
71 #include "checksum.h"
72 #include "mem_layout.h"
73
74 // these members needs to be initialized with some
75 // data to go into the data section and not into bss
76 Address  Boot_info::_mbi_pa        = 125;
77 unsigned Boot_info::_flag          = 3;
78 unsigned Boot_info::_checksum_ro   = 15;
79 unsigned Boot_info::_checksum_rw   = 16;
80
81 // initialized after startup cleaned out the bss
82
83 Multiboot_info Boot_info::_kmbi;
84
85
86 /// \defgroup pre init setup
87 /**
88  * The Boot_info object must be set up with these functions
89  * before Boot_info::init() is called!
90  * This can be done either in __main, if booted on hardware
91  * or in an initializer with a higher priority than BOOT_INFO_INIT_PRIO
92  * (e.g UX_STARTUP1_INIT_PRIO) if the kernel runs on software (FIASCO-UX)
93  */
94 //@{
95
96 PUBLIC inline static
97 void Boot_info::set_flags(unsigned aflags)
98 {  _flag = aflags; }
99
100 PUBLIC inline static
101 void Boot_info::set_checksum_ro(unsigned ro_cs)
102 {  _checksum_ro = ro_cs; }
103
104 PUBLIC inline static
105 void Boot_info::set_checksum_rw(unsigned rw_cs)
106 {  _checksum_rw = rw_cs; }
107 //@}
108
109
110 IMPLEMENT
111 void
112 Boot_info::init()
113 {
114   // we assume that we run in 1:1 mapped mode
115   _kmbi = *(Multiboot_info *)mbi_phys();
116 }
117
118 PUBLIC inline static
119 unsigned
120 Boot_info::get_flags(void)
121 {
122   return _flag;
123 }
124
125 PUBLIC inline static
126 unsigned
127 Boot_info::get_checksum_ro(void)
128 {
129   return _checksum_ro;
130 }
131
132 PUBLIC inline static
133 unsigned
134 Boot_info::get_checksum_rw(void)
135 {
136   return _checksum_rw;
137 }
138
139 PUBLIC static
140 void
141 Boot_info::reset_checksum_ro(void)
142 {
143   set_checksum_ro(Checksum::get_checksum_ro());
144 }
145
146 PUBLIC inline static
147 void
148 Boot_info::set_mbi_phys(Address phys)
149 {
150   _mbi_pa = phys;
151 }
152
153 IMPLEMENT inline
154 Address
155 Boot_info::mbi_phys(void)
156 {
157   return _mbi_pa;
158 }
159
160 IMPLEMENT inline
161 Multiboot_info *
162 Boot_info::mbi_virt()
163 {
164   return &_kmbi;
165 }