Add llvm build support

This commit is contained in:
Dmitry Dubrovin 2023-01-24 00:26:33 +03:00
parent 4c075b8b6f
commit a8db9b0b08
2 changed files with 42 additions and 2 deletions

View File

@ -10,6 +10,16 @@ endif
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \ CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
-Wall -ggdb -m32 -Werror -fno-omit-frame-pointer -Wall -ggdb -m32 -Werror -fno-omit-frame-pointer
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASMFLAGS = -m32 -ffreestanding -c -g
ifeq ($(LLVM),on)
#AS=llvm-as
LD=ld.lld
CC=clang
CFLAGS += -target elf-i386
ASMFLAGS = -target elf-i386 -ffreestanding -c -g
LDKERNELFLAGS = --script=script.ld
endif
run: image.bin run: image.bin
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
@ -41,6 +51,12 @@ debug-boot: image.bin mbr.elf
-ex "break *0x7c00" \ -ex "break *0x7c00" \
-ex "continue" -ex "continue"
debug-server: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S
debug-server-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S
debug: image.bin debug: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S & qemu-system-i386 -drive format=raw,file=$< -s -S &
$(GDB) kernel.bin \ $(GDB) kernel.bin \
@ -67,13 +83,13 @@ image.bin: mbr.bin fs.img
cat $^ >$@ cat $^ >$@
kernel.bin: kernel.o console.o drivers/vga.o drivers/uart.o kernel.bin: kernel.o console.o drivers/vga.o drivers/uart.o
$(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^ $(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x1000 $^
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
%.o: %.S %.o: %.S
$(CC) -m32 -ffreestanding -c -g $^ -o $@ $(CC) $(ASMFLAGS) $^ -o $@
mbr.bin: mbr.o mbr.bin: mbr.o
$(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@ $(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@

24
script.ld Normal file
View File

@ -0,0 +1,24 @@
SECTIONS
{
.text (0x1000) : {
startup.o( .text )
}
.data : ALIGN(CONSTANT(MAXPAGESIZE)) {
_DATA_START_ = .;
*(.data)
_DATA_END_ = .;
}
.rodata : ALIGN(CONSTANT(MAXPAGESIZE)) {
_RODATA_START_ = .;
*(.rodata)
_RODATA_START_ = .;
}
.bss : ALIGN(CONSTANT(MAXPAGESIZE)) {
_BSS_START_ = .;
*(.bss)
_BSS_END_ = .;
}
}