Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
RayeR(R)

Homepage

CZ,
20.02.2015, 11:03
 

64b long mode and VMX/VT-x tutorial and source examples (Developers)

Hi,
during browsing on Internet I found a nice tutorials by Michael Chourdakis @CodeProject.
One explains real, unreal, V86, PM and long mode including an example how to switch to long mode from DOS and return back
http://www.codeproject.com/Articles/45788/The-Real-Protected-Long-mode-assembly-tutorial-for
The second aims to hardware virtualisation basics and implements some very basic hypervisor
http://www.codeproject.com/Articles/215458/Virtualization-for-System-Programmers
I didn't go through yet but looks interesting. Maybe someone else would like to experiment with this under DOS...

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
20.02.2015, 18:25

@ RayeR
 

64b long mode and VMX/VT-x tutorial and source examples

Japheth did a very good example of switching to long mode and back to 16bit mode here:

http://web.archive.org/web/20120411125554/http://www.japheth.de/

As far as I see Michael Chourdakis does not go back to 16bit mode in his example.

There was a long discussion regarding adding multi tasking/protected mode to FreeDOS in the FreeDOS forum. I think one should skip protected mode support because protected mode is outdated. It is better to implement a hypervisor instead. However, this will not work on old PCs. On the other hand by the time the hypervisor for FreeDOS is ready these PCs will be very difficult to find.:-)

I tested the Nova hypervisor which is open source. But as far as I could make out it still needs work to be usable. You have to have drivers for this which you need to borrow from e.g. Linux since it is too much work to implement these for all sorts of devices.

Given the resources available for DOS developments it could be better to make a new hypervisor distribution based on Xen. See e.g. Install Xen bare metal hypervisor

Georg

RayeR(R)

Homepage

CZ,
05.03.2015, 20:02

@ georgpotthast
 

64b long mode and VMX/VT-x tutorial and source examples

Yes, I remember, that Japheth did some 64bit mode experiment years ago. I just wanted to share the examples I found. I didn't have time to go through yet.

I also played with Nova Hypervisor (there is some updated sources, no binary) but most apps I tried crashed it (probably everything pmode). I think about how complex would be to write a simple single-task hypervisor that will pass most of exceptions to real hardware and only traps some specific IO e.g. for SB emulation. AFAIK guest OS is usually run in CPL>0 that cause some problems because it was not designed for but it should be possible to run it in CLP 0 that probably remove protection of hypervisor code but maybe possible to reserve some small block of memory for it...
I also read that some trojans can run OS silently under hypervisor and traps keystrokes or so...

---
DOS gives me freedom to unlimited HW access.

RayeR(R)

Homepage

CZ,
06.03.2015, 12:34

@ RayeR
 

64b long mode and VMX/VT-x tutorial and source examples

I read about Execution Control Fields in VMCS structures that set what operations in guest cause VMExit to VMM. If I would set all to be allowed will I get the guest running uninterrupted like without VMM? (of course I would need exit to VMM sometimes but looking for the simplest scenario).

---
DOS gives me freedom to unlimited HW access.

RayeR(R)

Homepage

CZ,
10.03.2015, 10:51

@ RayeR
 

64b long mode and VMX/VT-x tutorial and source examples

It seems that it also depends on used CPU - if it supports unrestricted guest (can be checked by bitflag in some MSR). I will add display some VTX details to my CPUID utility. And uh oh, VTX needs enable paging and PAE-needs to setup lot of data structures (I hoped that paging will be enabled by guest if it needs it), my head inflates while reading... :)

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
10.03.2015, 19:06

@ RayeR
 

64b long mode and VMX/VT-x tutorial and source examples

I cannot comment on this since it is quite a while ago that I looked into this a little bit. However, I would take a look at the Nova, Xen or KVM source code and see if this provides some help.

RayeR(R)

Homepage

CZ,
10.03.2015, 20:01

@ georgpotthast
 

64b long mode and VMX/VT-x tutorial and source examples

> I cannot comment on this since it is quite a while ago that I looked into
> this a little bit. However, I would take a look at the Nova, Xen or KVM
> source code and see if this provides some help.

I played with NovaHV ~2 yeas ago with freedos but I was disappointed that most of apps ended immediatelly in vmm error so lost the interest. I still have some screenshots here:
http://rayer.g6.cz/1tmp/novahv/
Anyway, Nova, Xen or KVM sources are sooo huge and I no longer have spare endless hours to dive in. The tutorial I linked is much more smaller and of course less functional. The text is written very understandable, if you have necessary background. I would rather see if its possible to make even lighter hypervisor that would do just simple run a single instance of dos (including v86/pm) in pass-through mode. There will be a possibility that guest DOS can destroy VMM code but it would be enough to limit max XMS to leave some spare MB RAM at end. But before all that I would need better understand the paging, I never hanled this stuff...
That's a pitty that Japhet left his work on DOS stuff, he's the one who have the best understanding of this memory management, etc... :(

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
10.03.2015, 21:21

@ RayeR
 

64b long mode and VMX/VT-x tutorial and source examples

If you do not have the time to read that code why do you have the time to write a similar software? To make something useful you will have to program a userland and a fleet of device drivers after you are done with the Hypervisor.

Maybe these links do help a bit:
http://linux.linti.unlp.edu.ar/images/f/f1/Vtx.pdf

http://wiki.osdev.org/Paging

This book covers 386 paging but as far as I recall 64bit paging just adds another table to this principle:
https://books.google.de/books?id=yXriyj4eZ-gC&dq=page+fault+linear+address&hl=de&source=gbs_navlinks_s

This discusses turning on 64bit paging:
http://140.120.7.21/LinuxRef/mmLinux/VmOutline/vminit.html

RayeR(R)

Homepage

CZ,
10.03.2015, 23:07

@ georgpotthast
 

64b long mode and VMX/VT-x tutorial and source examples

> If you do not have the time to read that code why do you have the time to
> write a similar software?

No, I don't want to write similar complex software but only trap and emulate specific operation with single guest, if possible. And I'm not going to program anything yet, just reading. As I found the Michael's tutorial interesting I just posted here because someone else may be interested, nothing more for now...
Thanks for links, that pdf was not accessible for me but via archvie
https://web.archive.org/web/*/http://linux.linti.unlp.edu.ar/images/f/f1/Vtx.pdf

---
DOS gives me freedom to unlimited HW access.

RayeR(R)

Homepage

CZ,
11.03.2015, 13:27

@ RayeR
 

xvisor

BTW did you tried xvisor? http://xhypervisor.org/
I was trying to compile v0.2.5 under 64b linux but after configure and type make I got only a bunch of
/start.dep:1: *** missing separator. Stop.
errors in every *.dep file

v0.2.4 says:
(cc-dep) arch/x86/cpu/x86_64/cpu_elf.dep
In file included from <command-line>:0:0:
/usr/include/stdc-predef.h:59:1: fatal error: /home/public/xvisor-0.2.4/build/tmpconf/openconf.h: No such file or directory
#endif
^
compilation terminated.
Is there a precompiled binary for x86 to try?

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
11.03.2015, 18:33

@ RayeR
 

xvisor

> BTW did you tried xvisor? http://xhypervisor.org/
No I did not know about that project yet. I looked around in the net for it and found these links ;-) ;-) :

Video of a xvisor presentation at fosdem conference:
http://video.fosdem.org/2015/devroom-embedded/car_hypervisor.mp4

Picture of Anup Patel:
https://github.com/avpatel
He currently works for http://flipkart.com

Here are instructions for beginners;-) :
https://groups.google.com/forum/#!topic/xvisor-devel/mgyIZwpc8aE

So apparently the development currently focuses on ARM which you can emulate with Qemu.

> I was trying to compile v0.2.5 under 64b linux but after configure and type
> make I got only a bunch of
> /start.dep:1: *** missing separator. Stop.
> errors in every *.dep file
>

IIRC this may be caused by blanks instead of tabs in the makefile.

Georg

RayeR(R)

Homepage

CZ,
11.03.2015, 22:47

@ georgpotthast
 

xvisor

> IIRC this may be caused by blanks instead of tabs in the makefile.

There are some spaces at beginning of line in dep files:

/xvisor-0.2.5/build/arch/x86/cpu/x86_64/start.o: /xvisor-0.2.5/arch/x86/cpu/x86_64/start.S \
 /xvisor-0.2.5/build/tmpconf/openconf.h \
 /xvisor-0.2.5/arch/x86/cpu/x86_64/include/cpu_mmu.h \
 /xvisor-0.2.5/arch/x86/cpu/x86_64/include/multiboot.h \
 /xvisor-0.2.5/arch/x86/cpu/x86_64/include/arch_config.h

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
12.03.2015, 08:36

@ RayeR
 

xvisor

I do not know if this is meant as a question. In the makefiles the lines have to start with a tab and not with blanks. (If not directly at the left border) You find that mentioned in a lot of places on the net. Some editors may replace the tabs with blanks and then the makefile will not work.

> > IIRC this may be caused by blanks instead of tabs in the makefile.
>
> There are some spaces at beginning of line in dep files:
>
> /xvisor-0.2.5/build/arch/x86/cpu/x86_64/start.o:
> /xvisor-0.2.5/arch/x86/cpu/x86_64/start.S \
> /xvisor-0.2.5/build/tmpconf/openconf.h \
> /xvisor-0.2.5/arch/x86/cpu/x86_64/include/cpu_mmu.h \
> /xvisor-0.2.5/arch/x86/cpu/x86_64/include/multiboot.h \
> /xvisor-0.2.5/arch/x86/cpu/x86_64/include/arch_config.h
>

Rugxulo(R)

Homepage

Usono,
12.03.2015, 09:04

@ georgpotthast
 

xvisor

> I do not know if this is meant as a question. In the makefiles the lines
> have to start with a tab and not with blanks. (If not directly at the left
> border) You find that mentioned in a lot of places on the net. Some editors
> may replace the tabs with blanks and then the makefile will not work.

I haven't looked (and probably won't) at whatever it is you're talking about.

But just FYI, most "make"s will indeed let you avoid tabs (at least several that I tried). Although GNU Make was always pretty stubborn and picky, but even that added (in 3.82, IIRC, which specifically doesn't have a DJGPP port, so you need /beta/mak4[01]b.zip) ".RECIPEPREFIX" if you don't like the default.

RayeR(R)

Homepage

CZ,
12.03.2015, 19:02
(edited by RayeR, 12.03.2015, 19:37)

@ Rugxulo
 

xvisor

I know that makefiles use tabs instead spaces but I had problem with *.dep files that are generated automatically by Makefile. Even I cannot run "make distclean" because it stopped at error on first *.dep file. So I recursively deleted all *.dep run make clean and distclean again that passed. I run make menuconfig and make again and I got much further. Compiling stopped at error:

/home/public/xvisor-0.2.5/build/arch/x86/cpu/cpu.o: In function `arch_guest_add_region':
/home/public/xvisor-0.2.5/arch/x86/cpu/x86_64/arch_guest_helper.c:105: undefined reference to `enable_ioport_intercept'
/home/public/xvisor-0.2.5/build/arch/x86/cpu/cpu.o: In function `arch_guest_del_region':
/home/public/xvisor-0.2.5/arch/x86/cpu/x86_64/arch_guest_helper.c:134: undefined reference to `disable_ioport_intercept'
/home/public/xvisor-0.2.5/build/arch/x86/cpu/cpu.o: In function `cpu_init_vcpu_hw_context':
/home/public/xvisor-0.2.5/arch/x86/cpu/common/vm/vm.c:161: undefined reference to `amd_setup_vm_control'
/home/public/xvisor-0.2.5/build/arch/x86/cpu/cpu.o: In function `cpu_enable_vm_extensions':
/home/public/xvisor-0.2.5/arch/x86/cpu/common/vm/vm.c:201: undefined reference to `init_amd'
collect2: error: ld returned 1 exit status
make: *** [/home/public/xvisor-0.2.5/build/vmm_tmp1.elf] Error 1

I guessed that sources for intel and amd virt. are not well separated because I selected only intel vt-x and it's trying to compile something for amd. So I run menuconfig again and selected both AMD-SVM and intel VT-x. Then I got another nice error:

/home/public/xvisor-0.2.5/arch/x86/board/x86_64_generic/hpet.c: In function ?hpet_clockchip_init?:
/home/public/xvisor-0.2.5/arch/x86/board/x86_64_generic/hpet.c:394:7: error: ?struct hpet_timer? has no member named ?clkcip?
  timer->clkcip.cpumask = vmm_cpumask_of(target_cpu);
       ^
/home/public/xvisor-0.2.5/arch/x86/board/x86_64_generic/hpet.c:412:38: error: ?irqno? undeclared (first use in this function)
  if ((rc = vmm_host_irq_set_affinity(irqno,
                                      ^
/home/public/xvisor-0.2.5/arch/x86/board/x86_64_generic/hpet.c:412:38: note: each undeclared identifier is reported only once for each function it appears in
make: *** [/home/public/xvisor-0.2.5/build/arch/x86/board/x86_64_generic/hpet.o] Error 1

I guessed that I have to disable multiprocessor host support. Then it finally compiled something, I got build/vmm.bin. Warning, if you do make clean, entire build directory is removed with your .config file (I guess it should be placed in top dir and not in build dir). All this seems very experimental, dirty and crappy...

---
DOS gives me freedom to unlimited HW access.

RayeR(R)

Homepage

CZ,
13.03.2015, 01:32

@ RayeR
 

xvisor

WTF, xvisor doesn't support intel CPU yet :-D
[image]

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
13.03.2015, 18:07

@ RayeR
 

xvisor

from your previous post it seems that there is code for AMD-V though.

> WTF, xvisor doesn't support intel CPU yet :-D

RayeR(R)

Homepage

CZ,
13.03.2015, 19:18
(edited by RayeR, 13.03.2015, 20:10)

@ georgpotthast
 

xvisor

> from your previous post it seems that there is code for AMD-V though.

I compiled with BOTH virt. technologies because it couldn't compile with only one selected. In fosdem presentation video, that I watched now, was only mention about AMD an ARM VT support... So maybe next try after an year... :)

---
DOS gives me freedom to unlimited HW access.

georgpotthast(R)

Homepage

Germany,
13.03.2015, 21:14

@ RayeR
 

xvisor

I thought you were looking for something that does not work yet ;-) (not serious)

If you want something working you will have to test e.g. KVM or Xen.


> > from your previous post it seems that there is code for AMD-V though.
>
> I compiled with BOTH virt. technologies because it couldn't compile with
> only one selected. In fosdem presentation video, that I watched now, was
> only mention about AMD an ARM VT support... So maybe next try after an
> year... :)

Rugxulo(R)

Homepage

Usono,
15.03.2015, 05:15

@ georgpotthast
 

xvisor

> I thought you were looking for something that does not work yet ;-) (not
> serious)
>
> If you want something working you will have to test e.g. KVM or Xen.

I'm half-tempted to try (under VirtualBox using Intel Nehalem VT-X) FreeBSD 10.1 running bhyve running 32-bit Linux running DOSEMU. Do you think it'll work?? :-)

georgpotthast(R)

Homepage

Germany,
16.03.2015, 17:15

@ Rugxulo
 

xvisor

> > I thought you were looking for something that does not work yet ;-) (not
> > serious)
> >
> > If you want something working you will have to test e.g. KVM or Xen.
>
> I'm half-tempted to try (under VirtualBox using Intel Nehalem VT-X) FreeBSD
> 10.1 running bhyve running 32-bit Linux running DOSEMU. Do you think it'll
> work?? :-)

I am not familiar with bhyve but kvm works in combination with qemu and you can run Freedos based on qemu.

If bhyve can run a 32-bit Linux distro it should be able to run Freedos instead.

Back to index page
Thread view  Board view
15188 Postings in 1365 Threads, 250 registered users, 14 users online (0 registered, 14 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum