1 00:00:00,660 --> 00:00:07,200 In this video we will set up the environment for the OS projects in Mac OS. 2 00:00:07,320 --> 00:00:12,470 The tools we need in the course are cross compiler, nasm assembler and bochs emulator. 3 00:00:13,050 --> 00:00:16,170 As you see, this is the download link of the cross compiler. 4 00:00:16,770 --> 00:00:22,620 The version of the compiler is gcc 4.8.1 x86-64. 5 00:00:23,140 --> 00:00:26,270 The link is added to the external source of this lecture. 6 00:00:26,730 --> 00:00:28,710 You can download it using this link. 7 00:00:29,730 --> 00:00:31,620 After the package is downloaded. 8 00:00:34,680 --> 00:00:35,550 double click it 9 00:00:38,280 --> 00:00:44,940 and you see the name of the package is gcc 4.8.1 linux x64. 10 00:00:45,960 --> 00:00:49,490 Once we check the package is the correct one, we can install it. 11 00:00:50,750 --> 00:00:57,140 When the first time we run it, we could have this warning message. In order to open it, we go to system preference panel 12 00:00:57,140 --> 00:00:58,340 , 13 00:00:59,710 --> 00:01:01,360 security and privacy 14 00:01:02,640 --> 00:01:04,349 and click open anyway. 15 00:01:07,500 --> 00:01:11,400 Ok now we can install the compiler. Click continue, 16 00:01:14,220 --> 00:01:21,150 agree and then we get to the installation part. Click install and we are done. 17 00:01:21,150 --> 00:01:24,020 Since it’s installed in my machine, I just exit out. 18 00:01:25,430 --> 00:01:34,130 After the installation is done, we can check the status in the terminal. 19 00:01:34,130 --> 00:01:39,140 The path is usr local and the gcc we just installed. The command is located in the bin folder. 20 00:01:40,170 --> 00:01:43,690 As you can see, they are the commands we will use when we build the project. 21 00:01:44,550 --> 00:01:48,660 OK, what we are going to do next is we are going to install bochs emulator. 22 00:01:49,110 --> 00:01:53,980 All the projects will be tested in the emulator and then running in the real machine. 23 00:01:54,660 --> 00:02:00,240 The reason we need virtual machine is that when we put the project in the real machine, 24 00:02:00,240 --> 00:02:04,570 the computer could restart if we have no interrupt handlers when the exception occurs. 25 00:02:05,250 --> 00:02:10,259 Therefore, we tested the project in the virtual machine and then run the code in the real machine, 26 00:02:10,259 --> 00:02:10,919 if you like. 27 00:02:11,930 --> 00:02:18,170 And also, Bochs emulator can report error messages if the code causes exceptions, 28 00:02:18,170 --> 00:02:20,150 which is especially important for us to debug the code. 29 00:02:21,180 --> 00:02:27,750 To install it, we type brew install bochs and press enter to finish the installation. 30 00:02:28,830 --> 00:02:34,010 I have already installed the bochs, so I don’t run this command. 31 00:02:34,080 --> 00:02:41,190 After you install it, you can check the status by typing bochs and press enter. You can see we have several options here. 32 00:02:41,730 --> 00:02:43,320 We will discuss it in a minute. 33 00:02:43,890 --> 00:02:46,850 Right now, we just choose seven and close it out. 34 00:02:47,700 --> 00:02:52,230 The next thing we are going to do is we are going to create an image file 35 00:02:52,320 --> 00:02:54,660 since bochs will boot our projects with the image file. 36 00:02:55,500 --> 00:03:02,060 First off, we navigate to desktop and the image will be created here. 37 00:03:02,070 --> 00:03:06,060 To create the image file, we use command bximage. 38 00:03:06,070 --> 00:03:08,070 We want to create hard disk image. 39 00:03:08,310 --> 00:03:10,800 so we select option 1 and hit enter. 40 00:03:12,100 --> 00:03:18,940 The default setting is hard disk, we press enter. Then we use the default settings as well. 41 00:03:18,940 --> 00:03:25,570 Sectors is set to 512 bytes. The size of disk is 10 megabytes which is enough for our project. 42 00:03:26,830 --> 00:03:33,550 We name the image file boot.img and we will write the project into this image file and boot the computer. 43 00:03:34,030 --> 00:03:41,410 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 44 00:03:41,410 --> 00:03:44,050 OK 45 00:03:44,050 --> 00:03:47,650 at this point we can open bochs and edit the configuration file. 46 00:03:48,930 --> 00:03:55,230 Because some options of the virtual environment configuration is not for our os projects. 47 00:03:55,230 --> 00:03:57,120 We select option 3 to change some settings. 48 00:03:57,690 --> 00:04:04,500 The first one we change is for the cpu features which is at option 6 cpuid options. 49 00:04:05,160 --> 00:04:11,460 As you see, long mode support is enable and what we want is the 1g page support. 50 00:04:12,150 --> 00:04:19,170 Our memory manager requires one gigabyte page support at the initialization stage, so we enable this 51 00:04:19,170 --> 00:04:19,680 feature. 52 00:04:20,579 --> 00:04:22,380 Then we return to the options menu. 53 00:04:23,400 --> 00:04:30,870 The memory allocated for the virtual machine is 1024 megabytes, which is enough for the product. 54 00:04:30,870 --> 00:04:36,870 In the memory options, we select standard options and we change the memory size to 1024. 55 00:04:40,390 --> 00:04:47,180 Ok the last settings we need to change is for the boot image file. The option is 12 disk and boot options 56 00:04:47,200 --> 00:04:47,950 . 57 00:04:49,840 --> 00:04:51,420 we first look at channel 0. 58 00:04:52,850 --> 00:04:56,540 You can see channel is enabled. And we use the default settings here. 59 00:04:58,170 --> 00:04:59,610 Next we go to option 4 60 00:05:01,500 --> 00:05:09,210 and we specify the type of device disk. The file name is the name of the boot image file and press enter. 61 00:05:09,210 --> 00:05:12,200 We use the default mode. 62 00:05:13,230 --> 00:05:18,180 Remember we have seen the three numbers 20 16 and 63. 63 00:05:22,740 --> 00:05:26,460 Here. They will be put into these settings. 64 00:05:33,950 --> 00:05:36,890 As for other settings, we simply leave them unchanged. 65 00:05:39,490 --> 00:05:42,760 Ok now the boot image will be loaded as a disk device. 66 00:05:43,850 --> 00:05:50,950 Then we will select this device as the one booted first. So we change the floppy drive to disk. 67 00:05:50,960 --> 00:05:51,230 That's it. 68 00:05:52,840 --> 00:05:54,490 We return to the top menu 69 00:05:55,650 --> 00:05:58,170 and save options to the configuration file. 70 00:06:00,510 --> 00:06:03,630 We exit it out and see what we have in the configuration file. 71 00:06:09,830 --> 00:06:18,560 As you can see, the memory size is 1024mb. The boot option is set to disk. The disk path is boot.img. 72 00:06:18,560 --> 00:06:25,670 We will place this file in the folder where we build the project. 73 00:06:25,670 --> 00:06:32,750 And bochs will starts with the boot.img in the same folder. We will delve into details when we build our first program. 74 00:06:33,950 --> 00:06:40,760 Another thing I need to mention is that since the gcc is installed in the customized path, 75 00:06:40,760 --> 00:06:42,190 we need to run the command with full path. 76 00:06:42,620 --> 00:06:45,770 You can check lecture how to use the resources in this section. 77 00:06:46,800 --> 00:06:53,950 Ok the next tool is nasm assembler, in the boot process of the operating system, 78 00:06:53,950 --> 00:06:55,350 the assembly language is the only language we can use. 79 00:06:55,860 --> 00:06:58,320 So we choose nasm assembler in this course. 80 00:06:59,740 --> 00:07:07,420 To install nasm, we type brew install nasm and hit enter to install it. After you are done, 81 00:07:07,420 --> 00:07:07,710 you can check it 82 00:07:07,720 --> 00:07:09,670 by the command nasm -v. 83 00:07:12,410 --> 00:07:18,200 As for the text editor, I use visual studio code in the course. You can choose other ones you like. 84 00:07:18,800 --> 00:07:24,640 If you choose visual studio code, I have added the link in the external source of the lecture. 85 00:07:24,950 --> 00:07:26,870 You can download it using this link. 86 00:07:27,680 --> 00:07:30,380 When you install it, you can add some extensions. 87 00:07:36,160 --> 00:07:39,910 The extensions I use are c extensions 88 00:07:42,230 --> 00:07:48,890 and x86 64 assembly syntax highlighting. Ok right now we have set up the environment. 89 00:07:49,700 --> 00:07:53,840 in the next section, we will start to build our operating system from scratch. 90 00:07:54,650 --> 00:07:55,650 Let's get started.