NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-sh3/51724: landisk fails to reboot



>Number:         51724
>Category:       port-sh3
>Synopsis:       landisk fails to reboot
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sh3-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 16 05:10:00 +0000 2016
>Originator:     Rin Okuyama
>Release:        7.99.49
>Organization:
Faculty of Science and Technology, Keio University
>Environment:
NetBSD usl5p 7.99.49 NetBSD 7.99.49 (USL-5P_RO) #0: Fri Dec 16 04:39:06 JST 2016  rin@latipes:/var/build/src/sys/arch/landisk/compile/USL-5P_RO landisk
>Description:
USL-5P does not reboot, but falls into infinite loop instead. This is
because the reset instructions are not executed. The followings are the
original source code and its objdump:

src/sys/landisk/landisk/machdep.c

  377  void
  378  machine_reset(void)
  379  {
  380
  381          _cpu_exception_suspend();
  382          _reg_write_4(SH_(EXPEVT), EXPEVT_RESET_MANUAL);
  383          (void)*(volatile uint32_t *)0x80000001; /* CPU shutdown */
  384
  385          /*NOTREACHED*/
  386          for (;;) {
  387                  continue;
  388          }
  389  }

objdump -d machdep.o

  00000244 <machine_reset>:
   244:   22 4f           sts.l   pr,@-r15
   246:   06 d0           mov.l   260 <machine_reset+0x1c>,r0     ! 0 <sysctl_machdep_setup>
   248:   0b 40           jsr     @r0
   24a:   09 00           nop
   24c:   05 d1           mov.l   264 <machine_reset+0x20>,r1     ! ff000024
   24e:   20 e2           mov     #32,r2
   250:   22 21           mov.l   r2,@r1
   252:   05 d2           mov.l   268 <machine_reset+0x24>,r2     ! 80000001
   254:   20 61           mov.b   @r2,r1
   256:   21 84           mov.b   @(1,r2),r0
   258:   22 84           mov.b   @(2,r2),r0
   25a:   23 84           mov.b   @(3,r2),r0
   25c:   fe af           bra     25c <machine_reset+0x18>
   25e:   09 00           nop
   260:   00 00           .word 0x0000
   262:   00 00           .word 0x0000
   264:   24 00           mov.b   r2,@(r0,r0)
   266:   00 ff           .word 0xff00
   268:   01 00           .word 0x0001
   26a:   00 80           mov.b   r0,@(0,r0)

You can see that 0x80000001 at 0x268 is never executed. This is probably
because the behavior of GCC has been changed. As a work around, replace

  383          (void)*(volatile uint32_t *)0x80000001; /* CPU shutdown */

with

  383          goto *(void *)0x80000001; /* CPU shutdown */

as in a similar manner to src/sys/arch/sh3/sh3/sh3_machdep.c. Then,
objdump yields

  00000244 <machine_reset>:
   244:   22 4f           sts.l   pr,@-r15
   246:   04 d0           mov.l   258 <machine_reset+0x14>,r0     ! 0 <sysctl_machdep_setup>
   248:   0b 40           jsr     @r0
   24a:   09 00           nop
   24c:   03 d1           mov.l   25c <machine_reset+0x18>,r1     ! ff000024
   24e:   20 e2           mov     #32,r2
   250:   22 21           mov.l   r2,@r1
   252:   03 d1           mov.l   260 <machine_reset+0x1c>,r1     ! 80000001
   254:   2b 41           jmp     @r1
   256:   09 00           nop
   258:   00 00           .word 0x0000
   25a:   00 00           .word 0x0000
   25c:   24 00           mov.b   r2,@(r0,r0)
   25e:   00 ff           .word 0xff00
   260:   01 00           .word 0x0001
   262:   00 80           mov.b   r0,@(0,r0)

and the system reboots successfully.

Better fix may be use cpu_reset() in sh3_machdep.c. Please find the
attached patch. I've confirmed that it does not break other sh3 ports.
>How-To-Repeat:
Attempt "reboot" or "shutdown -r" on landisk boxes.
>Fix:
--- src/sys/arch/landisk/conf/std.landisk.orig	2016-12-16 03:24:16.391310471 +0900
+++ src/sys/arch/landisk/conf/std.landisk	2016-12-16 04:31:02.580040861 +0900
@@ -15,4 +15,6 @@
 options 	IOM_RAM_BEGIN=0x0c000000
 options 	IOM_RAM_SIZE=0x04000000         # 64MB
 
+options 	RESET_INSTR=0x80000001
+
 makeoptions	DEFTEXTADDR="0x8c001000"
--- src/sys/arch/landisk/landisk/machdep.c.orig	2016-12-16 03:14:04.567471879 +0900
+++ src/sys/arch/landisk/landisk/machdep.c	2016-12-16 04:31:19.030692713 +0900
@@ -366,21 +366,7 @@
 #endif
 
 	printf("rebooting...\n");
-	machine_reset();
-
-	/*NOTREACHED*/
-	for (;;) {
-		continue;
-	}
-}
-
-void
-machine_reset(void)
-{
-
-	_cpu_exception_suspend();
-	_reg_write_4(SH_(EXPEVT), EXPEVT_RESET_MANUAL);
-	(void)*(volatile uint32_t *)0x80000001;	/* CPU shutdown */
+	cpu_reset();
 
 	/*NOTREACHED*/
 	for (;;) {
--- src/sys/arch/sh3/sh3/sh3_machdep.c.orig	2016-12-16 03:19:31.920134296 +0900
+++ src/sys/arch/sh3/sh3/sh3_machdep.c	2016-12-16 04:30:45.202026098 +0900
@@ -134,6 +134,11 @@
 #ifdef SH4
 extern char sh4_vector_tlbmiss[], sh4_vector_tlbmiss_end[];
 #endif
+
+#ifndef RESET_INSTR
+#define RESET_INSTR 0xa0000000
+#endif
+
 /*
  * These variables are needed by /sbin/savecore
  */
@@ -559,7 +564,7 @@
 	_reg_write_4(SH_(EXPEVT), EXPEVT_RESET_MANUAL);
 
 #ifndef __lint__
-	goto *(void *)0xa0000000;
+	goto *(void *)RESET_INSTR;
 #endif
 	/* NOTREACHED */
 }



Home | Main Index | Thread Index | Old Index