1 00:00:00,950 --> 00:00:08,900 Hello, in this lecture we will test a20 line. The a20 line was introduced from old machine. 2 00:00:08,900 --> 00:00:15,320 Back in the day when machines had 20-bit address, we can address memory of 2 to the power of 20 which is 1mb. 3 00:00:15,320 --> 00:00:24,020 Later machines come with address bus wider than 20 bits. For compatibility purposes, 4 00:00:24,760 --> 00:00:26,870 a20 line of the address bus is off. 5 00:00:27,590 --> 00:00:30,230 So when the address is higher than 1mb, 6 00:00:30,770 --> 00:00:34,500 the address will get truncated as if it starts from 0 again. 7 00:00:35,000 --> 00:00:40,730 Our system runs on the 64-bit processor which has address wider than 20 bits. 8 00:00:41,480 --> 00:00:49,330 If we try to access memory with a20 line disabled, we will end up only accessing even megabytes, 9 00:00:49,430 --> 00:00:50,870 because a20 line is 0 10 00:00:51,480 --> 00:00:56,830 and any address we are gonna access is actually the address with bit 20 cleared. 11 00:00:57,680 --> 00:01:01,850 Therefore we need to toggle a20 line to access all the memory. 12 00:01:02,910 --> 00:01:09,410 There are different ways to activate a20 line and each method is not guaranteed to be working across all the different machines 13 00:01:09,420 --> 00:01:10,740 . 14 00:01:11,650 --> 00:01:19,570 But newer machines seem to have a20 line enabled by default. To make our project simple, 15 00:01:19,570 --> 00:01:21,660 we assume our machines enabled a20 line. 16 00:01:22,420 --> 00:01:27,670 What we are gonna do here is we are going to test to see if a20 line is already enabled. 17 00:01:28,420 --> 00:01:31,600 If enabled, we print message a20 line is on. 18 00:01:32,200 --> 00:01:34,930 Otherwise, we stop and leave blank on the screen. 19 00:01:35,740 --> 00:01:39,230 If you find your computer doesn't enable a20 line by default , 20 00:01:40,000 --> 00:01:41,660 please leave message to let me know. 21 00:01:43,700 --> 00:01:52,370 OK, The logic for testing a20 line in our project is simple. If a20 line is not enabled, when we try to access address, 22 00:01:52,370 --> 00:02:00,590 for example, 107c00. If we look at the value in binary format, you can see bit 20 is 1 23 00:02:00,590 --> 00:02:01,490 . 24 00:02:02,360 --> 00:02:06,660 Suppose if a20 line is off, then bit 20 will be 0. 25 00:02:07,370 --> 00:02:11,870 So the address we referenced in this case is actually 7c00. 26 00:02:13,070 --> 00:02:16,490 In the project, we are going to use this method to do the test. 27 00:02:17,610 --> 00:02:23,310 The reason we choose this address is that 7c00 is the start address of the boot code. 28 00:02:24,030 --> 00:02:29,610 Remember our boot code is loaded at 7c00. Since the boot code has done its work, 29 00:02:29,970 --> 00:02:32,600 we reuse that memory area to do the test. 30 00:02:33,530 --> 00:02:34,900 OK, let's get started. 31 00:02:42,990 --> 00:02:45,000 We defined label test a20. 32 00:02:46,280 --> 00:02:52,090 In order to access memory 107c00, we move ax, f,f,f,f 33 00:02:53,980 --> 00:02:58,450 and copy it to es register. 34 00:03:03,070 --> 00:03:09,880 Next we write a random value, for example, a200 to address 7c00. 35 00:03:13,050 --> 00:03:16,140 The segment register we use here is ds register 36 00:03:17,060 --> 00:03:19,130 which has been set to 0 by us. 37 00:03:23,470 --> 00:03:31,020 So the logical address now points to 7c00. This instruction will copy a200 38 00:03:31,030 --> 00:03:32,740 at the memory 7c00. 39 00:03:33,780 --> 00:03:39,480 .Then we are gonna compare the content at address 107c00 with a200. 40 00:03:42,800 --> 00:03:46,100 So the segment register we use is es register 41 00:03:46,120 --> 00:03:47,060 . 42 00:03:52,090 --> 00:04:02,420 The logical address is es, 7c10. The physical address it points to is 107c00 43 00:04:02,440 --> 00:04:04,930 which is the address we want. 44 00:04:05,970 --> 00:04:13,140 If the content at address 107c00 is not equal to a200, we know that we have accessed 45 00:04:13,140 --> 00:04:17,480 the memory address 107c00 successfully 46 00:04:18,300 --> 00:04:21,000 and we jump to set a20 line done. 47 00:04:24,760 --> 00:04:28,050 We define label set a20 line done 48 00:04:30,760 --> 00:04:32,650 and copy the code for printing the message. 49 00:04:36,530 --> 00:04:38,090 the message we want to print 50 00:04:40,830 --> 00:04:43,530 is a20 line is on. 51 00:04:46,420 --> 00:04:53,650 If the content at address 107c00 is equal to a200, it means there is high chance that 52 00:04:53,650 --> 00:04:59,610 the address 107c00 gets truncated to 7c00, 53 00:05:00,220 --> 00:05:08,020 we actually access the same memory location. But, maybe the content at 107c00 54 00:05:08,020 --> 00:05:09,250 happens to be the same value a200. 55 00:05:09,370 --> 00:05:10,430 . 56 00:05:11,080 --> 00:05:13,960 So we do the second test. 57 00:05:13,960 --> 00:05:18,610 Here I’m gonna write a random value, for example, b200 to 7c00 58 00:05:24,270 --> 00:05:27,870 and then compare the content at 107c00 with B200. 59 00:05:34,730 --> 00:05:40,250 If they are still the same, it means that a20 line is not enabled and we jump to the end. 60 00:05:41,720 --> 00:05:45,890 So here we use the instruction j,e, jump if equal. 61 00:05:47,130 --> 00:05:52,950 If they are not equal, it means that a20 line is enabled and we print a20 line is on 62 00:05:52,950 --> 00:05:53,190 . 63 00:05:54,080 --> 00:05:58,250 And don’t forget to change back es register to 0. 64 00:06:01,240 --> 00:06:07,170 So we zero ax and copy the value of ax to es segment register. 65 00:06:08,900 --> 00:06:12,560 OK, we save the file and build the project in the terminal. 66 00:06:16,040 --> 00:06:16,460 OK. 67 00:06:18,720 --> 00:06:20,130 Let's run bochs. 68 00:06:24,410 --> 00:06:28,700 a20 line is on is printed on the screen. 69 00:06:30,630 --> 00:06:35,700 Here is test on my computer, a20 line is enabled by default. 70 00:06:36,390 --> 00:06:37,560 All right, that's it. 71 00:06:37,620 --> 00:06:39,030 See you in the next video.