MMU translate from recompiler

Discussion of development and patch submission.
Post Reply
Alegend45
Posts: 85
Joined: Sat 26 Apr, 2014 4:33 am

MMU translate from recompiler

Post by Alegend45 »

It currently just calls the interpreter version, but this could be useful nonetheless.

Code: Select all

diff -r 9c1cbcfcbad1 -r 197f771862a1 src/codegen.h
--- a/src/codegen.h	Wed Jan 28 21:58:02 2015 +0000
+++ b/src/codegen.h	Fri Jan 30 13:39:46 2015 -0600
@@ -63,6 +63,7 @@
 void codegen_block_init(uint32_t phys_addr);
 void codegen_block_remove();
 void codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_pc, uint32_t old_pc);
+void codegen_generate_mmu_call(uint32_t addr, bool rw);
 void codegen_generate_seg_restore();
 void codegen_check_abrt();
 void codegen_set_op32();
diff -r 9c1cbcfcbad1 -r 197f771862a1 src/codegen_x86.c
--- a/src/codegen_x86.c	Wed Jan 28 21:58:02 2015 +0000
+++ b/src/codegen_x86.c	Fri Jan 30 13:39:46 2015 -0600
@@ -914,6 +914,24 @@
         codegen_endpc = (cs + pc) + 8;
 }
 
+void codegen_generate_mmu_call(uint32_t addr, bool rw)
+{
+        codeblock_t *block = &codeblock[block_current];
+
+        for (c = 0; c < NR_HOST_REGS; c++)
+                host_reg_mapping[c] = -1;
+
+        addbyte(0x58); //PUSH rbp
+        addbyte(0x8b); //MOVL rbp,rsp
+        addbyte(0xec);
+        addbyte(0x68); //PUSH addr
+        addlong(addr);
+        addbyte(0x68); //PUSH rw
+        addlong(rw); //bools are 32bits long on most archs
+        addbyte(0xe8); //CALL
+        addlong((uint8_t *)mmutranslatereal - (uint8_t *)(&block->data[block_pos + 4]));
+}
+
 void codegen_check_abrt()
 {
         codeblock_t *block = &codeblock[block_current];
Last edited by Alegend45 on Sat 31 Jan, 2015 1:48 am, edited 1 time in total.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: MMU translate from recompiler

Post by SarahWalker »

Could you remove any whitespace changes before posting the patch? It's difficult to quickly see what's been changed.
Alegend45
Posts: 85
Joined: Sat 26 Apr, 2014 4:33 am

Re: MMU translate from recompiler

Post by Alegend45 »

Done.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: MMU translate from recompiler

Post by SarahWalker »

Okay, thanks. But please don't let 64-bit-isms enter the code - codegen_x86.* is definitely aiming for 32-bit systems.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: MMU translate from recompiler

Post by SarahWalker »

I should also say that as I'm actively working on this area of the emulator, you are quite likely to end up duplicating work I'm already doing. By all means continue - if nothing else it will be a learning experience - but be aware that I'm unlikely to accept patches for work I'm already doing / have already done.
Alegend45
Posts: 85
Joined: Sat 26 Apr, 2014 4:33 am

Re: MMU translate from recompiler

Post by Alegend45 »

Ah, okay, then.
Alegend45
Posts: 85
Joined: Sat 26 Apr, 2014 4:33 am

Re: MMU translate from recompiler

Post by Alegend45 »

TomWalker wrote:Okay, thanks. But please don't let 64-bit-isms enter the code - codegen_x86.* is definitely aiming for 32-bit systems.
Well, this code works either way.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: MMU translate from recompiler

Post by SarahWalker »

Your comments refer to registers that don't exist on x86-32. It's also best to not be running code in a mode it wasn't designed for, regardless of how much it might appear to work; it may stop working in the future. My intention, once the 32-bit recompiler has matured a bit, is to have a seperate 64-bit compiler optimised for that mode.
Post Reply