1 00:00:01,180 --> 00:00:07,570 In this video we will set up the environment for the OS projects in windows 10. 2 00:00:07,570 --> 00:00:10,130 In this course we will build the projects under linux environment. 3 00:00:10,930 --> 00:00:15,070 So we need to enable Windows subsystem for Linux in Windows 10. 4 00:00:16,059 --> 00:00:19,330 To do that, we search windows subsystem windows 10. We click the link install windows subsystem for linux. 5 00:00:20,650 --> 00:00:23,830 We click the link install window subsystem for Linux. 6 00:00:25,250 --> 00:00:30,920 In this page, we can follow the steps to finish the installation. We first need to enable subsystem feature. 7 00:00:30,920 --> 00:00:36,830 So we copy the command and paste it in the power shell. 8 00:00:37,460 --> 00:00:42,440 In the search box we type power shell and open it as administrator. administrator. 9 00:00:44,420 --> 00:00:51,170 Ok, we paste the command here. After the operation is completed, restart the computer before we go to next step. 10 00:00:52,950 --> 00:00:58,500 At this point, we can install linux system. Here we go to step 6. 11 00:01:03,450 --> 00:01:08,550 All you need to do is open microsoft store and search ubuntu system. 12 00:01:09,670 --> 00:01:12,940 We use Ubuntu 18.04 in this course. 13 00:01:14,220 --> 00:01:19,510 In this page, you can click get to install Ubuntu. After the installation is done, 14 00:01:19,650 --> 00:01:24,690 you can open the ubuntu in the start menu or you can run the system in the search box. 15 00:01:25,680 --> 00:01:30,610 The first time you launch the system, you will need to create a user account and password. 16 00:01:31,290 --> 00:01:34,350 This is the account we will use when we build our projects. 17 00:01:35,590 --> 00:01:42,960 When you set up the user account, we can go to next step. In the ubuntu system, we need gcc and nasm 18 00:01:42,980 --> 00:01:43,990 to build the projects. 19 00:01:44,560 --> 00:01:50,440 So we install gcc and press enter. As you see, I have already installed it. 20 00:01:50,800 --> 00:01:56,170 When the installation is done, you can check the status by typing gcc -v. 21 00:01:56,710 --> 00:01:59,630 The version we use is x86 64. 22 00:02:00,520 --> 00:02:06,430 OK, the next thing we will do is install nasm assembler which is used for the assembly code. 23 00:02:07,420 --> 00:02:11,380 You can also check the version by command nasm -v. 24 00:02:12,600 --> 00:02:15,540 Ok that’s it for the setup in ubuntu system. 25 00:02:16,620 --> 00:02:22,320 Then we get to virtual machine. All the projects will be tested in the emulator and then running 26 00:02:22,320 --> 00:02:23,190 in the real machine. 27 00:02:24,000 --> 00:02:29,370 The reason we need virtual machine is that when we put the projects in the real machine, the computer could restart 28 00:02:29,370 --> 00:02:30,230 , 29 00:02:30,540 --> 00:02:36,960 if we have no interrupt handlers when the exception occurs. Therefore, we test the project in the virtual machine 30 00:02:36,990 --> 00:02:39,960 and then can run the code in the real machine if you like. 31 00:02:40,940 --> 00:02:46,940 Bochs emulator can report error messages if the code causes exceptions, 32 00:02:46,940 --> 00:02:52,700 which is very important for us to debug the code. To download it, we search bochs and go to the website. 33 00:02:56,190 --> 00:03:00,990 Click source forge project. In this page, we choose 64-bit version. 34 00:03:07,310 --> 00:03:13,700 Now you can click it to install bochs. The installation is simple, all you need to do is keep the default settings 35 00:03:13,700 --> 00:03:15,080 and install it. 36 00:03:15,770 --> 00:03:18,470 Once you are done, we create an image file. 37 00:03:22,430 --> 00:03:29,300 So in the search box, we open command prompt, in this window we navigate to desktop 38 00:03:29,300 --> 00:03:35,030 and the image will be created here. To create the image file, we use command bximage. 39 00:03:36,780 --> 00:03:44,220 If you have an error bxiamge is not recognized as a command, you can edit the path in the environment variables. 40 00:03:44,220 --> 00:03:50,040 In the search box, we type environment variables 41 00:03:52,120 --> 00:04:01,330 and edit the system environment variables. In this window, we select path and click edit 42 00:04:02,250 --> 00:04:05,280 You can add the bochs path here by clicking new 43 00:04:07,160 --> 00:04:13,250 and copy the path here. As you see, I have added the path. Once you are done, we can run this command 44 00:04:13,250 --> 00:04:13,760 . 45 00:04:17,220 --> 00:04:22,380 Here we want to create hard disk image, so we select option 1 and hit enter. 46 00:04:23,480 --> 00:04:27,350 The default setting is hard disk, we press enter. 47 00:04:28,390 --> 00:04:34,450 Sectors is set to 512 bytes. The size of disk is 10 megabytes which is enough for our project. 48 00:04:34,450 --> 00:04:40,900 We name the image file boot.img and we will write the project into this image file 49 00:04:40,900 --> 00:04:41,300 . 50 00:04:42,550 --> 00:04:44,460 OK, the image is created. 51 00:04:45,190 --> 00:04:50,650 Notice that we have these three values which we will need to fill in the bochs configuration file later. 52 00:04:53,150 --> 00:05:00,020 At this point, we can open bochs and edit the configuration file. So we type bochs and open it in the search box. 53 00:05:00,020 --> 00:05:06,920 Because some options of the virtual environment configuration is not for our os projects. 54 00:05:07,590 --> 00:05:09,060 We need to change some settings. 55 00:05:09,720 --> 00:05:15,980 The first one we change is for the cpu features which is in the cpuid option. As you see, 56 00:05:15,990 --> 00:05:19,160 long mode support is enabled 57 00:05:19,160 --> 00:05:26,930 what we want here is the 1g page support. Our memory manager requires 1g page support at its initialization stage 58 00:05:26,930 --> 00:05:27,350 . 59 00:05:27,860 --> 00:05:29,480 So we enable this feature. 60 00:05:31,020 --> 00:05:37,710 The memory allocated for the virtual machine is 1024mb which is enough for the project. 61 00:05:38,130 --> 00:05:42,600 In the memory option, we change the memory size to 1024. 62 00:05:43,620 --> 00:05:43,970 OK. 63 00:05:44,010 --> 00:05:49,320 The last settings we need to change is for the boot image file which is located in the disk and boot options 64 00:05:49,320 --> 00:05:50,130 . 65 00:05:53,230 --> 00:05:59,590 We first look at ata channel 0. You can see channel is enabled. And we use the default settings here. 66 00:05:59,590 --> 00:06:06,970 Next we specify the type of device disk. The path or physical device name is the name of the boot image file 67 00:06:06,970 --> 00:06:07,870 . 68 00:06:09,310 --> 00:06:16,210 As for the next three options, remember we have seen the three numbers 20 16 and 63. 69 00:06:16,210 --> 00:06:19,240 They will be put into these settings. 70 00:06:21,550 --> 00:06:28,300 Ok now the boot image will be loaded as a disk device. Then we will select this device as the first device to boot. 71 00:06:28,300 --> 00:06:31,510 So we change the floppy drive to disk. 72 00:06:33,150 --> 00:06:36,540 Save options to the configuration file and we are good to go. 73 00:06:37,900 --> 00:06:41,140 We exit it out and see what we have in the configuration file. 74 00:06:44,850 --> 00:06:48,630 As you can see, the memory size is 1024mb. 75 00:06:50,130 --> 00:06:57,810 The boot option is set to disk. The disk path is boot.img. 76 00:06:57,810 --> 00:07:00,400 In the following lectures, we will place this file in the folder where we build the project. 77 00:07:00,410 --> 00:07:06,990 And bochs will start with the boot.img in the same folder. We will delve into details 78 00:07:06,990 --> 00:07:08,550 when we build our first program. 79 00:07:09,590 --> 00:07:15,680 As for the text editor, you can choose what you like. The editor used in this course is visual studio code. 80 00:07:16,460 --> 00:07:20,960 If you want to use the same text editor, you can search visual studio code. 81 00:07:21,500 --> 00:07:24,260 Go to the website and click download. 82 00:07:27,490 --> 00:07:29,440 Once it's done, click it to install. 83 00:07:33,750 --> 00:07:39,270 So the process is simple, all you need to do is follow the instructions and install the program. 84 00:07:40,450 --> 00:07:46,260 After the installation is done, you can add some extensions. The extensions I use in this course 85 00:07:46,570 --> 00:07:47,770 are c extensions 86 00:07:50,580 --> 00:07:53,910 and x86 64 assembly syntax highlighting. 87 00:07:56,680 --> 00:08:03,100 Ok the last program we need is rufus which can create a bootable usb flash drive 88 00:08:03,100 --> 00:08:04,930 if you want to test the system in a real machine. 89 00:08:08,050 --> 00:08:11,190 In the download section, click rufus to download it. 90 00:08:12,880 --> 00:08:15,040 You can place it in the desktop here 91 00:08:16,190 --> 00:08:23,030 I highly recommend using rufus to write the project into usb flash drive. Because if we don’t insert 92 00:08:23,030 --> 00:08:27,050 usb flash drive to the computer, there is no options in the device list. 93 00:08:28,240 --> 00:08:34,419 If we use commands to do that instead, we could write the project into the wrong device, 94 00:08:34,419 --> 00:08:35,450 which could overwrite the data. 95 00:08:36,280 --> 00:08:42,970 So if you have windows system, be sure to use rufus to write the project into the USB flash drive. 96 00:08:43,970 --> 00:08:48,130 In the next section, we will start to build our operating system from scratch. 97 00:08:49,110 --> 00:08:50,080 Let's get started.