Search
lxdream.org :: lxdream/src/sh4/mmu.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/mmu.h
changeset 953:f4a156508ad1
next963:1c3a0f67c603
author nkeynes
date Tue Jan 13 11:56:28 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Merge lxdream-mem branch back to trunk
file annotate diff log raw
nkeynes@953
     1
/**
nkeynes@953
     2
 * $Id$
nkeynes@953
     3
 *
nkeynes@953
     4
 * MMU/TLB definitions.
nkeynes@953
     5
 *
nkeynes@953
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@953
     7
 *
nkeynes@953
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@953
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@953
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@953
    11
 * (at your option) any later version.
nkeynes@953
    12
 *
nkeynes@953
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@953
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@953
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@953
    16
 * GNU General Public License for more details.
nkeynes@953
    17
 */
nkeynes@953
    18
nkeynes@953
    19
nkeynes@953
    20
#ifndef lxdream_sh4_mmu_H
nkeynes@953
    21
#define lxdream_sh4_mmu_H 1
nkeynes@953
    22
nkeynes@953
    23
#include "lxdream.h"
nkeynes@953
    24
nkeynes@953
    25
#ifdef __cplusplus
nkeynes@953
    26
extern "C" {
nkeynes@953
    27
#endif
nkeynes@953
    28
nkeynes@953
    29
#define VMA_TO_EXT_ADDR(vma) ((vma)&0x1FFFFFFF)
nkeynes@953
    30
nkeynes@953
    31
/************************** UTLB/ITLB Definitions ***************************/
nkeynes@953
    32
/* mmucr register bits */
nkeynes@953
    33
#define MMUCR_AT   0x00000001 /* Address Translation enabled */
nkeynes@953
    34
#define MMUCR_TI   0x00000004 /* TLB invalidate (always read as 0) */
nkeynes@953
    35
#define MMUCR_SV   0x00000100 /* Single Virtual mode=1 / multiple virtual=0 */
nkeynes@953
    36
#define MMUCR_SQMD 0x00000200 /* Store queue mode bit (0=user, 1=priv only) */
nkeynes@953
    37
#define MMUCR_URC  0x0000FC00 /* UTLB access counter */
nkeynes@953
    38
#define MMUCR_URB  0x00FC0000 /* UTLB entry boundary */
nkeynes@953
    39
#define MMUCR_LRUI 0xFC000000 /* Least recently used ITLB */
nkeynes@953
    40
#define MMUCR_MASK 0xFCFCFF05
nkeynes@953
    41
#define MMUCR_RMASK 0xFCFCFF01 /* Read mask */
nkeynes@953
    42
    
nkeynes@953
    43
#define IS_TLB_ENABLED() (MMIO_READ(MMU, MMUCR)&MMUCR_AT)
nkeynes@953
    44
#define IS_SV_ENABLED() (MMIO_READ(MMU,MMUCR)&MMUCR_SV)
nkeynes@953
    45
nkeynes@953
    46
#define ITLB_ENTRY_COUNT 4
nkeynes@953
    47
#define UTLB_ENTRY_COUNT 64
nkeynes@953
    48
nkeynes@953
    49
/* Entry address */
nkeynes@953
    50
#define TLB_VALID     0x00000100
nkeynes@953
    51
#define TLB_USERMODE  0x00000040
nkeynes@953
    52
#define TLB_WRITABLE  0x00000020
nkeynes@953
    53
#define TLB_USERWRITABLE (TLB_WRITABLE|TLB_USERMODE)
nkeynes@953
    54
#define TLB_SIZE_MASK 0x00000090
nkeynes@953
    55
#define TLB_SIZE_1K   0x00000000
nkeynes@953
    56
#define TLB_SIZE_4K   0x00000010
nkeynes@953
    57
#define TLB_SIZE_64K  0x00000080
nkeynes@953
    58
#define TLB_SIZE_1M   0x00000090
nkeynes@953
    59
#define TLB_CACHEABLE 0x00000008
nkeynes@953
    60
#define TLB_DIRTY     0x00000004
nkeynes@953
    61
#define TLB_SHARE     0x00000002
nkeynes@953
    62
#define TLB_WRITETHRU 0x00000001
nkeynes@953
    63
nkeynes@953
    64
#define MASK_1K  0xFFFFFC00
nkeynes@953
    65
#define MASK_4K  0xFFFFF000
nkeynes@953
    66
#define MASK_64K 0xFFFF0000
nkeynes@953
    67
#define MASK_1M  0xFFF00000
nkeynes@953
    68
nkeynes@953
    69
struct itlb_entry {
nkeynes@953
    70
    sh4addr_t vpn; // Virtual Page Number
nkeynes@953
    71
    uint32_t asid; // Process ID
nkeynes@953
    72
    uint32_t mask;
nkeynes@953
    73
    sh4addr_t ppn; // Physical Page Number
nkeynes@953
    74
    uint32_t flags;
nkeynes@953
    75
};
nkeynes@953
    76
nkeynes@953
    77
struct utlb_entry {
nkeynes@953
    78
    sh4addr_t vpn; // Virtual Page Number
nkeynes@953
    79
    uint32_t mask; // Page size mask
nkeynes@953
    80
    uint32_t asid; // Process ID
nkeynes@953
    81
    sh4addr_t ppn; // Physical Page Number
nkeynes@953
    82
    uint32_t flags;
nkeynes@953
    83
    uint32_t pcmcia; // extra pcmcia data - not used in this implementation
nkeynes@953
    84
};
nkeynes@953
    85
nkeynes@953
    86
#define TLB_FUNC_SIZE 48
nkeynes@953
    87
nkeynes@953
    88
struct utlb_page_entry {
nkeynes@953
    89
    struct mem_region_fn fn;
nkeynes@953
    90
    struct mem_region_fn *user_fn;
nkeynes@953
    91
    mem_region_fn_t target;
nkeynes@953
    92
    unsigned char code[TLB_FUNC_SIZE*9];
nkeynes@953
    93
};
nkeynes@953
    94
nkeynes@953
    95
struct utlb_1k_entry {
nkeynes@953
    96
    struct mem_region_fn fn;
nkeynes@953
    97
    struct mem_region_fn user_fn;
nkeynes@953
    98
    struct mem_region_fn *subpages[4];
nkeynes@953
    99
    struct mem_region_fn *user_subpages[4];
nkeynes@953
   100
    unsigned char code[TLB_FUNC_SIZE*18];
nkeynes@953
   101
};
nkeynes@953
   102
nkeynes@953
   103
struct utlb_default_regions {
nkeynes@953
   104
    mem_region_fn_t tlb_miss;
nkeynes@953
   105
    mem_region_fn_t tlb_prot;
nkeynes@953
   106
    mem_region_fn_t tlb_multihit;
nkeynes@953
   107
};
nkeynes@953
   108
nkeynes@953
   109
nkeynes@953
   110
void mmu_utlb_init_vtable( struct utlb_entry *ent, struct utlb_page_entry *page, gboolean writable ); 
nkeynes@953
   111
void mmu_utlb_1k_init_vtable( struct utlb_1k_entry *ent ); 
nkeynes@953
   112
void mmu_utlb_init_storequeue_vtable( struct utlb_entry *ent, struct utlb_page_entry *page );
nkeynes@953
   113
nkeynes@953
   114
extern uint32_t mmu_urc;
nkeynes@953
   115
extern uint32_t mmu_urb;
nkeynes@953
   116
nkeynes@953
   117
/** Primary SH4 address space (privileged and user access)
nkeynes@953
   118
 * Page map (4KB) of the entire 32-bit address space
nkeynes@953
   119
 * Note: only callable from the SH4 cores as it depends on the caller setting
nkeynes@953
   120
 * up an appropriate exception environment. 
nkeynes@953
   121
 **/
nkeynes@953
   122
extern struct mem_region_fn **sh4_address_space;
nkeynes@953
   123
extern struct mem_region_fn **sh4_user_address_space;
nkeynes@953
   124
nkeynes@953
   125
/************ Storequeue/cache functions ***********/
nkeynes@953
   126
void FASTCALL ccn_storequeue_write_long( sh4addr_t addr, uint32_t val );
nkeynes@953
   127
int32_t FASTCALL ccn_storequeue_read_long( sh4addr_t addr );
nkeynes@953
   128
nkeynes@953
   129
/** Default storequeue prefetch when TLB is disabled */
nkeynes@953
   130
void FASTCALL ccn_storequeue_prefetch( sh4addr_t addr ); 
nkeynes@953
   131
nkeynes@953
   132
/** TLB-enabled variant of the storequeue prefetch */
nkeynes@953
   133
void FASTCALL ccn_storequeue_prefetch_tlb( sh4addr_t addr );
nkeynes@953
   134
nkeynes@953
   135
/** Non-storequeue prefetch */
nkeynes@953
   136
void FASTCALL ccn_prefetch( sh4addr_t addr );
nkeynes@953
   137
nkeynes@953
   138
/** Non-cached prefetch (ie, no-op) */
nkeynes@953
   139
void FASTCALL ccn_uncached_prefetch( sh4addr_t addr );
nkeynes@953
   140
nkeynes@953
   141
nkeynes@953
   142
extern struct mem_region_fn mem_region_address_error;
nkeynes@953
   143
extern struct mem_region_fn mem_region_tlb_miss;
nkeynes@953
   144
extern struct mem_region_fn mem_region_tlb_multihit;
nkeynes@953
   145
extern struct mem_region_fn mem_region_tlb_protected;
nkeynes@953
   146
nkeynes@953
   147
extern struct mem_region_fn p4_region_storequeue; 
nkeynes@953
   148
extern struct mem_region_fn p4_region_storequeue_multihit; 
nkeynes@953
   149
extern struct mem_region_fn p4_region_storequeue_miss; 
nkeynes@953
   150
extern struct mem_region_fn p4_region_storequeue_protected; 
nkeynes@953
   151
extern struct mem_region_fn p4_region_storequeue_sqmd; 
nkeynes@953
   152
extern struct mem_region_fn p4_region_storequeue_sqmd_miss; 
nkeynes@953
   153
extern struct mem_region_fn p4_region_storequeue_sqmd_multihit; 
nkeynes@953
   154
extern struct mem_region_fn p4_region_storequeue_sqmd_protected; 
nkeynes@953
   155
nkeynes@953
   156
#ifdef __cplusplus
nkeynes@953
   157
}
nkeynes@953
   158
#endif
nkeynes@953
   159
#endif /* !lxdream_sh4_mmu_H */
.