add a simple disk driver, pass the path to the disk image on the kernel command line:
soundwave$ ./netbsd /tmp/test.fs NetBSD/usermode startup [...] ld0 at mainbus0: /tmp/test.fs (33554432) ld0: 32768 KB, 8322 cyl, 64 head, 63 sec, 1 bytes/sect x 33554432 sectors boot device: ld0 root on ld0a dumps on ld0b
This commit is contained in:
parent
cd366a78be
commit
ce6e29d2a8
@ -1,9 +1,9 @@
|
||||
# $NetBSD: GENERIC,v 1.8 2011/08/11 23:04:43 jmcneill Exp $
|
||||
# $NetBSD: GENERIC,v 1.9 2011/08/12 12:59:13 jmcneill Exp $
|
||||
|
||||
include "arch/usermode/conf/std.usermode"
|
||||
|
||||
options INCLUDE_CONFIG_FILE
|
||||
#ident "GENERIC-$Revision: 1.8 $"
|
||||
#ident "GENERIC-$Revision: 1.9 $"
|
||||
maxusers 32
|
||||
|
||||
makeoptions DEBUG="-g3"
|
||||
@ -43,5 +43,6 @@ mainbus0 at root
|
||||
cpu0 at mainbus?
|
||||
clock0 at mainbus?
|
||||
ttycons0 at mainbus?
|
||||
ld0 at mainbus?
|
||||
|
||||
pseudo-device loop
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.usermode,v 1.3 2011/06/12 03:35:48 rmind Exp $
|
||||
# $NetBSD: files.usermode,v 1.4 2011/08/12 12:59:13 jmcneill Exp $
|
||||
|
||||
maxpartitions 8
|
||||
maxusers 8 16 64
|
||||
@ -23,6 +23,9 @@ device ttycons { } : tty
|
||||
attach ttycons at thunkbus
|
||||
file arch/usermode/dev/ttycons.c ttycons
|
||||
|
||||
attach ld at thunkbus with ld_thunkbus
|
||||
file arch/usermode/dev/ld_thunkbus.c ld_thunkbus
|
||||
|
||||
file arch/usermode/usermode/copy.c
|
||||
file arch/usermode/usermode/machdep.c
|
||||
file arch/usermode/usermode/pmap.c
|
||||
@ -33,5 +36,6 @@ file arch/usermode/usermode/trap.c
|
||||
file arch/usermode/usermode/vm_machdep.c
|
||||
file dev/cons.c
|
||||
file dev/md_root.c memory_disk_hooks
|
||||
file kern/subr_disk_mbr.c disk
|
||||
|
||||
include "arch/usermode/conf/majors.usermode"
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: majors.usermode,v 1.1 2007/12/29 14:38:30 jmcneill Exp $
|
||||
# $NetBSD: majors.usermode,v 1.2 2011/08/12 12:59:13 jmcneill Exp $
|
||||
|
||||
device-major cons char 0
|
||||
device-major ctty char 1
|
||||
@ -10,3 +10,4 @@ device-major ptc char 6 pty
|
||||
device-major log char 7
|
||||
device-major com char 8 com
|
||||
device-major md char 24 block 17 md
|
||||
device-major ld char 69 block 19 ld
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $ */
|
||||
/* $NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
@ -323,8 +323,12 @@ cpu_rootconf(void)
|
||||
{
|
||||
device_t rdev;
|
||||
|
||||
rdev = device_find_by_xname("md0");
|
||||
rdev = device_find_by_xname("ld0");
|
||||
if (rdev == NULL)
|
||||
rdev = device_find_by_xname("md0");
|
||||
|
||||
aprint_normal("boot device: %s\n",
|
||||
rdev ? device_xname(rdev) : "<unknown>");
|
||||
setroot(rdev, 0);
|
||||
}
|
||||
|
||||
|
156
sys/arch/usermode/dev/ld_thunkbus.c
Normal file
156
sys/arch/usermode/dev/ld_thunkbus.c
Normal file
@ -0,0 +1,156 @@
|
||||
/* $NetBSD: ld_thunkbus.c,v 1.1 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
* 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 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.1 2011/08/12 12:59:13 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/disk.h>
|
||||
|
||||
#include <dev/ldvar.h>
|
||||
|
||||
#include <machine/mainbus.h>
|
||||
#include <machine/thunk.h>
|
||||
|
||||
static int ld_thunkbus_match(device_t, cfdata_t, void *);
|
||||
static void ld_thunkbus_attach(device_t, device_t, void *);
|
||||
|
||||
static int ld_thunkbus_ldstart(struct ld_softc *, struct buf *);
|
||||
static int ld_thunkbus_lddump(struct ld_softc *, void *, int, int);
|
||||
static int ld_thunkbus_ldflush(struct ld_softc *, int);
|
||||
|
||||
struct ld_thunkbus_softc {
|
||||
struct ld_softc sc_ld;
|
||||
|
||||
int sc_fd;
|
||||
struct stat sc_st;
|
||||
};
|
||||
|
||||
CFATTACH_DECL_NEW(ld_thunkbus, sizeof(struct ld_thunkbus_softc),
|
||||
ld_thunkbus_match, ld_thunkbus_attach, NULL, NULL);
|
||||
|
||||
extern int errno;
|
||||
|
||||
static int
|
||||
ld_thunkbus_match(device_t parent, cfdata_t match, void *opaque)
|
||||
{
|
||||
struct thunkbus_attach_args *taa = opaque;
|
||||
|
||||
if (taa->taa_type != THUNKBUS_TYPE_DISKIMAGE)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
ld_thunkbus_attach(device_t parent, device_t self, void *opaque)
|
||||
{
|
||||
struct ld_thunkbus_softc *sc = device_private(self);
|
||||
struct ld_softc *ld = &sc->sc_ld;
|
||||
struct thunkbus_attach_args *taa = opaque;
|
||||
const char *path = taa->u.diskimage.path;
|
||||
|
||||
ld->sc_dv = self;
|
||||
|
||||
sc->sc_fd = thunk_open(path, O_RDWR, 0);
|
||||
if (sc->sc_fd == -1) {
|
||||
aprint_error(": couldn't open %s: %d\n", path, errno);
|
||||
return;
|
||||
}
|
||||
if (thunk_fstat(sc->sc_fd, &sc->sc_st) == -1) {
|
||||
aprint_error(": couldn't stat %s: %d\n", path, errno);
|
||||
return;
|
||||
}
|
||||
|
||||
aprint_naive("\n");
|
||||
aprint_normal(": %s (%lld)\n", path, (long long)sc->sc_st.st_size);
|
||||
|
||||
ld->sc_flags = LDF_ENABLED;
|
||||
ld->sc_maxxfer = sc->sc_st.st_blksize;
|
||||
ld->sc_secsize = 1;
|
||||
ld->sc_secperunit = sc->sc_st.st_size;
|
||||
ld->sc_maxqueuecnt = 1;
|
||||
ld->sc_start = ld_thunkbus_ldstart;
|
||||
ld->sc_dump = ld_thunkbus_lddump;
|
||||
ld->sc_flush = ld_thunkbus_ldflush;
|
||||
|
||||
ldattach(ld);
|
||||
}
|
||||
|
||||
static int
|
||||
ld_thunkbus_ldstart(struct ld_softc *ld, struct buf *bp)
|
||||
{
|
||||
struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
|
||||
ssize_t len;
|
||||
|
||||
if (bp->b_flags & B_READ)
|
||||
len = thunk_pread(sc->sc_fd, bp->b_data, bp->b_bcount,
|
||||
bp->b_rawblkno);
|
||||
else
|
||||
len = thunk_pwrite(sc->sc_fd, bp->b_data, bp->b_bcount,
|
||||
bp->b_rawblkno);
|
||||
|
||||
if (len == -1)
|
||||
return errno;
|
||||
else if (len != bp->b_bcount)
|
||||
panic("%s: short xfer", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ld_thunkbus_lddump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
|
||||
{
|
||||
struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
|
||||
ssize_t len;
|
||||
|
||||
len = thunk_pwrite(sc->sc_fd, data, blkcnt, blkno);
|
||||
if (len == -1)
|
||||
return errno;
|
||||
else if (len != blkcnt) {
|
||||
device_printf(ld->sc_dv, "%s failed (short xfer)\n", __func__);
|
||||
return EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ld_thunkbus_ldflush(struct ld_softc *ld, int flags)
|
||||
{
|
||||
struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
|
||||
|
||||
if (thunk_fsync(sc->sc_fd) == -1)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mainbus.c,v 1.3 2009/11/27 03:23:14 rmind Exp $ */
|
||||
/* $NetBSD: mainbus.c,v 1.4 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.3 2009/11/27 03:23:14 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.4 2011/08/12 12:59:13 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -50,6 +50,8 @@ typedef struct mainbus_softc {
|
||||
CFATTACH_DECL_NEW(mainbus, sizeof(mainbus_softc_t),
|
||||
mainbus_match, mainbus_attach, NULL, NULL);
|
||||
|
||||
extern char *usermode_root_image_path;
|
||||
|
||||
static int
|
||||
mainbus_match(device_t parent, cfdata_t match, void *opaque)
|
||||
{
|
||||
@ -74,6 +76,12 @@ mainbus_attach(device_t parent, device_t self, void *opaque)
|
||||
config_found_ia(self, "thunkbus", &taa, mainbus_print);
|
||||
taa.taa_type = THUNKBUS_TYPE_TTYCONS;
|
||||
config_found_ia(self, "thunkbus", &taa, mainbus_print);
|
||||
|
||||
if (usermode_root_image_path) {
|
||||
taa.taa_type = THUNKBUS_TYPE_DISKIMAGE;
|
||||
taa.u.diskimage.path = usermode_root_image_path;
|
||||
config_found_ia(self, "thunkbus", &taa, mainbus_print);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mainbus.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
|
||||
/* $NetBSD: mainbus.h,v 1.3 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -34,6 +34,13 @@ struct thunkbus_attach_args {
|
||||
#define THUNKBUS_TYPE_CPU 0
|
||||
#define THUNKBUS_TYPE_CLOCK 1
|
||||
#define THUNKBUS_TYPE_TTYCONS 2
|
||||
#define THUNKBUS_TYPE_DISKIMAGE 3
|
||||
|
||||
union {
|
||||
struct {
|
||||
const char *path;
|
||||
} diskimage;
|
||||
} u;
|
||||
};
|
||||
|
||||
#endif /* !_ARCH_USERMODE_INCLUDE_MAINBUS_H */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: thunk.h,v 1.2 2011/08/12 11:37:04 jmcneill Exp $ */
|
||||
/* $NetBSD: thunk.h,v 1.3 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -31,6 +31,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ucontext.h>
|
||||
|
||||
int thunk_setitimer(int, const struct itimerval *, struct itimerval *);
|
||||
@ -50,4 +52,10 @@ void thunk_putchar(int);
|
||||
|
||||
int thunk_execv(const char *, char * const []);
|
||||
|
||||
int thunk_open(const char *, int, mode_t);
|
||||
int thunk_fstat(int, struct stat *);
|
||||
ssize_t thunk_pread(int, void *, size_t, off_t);
|
||||
ssize_t thunk_pwrite(int, const void *, size_t, off_t);
|
||||
int thunk_fsync(int);
|
||||
|
||||
#endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: machdep.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $ */
|
||||
/* $NetBSD: machdep.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
@ -53,6 +53,7 @@ int usermode_x = IPL_NONE;
|
||||
int physmem = MEMSIZE * 1024 / PAGE_SIZE;
|
||||
|
||||
static char **saved_argv;
|
||||
char *usermode_root_image_path = NULL;
|
||||
|
||||
void main(int argc, char *argv[]);
|
||||
void usermode_reboot(void);
|
||||
@ -70,6 +71,10 @@ main(int argc, char *argv[])
|
||||
ttycons_consinit();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
usermode_root_image_path = argv[i];
|
||||
continue;
|
||||
}
|
||||
for (j = 1; argv[i][j] != '\0'; j++) {
|
||||
r = 0;
|
||||
BOOT_FLAG(argv[i][j], r);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: thunk.c,v 1.2 2011/08/12 11:37:05 jmcneill Exp $ */
|
||||
/* $NetBSD: thunk.c,v 1.3 2011/08/12 12:59:13 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -27,11 +27,12 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: thunk.c,v 1.2 2011/08/12 11:37:05 jmcneill Exp $");
|
||||
__RCSID("$NetBSD: thunk.c,v 1.3 2011/08/12 12:59:13 jmcneill Exp $");
|
||||
|
||||
#include <machine/thunk.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -116,3 +117,32 @@ thunk_execv(const char *path, char * const argv[])
|
||||
return execv(path, argv);
|
||||
}
|
||||
|
||||
int
|
||||
thunk_open(const char *path, int flags, mode_t mode)
|
||||
{
|
||||
return open(path, flags, mode);
|
||||
}
|
||||
|
||||
int
|
||||
thunk_fstat(int fd, struct stat *sb)
|
||||
{
|
||||
return fstat(fd, sb);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
thunk_pread(int d, void *buf, size_t nbytes, off_t offset)
|
||||
{
|
||||
return pread(d, buf, nbytes, offset);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
thunk_pwrite(int d, const void *buf, size_t nbytes, off_t offset)
|
||||
{
|
||||
return pwrite(d, buf, nbytes, offset);
|
||||
}
|
||||
|
||||
int
|
||||
thunk_fsync(int fd)
|
||||
{
|
||||
return fsync(fd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user