static int dump_port_info(int argc, char** argv) { ConditionVariable* condition = NULL; const char* name = NULL; if (argc < 2) { print_debugger_command_usage(argv[0]); return 0; } if (argc > 2) { if (!strcmp(argv[1], "address")) { _dump_port_info((struct port_entry*)parse_expression(argv[2])); return 0; } else if (!strcmp(argv[1], "condition")) condition = (ConditionVariable*)parse_expression(argv[2]); else if (!strcmp(argv[1], "name")) name = argv[2]; } else if (parse_expression(argv[1]) > 0) { // if the argument looks like a number, treat it as such int32 num = parse_expression(argv[1]); int32 slot = num % sMaxPorts; if (sPorts[slot].id != num) { kprintf("port %ld (%#lx) doesn't exist!\n", num, num); return 0; } _dump_port_info(&sPorts[slot]); return 0; } else name = argv[1]; // walk through the ports list, trying to match name for (int32 i = 0; i < sMaxPorts; i++) { if ((name != NULL && sPorts[i].lock.name != NULL && !strcmp(name, sPorts[i].lock.name)) || (condition != NULL && (&sPorts[i].read_condition == condition || &sPorts[i].write_condition == condition))) { _dump_port_info(&sPorts[i]); return 0; } } return 0; }
static void dump_port_info(int argc, char **argv) { int i; if(argc < 2) { dprintf("port: not enough arguments\n"); return; } // if the argument looks like a hex number, treat it as such if(strlen(argv[1]) > 2 && argv[1][0] == '0' && argv[1][1] == 'x') { unsigned long num = atoul(argv[1]); if(is_kernel_address(num)) { // XXX semi-hack // one can use either address or a port_id, since KERNEL_BASE > MAX_PORTS assumed _dump_port_info((struct port_entry *)num); return; } else { unsigned slot = num % MAX_PORTS; if(ports[slot].id != (int)num) { dprintf("port 0x%lx doesn't exist!\n", num); return; } _dump_port_info(&ports[slot]); return; } } // walk through the ports list, trying to match name for(i=0; i<MAX_PORTS; i++) { if (ports[i].name != NULL) if(strcmp(argv[1], ports[i].name) == 0) { _dump_port_info(&ports[i]); return; } } }