In this video we will set up the environment for the OS projects in Mac OS.
The tools we need in the course are cross compiler, nasm assembler and bochs emulator.
As you see, this is the download link of the cross compiler.
The version of the compiler is gcc 4.8.1 x86-64.
The link is added to the external source of this lecture.
You can download it using this link.
After the package is downloaded.
double click it
and you see the name of the package is gcc 4.8.1 linux x64.
Once we check the package is the correct one, we can install it.
When the first time we run it, we could have this warning message. In order to open it, we go to system preference panel
,
security and privacy
and click open anyway.
Ok now we can install the compiler. Click continue,
agree and then we get to the installation part. Click install and we are done.
Since it’s installed in my machine, I just exit out.
After the installation is done, we can check the status in the terminal.
The path is usr local and the gcc we just installed. The command is located in the bin folder.
As you can see, they are the commands we will use when we build the project.
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 restart if we have no interrupt handlers when the exception occurs.
Therefore, we tested the project in the virtual machine and then run the code in the real machine,
if you like.
And also, Bochs emulator can report error messages if the code causes exceptions,
which is especially important for us to debug the code.
To install it, we type brew install bochs and press enter to finish the installation.
I have already installed the bochs, so I don’t run this command.
After you install it, you can check the status by typing bochs and press enter. You can see we have several options here.
We will discuss it in a minute.
Right now, we just choose seven and close it out.
The next thing we are going to do is we are going to create an image file
since bochs will boot our projects with the image file.
First off, we navigate to desktop and the image will be created here.
To create the image file, we use command bximage.
We want to create hard disk image.
so we select option 1 and hit enter.
The default setting is hard disk, 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.
We name the image file 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 we change is for the cpu features which is at option 6 cpuid options.
As you see, long mode support is enable and what we want is the 1g page support.
Our memory manager requires one gigabyte page support at the initialization stage, so we enable this
feature.
Then we return to the options menu.
The memory allocated for the virtual machine is 1024 megabytes, which is enough for the product.
In the memory options, 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 option is 12 disk and boot options
.
we first look at channel 0.
You can 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.
We use the default mode.
Remember we have seen the three numbers 20 16 and 63.
Here. 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 booted 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 starts with the boot.img in the same folder. We will delve into details when we build our first program.
Another thing I need to mention is that since the gcc is installed in the customized path,
we need to run the command with full path.
You can check lecture how to use the resources in this section.
Ok the next tool is nasm assembler, in the boot process of the operating system,
the assembly language is the only language we can use.
So we choose nasm assembler in this course.
To install nasm, we type brew install nasm and hit enter to install it. After you are done,
you can check it
by the command nasm -v.
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, I have added the link in the external source of the lecture.
You can download it using this link.
When you install it, 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.
Let's get started.