4 #include "kernel_task.h"
5 #include "kmem_alloc.h"
6 #include "kmem_space.h"
8 #include "mem_layout.h"
10 #include "static_init.h"
13 STATIC_INITIALIZE_P(Jdb, JDB_INIT_PRIO);
15 static Per_cpu<Proc::Status> DEFINE_PER_CPU jdb_irq_state;
17 // disable interrupts before entering the kernel debugger
20 Jdb::save_disable_irqs(unsigned cpu)
22 jdb_irq_state.cpu(cpu) = Proc::cli_save();
25 // restore interrupts after leaving the kernel debugger
28 Jdb::restore_irqs(unsigned cpu)
30 Proc::sti_restore(jdb_irq_state.cpu(cpu));
35 Jdb::enter_trap_handler(unsigned /*cpu*/)
40 Jdb::leave_trap_handler(unsigned /*cpu*/)
43 PROTECTED static inline
45 Jdb::monitor_address(unsigned, void *)
50 Jdb::handle_conditional_breakpoint(unsigned /*cpu*/)
55 Jdb::handle_nested_trap(Jdb_entry_frame *e)
57 printf("Trap in JDB: IP:%08lx PSR=%08lx ERR=%08lx\n",
58 e->ip(), e->psr, e->error_code);
63 Jdb::handle_debug_traps(unsigned cpu)
65 Jdb_entry_frame *ef = entry_frame.cpu(cpu);
67 if (ef->error_code == 0x00e00000)
68 snprintf(error_buffer.cpu(cpu), sizeof(error_buffer.cpu(0)), "%s",
69 (char const *)ef->r[0]);
70 else if (ef->error_code == 0x00f00000)
71 snprintf(error_buffer.cpu(cpu), sizeof(error_buffer.cpu(0)),
79 Jdb::handle_user_request(unsigned cpu)
81 Jdb_entry_frame *ef = Jdb::entry_frame.cpu(cpu);
82 const char *str = (char const *)ef->r[0];
83 Space * task = get_task(cpu);
86 if (!peek(str, task, tmp) || tmp != '*')
88 if (!peek(str+1, task, tmp) || tmp != '#')
91 return execute_command_ni(task, str+2);
101 Jdb::handle_special_cmds(int)
105 FIASCO_INIT FIASCO_NOINLINE void
108 static Jdb_handler enter(at_jdb_enter);
109 static Jdb_handler leave(at_jdb_leave);
111 Jdb::jdb_enter.add(&enter);
112 Jdb::jdb_leave.add(&leave);
114 Thread::nested_trap_handler = (Trap_state::Handler)enter_jdb;
116 Kconsole::console()->register_console(push_cons());
122 Jdb::access_mem_task(Address virt, Space * task)
131 if (Mem_layout::in_kernel(virt))
133 Pte p = Kmem_space::kdir()->walk((void *)virt, 0, false,0);
137 phys = p.phys((void*)virt);
144 phys = Address(task->mem_space()->virt_to_phys(virt));
147 if (phys == (Address)-1)
148 phys = task->mem_space()->virt_to_phys_s0((void *)virt);
150 if (phys == (Address)-1)
154 unsigned long addr = Mem_layout::phys_to_pmem(phys);
155 if (addr == (Address)-1)
157 Mem_unit::flush_vdcache();
158 Pte pte = Kernel_task::kernel_task()->mem_space()->_dir->walk
159 ((void*)Mem_layout::Jdb_tmp_map_area, 0, false, 0);
161 if (pte.phys() != (phys & ~(Config::SUPERPAGE_SIZE - 1)))
162 pte.set(phys & ~(Config::SUPERPAGE_SIZE - 1), Config::SUPERPAGE_SIZE,
163 Mem_page_attr(Page::KERN_RW | Page::CACHEABLE), true);
165 Mem_unit::dtlb_flush();
167 addr = Mem_layout::Jdb_tmp_map_area + (phys & (Config::SUPERPAGE_SIZE - 1));
175 Jdb::translate_task(Address addr, Space * task)
177 return (Kmem::is_kmem_page_fault(addr, 0)) ? 0 : task;
182 Jdb::peek_task(Address virt, Space * task, void *value, int width)
184 void const *mem = access_mem_task(virt, task);
192 Mword dealign = (virt & 0x3) * 8;
193 *(Mword*)value = (*(Mword*)mem & (0xff << dealign)) >> dealign;
198 Mword dealign = ((virt & 0x2) >> 1) * 16;
199 *(Mword*)value = (*(Mword*)mem & (0xffff << dealign)) >> dealign;
203 memcpy(value, mem, width);
211 Jdb::is_adapter_memory(Address, Space *)
218 Jdb::poke_task(Address virt, Space * task, void const *val, int width)
220 void *mem = access_mem_task(virt, task);
224 memcpy(mem, val, width);
233 Mem_unit::clean_vdcache();
240 Mem_unit::flush_vcache();
255 Jdb::write_tsc_s(Signed64 tsc, char *buf, int maxlen, bool sign)
259 *buf++ = (tsc < 0) ? '-' : (tsc == 0) ? ' ' : '+';
262 snprintf(buf, maxlen, "%lld c", tsc);
267 Jdb::write_tsc(Signed64 tsc, char *buf, int maxlen, bool sign)
269 write_tsc_s(tsc, buf, maxlen, sign);
272 //----------------------------------------------------------------------------
273 IMPLEMENTATION [arm && mp]:
279 Jdb::send_nmi(unsigned /*cpu*/)
281 printf("NMI, what's that?\n");