summaryrefslogtreecommitdiff
path: root/sys/arch/sparc64/stand
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2009-11-04 12:03:58 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2009-11-04 12:03:58 +0000
commit395273a1e83ae3df343a3bb6db9f55b471d20325 (patch)
tree90e226468e2ed13797aed158a647a62e8b4e1144 /sys/arch/sparc64/stand
parente9c829b4e1c51318cb40adbd0b53553f1a830e8f (diff)
Replace the #ifdef NON_DEBUG and #ifdef NOTDEF_DEBUG mess with more sane
DPRINTF/DNPRINTF() debugging.
Diffstat (limited to 'sys/arch/sparc64/stand')
-rw-r--r--sys/arch/sparc64/stand/ofwboot/boot.c9
-rw-r--r--sys/arch/sparc64/stand/ofwboot/netif_of.c79
-rw-r--r--sys/arch/sparc64/stand/ofwboot/ofdev.c111
-rw-r--r--sys/arch/sparc64/stand/ofwboot/ofdev.h14
4 files changed, 84 insertions, 129 deletions
diff --git a/sys/arch/sparc64/stand/ofwboot/boot.c b/sys/arch/sparc64/stand/ofwboot/boot.c
index 3e96a9bcdef..7568304346c 100644
--- a/sys/arch/sparc64/stand/ofwboot/boot.c
+++ b/sys/arch/sparc64/stand/ofwboot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.15 2009/08/17 14:23:09 jsing Exp $ */
+/* $OpenBSD: boot.c,v 1.16 2009/11/04 12:03:57 jsing Exp $ */
/* $NetBSD: boot.c,v 1.3 2001/05/31 08:55:19 mrg Exp $ */
/*
* Copyright (c) 1997, 1999 Eduardo E. Horvath. All rights reserved.
@@ -59,6 +59,13 @@
#include "ofdev.h"
#include "openfirm.h"
+#ifdef BOOT_DEBUG
+uint32_t boot_debug = 0
+ /* | BOOT_D_OFDEV */
+ /* | BOOT_D_OFNET */
+ ;
+#endif
+
#define MEG (1024*1024)
/*
diff --git a/sys/arch/sparc64/stand/ofwboot/netif_of.c b/sys/arch/sparc64/stand/ofwboot/netif_of.c
index 513a9d34aed..ba43731d775 100644
--- a/sys/arch/sparc64/stand/ofwboot/netif_of.c
+++ b/sys/arch/sparc64/stand/ofwboot/netif_of.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netif_of.c,v 1.5 2009/08/17 14:23:09 jsing Exp $ */
+/* $OpenBSD: netif_of.c,v 1.6 2009/11/04 12:03:57 jsing Exp $ */
/* $NetBSD: netif_of.c,v 1.1 2000/08/20 14:58:39 mrg Exp $ */
/*
@@ -76,15 +76,12 @@ netif_open(void *machdep_hint)
int fd, error;
char addr[32];
-#ifdef NETIF_DEBUG
- printf("netif_open...");
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_open...");
+
/* find a free socket */
io = sockets;
if (io->io_netif) {
-#ifdef NETIF_DEBUG
- printf("device busy\n");
-#endif
+ DNPRINTF(BOOT_D_OFNET, "device busy\n");
errno = ENFILE;
return -1;
}
@@ -97,9 +94,7 @@ netif_open(void *machdep_hint)
OF_getprop(OF_instance_to_package(op->handle),
"mac-address", io->myea, sizeof io->myea);
-#ifdef NETIF_DEBUG
- printf("OK\n");
-#endif
+ DNPRINTF(BOOT_D_OFNET, "OK\n");
return 0;
}
@@ -109,13 +104,10 @@ netif_close(int fd)
struct iodesc *io;
struct netif *ni;
-#ifdef NETIF_DEBUG
- printf("netif_close(%x)...", fd);
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_close(%x)...", fd);
+
if (fd != 0) {
-#ifdef NETIF_DEBUG
- printf("EBADF\n");
-#endif
+ DNPRINTF(BOOT_D_OFNET, "EBADF\n");
errno = EBADF;
return -1;
}
@@ -126,9 +118,8 @@ netif_close(int fd)
ni->nif_devdata = NULL;
io->io_netif = NULL;
}
-#ifdef NETIF_DEBUG
- printf("OK\n");
-#endif
+
+ DNPRINTF(BOOT_D_OFNET, "OK\n");
return 0;
}
@@ -145,32 +136,23 @@ netif_put(struct iodesc *desc, void *pkt, size_t len)
op = desc->io_netif->nif_devdata;
-#ifdef NETIF_DEBUG
- {
- struct ether_header *eh;
-
- printf("netif_put: desc=0x%x pkt=0x%x len=%d\n",
- desc, pkt, len);
- eh = pkt;
- printf("dst: %s ", ether_sprintf(eh->ether_dhost));
- printf("src: %s ", ether_sprintf(eh->ether_shost));
- printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
- }
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_put: desc=0x%x pkt=0x%x len=%d\n",
+ desc, pkt, len);
+ DNPRINTF(BOOT_D_OFNET, "dst: %s, src: %s, type: 0x%x\n",
+ ether_sprintf(((struct ether_header *)pkt)->ether_dhost),
+ ether_sprintf(((struct ether_header *)pkt)->ether_shost),
+ ((struct ether_header *)pkt)->ether_type & 0xFFFF);
sendlen = len;
if (sendlen < 60) {
sendlen = 60;
-#ifdef NETIF_DEBUG
- printf("netif_put: length padded to %d\n", sendlen);
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_put: length padded to %d\n",
+ sendlen);
}
rv = OF_write(op->handle, pkt, sendlen);
-#ifdef NETIF_DEBUG
- printf("netif_put: xmit returned %d\n", rv);
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_put: xmit returned %d\n", rv);
return rv;
}
@@ -188,10 +170,8 @@ netif_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timo)
op = desc->io_netif->nif_devdata;
-#ifdef NETIF_DEBUG
- printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
- pkt, maxlen, timo);
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
+ pkt, maxlen, timo);
tmo_ms = timo * 1000;
tick0 = OF_milliseconds();
@@ -201,22 +181,15 @@ netif_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timo)
} while ((len == -2 || len == 0) &&
(OF_milliseconds() - tick0 < tmo_ms));
-#ifdef NETIF_DEBUG
- printf("netif_get: received len=%d\n", len);
-#endif
+ DNPRINTF(BOOT_D_OFNET, "netif_get: received len=%d\n", len);
if (len < 12)
return -1;
-#ifdef NETIF_DEBUG
- {
- struct ether_header *eh = pkt;
-
- printf("dst: %s ", ether_sprintf(eh->ether_dhost));
- printf("src: %s ", ether_sprintf(eh->ether_shost));
- printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
- }
-#endif
+ DNPRINTF(BOOT_D_OFNET, "dst: %s, src: %s, type: 0x%x\n",
+ ether_sprintf(((struct ether_header *)pkt)->ether_dhost),
+ ether_sprintf(((struct ether_header *)pkt)->ether_shost),
+ ((struct ether_header *)pkt)->ether_type & 0xFFFF);
return len;
}
diff --git a/sys/arch/sparc64/stand/ofwboot/ofdev.c b/sys/arch/sparc64/stand/ofwboot/ofdev.c
index e3ab41451a5..325051b0400 100644
--- a/sys/arch/sparc64/stand/ofwboot/ofdev.c
+++ b/sys/arch/sparc64/stand/ofwboot/ofdev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofdev.c,v 1.11 2009/08/17 14:23:09 jsing Exp $ */
+/* $OpenBSD: ofdev.c,v 1.12 2009/11/04 12:03:57 jsing Exp $ */
/* $NetBSD: ofdev.c,v 1.1 2000/08/20 14:58:41 mrg Exp $ */
/*
@@ -77,19 +77,16 @@ filename(char *str, char *ppart)
*cp = 0;
/* ...look whether there is a device with this name */
dhandle = OF_finddevice(str);
-#ifdef NOTDEF_DEBUG
- printf("filename: OF_finddevice(%s) says %x\n",
- str, dhandle);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "filename: OF_finddevice(%s) says %x\n",
+ str, dhandle);
*cp = savec;
if (dhandle == -1) {
/* if not, lp is the delimiter between device and path */
/* if the last component was a block device... */
if (!strcmp(devtype, "block")) {
/* search for arguments */
-#ifdef NOTDEF_DEBUG
- printf("filename: hunting for arguments in %s\n", str);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "filename: hunting for "
+ "arguments in %s\n", str);
for (cp = lp;
--cp >= str && *cp != '/' && *cp != '-';);
if (cp >= str && *cp == '-') {
@@ -100,16 +97,12 @@ filename(char *str, char *ppart)
*ppart = *cp;
}
}
-#ifdef NOTDEF_DEBUG
- printf("filename: found %s\n",lp);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "filename: found %s\n", lp);
return lp;
} else if (OF_getprop(dhandle, "device_type", devtype, sizeof devtype) < 0)
devtype[0] = 0;
}
-#ifdef NOTDEF_DEBUG
- printf("filename: not found\n",lp);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "filename: not found\n", lp);
return 0;
}
@@ -126,23 +119,18 @@ strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
if (dev->type != OFDEV_DISK)
panic("strategy");
-#ifdef NON_DEBUG
- printf("strategy: block %lx, partition offset %lx, blksz %lx\n",
- (long)blk, (long)dev->partoff, (long)dev->bsize);
- printf("strategy: seek position should be: %lx\n",
- (long)((blk + dev->partoff) * dev->bsize));
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "strategy: block %lx, partition offset %lx, "
+ "blksz %lx\n", (long)blk, (long)dev->partoff, (long)dev->bsize);
+ DNPRINTF(BOOT_D_OFDEV, "strategy: seek position should be: %lx\n",
+ (long)((blk + dev->partoff) * dev->bsize));
pos = (u_quad_t)(blk + dev->partoff) * dev->bsize;
for (;;) {
-#ifdef NON_DEBUG
- printf("strategy: seeking to %lx\n", (long)pos);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "strategy: seeking to %lx\n", (long)pos);
if (OF_seek(dev->handle, pos) < 0)
break;
-#ifdef NON_DEBUG
- printf("strategy: reading %lx at %p\n", (long)size, buf);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "strategy: reading %lx at %p\n",
+ (long)size, buf);
n = OF_read(dev->handle, buf, size);
if (n == -2)
continue;
@@ -209,6 +197,7 @@ get_long(const void *p)
return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
}
+
/************************************************************************
*
* The rest of this was taken from arch/sparc64/scsi/sun_disklabel.c
@@ -284,9 +273,8 @@ disklabel_sun_to_bsd(char *cp, struct disklabel *lp)
npp = &lp->d_partitions[i];
npp->p_offset = spp->sdkp_cyloffset * secpercyl;
npp->p_size = spp->sdkp_nsectors;
-#ifdef NOTDEF_DEBUG
- printf("partition %d start %x size %x\n", i, (int)npp->p_offset, (int)npp->p_size);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "partition %d start %x size %x\n",
+ i, (int)npp->p_offset, (int)npp->p_size);
if (npp->p_size == 0) {
npp->p_fstype = FS_UNUSED;
} else {
@@ -305,9 +293,7 @@ disklabel_sun_to_bsd(char *cp, struct disklabel *lp)
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
-#ifdef NOTDEF_DEBUG
- printf("disklabel_sun_to_bsd: success!\n");
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "disklabel_sun_to_bsd: success!\n");
return (NULL);
}
@@ -345,9 +331,7 @@ search_label(struct of_dev *devp, u_long off, char *buf, struct disklabel *lp,
if (dkcksum(dlp))
return ("NetBSD disk label corrupted");
*lp = *dlp;
-#ifdef NOTDEF_DEBUG
- printf("search_label: found NetBSD label\n");
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "search_label: found NetBSD label\n");
return (NULL);
}
@@ -378,9 +362,7 @@ devopen(struct open_file *of, const char *name, char **file)
panic("devopen");
if (of->f_flags != F_READ)
return EPERM;
-#ifdef NOTDEF_DEBUG
- printf("devopen: you want %s\n", name);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: you want %s\n", name);
strlcpy(fname, name, sizeof fname);
cp = filename(fname, &partition);
if (cp) {
@@ -402,51 +384,37 @@ devopen(struct open_file *of, const char *name, char **file)
strlcat(opened_name, "/", sizeof opened_name);
strlcat(opened_name, buf, sizeof opened_name);
*file = opened_name + strlen(fname) + 1;
-#ifdef NOTDEF_DEBUG
- printf("devopen: trying %s\n", fname);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: trying %s\n", fname);
if ((handle = OF_finddevice(fname)) == -1)
return ENOENT;
-#ifdef NOTDEF_DEBUG
- printf("devopen: found %s\n", fname);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: found %s\n", fname);
if (OF_getprop(handle, "name", buf, sizeof buf) < 0)
return ENXIO;
-#ifdef NOTDEF_DEBUG
- printf("devopen: %s is called %s\n", fname, buf);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: %s is called %s\n", fname, buf);
if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0)
return ENXIO;
-#ifdef NOTDEF_DEBUG
- printf("devopen: %s is a %s device\n", fname, buf);
-#endif
-#ifdef NOTDEF_DEBUG
- printf("devopen: opening %s\n", fname);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: %s is a %s device\n", fname, buf);
+ DNPRINTF(BOOT_D_OFDEV, "devopen: opening %s\n", fname);
if ((handle = OF_open(fname)) == -1) {
-#ifdef NOTDEF_DEBUG
- printf("devopen: open of %s failed\n", fname);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: open of %s failed\n", fname);
return ENXIO;
}
-#ifdef NOTDEF_DEBUG
- printf("devopen: %s is now open\n", fname);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: %s is now open\n", fname);
bzero(&ofdev, sizeof ofdev);
ofdev.handle = handle;
if (!strcmp(buf, "block")) {
ofdev.type = OFDEV_DISK;
ofdev.bsize = DEV_BSIZE;
/* First try to find a disklabel without MBR partitions */
-#ifdef NOTDEF_DEBUG
- printf("devopen: trying to read disklabel\n");
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: trying to read disklabel\n");
if (strategy(&ofdev, F_READ,
LABELSECTOR, DEV_BSIZE, buf, &read) != 0
|| read != DEV_BSIZE
|| (errmsg = getdisklabel(buf, &label))) {
-#ifdef NOTDEF_DEBUG
- if (errmsg) printf("devopen: getdisklabel says %s\n", errmsg);
+#ifdef BOOT_DEBUG
+ if (errmsg)
+ DNPRINTF(BOOT_D_OFDEV,
+ "devopen: getdisklabel says %s\n", errmsg);
#endif
/* Else try MBR partitions */
errmsg = search_label(&ofdev, 0, buf, &label, 0);
@@ -467,10 +435,8 @@ devopen(struct open_file *of, const char *name, char **file)
} else {
part = partition ? partition - 'a' : 0;
ofdev.partoff = label.d_partitions[part].p_offset;
-#ifdef NOTDEF_DEBUG
- printf("devopen: setting partition %d offset %x\n",
- part, ofdev.partoff);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: setting partition %d "
+ "offset %x\n", part, ofdev.partoff);
}
of->f_dev = devsw;
@@ -482,9 +448,7 @@ devopen(struct open_file *of, const char *name, char **file)
bcopy(&file_system_cd9660, &file_system[nfsys++],
sizeof file_system[0]);
#endif
-#ifdef NOTDEF_DEBUG
- printf("devopen: return 0\n");
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: return 0\n");
return 0;
}
#ifdef NETBOOT
@@ -501,9 +465,8 @@ devopen(struct open_file *of, const char *name, char **file)
#endif
error = EFTYPE;
bad:
-#ifdef NOTDEF_DEBUG
- printf("devopen: error %d, cannot open device\n", error);
-#endif
+ DNPRINTF(BOOT_D_OFDEV, "devopen: error %d, cannot open device\n",
+ error);
OF_close(handle);
ofdev.handle = -1;
return error;
diff --git a/sys/arch/sparc64/stand/ofwboot/ofdev.h b/sys/arch/sparc64/stand/ofwboot/ofdev.h
index c4091be46dd..33cc9328561 100644
--- a/sys/arch/sparc64/stand/ofwboot/ofdev.h
+++ b/sys/arch/sparc64/stand/ofwboot/ofdev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofdev.h,v 1.3 2001/08/22 04:30:52 jason Exp $ */
+/* $OpenBSD: ofdev.h,v 1.4 2009/11/04 12:03:57 jsing Exp $ */
/* $NetBSD: ofdev.h,v 1.1 2000/08/20 14:58:41 mrg Exp $ */
/*
@@ -34,6 +34,18 @@
#ifndef _STAND_DEV_H_
#define _STAND_DEV_H_
+/* #define BOOT_DEBUG */
+#ifdef BOOT_DEBUG
+extern u_int32_t boot_debug;
+#define DPRINTF(x...) do { if (boot_debug) printf(x); } while(0)
+#define DNPRINTF(n,x...) do { if (boot_debug & n) printf(x); } while(0)
+#define BOOT_D_OFDEV 0x0001
+#define BOOT_D_OFNET 0x0002
+#else
+#define DPRINTF(x...)
+#define DNPRINTF(n,x...)
+#endif
+
struct of_dev {
int handle;
int type;