Page 1 of 1

makefile, linking problems

Posted: Fri Jul 06, 2007 6:33 am
by spectrum
hi all,

i'm trying developing a very little real-time kernel.

A first bootstrap binary was working, until i've added another .S (gcc asm) file in the makefile.

My first boot binary start relocated at 0x7c00, and perform the protected mode switching fine.
Then, it have to jump to the firt C function called _kmain(). In this passage, the system get locked, instade of printf a little string as first line of code in _kmain.

Everything was working fine. It stopped working when i've added a second assembler file, interrupt.S, and it seems that the call to _kmain is done, but to another address. So seems a linker problem that put the objects togheter in a wrong way.

this is my makefile:

Code: Select all

CC=gcc
BINARY=boot

OSDIR=$(CURDIR)

INCDIR=-I$(OSDIR)/include \
       -I$(OSDIR)/../modules/include
SRCDIR=$(OSDIR)/src
MODDIR=$(OSDIR)/../modules/src
OBJDIR=$(OSDIR)/obj

# os sources
SRCS:=$(wildcard $(SRCDIR)/*.c)
OBJS:=$(patsubst %.c,%.o,$(SRCS))
OBJS:=$(patsubst $(SRCDIR)%,$(OBJDIR)%,$(OBJS))

# asms
ASMS:=$(wildcard $(SRCDIR)/*.S)
AOBJS:=$(patsubst %.S,%.o,$(ASMS))
AOBJS:=$(patsubst $(SRCDIR)%,$(OBJDIR)%,$(AOBJS))

# modules
MODS:=$(wildcard $(MODDIR)/*.c)
MOBJS:=$(patsubst %.c,%.o,$(MODS))
MOBJS:=$(patsubst $(MODDIR)%,$(OBJDIR)%,$(MOBJS))

$(BINARY): $(OBJS) $(MOBJS) $(AOBJS)
	ld --oformat=binary -Ttext=7c00 $(AOBJS) $(OBJS) $(MOBJS) -o $@

$(OBJDIR)/%.o: $(MODDIR)/%.c
	$(CC) $< $(INCDIR) -Wall -c -o $@

$(OBJDIR)/%.o: $(SRCDIR)/%.c
	$(CC) $< $(INCDIR) -Wall -c -o $@

$(OBJDIR)/%.o: $(SRCDIR)/%.S
	as $< -o $@

clean:
	rm -f boot
	rm -f obj/*.o

and the output:

Code: Select all


angelo@angelo:~/progetti/aos/os$  make
gcc /home/angelo/progetti/aos/os/src/aos.c -I/home/angelo/progetti/aos/os/include -I/home/angelo/progetti/aos/os/../modules/include -Wall -c -o /home/angelo/progetti/aos/os/obj/aos.o
gcc /home/angelo/progetti/aos/os/src/fs.c -I/home/angelo/progetti/aos/os/include -I/home/angelo/progetti/aos/os/../modules/include -Wall -c -o /home/angelo/progetti/aos/os/obj/fs.o
gcc /home/angelo/progetti/aos/os/src/interrupts.c -I/home/angelo/progetti/aos/os/include -I/home/angelo/progetti/aos/os/../modules/include -Wall -c -o /home/angelo/progetti/aos/os/obj/interrupts.o
gcc /home/angelo/progetti/aos/os/../modules/src/hd.c -I/home/angelo/progetti/aos/os/include -I/home/angelo/progetti/aos/os/../modules/include -Wall -c -o /home/angelo/progetti/aos/os/obj/hd.o
as /home/angelo/progetti/aos/os/src/boot.S -o /home/angelo/progetti/aos/os/obj/boot.o
as /home/angelo/progetti/aos/os/src/isr.S -o /home/angelo/progetti/aos/os/obj/isr.o
ld --oformat=binary -Ttext=7c00 /home/angelo/progetti/aos/os/obj/boot.o /home/angelo/progetti/aos/os/obj/isr.o /home/angelo/progetti/aos/os/obj/aos.o /home/angelo/progetti/aos/os/obj/fs.o /home/angelo/progetti/aos/os/obj/interrupts.o /home/angelo/progetti/aos/os/obj/hd.o -o boot
angelo@angelo:~/progetti/aos/os$    

boot.S has a regular .text section, with the _start entry point.
interrupt.S has just some isr entries, and a regular .text section. I've try also to put it as .data. Nothing change.

every help on this issue is appreciated.
infinite thanks
angelo

Posted: Thu Jul 12, 2007 7:14 am
by synthetix
Could you put the source files ? Without this information, it is very hard to know what happens. If I understood well, you're trying to implement interrupts, but your kernel freezes in the boot routine.

Without source code, I can't do much. Also, instead of using -Ttext in the linker arguments, I suggest you to create a linker script.