Problem with linking kernel
Posted: Sun Dec 07, 2003 7:28 pm
Im trying to compile my OS on Windows 2000 using Cygwin and am having problems with ld linking my kernel. I am using a makefile.
In my makefile, if I set ld told gives me this error: ld = bad reloc address 0x820 in section .data. I searched on google and on a post, it said to use the "-r" command with ld to link without relocations.
So I use the "-r" and make gives me a segmentation fault.
My ld on cygwin is set up for 'pe-i386" file format only and at the moment I am re-compiling ld to support all the file format targets. I not sure what Im doing wrong, but heres my makefile
Linker.ld
In my makefile, if I set ld to
Code: Select all
ld -T linker.ld -o $(KERNEL_NAME)
So I use the "-r" and make gives me a segmentation fault.
My ld on cygwin is set up for 'pe-i386" file format only and at the moment I am re-compiling ld to support all the file format targets. I not sure what Im doing wrong, but heres my makefile
Code: Select all
# Basic Makefile for IBOX OS, Ver.0.01, Date: 04/22/03 1:14PM
# Name of IBOX OS kernel
#KERNEL_NAME = ibox.img
KERNEL_NAME = kernel.exe
# C compiler to use
CC = gcc
CFLAGS = -c -Wall -I./include/
# Assembler to use
NASM = nasm
NASMFLAGS = -f coff
# Linker to use
LD = ld # we're using the GNU linker
#LDFLAGS = -T linker.ld -o $(KERNEL_NAME) # -T, Link with relocation
LDFLAGS = -r linker.ld -o $(KERNEL_NAME) # -r, Link without relocation
# OBJCOPY
OBJC = objcopy
OBJCFLAGS = -0 binary kernel.exe kernel.bin
OBJS = boot/stub.o kernel/kernel.o kernel/8259.o kernel/exceptions.o kernel/io.o kernel/stdio.o kernel/string.o kernel/timer.o kernel/vsprintf.o boot/handlers.o
all: $(KERNEL_NAME)
install:
# this will install the kernel on a floppy
# you may change this easily
mount /floppy/
cp $(KERNEL_NAME) /floppy/
umount /floppy/
clean:
rm $(OBJS)
# compile all assembler files
%.o : %.asm
$(NASM) $(NASMFLAGS) -o $@ $<
# compile all C files
%.o : %.c
$(CC) $(CFLAGS) -o $@ $<
# and link them all together
$(KERNEL_NAME): $(OBJS)
$(LD) $(LDFLAGS) $(OBJS)
$(OBJC) $(OBJCFLAGS)
Code: Select all
OUTPUT_FORMAT("pe-i386")
ENTRY("_start")
SECTIONS
{
/* Kernel .text section */
.text 0x100000 :
{
kernel_code = .;
*(.text)
}
/* Kernel .data section */
.data :
{
kernel_data = .;
*(.data)
}
/* Kernel .bss section */
.bss :
{
kernel_bss = .;
*(.bss)
*(.common)
}
/* Kernel .end section */
kernel_end = .;
}