1
00:00:00,640 --> 00:00:07,270
In this video we will set up the environment for the OS projects in Ubuntu.  

2
00:00:07,270 --> 00:00:10,770
The tools we use in the course are gcc, nasm assembler and bochs emulator.  

3
00:00:10,780 --> 00:00:18,340
If you have not installed gcc, you can install it in the terminal, install gcc and press enter. 

4
00:00:18,520 --> 00:00:20,520
After it’s done, 

5
00:00:20,530 --> 00:00:28,510
you can check the version by the command gcc -v. As you see, the version is x86 64-bit.

6
00:00:29,640 --> 00:00:31,980
Ok the next one is nasm assembler. 

7
00:00:32,700 --> 00:00:39,010
In the boot process of the operating system, we need assembly language to do the specific tasks 

8
00:00:39,030 --> 00:00:39,840
such as mode switching.  

9
00:00:40,410 --> 00:00:44,730
So we choose nasm assembler in this course. To install nasm, 

10
00:00:44,970 --> 00:00:47,930
we install nasm and hit enter to install it. 

11
00:00:49,800 --> 00:00:57,450
After you install it, you can check it by the command nasm -v.

12
00:00:57,450 --> 00:01:00,480
Ok what we are going to do next is we are going to install bochs emulator. 

13
00:01:01,880 --> 00:01:07,060
All the projects will be tested in the emulator and then running in the real machine.

14
00:01:07,940 --> 00:01:13,640
The reason we need virtual machine is that when we put the project in the real machine, 

15
00:01:13,850 --> 00:01:17,450
the computer could reset if we have no interrupt handlers when the exception occurs. 

16
00:01:18,260 --> 00:01:23,840
Therefore, we test the project in the virtual machine and then we can run the code in the real machine. 

17
00:01:24,710 --> 00:01:30,830
Bochs emulator can report error messages if the code causes exceptions, which is very important for us to 

18
00:01:30,830 --> 00:01:32,000
debug the code. 

19
00:01:33,080 --> 00:01:41,030
OK, now let's install it. We type install bochs and press enter to finish the installation. 

20
00:01:41,030 --> 00:01:48,050
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. 

21
00:01:48,050 --> 00:01:48,940
To create the image file, 

22
00:01:48,950 --> 00:01:51,980
we use command bximage. 

23
00:01:51,980 --> 00:01:57,020
Here we want to create hard disk image, so we select option 1 and hit enter. 

24
00:01:57,740 --> 00:01:59,480
The default setting is hard disk.

25
00:01:59,690 --> 00:02:03,110
So we press enter, then we use the default settings as well.

26
00:02:03,860 --> 00:02:06,710
Sectors is set to 512 bytes. 

27
00:02:07,400 --> 00:02:11,230
The size of disk is 10 megabytes which is enough for our project. 

28
00:02:12,080 --> 00:02:18,800
As for the name of the image file, we name it boot.img and we will write the project into this image file 

29
00:02:18,800 --> 00:02:20,530
and boot the computer. 

30
00:02:21,230 --> 00:02:21,730
Alright.

31
00:02:21,740 --> 00:02:29,000
the image file is created. Notice that we have these three values which we will need to fill in the bochs configuration file later

32
00:02:29,000 --> 00:02:29,690
.

33
00:02:30,650 --> 00:02:38,210
Ok at this point we can open bochs and edit the configuration file. Because some options of the virtual environment configuration 

34
00:02:38,210 --> 00:02:40,850
is not for our os projects. 

35
00:02:41,420 --> 00:02:44,360
We select option 3 to change some settings.

36
00:02:45,140 --> 00:02:50,840
The first one is for the cpu features which is at option 6 cpuid options. 

37
00:02:52,160 --> 00:02:57,800
As you see, long mode support is enabled and what we want is the 1g page support. 

38
00:02:58,520 --> 00:03:06,020
Our memory manager requires 1g page support at its initialization stage. So we enable this feature. 

39
00:03:07,640 --> 00:03:15,200
Then we return to the options menu. The memory allocated for the virtual machine is set to 1024mb 

40
00:03:15,230 --> 00:03:16,940
which is enough for the project. 

41
00:03:17,360 --> 00:03:20,570
In the memory opitions, we select standard options 

42
00:03:21,910 --> 00:03:25,180
and we change the memory size to 1024. 

43
00:03:27,150 --> 00:03:34,320
Ok the last settings we need to change is for the boot image file. The options is 12 disk and boot options

44
00:03:34,320 --> 00:03:34,920
.

45
00:03:37,220 --> 00:03:39,140
Here we first look at Channel 0.

46
00:03:41,450 --> 00:03:45,680
You see, channel is enabled and we use the default settings here.

47
00:03:46,800 --> 00:03:51,060
Next we go to option 4 and we specify the type of device disk.  

48
00:03:52,120 --> 00:03:57,010
The file name is the name of the boot image file and press enter. 

49
00:03:59,230 --> 00:04:00,790
Also, we use the default mode.

50
00:04:03,020 --> 00:04:09,230
Remember we have seen the three numbers 20 16 and 63. They will be put into these settings.

51
00:04:11,110 --> 00:04:13,960
As for other settings, we simply leave them unchanged. 

52
00:04:18,079 --> 00:04:24,640
Ok now the boot image will be loaded as a disk device.  Then we will select this device as the one to boot first

53
00:04:24,650 --> 00:04:25,190
.

54
00:04:25,610 --> 00:04:27,830
So we change the floppy drive to disk. 

55
00:04:28,860 --> 00:04:32,190
That’s it. We return to the top menu 

56
00:04:33,410 --> 00:04:35,690
and save options to the configuration file. 

57
00:04:39,240 --> 00:04:42,510
We exit it out and see what we have in the configuration file. 

58
00:04:50,280 --> 00:04:59,430
As you can see, the memory size is 1024mb. The boot option is set to disk. The disk path is boot.img. 

59
00:04:59,450 --> 00:05:05,820
We will place this file in the folder where we build the project. 

60
00:05:05,820 --> 00:05:11,370
And bochs will start with the boot.img in the same folder.  We will delve into details when we build our first project

61
00:05:11,370 --> 00:05:12,000
.

62
00:05:13,750 --> 00:05:20,680
As for the text editor, I use visual studio code in the course. You can choose other ones you like. 

63
00:05:20,920 --> 00:05:24,610
If you choose visual studio code, you can search visual studio code, go to the website. 

64
00:05:27,340 --> 00:05:28,510
Go to the website.

65
00:05:31,960 --> 00:05:33,400
And download the package.

66
00:05:34,620 --> 00:05:37,320
I have downloaded in the download folder.

67
00:05:40,530 --> 00:05:42,630
Open it with software installer

68
00:05:46,540 --> 00:05:47,680
and click install.  

69
00:05:48,730 --> 00:05:52,210
After the installation is done, you can add some extensions.

70
00:05:56,210 --> 00:05:58,730
The extensions I use are c extensions 

71
00:06:01,410 --> 00:06:04,740
and x86 64 assembly syntax highlighting. 

72
00:06:06,040 --> 00:06:12,370
OK, right now, we have set up the environment.  In the next section we will start to build our operating system from scratch

73
00:06:12,370 --> 00:06:13,660
.

74
00:06:14,380 --> 00:06:15,620
So let's get started.

