6 * Copyright (c) 2006 Nathan Keynes.
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.
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.
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)
48 #define SYS_ASSIGNWRKMEM 14
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 )
62 printf( "Got syscall: %d\n", syscall );
67 data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
70 rv = read( fd, data, len );
72 memcpy_to_aica( data, tmp, rv );
77 data = (char *)(AICA_RAM_BASE + (arg2 & 0x001FFFFF));
80 memcpy(tmp, data, len);
81 rv = write( fd, tmp, len );
89 int main( int argc, char *argv[] )
91 char buf[65536] __attribute__((aligned(32)));
92 uint32_t aica_addr = AICA_RAM_BASE;
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" );
106 printf( "Program loaded (%d bytes)\n", totallen);
108 /* Main loop waiting for IO commands */
113 int syscall = long_read(AICA_SYSCALL);
115 if( syscall != -1 ) {
116 if( syscall == -2 ) {
117 fprintf( stderr, "ARM aborted with general exception\n" );
119 } else if( syscall == SYS_EXIT ) {
120 printf( "Exiting at ARM request\n" );
122 return long_read(AICA_SYSCALL_ARG1);
124 uint32_t result = do_syscall( syscall, long_read(AICA_SYSCALL_ARG1),
125 long_read(AICA_SYSCALL_ARG2), long_read(AICA_SYSCALL_ARG3) );
128 long_write( AICA_SYSCALL_RETURN, result );
129 long_write( AICA_SYSCALL, -1 );
.