Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added functioning ramdisk, makefile support
[palacios.git] / palacios / src / devices / cdrom.c
1 /*
2  * Zheng Cui
3  * cuizheng@cs.unm.edu
4  * July 2008
5  */
6
7
8 #include <devices/cdrom.h>
9 #include <palacios/vmm.h>
10
11 #ifdef DEBUG_RAMDISK
12 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
13 #else
14 #define Ramdisk_Print_CD(_f, _a...)
15 #endif
16
17
18 extern ulong_t g_ramdiskImage;
19 extern ulong_t s_ramdiskSize;
20
21 static
22 void cdrom_init(struct cdrom_interface * cdrom)
23 {
24
25   Ramdisk_Print_CD("[cdrom_init]\n");
26   V3_ASSERT(g_ramdiskImage);
27   cdrom->fd = g_ramdiskImage;
28   PrintDebug("CDIMAGE located at: %x\n", cdrom->fd);
29   cdrom->capacity_B = s_ramdiskSize; 
30   //FIXME:lba
31   cdrom->lba = 1; 
32   return;
33 }
34
35 /* 
36  * Load CD-ROM. Returns false if CD is not ready.
37  */
38  
39 static
40 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
41 {
42   Ramdisk_Print_CD("[cdrom_insert]\n");
43   return 1;
44 }
45
46 /*
47  * Logically eject the CD.
48  */
49 static
50 void cdrom_eject(struct cdrom_interface *cdrom)
51 {
52   Ramdisk_Print_CD("[cdrom_eject]\n");
53   return;
54 }
55
56 /*
57  * Read CD TOC. Returns false if start track is out of bounds.
58  */
59 static
60 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8_t* buf, int* length, rd_bool msf, int start_track)
61 {
62   Ramdisk_Print_CD("[cdrom_read_toc]\n");
63   return 1;
64 }
65
66 /*
67  * Return CD-ROM capacity (in 2048 byte frames)
68  */
69 static
70 uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
71 {
72   Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
73   if (cdrom->lba) {
74     if (cdrom->capacity_B % 2048) {
75       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
76       return cdrom->capacity_B/2048 + 1;
77     } else {
78       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
79       return cdrom->capacity_B/2048;
80     }
81   } else {
82     //FIXME CHS mode
83     return 0;
84   }
85 }
86
87 /*
88  * Read a single block from the CD
89  */
90 static
91 void cdrom_read_block(struct cdrom_interface *cdrom, uint8_t* buf, int lba)// __attribute__(regparm(2));
92 {
93
94   V3_ASSERT(lba != 0);
95   
96   Ramdisk_Print_CD("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->fd);
97   memcpy(buf, (uint8_t *)(cdrom->fd + lba * 2048), 2048);
98   PrintDebug("Returning from read block\n");
99     return;
100 }
101
102 /*
103  * Start (spin up) the CD.
104  */
105 static
106 int cdrom_start(struct cdrom_interface *cdrom)
107 {
108   Ramdisk_Print_CD("[cdrom_start]\n");
109   return 1;
110 }
111
112
113 void init_cdrom(struct cdrom_interface *cdrom)
114 {
115   V3_ASSERT(cdrom != NULL);
116   
117   cdrom->ops.init = &cdrom_init;
118   cdrom->ops.insert_cdrom = &cdrom_insert;
119   cdrom->ops.eject_cdrom = &cdrom_eject;
120   cdrom->ops.read_toc = &cdrom_read_toc;
121   cdrom->ops.capacity = &cdrom_capacity;
122   cdrom->ops.read_block = &cdrom_read_block;
123   cdrom->ops.start_cdrom = &cdrom_start;
124
125   return;
126 }
127