Next Generation Emulation banner
1 - 4 of 4 Posts

·
Registered
Joined
·
774 Posts
Discussion Starter · #1 ·
I'm currently working on programming an emulator of my own, although I'm going to keep exectely what the emulator is for a secret until I at least finish implementing enough of it to get the emulator to show something. Besides, I'm still not entirely sure I'm going to make it a public release. At any rate, I've been thinking about the issue of address translation, and it's causing me a bit of trouble. It seems that there is no fast way to implement it fully in software, but I hear it's possible to do enirely in hardware using the x86's MMU. So far all the work I've done with assembler is relatively basic, but this is an advanced level problem. Can anyone give me an example of how I could implement hardware address translation in x86 assembly? Preferably one with no extra function calls invloved once the intitial translation has occured.
 

·
Registered
Joined
·
774 Posts
Discussion Starter · #3 ·
Well, basicly what I had in mind was for my opcode translations to keep their original address, or at least an offset one to put it in a memory region my program doesn't use. Then I execute the code with that address and have the x86's MMU translate it to where the memory is really located. I know it's not possible to do without a bit of trickyness, due to the fact a user mode program can only address 2GB of memory, while my target CPU to emulate can address a full 4GB of memory in privelaged mode (and that's the only clue you get :p). I think maybe if I did some address table swapping though, if that's even possible, then it could be done. I'm just not sure what opcodes I need to use to interact with the MMU, and how to avoid having it mess up address translation in the rest of my code which is written mostly in C (so God only knows where it ends up in memory).
 

·
Registered
Joined
·
774 Posts
Discussion Starter · #5 ·
Exophase said:
How much do you know about how x86's MMU works? You should know that pages are 4kb, whereas chances are whatever you're emulating has pages that are either variable size or larger than that.
I'm aware of both those things, however I don't really see how the excact page boundries being different sizes would cause many issues.

Exophase said:
At any rate, the OS isn't going to let you modify a process's page table directly, so unless you plan on doing this independantly of an operating system it's not even worth worrying about how to accomplish it. I do believe the 2GB figure you cited only applies to Windows; Linux should have 3GB for user apps but you still might not get all of that to do as you wish with. I doubt any of this means that much to you though...
I'm writing my emu for Windows and I haven't made portability a big concern, so how much memory linux gives my doesn't mean a thing to me. I really wonder why Windows couldn't let you modify your own processes page table though. As long as it can't interfere with other programs, it doesn't seem like much of a problem.

Exophase said:
I'm going to assume you're using Windows. What you would want is an OS call that would let you bind a specific part of the process's address space to somewhere in physical memory - exactly where may not be important, as long as you could allow other areas to be bound there too. Unfortunately this isn't possible (as far as I'm aware). What's more, you would also want the to be alerted when memory accesses are made to areas outside of the emulated machine's physical RAM but in other important areas of its address space (mem-mapped I/O). This would be impossible without low level access to the exception handler of the operating system, and what's more, the granularity of page accesses might not be good enough for this. So you'd get stuck checking all memory accesses for address region anyway, and what's more, you'd most likely have to do it after translation which is impossible if you're letting the hardware translate for you. At this point you're going to be doing enough work as it is that if constructed cleverly you can throw in the address translation for little or no additional cost.

This is something I've considered before, but the bottom line is that it just isn't going to happen. The bare minimum would be to do this independantly of an OS, but even that simply isn't enough unless the platform you're emulating is in some way heavily restricted (and a 4GB address space doesn't indicate this).

- Exo
Ok, I see what you mean. Well, it was just a thought. You know, I think what they really need to do is design a CPU with emulation in mind. It's really not such a far-fetched idea considering that emulation is the best (cheapest) way to do backwards compatibility. Hardware optimizations for emulation would make the whole thing so much easier.
 

·
Registered
Joined
·
774 Posts
Discussion Starter · #8 ·
I meant that it wouldn't be a problem for windows to allow it, not that it isn't one that it doesn't allow it.

Exophase said:
It's called Transmeta Crusoe. :)

- Exo
Damn, I'm never the first one to think of anything :p.
 
1 - 4 of 4 Posts
Top