root / hw / cdrom.c @ c75a823c
History | View | Annotate | Download (4.2 kB)
1 | 2e5d83bb | pbrook | /*
|
---|---|---|---|
2 | 2e5d83bb | pbrook | * QEMU ATAPI CD-ROM Emulator
|
3 | 5fafdf24 | ths | *
|
4 | 2e5d83bb | pbrook | * Copyright (c) 2006 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 2e5d83bb | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 2e5d83bb | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | 2e5d83bb | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | 2e5d83bb | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 2e5d83bb | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | 2e5d83bb | pbrook | * furnished to do so, subject to the following conditions:
|
12 | 2e5d83bb | pbrook | *
|
13 | 2e5d83bb | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | 2e5d83bb | pbrook | * all copies or substantial portions of the Software.
|
15 | 2e5d83bb | pbrook | *
|
16 | 2e5d83bb | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 2e5d83bb | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 2e5d83bb | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 2e5d83bb | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 2e5d83bb | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 2e5d83bb | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 2e5d83bb | pbrook | * THE SOFTWARE.
|
23 | 2e5d83bb | pbrook | */
|
24 | 2e5d83bb | pbrook | |
25 | 2e5d83bb | pbrook | /* ??? Most of the ATAPI emulation is still in ide.c. It should be moved
|
26 | 2e5d83bb | pbrook | here. */
|
27 | 2e5d83bb | pbrook | |
28 | 87ecb68b | pbrook | #include "qemu-common.h" |
29 | 87ecb68b | pbrook | #include "scsi-disk.h" |
30 | 2e5d83bb | pbrook | |
31 | 2e5d83bb | pbrook | static void lba_to_msf(uint8_t *buf, int lba) |
32 | 2e5d83bb | pbrook | { |
33 | 2e5d83bb | pbrook | lba += 150;
|
34 | 2e5d83bb | pbrook | buf[0] = (lba / 75) / 60; |
35 | 2e5d83bb | pbrook | buf[1] = (lba / 75) % 60; |
36 | 2e5d83bb | pbrook | buf[2] = lba % 75; |
37 | 2e5d83bb | pbrook | } |
38 | 2e5d83bb | pbrook | |
39 | 2e5d83bb | pbrook | /* same toc as bochs. Return -1 if error or the toc length */
|
40 | 2e5d83bb | pbrook | /* XXX: check this */
|
41 | 2e5d83bb | pbrook | int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track) |
42 | 2e5d83bb | pbrook | { |
43 | 2e5d83bb | pbrook | uint8_t *q; |
44 | 2e5d83bb | pbrook | int len;
|
45 | 3b46e624 | ths | |
46 | 2e5d83bb | pbrook | if (start_track > 1 && start_track != 0xaa) |
47 | 2e5d83bb | pbrook | return -1; |
48 | 2e5d83bb | pbrook | q = buf + 2;
|
49 | 2e5d83bb | pbrook | *q++ = 1; /* first session */ |
50 | 2e5d83bb | pbrook | *q++ = 1; /* last session */ |
51 | 2e5d83bb | pbrook | if (start_track <= 1) { |
52 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
53 | 2e5d83bb | pbrook | *q++ = 0x14; /* ADR, control */ |
54 | 2e5d83bb | pbrook | *q++ = 1; /* track number */ |
55 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
56 | 2e5d83bb | pbrook | if (msf) {
|
57 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
58 | 2e5d83bb | pbrook | lba_to_msf(q, 0);
|
59 | 2e5d83bb | pbrook | q += 3;
|
60 | 2e5d83bb | pbrook | } else {
|
61 | 2e5d83bb | pbrook | /* sector 0 */
|
62 | 2e5d83bb | pbrook | cpu_to_be32wu((uint32_t *)q, 0);
|
63 | 2e5d83bb | pbrook | q += 4;
|
64 | 2e5d83bb | pbrook | } |
65 | 2e5d83bb | pbrook | } |
66 | 2e5d83bb | pbrook | /* lead out track */
|
67 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
68 | 2e5d83bb | pbrook | *q++ = 0x16; /* ADR, control */ |
69 | 2e5d83bb | pbrook | *q++ = 0xaa; /* track number */ |
70 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
71 | 2e5d83bb | pbrook | if (msf) {
|
72 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
73 | 2e5d83bb | pbrook | lba_to_msf(q, nb_sectors); |
74 | 2e5d83bb | pbrook | q += 3;
|
75 | 2e5d83bb | pbrook | } else {
|
76 | 2e5d83bb | pbrook | cpu_to_be32wu((uint32_t *)q, nb_sectors); |
77 | 2e5d83bb | pbrook | q += 4;
|
78 | 2e5d83bb | pbrook | } |
79 | 2e5d83bb | pbrook | len = q - buf; |
80 | 2e5d83bb | pbrook | cpu_to_be16wu((uint16_t *)buf, len - 2);
|
81 | 2e5d83bb | pbrook | return len;
|
82 | 2e5d83bb | pbrook | } |
83 | 2e5d83bb | pbrook | |
84 | 2e5d83bb | pbrook | /* mostly same info as PearPc */
|
85 | 2e5d83bb | pbrook | int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num) |
86 | 2e5d83bb | pbrook | { |
87 | 2e5d83bb | pbrook | uint8_t *q; |
88 | 2e5d83bb | pbrook | int len;
|
89 | 3b46e624 | ths | |
90 | 2e5d83bb | pbrook | q = buf + 2;
|
91 | 2e5d83bb | pbrook | *q++ = 1; /* first session */ |
92 | 2e5d83bb | pbrook | *q++ = 1; /* last session */ |
93 | 2e5d83bb | pbrook | |
94 | 2e5d83bb | pbrook | *q++ = 1; /* session number */ |
95 | 2e5d83bb | pbrook | *q++ = 0x14; /* data track */ |
96 | 2e5d83bb | pbrook | *q++ = 0; /* track number */ |
97 | 2e5d83bb | pbrook | *q++ = 0xa0; /* lead-in */ |
98 | 2e5d83bb | pbrook | *q++ = 0; /* min */ |
99 | 2e5d83bb | pbrook | *q++ = 0; /* sec */ |
100 | 2e5d83bb | pbrook | *q++ = 0; /* frame */ |
101 | 2e5d83bb | pbrook | *q++ = 0;
|
102 | 2e5d83bb | pbrook | *q++ = 1; /* first track */ |
103 | 2e5d83bb | pbrook | *q++ = 0x00; /* disk type */ |
104 | 2e5d83bb | pbrook | *q++ = 0x00;
|
105 | 3b46e624 | ths | |
106 | 2e5d83bb | pbrook | *q++ = 1; /* session number */ |
107 | 2e5d83bb | pbrook | *q++ = 0x14; /* data track */ |
108 | 2e5d83bb | pbrook | *q++ = 0; /* track number */ |
109 | 2e5d83bb | pbrook | *q++ = 0xa1;
|
110 | 2e5d83bb | pbrook | *q++ = 0; /* min */ |
111 | 2e5d83bb | pbrook | *q++ = 0; /* sec */ |
112 | 2e5d83bb | pbrook | *q++ = 0; /* frame */ |
113 | 2e5d83bb | pbrook | *q++ = 0;
|
114 | 2e5d83bb | pbrook | *q++ = 1; /* last track */ |
115 | 2e5d83bb | pbrook | *q++ = 0x00;
|
116 | 2e5d83bb | pbrook | *q++ = 0x00;
|
117 | 3b46e624 | ths | |
118 | 2e5d83bb | pbrook | *q++ = 1; /* session number */ |
119 | 2e5d83bb | pbrook | *q++ = 0x14; /* data track */ |
120 | 2e5d83bb | pbrook | *q++ = 0; /* track number */ |
121 | 2e5d83bb | pbrook | *q++ = 0xa2; /* lead-out */ |
122 | 2e5d83bb | pbrook | *q++ = 0; /* min */ |
123 | 2e5d83bb | pbrook | *q++ = 0; /* sec */ |
124 | 2e5d83bb | pbrook | *q++ = 0; /* frame */ |
125 | 2e5d83bb | pbrook | if (msf) {
|
126 | 2e5d83bb | pbrook | *q++ = 0; /* reserved */ |
127 | 2e5d83bb | pbrook | lba_to_msf(q, nb_sectors); |
128 | 2e5d83bb | pbrook | q += 3;
|
129 | 2e5d83bb | pbrook | } else {
|
130 | 2e5d83bb | pbrook | cpu_to_be32wu((uint32_t *)q, nb_sectors); |
131 | 2e5d83bb | pbrook | q += 4;
|
132 | 2e5d83bb | pbrook | } |
133 | 2e5d83bb | pbrook | |
134 | 2e5d83bb | pbrook | *q++ = 1; /* session number */ |
135 | 2e5d83bb | pbrook | *q++ = 0x14; /* ADR, control */ |
136 | 2e5d83bb | pbrook | *q++ = 0; /* track number */ |
137 | 2e5d83bb | pbrook | *q++ = 1; /* point */ |
138 | 2e5d83bb | pbrook | *q++ = 0; /* min */ |
139 | 2e5d83bb | pbrook | *q++ = 0; /* sec */ |
140 | 2e5d83bb | pbrook | *q++ = 0; /* frame */ |
141 | 2e5d83bb | pbrook | if (msf) {
|
142 | 5fafdf24 | ths | *q++ = 0;
|
143 | 2e5d83bb | pbrook | lba_to_msf(q, 0);
|
144 | 2e5d83bb | pbrook | q += 3;
|
145 | 2e5d83bb | pbrook | } else {
|
146 | 5fafdf24 | ths | *q++ = 0;
|
147 | 5fafdf24 | ths | *q++ = 0;
|
148 | 5fafdf24 | ths | *q++ = 0;
|
149 | 5fafdf24 | ths | *q++ = 0;
|
150 | 2e5d83bb | pbrook | } |
151 | 2e5d83bb | pbrook | |
152 | 2e5d83bb | pbrook | len = q - buf; |
153 | 2e5d83bb | pbrook | cpu_to_be16wu((uint16_t *)buf, len - 2);
|
154 | 2e5d83bb | pbrook | return len;
|
155 | 2e5d83bb | pbrook | } |
156 | 2e5d83bb | pbrook |