1from xnu import * 2from utils import * 3from process import * 4 5# TODO: write scheduler related macros here 6 7# Macro: showinterrupts 8@lldb_command('showinterrupts') 9def ShowInterrupts(cmd_args=None): 10 """ Prints IRQ, IPI and TMR counts for each CPU 11 """ 12 bcdata = kern.GetValueFromAddress(kern.GetLoadAddressForSymbol('BootCpuData'), 'cpu_data_t *') 13 print "CPU 0 IRQ: {:d}\n".format(bcdata.cpu_stat.irq_ex_cnt) 14 print "CPU 0 IPI: {:d}\n".format(bcdata.cpu_stat.ipi_cnt) 15 print "CPU 0 TMR: {:d}\n".format(bcdata.cpu_stat.timer_cnt) 16 if (kern.globals.machine_info.physical_cpu == 2): 17 if kern.arch == 'arm': 18 cdentries = kern.GetValueFromAddress(kern.GetLoadAddressForSymbol('CpuDataEntries') + 20, 'uintptr_t *') 19 cpu_data_entry = Cast(dereference(cdentries), 'cpu_data_t *') 20 print "CPU 1 IRQ: {:d}\n".format(cpu_data_entry.cpu_stat.irq_ex_cnt) 21 print "CPU 1 IPI: {:d}\n".format(cpu_data_entry.cpu_stat.ipi_cnt) 22 print "CPU 1 TMR: {:d}\n".format(cpu_data_entry.cpu_stat.timer_cnt) 23 24# EndMacro: showinterrupts 25 26# Macro: showactiveinterrupts 27@lldb_command('showactiveinterrupts') 28def ShowActiveInterrupts(cmd_args=None): 29 """ Prints the interrupts that are unmasked & active with the Interrupt Controller 30 Usage: showactiveinterrupts <address of Interrupt Controller object> 31 """ 32 if not cmd_args: 33 print "No arguments passed" 34 print ShowActiveInterrupts.__doc__ 35 return False 36 aic = kern.GetValueFromAddress(cmd_args[0], 'AppleInterruptController *') 37 if not aic: 38 print "unknown arguments:", str(cmd_args) 39 return False 40 41 aic_base = unsigned(aic._aicBaseAddress) 42 current_interrupt = 0 43 aic_imc_base = aic_base + 0x4180 44 aic_him_offset = 0x80 45 current_pointer = aic_imc_base 46 unmasked = dereference(kern.GetValueFromAddress(current_pointer, 'uintptr_t *')) 47 active = dereference(kern.GetValueFromAddress(current_pointer + aic_him_offset, 'uintptr_t *')) 48 group_count = 0 49 mask = 1 50 while current_interrupt < 192: 51 if (((unmasked & mask) == 0) and (active & mask)): 52 print "Interrupt {:d} unmasked and active\n".format(current_interrupt) 53 current_interrupt = current_interrupt + 1 54 if (current_interrupt % 32 == 0): 55 mask = 1 56 group_count = group_count + 1 57 unmasked = dereference(kern.GetValueFromAddress(current_pointer + (4 * group_count), 'uintptr_t *')) 58 active = dereference(kern.GetValueFromAddress((current_pointer + aic_him_offset) + (4 * group_count), 'uintptr_t *')) 59 else: 60 mask = mask << 1 61 62# EndMacro: showactiveinterrupts 63 64