CPU Virtualization / CPU state

Thread Starter

Ab Abrams

Joined Apr 27, 2017
25
Hi,
I was wondering if someone can explain to me what CPU virtualization means from the perspective of inside of a CPU. I mean, If I have a single core how I virtualized it?
What parts and functions of a CPU I have to know (registers, MMU) for achieving this CPU virtualization function? Is there any "general" programming code that does this?

Also, I wil try to explain it as much better I can, I want to "play", understand and descover the "state" of a CPU (state of registers), to be more specific, of an ARM CPU (any model). Can somebody guide me how I can do this? Do I have to buy a microcontroller?

Many thanks!
 

MrSoftware

Joined Oct 29, 2013
2,202
Check out Virtual Box. I've never used it myself, but it's open source so you can check out the code and see what they do.

https://www.virtualbox.org/

Starting with a microcontroller isn't a bad idea as far as learning how a processor works, and that might make it easier for you to understand how virtualization works.
 

Papabravo

Joined Feb 24, 2006
21,228
The goal of virtualization is to be able to take a program written for a particular hardware platform and operating system, run it on a different hardware platform and have it duplicate the original behavior. Reasons you might want to do this include the obsolescence or unavailability of the original platform.

It is also desirable to repeatedly create clean versions of a platform and an OS to test installation procedures.
 

joeyd999

Joined Jun 6, 2011
5,287
The goal of virtualization is to be able to take a program written for a particular hardware platform and operating system, run it on a different hardware platform...
No. That would be emulation. Virtualization mimics the underlying hardware (actually, it exposes the underlying hardware) in such a way that the virtual machine looks like a real -- and separate -- machine to the software.

One cannot run, say, ARM code on virtualized hardware on an Intel machine.
 

Papabravo

Joined Feb 24, 2006
21,228
No. That would be emulation. Virtualization mimics the underlying hardware (actually, it exposes the underlying hardware) in such a way that the virtual machine looks like a real machine to the software.

One cannot run, say, ARM code on virtualized hardware on an Intel machine.
I think it may be a distinction without a difference. You can certainly create an ARM virtual environment on an Intel machine so the code cannot tell the difference. Just because you can do something doesn't necessarily mean you should do it.
 

nsaspook

Joined Aug 27, 2009
13,315
Last edited:

Papabravo

Joined Feb 24, 2006
21,228
Yes, it matters, a lot if you write modern OS software. Most 32bit machines today are capable of Virtualization but many older ones were not because they lacked the hardware. The original MC68000 is an example. That was fixed with the MC68010.
http://www.cpu-world.com/CPUs/68010/index.html

The PIC32MZ has Full Virtualization because its a MIPS M-class CPU.
https://github.com/lyegoshin/tinyVP
Specifically what hardware would that be? In other words, can you define the minimum set of hardware required for virtualization, as opposed to emulation?
 

nsaspook

Joined Aug 27, 2009
13,315
Specifically what hardware would that be? In other words, can you define the minimum set of hardware required for virtualization, as opposed to emulation?
You can define the minimum set of hardware (runs code directly on the hardware) requirements per:
http://cs.nyu.edu/courses/fall14/CSCI-GA.3033-010/popek-goldberg.pdf

Virtualization allows code (like several different OS) to run directly on the CPU as a totally separate isolated CPU and machine. Emulators will run the code themselves as a CPU task on a CPU.

You can virtualize a real physical CD drive so that different host OS systems can use it on the same physical computer to load a real CD within each OS or you can emulate a CD drive using a ISO image.

https://blog.dell.com/en-us/emulation-or-virtualization-what-s-the-difference/
 
Last edited:

philba

Joined Aug 17, 2017
959
Specifically what hardware would that be? In other words, can you define the minimum set of hardware required for virtualization, as opposed to emulation?
Basically, the supervisor needs to be able to trap access to certain instructions, i/o ports and memory location. For example, if the program executes a halt instruction, the supervisor will get control. If the program tries to use an I/O channel, the virtual driver for that channel will do the right thing.

No hardware is needed for emulation because the emulated code isn't actually being executed in hardware - the emulator (a program) takes each op code and "executes" it in software which is why it's often really slow.
 

MrSoftware

Joined Oct 29, 2013
2,202
Virtualization is used a LOT for servers, for better hardware utilization and easier management. It's used for many other reasons as well. For example:

https://www.vmware.com/products/vsphere.html

I agree that you cannot virtualize an OS written for hardware that is different from the host, without emulation. For example, grab any x64 based virtualization software and try to install Solaris for SPARC on it. The host hardware has a different architecture and won't be able to run the software compiled for SPARC. A SPARC emulator would be required.
 
Top