From eb6f565825dec5931beee6f7f4f1a355e0eee7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20=27q3k=27=20Baza=C5=84ski?= Date: Fri, 5 Jul 2013 14:48:24 +0200 Subject: [PATCH] Added clang support. --- Kernel/Makefile | 33 ++++++++-------------- Kernel/contrib/fix-pci-db.py | 54 ++++++++++++++++++++++++++---------- Kernel/src/Tier0/kmain.c | 1 + Kernel/src/Tier0/kstdio.c | 2 +- Kernel/src/kernel.ld | 21 ++++++++------ Loader/src/load.c | 1 - 6 files changed, 65 insertions(+), 47 deletions(-) diff --git a/Kernel/Makefile b/Kernel/Makefile index ae8e6e5..8c17dd7 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -12,28 +12,19 @@ default: emulate-nohdd SHELL:=/bin/bash -#ENV:=/usr/xdev/bin -TARGET:=x86_64-elf -CC:=$(TARGET)-gcc -CX:=$(TARGET)-g++ +CC:=clang +CX:=clang++ AS:=nasm -LD:=$(TARGET)-ld +LD:=ld # -O2 sets -foptimize-sibling-calls which breaks code... -CFLAGS:=-m64 -mcmodel=large -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99 -g -CFLAGS+=-I ./include -Wno-packed-bitfield-compat -O2 -fno-optimize-sibling-calls -mcmodel=kernel -CFLAGS+= -mno-red-zone -ffreestanding -I ./include/Lua -I ./src/Lua +CFLAGS:= -mcmodel=large -Wall -Werror -nostdlib -ffreestanding -std=c99 -g +CFLAGS+=-I ./include -nostdinc -O2 -fno-optimize-sibling-calls -mcmodel=kernel +CFLAGS+= -mno-red-zone -ffreestanding -I ./include/Lua -I ./src/Lua -target x86_64-elf -#CXFLAGS:= -Wall -Werror -nostdlib -fno-builtin -nostartfiles -I ./include -#CXFLAGS+= -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector -#CXFLAGS+= -Wno-packed-bitfield-compat -O3 -mcmodel=kernel +CXFLAGS:= $(CFLAGS) -fno-rtti -fno-stack-protector -fno-exceptions -std=c++11 -CXFLAGS:=-m64 -mcmodel=large -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -g -CXFLAGS+=-I ./include -Wno-packed-bitfield-compat -O2 -fno-optimize-sibling-calls -mcmodel=kernel -CXFLAGS+= -mno-red-zone -ffreestanding -I ./include/Lua -I ./src/Lua -fno-exceptions -fno-rtti -CXFLAGS+= -fno-stack-protector -std=c++11 - -LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs +LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs -m elf_x86_64 -nostdinc -z nodefaultlib -n debug: CFLAGS += -DDEBUG -gdwarf-4 -fvar-tracking-assignments -O0 debug: CXFLAGS += -DDEBUG -gdwarf-4 -fvar-tracking-assignments -O0 @@ -104,11 +95,11 @@ Lua: $(LUA) kernel.bin: version-gen Tier0 Tier1 Lua Alentours @echo "[i] Linking kernel.bin..." - @$(LD) -T src/kernel.ld -o kernel.bin $(TIER0) $(TIER1) $(ALENTOURS) -Lsrc/Lua -llua + @$(LD) $(LFLAGS) -T src/kernel.ld -o kernel.bin $(TIER0) $(TIER1) $(ALENTOURS) -Lsrc/Lua -llua @echo "[i] Creating debug symbols." @cp kernel.bin ksyms.elf - @strip --only-keep-debug ksyms.elf - @strip --strip-debug --strip-unneeded kernel.bin + #@strip --only-keep-debug ksyms.elf + #@strip --strip-debug --strip-unneeded kernel.bin hdd.img: kernel.bin @echo "[i] Creating HDD image..." @@ -124,7 +115,7 @@ hdd.img: kernel.bin emulate-nohdd-debug: debug @echo "[i] Starting GDB..." @echo -e "file kernel.bin\nsymbol-file ksyms.elf\ntarget remote localhost:1234\n" > gdbcommands - @terminal -x /bin/bash -c "sleep 1 && gdb -tui -x gdbcommands && rm gdbcommands" & + xterm -e /bin/bash -c "sleep 1 && gdb -tui -x gdbcommands && rm gdbcommands" & @echo "[i] Starting QEmu..." @qemu-system-x86_64 --no-kvm -S -gdb tcp::1234 -d int -smp 4 -kernel ../Loader/loader.bin -initrd kernel.bin diff --git a/Kernel/contrib/fix-pci-db.py b/Kernel/contrib/fix-pci-db.py index ed04bf5..fe2f1d2 100644 --- a/Kernel/contrib/fix-pci-db.py +++ b/Kernel/contrib/fix-pci-db.py @@ -1,5 +1,6 @@ #!/usr/bin/python2 import re +import string f = open("include/Alentours/PCIDB.h", "r") d = f.read() @@ -13,22 +14,45 @@ in_ventable = False in_devtable = False for line in lines: - if line.startswith(' { 0x165C, 0x0002'): - in_devtable = True - if in_devtable and line.startswith("}"): - in_devtable = False - - if in_devtable: - if not re.match(r' { 0x([a-fA-F0-9]){4}, 0x([a-fA-F0-9]){4}, "[^"\\]*", "[^"\\]*".+', line) or line.find("??") >= 0: - print "[i] Removing invalid line %s from PCIDB.h..." % line - else: - newlines.append(line) - else: - newlines.append(line) + if line.startswith('PCI_DEVTABLE'): + in_devtable = True + print "[i] In devtable" + newlines.append(line) + continue + if in_devtable and line.startswith("{"): + newlines.append(line) + continue + if in_devtable and line.startswith("}"): + newlines.append(line) + in_devtable = False + continue + + if line.startswith('PCI_VENTABLE'): + in_ventable = True + print "[i] In ventable" + newlines.append(line) + continue + if in_ventable and line.startswith("{"): + newlines.append(line) + continue + if in_ventable and line.startswith("}"): + in_ventable = False + newlines.append(line) + continue + + if in_devtable: + if not re.match('\t' + r'\{ 0x([a-fA-F0-9]){4}, 0x([a-fA-F0-9]){4}, "[^"\\]*", "[^"\\]*".+', line) or line.find("??") >= 0: + print "[i] Removing invalid line %s from PCIDB.h..." % line + else: + newlines.append(filter(lambda x: x in string.printable, line)) + elif in_ventable: + if not re.match('\t' + r'{ 0x([a-fA-F0-9]){4}, "[^"\\]*", "[^"\\]*".+', line): + print "[i] Removing invalid line %s from PCIDB.h..." % line + else: + newlines.append(filter(lambda x: x in string.printable, line)) + else: + newlines.append(filter(lambda x: x in string.printable, line)) f = open("include/Alentours/PCIDB.h", "w") f.write("\n".join(newlines)) f.close() - - - diff --git a/Kernel/src/Tier0/kmain.c b/Kernel/src/Tier0/kmain.c index 5692776..81926ed 100644 --- a/Kernel/src/Tier0/kmain.c +++ b/Kernel/src/Tier0/kmain.c @@ -25,6 +25,7 @@ void kmain_newstack(void); // Real kernel entry point, called from loader void kmain(u32 LoadContextAddress) { + for(;;){} T_LOAD_CONTEXT *LoadContext = (T_LOAD_CONTEXT*)(u64)LoadContextAddress; kstdio_init(); diff --git a/Kernel/src/Tier0/kstdio.c b/Kernel/src/Tier0/kstdio.c index ace0b11..f7ba927 100644 --- a/Kernel/src/Tier0/kstdio.c +++ b/Kernel/src/Tier0/kstdio.c @@ -2,7 +2,7 @@ #include "Tier0/kstdio.h" #include "Tier0/kstdlib.h" //#include "Tier0/semaphore.h" -#include +// #include #define va_start(v,l) __builtin_va_start(v,l) #define va_arg(v,l) __builtin_va_arg(v,l) diff --git a/Kernel/src/kernel.ld b/Kernel/src/kernel.ld index c1a3cdb..2fd10f6 100644 --- a/Kernel/src/kernel.ld +++ b/Kernel/src/kernel.ld @@ -9,7 +9,7 @@ SECTIONS _start = .; - .text : AT(ADDR(.text) - KERNEL_VMA) + .text : { _code = .; *(.text) @@ -21,29 +21,32 @@ SECTIONS _start_ctors = .; *(.ctors) _end_ctors = .; - - . = ALIGN(4096); } - .data : AT(ADDR(.data) - KERNEL_VMA) + . = ALIGN(4096); + + .data : { _data = .; *(.data) - . = ALIGN(4096); } - .bss : AT(ADDR(.bss) - KERNEL_VMA) + . = ALIGN(4096); + + .bss : { _bss = .; *(.bss) - *(COMMON) - . = ALIGN(4096); + *(COMMON) } _end = .; /DISCARD/ : { - *(.eh_frame) + *(.eh_frame*) + *(.ehframe*) + *(.debug*) + } } diff --git a/Loader/src/load.c b/Loader/src/load.c index 0f5dfcb..0139f7b 100644 --- a/Loader/src/load.c +++ b/Loader/src/load.c @@ -321,7 +321,6 @@ u32 create_ia32e_paging(u64 KernelPhysicalStart, u64 KernelVirtualStart, u64 Ker Address += 0x1000; } - return 0; }