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 PrintDebug("CDIMAGE located at: %x\n", cdrom->fd);
29 cdrom->capacity_B = s_ramdiskSize;
36 * Load CD-ROM. Returns false if CD is not ready.
40 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
42 Ramdisk_Print_CD("[cdrom_insert]\n");
47 * Logically eject the CD.
50 void cdrom_eject(struct cdrom_interface *cdrom)
52 Ramdisk_Print_CD("[cdrom_eject]\n");
57 * Read CD TOC. Returns false if start track is out of bounds.
60 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8_t* buf, int* length, rd_bool msf, int start_track)
62 Ramdisk_Print_CD("[cdrom_read_toc]\n");
67 * Return CD-ROM capacity (in 2048 byte frames)
70 uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
72 Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
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;
78 Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
79 return cdrom->capacity_B/2048;
88 * Read a single block from the CD
91 void cdrom_read_block(struct cdrom_interface *cdrom, uint8_t* buf, int lba)// __attribute__(regparm(2));
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");
103 * Start (spin up) the CD.
106 int cdrom_start(struct cdrom_interface *cdrom)
108 Ramdisk_Print_CD("[cdrom_start]\n");
113 void init_cdrom(struct cdrom_interface *cdrom)
115 V3_ASSERT(cdrom != NULL);
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;