Mercurial > hg > Members > shivanidubey > xv6
comparison src/memide.c @ 0:83c23a36980d
Init
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 26 May 2017 23:11:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:83c23a36980d |
---|---|
1 // Fake IDE disk; stores blocks in memory. | |
2 // Useful for running kernel without scratch disk. | |
3 | |
4 #include "types.h" | |
5 #include "defs.h" | |
6 #include "param.h" | |
7 #include "mmu.h" | |
8 #include "proc.h" | |
9 #include "spinlock.h" | |
10 #include "buf.h" | |
11 | |
12 // a file system image, embeded | |
13 extern uchar _binary_fs_img_start[], _binary_fs_img_size[]; | |
14 | |
15 static int disksize; | |
16 static uchar *memdisk; | |
17 | |
18 void ideinit(void) | |
19 { | |
20 memdisk = _binary_fs_img_start; | |
21 disksize = (uint)_binary_fs_img_size/512; | |
22 } | |
23 | |
24 // Interrupt handler. | |
25 void ideintr(void) | |
26 { | |
27 // no-op | |
28 } | |
29 | |
30 // Sync buf with disk. | |
31 // If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID. | |
32 // Else if B_VALID is not set, read buf from disk, set B_VALID. | |
33 void iderw(struct buf *b) | |
34 { | |
35 uchar *p; | |
36 | |
37 if(!(b->flags & B_BUSY)) { | |
38 panic("iderw: buf not busy"); | |
39 } | |
40 | |
41 if((b->flags & (B_VALID|B_DIRTY)) == B_VALID) { | |
42 panic("iderw: nothing to do"); | |
43 } | |
44 | |
45 if(b->dev != 1) { | |
46 panic("iderw: request not for disk 1"); | |
47 } | |
48 | |
49 if(b->sector >= disksize) { | |
50 panic("iderw: sector out of range"); | |
51 } | |
52 | |
53 p = memdisk + b->sector*512; | |
54 | |
55 if(b->flags & B_DIRTY){ | |
56 b->flags &= ~B_DIRTY; | |
57 memmove(p, b->data, 512); | |
58 } else { | |
59 memmove(b->data, p, 512); | |
60 } | |
61 | |
62 b->flags |= B_VALID; | |
63 } |