/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Minoura Makoto.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
#ifndef SRAMDEBUG
#include <machine/sram.h>
#else
/*
* SRAMDEBUG -- works on other (faster) platforms;
* store in a regular file instead of actual non-volatile static RAM.
*/
#include <sys/stat.h>
#define PATH_RAMFILE "/tmp/sramfile"
#endif
while ((ch = getopt(argc, argv, "whanrs")) != -1) {
switch (ch) {
case 'w': /* write */
mode = MD_WRITE;
break;
case 'h':
mode = MD_HELP;
break;
case 'a':
mode = MD_SHOWALL;
break;
case 'n':
nflag = 1;
break;
case 's':
mode = MD_SAVE;
break;
case 'r':
mode = MD_RESTORE;
break;
}
}
argc -= optind;
argv += optind;
switch (mode) {
case MD_NONE:
if (argc == 0)
usage();
while (argv[0]) {
show_single(argv[0]);
argv++;
}
break;
case MD_SHOWALL:
if (argc)
usage();
show_all();
break;
case MD_WRITE:
if (argc == 0)
usage();
while (argv[0]) {
modify_single (argv[0]);
argv++;
}
flush();
break;
case MD_HELP:
if (argc == 0)
usage();
while (argv[0]) {
help_single(argv[0]);
argv++;
}
break;
case MD_SAVE:
if (argc != 1)
usage();
save(argv[0]);
break;
case MD_RESTORE:
if (argc != 1)
usage();
restore(argv[0]);
break;
}
return 0;
}
void
show_single(const char *name)
{
int i;
int n = 0;
char fullname[50];
char valuestr[MAXVALUELEN];
for (i = 0; i < number_of_props; i++) {
snprintf(fullname, sizeof(fullname), "%s.%s",
properties[i].class, properties[i].node);
if (strcmp(name, fullname) == 0 || strcmp(name, properties[i].class) == 0) {
properties[i].print(&properties[i], valuestr);
if (!nflag)
printf("%s=%s\n", fullname, valuestr);
n++;
}
}
if (n == 0) {
errx(1, "No such %s: %s", strstr(name, ".")?"property":"class", name);
}
return;
}
void
show_all(void)
{
int i;
char valuestr[MAXVALUELEN];
for (i = 0; i < number_of_props; i++) {
properties[i].print(&properties[i], valuestr);
if (!nflag)
printf("%s.%s=",
properties[i].class, properties[i].node);
printf("%s\n", valuestr);
}
for (i = 0; i < number_of_props; i++) {
snprintf(fullname, sizeof(fullname), "%s.%s",
properties[i].class, properties[i].node);
if (strcmp(name, fullname) == 0) {
properties[i].print(&properties[i], valuestr);
if (!nflag)
printf("%s=", fullname);
printf("%s\n", valuestr);
printf("%s", properties[i].descr);
break;
}
}
if (i >= number_of_props) {
errx(1, "No such property: %s", name);
}
void
flush(void)
{
int i;
int sramfd = 0;
#ifndef SRAMDEBUG
struct sram_io buffer;
#endif
for (i = 0; i < number_of_props; i++) {
if (properties[i].modified)
properties[i].flush(&properties[i]);
}
if (modified_values == 0)
/* Not modified at all. */
return;
#ifndef SRAMDEBUG
/* Assume SRAM_IO_SIZE = n * 16. */
for (i = 0; i < 256; i += SRAM_IO_SIZE) {
if (memcmp(¤t_values[i], &modified_values[i],
SRAM_IO_SIZE) == 0)
continue;