On 13/12/17(Wed) 19:09, Florian Riehm wrote:
> Hi,
>
> This patch follows bluhm's attempt for a ddb command 'boot reset'.
> My first attempt was not architecture aware.
>
> Tested on i386 by bluhm@ and on amd64 by me.
I don't understand why we need to add "boot reset"? To not fix ddb(4)
and keep a broken "boot reboot"? If we cannot fix our own code...
> Index: share/man/man4/ddb.4
> ===================================================================
> RCS file: /openbsd/src/share/man/man4/ddb.4,v
> retrieving revision 1.92
> diff -u -p -r1.92 ddb.4
> --- share/man/man4/ddb.4 29 Nov 2017 07:28:21 -0000 1.92
> +++ share/man/man4/ddb.4 12 Dec 2017 06:35:44 -0000
> @@ -381,6 +381,15 @@ Just halt.
> Just reboot.
> .It Ic boot poweroff
> Power down the machine whenever possible; if it fails, just halt.
> +.It Ic boot reset
> +Restart the machine by resetting the CPU on i386 and amd64
> +architectures.
> +Useful in situations were
> +.Ic boot reboot
> +does not work anymore, i.e. due to locking issues.
> +On other platforms it is equivalent to the
> +.Ic boot reboot
> +command.
> .El
> .\" --------------------
> .It Xo
> Index: sys/arch/amd64/amd64/machdep.c
> ===================================================================
> RCS file: /openbsd/src/sys/arch/amd64/amd64/machdep.c,v
> retrieving revision 1.236
> diff -u -p -r1.236 machdep.c
> --- sys/arch/amd64/amd64/machdep.c 11 Dec 2017 05:27:40 -0000 1.236
> +++ sys/arch/amd64/amd64/machdep.c 12 Dec 2017 06:35:44 -0000
> @@ -713,6 +713,9 @@ struct pcb dumppcb;
> __dead void
> boot(int howto)
> {
> + if ((howto & RB_RESET) != 0)
> + goto reset;
> +
> if ((howto & RB_POWERDOWN) != 0)
> lid_action = 0;
>
> @@ -770,6 +773,7 @@ haltsys:
> printf("rebooting...\n");
> if (cpureset_delay > 0)
> delay(cpureset_delay * 1000);
> +reset:
> cpu_reset();
> for (;;)
> continue;
> Index: sys/arch/i386/i386/machdep.c
> ===================================================================
> RCS file: /openbsd/src/sys/arch/i386/i386/machdep.c,v
> retrieving revision 1.607
> diff -u -p -r1.607 machdep.c
> --- sys/arch/i386/i386/machdep.c 11 Dec 2017 05:27:40 -0000 1.607
> +++ sys/arch/i386/i386/machdep.c 12 Dec 2017 06:35:44 -0000
> @@ -2629,6 +2629,9 @@ struct pcb dumppcb;
> __dead void
> boot(int howto)
> {
> + if ((howto & RB_RESET) != 0)
> + goto reset;
> +
> if ((howto & RB_POWERDOWN) != 0)
> lid_action = 0;
>
> @@ -2709,6 +2712,7 @@ haltsys:
> }
>
> printf("rebooting...\n");
> +reset:
> cpu_reset();
> for (;;)
> continue;
> Index: sys/ddb/db_command.c
> ===================================================================
> RCS file: /openbsd/src/sys/ddb/db_command.c,v
> retrieving revision 1.81
> diff -u -p -r1.81 db_command.c
> --- sys/ddb/db_command.c 11 Dec 2017 05:27:40 -0000 1.81
> +++ sys/ddb/db_command.c 12 Dec 2017 06:35:44 -0000
> @@ -105,6 +105,7 @@ void db_boot_dump_cmd(db_expr_t, int, db
> void db_boot_halt_cmd(db_expr_t, int, db_expr_t, char *);
> void db_boot_reboot_cmd(db_expr_t, int, db_expr_t, char *);
> void db_boot_poweroff_cmd(db_expr_t, int, db_expr_t, char *);
> +void db_boot_reset_cmd(db_expr_t, int, db_expr_t, char *);
> void db_stack_trace_cmd(db_expr_t, int, db_expr_t, char *);
> void db_dmesg_cmd(db_expr_t, int, db_expr_t, char *);
> void db_show_panic_cmd(db_expr_t, int, db_expr_t, char *);
> @@ -597,6 +598,7 @@ struct db_command db_boot_cmds[] = {
> { "halt", db_boot_halt_cmd, 0, 0 },
> { "reboot", db_boot_reboot_cmd, 0, 0 },
> { "poweroff", db_boot_poweroff_cmd, 0, 0 },
> + { "reset", db_boot_reset_cmd, 0, 0 },
> { NULL, }
> };
>
> @@ -812,6 +814,12 @@ void
> db_boot_poweroff_cmd(db_expr_t addr, int haddr, db_expr_t count, char *modif)
> {
> db_reboot(RB_NOSYNC | RB_HALT | RB_POWERDOWN | RB_TIMEBAD | RB_USERREQ);
> +}
> +
> +void
> +db_boot_reset_cmd(db_expr_t addr, int haddr, db_expr_t count, char *modif)
> +{
> + db_reboot(RB_RESET | RB_AUTOBOOT | RB_NOSYNC | RB_TIMEBAD | RB_USERREQ);
> }
>
> void
> Index: sys/sys/reboot.h
> ===================================================================
> RCS file: /openbsd/src/sys/sys/reboot.h,v
> retrieving revision 1.17
> diff -u -p -r1.17 reboot.h
> --- sys/sys/reboot.h 11 Jul 2014 14:36:44 -0000 1.17
> +++ sys/sys/reboot.h 12 Dec 2017 06:35:45 -0000
> @@ -56,6 +56,7 @@
> #define RB_POWERDOWN 0x1000 /* attempt to power down machine */
> #define RB_SERCONS 0x2000 /* use serial console if available */
> #define RB_USERREQ 0x4000 /* boot() called at user request (e.g.
> ddb) */
> +#define RB_RESET 0x8000 /* do not try to cleanup, only for ddb
> */
>
> /*
> * Constants for converting boot-style device number to type,
>