Search
lxdream.org :: lxdream/test/testaica.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/testaica.c
changeset 1022:43f35b12ece7
prev821:4398dafeb77d
author nkeynes
date Tue Feb 28 18:22:52 2012 +1000 (9 years ago)
permissions -rw-r--r--
last change Add a GL-only video driver for android usage (since the Java code is
responsible for creating the context)
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * 
     4  * AICA test loader
     5  *
     6  * Copyright (c) 2006 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include <stdio.h>
    20 #include <stdlib.h>
    21 #include <assert.h>
    23 #include "lib.h"
    24 #include "dma.h"
    26 #define AICA_RAM_BASE 0xA0800000
    28 #define AICA_SYSCALL (AICA_RAM_BASE+0x30)
    29 #define AICA_SYSCALL_ARG1 (AICA_SYSCALL+4)
    30 #define AICA_SYSCALL_ARG2 (AICA_SYSCALL+8)
    31 #define AICA_SYSCALL_ARG3 (AICA_SYSCALL+12)
    32 #define AICA_SYSCALL_RETURN (AICA_SYSCALL+4)
    34 #define SYS_READ 0
    35 #define SYS_WRITE 1
    36 #define SYS_OPEN 2
    37 #define SYS_CLOSE 3
    38 #define SYS_CREAT 4
    39 #define SYS_LINK 5
    40 #define SYS_UNLINK 6
    41 #define SYS_CHDIR 7
    42 #define SYS_CHMOD 8
    43 #define SYS_LSEEK 9
    44 #define SYS_FSTAT 10
    45 #define SYS_TIME 11
    46 #define SYS_STAT 12
    47 #define SYS_UTIME 13
    48 #define SYS_ASSIGNWRKMEM 14
    49 #define SYS_EXIT 15
    50 #define SYS_OPENDIR 16
    51 #define SYS_CLOSEDIR 17
    52 #define SYS_READDIR 18
    53 #define SYS_GETHOSTINFO 19
    55 uint32_t do_syscall( uint32_t syscall, uint32_t arg1, uint32_t arg2, uint32_t arg3 )
    56 {
    57     uint32_t fd, len;
    58     char *data;
    59     char *tmp;
    60     int rv;
    62     printf( "Got syscall: %d\n", syscall );
    64     switch( syscall ) {
    65     case SYS_READ:
    66         fd = arg1;
    67         data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
    68         len = arg3;
    69         tmp = malloc(len);
    70         rv = read( fd, data, len );
    71         if( rv >= 0 ) 
    72             memcpy_to_aica( data, tmp, rv );
    73         free(tmp);
    74         return rv;
    75     case SYS_WRITE:
    76         fd = arg1;
    77         data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
    78         len = arg3;
    79         tmp = malloc(len);
    80         memcpy(tmp, data, len);
    81         rv = write( fd, tmp, len );
    82         free(tmp);
    83         return rv;
    84     }
    85     return 0;
    86 }
    89 int main( int argc, char *argv[] ) 
    90 {
    91     char buf[65536] __attribute__((aligned(32)));
    92     uint32_t aica_addr = AICA_RAM_BASE;
    93     int len;
    94     int totallen = 0;
    96     aica_disable();
    97     /* Load ARM program from stdin and copy to ARM memory */
    98     while( (len = read(0, buf, sizeof(buf))) > 0 ) {
    99         if(memcpy_to_aica( aica_addr, buf, len ) != 0 ) {
   100             printf( "Failed to load program!\n" );
   101             return 1;
   102         }
   103         aica_addr += len;
   104         totallen += len;
   105     }
   106     printf( "Program loaded (%d bytes)\n", totallen);
   108     /* Main loop waiting for IO commands */
   109     aica_enable();
   110     do {
   111         g2_fifo_wait();
   112         irq_disable();
   113         int syscall = long_read(AICA_SYSCALL);
   114         irq_enable();
   115         if( syscall != -1 ) {
   116             if( syscall == -2 ) {
   117                 fprintf( stderr, "ARM aborted with general exception\n" );
   118                 return -2;
   119             } else if( syscall == SYS_EXIT ) {
   120                 printf( "Exiting at ARM request\n" );
   121                 aica_disable();
   122                 return long_read(AICA_SYSCALL_ARG1);
   123             } else {
   124                 uint32_t result = do_syscall( syscall, long_read(AICA_SYSCALL_ARG1), 
   125                         long_read(AICA_SYSCALL_ARG2), long_read(AICA_SYSCALL_ARG3) );
   126                 g2_fifo_wait();
   127                 irq_disable();
   128                 long_write( AICA_SYSCALL_RETURN, result );
   129                 long_write( AICA_SYSCALL, -1 );
   130                 irq_enable();
   131             }
   132         }
   133     } while( 1 );
   134 }
.