14 //---------------------------------------------------------------------------
19 // We have to do this here because Jdb_symbol and Jdb_lines must not depend
21 PRIVATE static inline NOEXPORT
23 Jdb_dbinfo::init_symbols_lines ()
27 p = (sizeof(Jdb_symbol_info)*Jdb_symbol::Max_tasks) >> Config::PAGE_SHIFT;
28 Jdb_symbol::init(Kmem_alloc::allocator()
29 ->unaligned_alloc(p*Config::PAGE_SIZE), p);
30 p = (sizeof(Jdb_lines_info) *Jdb_lines::Max_tasks) >> Config::PAGE_SHIFT;
31 Jdb_lines::init(Kmem_alloc::allocator()
32 ->unaligned_alloc(p*Config::PAGE_SIZE), p);
36 //---------------------------------------------------------------------------
37 IMPLEMENTATION[ia32,amd64]:
40 #include "jdb_lines.h"
41 #include "jdb_symbol.h"
43 #include "kmem_alloc.h"
44 #include "mem_layout.h"
48 #include "static_init.h"
50 const Address area_start = Mem_layout::Jdb_debug_start;
51 const Address area_end = Mem_layout::Jdb_debug_end;
52 const unsigned area_size = area_end - area_start;
53 const unsigned bitmap_size = (area_size / Config::PAGE_SIZE) / 8;
55 // We don't use the amm library here anymore since it is nearly impossible
56 // to debug it and I got some strange behavior. Instead of this we use a
57 // simple bitfield here that takes 2k for a virtual memory size of 64MB
58 // which is enough for the Jdb debug info. Speed for allocating/deallocating
59 // pages is not an issue here.
60 static unsigned char bitmap[bitmap_size];
62 STATIC_INITIALIZE(Jdb_dbinfo);
64 //---------------------------------------------------------------------------
65 IMPLEMENTATION[ia32, amd64]:
67 PUBLIC static FIASCO_INIT
73 for (addr = area_start; addr < area_end; addr += Config::SUPERPAGE_SIZE)
74 Kmem::kdir->walk(Virt_addr(addr), 100, pdir_alloc(Kmem_alloc::allocator()));
82 Jdb_dbinfo::reserve_pages(unsigned pages)
84 auto guard = lock_guard(cpu_lock);
88 for (ptr=bitmap, bit=0; ptr<bitmap+bitmap_size;)
90 Unsigned8 *ptr1, bit1, c;
93 for (ptr1=ptr, bit1=bit, pages1=pages;;)
95 if (ptr1>=bitmap+bitmap_size)
98 c = *ptr1 & (1<<bit1);
115 // found area -- make it as reserved
116 for (ptr1=ptr, bit1=bit, pages1=pages; pages1>0; pages1--)
125 return area_start + Config::PAGE_SIZE * (8*(ptr-bitmap) + bit);
135 Jdb_dbinfo::return_pages(Address addr, unsigned pages)
137 auto guard = lock_guard(cpu_lock);
139 unsigned nr_page = (addr-area_start) / Config::PAGE_SIZE;
140 Unsigned8 *ptr = bitmap + nr_page/8, bit = nr_page % 8;
142 for (; pages && ptr < bitmap+bitmap_size; pages--)
144 assert (*ptr & (1<<bit));
154 //---------------------------------------------------------------------------
155 IMPLEMENTATION[ia32, amd64]:
159 Jdb_dbinfo::map(Address phys, size_t &size, Address &virt)
161 Address offs = phys & ~Config::PAGE_MASK;
163 size = (offs + size + Config::PAGE_SIZE - 1) & Config::PAGE_MASK;
164 virt = reserve_pages (size / Config::PAGE_SIZE);
168 phys &= Config::PAGE_MASK;
170 Kmem::kdir->map(phys, Virt_addr(virt), Virt_size(size),
171 Pt_entry::Valid | Pt_entry::Writable | Pt_entry::Referenced
172 | Pt_entry::Dirty, 100, Ptab::Null_alloc());
180 Jdb_dbinfo::unmap(Address virt, size_t size)
184 virt &= Config::PAGE_MASK;
186 Kmem::kdir->unmap(Virt_addr(virt), Virt_size(size), 100);
187 Mem_unit::tlb_flush ();
189 return_pages(virt, size/Config::PAGE_SIZE);
195 Jdb_dbinfo::set(Jdb_symbol_info *sym, Address phys, size_t size)
204 sym->get (virt, size);
213 if (! map (phys, size, virt))
216 if (! sym->set (virt, size))
225 Jdb_dbinfo::set(Jdb_lines_info *lin, Address phys, size_t size)
234 lin->get(virt, size);
242 if (!map(phys, size, virt))
245 if (!lin->set(virt, size))
253 //---------------------------------------------------------------------------
256 // No special mapping required for UX since all physical memory is mapped
258 #include "jdb_lines.h"
259 #include "jdb_symbol.h"
260 #include "kmem_alloc.h"
261 #include "mem_layout.h"
262 #include "static_init.h"
264 STATIC_INITIALIZE(Jdb_dbinfo);
270 init_symbols_lines();
275 Jdb_dbinfo::set(Jdb_symbol_info *sym, Address phys, size_t size)
283 sym->set(Mem_layout::phys_to_pmem(phys), size);
288 Jdb_dbinfo::set(Jdb_lines_info *lin, Address phys, size_t size)
296 lin->set(Mem_layout::phys_to_pmem(phys), size);