|
| 1 | +#include "guest/sh4/sh4.h" |
| 2 | + |
| 3 | +#if 0 |
| 4 | +#define LOG_MMU LOG_INFO |
| 5 | +#else |
| 6 | +#define LOG_MMU(...) |
| 7 | +#endif |
| 8 | + |
| 9 | +#define TLB_INDEX(addr) (((addr) >> 8) & 0x3f) |
| 10 | + |
| 11 | +#define PAGE_SIZE(entry) (((entry)->lo.SZ1 << 1) | (entry)->lo.SZ0) |
| 12 | + |
| 13 | +enum { |
| 14 | + PAGE_SIZE_1KB, |
| 15 | + PAGE_SIZE_4KB, |
| 16 | + PAGE_SIZE_64KB, |
| 17 | + PAGE_SIZE_1MB, |
| 18 | +}; |
| 19 | + |
| 20 | +static void sh4_mmu_utlb_sync(struct sh4 *sh4, struct sh4_tlb_entry *entry) { |
| 21 | + int n = entry - sh4->utlb; |
| 22 | + |
| 23 | + /* check if entry maps to sq region [0xe0000000, 0xe3ffffff] */ |
| 24 | + if ((entry->hi.VPN & (0xfc000000 >> 10)) == (0xe0000000 >> 10)) { |
| 25 | + /* assume page size is 1MB |
| 26 | + FIXME support all page sizes */ |
| 27 | + uint32_t vpn = entry->hi.VPN >> 10; |
| 28 | + uint32_t ppn = entry->lo.PPN << 10; |
| 29 | + |
| 30 | + sh4->utlb_sq_map[vpn & 0x3f] = ppn; |
| 31 | + |
| 32 | + LOG_INFO("sh4_mmu_utlb_sync sq map (%d) 0x%x -> 0x%x", n, vpn, ppn); |
| 33 | + } else { |
| 34 | + LOG_FATAL("sh4_mmu_utlb_sync memory mapping not supported"); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +static void sh4_mmu_translate(struct sh4 *sh4, uint32_t addr) {} |
| 39 | + |
| 40 | +void sh4_mmu_load_tlb(void *data) { |
| 41 | + struct sh4 *sh4 = data; |
| 42 | + |
| 43 | + uint32_t n = sh4->MMUCR->URC; |
| 44 | + struct sh4_tlb_entry *entry = &sh4->utlb[n]; |
| 45 | + entry->lo = *sh4->PTEL; |
| 46 | + entry->hi = *sh4->PTEH; |
| 47 | + |
| 48 | + sh4_mmu_utlb_sync(sh4, entry); |
| 49 | +} |
| 50 | + |
| 51 | +uint32_t sh4_mmu_itlb_read(struct sh4 *sh4, uint32_t addr, uint32_t data_mask) { |
| 52 | + if (addr < 0x01000000) { |
| 53 | + LOG_MMU("sh4_mmu_itlb_read address array %08x", addr); |
| 54 | + } else { |
| 55 | + LOG_MMU("sh4_mmu_itlb_read data array %08x", addr); |
| 56 | + } |
| 57 | + |
| 58 | + /* return an invalid entry */ |
| 59 | + return 0; |
| 60 | +} |
| 61 | + |
| 62 | +uint32_t sh4_mmu_utlb_read(struct sh4 *sh4, uint32_t addr, uint32_t data_mask) { |
| 63 | + if (addr < 0x01000000) { |
| 64 | + LOG_MMU("sh4_mmu_utlb_read address array %08x", addr); |
| 65 | + |
| 66 | + struct sh4_tlb_entry *entry = &sh4->utlb[TLB_INDEX(addr)]; |
| 67 | + uint32_t data = entry->hi.full; |
| 68 | + data |= entry->lo.D << 9; |
| 69 | + data |= entry->lo.V << 8; |
| 70 | + return data; |
| 71 | + } else { |
| 72 | + if (addr & 0x800000) { |
| 73 | + LOG_FATAL("sh4_mmu_utlb_read data array 2 %08x", addr); |
| 74 | + } else { |
| 75 | + LOG_MMU("sh4_mmu_utlb_read data array 1 %08x", addr); |
| 76 | + |
| 77 | + struct sh4_tlb_entry *entry = &sh4->utlb[TLB_INDEX(addr)]; |
| 78 | + uint32_t data = entry->lo.full; |
| 79 | + return data; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +void sh4_mmu_itlb_write(struct sh4 *sh4, uint32_t addr, uint32_t data, |
| 85 | + uint32_t data_mask) { |
| 86 | + if (addr < 0x01000000) { |
| 87 | + LOG_MMU("sh4_mmu_itlb_write address array %08x %08x", addr, data); |
| 88 | + } else { |
| 89 | + LOG_MMU("sh4_mmu_itlb_write data array %08x %08x", addr, data); |
| 90 | + } |
| 91 | + |
| 92 | + /* ignore */ |
| 93 | +} |
| 94 | + |
| 95 | +void sh4_mmu_utlb_write(struct sh4 *sh4, uint32_t addr, uint32_t data, |
| 96 | + uint32_t data_mask) { |
| 97 | + if (addr < 0x01000000) { |
| 98 | + if (addr & 0x80) { |
| 99 | + LOG_FATAL("sh4_mmu_utlb_write address array (associative) %08x %08x", |
| 100 | + addr, data); |
| 101 | + } else { |
| 102 | + LOG_MMU("sh4_mmu_utlb_write address array %08x %08x", addr, data); |
| 103 | + |
| 104 | + struct sh4_tlb_entry *entry = &sh4->utlb[TLB_INDEX(addr)]; |
| 105 | + entry->hi.full = data & 0xfffffcff; |
| 106 | + entry->lo.D = (data >> 9) & 1; |
| 107 | + entry->lo.V = (data >> 8) & 1; |
| 108 | + |
| 109 | + sh4_mmu_utlb_sync(sh4, entry); |
| 110 | + } |
| 111 | + } else { |
| 112 | + if (addr & 0x800000) { |
| 113 | + LOG_FATAL("sh4_mmu_utlb_write data array 2 %08x %08x", addr, data); |
| 114 | + } else { |
| 115 | + LOG_MMU("sh4_mmu_utlb_write data array 1 %08x %08x", addr, data); |
| 116 | + |
| 117 | + struct sh4_tlb_entry *entry = &sh4->utlb[TLB_INDEX(addr)]; |
| 118 | + entry->lo.full = data; |
| 119 | + |
| 120 | + sh4_mmu_utlb_sync(sh4, entry); |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments