A few weeks ago I started to build a small OS with C for x86. Some basic stuff (gdt set up, paging, interrupts, printing something to screen,...) seems to work fine now, but since a few days I have a problem with debugging my kernel. It's a little bit strange that it worked before, but however, perhaps I'm missing something

Now to my problem:
It seems that as soon as I link the text of the kernel above 0xC0000000 gdb does ignore the breakpoints I set. That means I can set the breakpoint, gdb stores it with the correct address, but it does not break.
My linker script is:
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(loader)
SECTIONS
{
. = 0x100000;
.setup :
{
*(.setup)
}
. += 0xC0000000;
.text : AT(ADDR(.text) - 0xC0000000)
{
*(.text)
}
.data ALIGN (4096) : AT(ADDR(.data) - 0xC0000000)
{
*(.data)
*(.rodata*)
}
.bss ALIGN (4096) : AT(ADDR(.bss) - 0xC0000000)
{
*(COMMON*)
*(.bss*)
}
}
Code: Select all
[BITS 32] ; 32 bit code
[extern main]
; Multiboot constants
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
; Multiboot header (needed to boot from GRUB)
ALIGN 4
KernelStart:
multiboot_header:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
; the kernel entry point
loader:
; here is the trick: we load a GDT with a base address
; of 0x40000000 for the code (0x08) and data (0x10) segments
lgdt [setupGDT]
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
; jump to the higher half kernel
jmp 0x08:higherhalf
higherhalf:
; from now the CPU will translate automatically every address
; by adding the base 0x40000000
mov esp, sys_stack ; set up a new stack for our kernel
push eax ; push Multiboot Magicnumber onto the stack
push ebx ; push address of Multiboot-Structure
call main ; jump to our C kernel ;)
; just a simple protection...
jmp $
[section .setup]
; our GDT for the setup-process
setupGDT:
; GDT size
dw setupGDTEntries - setupGDTEntriesEnd - 1
; Pointer to entries
dd setupGDTEntries
; the GDT-entries
setupGDTEntries:
; null gate
dd 0,0
; code selector 0x08: base 0x40000000, limit 0xFFFFFFFF, type 0x9A, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 10011010b, 11001111b, 0x40
; data selector 0x10: base 0x40000000, limit 0xFFFFFFFF, type 0x92, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 10010010b, 11001111b, 0x40
setupGDTEntriesEnd:
[section .bss]
resb 0x1000
sys_stack:
; our kernel stack
I compile and link the kernel with:
Code: Select all
nasm -g -f elf -o ../build/kernel_asm.o src/kernel.asm
gcc -g -O2 -fno-inline -ffreestanding -Wall -ansi -nostdlib -nostartfiles -nodefaultlibs -o ../build/kernel.o -c src/kernel.c
ld -T src/ld.conf -o ../build/kernel.bin ../build/kernel_asm.o ../build/kernel.o
Code: Select all
qemu -serial stdio -s -S -no-kqemu -fda build/disk.img > log.txt 2>&1 &
sleep 0.5
gdb --symbols build/kernel.bin
Code: Select all
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x0000fff0 in ?? ()
(gdb) b main
Breakpoint 1 at 0xc0100060: file src/kernel.c, line 10.
(gdb) c
Continuing.
I've searched quite a long time to find a solution and tried many things but without success

Does anybody know what I'm doing wrong or what I can do to solve the problem?
Thanks in advance!
hrniels