1 00:00:00,240 --> 00:00:07,470 Hello and welcome in this lecture, and we will check to see if the cpu support long mode. 2 00:00:07,470 --> 00:00:13,770 The modern processors should support long mode. Since checking it is really simple, we will see how to do it 3 00:00:13,770 --> 00:00:14,030 . 4 00:00:14,340 --> 00:00:18,210 Another check we need to perform is 1g page support. 5 00:00:18,750 --> 00:00:25,690 Our memory module allocates pages using this feature. So our kernel requires the processor support 1g page 6 00:00:25,720 --> 00:00:27,840 . 7 00:00:29,220 --> 00:00:34,150 The first thing we are going to do is we are going to save the drive id for later use. 8 00:00:34,710 --> 00:00:39,930 Remember we have saved the drive id in dl register before we jump to the loader. 9 00:00:40,440 --> 00:00:42,300 we define the variable 10 00:00:44,040 --> 00:00:44,910 drive id 11 00:00:49,680 --> 00:00:51,750 Just like we did in the boot file 12 00:00:55,220 --> 00:00:58,880 and save the value of dl to the variable. 13 00:01:04,810 --> 00:01:06,470 Ok let’s check long mode. 14 00:01:07,090 --> 00:01:10,420 There is a special instruction called cpuid 15 00:01:12,410 --> 00:01:18,410 which returns processor identification and feature information. We pass the input value 16 00:01:22,060 --> 00:01:25,870 80000001 to eax 17 00:01:29,940 --> 00:01:37,860 and execute cpuid. By passing different number to eax, we will get different information about processor returned by cpuid. 18 00:01:37,860 --> 00:01:44,790 Passing 80000001 to eax will return processor features. 19 00:01:45,360 --> 00:01:48,330 The information about long mode support is saved in edx. 20 00:01:48,660 --> 00:01:52,920 We test bit 29 in edx. 21 00:01:53,940 --> 00:01:57,360 If it is set, it means that long mode is supported. 22 00:01:57,810 --> 00:02:02,130 Otherwise long mode is not available and we jump to the label not support. 23 00:02:04,390 --> 00:02:07,480 So we use test instruction to test. 24 00:02:08,919 --> 00:02:11,700 the bit 29 in edx 25 00:02:13,760 --> 00:02:15,440 We use jz instruction. 26 00:02:16,680 --> 00:02:23,550 If zero flag is set, it means that the bit we checked is not set and we jump to not support. 27 00:02:27,810 --> 00:02:35,360 Also, we check 1g page support which is at bit 26, so we test edx 28 00:02:37,930 --> 00:02:39,640 and the bit 26. 29 00:02:43,790 --> 00:02:46,470 If it is set, this feature is supported. 30 00:02:47,180 --> 00:02:53,990 If zero flag is set, it means that this feature is not supported and we jump to not support. 31 00:02:56,320 --> 00:03:02,380 There is one thing left to do. Before we use value 80000001, 32 00:03:03,270 --> 00:03:09,480 we need to check whether it supports this input value. In order to check that, we pass value 33 00:03:14,040 --> 00:03:17,680 80000000 to eax 34 00:03:18,560 --> 00:03:24,150 and execute cpuid instruction. If the return value in eax 35 00:03:27,670 --> 00:03:28,660 is less than 36 00:03:30,780 --> 00:03:36,870 80000001, we know that it does not support input value 37 00:03:38,290 --> 00:03:45,370 So we use jb instruction, which means jump if below and we simply jump to not support. 38 00:03:49,190 --> 00:03:56,600 Because our operating system is designed for running on long mode, we place not support at the end of the code 39 00:03:56,600 --> 00:03:57,080 , 40 00:04:02,520 --> 00:04:09,530 and stop here if the processor does not support it. Otherwise, we print message long mode is supported. 41 00:04:10,650 --> 00:04:12,350 so we change the message 42 00:04:13,960 --> 00:04:15,700 to long mode is supported. 43 00:04:20,050 --> 00:04:24,040 OK, let's build the project and test it out in virtual machine. 44 00:04:30,330 --> 00:04:31,680 We open the terminal. 45 00:04:36,800 --> 00:04:39,050 and to navigate to the boot folder. 46 00:04:44,640 --> 00:04:46,050 and run the build script. 47 00:04:47,370 --> 00:04:51,060 OK, let's open the bochs, we double click it. 48 00:04:54,450 --> 00:04:58,920 As you see long mode is supported is printed on screen? 49 00:05:03,020 --> 00:05:05,870 OK, this is what it's showing in real machine. 50 00:05:07,440 --> 00:05:08,850 That's it for this lecture. 51 00:05:09,030 --> 00:05:10,350 See you in the next video.