15 #include <sys/types.h>
17 #include <sys/ioctl.h>
19 #include "gpio/ps_protocol.h"
20 #include "platforms/amiga/gayle-ide/ide.h"
22 #define SIZE_KILO 1024
23 #define SIZE_MEGA (1024 * 1024)
24 #define SIZE_GIGA (1024 * 1024 * 1024)
26 uint8_t garbege_datas[2 * SIZE_MEGA];
33 uint8_t loop_tests = 0, total_errors = 0;
35 void sigint_handler(int sig_num) {
36 printf("Received sigint %d, exiting.\n", sig_num);
37 printf("Total number of transaction errors occured: %d\n", total_errors);
44 int main(int argc, char *argv[]) {
45 uint32_t test_size = 512 * SIZE_KILO, cur_loop = 0;
47 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2);
48 srand((unsigned int)f2.tv_nsec);
50 signal(SIGINT, sigint_handler);
53 ps_reset_state_machine();
58 write8(0xbfe201, 0x0101); //CIA OVL
59 write8(0xbfe001, 0x0000); //CIA OVL LOW
62 test_size = atoi(argv[1]) * SIZE_KILO;
63 if (test_size == 0 || test_size > 2 * SIZE_MEGA) {
64 test_size = 512 * SIZE_KILO;
66 printf("Testing %d KB of memory.\n", test_size / SIZE_KILO);
68 if (strcmp(argv[2], "l") == 0) {
69 printf("Looping tests.\n");
76 printf("Writing garbege datas.\n");
77 for (uint32_t i = 0; i < test_size; i++) {
78 while(garbege_datas[i] == 0x00)
79 garbege_datas[i] = (uint8_t)(rand() % 0xFF);
80 write8(i, (uint32_t)garbege_datas[i]);
83 printf("Reading back garbege datas, read8()...\n");
84 for (uint32_t i = 0; i < test_size; i++) {
85 uint32_t c = read8(i);
86 if (c != garbege_datas[i]) {
88 printf("READ8: Garbege data mismatch at $%.6X: %.2X should be %.2X.\n", i, c, garbege_datas[i]);
92 printf("read8 errors total: %d.\n", errors);
93 total_errors += errors;
97 printf("Reading back garbege datas, read16(), even addresses...\n");
98 for (uint32_t i = 0; i < (test_size) - 2; i += 2) {
99 uint32_t c = be16toh(read16(i));
100 if (c != *((uint16_t *)&garbege_datas[i])) {
102 printf("READ16_EVEN: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
106 printf("read16 even errors total: %d.\n", errors);
107 total_errors += errors;
111 printf("Reading back garbege datas, read16(), odd addresses...\n");
112 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
113 uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
114 if (c != *((uint16_t *)&garbege_datas[i])) {
116 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
120 printf("read16 odd errors total: %d.\n", errors);
124 printf("Reading back garbege datas, read32(), even addresses...\n");
125 for (uint32_t i = 0; i < (test_size) - 4; i += 2) {
126 uint32_t c = be32toh(read32(i));
127 if (c != *((uint32_t *)&garbege_datas[i])) {
129 printf("READ32_EVEN: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
133 printf("read32 even errors total: %d.\n", errors);
134 total_errors += errors;
138 printf("Reading back garbege datas, read32(), odd addresses...\n");
139 for (uint32_t i = 1; i < (test_size) - 4; i += 2) {
140 uint32_t c = read8(i);
141 c |= (be16toh(read16(i + 1)) << 8);
142 c |= (read8(i + 3) << 24);
143 if (c != *((uint32_t *)&garbege_datas[i])) {
145 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
149 printf("read32 odd errors total: %d.\n", errors);
150 total_errors += errors;
154 printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
155 for (uint32_t i = 0; i < test_size; i++) {
156 write8(i, (uint32_t)0x0);
159 printf("[WORD] Writing garbege datas to Chip, unaligned...\n");
160 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
161 uint16_t v = *((uint16_t *)&garbege_datas[i]);
162 write8(i, (v & 0x00FF));
163 write8(i + 1, (v >> 8));
167 printf("Reading back garbege datas, read16(), odd addresses...\n");
168 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
169 uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
170 if (c != *((uint16_t *)&garbege_datas[i])) {
172 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
176 printf("read16 odd errors total: %d.\n", errors);
177 total_errors += errors;
180 printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
181 for (uint32_t i = 0; i < test_size; i++) {
182 write8(i, (uint32_t)0x0);
185 printf("[LONG] Writing garbege datas to Chip, unaligned...\n");
186 for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
187 uint32_t v = *((uint32_t *)&garbege_datas[i]);
188 write8(i , v & 0x0000FF);
189 write16(i + 1, htobe16(((v & 0x00FFFF00) >> 8)));
190 write8(i + 3 , (v & 0xFF000000) >> 24);
194 printf("Reading back garbege datas, read32(), odd addresses...\n");
195 for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
196 uint32_t c = read8(i);
197 c |= (be16toh(read16(i + 1)) << 8);
198 c |= (read8(i + 3) << 24);
199 if (c != *((uint32_t *)&garbege_datas[i])) {
201 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
205 printf("read32 odd errors total: %d.\n", errors);
206 total_errors += errors;
210 printf ("Loop %d done. Begin loop %d.\n", cur_loop + 1, cur_loop + 2);
211 printf ("Current total errors: %d.\n", total_errors);
218 void m68k_set_irq(unsigned int level) {
221 struct ide_controller *get_ide(int index) {