2024-12-20 22:45:12 +00:00
|
|
|
RM= rm
|
|
|
|
CC= $(CONFIG_TARGET_CC)
|
|
|
|
AS= $(CONFIG_TARGET_CC)
|
|
|
|
# NOTE(dinosaure): we must use [aarch64-none-elf-gcc] to compile assembly code
|
|
|
|
# to be able to include some files and define some macros.
|
|
|
|
LD= $(CONFIG_TARGET_LD)
|
|
|
|
AR= aarch64-none-elf-ar # TODO
|
|
|
|
OBJDUMP= aarch64-none-elf-objdump # TODO
|
|
|
|
OBJCOPY= $(CONFIG_TARGET_OBJCOPY)
|
|
|
|
|
|
|
|
export TOPDIR := $(abspath .)
|
|
|
|
|
|
|
|
$(TOPDIR)/Makeconf:
|
|
|
|
$(error Makeconf not found, please run ./configure.sh)
|
|
|
|
|
|
|
|
include $(TOPDIR)/Makeconf
|
|
|
|
|
|
|
|
# armstub8.bin: armstub8.S
|
|
|
|
# @echo "CC -DGIC=1 $<"
|
|
|
|
# @$(CC) -DGIC=1 -o ${<:S=o} -c $<
|
|
|
|
# @echo "LD --section-start=.text=0 ${<:S=o}"
|
|
|
|
# @$(LD) --section-start=.text=0 -o ${<:S=elf} ${<:S=o}
|
|
|
|
# @echo "DUMP ${<:S=elf}"
|
|
|
|
# @$(OBJDUMP) -D ${<:S=elf} > ${<:S=lst}
|
|
|
|
# @echo "COPY ${<:S=elf}"
|
|
|
|
# @$(OBJCOPY) ${<:S=elf} -O binary $@
|
|
|
|
|
|
|
|
include/$(CONFIG_TARGET_TRIPLE):
|
|
|
|
@echo "GEN $@"
|
|
|
|
@./gen-headers.sh $@
|
|
|
|
|
|
|
|
CPU ?= -mcpu=cortex-a76 -mlittle-endian
|
|
|
|
ARCH += -DAARCH=64 $(CPU)
|
|
|
|
TARGET ?= kernel_2712
|
|
|
|
|
|
|
|
DEFINE += -DSSP_GUARD_SYMBOL=__stack_chk_guard \
|
|
|
|
-DSSP_FAIL_SYMBOL=__stack_chk_fail
|
|
|
|
|
|
|
|
INCLUDE += -I $(TOPDIR)/include -I $(TOPDIR)/include/$(CONFIG_TARGET_TRIPLE) \
|
|
|
|
-I $(TOPDIR)/nolibc/include
|
|
|
|
|
|
|
|
AFLAGS += $(ARCH) $(DEFINE) $(INCLUDE)
|
|
|
|
|
|
|
|
CFLAGS += -std=c11 -ffreestanding -fstack-protector-strong -nostdlib \
|
|
|
|
-nostartfiles -mstrict-align -Wall \
|
|
|
|
$(ARCH) $(DEFINE) $(INCLUDE) $(CONFIG_TARGET_CC_CFLAGS)
|
|
|
|
|
|
|
|
LDFLAGS += -nostdlib -static -Wl,--no-warn-rwx-segments \
|
|
|
|
-Wl,--section-start=.init=0x80000 -Wl,--build-id=none \
|
|
|
|
-Wl,--start-group -L . -lgilbraltar -L nolibc -lnolibc -L openlibm -lopenlibm -lgcc -Wl,--end-group
|
|
|
|
|
|
|
|
SRCS= kernel.c timer.c led.c interrupt_handler.c exception_handler.c \
|
2024-12-23 00:46:17 +00:00
|
|
|
mbox.c clock.c crt.c serial.c log.c power.c tag.c coherent_page.c dtb.c \
|
|
|
|
synchronize.c spinlock.c memory.c pager.c translation_table.c
|
2024-12-20 22:45:12 +00:00
|
|
|
|
|
|
|
ASMS= startup.S exception_stub.S
|
|
|
|
|
|
|
|
OBJS= $(SRCS:c=o) $(ASMS:S=o)
|
|
|
|
|
|
|
|
%.o: %.S
|
|
|
|
@echo "AS $@"
|
|
|
|
@$(AS) $(AFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
%.o: %.c include/$(CONFIG_TARGET_TRIPLE)
|
|
|
|
@echo "CC $@"
|
|
|
|
@$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
libgilbraltar.a: $(OBJS)
|
|
|
|
@echo "AR $@"
|
|
|
|
@rm -f $@
|
|
|
|
@$(AR) cr $@ $^
|
|
|
|
|
|
|
|
.PHONY: phony-openlibm
|
|
|
|
phony-openlibm: include/$(CONFIG_TARGET_TRIPLE)
|
|
|
|
@$(MAKE) -C openlibm \
|
|
|
|
"CC=$(CC)" "CPPFLAGS=$(CFLAGS)" libopenlibm.a
|
|
|
|
|
|
|
|
openlibm/libopenlibm.a: phony-openlibm
|
|
|
|
|
|
|
|
NOLIBC_CFLAGS= $(CFLAGS) -I $(TOPDIR)/nolibc/include -I $(TOPDIR)/openlibm/src -I $(TOPDIR)/openlibm/include
|
|
|
|
|
|
|
|
.PHONY: phony-nolibc
|
|
|
|
phony-nolibc: include/$(CONFIG_TARGET_TRIPLE)
|
|
|
|
$(MAKE) -C nolibc libnolibc.a \
|
|
|
|
"CC=$(CC)" "FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)"
|
|
|
|
|
|
|
|
nolibc/libnolibc.a: phony-nolibc
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: libgilbraltar.a
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
$(RM) -f *.o *.a *.elf *.bin *.lst *.img
|
|
|
|
$(RM) -rf include/$(CONFIG_TARGET_TRIPLE)
|
|
|
|
$(RM) -f test/*.o
|
|
|
|
$(MAKE) -C openlibm clean
|
|
|
|
$(MAKE) -C nolibc clean FREESTANDING_CFLAGS=_
|
|
|
|
|
|
|
|
.PHONY: distclean
|
|
|
|
distclean: clean
|
|
|
|
$(RM) -f Makeconf
|
|
|
|
|
|
|
|
test/%.o: test/%.c
|
|
|
|
@echo "CC $@"
|
|
|
|
@$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
test01.img: libgilbraltar.a nolibc/libnolibc.a openlibm/libopenlibm.a test/test01.o
|
|
|
|
@echo "LD ${@:img=elf}"
|
|
|
|
@$(LD) test/${@:img=o} -o ${@:img=elf} $(LDFLAGS) -Wl,-T gilbraltar.ld
|
|
|
|
@$(OBJCOPY) ${@:img=elf} -O binary $@
|
|
|
|
|
|
|
|
test02.img: libgilbraltar.a nolibc/libnolibc.a openlibm/libopenlibm.a test/test02.o
|
|
|
|
@echo "LD ${@:img=elf}"
|
|
|
|
@$(LD) test/${@:img=o} -o ${@:img=elf} $(LDFLAGS) -Wl,-T gilbraltar.ld
|
|
|
|
@$(OBJCOPY) ${@:img=elf} -O binary $@
|
|
|
|
|
|
|
|
test03.img: libgilbraltar.a nolibc/libnolibc.a openlibm/libopenlibm.a test/test03.o
|
|
|
|
@echo "LD ${@:img=elf}"
|
2024-12-23 00:46:17 +00:00
|
|
|
@$(LD) test/${@:img=o} -o ${@:img=elf} $(LDFLAGS) -Wl,-Map ${@:img=map} -Wl,-T gilbraltar.ld
|
2024-12-20 22:45:12 +00:00
|
|
|
@$(OBJCOPY) ${@:img=elf} -O binary $@
|