Search
lxdream.org :: lxdream/src/aica/armmem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/armmem.c
changeset 37:1d84f4c18816
prev31:495e480360d7
next40:852ee31ace0d
author nkeynes
date Mon Dec 26 06:38:51 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change More ARM work-in-progress - idle loop works now :)
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@37
     2
 * $Id: armmem.c,v 1.5 2005-12-26 06:38:51 nkeynes Exp $
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@7
    22
nkeynes@11
    23
char *arm_mem = NULL;
nkeynes@11
    24
nkeynes@7
    25
void arm_mem_init() {
nkeynes@11
    26
    arm_mem = mem_get_region_by_name( MEM_REGION_AUDIO );
nkeynes@11
    27
    
nkeynes@7
    28
}
nkeynes@7
    29
nkeynes@14
    30
int arm_has_page( uint32_t addr ) {
nkeynes@14
    31
    return ( addr < 0x00200000 ||
nkeynes@14
    32
	     (addr >= 0x00800000 && addr <= 0x00805000 ) );
nkeynes@14
    33
}
nkeynes@14
    34
nkeynes@37
    35
uint32_t arm_read_long( uint32_t addr ) {
nkeynes@11
    36
    if( addr < 0x00200000 ) {
nkeynes@11
    37
	return *(int32_t *)(arm_mem + addr);
nkeynes@11
    38
	/* Main sound ram */
nkeynes@11
    39
    } else {
nkeynes@37
    40
	switch( addr & 0xFFFFF000 ) {
nkeynes@37
    41
	case 0x00800000:
nkeynes@37
    42
	    return mmio_region_AICA0_read(addr);
nkeynes@37
    43
	    break;
nkeynes@37
    44
	case 0x00801000:
nkeynes@37
    45
	    return mmio_region_AICA1_read(addr);
nkeynes@37
    46
	    break;
nkeynes@37
    47
	case 0x00802000:
nkeynes@37
    48
	    return mmio_region_AICA2_read(addr);
nkeynes@37
    49
	    break;
nkeynes@37
    50
	case 0x00803000:
nkeynes@37
    51
	    break;
nkeynes@37
    52
	case 0x00804000:
nkeynes@37
    53
	    break;
nkeynes@37
    54
	}
nkeynes@11
    55
    }
nkeynes@37
    56
    ERROR( "Attempted long read to undefined page: %08X",
nkeynes@37
    57
	   addr );
nkeynes@37
    58
    /* Undefined memory */
nkeynes@37
    59
    return 0;
nkeynes@7
    60
}
nkeynes@7
    61
nkeynes@37
    62
uint32_t arm_read_word( uint32_t addr ) {
nkeynes@11
    63
    if( addr < 0x00200000 ) {
nkeynes@11
    64
	return *(int16_t *)(arm_mem + addr);
nkeynes@11
    65
	/* Main sound ram */
nkeynes@11
    66
    } else {
nkeynes@11
    67
	/* Undefined memory */
nkeynes@11
    68
	ERROR( "Attempted word read to undefined page: %08X",
nkeynes@11
    69
	       addr );
nkeynes@11
    70
	return 0;
nkeynes@11
    71
    }
nkeynes@11
    72
nkeynes@7
    73
}
nkeynes@7
    74
nkeynes@37
    75
uint32_t arm_read_byte( uint32_t addr ) {
nkeynes@11
    76
    if( addr < 0x00200000 ) {
nkeynes@37
    77
	return (uint32_t)(*(uint8_t *)(arm_mem + addr));
nkeynes@11
    78
	/* Main sound ram */
nkeynes@11
    79
    } else {
nkeynes@11
    80
	/* Undefined memory */
nkeynes@11
    81
	ERROR( "Attempted byte read to undefined page: %08X",
nkeynes@11
    82
	       addr );
nkeynes@11
    83
	return 0;
nkeynes@11
    84
    }
nkeynes@7
    85
}
nkeynes@7
    86
nkeynes@37
    87
void arm_write_long( uint32_t addr, uint32_t value )
nkeynes@37
    88
{
nkeynes@37
    89
    if( addr < 0x00200000 ) {
nkeynes@37
    90
	*(uint32_t *)(arm_mem + addr) = value;
nkeynes@37
    91
    } else {
nkeynes@37
    92
    }
nkeynes@37
    93
}
nkeynes@37
    94
nkeynes@37
    95
void arm_write_byte( uint32_t addr, uint32_t value )
nkeynes@37
    96
{
nkeynes@37
    97
    if( addr < 0x00200000 ) {
nkeynes@37
    98
	*(uint8_t *)(arm_mem+addr) = (uint8_t)value;
nkeynes@37
    99
    } else {
nkeynes@37
   100
    }
nkeynes@37
   101
}
nkeynes@37
   102
nkeynes@37
   103
/* User translations - TODO */
nkeynes@37
   104
nkeynes@11
   105
uint32_t arm_read_long_user( uint32_t addr ) {
nkeynes@37
   106
    return arm_read_long( addr );
nkeynes@11
   107
}
nkeynes@11
   108
nkeynes@11
   109
uint32_t arm_read_byte_user( uint32_t addr ) {
nkeynes@37
   110
    return arm_read_byte( addr );
nkeynes@37
   111
}
nkeynes@11
   112
nkeynes@37
   113
void arm_write_long_user( uint32_t addr, uint32_t val ) {
nkeynes@37
   114
    arm_write_long( addr, val );
nkeynes@11
   115
}
nkeynes@37
   116
nkeynes@37
   117
void arm_write_byte_user( uint32_t addr, uint32_t val )
nkeynes@37
   118
{
nkeynes@37
   119
    arm_write_byte( addr, val );
nkeynes@37
   120
}
.