Module Name:    src
Committed By:   isaki
Date:           Tue Aug  5 13:49:04 UTC 2014

Modified Files:
        src/sys/arch/x68k/stand/boot: Makefile boot.c
        src/sys/arch/x68k/stand/netboot: Makefile
Added Files:
        src/sys/arch/x68k/stand/boot: switch.c switch.h

Log Message:
Support a 'switch' command.
It displays/modifies some SRAM parameters on X680x0, like as
memswitch(1) or Human68k's SWITCH.X .
It makes easy to change the boot devices or correct the inconsistency
of SRAM/real memory size.

sample usage:
 > switch show         .. show all supported parameters
 > switch boot=std     .. set boot order to 'STD'
 > switch memory=12    .. set memory size to 12MB


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/x68k/stand/boot/Makefile
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x68k/stand/boot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/x68k/stand/boot/switch.c \
    src/sys/arch/x68k/stand/boot/switch.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/stand/netboot/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x68k/stand/boot/Makefile
diff -u src/sys/arch/x68k/stand/boot/Makefile:1.23 src/sys/arch/x68k/stand/boot/Makefile:1.24
--- src/sys/arch/x68k/stand/boot/Makefile:1.23	Sun Jul  6 06:28:49 2014
+++ src/sys/arch/x68k/stand/boot/Makefile	Tue Aug  5 13:49:04 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.23 2014/07/06 06:28:49 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.24 2014/08/05 13:49:04 isaki Exp $
 
 NOMAN=		# defined
 
@@ -22,7 +22,7 @@ BFDNAME=	a.out-m68k-netbsd
 STRIP?=		/usr/bin/strip
 OBJCOPY?=	/usr/bin/objcopy
 
-SRCS=		srt0.S boot.c conf.c exec_image.S
+SRCS=		srt0.S boot.c conf.c switch.c exec_image.S
 S=		${.CURDIR}/../../../..
 M=		${.CURDIR}/../..
 COMMONDIR=	$M/stand/common

Index: src/sys/arch/x68k/stand/boot/boot.c
diff -u src/sys/arch/x68k/stand/boot/boot.c:1.21 src/sys/arch/x68k/stand/boot/boot.c:1.22
--- src/sys/arch/x68k/stand/boot/boot.c:1.21	Sun Jul  6 08:10:21 2014
+++ src/sys/arch/x68k/stand/boot/boot.c	Tue Aug  5 13:49:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.21 2014/07/06 08:10:21 tsutsui Exp $	*/
+/*	$NetBSD: boot.c,v 1.22 2014/08/05 13:49:04 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -39,6 +39,7 @@
 
 #include "libx68k.h"
 #include "iocs.h"
+#include "switch.h"
 
 #include "exec_image.h"
 
@@ -122,6 +123,7 @@ help(void)
 #ifndef NETBOOT
 	printf("ls [dev:][directory]\n");
 #endif
+	printf("switch [show | key=val]\n");
 	printf("halt\nreboot\n");
 }
 
@@ -318,6 +320,8 @@ bootmenu(void)
 		else if (strcmp("halt", p) == 0 ||
 			 strcmp("reboot", p) == 0)
 			exit(0);
+		else if (strcmp("switch", p) == 0)
+			cmd_switch(options);
 #ifndef NETBOOT
 		else if (strcmp("ls", p) == 0)
 			cmd_ls(options);

Index: src/sys/arch/x68k/stand/netboot/Makefile
diff -u src/sys/arch/x68k/stand/netboot/Makefile:1.3 src/sys/arch/x68k/stand/netboot/Makefile:1.4
--- src/sys/arch/x68k/stand/netboot/Makefile:1.3	Sun Jul  6 06:28:49 2014
+++ src/sys/arch/x68k/stand/netboot/Makefile	Tue Aug  5 13:49:04 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.3 2014/07/06 06:28:49 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.4 2014/08/05 13:49:04 isaki Exp $
 
 NOMAN=		# defined
 
@@ -29,7 +29,7 @@ OBJCOPY?=	/usr/bin/objcopy
 BOOTDIR=	${.CURDIR}/../boot
 .PATH:		${BOOTDIR}
 
-SRCS=		srt0.S boot.c conf.c exec_image.S if_ne.c ne.c dp8390.c
+SRCS=		srt0.S boot.c conf.c switch.c exec_image.S if_ne.c ne.c dp8390.c
 S=		${.CURDIR}/../../../..
 M=		${.CURDIR}/../..
 COMMONDIR=	$M/stand/common

Added files:

Index: src/sys/arch/x68k/stand/boot/switch.c
diff -u /dev/null src/sys/arch/x68k/stand/boot/switch.c:1.1
--- /dev/null	Tue Aug  5 13:49:04 2014
+++ src/sys/arch/x68k/stand/boot/switch.c	Tue Aug  5 13:49:04 2014
@@ -0,0 +1,330 @@
+/*	$NetBSD: switch.c,v 1.1 2014/08/05 13:49:04 isaki Exp $	*/
+
+/*
+ * Copyright (c) 2014 Tetsuya Isaki. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+
+#include "switch.h"
+
+#define SRAM_MEMSIZE	(*((volatile uint32_t *)0x00ed0008))
+#define SRAM_ROMADDR	(*((volatile uint32_t *)0x00ed000c))
+#define SRAM_RAMADDR	(*((volatile uint32_t *)0x00ed0010))
+#define SRAM_BOOTDEV	(*((volatile uint16_t *)0x00ed0018))
+
+#define SYSPORT_SRAM_WP	(*((volatile uint8_t *)0x00e8e00d))
+
+static int hextoi(const char *);
+static void cmd_switch_help(void);
+static void cmd_switch_show(void);
+static void cmd_switch_show_boot(void);
+static void cmd_switch_show_rom(void);
+static void cmd_switch_show_memory(void);
+static const char *romaddr_tostr(uint32_t);
+static const char *get_romaddr_name(uint32_t);
+static void cmd_switch_boot(const char *);
+static void cmd_switch_rom(const char *);
+static void cmd_switch_memory(const char *);
+
+static inline void
+sram_write_enable(void)
+{
+	SYSPORT_SRAM_WP = 0x31;
+}
+
+static inline void
+sram_write_disable(void)
+{
+	SYSPORT_SRAM_WP = 0;
+}
+
+static int
+atoi(const char *in)
+{
+	char *c;
+	int ret;
+
+	ret = 0;
+	c = (char *)in;
+	if (*c == '-')
+		c++;
+	for (; isdigit(*c); c++)
+		ret = (ret * 10) + (*c - '0');
+
+	return (*in == '-') ? -ret : ret;
+}
+
+static int
+hextoi(const char *in)
+{
+	char *c;
+	int ret;
+
+	ret = 0;
+	c = (char *)in;
+	for (; isxdigit(*c); c++) {
+		ret = (ret * 16) +
+		      (*c > '9' ? ((*c | 0x20) - 'a' + 10) : *c - '0');
+	}
+	return ret;
+}
+
+static void
+cmd_switch_help(void)
+{
+	printf(
+		"usage: switch <key>=<val>\n"
+		"         boot=[std | inscsi<N> | exscsi<N> | fd<N> | rom ]\n"
+		"         rom=[ inscsi<N> | exscsi<N> | $<addr> ]\n"
+		"         memory=<1..12> (unit:MB)\n"
+		"       switch show\n"
+	);
+}
+
+void
+cmd_switch(char *arg)
+{
+	char *val;
+
+	if (strcmp(arg, "show") == 0) {
+		cmd_switch_show();
+		return;
+	}
+
+	val = strchr(arg, '=');
+	if (val == NULL) {
+		cmd_switch_help();
+		return;
+	}
+	*val++ = '\0';
+
+	if (strcmp(arg, "boot") == 0) {
+		cmd_switch_boot(val);
+	} else if (strcmp(arg, "rom") == 0) {
+		cmd_switch_rom(val);
+	} else if (strcmp(arg, "memory") == 0) {
+		cmd_switch_memory(val);
+	} else {
+		cmd_switch_help();
+	}
+}
+
+static void
+cmd_switch_show(void)
+{
+	cmd_switch_show_boot();
+	cmd_switch_show_rom();
+	cmd_switch_show_memory();
+}
+
+static void
+cmd_switch_show_boot(void)
+{
+	uint32_t romaddr;
+	uint16_t bootdev;
+	const char *name;
+
+	bootdev = SRAM_BOOTDEV;
+	romaddr = SRAM_ROMADDR;
+
+	/*
+	 * $0000: std
+	 * $8n00: sasi<N>
+	 * $9n70: fd<N>
+	 * $a000: ROM
+	 * $b000: RAM
+	 */
+	printf("boot=");
+	switch (bootdev >> 12) {
+	default:
+	case 0x0:
+		/*
+		 * The real order is fd->sasi->rom->ram
+		 * but it is a bit redundant..
+		 */
+		printf("std (fd -> ");
+		name = get_romaddr_name(romaddr);
+		if (name)
+			printf("%s)", name);
+		else
+			printf("rom$%x)", romaddr);
+		break;
+	case 0x8:
+		printf("sasi%d", (bootdev >> 8) & 15);
+		break;
+	case 0x9:
+		printf("fd%d", (bootdev >> 8) & 3);
+		break;
+	case 0xa:
+		printf("rom%s", romaddr_tostr(romaddr));
+		break;
+	case 0xb:
+		printf("ram$%x", SRAM_RAMADDR);
+		break;
+	}
+	printf("\n");
+}
+
+static void
+cmd_switch_show_rom(void)
+{
+	uint32_t romaddr;
+
+	romaddr = SRAM_ROMADDR;
+	printf("rom=%s\n", romaddr_tostr(romaddr));
+}
+
+static void
+cmd_switch_show_memory(void)
+{
+	printf("memory=%d MB\n", SRAM_MEMSIZE / (1024 * 1024));
+}
+
+/* return rom address as string with name if any */
+static const char *
+romaddr_tostr(uint32_t addr)
+{
+	static char buf[32];
+	const char *name;
+
+	name = get_romaddr_name(addr);
+	if (name)
+		snprintf(buf, sizeof(buf), "$%x (%s)", addr, name);
+	else
+		snprintf(buf, sizeof(buf), "$%x", addr);
+
+	return buf;
+}
+
+/*
+ * return "inscsiN" / "exscsiN" if addr is in range of SCSI boot.
+ * Otherwise return NULL.
+ */
+static const char *
+get_romaddr_name(uint32_t addr)
+{
+	static char buf[8];
+
+	if (0xfc0000 <= addr && addr < 0xfc0020 && addr % 4 == 0) {
+		snprintf(buf, sizeof(buf), "inscsi%d", (addr >> 2) & 7);
+	} else if (0xea0020 <= addr && addr < 0xea0040 && addr % 4 == 0) {
+		snprintf(buf, sizeof(buf), "exscsi%d", (addr >> 2) & 7);
+	} else {
+		return NULL;
+	}
+	return buf;
+}
+
+static void
+cmd_switch_boot(const char *arg)
+{
+	int id;
+	uint32_t romaddr;
+	uint16_t bootdev;
+
+	romaddr = 0xffffffff;
+
+	if (strcmp(arg, "std") == 0) {
+		bootdev = 0x0000;
+
+	} else if (strcmp(arg, "rom") == 0) {
+		bootdev = 0xa000;
+
+	} else if (strncmp(arg, "inscsi", 6) == 0) {
+		id = (arg[6] - '0') & 7;
+		bootdev = 0xa000;
+		romaddr = 0xfc0000 + id * 4;
+
+	} else if (strncmp(arg, "exscsi", 6) == 0) {
+		id = (arg[6] - '0') & 7;
+		bootdev = 0xa000;
+		romaddr = 0xea0020 + id * 4;
+
+	} else if (strncmp(arg, "fd", 2) == 0) {
+		id = (arg[2] - '0') & 3;
+		bootdev = 0x9070 | (id << 8);
+
+	} else {
+		cmd_switch_help();
+		return;
+	}
+
+	sram_write_enable();
+	SRAM_BOOTDEV = bootdev;
+	if (romaddr != 0xffffffff)
+		SRAM_ROMADDR = romaddr;
+	sram_write_disable();
+
+	cmd_switch_show_boot();
+}
+
+static void
+cmd_switch_rom(const char *arg)
+{
+	int id;
+	uint32_t romaddr;
+
+	if (strncmp(arg, "inscsi", 6) == 0) {
+		id = (arg[6] - '0') & 7;
+		romaddr = 0xfc0000 + id * 4;
+
+	} else if (strncmp(arg, "exscsi", 6) == 0) {
+		id = (arg[6] - '0') & 7;
+		romaddr = 0xea0020 + id * 4;
+
+	} else if (*arg == '$') {
+		romaddr = hextoi(arg + 1);
+
+	} else {
+		cmd_switch_help();
+		return;
+	}
+
+	sram_write_enable();
+	SRAM_ROMADDR = romaddr;
+	sram_write_disable();
+
+	cmd_switch_show_rom();
+}
+
+static void
+cmd_switch_memory(const char *arg)
+{
+	int num;
+
+	num = atoi(arg);
+	if (num < 1 || num > 12) {
+		cmd_switch_help();
+		return;
+	}
+
+	sram_write_enable();
+	SRAM_MEMSIZE = num * (1024 * 1024);
+	sram_write_disable();
+
+	cmd_switch_show_memory();
+}
Index: src/sys/arch/x68k/stand/boot/switch.h
diff -u /dev/null src/sys/arch/x68k/stand/boot/switch.h:1.1
--- /dev/null	Tue Aug  5 13:49:04 2014
+++ src/sys/arch/x68k/stand/boot/switch.h	Tue Aug  5 13:49:04 2014
@@ -0,0 +1,28 @@
+/*	$NetBSD: switch.h,v 1.1 2014/08/05 13:49:04 isaki Exp $	*/
+
+/*
+ * Copyright (c) 2014 Tetsuya Isaki. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+extern void cmd_switch(char *);

Reply via email to