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.


build reorganization
[palacios.git] / palacios / src / devices / cdrom.c
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Zheng Cui <cuizheng@cs.unm.edu> 
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Zheng Cui <cuizheng@cs.unm.edu> 
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #include <devices/cdrom.h>
22 #include <palacios/vmm.h>
23
24 #ifdef DEBUG_RAMDISK
25 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
26 #else
27 #define Ramdisk_Print_CD(_f, _a...)
28 #endif
29
30
31
32 ulong_t g_ramdiskImage;
33 ulong_t s_ramdiskSize;
34
35 static
36 void cdrom_init(struct cdrom_interface * cdrom)
37 {
38
39   Ramdisk_Print_CD("[cdrom_init]\n");
40   V3_ASSERT(g_ramdiskImage);
41   cdrom->fd = g_ramdiskImage;
42   PrintDebug("CDIMAGE located at: %x\n", cdrom->fd);
43   cdrom->capacity_B = s_ramdiskSize; 
44   //FIXME:lba
45   cdrom->lba = 1; 
46   return;
47 }
48
49 /* 
50  * Load CD-ROM. Returns false if CD is not ready.
51  */
52  
53 static
54 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
55 {
56   Ramdisk_Print_CD("[cdrom_insert]\n");
57   return 1;
58 }
59
60 /*
61  * Logically eject the CD.
62  */
63 static
64 void cdrom_eject(struct cdrom_interface *cdrom)
65 {
66   Ramdisk_Print_CD("[cdrom_eject]\n");
67   return;
68 }
69
70 /*
71  * Read CD TOC. Returns false if start track is out of bounds.
72  */
73 static
74 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8_t* buf, int* length, rd_bool msf, int start_track)
75 {
76   Ramdisk_Print_CD("[cdrom_read_toc]\n");
77   return 1;
78 }
79
80 /*
81  * Return CD-ROM capacity (in 2048 byte frames)
82  */
83 static
84 uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
85 {
86   Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
87   if (cdrom->lba) {
88     if (cdrom->capacity_B % 2048) {
89       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
90       return cdrom->capacity_B/2048 + 1;
91     } else {
92       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
93       return cdrom->capacity_B/2048;
94     }
95   } else {
96     //FIXME CHS mode
97     return 0;
98   }
99 }
100
101 /*
102  * Read a single block from the CD
103  */
104 static
105 void cdrom_read_block(struct cdrom_interface *cdrom, uint8_t* buf, int lba)// __attribute__(regparm(2));
106 {
107
108   V3_ASSERT(lba != 0);
109   
110   Ramdisk_Print_CD("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->fd);
111   memcpy(buf, (uint8_t *)(cdrom->fd + lba * 2048), 2048);
112   PrintDebug("Returning from read block\n");
113     return;
114 }
115
116 /*
117  * Start (spin up) the CD.
118  */
119 static
120 int cdrom_start(struct cdrom_interface *cdrom)
121 {
122   Ramdisk_Print_CD("[cdrom_start]\n");
123   return 1;
124 }
125
126
127 void init_cdrom(struct cdrom_interface *cdrom)
128 {
129   V3_ASSERT(cdrom != NULL);
130   
131   cdrom->ops.init = &cdrom_init;
132   cdrom->ops.insert_cdrom = &cdrom_insert;
133   cdrom->ops.eject_cdrom = &cdrom_eject;
134   cdrom->ops.read_toc = &cdrom_read_toc;
135   cdrom->ops.capacity = &cdrom_capacity;
136   cdrom->ops.read_block = &cdrom_read_block;
137   cdrom->ops.start_cdrom = &cdrom_start;
138
139   return;
140 }
141
142