Initialize
[sdk/emulator/qemu.git] / hw / s5pc1xx_debug.c
1 /*
2  * S5PC110 Test & Debug
3  *
4  * Copyright (c) 2009 Samsung Electronics.
5  * Contributed by Kirill Batuzov <batuzovk@ispras.ru>
6  */
7
8 /* Print all system information to stderr */
9 static __attribute__((unused)) void debug_sysinfo(const struct s5pc1xx_state_s *s)
10 {
11     fprintf(stderr, "CPU: %s\n", s->env->cpu_model_str);
12     fprintf(stderr, "SDRAM: %lu MB\n", s->sdram_size / (1024 * 1024));
13     fprintf(stderr, "SRAM: %lu KB\n", s->isram_size / 1024);
14     fprintf(stderr, "SROM: %lu KB\n", s->isrom_size / 1024);
15 }
16
17
18 /* Interrupt Controller */
19
20 #define ADDR    0xF2000F00
21
22
23 target_phys_addr_t vic_base[] = {
24     S5PC1XX_VIC0_BASE, S5PC1XX_VIC1_BASE, S5PC1XX_VIC2_BASE, S5PC1XX_VIC3_BASE
25 };
26
27 typedef enum {
28     enable, disable, swint, swclear, select_irq, selclear, priomask, daisyprio
29 } irq_op;
30
31
32 static __attribute__((unused)) void test_irq_handler(void *opaque, int irq,
33                                                      int level)
34 {
35     const char *name;
36
37     if (irq)
38         name = "FIQ";
39     else
40         name = "IRQ";
41
42     if (level)
43         fprintf(stderr, "%s was raised\n", name);
44 }
45
46 static __attribute__((unused)) qemu_irq *test_irq_init(void)
47 {
48     return qemu_allocate_irqs(test_irq_handler, NULL, 2);
49 }
50
51 static __attribute__((unused)) uint32_t test_irq_op(irq_op op, int irq,
52                                                     int is_wr, uint32_t val)
53 {
54     int vic_id = irq / S5PC1XX_VIC_SIZE;
55     uint32_t res;
56     target_phys_addr_t base = vic_base[vic_id];
57     target_phys_addr_t off;
58
59     switch (op) {
60         case enable:
61             off = 0x10;
62             break;
63         case disable:
64             off = 0x14;
65             break;
66         case swint:
67             off = 0x18;
68             break;
69         case swclear:
70             off = 0x1C;
71             break;
72         case select_irq:
73         case selclear:
74             off = 0xC;
75             break;
76         case priomask:
77             off = 0x24;
78             break;
79         case daisyprio:
80             off = 0x28;
81             break;
82         default:
83             off = 0x0;
84             break;
85     }
86     if (op == priomask || op == daisyprio || !is_wr) {
87         if (is_wr) {
88             cpu_physical_memory_write(base + off, (uint8_t *)&val, 4);
89         } else {
90             cpu_physical_memory_read(base + off, (uint8_t *)&res, 4);
91         }
92         return res;
93     }
94     if (op == select_irq || op == selclear)
95         cpu_physical_memory_read(base + off, (uint8_t *)&res, 4);
96     if (op == select_irq)
97         res |= 1 << (irq % S5PC1XX_VIC_SIZE);
98     else if (op == selclear)
99         res &= ~(1 << (irq % S5PC1XX_VIC_SIZE));
100     else
101         res = 1 << (irq % S5PC1XX_VIC_SIZE);
102     cpu_physical_memory_write(base + off, (uint8_t *)&res, 4);
103     return 0;
104 }
105
106 static __attribute__((unused)) void test_irq_script(struct s5pc1xx_state_s *s)
107 {
108     uint32_t res;
109
110     fprintf(stderr,"Step 1: Interrupts disabled. Raising and lowering them.\n");
111     qemu_irq_raise(s5pc1xx_get_irq(s, 14));
112     qemu_irq_raise(s5pc1xx_get_irq(s, 33));
113     qemu_irq_lower(s5pc1xx_get_irq(s, 14));
114     qemu_irq_lower(s5pc1xx_get_irq(s, 33));
115     qemu_irq_raise(s5pc1xx_get_irq(s, 69));
116     qemu_irq_lower(s5pc1xx_get_irq(s, 69));
117     qemu_irq_raise(s5pc1xx_get_irq(s, 101));
118
119     fprintf(stderr, "Step 2: Interrupt 101 is raised. Enable some other.\n");
120     test_irq_op(enable, 4, 1, 0);
121     test_irq_op(enable, 34, 1, 0);
122     test_irq_op(enable, 5, 1, 0);
123
124     fprintf(stderr, "Step 3: Interrupt 101 is raised. Enable it.\n");
125     res = 0xDDEEAABB;
126     cpu_physical_memory_write(0xF2300114, (const uint8_t *)&res, 4);
127     test_irq_op(enable, 101, 1, 0);
128     cpu_physical_memory_read(ADDR, (uint8_t *)&res, 4);
129     fprintf(stderr, "Interrupt 101 vector is %x\n", res);
130     qemu_irq_raise(s5pc1xx_get_irq(s, 5));
131     fprintf(stderr, "Step 4: Interrupt 101 has been acknoledged. "
132                     "Interrupt 5 has been raised.\n");
133
134     fprintf(stderr, "Step 5: Generate IRQ 4 with higher priority.\n");
135     res = 0xa;
136     cpu_physical_memory_write(0xF2000210, (const uint8_t *)&res, 4);
137     res = 0xDDEEBBAA;
138     cpu_physical_memory_write(0xF2000110, (const uint8_t *)&res, 4);
139     qemu_irq_raise(s5pc1xx_get_irq(s, 4));
140
141     fprintf(stderr, "Step 6: Acknoledge IRQ 4. Then lower it.\n");
142     cpu_physical_memory_read(ADDR, (uint8_t *)&res, 4);
143     fprintf(stderr, "Interrupt 4 vector is %x\n", res);
144     qemu_irq_lower(s5pc1xx_get_irq(s, 4));
145
146     fprintf(stderr, "Step 7: Finalize IRQ 4 processing. No new interrupts "
147                     "should appear as IRQ 101 is in progress.\n");
148     cpu_physical_memory_write(ADDR, (const uint8_t *)&res, 4);
149
150     fprintf(stderr, "Step 8: Mask IRQ 4's priority, then raise it again.\n");
151     test_irq_op(priomask, 0, 1, 0xffff & ~(1 << 0xa));
152     qemu_irq_raise(s5pc1xx_get_irq(s, 4));
153
154     fprintf(stderr, "Step 9: Finalize IRQ 101 processing. "
155                     "We should recive IRQ 5.\n");
156     res = 0xDDEEBBCC;
157     cpu_physical_memory_write(0xF2000114, (const uint8_t *)&res, 4);
158     qemu_irq_lower(s5pc1xx_get_irq(s, 101));
159     cpu_physical_memory_write(ADDR, (const uint8_t *)&res, 4);
160     cpu_physical_memory_read(ADDR, (uint8_t *)&res, 4);
161     fprintf(stderr, "Interrupt 5 vector is %x\n", res);
162
163     fprintf(stderr, "Step 10: Finalize IRQs. Clear them all.\n");
164     qemu_irq_lower(s5pc1xx_get_irq(s, 5));
165     qemu_irq_lower(s5pc1xx_get_irq(s, 4));
166     cpu_physical_memory_write(ADDR, (const uint8_t *)&res, 4);
167 }
168
169
170 /* DMA */
171
172 #define DATA_ADDR       0x20010000
173 #define RESULT_ADDR     0x20020000
174 #define PROG_ADDR       0x20030000
175
176 #define DBGGO_ADDR      0xFA200D04
177 #define DBG0_ADDR       0xFA200D08
178 #define DBG1_ADDR       0xFA200D0C
179
180 #define FSC_ADDR        0xFA200034
181 #define FTC1_ADDR       0xFA200044
182 #define CPC1_ADDR       0xFA20010C
183
184
185 uint32_t dbg0 = 0x01A00000;
186 uint32_t dbg1 = PROG_ADDR;
187 uint32_t dbggo = 0x0;
188 uint32_t dbgkill = 0x00010101;
189
190 static const uint8_t dma_data[] = {
191     1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
192    11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
193    21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
194    31, 32
195 };
196
197 static const uint8_t dma_stz[] = {
198     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
199     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
200     0xBC, 0x01, 0x35, 0x40, 0x0D, 0x00, /* DMAMOV   CCR SAI SS4 SB4 DAI DS4 DB4 */
201     0x0C,                               /* DMASTZ   */
202     0x00                                /* DMAEND   */
203 };
204
205 static const uint8_t dma_stzlp[] = {
206     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
207     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
208     0xBC, 0x01, 0x35, 0x40, 0x0D, 0x00, /* DMAMOV   CCR SAI SS4 SB4 DAI DS4 DB4 */
209     0x20, 0x01,                         /* DMALP    2 */
210     0x0C,                               /* DMASTZ   */
211     0x38, 0x01,                         /* DMALPEND */
212     0x00                                /* DMAEND   */
213 };
214
215 static const uint8_t dma_copy[] = {
216     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
217     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
218     0xBC, 0x01, 0x35, 0x40, 0x0D, 0x00, /* DMAMOV   CCR SAI SS4 SB4 DAI DS4 DB4 */
219     0x20, 0x01,                         /* DMALP    2 */
220     0x04,                               /* DMALD    */
221     0x08,                               /* DMAST    */
222     0x38, 0x02,                         /* DMALPEND */
223     0x00                                /* DMAEND   */
224 };
225
226 /* Paradoxically but this should work correctly too. */
227 static const uint8_t dma_copy_2[] = {
228     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
229     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
230     0xBC, 0x01, 0x35, 0x40, 0x0D, 0x00, /* DMAMOV   CCR SAI SS4 SB4 DAI DS4 DB4 */
231     0x20, 0x01,                         /* DMALP    2 */
232     0x08,                               /* DMAST    */
233     0x04,                               /* DMALD    */
234     0x38, 0x02,                         /* DMALPEND */
235     0x00                                /* DMAEND   */
236 };
237
238 static const uint8_t dma_scatter[] = {
239     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
240     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
241     0xBC, 0x01, 0x34, 0x40, 0x0D, 0x00, /* DMAMOV   CCR SAF SS4 SB4 DAI DS4 DB4 */
242     0x20, 0x01,                         /* DMALP    2 */
243     0x04,                               /* DMALD    */
244     0x08,                               /* DMAST    */
245     0x38, 0x02,                         /* DMALPEND */
246     0x00                                /* DMAEND   */
247 };
248
249 static const uint8_t dma_gather[] = {
250     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
251     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
252     0xBC, 0x01, 0x35, 0x00, 0x0D, 0x00, /* DMAMOV   CCR SAI SS4 SB4 DAF DS4 DB4 */
253     0x20, 0x01,                         /* DMALP    2 */
254     0x04,                               /* DMALD    */
255     0x08,                               /* DMAST    */
256     0x38, 0x02,                         /* DMALPEND */
257     0x00                                /* DMAEND   */
258 };
259
260 /* Watchdog abort at DMAEND */
261 static const uint8_t dma_nold[] = {
262     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
263     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
264     0xBC, 0x01, 0x34, 0x00, 0x0D, 0x00, /* DMAMOV   CCR SAF SS4 SB4 DAF DS4 DB4 */
265     0x08,                               /* DMAST    */
266     0x18,                               /* DMANOP   */
267     0x00                                /* DMAEND   */
268 };
269
270 /* Watchdog abort at DMAEND */
271 static const uint8_t dma_nost[] = {
272     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
273     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
274     0xBC, 0x01, 0x34, 0x00, 0x0D, 0x00, /* DMAMOV   CCR SAF SS4 SB4 DAF DS4 DB4 */
275     0x04,                               /* DMALD    */
276     0x18,                               /* DMANOP   */
277     0x00                                /* DMAEND   */
278 };
279
280 /* Watchdog abort at DMALD */
281 static const uint8_t dma_ldfe[] = {
282     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
283     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
284     0xBC, 0x01, 0x34, 0x00, 0x0D, 0x00, /* DMAMOV   CCR SAF SS4 SB4 DAF DS4 DB4 */
285                                         /* DMALPFE  */
286     0x04,                               /* DMALD    */
287     0x28, 0x01,                         /* DMALPEND */
288     0x00                                /* DMAEND   */
289 };
290
291 /* Watchdog abort at DMAST */
292 static const uint8_t dma_stfe[] = {
293     0xBC, 0x00, 0x00, 0x00, 0x01, 0x20, /* DMAMOV   SAR 0x20010000 */
294     0xBC, 0x02, 0x00, 0x00, 0x02, 0x20, /* DMAMOV   DAR 0x20020000 */
295     0xBC, 0x01, 0x34, 0x00, 0x0D, 0x00, /* DMAMOV   CCR SAF SS4 SB4 DAF DS4 DB4 */
296                                         /* DMALPFE  */
297     0x08,                               /* DMAST    */
298     0x28, 0x01,                         /* DMALPEND */
299     0x00                                /* DMAEND   */
300 };
301
302
303 static inline void dma_exec_dbg(const uint8_t *prog, int size)
304 {
305     cpu_physical_memory_write(PROG_ADDR, prog, size);
306     cpu_physical_memory_write(DBG0_ADDR, (uint8_t *)&dbg0, 4);
307     cpu_physical_memory_write(DBG1_ADDR, (uint8_t *)&dbg1, 4);
308     cpu_physical_memory_write(DBGGO_ADDR, (uint8_t *)&dbggo, 4);
309 }
310
311 static inline void dma_kill_dbg(void)
312 {
313     uint32_t zeroval = 0x0;
314
315     cpu_physical_memory_write(DBG0_ADDR, (uint8_t *)&dbgkill, 4);
316     cpu_physical_memory_write(DBG1_ADDR, (uint8_t *)&zeroval, 4);
317     cpu_physical_memory_write(DBGGO_ADDR, (uint8_t *)&dbggo, 4);
318 }
319
320 static __attribute__((unused)) void test_dma_script(struct s5pc1xx_state_s *s)
321 {
322     uint8_t res[32];
323     uint32_t reg;
324     int outcome;
325     int i;
326
327     cpu_physical_memory_write(DATA_ADDR, dma_data, 32);
328
329     /* TEST 1 */
330     cpu_physical_memory_write(RESULT_ADDR, dma_data, 32);
331     dma_exec_dbg(dma_stz, 20);
332     outcome = 0;
333     cpu_physical_memory_read(RESULT_ADDR, res, 16);
334     for (i = 0; i < 16; i++) {
335         if (res[i] != 0) {
336             outcome = 1;
337         }
338     }
339     if (outcome) {
340         fprintf(stderr, "DMA test 1: DMASTZ. FAILED\n");
341     } else {
342         fprintf(stderr, "DMA test 1: DMASTZ. OK\n");
343     }
344
345     /* TEST 2 */
346     cpu_physical_memory_write(RESULT_ADDR, dma_data, 32);
347     dma_exec_dbg(dma_stzlp, 24);
348     outcome = 0;
349     cpu_physical_memory_read(RESULT_ADDR, res, 32);
350     for (i = 0; i < 32; i++) {
351         if (res[i] != 0) {
352             outcome = 1;
353         }
354     }
355     if (outcome) {
356         fprintf(stderr, "DMA test 2: DMASTZ in loop. FAILED\n");
357     } else {
358         fprintf(stderr, "DMA test 2: DMASTZ in loop. OK\n");
359     }
360
361     /* TEST 3 */
362     dma_exec_dbg(dma_stzlp, 24);
363     dma_exec_dbg(dma_copy, 25);
364     outcome = 0;
365     cpu_physical_memory_read(RESULT_ADDR, res, 32);
366     for (i = 0; i < 32; i++) {
367         if (res[i] != dma_data[i]) {
368             outcome = 1;
369         }
370     }
371     if (outcome) {
372         fprintf(stderr, "DMA test 3: DMA copy of 32 bytes of data. FAILED\n");
373     } else {
374         fprintf(stderr, "DMA test 3: DMA copy of 32 bytes of data. OK\n");
375     }
376
377     /* TEST 4 */
378     dma_exec_dbg(dma_stzlp, 24);
379     dma_exec_dbg(dma_copy_2, 25);
380     outcome = 0;
381     cpu_physical_memory_read(RESULT_ADDR, res, 32);
382     for (i = 0; i < 32; i++) {
383         if (res[i] != dma_data[i]) {
384             outcome = 1;
385         }
386     }
387     if (outcome) {
388         fprintf(stderr, "DMA test 4: DMA copy of 32 bytes of data (store before load). FAILED\n");
389     } else {
390         fprintf(stderr, "DMA test 4: DMA copy of 32 bytes of data (store before load). OK\n");
391     }
392
393     /* TEST 5 */
394     dma_exec_dbg(dma_stzlp, 24);
395     dma_exec_dbg(dma_scatter, 25);
396     outcome = 0;
397     cpu_physical_memory_read(RESULT_ADDR, res, 32);
398     for (i = 0; i < 32; i++) {
399         if (res[i] != dma_data[i % 4]) {
400             outcome = 1;
401         }
402     }
403     if (outcome) {
404         fprintf(stderr, "DMA test 5: DMA scatter. FAILED\n");
405     } else {
406         fprintf(stderr, "DMA test 5: DMA scatter. OK\n");
407     }
408
409     /* TEST 6 */
410     dma_exec_dbg(dma_stzlp, 24);
411     dma_exec_dbg(dma_gather, 25);
412     outcome = 0;
413     cpu_physical_memory_read(RESULT_ADDR, res, 32);
414     for (i = 0; i < 32; i++) {
415         if (res[i] != ((i > 3) ? 0 : dma_data[28 + i])) {
416             outcome = 1;
417         }
418     }
419     if (outcome) {
420         fprintf(stderr, "DMA test 6: DMA gather. FAILED\n");
421     } else {
422         fprintf(stderr, "DMA test 6: DMA gather. OK\n");
423     }
424
425     /* TEST 7 */
426     dma_exec_dbg(dma_stzlp, 24);
427     dma_exec_dbg(dma_nost, 21);
428     outcome = 0;
429     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
430     if (! (reg & 2)) {
431         outcome = 1;
432     }
433     cpu_physical_memory_read(FTC1_ADDR, (uint8_t *)&reg, 4);
434     if (reg != ((unsigned)1 << 31)) {
435         outcome = 1;
436     }
437     cpu_physical_memory_read(CPC1_ADDR, (uint8_t *)&reg, 4);
438     if (reg != PROG_ADDR + 20) {
439         outcome = 1;
440     }
441     dma_kill_dbg();
442     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
443     if (reg & 2) {
444         outcome = 1;
445     }
446     if (outcome) {
447         fprintf(stderr, "DMA test 7: DMALD without DMAST. FAILED\n");
448     } else {
449         fprintf(stderr, "DMA test 7: DMALD without DMAST. OK\n");
450     }
451
452     /* TEST 8 */
453     dma_exec_dbg(dma_stzlp, 24);
454     dma_exec_dbg(dma_nold, 21);
455     outcome = 0;
456     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
457     if (! (reg & 2)) {
458         outcome = 1;
459     }
460     cpu_physical_memory_read(FTC1_ADDR, (uint8_t *)&reg, 4);
461     if (reg != ((unsigned)1 << 31)) {
462         outcome = 1;
463     }
464     cpu_physical_memory_read(CPC1_ADDR, (uint8_t *)&reg, 4);
465     if (reg != PROG_ADDR + 20) {
466         outcome = 1;
467     }
468     dma_kill_dbg();
469     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
470     if (reg & 2) {
471         outcome = 1;
472     }
473     if (outcome) {
474         fprintf(stderr, "DMA test 8: DMAST without DMALD. FAILED\n");
475     } else {
476         fprintf(stderr, "DMA test 8: DMAST without DMALD. OK\n");
477     }
478
479     /* TEST 9 */
480     dma_exec_dbg(dma_stzlp, 24);
481     dma_exec_dbg(dma_ldfe, 22);
482     outcome = 0;
483     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
484     if (! (reg & 2)) {
485         outcome = 1;
486     }
487     cpu_physical_memory_read(FTC1_ADDR, (uint8_t *)&reg, 4);
488     if (reg != ((unsigned)1 << 31)) {
489         outcome = 1;
490     }
491     cpu_physical_memory_read(CPC1_ADDR, (uint8_t *)&reg, 4);
492     if (reg != PROG_ADDR + 18) {
493         outcome = 1;
494     }
495     dma_kill_dbg();
496     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
497     if (reg & 2) {
498         outcome = 1;
499     }
500     if (outcome) {
501         fprintf(stderr, "DMA test 9: DMALD in infinite loop. FAILED\n");
502     } else {
503         fprintf(stderr, "DMA test 9: DMALD in infinite loop. OK\n");
504     }
505
506     /* TEST 10 */
507     dma_exec_dbg(dma_stzlp, 24);
508     dma_exec_dbg(dma_stfe, 22);
509     outcome = 0;
510     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
511     if (! (reg & 2)) {
512         outcome = 1;
513     }
514     cpu_physical_memory_read(FTC1_ADDR, (uint8_t *)&reg, 4);
515     if (reg != ((unsigned)1 << 31)) {
516         outcome = 1;
517     }
518     cpu_physical_memory_read(CPC1_ADDR, (uint8_t *)&reg, 4);
519     if (reg != PROG_ADDR + 18) {
520         outcome = 1;
521     }
522     dma_kill_dbg();
523     cpu_physical_memory_read(FSC_ADDR, (uint8_t *)&reg, 4);
524     if (reg & 2) {
525         outcome = 1;
526     }
527     if (outcome) {
528         fprintf(stderr, "DMA test 10: DMAST in infinite loop. FAILED\n");
529     } else {
530         fprintf(stderr, "DMA test 10: DMAST in infinite loop. OK\n");
531     }
532 }
533
534
535 /* UART */
536
537 #define TRSTATUS_ADDR   0xE2900810
538 #define FIFOCTL_ADDR    0xE2900808
539 #define TRANSMIT_ADDR   0xE2900820
540 #define RECIVE_ADDR     0xE2900824
541
542
543 static const char *hello = "Hello world!\n";
544 static char buf[256];
545
546
547 static __attribute__((unused)) void test_uart_script(void)
548 {
549     uint32_t res;
550     char *s;
551     int i;
552
553     res = 1;
554     cpu_physical_memory_write(FIFOCTL_ADDR, (uint8_t *)&res, 4);
555     cpu_physical_memory_read(TRSTATUS_ADDR, (uint8_t *)&res, 4);
556     if (! (res & 4)) {
557         fprintf(stderr, "Error: UART2 transmitter is not ready!\n");
558     }
559     s = (char *)hello;
560     while (*s) {
561         cpu_physical_memory_write(TRANSMIT_ADDR, (uint8_t *)s, 1);
562         s++;
563     }
564     sleep(10);
565     s = buf;
566     i = 0;
567     while (1) {
568         cpu_physical_memory_read(TRSTATUS_ADDR, (uint8_t *)&res, 4);
569         if (! (res & 1)) {
570             break;
571         }
572         if (i >= 255) {
573             fprintf(stderr, "Error: UART2 too many input data!\n");
574             break;
575         }
576         cpu_physical_memory_read(RECIVE_ADDR, (uint8_t *)s, 1);
577         s++;
578     }
579     *s = '\0';
580     fprintf (stderr, "Read data: %s\n", s);
581 }
582