Search
lxdream.org :: lxdream/src/sdram.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sdram.c
changeset 939:6f2302afeb89
next940:81e0d3051d5f
author nkeynes
date Sat Jan 03 03:30:26 2009 +0000 (13 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@939
     1
/**
nkeynes@939
     2
 * $Id: sdram.c 954 2008-12-26 14:25:23Z nkeynes $
nkeynes@939
     3
 *
nkeynes@939
     4
 * Dreamcast main SDRAM - access methods and timing controls. This is fairly
nkeynes@939
     5
 * directly coupled to the SH4
nkeynes@939
     6
 *
nkeynes@939
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@939
     8
 *
nkeynes@939
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@939
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@939
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@939
    12
 * (at your option) any later version.
nkeynes@939
    13
 *
nkeynes@939
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@939
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@939
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@939
    17
 * GNU General Public License for more details.
nkeynes@939
    18
 */
nkeynes@939
    19
nkeynes@939
    20
#include "lxdream.h"
nkeynes@939
    21
#include "mem.h"
nkeynes@939
    22
#include "dreamcast.h"
nkeynes@939
    23
#include <string.h>
nkeynes@939
    24
nkeynes@939
    25
nkeynes@939
    26
static int32_t FASTCALL ext_sdram_read_long( sh4addr_t addr )
nkeynes@939
    27
{
nkeynes@939
    28
    return *((int32_t *)(dc_main_ram + (addr&0x00FFFFFF)));
nkeynes@939
    29
}
nkeynes@939
    30
static int32_t FASTCALL ext_sdram_read_word( sh4addr_t addr )
nkeynes@939
    31
{
nkeynes@939
    32
    return SIGNEXT16(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@939
    33
}
nkeynes@939
    34
static int32_t FASTCALL ext_sdram_read_byte( sh4addr_t addr )
nkeynes@939
    35
{
nkeynes@939
    36
    return SIGNEXT8(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@939
    37
}
nkeynes@939
    38
static void FASTCALL ext_sdram_write_long( sh4addr_t addr, uint32_t val )
nkeynes@939
    39
{
nkeynes@939
    40
    *(uint32_t *)(dc_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@939
    41
    xlat_invalidate_long(addr);
nkeynes@939
    42
}
nkeynes@939
    43
static void FASTCALL ext_sdram_write_word( sh4addr_t addr, uint32_t val )
nkeynes@939
    44
{
nkeynes@939
    45
    *(uint16_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint16_t)val;
nkeynes@939
    46
    xlat_invalidate_word(addr);
nkeynes@939
    47
}
nkeynes@939
    48
static void FASTCALL ext_sdram_write_byte( sh4addr_t addr, uint32_t val )
nkeynes@939
    49
{
nkeynes@939
    50
    *(uint8_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint8_t)val;
nkeynes@939
    51
    xlat_invalidate_word(addr);
nkeynes@939
    52
}
nkeynes@939
    53
static void FASTCALL ext_sdram_read_burst( unsigned char *dest, sh4addr_t addr )
nkeynes@939
    54
{
nkeynes@939
    55
    memcpy( dest, dc_main_ram+(addr&0x00FFFFFF), 32 );
nkeynes@939
    56
}
nkeynes@939
    57
static void FASTCALL ext_sdram_write_burst( sh4addr_t addr, unsigned char *src )
nkeynes@939
    58
{
nkeynes@939
    59
    memcpy( dc_main_ram+(addr&0x00FFFFFF), src, 32 );
nkeynes@939
    60
}
nkeynes@939
    61
nkeynes@939
    62
struct mem_region_fn mem_region_sdram = { ext_sdram_read_long, ext_sdram_write_long, 
nkeynes@939
    63
        ext_sdram_read_word, ext_sdram_write_word, 
nkeynes@939
    64
        ext_sdram_read_byte, ext_sdram_write_byte, 
nkeynes@939
    65
        ext_sdram_read_burst, ext_sdram_write_burst }; 
.