Search
lxdream.org :: lxdream/src/aica/armmem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/armmem.c
changeset 736:a02d1475ccfd
prev561:533f6b478071
next811:7ff871670e58
author nkeynes
date Mon Jul 21 00:08:34 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Add gettext.h and build sanely without libintl if it's not available
Remove x86dasm's config.h & opintl.h (no longer needed and actually wrong)
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@31
     3
 *
nkeynes@31
     4
 * Implements the ARM's memory map.
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@31
    17
 */
nkeynes@31
    18
nkeynes@11
    19
#include <stdlib.h>
nkeynes@11
    20
#include "dream.h"
nkeynes@7
    21
#include "mem.h"
nkeynes@66
    22
#include "aica.h"
nkeynes@7
    23
nkeynes@502
    24
unsigned char *arm_mem = NULL;
nkeynes@502
    25
unsigned char *arm_mem_scratch = NULL;
nkeynes@11
    26
nkeynes@7
    27
void arm_mem_init() {
nkeynes@11
    28
    arm_mem = mem_get_region_by_name( MEM_REGION_AUDIO );
nkeynes@40
    29
    arm_mem_scratch = mem_get_region_by_name( MEM_REGION_AUDIO_SCRATCH );
nkeynes@7
    30
}
nkeynes@7
    31
nkeynes@14
    32
int arm_has_page( uint32_t addr ) {
nkeynes@14
    33
    return ( addr < 0x00200000 ||
nkeynes@736
    34
            (addr >= 0x00800000 && addr <= 0x00805000 ) );
nkeynes@14
    35
}
nkeynes@14
    36
nkeynes@37
    37
uint32_t arm_read_long( uint32_t addr ) {
nkeynes@11
    38
    if( addr < 0x00200000 ) {
nkeynes@736
    39
        return *(int32_t *)(arm_mem + addr);
nkeynes@736
    40
        /* Main sound ram */
nkeynes@11
    41
    } else {
nkeynes@736
    42
        uint32_t val;
nkeynes@736
    43
        switch( addr & 0xFFFFF000 ) {
nkeynes@736
    44
        case 0x00800000:
nkeynes@736
    45
            val = mmio_region_AICA0_read(addr&0x0FFF);
nkeynes@736
    46
            //	    DEBUG( "ARM long read from %08X => %08X", addr, val );
nkeynes@736
    47
            return val;
nkeynes@736
    48
        case 0x00801000:
nkeynes@736
    49
            val = mmio_region_AICA1_read(addr&0x0FFF);
nkeynes@736
    50
            //	    DEBUG( "ARM long read from %08X => %08X", addr, val );
nkeynes@736
    51
            return val;
nkeynes@736
    52
        case 0x00802000:
nkeynes@736
    53
            val = mmio_region_AICA2_read(addr&0x0FFF);
nkeynes@736
    54
            // DEBUG( "ARM long read from %08X => %08X", addr, val );
nkeynes@736
    55
            return val;
nkeynes@736
    56
        case 0x00803000:
nkeynes@736
    57
        case 0x00804000:
nkeynes@736
    58
            return *(int32_t *)(arm_mem_scratch + addr - 0x00803000);
nkeynes@736
    59
        }
nkeynes@11
    60
    }
nkeynes@37
    61
    ERROR( "Attempted long read to undefined page: %08X",
nkeynes@736
    62
           addr );
nkeynes@37
    63
    /* Undefined memory */
nkeynes@37
    64
    return 0;
nkeynes@7
    65
}
nkeynes@7
    66
nkeynes@37
    67
uint32_t arm_read_word( uint32_t addr ) {
nkeynes@40
    68
    return (uint32_t)(uint16_t)arm_read_long( addr );
nkeynes@7
    69
}
nkeynes@7
    70
nkeynes@37
    71
uint32_t arm_read_byte( uint32_t addr ) {
nkeynes@40
    72
    return (uint32_t)(uint8_t)arm_read_long( addr );
nkeynes@7
    73
}
nkeynes@7
    74
nkeynes@37
    75
void arm_write_long( uint32_t addr, uint32_t value )
nkeynes@37
    76
{
nkeynes@37
    77
    if( addr < 0x00200000 ) {
nkeynes@736
    78
        /* Main sound ram */
nkeynes@736
    79
        *(uint32_t *)(arm_mem + addr) = value;
nkeynes@37
    80
    } else {
nkeynes@736
    81
        switch( addr & 0xFFFFF000 ) {
nkeynes@736
    82
        case 0x00800000:
nkeynes@736
    83
            // DEBUG( "ARM long write to %08X <= %08X", addr, value );
nkeynes@736
    84
            mmio_region_AICA0_write(addr&0x0FFF, value);
nkeynes@736
    85
            break;
nkeynes@736
    86
        case 0x00801000:
nkeynes@736
    87
            // DEBUG( "ARM long write to %08X <= %08X", addr, value );
nkeynes@736
    88
            mmio_region_AICA1_write(addr&0x0FFF, value);
nkeynes@736
    89
            break;
nkeynes@736
    90
        case 0x00802000:
nkeynes@736
    91
            // DEBUG( "ARM long write to %08X <= %08X", addr, value );
nkeynes@736
    92
            mmio_region_AICA2_write(addr&0x0FFF, value);
nkeynes@736
    93
            break;
nkeynes@736
    94
        case 0x00803000:
nkeynes@736
    95
        case 0x00804000:
nkeynes@736
    96
            *(uint32_t *)(arm_mem_scratch + addr - 0x00803000) = value;
nkeynes@736
    97
            break;
nkeynes@736
    98
        default:
nkeynes@736
    99
            ERROR( "Attempted long write to undefined address: %08X",
nkeynes@736
   100
                    addr );
nkeynes@736
   101
            /* Undefined memory */
nkeynes@736
   102
        } 
nkeynes@37
   103
    }
nkeynes@431
   104
    return;
nkeynes@37
   105
}
nkeynes@37
   106
nkeynes@66
   107
uint32_t arm_combine_byte( uint32_t addr, uint32_t val, uint8_t byte )
nkeynes@66
   108
{
nkeynes@66
   109
    switch( addr & 0x03 ) {
nkeynes@66
   110
    case 0:
nkeynes@736
   111
        return (val & 0xFFFFFF00) | byte;
nkeynes@66
   112
    case 1:
nkeynes@736
   113
        return (val & 0xFFFF00FF) | (byte<<8);
nkeynes@66
   114
    case 2:
nkeynes@736
   115
        return (val & 0xFF00FFFF) | (byte<<16);
nkeynes@66
   116
    case 3:
nkeynes@736
   117
        return (val & 0x00FFFFFF) | (byte<<24);
nkeynes@431
   118
    default:
nkeynes@736
   119
        return val; // Can't happen, but make gcc happy
nkeynes@66
   120
    }
nkeynes@66
   121
}
nkeynes@66
   122
nkeynes@37
   123
void arm_write_byte( uint32_t addr, uint32_t value )
nkeynes@37
   124
{
nkeynes@37
   125
    if( addr < 0x00200000 ) {
nkeynes@736
   126
        /* Main sound ram */
nkeynes@736
   127
        *(uint8_t *)(arm_mem + addr) = (uint8_t)value;
nkeynes@37
   128
    } else {
nkeynes@736
   129
        uint32_t tmp;
nkeynes@736
   130
        switch( addr & 0xFFFFF000 ) {
nkeynes@736
   131
        case 0x00800000:
nkeynes@736
   132
            tmp = MMIO_READ( AICA0, addr & 0x0FFC );
nkeynes@736
   133
            value = arm_combine_byte( addr, tmp, value );
nkeynes@736
   134
            mmio_region_AICA0_write(addr&0x0FFC, value);
nkeynes@736
   135
            break;
nkeynes@736
   136
        case 0x00801000:
nkeynes@736
   137
            tmp = MMIO_READ( AICA1, addr & 0x0FFC );
nkeynes@736
   138
            value = arm_combine_byte( addr, tmp, value );
nkeynes@736
   139
            mmio_region_AICA1_write(addr&0x0FFC, value);
nkeynes@736
   140
            break;
nkeynes@736
   141
        case 0x00802000:
nkeynes@736
   142
            tmp = MMIO_READ( AICA2, addr & 0x0FFC );
nkeynes@736
   143
            value = arm_combine_byte( addr, tmp, value );
nkeynes@736
   144
            mmio_region_AICA2_write(addr&0x0FFC, value);
nkeynes@736
   145
            break;
nkeynes@736
   146
        case 0x00803000:
nkeynes@736
   147
        case 0x00804000:
nkeynes@736
   148
            *(uint8_t *)(arm_mem_scratch + addr - 0x00803000) = (uint8_t)value;
nkeynes@736
   149
            break;
nkeynes@736
   150
        default:
nkeynes@736
   151
            ERROR( "Attempted byte write to undefined address: %08X",
nkeynes@736
   152
                    addr );
nkeynes@736
   153
            /* Undefined memory */
nkeynes@736
   154
        } 
nkeynes@37
   155
    }
nkeynes@431
   156
    return;
nkeynes@37
   157
}
nkeynes@37
   158
nkeynes@37
   159
/* User translations - TODO */
nkeynes@37
   160
nkeynes@11
   161
uint32_t arm_read_long_user( uint32_t addr ) {
nkeynes@37
   162
    return arm_read_long( addr );
nkeynes@11
   163
}
nkeynes@11
   164
nkeynes@11
   165
uint32_t arm_read_byte_user( uint32_t addr ) {
nkeynes@37
   166
    return arm_read_byte( addr );
nkeynes@37
   167
}
nkeynes@11
   168
nkeynes@37
   169
void arm_write_long_user( uint32_t addr, uint32_t val ) {
nkeynes@37
   170
    arm_write_long( addr, val );
nkeynes@11
   171
}
nkeynes@37
   172
nkeynes@37
   173
void arm_write_byte_user( uint32_t addr, uint32_t val )
nkeynes@37
   174
{
nkeynes@37
   175
    arm_write_byte( addr, val );
nkeynes@37
   176
}
.