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