Real Mode Emulator v2

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Real Mode Emulator v2

Post by thepowersgang »

Well, nearly two years ago I posted one of my projects on this forum, the Real Mode Emulator (Link)

Recently, someone brought the code back up in another topic and this spurred me to complete it. I ended up essentially doing a complete rewrite but now I am truly confident that it is ready for release.

The current version has some opcodes still unimplemented, and there seems to be a bug somewhere but I can't seem to find it, but the codebase is stable and should be usable.

So without further ado, here is Real Mode Emulator 2.

The emulator is licensed under the BSD licence and id designed to be included in almost any OS.
There is a small amount of changes needed to the start of rme.c to account for different debugging function names and IO port access, but this should be all.
I have included with it a testing kernel that sets up an emulator context and calls different BIOS functions (atm these are selected by using #if statements to disable unused ones)

If people could try this out and post bug reports (unimplemented opcodes and badly implemented opcodes) it would be appreciated.
I will be pushing changes to my tree to my git repository as I go along, so if you have posted a bug report, expect it to be fixed in this version rather quickly.

NOTE: This emulator does not, and I doubt will ever, support size overrides. Including support for these would make the code that much more ugly to work with, so I am planning not to support them. If someone can convince me why I might need them, I may reconsider, if it can be done cleanly.
Attachments
RME2.tar.gz
RME2 Git Dump 13-Mar-2010
(17.46 KiB) Downloaded 262 times
Last edited by thepowersgang on Sat Mar 13, 2010 8:05 am, edited 1 time in total.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Real Mode Emulator v2

Post by quanganht »

It was me who brought your code back from 6 feet under :)
I have a couple of (dumb) questions:
1. Can it work in Long mode?
2. Can I call Vesa interrupts using this emulator?

Sadly, my 64-bit kernel is on a long way to go, so I can't test this emulator yet. :(
"Programmers are tools for converting caffeine into code."
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Real Mode Emulator v2

Post by Combuster »

thepowersgang wrote:NOTE: This emulator does not, and I doubt will ever, support size overrides. Including support for these would make the code that much more ugly to work with, so I am planning not to support them. If someone can convince me why I might need them, I may reconsider, if it can be done cleanly.
...because half of the modern bios call require 32 bits registers (=operand size prefix)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Real Mode Emulator v2

Post by quanganht »

Just compiled the test kernel:

Code: Select all

lib.c: Assembler messages:
lib.c:18: Error: suffix or operands invalid for `mov'
lib.c:31: Error: suffix or operands invalid for `mov'
"Programmers are tools for converting caffeine into code."
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Real Mode Emulator v2

Post by earlz »

So by "Real-Mode Emulator" do you mean you've built an 8086 emulator? Or is it more than that? Are all the opcodes interpreted?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Real Mode Emulator v2

Post by thepowersgang »

@earlz: It's currently an 8086 emulator.

@quanganht: Well, it's designed to be able to work in long mode, but I haven't explicitly tested it in long mode. As for Vesa interrupts, it should be able to call them.
Try changing the mov instructions to movl. On my version (GCC 4.4.1 / Binutils 2.20) it doesn't seem to error.

@Combuster: Hmm, I didn't know that (I rarely use BIOS functions). I'll look into how to implement size overrides without making the codebase messy.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Real Mode Emulator v2

Post by quanganht »

movl doesn't help. I'm using GCC targeted at x86_64
"Programmers are tools for converting caffeine into code."
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Real Mode Emulator v2

Post by thepowersgang »

I forgot to mention that the test kernel is for PMode.
The emulator (in rme/) should work x86_64, but the test kernel won't
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Real Mode Emulator v2

Post by earlz »

thepowersgang wrote:@earlz: It's currently an 8086 emulator.
And is it interpreted or JITed or what? What is magic about it compared to porting an emulator to your OS?
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Real Mode Emulator v2

Post by ~ »

From what I saw in the code, it looks like it doesn't use JIT, but instead does manually all of the CPU operations (parity checking, etc.) using C macros, but I may be wrong.

I think it is intended to be used as a kernel-mode interface which would replace V86 mode in the same way as software multitasking replaces x86 built-in multitasking capabilities.

It is also more portable, which means that it could run 16-bit x86 code even if there's no V86 mode available, just what happens in 64-bit Long Mode.

Now BIOS interrupts could be executed (with care) as long as they don't contain instructions beyond 8086 or 32-bit register usage, without having to go back to Real Mode under any circumstances other than, maybe, really shuting down the PC.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Real Mode Emulator v2

Post by thepowersgang »

@~
Exactly. That is entirely the point of writing it.
Actually, the first version was written because I couldn't be bothered dropping to real mode or setting up VM8086 (I didn't have stable multitasking)

I'm currently working on getting size overrides working, but it seems that the Qemu BIOS doesn't use them.
Also, I've checked VESA and it seems to work correctly with AX=0x4F00, ..01 and ..02 in Qemu (I'm going to check bochs sometime today)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Real Mode Emulator v2

Post by pcmattman »

Sounds a lot like x86emu to me...
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Real Mode Emulator v2

Post by thepowersgang »

Possibly, I haven't had much experience with x86emu so I can't really say.
Mostly I'm doing this for fun, it may have already been done, but what are we all doing?
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Real Mode Emulator v2

Post by Combuster »

thepowersgang wrote:Also, I've checked VESA and it seems to work correctly with AX=0x4F00, ..01 and ..02 in Qemu (I'm going to check bochs sometime today)
I was mostly referring to real hardware which often uses 32-bit registers, and thus 32-bit outs (= o32 outw)

Some random function in my test box' video bios (copyright ATI/AMD, ~1996, posted under fair use) so you'll know what to expect :wink::

Code: Select all

00000572  6650              push eax
00000574  6653              push ebx
00000576  660FB7DB          movzx ebx,bx
0000057A  668BC3            mov eax,ebx
0000057D  66C1E303          shl ebx,0x3
00000581  B103              mov cl,0x3
00000583  E8C800            call 0x64e
00000586  7632              jna 0x5ba
00000588  662BD8            sub ebx,eax
0000058B  662BD8            sub ebx,eax
0000058E  B106              mov cl,0x6
00000590  E8BB00            call 0x64e
00000593  7625              jna 0x5ba
00000595  662BD8            sub ebx,eax
00000598  662BD8            sub ebx,eax
0000059B  B102              mov cl,0x2
0000059D  E8AE00            call 0x64e
000005A0  7618              jna 0x5ba
000005A2  662BD8            sub ebx,eax
000005A5  B104              mov cl,0x4
000005A7  E8A400            call 0x64e
000005AA  760E              jna 0x5ba
000005AC  662BD8            sub ebx,eax
000005AF  B101              mov cl,0x1
000005B1  E89A00            call 0x64e
000005B4  7604              jna 0x5ba
000005B6  D1EB              shr bx,1
000005B8  32C9              xor cl,cl
000005BA  8BC3              mov ax,bx
000005BC  665B              pop ebx
000005BE  8BD8              mov bx,ax
000005C0  6658              pop eax
000005C2  B81F00            mov ax,0x1f
000005C5  F7E3              mul bx
000005C7  BB9805            mov bx,0x598
000005CA  F7F3              div bx
000005CC  3DFF01            cmp ax,0x1ff
000005CF  7309              jnc 0x5da
000005D1  D1EB              shr bx,1
000005D3  D3EB              shr bx,cl
000005D5  3BDA              cmp bx,dx
000005D7  7701              ja 0x5da
000005D9  40                inc ax
000005DA  D1E8              shr ax,1
000005DC  8AD8              mov bl,al
000005DE  8AF9              mov bh,cl
000005E0  C3                ret
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Real Mode Emulator v2

Post by earlz »

thepowersgang wrote: I'm currently working on getting size overrides working, but it seems that the Qemu BIOS doesn't use them.
Also, I've checked VESA and it seems to work correctly with AX=0x4F00, ..01 and ..02 in Qemu (I'm going to check bochs sometime today)
Size overrides? I thought it was just emulating the 8086 right now? Have I forgotten some opcodes?

Also, I've made something similar to your project then. x86lib, it is a very lightweight library with it's only dependencies being exceptions and (optionally) cout/cin.
Post Reply