Aug 13, 2011

Simple OS - note

While I was working on my simple operating system project. I found something interesting.
Almost all the x86 system boot up in 16-bit real mode. And the way to enable the protected mode is quite easy.
As osdev wiki suggest, using the following instruction can take us from real mode to protected mode.
mov  eax, cr0   ; switch to pmode by
or al,1         ; set pmode bit
mov  cr0, eax
But there are one thing that bother me a lot, since our code is still in the real mode, 
how can we use the 32-bit register and instructions.
After google for a while I found a very helpful website that completely solved my question.
answer in stackoverflow 
answer in nasm forum 
The answer is that
When intel introduced 32-bit code - they used the same opcodes! 
When using 32bit register in 16 bit real mode, assembler will place a prefix in front of the instruction. (0x66 according to the nasm forum) This tell the cpu that I'm using 32-bit register
in 16-bits real mode.

I take some picture to verified the result.
My environment is ubuntu 10.10 and gcc 4.4.5
I' using qemu and gdb to verified the result.

As you can see, there are 0x66 prefix in front of the mov eax, 0 instruction.

Aug 9, 2011

compile qemu under ubuntu

For some reason, I have to build qemu from the source code.
This is some note of how to do this.

My environment:
ubuntu 10.10
gcc 4.4.5

download the source code of the qemu from the following link.
I choose version 0.15

install some require libraries and tools.
sudo apt-get install build-essential checkinstall 
sudo apt-get install zliblg-dev libSDL-dev

extract the tar.gz.
tar -xvf qemu-0.15.0.tar.gz

cd to the directory and configure.

build the source code.

install the qemu. You can use make install, but I recommend using the checkinstall.
It is easier to manage the code u build.
(Since I can't find the uninstall tag in the Makefile of qemu. Therefore, I use checkinstall instead of make install.)

sudo checkinstall -D --install=no
sudo dpkg -i $package_name
-D will create a debian package for the debian distribution.
If u want to build rpm , just use -R instead of -D 
dpkg is the utility to install a deb package. If u want to uninstall a package use -r.

reference website: