emu - /* * Emulator passthrough filesystem. * * The idea is...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * Emulator passthrough filesystem. * * The idea is that this appears as a filesystem in the VFS layer, and * passes VFS operations through a somewhat complicated "hardware" * interface to some simulated "hardware" in System/161 that accesses * the filesystem System/161 is running in. * * This makes it unnecessary to copy the system files to the simulated * disk, although we recommend doing so and trying running without this * device as part of testing your filesystem. */ #include <types.h> #include <kern/errno.h> #include <kern/unistd.h> #include <kern/stat.h> #include <lib.h> #include <synch.h> #include <array.h> #include <uio.h> #include <vfs.h> #include <emufs.h> #include <lamebus/emu.h> #include <machine/bus.h> #include "autoconf.h" /* Register offsets */ #define REG_HANDLE 0 #define REG_OFFSET 4 #define REG_IOLEN 8 #define REG_OPER 12 #define REG_RESULT 16 /* I/O buffer offset */ #define EMU_BUFFER 32768 /* Operation codes for REG_OPER */ #define EMU_OP_OPEN 1 #define EMU_OP_CREATE 2 #define EMU_OP_EXCLCREATE 3 #define EMU_OP_CLOSE 4 #define EMU_OP_READ 5 #define EMU_OP_READDIR 6 #define EMU_OP_WRITE 7 #define EMU_OP_GETSIZE 8 #define EMU_OP_TRUNC 9 /* Result codes for REG_RESULT */ #define EMU_RES_SUCCESS 1 #define EMU_RES_BADHANDLE 2 #define EMU_RES_BADOP 3 #define EMU_RES_BADPATH 4 #define EMU_RES_BADSIZE 5 #define EMU_RES_EXISTS 6 #define EMU_RES_ISDIR 7 #define EMU_RES_MEDIA 8 #define EMU_RES_NOHANDLES 9 #define EMU_RES_NOSPACE 10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
#define EMU_RES_NOTDIR 11 #define EMU_RES_UNKNOWN 12 #define EMU_RES_UNSUPP 13 //////////////////////////////////////////////////////////// // // Hardware ops // /* * Shortcut for reading a register */ static inline u_int32_t emu_rreg(struct emu_softc *sc, u_int32_t reg) { return bus_read_register(sc->e_busdata, sc->e_buspos, reg); } /* * Shortcut for writing a register */ static inline void emu_wreg(struct emu_softc *sc, u_int32_t reg, u_int32_t val) { bus_write_register(sc->e_busdata, sc->e_buspos, reg, val); } /* * Called by the underlying bus code when an interrupt happens */ void emu_irq(void *dev) { struct emu_softc *sc = dev; sc->e_result = emu_rreg(sc, REG_RESULT); emu_wreg(sc, REG_RESULT, 0); V(sc->e_sem); } /* * Convert the error codes reported by the "hardware" to errnos. * Or, on cases that indicate a programming error in emu.c, panic. */ static u_int32_t translate_err(struct emu_softc *sc, u_int32_t code) { switch (code) { case EMU_RES_SUCCESS: return 0; case EMU_RES_BADHANDLE: case EMU_RES_BADOP: case EMU_RES_BADSIZE: panic("emu%d: got fatal result code %d\n", sc->e_unit, code);
Background image of page 2
case EMU_RES_BADPATH: return ENOENT; case EMU_RES_EXISTS: return EEXIST; case EMU_RES_ISDIR: return EISDIR; case EMU_RES_MEDIA: return EIO; case EMU_RES_NOHANDLES: return ENFILE; case EMU_RES_NOSPACE: return ENOSPC; case EMU_RES_NOTDIR: return ENOTDIR; case EMU_RES_UNKNOWN: return EIO; case EMU_RES_UNSUPP: return EUNIMP; } kprintf("emu%d: Unknown result code %d\n", sc->e_unit, code); return EAGAIN; } /* * Wait for an operation to complete, and return an errno for the result. */ static
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Page1 / 19

emu - /* * Emulator passthrough filesystem. * * The idea is...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online