diff options
author | Russ Cox <[email protected]> | 2011-01-11 13:54:23 -0500 |
---|---|---|
committer | Russ Cox <[email protected]> | 2011-01-11 13:54:23 -0500 |
commit | 4fa8614db068e92c2628456df7a7d5483e4afe5b (patch) | |
tree | 21d35063b0d883fc18c7e3a0f19fe23c22115465 | |
parent | 417c37115e0c7fc3b2a65c3c4d213e566cbc8807 (diff) | |
download | xv6-labs-4fa8614db068e92c2628456df7a7d5483e4afe5b.tar.gz xv6-labs-4fa8614db068e92c2628456df7a7d5483e4afe5b.tar.bz2 xv6-labs-4fa8614db068e92c2628456df7a7d5483e4afe5b.zip |
missing file memide.c
-rw-r--r-- | memide.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/memide.c b/memide.c new file mode 100644 index 0000000..d2c5bb7 --- /dev/null +++ b/memide.c @@ -0,0 +1,58 @@ +// Fake IDE disk; stores blocks in memory. +// Useful for running kernel without scratch disk. + +#include "types.h" +#include "defs.h" +#include "param.h" +#include "mmu.h" +#include "proc.h" +#include "x86.h" +#include "traps.h" +#include "spinlock.h" +#include "buf.h" + +extern uchar _binary_fs_img_start[], _binary_fs_img_size[]; + +static int disksize; +static uchar *memdisk; + +void +ideinit(void) +{ + memdisk = _binary_fs_img_start; + disksize = (uint)_binary_fs_img_size/512; +} + +// Interrupt handler. +void +ideintr(void) +{ + // no-op +} + +// Sync buf with disk. +// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID. +// Else if B_VALID is not set, read buf from disk, set B_VALID. +void +iderw(struct buf *b) +{ + uchar *p; + + if(!(b->flags & B_BUSY)) + panic("iderw: buf not busy"); + if((b->flags & (B_VALID|B_DIRTY)) == B_VALID) + panic("iderw: nothing to do"); + if(b->dev != 1) + panic("iderw: request not for disk 1"); + if(b->sector >= disksize) + panic("iderw: sector out of range"); + + p = memdisk + b->sector*512; + + if(b->flags & B_DIRTY){ + b->flags &= ~B_DIRTY; + memmove(p, b->data, 512); + } else + memmove(b->data, p, 512); + b->flags |= B_VALID; +} |