Xv6 with picoc & Linkage editor
v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
|
00001 // Fake IDE disk; stores blocks in memory. 00002 // Useful for running kernel without scratch disk. 00003 00004 #include "types.h" 00005 #include "defs.h" 00006 #include "param.h" 00007 #include "mmu.h" 00008 #include "proc.h" 00009 #include "x86.h" 00010 #include "traps.h" 00011 #include "spinlock.h" 00012 #include "buf.h" 00013 00014 extern uchar _binary_fs_img_start[], _binary_fs_img_size[]; 00015 00016 static int disksize; 00017 static uchar *memdisk; 00018 00019 void 00020 ideinit(void) 00021 { 00022 memdisk = _binary_fs_img_start; 00023 disksize = (uint)_binary_fs_img_size/512; 00024 } 00025 00026 // Interrupt handler. 00027 void 00028 ideintr(void) 00029 { 00030 // no-op 00031 } 00032 00033 // Sync buf with disk. 00034 // If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID. 00035 // Else if B_VALID is not set, read buf from disk, set B_VALID. 00036 void 00037 iderw(struct buf *b) 00038 { 00039 uchar *p; 00040 00041 if(!(b->flags & B_BUSY)) 00042 panic("iderw: buf not busy"); 00043 if((b->flags & (B_VALID|B_DIRTY)) == B_VALID) 00044 panic("iderw: nothing to do"); 00045 if(b->dev != 1) 00046 panic("iderw: request not for disk 1"); 00047 if(b->sector >= disksize) 00048 panic("iderw: sector out of range"); 00049 00050 p = memdisk + b->sector*512; 00051 00052 if(b->flags & B_DIRTY){ 00053 b->flags &= ~B_DIRTY; 00054 memmove(p, b->data, 512); 00055 } else 00056 memmove(b->data, p, 512); 00057 b->flags |= B_VALID; 00058 }