SayoriOS 0.3.3

floppy.c
См. документацию.
1
11 #include <drv/disk/floppy.h>
12 #include <io/ports.h>
13 #include "sys/timer.h"
14 #include "mem/vmm.h"
15 #include "drv/disk/dpm.h"
16 #include "io/tty.h"
17 #include "sys/isr.h"
18
19 bool _FloppyDebug = false;
20
21 floppy_t floppy_data[2] = {0};
22 // standard IRQ number for floppy controllers
23 //static const int floppy_irq = 6;
24 static const char * drive_types[8] = {
25 "none",
26 "360kB 5.25\"",
27 "1.2MB 5.25\"",
28 "720kB 3.5\"",
29
30 "1.44MB 3.5\"",
31 "2.88MB 3.5\"",
32 "unknown type",
33 "unknown type"
34 };
35 static const char FLOPPY_DMABUFA[floppy_dmalen] __attribute__((aligned(0x8000)));
36 //static const char FLOPPY_DMABUFB[floppy_dmalen] __attribute__((aligned(0x8000))); ///< Буфер дискеты 2
37 volatile bool interrupted = false;
38
39 floppy_t Floppy(int device){
40 return floppy_data[device];
41 }
42
43 void irq_waitFloppy() {
44 while(interrupted){
45 sleep_ms(10);
46 }
47 }
48
49 static void irqFloppy(__attribute__((unused)) registers_t regs){
50 interrupted = 0;
51 }
52
53 int _FloppyError(int Device,int Error){
54 if (_FloppyDebug) qemu_log("FD%c ERROR! Code: %d",(Device==FDB?'B':'A'),Error);
55 floppy_data[Device].LastErr = Error;
56 return (Error*(-1));
57 }
58
59 static void _FloppyROOT(int device,int offset,int cmd){
60 size_t addr = Floppy(device).Addr + offset;
61
62 if (_FloppyDebug)
63 qemu_log(" [FD%c] ROOT | Addr: %x | Offset: %x | Input: %x | Cmd: %x",(device?'B':'A'),Floppy(device).Addr,offset,addr,cmd);
64
65 outb(addr, cmd);
66
67 kfree((void*)addr);
68 }
69
70 static void _FloppyDMA(FloppyMode dir) {
71
72 union {
73 unsigned char b[4]; // 4 bytes
74 unsigned long l; // 1 long = 32-bit
75 } a, c; // address and count
76
77 a.l = (unsigned) &FLOPPY_DMABUFA;
78 c.l = (unsigned) FLOPPY_144_CYLINDER_SIZE - 1; // -1 because of DMA counting
79
80 if((a.l >> 24) || (c.l >> 16) || (((a.l&0xffff)+c.l)>>16)) {
81 qemu_log("_FloppyDMA: static buffer problem\n");
82 }
83
84 unsigned char mode;
85 switch(dir) {
86 // 01:0:0:01:10 = single/inc/no-auto/to-mem/chan2
87 case FLOPPY_READ: mode = 0x46; break;
88 // 01:0:0:10:10 = single/inc/no-auto/from-mem/chan2
89 case FLOPPY_WRITE: mode = 0x4a; break;
90 default: qemu_log("_FloppyDMA: invalid direction");
91 return; // not reached, please "mode user uninitialized"
92 }
93 outb(0x0a, 0x06);
94 outb(0x0c, 0xff);
95 outb(0x04, a.b[0]);
96 outb(0x04, a.b[1]);
97 outb(0x81, a.b[2]);
98 outb(0x0c, 0xff);
99 outb(0x05, c.b[0]);
100 outb(0x05, c.b[1]);
101 outb(0x0b, mode);
102 outb(0x0a, 0x02);
103 }
104
105 void _FloppyMotor(int device, int status){
106 if (status == 2){
107 // Заглушить мотор
108 _FloppyROOT(device,FLOPPY_DIGITAL_OUTPUT_REGISTER,0x0C);
109 //outb(Floppy(device).Addr + FLOPPY_DIGITAL_OUTPUT_REGISTER, 0x0c);
110 floppy_data[device].Motor = 0;
111 if (_FloppyDebug) qemu_log(" [FD%c] Motor Offline",(device?'B':'A'));
112 } else if (status == 1){
113 if (_FloppyDebug) qemu_log(" [FD%c] Motor Online",(device?'B':'A'));
114 // Включить мотор
115 if (Floppy(device).Motor == 0){
116 //qemu_log("[FD%c] Motor | Addr: %x | DOR: %x ",(device?'B':'A'),Floppy(device).Addr,adrcmd);
117 if (device == 0) _FloppyROOT(device,FLOPPY_DIGITAL_OUTPUT_REGISTER,0x1C);
118 if (device == 1) _FloppyROOT(device,FLOPPY_DIGITAL_OUTPUT_REGISTER,0x2D);
119 sleep_ms(500);
120 }
121 floppy_data[device].Motor = 1;
122 } else {
123 // Перевести мотор в режим ожидания
124 if (_FloppyDebug) qemu_log(" [FD%c] Motor Waiting",(device?'B':'A'));
125 if (Floppy(device).Motor == 2){
126 if (_FloppyDebug) qemu_log(" [FD%c] Strange, fd motor-state already waiting..",(device?'B':'A'));
127 }
128 floppy_data[device].Motor = 2;
129 floppy_data[device].Ticks = 300;
130 }
131 }
132
133 int _FloppyCMD(int device, char cmd){
134 if (_FloppyDebug) qemu_log(" [FD%c] Addr: %x | Command: %x",(device?'B':'A'),Floppy(device).Addr,cmd);
135 for(int i = 0; i < 600; i++) {
136 sleep_ms(1); // sleep 10 ms
137 if(0x80 & inb(Floppy(device).Addr + FLOPPY_MAIN_STATUS_REGISTER)) {
138 _FloppyROOT(device,FLOPPY_DATA_FIFO,cmd);
139 //outb(Floppy(device).Addr + FLOPPY_DATA_FIFO, cmd);
140 return 1;
141 }
142 }
143 return _FloppyError(device,FLOPPY_ERROR_CMD);
144 }
145
146 unsigned char _FloppyData(int device){
147 for(int i = 0; i < 600; i++) {
148 sleep_ms(1); // sleep 10 ms
149 if(0x80 & inb(Floppy(device).Addr + FLOPPY_MAIN_STATUS_REGISTER)) {
150 return inb(Floppy(device).Addr + FLOPPY_DATA_FIFO);
151 }
152 }
153 qemu_log("floppy_read_data: timeout");
154 return 0; // not reached
155 }
156
157
158 void _FloppyCI(int device,int *st0, int *cyl){
159 _FloppyCMD(device, CMD_SENSE_INTERRUPT);
160
161 *st0 = _FloppyData(device);
162 *cyl = _FloppyData(device);
163 }
164
165
166 int _FloppyCalibrate(int device){
167 int i, st0, cyl = -1; // set to bogus cylinder
168 _FloppyMotor(device,1);
169 for(i = 0; i < 10; i++) {
170 if (_FloppyDebug) qemu_log(" [FD%c] Attempt Calibrate %d",(device?'B':'A'),i);
171 interrupted = false;
172 _FloppyCMD(device, CMD_RECALIBRATE);
173 _FloppyCMD(device, 0); // argument is drive, we only support 0
174 irq_waitFloppy();
175 _FloppyCI(device, &st0, &cyl);
176 if(st0 & 0xC0) continue;
177 if(!cyl) { // found cylinder 0 ?
178 _FloppyMotor(device, 0);
179 return 0;
180 }
181 }
182 if (_FloppyDebug) qemu_log("floppy_calibrate: 10 retries exhausted\n");
183 _FloppyMotor(device, 0);
184 return _FloppyError(device,FLOPPY_ERROR_CALIBRATE);
185 }
186
187 int _FloppyReset(int device){
188 interrupted = false;
189 _FloppyROOT(device,FLOPPY_DIGITAL_OUTPUT_REGISTER,0x00);
190 _FloppyROOT(device,FLOPPY_DIGITAL_OUTPUT_REGISTER,0x0C);
191 irq_waitFloppy(); // sleep until interrupt occurs
192 {
193 int st0, cyl; // ignore these here...
194 _FloppyCI(device, &st0, &cyl);
195 }
196 _FloppyROOT(device,FLOPPY_CONFIGURATION_CONTROL_REGISTER,0x00);
197 _FloppyCMD(device, CMD_SPECIFY);
198 _FloppyCMD(device, 0xdf); /* steprate = 3ms, unload time = 240ms */
199 _FloppyCMD(device, 0x02); /* load time = 16ms, no-DMA = 0 */
200
201 // it could fail...
202 if(_FloppyCalibrate(device) != 0)
203 return _FloppyError(device,FLOPPY_ERROR_RESET);
204 else
205 return 0;
206 }
207
208
209
210 int _FloppySeek(int device, unsigned cyli, int head){
211 int i, st0, cyl = -1;
212 _FloppyMotor(device, 1);
213 for(i = 0; i < 10; i++) {
214 if (_FloppyDebug) qemu_log(" [FD%c] Attempt Seek %d | Cyli: %c | Head: %d",(device?'B':'A'),i,cyli,head);
215 interrupted = false;
216 _FloppyCMD(device, CMD_SEEK);
217 _FloppyCMD(device, head<<2);
218 _FloppyCMD(device, cyli & 0xFF);
219 irq_waitFloppy();
220 _FloppyCI(device, &st0, &cyl);
221 if(st0 & 0xC0) continue;
222 if(cyl == cyli) {
223 _FloppyMotor(device, 0);
224 return 0;
225 }
226 }
227 qemu_log("floppy_seek: 10 retries exhausted\n");
228 _FloppyMotor(device, 0);
229 _FloppyError(device,FLOPPY_ERROR_SEEK);
230 return -1;
231 }
232
233 int _FloppyTrack(int device, unsigned cyl, FloppyMode dir) {
234 unsigned char cmd;
235 static const int flags = 0xC0;
236 switch(dir) {
237 case FLOPPY_READ:
238 cmd = CMD_READ_DATA | flags;
239 break;
240 case FLOPPY_WRITE:
241 cmd = CMD_WRITE_DATA | flags;
242 break;
243 default:
244
245 qemu_log("floppy_do_track: invalid direction");
246 return 0; // not reached, but pleases "cmd used uninitialized"
247 }
249 if(_FloppySeek(device, cyl, 0)) return -1;
250 if(_FloppySeek(device, cyl, 1)) return -1;
251
252 int i;
253 for(i = 0; i < 20; i++) {
254 _FloppyMotor(device, 1);
255 _FloppyDMA(dir);
256 sleep_ms(100); // give some time (100ms) to settle after the seeks
257 _FloppyCMD(device, cmd); // set above for current direction
258 _FloppyCMD(device, 0); // 0:0:0:0:0:HD:US1:US0 = head and drive
259 _FloppyCMD(device, cyl); // cylinder
260 _FloppyCMD(device, 0); // first head (should match with above)
261 _FloppyCMD(device, 1); // first sector, strangely counts from 1
262 _FloppyCMD(device, 2); // bytes/sector, 128*2^x (x=2 -> 512)
263 _FloppyCMD(device, 18); // number of tracks to operate on
264 _FloppyCMD(device, 0x1b); // GAP3 length, 27 is default for 3.5"
265 _FloppyCMD(device, 0xff); // data length (0xff if B/S != 0)
266
267 irq_waitFloppy(); // don't SENSE_INTERRUPT here!
268
269 unsigned char st0, st1, st2, rcy, rhe, rse, bps;
270 st0 = _FloppyData(device);
271 st1 = _FloppyData(device);
272 st2 = _FloppyData(device);
273 rcy = _FloppyData(device);
274 rhe = _FloppyData(device);
275 rse = _FloppyData(device);
276 bps = _FloppyData(device);
277
278 (void)rse;
279 (void)rhe;
280 (void)rcy;
281
282 if (st0 & 0xC0)
283
284 if(st0 & 0xC0) {
285 if ((st0 >> 6) == 0) return _FloppyError(device,FLOPPY_ERROR_NOSUPPORT);
286 if ((st0 >> 6) == 1) return _FloppyError(device,FLOPPY_ERROR_NOSUPPORT);
287 if ((st0 >> 6) == 2) return _FloppyError(device,FLOPPY_ERROR_CMD_UNK);
288 if ((st0 >> 6) == 3) return _FloppyError(device,FLOPPY_ERROR_NOREADY);
289 }
290 if(st1 & 0x80) return _FloppyError(device,FLOPPY_ERROR_EOL);
291 if(st0 & 0x08) return _FloppyError(device,FLOPPY_ERROR_NOREADY);
292 if(st1 & 0x20) return _FloppyError(device,FLOPPY_ERROR_CRC);
293 if(st1 & 0x10) return _FloppyError(device,FLOPPY_ERROR_CONTROLLER);
294 if(st1 & 0x04) return _FloppyError(device,FLOPPY_ERROR_NODATA);
295 if((st1|st2) & 0x01) return _FloppyError(device,FLOPPY_ERROR_NOADDR);
296 if(st2 & 0x40) return _FloppyError(device,FLOPPY_ERROR_DELADDR);
297 if(st2 & 0x20) return _FloppyError(device,FLOPPY_ERROR_CRC);
298 if(st2 & 0x10) return _FloppyError(device,FLOPPY_ERROR_CYLINDER);
299 if(st2 & 0x04) return _FloppyError(device,FLOPPY_ERROR_UPD765);
300 if(st2 & 0x02) return _FloppyError(device,FLOPPY_ERROR_CYLINDER);
301 if(bps != 0x2) return _FloppyError(device,FLOPPY_ERROR_512B);
302 if(st1 & 0x02) return _FloppyError(device,FLOPPY_ERROR_WRITE);
303 _FloppyMotor(device, 0);
304
305 // What a hell?
306 return 0;
307 }
308
309 qemu_log("floppy_do_sector: 20 retries exhausted\n");
310 _FloppyMotor(device, 0);
311 return _FloppyError(device,FLOPPY_ERROR_TRACK);
312
313 }
314
315 void addr_2_coff(uint32_t addr, uint16_t* cyl, uint32_t* offset, uint32_t* size) {
316 if (offset) *offset = addr % FLOPPY_144_CYLINDER_SIZE;
317 if (size) *size = FLOPPY_144_CYLINDER_SIZE - (addr % FLOPPY_144_CYLINDER_SIZE);
318 if (cyl) *cyl = addr / FLOPPY_144_CYLINDER_SIZE;
319 }
320
321
322
323 int _FloppyCache(int device,FloppyMode mode,unsigned int addr,unsigned int* offset,unsigned int* size){
324 //if (Floppy(device).Status != 1) return _FloppyError(device,FLOPPY_ERROR_NOREADY);
325 //qemu_log("[FD%c] Cache | Addr: %d | Off: %d | Size: %d",(device==FDB?'B':'A'),addr,offset,size);
326 uint16_t cyl;
327 addr_2_coff(addr, &cyl, offset, size);
328 if (mode == FLOPPY_READ && cyl == floppy_data[device].Cyr) return 0;
329 int ret = _FloppyTrack(device, cyl, mode);
330 if (ret >= 0) floppy_data[device].Cyr = cyl;
331 return ret;
332 }
333
343 size_t _FloppyRead(int device,char* dst,uint32_t addr,uint32_t size){
344 if (Floppy(device).Status != 1) return _FloppyError(FDA,FLOPPY_ERROR_NOREADY);
345 //qemu_log("[FD%c] Read | Addr: %d | Size: %d",(device==FDB?'B':'A'),addr,size);
346 floppy_data[device].LastErr = 0;
347 uint32_t offset=0, ws=0;
348 size_t ds = 0;
349 int ret;
350 while (size > ds){
351 ret = _FloppyCache(device,FLOPPY_READ,addr+ds,&offset,&ws);
352 if (ret < 0) return ret;
353 if (ws > size - ds) ws = size - ds;
354 memcpy(dst + ds, (void*) &FLOPPY_DMABUFA[offset], ws);
355 ds += ws;
356 }
357 return ds;
358 }
359
360 size_t _FloppyWrite(int device,const char* dst,uint32_t addr,uint32_t size){
361 if (Floppy(device).Status != 1) return _FloppyError(FDA,FLOPPY_ERROR_NOREADY);
362 //qemu_log("[FD%c] Write | Addr: %d | Size: %d",(device==FDB?'B':'A'),addr,size);
363
364 uint32_t offset=0, ws=0;
365 size_t ds = 0;
366 int ret;
367 while (size > ds){
368 ret = _FloppyCache(device,FLOPPY_READ,addr+ds, &offset, &ws);
369 if (ret < 0) return ret;
370 if (ws > size - ds) ws = size - ds;
371 memcpy((void*) &FLOPPY_DMABUFA[offset],dst+ds,ws);
372 ret = _FloppyCache(device,FLOPPY_WRITE,addr+ds,nullptr,nullptr);
373 if (ret < 0) return ret;
374 ds += ws;
375 }
376 return ds;
377 }
378
379 void _FloppyServiceA(){
380 outb(0x70, 0x10);
381 unsigned drives = inb(0x71);
382 int DiskA = drives >> 4;
383 if (DiskA != floppy_data[FDA].Type){
384 // Выполняем обслуживание Диска А, так как диск извлечен.
385 floppy_data[FDA].Type = DiskA;
386 floppy_data[FDA].Status = (floppy_data[FDA].Type == 4?1:0);
387 dpm_unmount('A', false);
388 dpm_reg('A',"Disk A","Unknown",floppy_data[FDA].Status,0,0,0,3,"FLOP-PYDA",0);
389 }
390 }
391
395 void _FloppyCheck(){
396 outb(0x70, 0x10);
397 unsigned drives = inb(0x71);
398 if (Floppy(FDA).Type != drives >> 4){
399 floppy_data[FDA].Type = drives >> 4;
400 if (_FloppyDebug) qemu_log("[FDA] Change disk type: %d",Floppy(FDA).Type);
401 }
402 if (Floppy(FDB).Type != (drives & 0xf)){
403 floppy_data[FDB].Type = (drives & 0xf);
404 if (_FloppyDebug) qemu_log("[FDB] Change disk type: %d",Floppy(FDB).Type);
405 }
406 if (Floppy(FDA).Type == 0) {
407 floppy_data[FDA].Status = _FloppyError(FDA,FLOPPY_ERROR_NOREADY);
408 } else if (Floppy(FDA).Type != 4){
409 floppy_data[FDA].Status = _FloppyError(FDA,FLOPPY_ERROR_NOSUPPORT);
410 } else {
411 floppy_data[FDA].Status = 1;
412 }
413
414 if (Floppy(FDB).Type == 0) {
415 floppy_data[FDB].Status = _FloppyError(FDB,FLOPPY_ERROR_NOREADY);
416 } else if (Floppy(FDB).Type != 4){
417 floppy_data[FDB].Status = _FloppyError(FDB,FLOPPY_ERROR_NOSUPPORT);
418 } else {
419 floppy_data[FDB].Status = 1;
420 }
421
422
423 // Обновление имени устройства
424
425 char fda_fs[6],fdb_fs[6] = {0};
426 char fda_label[12],fdb_label[12] = {0};
427 char fs_fat12[6] = {'F','A','T','1','2',0};
428 // char fs_smfs10[8] = {'S','M','F','S','1','.','0',0};
429 int read = -1;
430 if (Floppy(FDA).Status == 1){
431 //qemu_log("[FD%c] U",(device==FDB?'B':'A'));
432 read = Floppy(FDA).Read(FDA,fda_fs,54,5);
433 if (_FloppyDebug) qemu_log("[FDA] Read File System => (%d) '%s'",read,fda_fs);
434 if (Floppy(FDA).LastErr != 0){
435 floppy_data[FDA].Status = FLOPPY_ERROR_NOREADY;
436 if (_FloppyDebug) qemu_log("[FDA] No ready drive!");
437 floppy_data[FDA].LastErr = 0;
438 }
439 read = Floppy(FDA).Read(FDA,fda_fs,54,8);
440 if (Floppy(FDA).LastErr == 0 && strcmp(fs_fat12, fda_fs) == 0){
441 if (_FloppyDebug) qemu_log("[FDA] File System: FAT12");
442 Floppy(FDA).Read(FDA, fda_label, 43, 11);
443 fda_label[11] = 0;
444 memcpy((void*) floppy_data[FDA].Name, fda_label, 12);
445 memcpy((void*) floppy_data[FDA].FileSystem, fda_fs, 6);
446 if (_FloppyDebug) qemu_log("[FDA] Label: %s",floppy_data[FDA].Name);
447
448 }
449 }
450 if (Floppy(FDB).Status == 1){
451 read = Floppy(FDB).Read(FDB,fdb_fs,54,5);
452 if (_FloppyDebug) qemu_log("[FDB] Read File System => (%d) '%s'",read,fdb_fs);
453 if (Floppy(FDB).LastErr != 0){
454 floppy_data[FDB].Status = FLOPPY_ERROR_NOREADY;
455 if (_FloppyDebug) qemu_log("[FDB] No ready drive!");
456 floppy_data[FDB].LastErr = 0;
457 } else if (strcmp(fs_fat12,fdb_fs) == 0){
458 if (_FloppyDebug) qemu_log("[FDB] File System: FAT12");
459 Floppy(FDB).Read(FDB,fdb_label,43,11);
460 fdb_label[11] = 0;
461 memcpy((void*) floppy_data[FDB].Name, fdb_label, 12);
462 if (_FloppyDebug) qemu_log("[FDB] Label: %s",floppy_data[FDB].Name);
463 memcpy((void*) floppy_data[FDB].FileSystem, fdb_fs, 6);
464
465 }
466 }
467 //kfree(fs_fat12);
468
469 }
470
471 size_t _FloppyDPMWriteA(size_t Disk, uint64_t high_offset, uint64_t low_offset, size_t Size, void* Buffer){
472 qemu_log("[DPM] Floppy A Write! Offset: %d | Size: %d",low_offset, Size);
473 if (Floppy(0).Status != 1) return 0;
474 //qemu_log("[FD%c] Write | Addr: %d | Size: %d",(device==FDB?'B':'A'),addr,size);
475
476 uint32_t _offset = 0, ws = 0;
477 size_t ds = 0;
478 int ret;
479 while (Size > ds){
480 ret = _FloppyCache(0,FLOPPY_READ, low_offset+ds, &_offset, &ws);
481 if (ret < 0) return ret;
482 if (ws > Size - ds) ws = Size - ds;
483 memcpy((void*) &FLOPPY_DMABUFA[_offset], Buffer+ds, ws);
484 ret = _FloppyCache(0,FLOPPY_WRITE, low_offset+ds, nullptr, nullptr);
485 if (ret < 0) return ret;
486 ds += ws;
487 }
488 return ds;
489 }
490
491 size_t _FloppyDPMReadA(size_t Disk, uint64_t high_offset, uint64_t low_offset, size_t Size, void* Buffer){
492 qemu_log("[DPM] Floppy A Read! Offset: %d | Size: %d",low_offset, Size);
493 if (Floppy(0).Status != 1) return 0;
494 floppy_data[0].LastErr = 0;
495 uint32_t _offset=0, ws=0;
496 size_t ds = 0;
497 int ret;
498 while (Size > ds){
499 ret = _FloppyCache(0, FLOPPY_READ, low_offset+ds, &_offset, &ws);
500 if (ret < 0) return ret;
501 if (ws > Size - ds) ws = Size - ds;
502 memcpy(Buffer + ds, (void*) &FLOPPY_DMABUFA[_offset], ws);
503 ds += ws;
504 }
505 return ds;
506 }
507
508 void _FloppyPrint(){
509 _FloppyCheck();
510 _tty_printf("[-] Floppy Disk A\n");
511 _tty_printf(" |--- Status: %d\n",Floppy(FDA).Status);
512 _tty_printf(" |--- Type: %s\n",drive_types[Floppy(FDA).Type]);
513 if (Floppy(FDA).Status == 1){
514 _tty_printf(" |--- File System: %s\n",Floppy(FDA).FileSystem);
515 _tty_printf(" |--- Label: %s\n",Floppy(FDA).Name);
516 }
517
518 tty_printf("\n");
519
520 _tty_printf("[-] Floppy Disk B\n");
521 _tty_printf(" |--- Status: %d\n",Floppy(FDB).Status);
522 _tty_printf(" |--- Type: %s\n",drive_types[Floppy(FDB).Type]);
523 if (Floppy(FDB).Status == 1){
524 _tty_printf(" |--- File System: %s\n",Floppy(FDB).FileSystem);
525 _tty_printf(" |--- Label: %s\n",Floppy(FDB).Name);
526 }
527 }
528
529 // Obviously you'd have this return the data, start drivers or something.
530 void initFloppy() {
531 tty_printf("Поиск дискет...\n");
532
533 floppy_data[FDA].Index = FDA;
534 floppy_data[FDA].Type = 0;
535
536 floppy_data[FDA].Cache = &_FloppyCache;
537 floppy_data[FDB].Cache = &_FloppyCache;
538
539 floppy_data[FDA].Read = &_FloppyRead;
540 floppy_data[FDB].Read = &_FloppyRead;
541
542 floppy_data[FDA].Write = &_FloppyWrite;
543 floppy_data[FDB].Write = &_FloppyWrite;
544
545 floppy_data[FDA].Addr = FLOPPY_MAIN;
546 floppy_data[FDB].Addr = FLOPPY_SECO;
547
548 floppy_data[FDA].Cyr = -1;
549 floppy_data[FDB].Cyr = -1;
550
551 floppy_data[FDA].Status = 0;
552 floppy_data[FDB].Status = 0;
553 floppy_data[FDA].Motor = 0;
554 floppy_data[FDB].Motor = 0;
555
556 _FloppyReset(FDA);
557 _FloppyReset(FDB);
558 register_interrupt_handler(32+6,&irqFloppy);
559
560 dpm_reg('A',"Disk A","Unknown",1,0,0,0,3,"FLOP-PYDA",0);
561 dpm_metadata_write('A', (uint32_t) &floppy_data[FDA]);
562 dpm_fnc_write('A',_FloppyDPMReadA,_FloppyDPMWriteA);
563
564 _FloppyServiceA();
565
566
567 dpm_reg('B',"Disk B","Unknown",0,0,0,0,3,"FLOP-PYDB",0);
568 dpm_metadata_write('B', (uint32_t) &floppy_data[FDB]);
569
570 _FloppyCheck();
571 _FloppyPrint();
572
573 // fs_tarfs_detect('A');
574 // fs_tarfs_detect('R');
575 //
576 // char* fs_fat12 = kmalloc(32);
577 // size_t read = dpm_read('A', 0x1F, 12, fs_fat12);
578 //
579 // qemu_log("[DPM] [A] Ready: %d | '%s'",read,fs_fat12);
580
581 // base - 0x03f0
582 //int data = 0;ЮПСРВЯАФ1234567890-=
583 //char text[32] = {0};
584 //int read = Floppy(0).Read(0,text,0xD0,32);
585 //qemu_log("FD0:TEST = (%d) '%s'",read,text);
586 //char* write = "SAYORIFLOPPY";
587 //floppy_write(0,write,strlen(write));
588 }
mode
uint32_t mode
Режим работы (0 - Обычный | 1 - Режим логирования)
Definition: bootscreen.c:23
dpm_reg
int dpm_reg(char Letter, char *Name, char *FS, int Status, size_t Size, size_t Sectors, size_t SectorSize, int AddrMode, char *Serial, void *Point)
[DPM] Регистрация дискового раздела
Definition: dpm.c:187
_FloppyRead
size_t _FloppyRead(int device, char *dst, uint32_t addr, uint32_t size)
[Floppy] Чтение данных на устройство
Definition: floppy.c:343
_FloppyTrack
int _FloppyTrack(int device, unsigned cyl, FloppyMode dir)
Definition: floppy.c:233
_FloppyCheck
void _FloppyCheck()
Автоматическое обновление данных о FD.
Definition: floppy.c:395
strcmp
int strcmp(const char *s1, const char *s2)
Сравнение строк
Definition: string.c:253
memcpy
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.
Definition: string.c:173
__attribute__
Структура файла
Definition: ahci.h:15
floppy
Definition: floppy.h:112
floppy::Ticks
int Ticks
Тики работы дисковода
Definition: floppy.h:117
floppy::Index
int Index
Индекс устройства
Definition: floppy.h:113
floppy::LastErr
int LastErr
Посл. ошибка
Definition: floppy.h:116
floppy::Motor
int Motor
Статус мотора
Definition: floppy.h:119
floppy::Addr
int Addr
Адрес устройства
Definition: floppy.h:114
floppy::Cache
FloppyCache_t Cache
Команда для кэша
Definition: floppy.h:125
floppy::Read
FloppyR_t Read
Команда для чтения данных
Definition: floppy.h:123
floppy::Cyr
unsigned Cyr
Цилиндры
Definition: floppy.h:122
floppy::Type
int Type
Тип устройства
Definition: floppy.h:118
floppy::Status
int Status
Статус
Definition: floppy.h:115
floppy::Write
FloppyW_t Write
Команда для записи данных
Definition: floppy.h:124
registers
Definition: common.h:59
sleep_ms
void sleep_ms(uint32_t milliseconds)
Ожидание по миллисекундам
Definition: timer.c:68