quiet wrote:
Thank you for your response. But, all of the other files, libc functions, vga driver are written in C as well and compiled the way gdt.c was compiled. What's different about gdt.c?
In real mode, the return address on the stack is 16-bit wide (although you shouldn't return after switching PM), the base pointer is 16-bit wide, etc. Gdb will expect that the addresses on the stack and operands are 32-bit wide and indeed, being fragile as it is, may crash while trying to unwind the stack or perform other frame related operations (it is not very stable). Furthermore, although the 16-bit and 32-bit opcodes are somewhat compatible, the compiler may generate code which inappropriately computes stack pointer offsets, etc. To put in other words, you are deceiving the debugger and the compiler about the execution mode in which you are running. After you switch PM on, the architecture will be as expected, so all drivers and other code that runs after that point runs with the right conditions. You could coerce the debugger to recognize real mode by using "set architecture i8086", but you cannot mix architectures inside the same object file.
P.S. As I said, the boot code preceding the PM switch is usually written in assembler, and can be debugged using "set architecture i8086" if necessary.