Search
lxdream.org :: lxdream/src/sh4/sh4mem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4mem.c
changeset 939:6f2302afeb89
prev934:3acd3b3ee6d1
next945:787729653236
author nkeynes
date Sat Jan 03 03:30:26 2009 +0000 (12 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change MMU work-in-progress
* Move SDRAM out into separate sdram.c
* Move all page-table management into mmu.c
* Convert UTLB management to use the new page-tables
* Rip out all calls to mmu_vma_to_phys_* and replace with direct access
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@939
     3
 * 
nkeynes@939
     4
 * This is a deprecated module that is not yet completely extricated from the
nkeynes@939
     5
 * surrounding code.
nkeynes@10
     6
 *
nkeynes@10
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@10
     8
 *
nkeynes@10
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@10
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@10
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@10
    12
 * (at your option) any later version.
nkeynes@10
    13
 *
nkeynes@10
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@10
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@10
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@10
    17
 * GNU General Public License for more details.
nkeynes@10
    18
 */
nkeynes@10
    19
nkeynes@35
    20
#define MODULE sh4_module
nkeynes@35
    21
nkeynes@10
    22
#include <string.h>
nkeynes@10
    23
#include <zlib.h>
nkeynes@10
    24
#include "dream.h"
nkeynes@10
    25
#include "mem.h"
nkeynes@10
    26
#include "mmio.h"
nkeynes@10
    27
#include "dreamcast.h"
nkeynes@422
    28
#include "sh4/sh4core.h"
nkeynes@422
    29
#include "sh4/sh4mmio.h"
nkeynes@422
    30
#include "sh4/xltcache.h"
nkeynes@100
    31
#include "pvr2/pvr2.h"
nkeynes@10
    32
nkeynes@939
    33
/************** Obsolete methods ***************/
nkeynes@931
    34
nkeynes@931
    35
int32_t FASTCALL sh4_read_long( sh4addr_t addr )
nkeynes@10
    36
{
nkeynes@931
    37
    return sh4_address_space[addr>>12]->read_long(addr);
nkeynes@10
    38
}
nkeynes@10
    39
nkeynes@931
    40
int32_t FASTCALL sh4_read_word( sh4addr_t addr )
nkeynes@10
    41
{
nkeynes@931
    42
    return sh4_address_space[addr>>12]->read_word(addr);
nkeynes@10
    43
}
nkeynes@10
    44
nkeynes@931
    45
int32_t FASTCALL sh4_read_byte( sh4addr_t addr )
nkeynes@10
    46
{
nkeynes@931
    47
    return sh4_address_space[addr>>12]->read_byte(addr);
nkeynes@931
    48
}
nkeynes@931
    49
nkeynes@931
    50
void FASTCALL sh4_write_long( sh4addr_t addr, uint32_t val )
nkeynes@931
    51
{
nkeynes@931
    52
    sh4_address_space[addr>>12]->write_long(addr, val);
nkeynes@931
    53
}
nkeynes@931
    54
nkeynes@931
    55
void FASTCALL sh4_write_word( sh4addr_t addr, uint32_t val )
nkeynes@931
    56
{
nkeynes@931
    57
    sh4_address_space[addr>>12]->write_word(addr,val);
nkeynes@931
    58
}
nkeynes@931
    59
nkeynes@931
    60
void FASTCALL sh4_write_byte( sh4addr_t addr, uint32_t val )
nkeynes@931
    61
{
nkeynes@931
    62
    sh4_address_space[addr>>12]->write_byte(addr, val);
nkeynes@10
    63
}
nkeynes@10
    64
nkeynes@10
    65
/* FIXME: Handle all the many special cases when the range doesn't fall cleanly
nkeynes@400
    66
 * into the same memory block
nkeynes@10
    67
 */
nkeynes@912
    68
void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t srcaddr, size_t count ) {
nkeynes@103
    69
    if( srcaddr >= 0x04000000 && srcaddr < 0x05000000 ) {
nkeynes@736
    70
        pvr2_vram64_read( dest, srcaddr, count );
nkeynes@103
    71
    } else {
nkeynes@736
    72
        sh4ptr_t src = mem_get_region(srcaddr);
nkeynes@736
    73
        if( src == NULL ) {
nkeynes@736
    74
            WARN( "Attempted block read from unknown address %08X", srcaddr );
nkeynes@736
    75
        } else {
nkeynes@736
    76
            memcpy( dest, src, count );
nkeynes@736
    77
        }
nkeynes@103
    78
    }
nkeynes@10
    79
}
nkeynes@10
    80
nkeynes@912
    81
void mem_copy_to_sh4( sh4addr_t destaddr, sh4ptr_t src, size_t count ) {
nkeynes@325
    82
    if( destaddr >= 0x10000000 && destaddr < 0x14000000 ) {
nkeynes@736
    83
        pvr2_dma_write( destaddr, src, count );
nkeynes@736
    84
        return;
nkeynes@325
    85
    } else if( (destaddr & 0x1F800000) == 0x05000000 ) {
nkeynes@736
    86
        pvr2_render_buffer_invalidate( destaddr, TRUE );
nkeynes@325
    87
    } else if( (destaddr & 0x1F800000) == 0x04000000 ) {
nkeynes@736
    88
        pvr2_vram64_write( destaddr, src, count );
nkeynes@736
    89
        return;
nkeynes@325
    90
    }
nkeynes@502
    91
    sh4ptr_t dest = mem_get_region(destaddr);
nkeynes@325
    92
    if( dest == NULL )
nkeynes@736
    93
        WARN( "Attempted block write to unknown address %08X", destaddr );
nkeynes@325
    94
    else {
nkeynes@736
    95
        xlat_invalidate_block( destaddr, count );
nkeynes@736
    96
        memcpy( dest, src, count );
nkeynes@90
    97
    }
nkeynes@10
    98
}
.