Most of our architectures implement a "machine" command as a MD extension in ddb(4).
Currently that is handled in this way: * A define is placed in a MD header. * The MI ddb code checks for the define, creates an incomplete entry in the command table, and provides an initialization function. * MD code calls this function to patch a pointer to the MD sub-command into the MI command table. I guess it made sense in 1990? We can simplify this: Define a consistently named db_machine_command_table[] across all archs that implement the MD "machine" command and hook this into the main command table instead of patching it at runtime. Most archs already use the name db_machine_command_table[]. This will allow constifying the ddb command tables in a subsequent step. I have tested amd64, arm64, and i386. Comments, ok? M sys/arch/alpha/alpha/db_interface.c M sys/arch/amd64/amd64/db_interface.c M sys/arch/arm/arm/db_interface.c M sys/arch/arm64/arm64/db_interface.c M sys/arch/i386/i386/db_interface.c M sys/arch/m88k/m88k/db_interface.c M sys/arch/mips64/mips64/db_machdep.c M sys/arch/powerpc/ddb/db_interface.c M sys/arch/powerpc64/powerpc64/db_interface.c M sys/arch/riscv64/riscv64/db_interface.c M sys/arch/sh/sh/db_interface.c M sys/arch/sparc64/sparc64/db_interface.c M sys/ddb/db_command.c M sys/ddb/db_command.h diff 7e559a9c431834a0b3471b1fa86985ca220b83ba c5fcb00219e59f5bbd0cb5171af7fe5d01f0a0c3 blob - fd83cb898bcddb466570b0c531b0b34171a1363f blob + 7e9ce6cc9803586260886d5c16ff2e1219cc2c77 --- sys/arch/alpha/alpha/db_interface.c +++ sys/arch/alpha/alpha/db_interface.c @@ -527,5 +527,4 @@ db_mach_cpu(db_expr_t addr, int have_addr, db_expr_t c void db_machine_init() { - db_machine_commands_install(db_machine_command_table); } blob - 186fb4d83fb4d5f849e88297c311f37eaf4638c6 blob + b12b9c48cf147c1525c19e11fac84b35b02bc19f --- sys/arch/amd64/amd64/db_interface.c +++ sys/arch/amd64/amd64/db_interface.c @@ -422,10 +422,7 @@ db_machine_init(void) { #ifdef MULTIPROCESSOR int i; -#endif - db_machine_commands_install(db_machine_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < MAXCPUS; i++) { if (cpu_info[i] != NULL) cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING; blob - a8d7805cd6f73e9d281b448e8bb03fb77e210df2 blob + 719da88249590509dabb734794daedc7c2a3dd61 --- sys/arch/arm/arm/db_interface.c +++ sys/arch/arm/arm/db_interface.c @@ -378,8 +378,6 @@ db_machine_init(void) */ db_uh.uh_handler = db_trapper; install_coproc_handler_static(0, &db_uh); - - db_machine_commands_install(db_machine_command_table); } u_int blob - ed28376be206f5eb55ae034981680025b2717513 blob + 1645b49186bed36130ffd73a933e45f8f9fc5e18 --- sys/arch/arm64/arm64/db_interface.c +++ sys/arch/arm64/arm64/db_interface.c @@ -499,10 +499,7 @@ db_machine_init(void) { #ifdef MULTIPROCESSOR int i; -#endif - db_machine_commands_install(db_machine_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < MAXCPUS; i++) { if (cpu_info[i] != NULL) cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING; blob - b4c6a02021c944ddea37cb8add864ee1f65a454b blob + 1807bc890744e4f32ef839e73e5647fd5488b901 --- sys/arch/i386/i386/db_interface.c +++ sys/arch/i386/i386/db_interface.c @@ -342,10 +342,7 @@ db_machine_init(void) { #ifdef MULTIPROCESSOR int i; -#endif /* MULTIPROCESSOR */ - db_machine_commands_install(db_machine_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < MAXCPUS; i++) { if (cpu_info[i] != NULL) cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING; blob - 4d540ea2ad0e5b2d0b8a3c15837309bfe5f8db8c blob + 55d5e5ba78719c954c4d6d1f5ffa9083e941a932 --- sys/arch/m88k/m88k/db_interface.c +++ sys/arch/m88k/m88k/db_interface.c @@ -654,7 +654,7 @@ m88k_db_cpu_cmd(db_expr_t addr, int have_addr, db_expr /* COMMAND TABLE / INIT */ /************************/ -struct db_command db_machine_cmds[] = { +struct db_command db_machine_command_table[] = { #ifdef MULTIPROCESSOR { "ddbcpu", m88k_db_cpu_cmd, 0, NULL }, #endif @@ -671,7 +671,6 @@ struct db_command db_machine_cmds[] = { void db_machine_init() { - db_machine_commands_install(db_machine_cmds); #ifdef MULTIPROCESSOR __mp_lock_init(&ddb_mp_lock); #endif blob - bbdf2462b57e310bb79ee1890d7a5495f9487226 blob + 2c7d67c597c2a237420af198985aaa20781f124e --- sys/arch/mips64/mips64/db_machdep.c +++ sys/arch/mips64/mips64/db_machdep.c @@ -492,7 +492,7 @@ db_dump_tlb_cmd(db_expr_t addr, int have_addr, db_expr } -struct db_command mips_db_command_table[] = { +struct db_command db_machine_command_table[] = { { "tlb", db_dump_tlb_cmd, 0, NULL }, { "trap", db_trap_trace_cmd, 0, NULL }, #ifdef MULTIPROCESSOR @@ -510,10 +510,7 @@ db_machine_init(void) extern char *ssym; #ifdef MULTIPROCESSOR int i; -#endif - db_machine_commands_install(mips_db_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < ncpus; i++) { get_cpu_info(i)->ci_ddb = CI_DDB_RUNNING; } blob - da7249e3b9956943537ee5eaab0209f0f071d522 blob + 079c4056ecd8ec4a4cf499410bd6c24d3d9d569c --- sys/arch/powerpc/ddb/db_interface.c +++ sys/arch/powerpc/ddb/db_interface.c @@ -236,10 +236,7 @@ db_machine_init(void) { #ifdef MULTIPROCESSOR int i; -#endif - db_machine_commands_install(db_machine_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < ncpus; i++) { cpu_info[i].ci_ddb_paused = CI_DDB_RUNNING; } blob - e86b1d664bd4d88c6369ebe341fab28ac945ba94 blob + 7c4f03640bf86fb5afea3c109554805d59806c8d --- sys/arch/powerpc64/powerpc64/db_interface.c +++ sys/arch/powerpc64/powerpc64/db_interface.c @@ -120,7 +120,6 @@ db_machine_init(void) } } - db_machine_commands_install(db_machine_command_table); #ifdef MULTIPROCESSOR for (i = 0; i < ncpus; i++) { cpu_info[i].ci_ddb_paused = CI_DDB_RUNNING; blob - d5f880b74b54777087f2b1b2617e9e8f36dbb94a blob + 958d60076a78906b70a859f48f577f8c9bae72da --- sys/arch/riscv64/riscv64/db_interface.c +++ sys/arch/riscv64/riscv64/db_interface.c @@ -446,10 +446,7 @@ db_machine_init(void) { #ifdef MULTIPROCESSOR int i; -#endif - db_machine_commands_install(db_machine_command_table); -#ifdef MULTIPROCESSOR for (i = 0; i < MAXCPUS; i++) { if (cpu_info[i] != NULL) cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING; blob - b01fdfead60bb04b19a72aba4809734d8d2f0903 blob + 4ff8543e198e66fe4dedcab0f649939815e610fd --- sys/arch/sh/sh/db_interface.c +++ sys/arch/sh/sh/db_interface.c @@ -86,8 +86,6 @@ struct db_command db_machine_command_table[] = { void db_machine_init(void) { - - db_machine_commands_install(db_machine_command_table); } void blob - fc2382cf0cf51c5dba9385685cb0ee7fa3a2859a blob + ebc6e20f0a8327c2b8fc3128a030460d4ecc9e8b --- sys/arch/sparc64/sparc64/db_interface.c +++ sys/arch/sparc64/sparc64/db_interface.c @@ -1363,5 +1363,4 @@ db_inst_trap_return(int inst) void db_machine_init(void) { - db_machine_commands_install(db_machine_command_table); } blob - f89595531f609f9fd32b6a9c26457c7a05fbb4b5 blob + 98c629cc808f62fcec89478bc9a2819bdb5804dc --- sys/ddb/db_command.c +++ sys/ddb/db_command.c @@ -628,7 +628,7 @@ struct db_command db_boot_cmds[] = { struct db_command db_command_table[] = { #ifdef DB_MACHINE_COMMANDS /* this must be the first entry, if it exists */ - { "machine", NULL, 0, NULL}, + { "machine", NULL, 0, db_machine_command_table }, #endif { "kill", db_kill_cmd, 0, NULL }, { "print", db_print_cmd, 0, NULL }, @@ -666,18 +666,6 @@ struct db_command db_command_table[] = { { NULL, NULL, 0, NULL } }; -#ifdef DB_MACHINE_COMMANDS - -/* this function should be called to install the machine dependent - commands. It should be called before the debugger is enabled */ -void -db_machine_commands_install(struct db_command *ptr) -{ - db_command_table[0].more = ptr; -} - -#endif - struct db_command *db_last_command = NULL; void blob - 45800424d35d40208d85ed98651dca98904e4f50 blob + 41bb4e3a7027ef12efe426b8bd9bfcebaea6e47d --- sys/ddb/db_command.h +++ sys/ddb/db_command.h @@ -39,7 +39,6 @@ void db_error(char *); void db_skip_to_eol(void); void db_command_loop(void); void db_command(struct db_command **, struct db_command *); -void db_machine_commands_install(struct db_command *); extern vaddr_t db_dot, db_last_addr, db_prev, db_next; @@ -57,3 +56,7 @@ struct db_command { #define CS_SET_DOT 0x100 /* set dot after command */ struct db_command *more; /* another level of command */ }; + +#ifdef DB_MACHINE_COMMANDS +extern struct db_command db_machine_command_table[]; +#endif -- Christian "naddy" Weisgerber na...@mips.inka.de