1 |
dpavlin |
24 |
/* |
2 |
|
|
* $Id: disk.c,v 1.2 2006/05/22 04:53:52 debug Exp $ |
3 |
|
|
* |
4 |
|
|
* GXemul demo: Disk image access |
5 |
|
|
* |
6 |
|
|
* This file is in the Public Domain. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#include "dev_cons.h" |
10 |
|
|
#include "dev_disk.h" |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#ifdef MIPS |
14 |
|
|
/* Note: The ugly cast to a signed int (32-bit) causes the address to be |
15 |
|
|
sign-extended correctly on MIPS when compiled in 64-bit mode */ |
16 |
|
|
#define PHYSADDR_OFFSET ((signed int)0xa0000000) |
17 |
|
|
#else |
18 |
|
|
#define PHYSADDR_OFFSET 0 |
19 |
|
|
#endif |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#define PUTCHAR_ADDRESS (PHYSADDR_OFFSET + \ |
23 |
|
|
DEV_CONS_ADDRESS + DEV_CONS_PUTGETCHAR) |
24 |
|
|
#define HALT_ADDRESS (PHYSADDR_OFFSET + \ |
25 |
|
|
DEV_CONS_ADDRESS + DEV_CONS_HALT) |
26 |
|
|
#define DISK_ADDRESS (PHYSADDR_OFFSET + DEV_DISK_ADDRESS) |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
void printchar(char ch) |
30 |
|
|
{ |
31 |
|
|
*((volatile unsigned char *) PUTCHAR_ADDRESS) = ch; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
void printstr(char *s) |
36 |
|
|
{ |
37 |
|
|
while (*s) |
38 |
|
|
printchar(*s++); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
void halt(void) |
43 |
|
|
{ |
44 |
|
|
*((volatile unsigned char *) HALT_ADDRESS) = 0; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
void printhex2(int i) |
49 |
|
|
{ |
50 |
|
|
printchar("0123456789abcdef"[i >> 4]); |
51 |
|
|
printchar("0123456789abcdef"[i & 15]); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
void printhex4(int i) |
56 |
|
|
{ |
57 |
|
|
printhex2(i >> 8); |
58 |
|
|
printhex2(i & 255); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
void f(void) |
63 |
|
|
{ |
64 |
|
|
int ofs, ide_id = 0, status, i; |
65 |
|
|
unsigned char ch; |
66 |
|
|
|
67 |
|
|
printstr("Testing dev_disk.\n"); |
68 |
|
|
printstr("Assuming that IDE ID 0 (primary master) is available.\n"); |
69 |
|
|
|
70 |
|
|
for (ofs = 0; ofs < 1024; ofs += 512) { |
71 |
|
|
printstr("\n"); |
72 |
|
|
|
73 |
|
|
*((volatile int *) (DISK_ADDRESS + DEV_DISK_OFFSET)) = ofs; |
74 |
|
|
*((volatile int *) (DISK_ADDRESS + DEV_DISK_ID)) = ide_id; |
75 |
|
|
|
76 |
|
|
*((volatile int *) (DISK_ADDRESS + DEV_DISK_START_OPERATION)) = |
77 |
|
|
DEV_DISK_OPERATION_READ; |
78 |
|
|
|
79 |
|
|
/* Get status: */ |
80 |
|
|
status = *((volatile int *) (DISK_ADDRESS + DEV_DISK_STATUS)); |
81 |
|
|
|
82 |
|
|
if (status == 0) { |
83 |
|
|
printstr("Read failed.\n"); |
84 |
|
|
halt(); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
printstr("Sector dump:\n"); |
88 |
|
|
for (i = 0; i < 512; i++) { |
89 |
|
|
if ((i % 16) == 0) { |
90 |
|
|
printhex4(i); |
91 |
|
|
printstr(" "); |
92 |
|
|
} |
93 |
|
|
printstr(" "); |
94 |
|
|
ch = *((volatile unsigned char *) DISK_ADDRESS |
95 |
|
|
+ DEV_DISK_BUFFER + i); |
96 |
|
|
printhex2(ch); |
97 |
|
|
if ((i % 16) == 15) { |
98 |
|
|
int j; |
99 |
|
|
printstr(" "); |
100 |
|
|
for (j = i-15; j <= i; j++) { |
101 |
|
|
ch = *((volatile unsigned char *) |
102 |
|
|
DISK_ADDRESS + DEV_DISK_BUFFER + j); |
103 |
|
|
if (ch < 32 || ch >= 127) |
104 |
|
|
ch = '.'; |
105 |
|
|
printchar(ch); |
106 |
|
|
} |
107 |
|
|
printstr("\n"); |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
printstr("\nDone.\n"); |
113 |
|
|
halt(); |
114 |
|
|
} |
115 |
|
|
|