Search
lxdream.org :: lxdream/test/testaica.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testaica.c
changeset 821:4398dafeb77d
prev812:8cc61d5ea1f8
next1022:43f35b12ece7
author nkeynes
date Sun Aug 24 01:43:17 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Correct generated UNDEF() => UNDEF(ir) for consistency with UNIMP(ir)
file annotate diff log raw
1.1 --- a/test/testaica.c Wed Aug 13 10:32:00 2008 +0000
1.2 +++ b/test/testaica.c Sun Aug 24 01:43:17 2008 +0000
1.3 @@ -17,10 +17,13 @@
1.4 */
1.5
1.6 #include <stdio.h>
1.7 +#include <stdlib.h>
1.8 +#include <assert.h>
1.9
1.10 #include "lib.h"
1.11 +#include "dma.h"
1.12
1.13 -#define AICA_RAM_BASE 0x00800000
1.14 +#define AICA_RAM_BASE 0xA0800000
1.15
1.16 #define AICA_SYSCALL (AICA_RAM_BASE+0x30)
1.17 #define AICA_SYSCALL_ARG1 (AICA_SYSCALL+4)
1.18 @@ -53,25 +56,33 @@
1.19 {
1.20 uint32_t fd, len;
1.21 char *data;
1.22 + char *tmp;
1.23 + int rv;
1.24 +
1.25 + printf( "Got syscall: %d\n", syscall );
1.26
1.27 switch( syscall ) {
1.28 case SYS_READ:
1.29 fd = arg1;
1.30 data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
1.31 len = arg3;
1.32 - return read( fd, data, len );
1.33 + tmp = malloc(len);
1.34 + rv = read( fd, data, len );
1.35 + if( rv >= 0 )
1.36 + memcpy_to_aica( data, tmp, rv );
1.37 + free(tmp);
1.38 + return rv;
1.39 case SYS_WRITE:
1.40 fd = arg1;
1.41 data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
1.42 len = arg3;
1.43 - return write( fd, data, len );
1.44 - break;
1.45 - case SYS_EXIT:
1.46 - aica_disable();
1.47 - exit(arg1);
1.48 - default:
1.49 - return 0;
1.50 - }
1.51 + tmp = malloc(len);
1.52 + memcpy(tmp, data, len);
1.53 + rv = write( fd, tmp, len );
1.54 + free(tmp);
1.55 + return rv;
1.56 + }
1.57 + return 0;
1.58 }
1.59
1.60
1.61 @@ -80,23 +91,44 @@
1.62 char buf[65536] __attribute__((aligned(32)));
1.63 uint32_t aica_addr = AICA_RAM_BASE;
1.64 int len;
1.65 + int totallen = 0;
1.66
1.67 aica_disable();
1.68 /* Load ARM program from stdin and copy to ARM memory */
1.69 while( (len = read(0, buf, sizeof(buf))) > 0 ) {
1.70 - aica_dma_write( aica_addr, buf, len );
1.71 + if(memcpy_to_aica( aica_addr, buf, len ) != 0 ) {
1.72 + printf( "Failed to load program!\n" );
1.73 + return 1;
1.74 + }
1.75 aica_addr += len;
1.76 + totallen += len;
1.77 }
1.78 + printf( "Program loaded (%d bytes)\n", totallen);
1.79
1.80 /* Main loop waiting for IO commands */
1.81 aica_enable();
1.82 do {
1.83 + g2_fifo_wait();
1.84 + irq_disable();
1.85 int syscall = long_read(AICA_SYSCALL);
1.86 + irq_enable();
1.87 if( syscall != -1 ) {
1.88 - uint32_t result = do_syscall( syscall, long_read(AICA_SYSCALL_ARG1),
1.89 - long_read(AICA_SYSCALL_ARG2), long_read(AICA_SYSCALL_ARG3) );
1.90 - long_write( AICA_SYSCALL_RETURN, result );
1.91 - long_write( AICA_SYSCALL, -1 );
1.92 + if( syscall == -2 ) {
1.93 + fprintf( stderr, "ARM aborted with general exception\n" );
1.94 + return -2;
1.95 + } else if( syscall == SYS_EXIT ) {
1.96 + printf( "Exiting at ARM request\n" );
1.97 + aica_disable();
1.98 + return long_read(AICA_SYSCALL_ARG1);
1.99 + } else {
1.100 + uint32_t result = do_syscall( syscall, long_read(AICA_SYSCALL_ARG1),
1.101 + long_read(AICA_SYSCALL_ARG2), long_read(AICA_SYSCALL_ARG3) );
1.102 + g2_fifo_wait();
1.103 + irq_disable();
1.104 + long_write( AICA_SYSCALL_RETURN, result );
1.105 + long_write( AICA_SYSCALL, -1 );
1.106 + irq_enable();
1.107 + }
1.108 }
1.109 } while( 1 );
1.110 -}
1.111 \ No newline at end of file
1.112 +}
.