Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x68k/stand Support a 'switch' command.
details: https://anonhg.NetBSD.org/src/rev/96eeb118d08d
branches: trunk
changeset: 331201:96eeb118d08d
user: isaki <isaki%NetBSD.org@localhost>
date: Tue Aug 05 13:49:04 2014 +0000
description:
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
diffstat:
sys/arch/x68k/stand/boot/Makefile | 4 +-
sys/arch/x68k/stand/boot/boot.c | 6 +-
sys/arch/x68k/stand/boot/switch.c | 330 +++++++++++++++++++++++++++++++++++
sys/arch/x68k/stand/boot/switch.h | 28 ++
sys/arch/x68k/stand/netboot/Makefile | 4 +-
5 files changed, 367 insertions(+), 5 deletions(-)
diffs (truncated from 436 to 300 lines):
diff -r aa9a4cf42913 -r 96eeb118d08d sys/arch/x68k/stand/boot/Makefile
--- a/sys/arch/x68k/stand/boot/Makefile Tue Aug 05 13:26:10 2014 +0000
+++ b/sys/arch/x68k/stand/boot/Makefile Tue Aug 05 13:49:04 2014 +0000
@@ -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 @@
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
diff -r aa9a4cf42913 -r 96eeb118d08d sys/arch/x68k/stand/boot/boot.c
--- a/sys/arch/x68k/stand/boot/boot.c Tue Aug 05 13:26:10 2014 +0000
+++ b/sys/arch/x68k/stand/boot/boot.c Tue Aug 05 13:49:04 2014 +0000
@@ -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 @@
#ifndef NETBOOT
printf("ls [dev:][directory]\n");
#endif
+ printf("switch [show | key=val]\n");
printf("halt\nreboot\n");
}
@@ -318,6 +320,8 @@
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);
diff -r aa9a4cf42913 -r 96eeb118d08d sys/arch/x68k/stand/boot/switch.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x68k/stand/boot/switch.c Tue Aug 05 13:49:04 2014 +0000
@@ -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)
+{
Home |
Main Index |
Thread Index |
Old Index