In this video we will set up the environment for the OS projects in windows 10.
In this course we will build the projects under linux environment.
So we need to enable Windows subsystem for Linux in Windows 10.
To do that, we search windows subsystem windows 10. We click the link install windows subsystem for linux.
We click the link install window subsystem for Linux.
In this page, we can follow the steps to finish the installation. We first need to enable subsystem feature.
So we copy the command and paste it in the power shell.
In the search box we type power shell and open it as administrator. administrator.
Ok, we paste the command here. After the operation is completed, restart the computer before we go to next step.
At this point, we can install linux system. Here we go to step 6.
All you need to do is open microsoft store and search ubuntu system.
We use Ubuntu 18.04 in this course.
In this page, you can click get to install Ubuntu. After the installation is done,
you can open the ubuntu in the start menu or you can run the system in the search box.
The first time you launch the system, you will need to create a user account and password.
This is the account we will use when we build our projects.
When you set up the user account, we can go to next step. In the ubuntu system, we need gcc and nasm
to build the projects.
So we install gcc and press enter. As you see, I have already installed it.
When the installation is done, you can check the status by typing gcc -v.
The version we use is x86 64.
OK, the next thing we will do is install nasm assembler which is used for the assembly code.
You can also check the version by command nasm -v.
Ok that’s it for the setup in ubuntu system.
Then we get to virtual machine. 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 projects in the real machine, the computer could restart
,
if we have no interrupt handlers when the exception occurs. Therefore, we test the project in the virtual machine
and then can run the code in the real machine if you like.
Bochs emulator can report error messages if the code causes exceptions,
which is very important for us to debug the code. To download it, we search bochs and go to the website.
Click source forge project. In this page, we choose 64-bit version.
Now you can click it to install bochs. The installation is simple, all you need to do is keep the default settings
and install it.
Once you are done, we create an image file.
So in the search box, we open command prompt, in this window we navigate to desktop
and the image will be created here. To create the image file, we use command bximage.
If you have an error bxiamge is not recognized as a command, you can edit the path in the environment variables.
In the search box, we type environment variables
and edit the system environment variables. In this window, we select path and click edit
You can add the bochs path here by clicking new
and copy the path here. As you see, I have added the path. Once you are done, we can run this command
.
Here we want to create hard disk image, so we select option 1 and hit enter.
The default setting is hard disk, we press enter.
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
.
OK, the image is created.
Notice that we have these three values which we will need to fill in the bochs configuration file later.
At this point, we can open bochs and edit the configuration file. So we type bochs and open it in the search box.
Because some options of the virtual environment configuration is not for our os projects.
We need to change some settings.
The first one we change is for the cpu features which is in the cpuid option. As you see,
long mode support is enabled
what we want here is the 1g page support. Our memory manager requires 1g page support at its initialization stage
.
So we enable this feature.
The memory allocated for the virtual machine is 1024mb which is enough for the project.
In the memory option, we change the memory size to 1024.
OK.
The last settings we need to change is for the boot image file which is located in the disk and boot options
.
We first look at ata channel 0. You can see channel is enabled. And we use the default settings here.
Next we specify the type of device disk. The path or physical device name is the name of the boot image file
.
As for the next three options, remember we have seen the three numbers 20 16 and 63.
They will be put into these settings.
Ok now the boot image will be loaded as a disk device. Then we will select this device as the first device to boot.
So we change the floppy drive to disk.
Save options to the configuration file and we are good to go.
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.
In the following lectures, 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 program.
As for the text editor, you can choose what you like. The editor used in this course is visual studio code.
If you want to use the same text editor, you can search visual studio code.
Go to the website and click download.
Once it's done, click it to install.
So the process is simple, all you need to do is follow the instructions and install the program.
After the installation is done, you can add some extensions. The extensions I use in this course
are c extensions
and x86 64 assembly syntax highlighting.
Ok the last program we need is rufus which can create a bootable usb flash drive
if you want to test the system in a real machine.
In the download section, click rufus to download it.
You can place it in the desktop here
I highly recommend using rufus to write the project into usb flash drive. Because if we don’t insert
usb flash drive to the computer, there is no options in the device list.
If we use commands to do that instead, we could write the project into the wrong device,
which could overwrite the data.
So if you have windows system, be sure to use rufus to write the project into the USB flash drive.
In the next section, we will start to build our operating system from scratch.
Let's get started.