Hello, in this lecture we will test a20 line. The a20 line was introduced from old machine.
Back in the day when machines had 20-bit address, we can address memory of 2 to the power of 20 which is 1mb.
Later machines come with address bus wider than 20 bits. For compatibility purposes,
a20 line of the address bus is off.
So when the address is higher than 1mb,
the address will get truncated as if it starts from 0 again.
Our system runs on the 64-bit processor which has address wider than 20 bits.
If we try to access memory with a20 line disabled, we will end up only accessing even megabytes,
because a20 line is 0
and any address we are gonna access is actually the address with bit 20 cleared.
Therefore we need to toggle a20 line to access all the memory.
There are different ways to activate a20 line and each method is not guaranteed to be working across all the different machines
.
But newer machines seem to have a20 line enabled by default. To make our project simple,
we assume our machines enabled a20 line.
What we are gonna do here is we are going to test to see if a20 line is already enabled.
If enabled, we print message a20 line is on.
Otherwise, we stop and leave blank on the screen.
If you find your computer doesn't enable a20 line by default ,
please leave message to let me know.
OK, The logic for testing a20 line in our project is simple. If a20 line is not enabled, when we try to access address,
for example, 107c00. If we look at the value in binary format, you can see bit 20 is 1
.
Suppose if a20 line is off, then bit 20 will be 0.
So the address we referenced in this case is actually 7c00.
In the project, we are going to use this method to do the test.
The reason we choose this address is that 7c00 is the start address of the boot code.
Remember our boot code is loaded at 7c00. Since the boot code has done its work,
we reuse that memory area to do the test.
OK, let's get started.
We defined label test a20.
In order to access memory 107c00, we move ax, f,f,f,f
and copy it to es register.
Next we write a random value, for example, a200 to address 7c00.
The segment register we use here is ds register
which has been set to 0 by us.
So the logical address now points to 7c00. This instruction will copy a200
at the memory 7c00.
.Then we are gonna compare the content at address 107c00 with a200.
So the segment register we use is es register
.
The logical address is es, 7c10. The physical address it points to is 107c00
which is the address we want.
If the content at address 107c00 is not equal to a200, we know that we have accessed
the memory address 107c00 successfully
and we jump to set a20 line done.
We define label set a20 line done
and copy the code for printing the message.
the message we want to print
is a20 line is on.
If the content at address 107c00 is equal to a200, it means there is high chance that
the address 107c00 gets truncated to 7c00,
we actually access the same memory location. But, maybe the content at 107c00
happens to be the same value a200.
.
So we do the second test.
Here I’m gonna write a random value, for example, b200 to 7c00
and then compare the content at 107c00 with B200.
If they are still the same, it means that a20 line is not enabled and we jump to the end.
So here we use the instruction j,e, jump if equal.
If they are not equal, it means that a20 line is enabled and we print a20 line is on
.
And don’t forget to change back es register to 0.
So we zero ax and copy the value of ax to es segment register.
OK, we save the file and build the project in the terminal.
OK.
Let's run bochs.
a20 line is on is printed on the screen.
Here is test on my computer, a20 line is enabled by default.
All right, that's it.
See you in the next video.