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.


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