In this video we will set up the environment for the OS projects in Ubuntu.
The tools we use in the course are gcc, nasm assembler and bochs emulator.
If you have not installed gcc, you can install it in the terminal, install gcc and press enter.
After it’s done,
you can check the version by the command gcc -v. As you see, the version is x86 64-bit.
Ok the next one is nasm assembler.
In the boot process of the operating system, we need assembly language to do the specific tasks
such as mode switching.
So we choose nasm assembler in this course. To install nasm,
we install nasm and hit enter to install it.
After you install it, you can check it by the command nasm -v.
Ok what we are going to do next is we are going to install bochs emulator.
All the projects will be tested in the emulator and then running in the real machine.
The reason we need virtual machine is that when we put the project in the real machine,
the computer could reset if we have no interrupt handlers when the exception occurs.
Therefore, we test the project in the virtual machine and then we can run the code in the real machine.
Bochs emulator can report error messages if the code causes exceptions, which is very important for us to
debug the code.
OK, now let's install it. We type install bochs and press enter to finish the installation.
The next thing we are going to do is we are going to create an image file since bochs will boot with the image file.
To create the image file,
we use command bximage.
Here we want to create hard disk image, so we select option 1 and hit enter.
The default setting is hard disk.
So we press enter, then we use the default settings as well.
Sectors is set to 512 bytes.
The size of disk is 10 megabytes which is enough for our project.
As for the name of the image file, we name it boot.img and we will write the project into this image file
and boot the computer.
Alright.
the image file is created. Notice that we have these three values which we will need to fill in the bochs configuration file later
.
Ok at this point we can open bochs and edit the configuration file. Because some options of the virtual environment configuration
is not for our os projects.
We select option 3 to change some settings.
The first one is for the cpu features which is at option 6 cpuid options.
As you see, long mode support is enabled and what we want is the 1g page support.
Our memory manager requires 1g page support at its initialization stage. So we enable this feature.
Then we return to the options menu. The memory allocated for the virtual machine is set to 1024mb
which is enough for the project.
In the memory opitions, we select standard options
and we change the memory size to 1024.
Ok the last settings we need to change is for the boot image file. The options is 12 disk and boot options
.
Here we first look at Channel 0.
You see, channel is enabled and we use the default settings here.
Next we go to option 4 and we specify the type of device disk.
The file name is the name of the boot image file and press enter.
Also, we use the default mode.
Remember we have seen the three numbers 20 16 and 63. They will be put into these settings.
As for other settings, we simply leave them unchanged.
Ok now the boot image will be loaded as a disk device. Then we will select this device as the one to boot first
.
So we change the floppy drive to disk.
That’s it. We return to the top menu
and save options to the configuration file.
We exit it out and see what we have in the configuration file.
As you can see, the memory size is 1024mb. The boot option is set to disk. The disk path is boot.img.
We will place this file in the folder where we build the project.
And bochs will start with the boot.img in the same folder. We will delve into details when we build our first project
.
As for the text editor, I use visual studio code in the course. You can choose other ones you like.
If you choose visual studio code, you can search visual studio code, go to the website.
Go to the website.
And download the package.
I have downloaded in the download folder.
Open it with software installer
and click install.
After the installation is done, you can add some extensions.
The extensions I use are c extensions
and x86 64 assembly syntax highlighting.
OK, right now, we have set up the environment. In the next section we will start to build our operating system from scratch
.
So let's get started.