Search
lxdream.org :: lxdream/src/aica/armmem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/armmem.c
changeset 40:852ee31ace0d
prev37:1d84f4c18816
next66:2ec5b6eb75e5
author nkeynes
date Mon Dec 26 10:48:20 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Fixup ARM memory to be a little more functional
view annotate diff log raw
     1 /**
     2  * $Id: armmem.c,v 1.6 2005-12-26 10:48:20 nkeynes Exp $
     3  *
     4  * Implements the ARM's memory map.
     5  *
     6  * Copyright (c) 2005 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 <stdlib.h>
    20 #include "dream.h"
    21 #include "mem.h"
    23 char *arm_mem = NULL;
    24 char *arm_mem_scratch = NULL;
    26 void arm_mem_init() {
    27     arm_mem = mem_get_region_by_name( MEM_REGION_AUDIO );
    28     arm_mem_scratch = mem_get_region_by_name( MEM_REGION_AUDIO_SCRATCH );
    29 }
    31 int arm_has_page( uint32_t addr ) {
    32     return ( addr < 0x00200000 ||
    33 	     (addr >= 0x00800000 && addr <= 0x00805000 ) );
    34 }
    36 uint32_t arm_read_long( uint32_t addr ) {
    37     if( addr < 0x00200000 ) {
    38 	return *(int32_t *)(arm_mem + addr);
    39 	/* Main sound ram */
    40     } else {
    41 	switch( addr & 0xFFFFF000 ) {
    42 	case 0x00800000:
    43 	    return mmio_region_AICA0_read(addr);
    44 	case 0x00801000:
    45 	    return mmio_region_AICA1_read(addr);
    46 	case 0x00802000:
    47 	    return mmio_region_AICA2_read(addr);
    48 	case 0x00803000:
    49 	case 0x00804000:
    50 	    return *(int32_t *)(arm_mem_scratch + addr - 0x00803000);
    51 	}
    52     }
    53     ERROR( "Attempted long read to undefined page: %08X",
    54 	   addr );
    55     /* Undefined memory */
    56     return 0;
    57 }
    59 uint32_t arm_read_word( uint32_t addr ) {
    60     return (uint32_t)(uint16_t)arm_read_long( addr );
    61 }
    63 uint32_t arm_read_byte( uint32_t addr ) {
    64     return (uint32_t)(uint8_t)arm_read_long( addr );
    65 }
    67 void arm_write_long( uint32_t addr, uint32_t value )
    68 {
    69     if( addr < 0x00200000 ) {
    70 	/* Main sound ram */
    71 	*(uint32_t *)(arm_mem + addr) = value;
    72     } else {
    73 	switch( addr & 0xFFFFF000 ) {
    74 	case 0x00800000:
    75 	    mmio_region_AICA0_write(addr, value);
    76 	    break;
    77 	case 0x00801000:
    78 	    mmio_region_AICA1_write(addr, value);
    79 	    break;
    80 	case 0x00802000:
    81 	    mmio_region_AICA2_write(addr, value);
    82 	    break;
    83 	case 0x00803000:
    84 	case 0x00804000:
    85 	    *(uint32_t *)(arm_mem_scratch + addr - 0x00803000) = value;
    86 	    break;
    87 	default:
    88 	    ERROR( "Attempted long write to undefined address: %08X",
    89 		   addr );
    90 	    /* Undefined memory */
    91 	} 
    92     }
    93     return 0;
    94 }
    96 void arm_write_byte( uint32_t addr, uint32_t value )
    97 {
    98     if( addr < 0x00200000 ) {
    99 	/* Main sound ram */
   100 	*(uint8_t *)(arm_mem + addr) = (uint8_t)value;
   101     } else {
   102 	switch( addr & 0xFFFFF000 ) {
   103 	case 0x00800000:
   104 	    mmio_region_AICA0_write(addr, value);
   105 	    break;
   106 	case 0x00801000:
   107 	    mmio_region_AICA1_write(addr, value);
   108 	    break;
   109 	case 0x00802000:
   110 	    mmio_region_AICA2_write(addr, value);
   111 	    break;
   112 	case 0x00803000:
   113 	case 0x00804000:
   114 	    *(uint8_t *)(arm_mem_scratch + addr - 0x00803000) = (uint8_t)value;
   115 	    break;
   116 	default:
   117 	    ERROR( "Attempted byte write to undefined address: %08X",
   118 		   addr );
   119 	    /* Undefined memory */
   120 	} 
   121     }
   122     return 0;
   123 }
   125 /* User translations - TODO */
   127 uint32_t arm_read_long_user( uint32_t addr ) {
   128     return arm_read_long( addr );
   129 }
   131 uint32_t arm_read_byte_user( uint32_t addr ) {
   132     return arm_read_byte( addr );
   133 }
   135 void arm_write_long_user( uint32_t addr, uint32_t val ) {
   136     arm_write_long( addr, val );
   137 }
   139 void arm_write_byte_user( uint32_t addr, uint32_t val )
   140 {
   141     arm_write_byte( addr, val );
   142 }
.