8 #include <devices/cdrom.h>
9 #include <palacios/vmm.h>
12 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
14 #define Ramdisk_Print_CD(_f, _a...)
18 extern ulong_t g_ramdiskImage;
19 extern ulong_t s_ramdiskSize;
22 void cdrom_init(struct cdrom_interface *cdrom)
25 Ramdisk_Print_CD("[cdrom_init]\n");
26 V3_ASSERT(g_ramdiskImage);
27 cdrom->fd = g_ramdiskImage;
28 cdrom->capacity_B = s_ramdiskSize;
35 * Load CD-ROM. Returns false if CD is not ready.
39 rd_bool cdrom_insert(struct cdrom_interface *cdrom, char *dev /*= NULL*/)
41 Ramdisk_Print_CD("[cdrom_insert]\n");
46 * Logically eject the CD.
49 void cdrom_eject(struct cdrom_interface *cdrom)
51 Ramdisk_Print_CD("[cdrom_eject]\n");
56 * Read CD TOC. Returns false if start track is out of bounds.
59 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8* buf, int* length, rd_bool msf, int start_track)
61 Ramdisk_Print_CD("[cdrom_read_toc]\n");
66 * Return CD-ROM capacity (in 2048 byte frames)
69 uint32 cdrom_capacity(struct cdrom_interface *cdrom)
71 Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
73 if (cdrom->capacity_B % 2048) {
74 Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
75 return cdrom->capacity_B/2048 + 1;
77 Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
78 return cdrom->capacity_B/2048;
87 * Read a single block from the CD
90 void cdrom_read_block(struct cdrom_interface *cdrom, uint8* buf, int lba)// __attribute__(regparm(2));
95 Ramdisk_Print_CD("[cdrom_read_block] lba = %d\n", lba);
96 memcpy(buf, (uint8 *)(cdrom->fd + lba*2048), 2048);
101 * Start (spin up) the CD.
104 int cdrom_start(struct cdrom_interface *cdrom)
106 Ramdisk_Print_CD("[cdrom_start]\n");
111 void init_cdrom(struct cdrom_interface *cdrom)
113 V3_ASSERT(cdrom != NULL);
115 cdrom->ops.init = &cdrom_init;
116 cdrom->ops.insert_cdrom = &cdrom_insert;
117 cdrom->ops.eject_cdrom = &cdrom_eject;
118 cdrom->ops.read_toc = &cdrom_read_toc;
119 cdrom->ops.capacity = &cdrom_capacity;
120 cdrom->ops.read_block = &cdrom_read_block;
121 cdrom->ops.start_cdrom = &cdrom_start;