Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/memswitch Add -DDEBUG for debug. Can be debuged on...
details: https://anonhg.NetBSD.org/src/rev/8fcff087c689
branches: trunk
changeset: 474111:8fcff087c689
user: minoura <minoura%NetBSD.org@localhost>
date: Mon Jun 28 08:48:35 1999 +0000
description:
Add -DDEBUG for debug. Can be debuged on other (faster) platforms.
diffstat:
usr.sbin/memswitch/memswitch.c | 83 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 72 insertions(+), 11 deletions(-)
diffs (180 lines):
diff -r e6d9415279af -r 8fcff087c689 usr.sbin/memswitch/memswitch.c
--- a/usr.sbin/memswitch/memswitch.c Mon Jun 28 08:20:40 1999 +0000
+++ b/usr.sbin/memswitch/memswitch.c Mon Jun 28 08:48:35 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: memswitch.c,v 1.2 1999/06/25 14:27:55 minoura Exp $ */
+/* $NetBSD: memswitch.c,v 1.3 1999/06/28 08:48:35 minoura Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -44,10 +44,19 @@
#include <err.h>
#include <unistd.h>
#include <fcntl.h>
+#include <errno.h>
#include <sys/ioctl.h>
+#ifndef DEBUG
#include <machine/sram.h>
+#else
+/*
+ * DEBUG -- works on other (faster) platforms;
+ * store in a regular file instead of actual non-volatile static RAM.
+ */
+#define PATH_RAMFILE "/tmp/sramfile"
+#endif
#include "memswitch.h"
@@ -55,6 +64,7 @@
int nflag = 0;
u_int8_t *current_values = 0;
u_int8_t *modified_values = 0;
+
int main __P((int, char*[]));
void
@@ -295,6 +305,7 @@
void
alloc_current_values(void)
{
+#ifndef DEBUG
int i;
int sramfd = 0;
struct sram_io buffer;
@@ -316,6 +327,48 @@
}
close (sramfd);
+#else
+ int i;
+ int fd;
+ struct stat st;
+
+ current_values = malloc (256);
+ if (current_values == 0)
+ err (1, "malloc");
+
+ fd = open (PATH_RAMFILE, O_RDONLY);
+ if (fd < 0 && errno == ENOENT) {
+ modified_values = malloc (256);
+ if (modified_values == 0)
+ err (1, NULL);
+ for (i = 0; i < number_of_props; i++) {
+ properties[i].modified_value
+ = properties[i].default_value;
+ properties[i].modified = 1;
+ properties[i].flush (&properties[i]);
+ }
+
+ fd = creat (PATH_RAMFILE, 0666);
+ if (fd < 0)
+ err (1, "Creating %s", PATH_RAMFILE);
+ if (write (fd, modified_values, 256) != 256)
+ err (1, "Writing %s", PATH_RAMFILE);
+ close (fd);
+ free (modified_values);
+ modified_values = 0;
+
+ fd = open (PATH_RAMFILE, O_RDONLY);
+ }
+ if (fd < 0)
+ err (1, "Opening %s", PATH_RAMFILE);
+ if (fstat (fd, &st) < 0)
+ err (1, "fstat");
+ if (st.st_size != 256)
+ errx (1, "PANIC! INVALID RAMFILE");
+ if (read (fd, current_values, 256) != 256)
+ err (1, "reading %s", PATH_RAMFILE);
+ close (fd);
+#endif
properties[PROP_MAGIC1].fill (&properties[PROP_MAGIC1]);
properties[PROP_MAGIC2].fill (&properties[PROP_MAGIC2]);
@@ -329,7 +382,9 @@
{
int i;
int sramfd = 0;
+#ifndef DEBUG
struct sram_io buffer;
+#endif
for (i = 0; i < number_of_props; i++) {
if (properties[i].modified)
@@ -340,6 +395,7 @@
/* Not modified at all. */
return;
+#ifndef DEBUG
/* Assume SRAM_IO_SIZE = n * 16. */
for (i = 0; i < 256; i += SRAM_IO_SIZE) {
if (memcmp (¤t_values[i], &modified_values[i],
@@ -353,14 +409,16 @@
}
buffer.offset = i;
memcpy (buffer.sram, &modified_values[i], SRAM_IO_SIZE);
-#if 0 /* debug */
- printf ("Issuing ioctl(%d, SIOPSRAM, {%d, ...}\n",
- sramfd, buffer.offset);
-#else
if (ioctl (sramfd, SIOPSRAM, &buffer) < 0)
err (1, "ioctl");
+ }
+#else
+ sramfd = open (PATH_RAMFILE, O_WRONLY);
+ if (sramfd < 0)
+ err (1, "Opening %s", PATH_RAMFILE);
+ if (write (sramfd, modified_values, 256) != 256)
+ err (1, "Writing %s", PATH_RAMFILE);
#endif
- }
if (sramfd != 0)
close (sramfd);
@@ -372,6 +430,7 @@
save(name)
const char *name;
{
+#ifndef DEBUG
int fd;
alloc_current_values ();
@@ -389,6 +448,9 @@
if (fd != 1)
close (fd);
+#else
+ fprintf (stderr, "Skipping save...\n");
+#endif
return 0;
}
@@ -397,6 +459,7 @@
restore (name)
const char *name;
{
+#ifndef DEBUG
int sramfd, fd, i;
struct sram_io buffer;
@@ -420,16 +483,14 @@
for (i = 0; i < 256; i += SRAM_IO_SIZE) {
buffer.offset = i;
memcpy (buffer.sram, &modified_values[i], SRAM_IO_SIZE);
-#if 0 /* debug */
- printf ("Issuing ioctl(%d, SIOPSRAM, {%d, ...}\n",
- sramfd, buffer.offset);
-#else
if (ioctl (sramfd, SIOPSRAM, &buffer) < 0)
err (1, "ioctl");
-#endif
}
close (sramfd);
+#else
+ fprintf (stderr, "Skipping restore...\n");
+#endif
return 0;
}
Home |
Main Index |
Thread Index |
Old Index