2011-01-11 18:54:23 +00:00
|
|
|
// 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"
|
2015-06-27 17:38:03 +00:00
|
|
|
#include "fs.h"
|
2011-01-11 18:54:23 +00:00
|
|
|
#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;
|
2015-04-03 12:22:02 +00:00
|
|
|
disksize = (uint)_binary_fs_img_size/BSIZE;
|
2011-01-11 18:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
2015-06-27 17:38:03 +00:00
|
|
|
if(b->blockno >= disksize)
|
2015-04-03 12:22:02 +00:00
|
|
|
panic("iderw: block out of range");
|
2011-01-11 18:54:23 +00:00
|
|
|
|
2015-06-27 17:38:03 +00:00
|
|
|
p = memdisk + b->blockno*BSIZE;
|
2011-01-11 18:54:23 +00:00
|
|
|
|
|
|
|
if(b->flags & B_DIRTY){
|
|
|
|
b->flags &= ~B_DIRTY;
|
2015-04-03 12:22:02 +00:00
|
|
|
memmove(p, b->data, BSIZE);
|
2011-01-11 18:54:23 +00:00
|
|
|
} else
|
2015-04-03 12:22:02 +00:00
|
|
|
memmove(b->data, p, BSIZE);
|
2011-01-11 18:54:23 +00:00
|
|
|
b->flags |= B_VALID;
|
|
|
|
}
|