1 |
/* |
2 |
* $Id: test_disk.c,v 1.1 2005/08/09 18:29:20 debug Exp $ |
3 |
* |
4 |
* Test program for dev_disk. This program reads the first two 512-byte |
5 |
* sectors of a disk image, and dumps them in hex/ascii format. |
6 |
* |
7 |
* Compile: |
8 |
* mips64-unknown-elf-gcc -O2 test_disk.c -mips4 -mabi=64 -c |
9 |
* |
10 |
* and link: |
11 |
* mips64-unknown-elf-ld -Ttext 0xa800000000030000 -e f |
12 |
* test_disk.o -o test_disk --oformat=elf64-bigmips |
13 |
* |
14 |
* Run: |
15 |
* gxemul -d disk.img -E testmips test_disk |
16 |
*/ |
17 |
|
18 |
/* Note: The cast to a signed int causes the address to be sign-extended |
19 |
correctly to 0xffffffffb00000xx when compiled in 64-bit mode */ |
20 |
#define PUTCHAR_ADDRESS ((signed int)0xb0000000) |
21 |
#define HALT_ADDRESS ((signed int)0xb0000010) |
22 |
|
23 |
#define DISK_ADDRESS ((signed int)0xb3000000) |
24 |
|
25 |
void printchar(char ch) |
26 |
{ |
27 |
*((volatile unsigned char *) PUTCHAR_ADDRESS) = ch; |
28 |
} |
29 |
|
30 |
void halt(void) |
31 |
{ |
32 |
*((volatile unsigned char *) HALT_ADDRESS) = 0; |
33 |
} |
34 |
|
35 |
void printstr(char *s) |
36 |
{ |
37 |
while (*s) |
38 |
printchar(*s++); |
39 |
} |
40 |
|
41 |
void printhex2(int i) |
42 |
{ |
43 |
printchar("0123456789abcdef"[i >> 4]); |
44 |
printchar("0123456789abcdef"[i & 15]); |
45 |
} |
46 |
|
47 |
void printhex4(int i) |
48 |
{ |
49 |
printhex2(i >> 8); |
50 |
printhex2(i & 255); |
51 |
} |
52 |
|
53 |
void f(void) |
54 |
{ |
55 |
int ofs, scsi_id = 0, status, i; |
56 |
unsigned char ch; |
57 |
|
58 |
printstr("Testing dev_disk.\n"); |
59 |
printstr("Assuming that SCSI ID 0 is available.\n"); |
60 |
|
61 |
for (ofs = 0; ofs < 1024; ofs += 512) { |
62 |
printstr("\n"); |
63 |
|
64 |
*((volatile int *) (DISK_ADDRESS + 0)) = ofs; |
65 |
*((volatile int *) (DISK_ADDRESS + 0x10)) = scsi_id; |
66 |
|
67 |
/* 0 = read, 1 = write: */ |
68 |
*((volatile int *) (DISK_ADDRESS + 0x20)) = 0; |
69 |
|
70 |
/* Get status: */ |
71 |
status = *((volatile int *) (DISK_ADDRESS + 0x30)); |
72 |
|
73 |
if (status == 0) { |
74 |
printstr("Read failed.\n"); |
75 |
halt(); |
76 |
} |
77 |
|
78 |
printstr("Sector dump:\n"); |
79 |
for (i = 0; i < 512; i++) { |
80 |
if ((i % 16) == 0) { |
81 |
printhex4(i); |
82 |
printstr(" "); |
83 |
} |
84 |
printstr(" "); |
85 |
ch = *((volatile unsigned char *) DISK_ADDRESS |
86 |
+ i + 0x4000); |
87 |
printhex2(ch); |
88 |
if ((i % 16) == 15) { |
89 |
int j; |
90 |
printstr(" "); |
91 |
for (j = i-15; j <= i; j++) { |
92 |
ch = *((volatile unsigned char *) |
93 |
DISK_ADDRESS + j + 0x4000); |
94 |
if (ch < 32 || ch >= 127) |
95 |
ch = '.'; |
96 |
printchar(ch); |
97 |
} |
98 |
printstr("\n"); |
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
printstr("\nDone.\n"); |
104 |
halt(); |
105 |
} |
106 |
|