Subject: Re: release
To: Adam Glass <glass@SUN-LAMP.CS.BERKELEY.EDU>
From: Chuck Silvers <>
List: port-sun3
Date: 02/08/1994 02:15:29
Ok, here's the guts of it, ramd.c:

#include <sys/param.h>
#include <sys/buf.h>

#define RAMD_SIZE (256 * 1024)

char ramd_image[RAMD_SIZE] = {0};

ramdopen(dev_t dev, int flags, int ifmt, struct proc *p)
    printf("ramdopen 0x%x\n", dev);

ramdstrategy(register struct buf *bp)
    int offset, count;

    printf("ramdstrat: blkno 0x%x bcount 0x%x\n", bp->b_blkno, bp->b_bcount);

    if (minor(bp->b_dev) != 0) {
        bp->b_error = EINVAL;
        bp->b_flags |= B_ERROR;

    offset = bp->b_blkno * DEV_BSIZE;
    count = bp->b_bcount;

    if (offset + count > RAMD_SIZE) {
        bp->b_error = EINVAL;
        bp->b_flags |= B_ERROR;

    if (bp->b_flags & B_READ) {
        bcopy(&ramd_image[offset], bp->b_un.b_addr, count);
    else {
        bcopy(bp->b_un.b_addr, &ramd_image[offset], count);

    bp->b_resid = 0;

    printf("ramdstrat: done\n");

ramdioctl(dev_t dev, int cmd, register caddr_t data, int flag, struct proc *p)
    printf("ramdioctl 0x%x\n", dev);
    return -1;

ramddump(dev_t dev, daddr_t blkoff, caddr_t addr, int len)
    return 0;

ramdsize(dev_t dev)
    return (RAMD_SIZE/DEV_BSIZE);


The necessary glue is:
in sun3/conf.c, add
in the appropriate places.

Figuring out how to hook this in so it was used as the root device
wasn't as clear in -current as it was in the magnum stuff,
what I did was to insert
    rootdev = makedev(3,0);
    swapdev = makedev(3,1);
    swdevt[0].sw_dev = makedev(3,1);
    swdevt[0].sw_freed = 0;
at the end of configure() in sun3/autoconf.c and to put in

extern int ufs_mountroot();
int (*mountroot)() = ufs_mountroot;

in the same file.  Then I just used

config netbsd swap generic

in the config file.  This didn't quite work in -current, but I think
it's pretty close.  I think the bits for dealing with swap are what
is wrong, but I don't know enough about that stuff to know for sure.
It would be good if there was a simple way to just run without any
swap space.

Then to initialize the ramdisk image, I ran

lwrite netbsd `echo 'ramd_image-0xe004000+0x20=D' |adb netbsd` < ~/fs.image.256

where fs.image.256 is an itty-bitty filesystem image and
lwrite is:

#include <ctype.h>
#include <stdio.h>
#include <sys/file.h>
#include <strings.h>

int hextoi(s)
char *s;
    int i = 0;
    static char *hex = "0123456789abcdef";

    while (*s) {
        i <<= 4;
        i += index(hex, isupper(*s) ? *s | 0x20 : *s) - hex;

    return i;

main(argc, argv)
int argc;
char **argv;
    int fd, offset, len;
    char buf[1024];

    if (argc != 3) {
        fputs("usage: lwrite [filename] [offset]\n", stderr);

    if ((fd = open(argv[1], O_WRONLY, 0666)) == -1) {
        fputs("lread: could not open ", stderr);
        fputs(argv[1], stderr);
        fputs("\n", stderr);

    offset = (argv[2][0] == '0' && argv[2][1] == 'x') ?
        hextoi(argv[2] + 2) : atoi(argv[2]);

    lseek(fd, offset, L_SET);

    for (;;) {
        if ((len = read(0, buf, sizeof(buf))) <= 0)
        write(fd, buf, len);

I think that's all of it.  A little rough, I must admit.