This looks wrong and won't properly loop as you expect:
Code:
skip:
addl $4096, %esi # Increment page address by 4 KiB page size
addl $4, %edi # Increment page table address by 4B (each entry is 32 bits)
loop table_loop
end:
The problem is the `loop table_loop' line. That decrements ECX and checks if it is zero, and if zero it exits the loop. Looking at your code I think you meant 'jmp table_loop' to jump unconditionally back to label 'table_loop'. So it would look like:
Code:
skip:
addl $4096, %esi # Increment page address by 4 KiB page size
addl $4, %edi # Increment page table address by 4B (each entry is 32 bits)
jmp table_loop
end:
Most likely whatever value was in ECX was low enough that it prevented enough iterations to occur and in turn you didn't map all the pages you wanted.
Since you are running 32-bit code (no 16-bit real mode code) debugging with QEMU and GDB can help find these kinds of problems. It was how I finally noticed the issue with `loop` vs `jmp`.
You can build your assembly and C/C++ files with the `-g` option to enable debugging information. There is a bit of an issue in your `boot.s` because the debugger may not see your `.mulitboot.text` section as executable because you forgot to use the `x` section option. This line:
Code:
.section .multiboot.text, "a"
should be:
Code:
.section .multiboot.text, "ax"
.
To build you could use commands like this:
Code:
gcc -g -c -m32 -fno-pic -ffreestanding kernel.c -o kernel.o
as -g --32 boot.s -o boot.o
ld -melf_i386 -Tlinker.ld boot.o kernel.o -o kernel.elf
Then you can run QMEU and debug with GDB doing something like:
Code:
qemu-system-i386 -kernel kernel.elf -no-shutdown -no-reboot -d int -D log.txt -S -s &
gdb kernel.elf \
-ex 'target remote localhost:1234' \
-ex 'layout src' \
-ex 'layout regs' \
-ex 'break *_start' \
-ex 'continue'
Interrupt/exception info will be written to log.txt. In this case I have it stopping at label `_start` so that I could debug the code before `kernel_main`. In the QEMU window you can gain access to the monitor with control-alt-2. In the monitor you can type help for all the commands. What may be useful is to see the paging information or the TLB using the `info mem` and `info tlb` commands. To switch out of the monitor back to the virtual machine you can use control-alt-1. You can find additional information on the monitor here:
https://en.wikibooks.org/wiki/QEMU/MonitorYou can find reference material/tutorials about using GDB to debug in Google. The GDB documentation is here:
https://sourceware.org/gdb/current/onlinedocs/gdb.html/ Some of the useful commands are `ni` (next instruction); 'si' (step instruction); 'c' continue; 'b' (set breakpoints).