Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint32_t EmotionEngine::translate_address(uint32_t address, bool write)
- {
- // Is this address legal to access?
- if (!cp0->status.exception && !cp0->status.error) {
- // It is illegal to access kernel and supervisor segments in user mode, assuming we're not in an exception.
- if (cp0->status.mode == 2 && address >= 0x80000000) {
- if (write)
- address_error_store();
- else
- address_error_load();
- }
- // It is illegal to access kernel segments in supervisor mode.
- if (cp0->status.mode == 1 && address >= 0x80000000 && !(address >= 0xC0000000 && address < 0xE0000000)) {
- if (write)
- address_error_store();
- else
- address_error_load();
- }
- }
- // kseg0 and kseg1 are not mapped; just translate to physical address.
- if (address >= 0x80000000 && address < 0xC0000000) {
- return address & 0x1FFFFFFF;
- }
- int tlb_virtual_page_number = cp0->gpr[10] >> 13;
- int tlb_address_space_id = cp0->gpr[10] & 0xFF;
- int tlb_page_mask = cp0->gpr[5];
- // Need to work out how to get the current virtual page number.
- //int virtual_page_number = (address & ~tlb_page_mask) >> 12;
- // Search for a matching TLB entry.
- int entry = 0;
- for (; entry < 48; entry++) {
- // Does the virtual page number match?
- if (cp0->tlb[entry].virtual_page_number != tlb_virtual_page_number)
- continue;
- // Does the address space ID match?
- if (cp0->tlb[entry].global && cp0->tlb[entry].address_space_id != tlb_address_space_id)
- continue;
- // We have a matching entry.
- break;
- }
- // If we have no matching entries, this is a TLB Miss exception.
- if (entry == 48) {
- tlb_miss();
- }
- // If the matching entry has a zero valid bit, this is a TLB Invalid exception.
- if (!cp0->tlb[entry].valid[0]) {
- tlb_invalid();
- }
- // If the matching entry has a zero dirty bit, and we are trying to write to it, this is a TLB Modified exception.
- if (write && !cp0->tlb[entry].dirty[0]) {
- tlb_modified();
- }
- if (cp0->tlb[entry].scratchpad) {
- Errors::die("[MMU] Unimplemented scratchpad mapping");
- }
- return cp0->tlb[entry].page_frame_number[0] | (address & 0x1FFF);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement