Search
lxdream.org :: lxdream/test/testaica.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testaica.c
changeset 812:8cc61d5ea1f8
next821:4398dafeb77d
author nkeynes
date Mon Aug 18 12:20:28 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Implement memcpy_to_aica, still a work in progress though
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/testaica.c Mon Aug 18 12:20:28 2008 +0000
1.3 @@ -0,0 +1,102 @@
1.4 +/**
1.5 + * $Id: testdata.c 602 2008-01-15 20:50:23Z nkeynes $
1.6 + *
1.7 + * AICA test loader
1.8 + *
1.9 + * Copyright (c) 2006 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <stdio.h>
1.23 +
1.24 +#include "lib.h"
1.25 +
1.26 +#define AICA_RAM_BASE 0x00800000
1.27 +
1.28 +#define AICA_SYSCALL (AICA_RAM_BASE+0x30)
1.29 +#define AICA_SYSCALL_ARG1 (AICA_SYSCALL+4)
1.30 +#define AICA_SYSCALL_ARG2 (AICA_SYSCALL+8)
1.31 +#define AICA_SYSCALL_ARG3 (AICA_SYSCALL+12)
1.32 +#define AICA_SYSCALL_RETURN (AICA_SYSCALL+4)
1.33 +
1.34 +#define SYS_READ 0
1.35 +#define SYS_WRITE 1
1.36 +#define SYS_OPEN 2
1.37 +#define SYS_CLOSE 3
1.38 +#define SYS_CREAT 4
1.39 +#define SYS_LINK 5
1.40 +#define SYS_UNLINK 6
1.41 +#define SYS_CHDIR 7
1.42 +#define SYS_CHMOD 8
1.43 +#define SYS_LSEEK 9
1.44 +#define SYS_FSTAT 10
1.45 +#define SYS_TIME 11
1.46 +#define SYS_STAT 12
1.47 +#define SYS_UTIME 13
1.48 +#define SYS_ASSIGNWRKMEM 14
1.49 +#define SYS_EXIT 15
1.50 +#define SYS_OPENDIR 16
1.51 +#define SYS_CLOSEDIR 17
1.52 +#define SYS_READDIR 18
1.53 +#define SYS_GETHOSTINFO 19
1.54 +
1.55 +uint32_t do_syscall( uint32_t syscall, uint32_t arg1, uint32_t arg2, uint32_t arg3 )
1.56 +{
1.57 + uint32_t fd, len;
1.58 + char *data;
1.59 +
1.60 + switch( syscall ) {
1.61 + case SYS_READ:
1.62 + fd = arg1;
1.63 + data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
1.64 + len = arg3;
1.65 + return read( fd, data, len );
1.66 + case SYS_WRITE:
1.67 + fd = arg1;
1.68 + data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
1.69 + len = arg3;
1.70 + return write( fd, data, len );
1.71 + break;
1.72 + case SYS_EXIT:
1.73 + aica_disable();
1.74 + exit(arg1);
1.75 + default:
1.76 + return 0;
1.77 + }
1.78 +}
1.79 +
1.80 +
1.81 +int main( int argc, char *argv[] )
1.82 +{
1.83 + char buf[65536] __attribute__((aligned(32)));
1.84 + uint32_t aica_addr = AICA_RAM_BASE;
1.85 + int len;
1.86 +
1.87 + aica_disable();
1.88 + /* Load ARM program from stdin and copy to ARM memory */
1.89 + while( (len = read(0, buf, sizeof(buf))) > 0 ) {
1.90 + aica_dma_write( aica_addr, buf, len );
1.91 + aica_addr += len;
1.92 + }
1.93 +
1.94 + /* Main loop waiting for IO commands */
1.95 + aica_enable();
1.96 + do {
1.97 + int syscall = long_read(AICA_SYSCALL);
1.98 + if( syscall != -1 ) {
1.99 + uint32_t result = do_syscall( syscall, long_read(AICA_SYSCALL_ARG1),
1.100 + long_read(AICA_SYSCALL_ARG2), long_read(AICA_SYSCALL_ARG3) );
1.101 + long_write( AICA_SYSCALL_RETURN, result );
1.102 + long_write( AICA_SYSCALL, -1 );
1.103 + }
1.104 + } while( 1 );
1.105 +}
1.106 \ No newline at end of file
.