3 #include <cstddef> // size_t
4 #include <flux/x86/types.h> // vm_offset_t & friends
5 #include <flux/x86/multiboot.h> // multiboot_info
6 #include <flux/x86/paging.h> // pd_entry_t
10 //#include "config_gdt.h"
12 /* our own implementation of C++ memory management: disallow dynamic
13 allocation (except where class-specific new/delete functions exist) */
15 void *operator new(size_t);
16 void operator delete(void *block);
18 // more specialized memory allocation/deallocation functions follow
19 // below in the "kmem" namespace
21 // kernel.ld definitions
24 extern char _start, _edata, _end;
25 // extern char _physmem_1;
26 // extern char _tcbs_1;
27 // extern char _iobitmap_1;
28 extern char _unused1_1, _unused2_1, _unused3_1, _unused4_io_1;
29 extern char _ipc_window0_1, _ipc_window1_1;
38 // the kernel memory is a singleton object. we access it through a
39 // static class interface. (we would have preferred to access it like
40 // a class, but our method saves the overhead of always passing the
41 // "this" pointer on the (very small) kernel stack).
43 // this object is the system's page-level allocator
47 // constants from the above kernel.ld declarations
48 // static const vm_offset_t mem_phys = reinterpret_cast<vm_offset_t>(&_physmem_1);
49 static const vm_offset_t mem_phys = 0;
50 // static const vm_offset_t mem_tcbs = reinterpret_cast<vm_offset_t>(&_tcbs_1);
51 static const vm_offset_t mem_user_max = 0xc0000000;
53 static vm_offset_t io_bitmap;
55 static const vm_offset_t ipc_window0
56 = reinterpret_cast<vm_offset_t>(&_ipc_window0_1);
57 static const vm_offset_t ipc_window1
58 = reinterpret_cast<vm_offset_t>(&_ipc_window1_1);
60 // enum { gdt_tss = GDT_TSS,
61 // gdt_code_kernel = GDT_CODE_KERNEL, gdt_data_kernel = GDT_DATA_KERNEL,
62 // gdt_code_user = GDT_CODE_USER, gdt_data_user = GDT_DATA_USER,
63 // gdt_max = GDT_MAX };
66 // static pd_entry_t *kdir; // kernel page directory
67 // static pd_entry_t cpu_global;
72 // friend class profile;
74 kmem(); // default constructors are undefined
77 // static vm_offset_t mem_max, _himem;
79 static const pd_entry_t flag_global = 0x200; // l4-specific pg dir entry flag
81 // static x86_gate *kidt;
82 // static x86_tss *tss;
83 // static x86_desc *gdt;
87 // static multiboot_info kmbi;
88 // static char kcmdline[256];
98 // #include <flux/x86/tss.h>
99 // #include <flux/x86/seg.h>
100 // #include <flux/x86/proc_reg.h>
101 // #include <flux/x86/gate_init.h>
102 // #include <flux/x86/base_vm.h>
106 // #include "entry.h"
107 // #include "irq_init.h"
108 // #include "config.h"
110 #include "unix_aligned_alloc.h"
116 // static class variables
118 // vm_offset_t kmem::mem_max, kmem::_himem;
119 // pd_entry_t *kmem::kdir;
120 // pd_entry_t kmem::cpu_global;
122 static Kip the_kinfo =
124 /* magic: */ L4_KERNEL_INFO_MAGIC,
125 /* version: */ 0x01004444,
132 // main_memory.high: mem_max,
133 /* main_memory: */ { 0, 0x4000000},
134 // reserved0.low = trunc_page(virt_to_phys(&__crt_dummy__)),
135 // reserved0.high = round_page(virt_to_phys(&_end)),
136 /* reserved0: */ { 0, 0},
137 /* reserved1: */ { 0, 0},
138 /* semi_reserved: */ { 1024 * 640, 1024 * 1024},
139 // Skipped rest -- rely on 0-initialization.
143 Kip *kmem::kinfo = &the_kinfo;
145 vm_offset_t kmem::io_bitmap
146 = reinterpret_cast<vm_offset_t>
147 (unix_aligned_alloc(2 * PAGE_SIZE + 4, 2* PAGE_SIZE));
149 // multiboot_info kmem::kmbi;
150 // char kmem::kcmdline[256];
152 // x86_gate *kmem::kidt;
153 // x86_tss *kmem::tss;
154 // x86_desc *kmem::gdt;
157 // kmem virtual-space related functions (similar to space_t)
161 kmem::virt_to_phys(const void *addr)
163 return reinterpret_cast<vm_offset_t>(addr);
167 inline void *kmem::phys_to_virt(vm_offset_t addr) // physical to kernel-virtual
169 return reinterpret_cast<void *>(addr);
172 // initialize a new task's page directory with the current master copy
173 // of kernel page tables
175 void kmem::dir_init(pd_entry_t *d)
184 inline void kmem::tlb_flush(vm_offset_t addr) // flush tlb at virtual addr
190 inline void kmem::tlb_flush()
200 kmem::ipc_window(unsigned win)
209 inline Kip *kmem::info() // returns the kernel info page
215 const pd_entry_t *kmem::dir() // returns the kernel's page directory
217 assert (! "Cannot request kernel's page directory.");
223 pd_entry_t kmem::pde_global() // returns mask for global pg dir entries
225 // return cpu_global;
227 | ((cpu.feature_flags & CPUF_PAGE_GLOBAL_EXT)
233 // inline const multiboot_info *kmem::mbi()
239 // inline const char *kmem::cmdline()
245 // inline x86_gate *kmem::idt()
251 // inline vm_offset_t kmem::himem()
256 // // Get a pointer to the CPUs kernel stack pointer
258 // inline NEEDS [<flux/x86/tss.h>]
259 // vm_offset_t *kmem::kernel_esp()
261 // return reinterpret_cast<vm_offset_t*>(& tss->esp0);