CPU Virtualization / CPU state

Discussion in 'Programmer's Corner' started by Ab Abrams, Oct 12, 2017.

  1. Ab Abrams

    Thread Starter New Member

    Apr 27, 2017
    14
    2
    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!
     
  2. MrSoftware

    Active Member

    Oct 29, 2013
    726
    201
    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.
     
  3. Papabravo

    Expert

    Feb 24, 2006
    11,156
    2,183
    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.
     
  4. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    3,113
    3,968
    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.
     
    nsaspook likes this.
  5. Papabravo

    Expert

    Feb 24, 2006
    11,156
    2,183
    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.
     
  6. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    3,113
    3,968
    Nope. BIG difference that matters greatly.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    11,156
    2,183
    If you say so massa.
     
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    3,631
    3,757
    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
     
    Last edited: Oct 20, 2017 at 8:02 PM
  9. Papabravo

    Expert

    Feb 24, 2006
    11,156
    2,183
    Specifically what hardware would that be? In other words, can you define the minimum set of hardware required for virtualization, as opposed to emulation?
     
  10. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    3,631
    3,757
    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: Oct 20, 2017 at 11:42 PM
  11. philba

    Member

    Aug 17, 2017
    324
    88
    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.
     
Loading...