Upcoming Posts

Upcoming Posts....

Make your own partition magic software.
How to make an assembler.
What is booting?
Write a simple OS!

‎"I have no special talents. I am only passionately curious." - Albert Einstein

Tuesday, February 28, 2012

Virtual Machine Implementation

Can application software run an operating system? Let me put it in other way, how can ‘VMware’ application executes/loads operating system like Linux? Curious to know, be patient and read this article:

Let me start with the computer fundamental to get you in the context of virtual machine:

Hardware – Computer consists of hardware's like processor, RAM, Hard disk, monitor, keyboard and motherboard which contains chips like BIOS, System timer chip 8054, Interrupt controller 8259 etc.

Software – Operating system (OS) and other software’s like compiler, MS office etc are nothing but a binary file or a set of binary files which contain machine level instructions or opcode (Operation code).

When OS gets loaded into the memory, processor reads instructions and performs operations accordingly. Anything (any machine/person/software) which can follow the instruction mention in binary file(s) can load/execute OS. Isn’t it? Let’s take an example of processor:

Processor: It has several registers used to hold values. Few registers tell processor where the code segment and where the data is in the memory. Using these special registers, processor executes instructions and completes its job. Suppose, the processor reads ‘89D8’ instruction (equivalent to MOV AX,BX assembly code), it will copy the content of BX register into AX register. Similarly, the opcode ‘A0 F4 C4’ (equivalent to MOV AL, [34F4] assembly code) will copy content stored at “34F4” memory address in data segment into AL register.

This is how the processor makes machine and OS usable. Here, you can think that processor is doing nothing but just following the instruction written in OS binaries files. Right?

Now think, can’t we write a program which can behave exactly like a processor? We can write a class to represent a processor and write methods which will perform operations as processor does. The program will work like a processor. Isn’t it? Note that the physical processor is not executing these instructions, a program is doing that. So we can call this program, a ‘virtual’ processor. Can’t we?

Similarly, we can write programs for implementing virtual RAM, Hard disk, monitor, keyboard and motherboard which contains chips like BIOS, System timer chip 8054, Interrupt controller 8259 etc. Combining all these virtual devices will make a virtual machine software like VMWare. Stay tuned for more information on implementation!!!

I hope you’d have enjoyed reading this article. Post your feedback and help me in improving my writing skills/style!

Wednesday, February 15, 2012

How is 'this' pointer passed to the member method?

We know the 'this' pointer points to the object being worked on. All the member methods access object's data using 'this' pointer. C++ Standards doesn't say anything about how to pass 'this' pointer to the Member function. It depends on compiler's calling convention implementation. There are two ways to pass 'this' pointer to the member methods:

1. Pass 'this' pointer to method as argument by pushing it on stack. GCC/CC uses this mechanism.

For example, you can consider that compiler will teat 'void test::display()' method as 'void test::display(test *this)'.

2. Copy 'this' pointer on a register (ECX register is used by VC++). Microsoft VC++ uses this mechanism to provide 'this' pointer to the member methods.

test a;
a.compile_time_binding_method();
     lea ecx,[a] // Address of object 'a' is getting copied in ECX register
     call test::compile_time_binding_method (41118Bh)

You can refer 'Calling Convention' for more information.