1 00:00:00,670 --> 00:00:07,660 Hi, in this lecture. We will add some new stuff in the boot file. As you see, this is our boot file 2 00:00:07,660 --> 00:00:09,910 we just write in the last video. 3 00:00:10,750 --> 00:00:17,080 What we are going to do first is we are going to test disk extension service. 4 00:00:17,080 --> 00:00:21,270 Because we need to load our kernel from disk to the memory and jump to the kernel. 5 00:00:21,850 --> 00:00:28,000 We know that we use BIOS disk services to load our file from disk in boot process. 6 00:00:28,930 --> 00:00:35,350 When we read file from disk, we should provide CHS value in order to locate the sector we want to read. 7 00:00:35,350 --> 00:00:40,390 And using chs value requires extra calculation. 8 00:00:40,870 --> 00:00:47,500 To make our boot file simple, we choose logical block address which disk extension service 9 00:00:47,500 --> 00:00:48,730 use to access the disk. 10 00:00:49,600 --> 00:00:54,850 Modern computers should support the extension service, but we will check it anyway. 11 00:00:55,390 --> 00:00:57,560 To check for this service is really simple. 12 00:00:57,760 --> 00:01:00,070 First off, we define a label 13 00:01:02,870 --> 00:01:03,650 called test. 14 00:01:04,700 --> 00:01:05,780 disk extension. 15 00:01:11,440 --> 00:01:13,840 The parameters we should pass includes 16 00:01:15,430 --> 00:01:18,770 save 41 in register ah, 17 00:01:21,720 --> 00:01:25,530 55AA in bx. 18 00:01:29,690 --> 00:01:36,690 Also note that dl holds the drive id when BIOS transfers control to our boot code. 19 00:01:36,720 --> 00:01:42,480 Since we will call disk service more than once later in the boot process, and we need to pass the drive id 20 00:01:42,480 --> 00:01:47,130 to dl register before we call the disk service like we do here. 21 00:01:47,880 --> 00:01:52,410 So we define a variable called driveid 22 00:02:01,140 --> 00:02:04,860 And save the value of dl to variable driveid 23 00:02:13,120 --> 00:02:18,640 Because we want to write the value into the memory location the driveid represents 24 00:02:19,090 --> 00:02:23,350 So here we use square brackets to access the location. 25 00:02:25,370 --> 00:02:27,080 Then we can call interrupt 13 26 00:02:29,940 --> 00:02:30,480 . 27 00:02:31,960 --> 00:02:39,520 If the services is not supported, the carry flag is set. So we use jc instruction 28 00:02:39,520 --> 00:02:44,370 which will jump to label not support if carry flag is set. 29 00:02:45,640 --> 00:02:52,270 Let’s define the label not support. We simply place the label at the end of our code. 30 00:02:54,930 --> 00:03:00,780 The label end and not support represent the same address which is the address of hlt instruction. 31 00:03:02,060 --> 00:03:07,640 So if it is not supported, we just jump to the end and end our program. 32 00:03:09,490 --> 00:03:10,930 If it passed the test, 33 00:03:13,360 --> 00:03:18,490 we compare bx with the value AA55. 34 00:03:20,840 --> 00:03:26,990 If bx is not equal to AA55, it means that extension service is not supported. 35 00:03:27,530 --> 00:03:30,740 Similarly, we jump to not support. 36 00:03:30,740 --> 00:03:33,110 We use jne instruction. 37 00:03:34,170 --> 00:03:36,210 which is jump, if not equal. 38 00:03:39,100 --> 00:03:45,310 Before we build our project, there is another change we need to do. When our computer support the extension service, 39 00:03:45,310 --> 00:03:50,200 what we want to do is print extension support message on the screen. 40 00:03:50,590 --> 00:03:52,390 So we change the message 41 00:03:55,690 --> 00:04:00,250 to disk extension is supported. 42 00:04:02,340 --> 00:04:08,430 By the way, there is no need to change the message length because $ represents the end of string 43 00:04:08,430 --> 00:04:12,410 in this case and the message represents the start of the string. 44 00:04:12,930 --> 00:04:16,649 So the message length is automatically adjusted to the correct value. 45 00:04:18,070 --> 00:04:19,839 OK, let's build our project. 46 00:04:23,970 --> 00:04:27,120 We open the terminal and run the built script. 47 00:04:29,990 --> 00:04:35,120 The binary file is written into the image file. Now we can open the bochs 48 00:04:37,550 --> 00:04:38,600 by double clicking it. 49 00:04:40,140 --> 00:04:45,810 If everything goes as expected, we will see disk extension is supported on screen. 50 00:04:49,470 --> 00:04:56,010 Here is a test on the real machine which supports the service, don't forget to write the boot image to 51 00:04:56,010 --> 00:04:58,680 USB flash drive before you boot the computer. 52 00:04:59,670 --> 00:05:05,670 If there is no message showing up on your real machine, you can run the programs on virtual machine 53 00:05:05,760 --> 00:05:09,030 bochs should support the extension service. 54 00:05:09,690 --> 00:05:12,990 In the next video, we will load another file called loader file 55 00:05:13,170 --> 00:05:14,640 See you in the next lecture.