diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 572096fc2e..1485a5e639 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -24,7 +24,7 @@ jobs: - run: ./verify-pycodestyle.sh build_mips_gcc: - name: Build MIPS (GCC + KASAN) + name: Build MIPS (GCC) runs-on: self-hosted needs: [verify_c_style, verify_py_style] steps: @@ -46,10 +46,10 @@ jobs: needs: [verify_c_style, verify_py_style] steps: - uses: actions/checkout@v2 - - run: make BOARD=malta CLANG=1 + - run: make BOARD=malta LLVM=1 KASAN=1 LOCKDEP=1 build_aarch64_gcc: - name: Build AArch64 (GCC + KASAN) + name: Build AArch64 (GCC) runs-on: self-hosted needs: [verify_c_style, verify_py_style] steps: @@ -73,10 +73,10 @@ jobs: needs: [verify_c_style, verify_py_style] steps: - uses: actions/checkout@v2 - - run: make BOARD=rpi3 CLANG=1 + - run: make BOARD=rpi3 LLVM=1 KASAN=1 LOCKDEP=1 build_rv32_gcc: - name: Build RISC-V 32-bit (GCC + KASAN) + name: Build RISC-V 32-bit (GCC) runs-on: self-hosted needs: [verify_c_style, verify_py_style] steps: @@ -98,10 +98,18 @@ jobs: needs: [verify_c_style, verify_py_style] steps: - uses: actions/checkout@v2 - - run: make BOARD=litex-riscv CLANG=1 + - run: make BOARD=litex-riscv LLVM=1 KASAN=1 LOCKDEP=1 + + build_rv64_clang: + name: Build RISC-V 64-bit (Clang) + runs-on: self-hosted + needs: [verify_c_style, verify_py_style] + steps: + - uses: actions/checkout@v2 + - run: make BOARD=sifive_u LLVM=1 KASAN=1 LOCKDEP=1 kernel_tests_mips_gcc: - name: Tests MIPS (GCC + KASAN) + name: Tests MIPS (GCC) runs-on: self-hosted needs: build_mips_gcc steps: @@ -112,7 +120,7 @@ jobs: - run: ./run_tests.py --board malta --timeout=80 --times=50 kernel_tests_aarch64_gcc: - name: Tests AArch64 (GCC + KASAN) + name: Tests AArch64 (GCC) runs-on: self-hosted needs: build_aarch64_gcc steps: diff --git a/Dockerfile b/Dockerfile index 22a418f462..5ac8ff706a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,9 @@ WORKDIR /root RUN apt-get -q update && apt-get upgrade -y RUN apt-get install -y --no-install-recommends -t bullseye-backports \ git make cpio curl universal-ctags cscope socat patch gperf quilt \ - bmake byacc python3-pip clang clang-format device-tree-compiler tmux \ - libmpfr6 libfdt1 libpython3.9 libsdl2-2.0-0 libglib2.0-0 libpixman-1-0 + bmake byacc python3-pip clang clang-format llvm lld \ + device-tree-compiler tmux libmpfr6 libfdt1 libpython3.9 \ + libsdl2-2.0-0 libglib2.0-0 libpixman-1-0 # patch & quilt required by lua and programs in contrib/ # gperf required by libterminfo # socat & tmux required by launch diff --git a/Makefile b/Makefile index 29e5c3a5fb..bf65ffc144 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ test: sys-build initrd.cpio PHONY-TARGETS += setup test -IMGVER = 1.9.0 +IMGVER = 1.9.1 IMGNAME = cahirwpz/mimiker-ci docker-build: diff --git a/bin/date/Makefile b/bin/date/Makefile index eef17d58b4..548add0990 100644 --- a/bin/date/Makefile +++ b/bin/date/Makefile @@ -2,7 +2,6 @@ TOPDIR = $(realpath ../..) PROGRAM = date FORMAT-EXCLUDE = $(SOURCES) +LDLIBS = -lutil include $(TOPDIR)/build/build.prog.mk - -LDLIBS = -lutil diff --git a/build/arch.aarch64.mk b/build/arch.aarch64.mk index f5e9218f40..0ff6ac9f66 100644 --- a/build/arch.aarch64.mk +++ b/build/arch.aarch64.mk @@ -1,16 +1,21 @@ -# vim: tabstop=8 shiftwidth=8 noexpandtab: +# vim: tabstop=2 shiftwidth=2 noexpandtab: # # Common makefile which specifies aarch64 architecture specific settings. # # Required common variables: KERNEL, BOARD. # -TARGET := aarch64-mimiker-elf -GCC_ABIFLAGS := -mno-outline-atomics -CLANG_ABIFLAGS := -target aarch64-elf ELFTYPE := elf64-littleaarch64 ELFARCH := aarch64 +ifeq ($(LLVM), 1) + TARGET := aarch64-linux-mimiker-elf + ABIFLAGS := +else + TARGET := aarch64-mimiker-elf + ABIFLAGS := -mno-outline-atomics +endif + # NOTE(pj): We set A, SA, SA0 bits for SCTLR_EL1 register (sys/aarch64/boot.c) # as a result not aligned access to memory causes an exception. It's okay but # user-space (taken from NetBSD) doesn't care about that by default. It @@ -18,20 +23,14 @@ ELFARCH := aarch64 # because we share bcopy (memcpy) implementation with user-space. CPPFLAGS += -DSTRICT_ALIGNMENT=1 +ASAN_SHADOW_OFFSET := 0xe0001f0000000000 + ifeq ($(KERNEL), 1) - CFLAGS += -mcpu=cortex-a53+nofp -march=armv8-a+nofp -mgeneral-regs-only - ifeq ($(KASAN), 1) - # Added to files that are sanitized - CFLAGS_KASAN = -fsanitize=kernel-address \ - -fasan-shadow-offset=0xe0001f0000000000 \ - --param asan-globals=1 \ - --param asan-stack=1 \ - --param asan-instrument-allocas=1 - endif + CFLAGS += -mcpu=cortex-a53+nofp -march=armv8-a+nofp -mgeneral-regs-only else - CFLAGS += -mcpu=cortex-a53 -march=armv8-a + CFLAGS += -mcpu=cortex-a53 -march=armv8-a endif ifeq ($(BOARD), rpi3) - KERNEL-IMAGES := mimiker.img mimiker.img.gz + KERNEL-IMAGES := mimiker.img mimiker.img.gz endif diff --git a/build/arch.mips.mk b/build/arch.mips.mk index d59508dc61..12e25884fb 100644 --- a/build/arch.mips.mk +++ b/build/arch.mips.mk @@ -1,30 +1,25 @@ -# vim: tabstop=8 shiftwidth=8 noexpandtab: +# vim: tabstop=2 shiftwidth=2 noexpandtab: # # Common makefile which specifies MIPS architecture specific settings. # # Required common variables: KERNEL, BOARD. -TARGET := mipsel-mimiker-elf +ELFARCH := mips + # -G 0 disables small-data and small-bss, # as otherwise they would exceed 64KB limit -GCC_ABIFLAGS := -mips32r2 -EL -G 0 -CLANG_ABIFLAGS := -target mipsel-elf -march=mips32r2 -mno-abicalls \ - -modd-spreg -G 0 -D__ELF__=1 -ELFTYPE := elf32-littlemips -ELFARCH := mips +ifeq ($(LLVM), 1) + TARGET := mipsel-linux-mimiker-elf + ABIFLAGS := -march=mips32r2 -mno-abicalls -modd-spreg -G 0 -D__ELF__=1 + ELFTYPE := elf32-tradlittlemips +else + TARGET := mipsel-mimiker-elf + ABIFLAGS := -mips32r2 -EL -G 0 + ELFTYPE := elf32-littlemips +endif + +ASAN_SHADOW_OFFSET := 0xD8000000 ifeq ($(KERNEL), 1) -ifeq ($(KASAN), 1) - # Added to files that are sanitized - CFLAGS_KASAN = -fsanitize=kernel-address -fasan-shadow-offset=0xD8000000 \ - --param asan-globals=1 \ - --param asan-stack=1 \ - --param asan-instrument-allocas=1 -endif -# Added to all files -GCC_ABIFLAGS += -msoft-float -CLANG_ABIFLAGS += -msoft-float -ifeq ($(KGPROF), 1) - CFLAGS_KGPROF = -finstrument-functions -endif + ABIFLAGS += -msoft-float endif diff --git a/build/arch.riscv.mk b/build/arch.riscv.mk index 4d412a9873..077bd875aa 100644 --- a/build/arch.riscv.mk +++ b/build/arch.riscv.mk @@ -1,4 +1,4 @@ -# vim: tabstop=8 shiftwidth=8 noexpandtab: +# vim: tabstop=2 shiftwidth=2 noexpandtab: # # Common makefile which specifies RISC-V architecture specific settings. # @@ -8,53 +8,49 @@ # Required common variables: KERNEL, BOARD. # -TARGET := riscv$(XLEN)-mimiker-elf ELFTYPE := elf$(XLEN)-littleriscv ELFARCH := riscv ifeq ($(BOARD), litex-riscv) - ifeq ($(CLANG), 1) - EXT := ima - else - EXT := ima_zicsr_zifencei - endif - ABI := ilp32 - KERNEL_PHYS := 0x40000000 - KERNEL-IMAGES := mimiker.img -ifeq ($(KERNEL), 1) - CPPFLAGS += -DFPU=0 - ifeq ($(KASAN), 1) - CFLAGS_KASAN += -fasan-shadow-offset=0x90000000 - endif -endif + ifeq ($(LLVM), 1) + EXT := ima + else + EXT := ima_zicsr_zifencei + endif + ABI := ilp32 + KERNEL_PHYS := 0x40000000 + KERNEL_VIRT := 0x80000000 + KERNEL-IMAGES := mimiker.img + ifeq ($(KERNEL), 1) + CPPFLAGS += -DFPU=0 + ASAN_SHADOW_OFFSET := 0x90000000 + endif endif ifeq ($(BOARD), sifive_u) - EXT := g - ABI := lp64d - KERNEL_PHYS := 0x80200000 -ifeq ($(KERNEL), 1) - CPPFLAGS += -DFPU=1 - ifeq ($(KASAN), 1) - CFLAGS_KASAN += -fasan-shadow-offset=0xdfffffe000000000 - endif -endif -ifeq ($(CLANG), 1) - CPPFLAGS += -D__riscv_d -D__riscv_f + EXT := g + ABI := lp64d + KERNEL_PHYS := 0x80200000 + KERNEL_VIRT := 0xffffffc000000000 + ifeq ($(KERNEL), 1) + CPPFLAGS += -DFPU=1 + ASAN_SHADOW_OFFSET := 0xdfffffe000000000 + endif + ifeq ($(LLVM), 1) + CPPFLAGS += -D__riscv_d -D__riscv_f + endif endif + +ifeq ($(LLVM), 1) + TARGET := riscv$(XLEN)-linux-mimiker-elf +else + TARGET := riscv$(XLEN)-mimiker-elf endif -GCC_ABIFLAGS += -march=rv$(XLEN)$(EXT) -mabi=$(ABI) -CLANG_ABIFLAGS += -target riscv$(XLEN)-elf -march=rv$(XLEN)$(EXT) -mabi=$(ABI) +ABIFLAGS += -march=rv$(XLEN)$(EXT) -mabi=$(ABI) ifeq ($(KERNEL), 1) - CFLAGS += -mcmodel=medany - CPPFLAGS += -DKERNEL_PHYS=$(KERNEL_PHYS) - CPPLDSCRIPT := 1 - ifeq ($(KASAN), 1) - CFLAGS_KASAN += -fsanitize=kernel-address \ - --param asan-globals=1 \ - --param asan-stack=1 \ - --param asan-instrument-allocas=1 - endif + CFLAGS += -mcmodel=medany + CPPFLAGS += -DKERNEL_PHYS=$(KERNEL_PHYS) -DKERNEL_VIRT=$(KERNEL_VIRT) + CPPLDSCRIPT := 1 endif diff --git a/build/build.kern.mk b/build/build.kern.mk index 40808273a2..6e1e5627ab 100644 --- a/build/build.kern.mk +++ b/build/build.kern.mk @@ -48,12 +48,4 @@ $(KLIB): $(OBJECTS) $(KLIBDEPS) @echo "[DTB] $(DIR)$< -> $(DIR)$@" dtc -O dtb -o $@ $< -%_dtb.o: %.dtb - @echo "[OBJCOPY] $(DIR)$< -> $(DIR)$@" - $(OBJCOPY) -I binary -O $(ELFTYPE) -B $(ELFARCH) \ - --redefine-sym _binary_$(@:%.o=%)_start=__$(@:%.o=%)_start \ - --redefine-sym _binary_$(@:%.o=%)_end=__$(@:%.o=%)_end \ - --redefine-sym _binary_$(@:%.o=%)_size=__$(@:%.o=%)_size \ - $< $@ - -CLEAN-FILES += *_dtb.o *.dtb +CLEAN-FILES += *.dtb diff --git a/build/compile.mk b/build/compile.mk index 4418015612..42f6d99183 100644 --- a/build/compile.mk +++ b/build/compile.mk @@ -27,7 +27,7 @@ $(DEPENDENCY-FILES): $(SOURCES_GEN) .%.D: %.S @echo "[DEP] $(DIR)$@" - $(AS) $(ASFLAGS) $(CPPFLAGS) -MT $*.o -MM -MG $^ -MF $@ + $(CC) $(ASFLAGS) $(CPPFLAGS) -MT $*.o -MM -MG $^ -MF $@ ifeq ($(words $(findstring $(MAKECMDGOALS), download clean distclean)), 0) -include $(DEPENDENCY-FILES) diff --git a/build/flags.kern.mk b/build/flags.kern.mk index 14a462a843..6af9151c4c 100644 --- a/build/flags.kern.mk +++ b/build/flags.kern.mk @@ -1,4 +1,4 @@ -# vim: tabstop=8 shiftwidth=8 noexpandtab: +# vim: tabstop=2 shiftwidth=2 noexpandtab: # # Common makefile used to supplement the compilation flags with the kernel # specific flags. @@ -17,4 +17,27 @@ ifeq ($(KCSAN), 1) --param tsan-distinguish-volatile=1 endif +ifeq ($(KASAN), 1) + # Added to files that are sanitized + ifeq ($(LLVM), 1) + CFLAGS_KASAN = -fsanitize=kernel-address \ + -mllvm -asan-mapping-offset=$(ASAN_SHADOW_OFFSET) \ + -mllvm -asan-instrumentation-with-call-threshold=0 \ + -mllvm -asan-globals=true \ + -mllvm -asan-stack=true \ + -mllvm -asan-instrument-dynamic-allocas=true + else + CFLAGS_KASAN = -fsanitize=kernel-address \ + -fasan-shadow-offset=$(ASAN_SHADOW_OFFSET) \ + --param asan-instrumentation-with-call-threshold=0 \ + --param asan-globals=1 \ + --param asan-stack=1 \ + --param asan-instrument-allocas=1 + endif +endif + +ifeq ($(KGPROF), 1) + CFLAGS_KGPROF = -finstrument-functions +endif + KERNEL := 1 diff --git a/build/flags.user.mk b/build/flags.user.mk index 8e49b4f7cc..ae36993c15 100644 --- a/build/flags.user.mk +++ b/build/flags.user.mk @@ -10,6 +10,5 @@ include $(TOPDIR)/build/flags.mk CPPFLAGS += -nostdinc --sysroot=$(SYSROOT) -I$(TOPDIR)/include CFLAGS += -ffreestanding -fno-builtin -LDFLAGS += -nostartfiles -nodefaultlibs --sysroot=$(SYSROOT) \ - -L= -T lib/ld.script -LDLIBS += +LDFLAGS += --sysroot=$(SYSROOT) -L=/lib +LDLIBS += -T $(SYSROOT)/lib/ld.script diff --git a/build/tools.mk b/build/tools.mk index 6ae7505c17..8d06a8ba22 100644 --- a/build/tools.mk +++ b/build/tools.mk @@ -1,47 +1,65 @@ -# vim: tabstop=8 shiftwidth=8 noexpandtab: +# vim: tabstop=2 shiftwidth=2 noexpandtab: # # This is a common makefile used to establish the implementation of the basic # tools used throughout the build system. # # The following make variables are set by the including makefile: -# - TARGET, {CLANG,GCC}_ABIFLAGS: Set by arch.*.mk files. +# - TARGET, ABIFLAGS: Set by arch.*.mk files. ifndef ARCH $(error ARCH variable not defined. Have you included config.mk?) endif -GCC_FOUND = $(shell which $(TARGET)-gcc > /dev/null; echo $$?) -ifneq ($(GCC_FOUND), 0) - $(error $(TARGET)-gcc compiler not found - please refer to README.md!) -endif +# Pass "LLVM=1" at command line to switch to llvm toolchain. +ifeq ($(LLVM), 1) -# Pass "CLANG=1" at command line to switch kernel compiler to Clang. -ifeq ($(CLANG), 1) -CLANG_FOUND = $(shell which clang > /dev/null; echo $$?) -ifneq ($(CLANG_FOUND), 0) +ifneq ($(shell which clang > /dev/null; echo $$?), 0) $(error clang compiler not found - please refer to README.md!) endif -TARGET_CC = clang $(CLANG_ABIFLAGS) -g + +ifneq ($(shell which lld > /dev/null; echo $$?), 0) + $(error lld linker not found) +endif + +ifneq ($(shell which llvm-ar > /dev/null; echo $$?), 0) + $(error llvm toolchain not found) +endif + +CC = clang -target $(TARGET) $(ABIFLAGS) -g +CPP = $(CC) -x c -E +AS = $(CC) +LD = ld.lld +AR = llvm-ar +NM = llvm-nm +RANLIB = llvm-ranlib +READELF = llvm-readelf +OBJCOPY = llvm-objcopy +OBJDUMP = llvm-objdump +STRIP = llvm-strip + # The genassym script produces C code with asm statements that have # garbage instructions, which Clang checks using its built-in assembler # and refuses to compile. This option disables this check. ASSYM_CFLAGS += -no-integrated-as + else -TARGET_CC = $(TARGET)-gcc $(GCC_ABIFLAGS) -g + +ifneq ($(shell which $(TARGET)-gcc > /dev/null; echo $$?), 0) + $(error $(TARGET)-gcc compiler not found - please refer to README.md!) endif -CC = $(TARGET_CC) -AS = $(TARGET_CC) -LD = $(TARGET)-gcc $(GCC_ABIFLAGS) -g -CPP = $(TARGET)-cpp -AR = $(TARGET)-ar -NM = $(TARGET)-nm -GDB = $(TARGET)-gdb -RANLIB = $(TARGET)-ranlib -READELF = $(TARGET)-readelf -OBJCOPY = $(TARGET)-objcopy -OBJDUMP = $(TARGET)-objdump -STRIP = $(TARGET)-strip +CC = $(TARGET)-gcc $(ABIFLAGS) -g +CPP = $(TARGET)-cpp +AS = $(CC) +LD = $(TARGET)-ld +AR = $(TARGET)-ar +NM = $(TARGET)-nm +RANLIB = $(TARGET)-ranlib +READELF = $(TARGET)-readelf +OBJCOPY = $(TARGET)-objcopy +OBJDUMP = $(TARGET)-objdump +STRIP = $(TARGET)-strip +endif CP = cp CPIO = cpio --format=crc diff --git a/config.mk b/config.mk index b5cdfab172..b905fc5894 100644 --- a/config.mk +++ b/config.mk @@ -6,7 +6,7 @@ CONFIG_OPTS := KASAN LOCKDEP KGPROF MIPS AARCH64 RISCV KCSAN -BOARD ?= malta +BOARD ?= rpi3 MIPS ?= 0 AARCH64 ?= 0 @@ -35,7 +35,7 @@ XLEN := 64 endif VERBOSE ?= 0 -CLANG ?= 0 +LLVM ?= 0 LOCKDEP ?= 0 KASAN ?= 0 KGPROF ?= 0 diff --git a/include/riscv/asm.h b/include/riscv/asm.h index d5c699c9e7..90b55f2623 100644 --- a/include/riscv/asm.h +++ b/include/riscv/asm.h @@ -38,7 +38,7 @@ #define _ENTRY(x) \ .globl _C_LABEL(x); \ - .align 4; \ + .p2align 2; \ .type _C_LABEL(x), @function; \ _C_LABEL(x) : diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index 976604773d..3ff0c89960 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -116,10 +116,10 @@ #define __sysloglike(fmtarg, firstvararg) \ __attribute__((__format__(__syslog__, fmtarg, firstvararg))) -#define __strong_alias(alias, sym) \ - extern __typeof(alias) alias __attribute__((__alias__(#sym))) -#define __weak_alias(alias, sym) \ - __strong_alias(alias, sym) __attribute__((__weak__)) +#define __strong_alias(sym, alias) \ + extern __typeof(sym) alias __attribute__((__alias__(#sym))) +#define __weak_alias(sym, alias) \ + __strong_alias(sym, alias) __attribute__((__weak__)) /* * The following macro is used to remove const cast-away warnings diff --git a/include/sys/mimiker.h b/include/sys/mimiker.h index 59e7568cef..040e9ca053 100644 --- a/include/sys/mimiker.h +++ b/include/sys/mimiker.h @@ -137,9 +137,12 @@ extern char __etext[]; /* Symbols defined by linker and used during kernel boot phase. */ extern char __boot[]; extern char __eboot[]; +extern char __text[]; extern char __data[]; extern char __bss[]; extern char __ebss[]; +extern char __kernel_start[]; +extern char __kernel_end[]; /* Last physical address used by kernel for boot memory allocation. */ extern __boot_data void *_bootmem_end; diff --git a/launch b/launch index 36927d8c94..436f9fca9b 100755 --- a/launch +++ b/launch @@ -61,6 +61,7 @@ CONFIG = { 'board': { 'malta': { 'kernel': 'sys/mimiker.elf', + 'dts': None, 'simulator': 'qemu' }, 'rpi3': { @@ -75,7 +76,7 @@ CONFIG = { }, 'sifive_u': { 'kernel': 'sys/mimiker.elf', - 'dts': 'sys/dts/sifive_u.dts', + 'dts': None, 'simulator': 'qemu' }, }, @@ -287,7 +288,7 @@ class QEMU(Launchable): port = uart['port'] self.options += ['-serial', f'tcp:127.0.0.1:{port},server,wait'] - if getvar('config.dts', failok=True) is None: + if not getvar('config.dts'): if getvar('config.args'): self.options += ['-append', ' '.join(getvar('config.args'))] else: @@ -436,8 +437,8 @@ def setup_terminal(): def prepare_dtb(): bootargs = ' '.join(getvar('config.args')) board = getvar('board') - dts = getvar('config.dts', failok=True) - if dts is None: + dts = getvar('config.dts') + if not dts: return if not os.path.isfile(dts): @@ -477,7 +478,7 @@ if __name__ == '__main__': help='Test-run will fail after n seconds.') parser.add_argument('-g', '--graphics', action='store_true', help='Enable VGA output.') - parser.add_argument('-b', '--board', default='malta', + parser.add_argument('-b', '--board', default='rpi3', choices=['malta', 'rpi3', 'litex-riscv', 'sifive_u'], help='Emulated board.') parser.add_argument('-s', '--storage', type=str, diff --git a/lib/csu/aarch64/ld.script b/lib/csu/aarch64/ld.script index fd9759a178..ebe9cd3b29 100644 --- a/lib/csu/aarch64/ld.script +++ b/lib/csu/aarch64/ld.script @@ -1,7 +1,7 @@ OUTPUT_ARCH(aarch64) ENTRY(_start) -INPUT(crt0.o crt0-common.o -lc -lm) +INPUT(crt0.o crt0-common.o libc.a libm.a) PHDRS { diff --git a/lib/csu/mips/ld.script b/lib/csu/mips/ld.script index 3d50d63621..b0227ba3a3 100644 --- a/lib/csu/mips/ld.script +++ b/lib/csu/mips/ld.script @@ -1,7 +1,7 @@ OUTPUT_ARCH(mips) ENTRY(_start) -INPUT(crt0.o crt0-common.o -lc -lm) +INPUT(crt0.o crt0-common.o libc.a libm.a) PHDRS { diff --git a/lib/csu/riscv/ld.script b/lib/csu/riscv/ld.script index c4bec0dc76..9e8dd65617 100644 --- a/lib/csu/riscv/ld.script +++ b/lib/csu/riscv/ld.script @@ -1,7 +1,7 @@ OUTPUT_ARCH(riscv) ENTRY(_start) -INPUT(crt0.o crt0-common.o -lc -lm) +INPUT(crt0.o crt0-common.o libc.a libm.a) PHDRS { diff --git a/lib/libc/stdlib/merge.c b/lib/libc/stdlib/merge.c index e65b191977..95fd2c251c 100644 --- a/lib/libc/stdlib/merge.c +++ b/lib/libc/stdlib/merge.c @@ -87,8 +87,7 @@ static void insertionsort(u_char *, size_t, size_t, */ /* Assumption: PSIZE is a power of 2. */ #define EVAL(p) \ - ((u_char **)(void *)(((u_char *)(void *)(p) + PSIZE - 1 - (u_char *)0) & \ - ~(PSIZE - 1))) + ((u_char **)(void *)(((uintptr_t)(p) + PSIZE - 1) & ~(PSIZE - 1))) /* * Arguments are as for qsort. @@ -117,7 +116,7 @@ int mergesort(void *base, size_t nmemb, size_t size, * Stupid subtraction for the Cray. */ iflag = 0; - if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) + if (!(size % ISIZE) && !(((uintptr_t)base) % ISIZE)) iflag = 1; if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index b32edc9944..834e84e2f6 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -57,7 +57,7 @@ static inline void swapfunc(char *, char *, size_t, int); } #define SWAPINIT(a, es) \ - swaptype = ((char *)a - (char *)0) % sizeof(long) || es % sizeof(long) \ + swaptype = ((uintptr_t)a) % sizeof(long) || es % sizeof(long) \ ? 2 \ : es == sizeof(long) ? 0 : 1; diff --git a/lib/libm/src/s_scalbn.c b/lib/libm/src/s_scalbn.c index f53b862b43..9bde0c63c0 100644 --- a/lib/libm/src/s_scalbn.c +++ b/lib/libm/src/s_scalbn.c @@ -30,7 +30,7 @@ double scalbn(double x, int n) { return scalbln(x, n); } -__weak_alias(ldexp, scalbn); +__weak_alias(scalbn, ldexp); double scalbln(double x, long n) { int32_t k, hx, lx; diff --git a/run_tests.py b/run_tests.py index f7477bed0d..d108c8cb4a 100755 --- a/run_tests.py +++ b/run_tests.py @@ -48,7 +48,7 @@ def run_test(seed, board, timeout): description='Automatically performs kernel tests.') parser.add_argument('--times', type=int, default=N_SIMPLE, help='Run tests given number of times.') - parser.add_argument('--board', default='malta', choices=['malta', 'rpi3'], + parser.add_argument('--board', default='rpi3', choices=['malta', 'rpi3'], help='Emulated board.') parser.add_argument('-T', '--timeout', type=int, default=DEFAULT_TIMEOUT, help='Test-run will fail after n seconds.') diff --git a/sys/Makefile b/sys/Makefile index 88f96beef3..245f41e4d2 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -14,13 +14,11 @@ include $(TOPDIR)/build/build.kern.mk LDSCRIPT = $(ARCH)/$(ARCH).ld LDFLAGS += -T $(TOPDIR)/sys/$(LDSCRIPT) -LDLIBS = -Wl,--start-group \ - -Wl,--whole-archive $(KLIBLIST) -Wl,--no-whole-archive \ - -Wl,--end-group +LDLIBS = --whole-archive $(KLIBLIST) --no-whole-archive mimiker.elf: $(KLIBDEPS) $(LDSCRIPT) @echo "[LD] Linking kernel image: $@" - $(LD) $(LDFLAGS) -Wl,-Map=$@.map $(LDLIBS) -o $@ + $(LD) $(LDFLAGS) -Map=$@.map $(LDLIBS) -o $@ mimiker.img: mimiker.elf @echo "[OBJCOPY] Prepare kernel image: $@" @@ -30,6 +28,9 @@ mimiker.img.gz: mimiker.img @echo "[GZIP] Compress kernel image: $@" $(GZIP) -k -f $^ > $@ +$(LDSCRIPT): + make -C $(dir $(LDSCRIPT)) $(notdir $(LDSCRIPT)) + # Lists of all files that we consider operating system kernel sources. SRCDIRS = $(TOPDIR)/include $(TOPDIR)/sys SRCFILES_C = $(shell find $(SRCDIRS) -iname '*.[ch]') diff --git a/sys/aarch64/Makefile b/sys/aarch64/Makefile index 98a0f6263b..5942dac761 100644 --- a/sys/aarch64/Makefile +++ b/sys/aarch64/Makefile @@ -31,3 +31,4 @@ $(SOURCES-AARCH64): assym.h boot.o : CFLAGS_KASAN = boot.o : CFLAGS_KCSAN = +boot.o : CFLAGS_KGPROF = diff --git a/sys/aarch64/boot.c b/sys/aarch64/boot.c index 8e661a9a06..87cde2c5c3 100644 --- a/sys/aarch64/boot.c +++ b/sys/aarch64/boot.c @@ -300,4 +300,4 @@ __boot_text void *aarch64_init(void) { typedef struct { } tlbentry_t; -static __unused __boot_data volatile tlbentry_t _gdb_tlb_entry; +static __used __boot_data volatile tlbentry_t _gdb_tlb_entry; diff --git a/sys/debug/kgmon.py b/sys/debug/kgmon.py index 653ca12b0b..7663b3dcac 100644 --- a/sys/debug/kgmon.py +++ b/sys/debug/kgmon.py @@ -12,6 +12,8 @@ class GmonParam(metaclass=GdbStructMeta): gparam = GmonParam(gdb.parse_and_eval('_gmonparam')) infer = gdb.inferiors()[0] + word_size = int(gdb.parse_and_eval('sizeof(long)')) + with open(path, "wb") as of: # Write headers gmonhdr_size = int(gdb.parse_and_eval('sizeof(_gmonhdr)')) @@ -28,6 +30,10 @@ class GmonParam(metaclass=GdbStructMeta): # The last H stands for padding in the tos strusture tos_rep = 'IiHH' + output_rep = "IIi" + if word_size == 8: + tos_rep = "QqHHi" + output_rep = "QQq" tos_rep_len = len(tos_rep) size = calcsize(tos_rep) tos_array = unpack(tos_rep * int(gparam.tossize/size), memory) @@ -50,7 +56,7 @@ class GmonParam(metaclass=GdbStructMeta): selfpc = tos_array[toindex * tos_rep_len] count = tos_array[toindex * tos_rep_len + 1] toindex = tos_array[toindex * tos_rep_len + 2] - of.write(pack('IIi', frompc, selfpc, count)) + of.write(pack(output_rep, frompc, selfpc, count)) class Kgmon(SimpleCommand): diff --git a/sys/debug/virtmem.py b/sys/debug/virtmem.py index b78f9bf2f3..f3407f1cf2 100644 --- a/sys/debug/virtmem.py +++ b/sys/debug/virtmem.py @@ -80,13 +80,9 @@ def __init__(self): super().__init__('vm_map') def __call__(self, args): - args = args.strip() - if args not in ['user', 'kernel']: - print('Choose either "user" or "kernel" vm_map!') - return - vm_map = gdb.parse_and_eval('vm_map_%s()' % args) + vm_map = gdb.parse_and_eval('vm_map_user()') if vm_map == 0: - print('No active %s vm_map!' % args) + print('No active user vm_map!') return entries = vm_map['entries'] table = TextTable(types='itttttt', align='rrrrrrr') diff --git a/sys/kern/kasan.c b/sys/kern/kasan.c index e2213a4270..b941e5e6ce 100644 --- a/sys/kern/kasan.c +++ b/sys/kern/kasan.c @@ -228,11 +228,12 @@ void kasan_mark_invalid(const void *addr, size_t size, uint8_t code) { } /* Call constructors that will register globals */ +typedef void (*ctor_t)(void); + static void call_ctors(void) { - extern uintptr_t __CTOR_LIST__, __CTOR_END__; - for (uintptr_t *ptr = &__CTOR_LIST__; ptr != &__CTOR_END__; ptr++) { - void (*func)(void) = (void (*)(void))(*ptr); - (*func)(); + extern ctor_t __CTOR_LIST__[], __CTOR_END__[]; + for (ctor_t *ctor = __CTOR_LIST__; ctor != __CTOR_END__; ctor++) { + (*ctor)(); } } @@ -272,9 +273,13 @@ void init_kasan(void) { void __asan_load##size##_noabort(uintptr_t addr) { \ shadow_check(addr, size, true); \ } \ + __weak_alias(__asan_load##size##_noabort, \ + __asan_report_load##size##_noabort); \ void __asan_store##size##_noabort(uintptr_t addr) { \ shadow_check(addr, size, false); \ - } + } \ + __weak_alias(__asan_store##size##_noabort, \ + __asan_report_store##size##_noabort); DEFINE_ASAN_LOAD_STORE(1); DEFINE_ASAN_LOAD_STORE(2); @@ -286,10 +291,14 @@ void __asan_loadN_noabort(uintptr_t addr, size_t size) { shadow_check(addr, size, true); } +__weak_alias(__asan_loadN_noabort, __asan_report_load_n_noabort); + void __asan_storeN_noabort(uintptr_t addr, size_t size) { shadow_check(addr, size, false); } +__weak_alias(__asan_storeN_noabort, __asan_report_store_n_noabort); + /* Called at the end of every function marked as "noreturn". * Performs cleanup of the current stack's shadow memory to prevent false * positives. */ diff --git a/sys/kern/kgprof.c b/sys/kern/kgprof.c index 0443f8c343..883b0565b4 100644 --- a/sys/kern/kgprof.c +++ b/sys/kern/kgprof.c @@ -6,7 +6,7 @@ #include gmonparam_t _gmonparam = {.state = GMON_PROF_NOT_INIT}; -static gmonhdr_t _gmonhdr = {.profrate = CLK_TCK}; +gmonhdr_t _gmonhdr = {.profrate = CLK_TCK}; /* The macros description are provided in gmon.h */ void init_kgprof(void) { @@ -64,4 +64,4 @@ void kgprof_tick(void) { g->kcount[instr]++; } } -} \ No newline at end of file +} diff --git a/sys/libkern/stdlib/qsort.c b/sys/libkern/stdlib/qsort.c index 77773cb77a..af55b59b81 100644 --- a/sys/libkern/stdlib/qsort.c +++ b/sys/libkern/stdlib/qsort.c @@ -59,7 +59,7 @@ void qsort(void *a, size_t n, size_t es, cmp_t *cmp); } while (--i > 0); \ } -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ +#define SWAPINIT(a, es) swaptype = ((uintptr_t)a) % sizeof(long) || \ es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; static inline void diff --git a/sys/riscv/Makefile b/sys/riscv/Makefile index 7e42230a85..de3bcb344e 100644 --- a/sys/riscv/Makefile +++ b/sys/riscv/Makefile @@ -24,6 +24,8 @@ CPPFLAGS += -D_MACHDEP include $(TOPDIR)/build/build.kern.mk -$(SOURCES-RISCV) riscv.ld.in: assym.h +$(SOURCES-RISCV) : assym.h boot.o : CFLAGS_KASAN = +boot.o : CFLAGS_KCSAN = +boot.o : CFLAGS_KGPROF = diff --git a/sys/riscv/boot.c b/sys/riscv/boot.c index 5077223851..b62106977a 100644 --- a/sys/riscv/boot.c +++ b/sys/riscv/boot.c @@ -14,7 +14,7 @@ * before knowing the physical memory boundaries which are contained in the * DTB itself), * - * - temoprarily mapping kernel page directory into VM (because there is + * - temporarily mapping kernel page directory into VM (because there is * no direct map to access it in the usual fashion), * * - Preparing KASAN shadow memory for the mapped area, @@ -70,50 +70,21 @@ #include #include -extern char __riscv_boot_pa[]; -extern char __boot_stack_pa[]; -extern char __kernel_start_pa[]; -extern char __text_pa[]; -extern char __data_pa[]; -extern char __ebss_pa[]; -extern char __kernel_end_pa[]; +#define PHYSADDR(x) ((paddr_t)((vaddr_t)(x) & ~KERNEL_VIRT) + KERNEL_PHYS) -#define RISCV_VIRTADDR(x) \ - ((vaddr_t)((paddr_t)(x)-KERNEL_PHYS) | KERNEL_SPACE_BEGIN) - -#define KERNEL_VIRT_IMG_END align(RISCV_VIRTADDR(__ebss_pa), PAGESIZE) -#define KERNEL_PHYS_IMG_END align((paddr_t)__ebss_pa, PAGESIZE) - -#define BOOT_KASAN_SANITIZED_SIZE \ - roundup2(roundup2(KERNEL_VIRT_IMG_END, GROWKERNEL_STRIDE) - \ - KASAN_SANITIZED_START, \ +#define BOOT_KASAN_SANITIZED_SIZE(end) \ + roundup2(roundup2((intptr_t)end, GROWKERNEL_STRIDE) - KASAN_SANITIZED_START, \ PAGESIZE * KASAN_SHADOW_SCALE_SIZE) -#define BOOT_KASAN_SHADOW_SIZE \ - (BOOT_KASAN_SANITIZED_SIZE / KASAN_SHADOW_SCALE_SIZE) - #define BOOT_DTB_VADDR DMAP_BASE #define BOOT_PD_VADDR (DMAP_BASE + GROWKERNEL_STRIDE) -/* - * Bare memory boot data. - */ - -/* Last physical address used by kernel for boot memory allocation. */ -__boot_data static void *bootmem_brk; - -__boot_data static pde_t *kernel_pde; - /* * Virtual memory boot data. */ -#define __bss_boot_stack __section(".bss.boot_stack") - /* NOTE: the boot stack is used before we switch out to `thread0`. */ -__bss_boot_stack static __used alignas(STACK_ALIGN) uint8_t - boot_stack[PAGESIZE]; - +static alignas(STACK_ALIGN) uint8_t boot_stack[PAGESIZE]; /* * Bare memory boot functions. */ @@ -123,6 +94,30 @@ __boot_text static __noreturn void halt(void) { __wfi(); } +/* + * Bare memory boot data. + */ + +/* Last physical address used by kernel for boot memory allocation. */ +__boot_data static void *bootmem_brk; + +__boot_data static pde_t *kernel_pde; + +static __noreturn void riscv_boot(paddr_t dtb, paddr_t pde, paddr_t kern_end); + +/* Without `volatile` Clang applies constant propagation optimization and + * that ends up generating relocations in `.text` instead of `.data` section. + * This is exactly what we're trying to avoid here! */ +__boot_data static volatile vaddr_t _kernel_start = (vaddr_t)__kernel_start; +__boot_data static volatile vaddr_t _kernel_end = (vaddr_t)__kernel_end; +__boot_data static volatile paddr_t _boot = (paddr_t)__boot; +__boot_data static volatile paddr_t _eboot = (paddr_t)__eboot; +__boot_data static volatile vaddr_t _ebss = (vaddr_t)__ebss; +__boot_data static volatile vaddr_t _text = (vaddr_t)__text; +__boot_data static volatile vaddr_t _data = (vaddr_t)__data; +__boot_data static volatile vaddr_t _riscv_boot = (vaddr_t)riscv_boot; +__boot_data static volatile vaddr_t _boot_stack = (vaddr_t)boot_stack; + /* * Allocate and clear pages in physical memory just after kernel image end. * The argument will be aligned to `PAGESIZE`. @@ -178,24 +173,22 @@ __boot_text static void early_kenter(vaddr_t va, size_t size, paddr_t pa, } __boot_text __noreturn void riscv_init(paddr_t dtb) { - if (!((paddr_t)__eboot < RISCV_VIRTADDR(__kernel_start_pa) || - RISCV_VIRTADDR(__kernel_end_pa) < (paddr_t)__boot)) + if (!(_eboot < _kernel_start || _kernel_end < _boot)) halt(); /* Initialize boot memory allocator. */ - bootmem_brk = (void *)KERNEL_PHYS_IMG_END; + bootmem_brk = (void *)align(PHYSADDR(_ebss), PAGESIZE); /* Allocate kernel page directory.*/ kernel_pde = bootmem_alloc(PAGESIZE); - const vaddr_t text = RISCV_VIRTADDR(__text_pa); - const vaddr_t data = RISCV_VIRTADDR(__data_pa); + vaddr_t kernel_end = align(_ebss, PAGESIZE); /* Kernel read-only segment - sections: .text and .rodata. */ - early_kenter(text, data - text, (paddr_t)__text_pa, PTE_X | PTE_KERN_RO); + early_kenter(_text, _data - _text, PHYSADDR(_text), PTE_X | PTE_KERN_RO); /* Kernel read-write segment - sections: .data and .bss. */ - early_kenter(data, KERNEL_VIRT_IMG_END - data, (paddr_t)__data_pa, PTE_KERN); + early_kenter(_data, kernel_end - _data, PHYSADDR(_data), PTE_KERN); /* * NOTE: we don't have to map the boot allocation area as the allocated @@ -211,14 +204,15 @@ __boot_text __noreturn void riscv_init(paddr_t dtb) { early_kenter(BOOT_PD_VADDR, PAGESIZE, (paddr_t)kernel_pde, PTE_KERN); #if KASAN - paddr_t shadow_mem = (paddr_t)bootmem_alloc(BOOT_KASAN_SHADOW_SIZE); + size_t shadow_size = + BOOT_KASAN_SANITIZED_SIZE(kernel_end) / KASAN_SHADOW_SCALE_SIZE; + paddr_t shadow_mem = (paddr_t)bootmem_alloc(shadow_size); - early_kenter(KASAN_SHADOW_START, BOOT_KASAN_SHADOW_SIZE, shadow_mem, - PTE_KERN); + early_kenter(KASAN_SHADOW_START, shadow_size, shadow_mem, PTE_KERN); #endif /* !KASAN */ /* Temporarily set the trap vector. */ - csr_write(stvec, RISCV_VIRTADDR(__riscv_boot_pa)); + csr_write(stvec, _riscv_boot); /* * Move to VM boot stage. @@ -229,7 +223,7 @@ __boot_text __noreturn void riscv_init(paddr_t dtb) { const paddr_t satp = SATP_MODE_SV32 | ((paddr_t)kernel_pde >> PAGE_SHIFT); #endif - void *boot_sp = (void *)RISCV_VIRTADDR(__boot_stack_pa) + PAGESIZE; + void *boot_sp = (void *)_boot_stack + PAGESIZE; __sfence_vma(); @@ -265,10 +259,7 @@ extern void cpu_exception_handler(void); extern void *board_stack(paddr_t dtb_pa, void *dtb_va); extern void __noreturn board_init(void); -#define __text_riscv_boot __section(".text.riscv_boot") - -__text_riscv_boot static __noreturn __used void -riscv_boot(paddr_t dtb, paddr_t pde, paddr_t kern_end) { +static __noreturn void riscv_boot(paddr_t dtb, paddr_t pde, paddr_t kern_end) { /* * Set initial register values. */ @@ -296,7 +287,8 @@ riscv_boot(paddr_t dtb, paddr_t pde, paddr_t kern_end) { kern_phys_end = kern_end; #if KASAN - _kasan_sanitized_end = KASAN_SANITIZED_START + BOOT_KASAN_SANITIZED_SIZE; + _kasan_sanitized_end = + KASAN_SANITIZED_START + BOOT_KASAN_SANITIZED_SIZE(__ebss); #endif void *dtb_va = (void *)BOOT_DTB_VADDR + (dtb & (PAGESIZE - 1)); diff --git a/sys/riscv/copy.S b/sys/riscv/copy.S index 4dafceedaf..78b580d6bf 100644 --- a/sys/riscv/copy.S +++ b/sys/riscv/copy.S @@ -1,6 +1,7 @@ #include #include #include +#include #include "assym.h" diff --git a/sys/riscv/genassym.cf b/sys/riscv/genassym.cf index 8d48d56b67..22094945ee 100644 --- a/sys/riscv/genassym.cf +++ b/sys/riscv/genassym.cf @@ -4,9 +4,6 @@ include include include -define USER_SPACE_END USER_SPACE_END -define KERNEL_SPACE_BEGIN KERNEL_SPACE_BEGIN - define TD_KCTX offsetof(thread_t, td_kctx) define TD_UCTX offsetof(thread_t, td_uctx) define TD_ONFAULT offsetof(thread_t, td_onfault) diff --git a/sys/riscv/riscv.ld.in b/sys/riscv/riscv.ld.in index dd3cb4c5ff..fc1b9a4d5e 100644 --- a/sys/riscv/riscv.ld.in +++ b/sys/riscv/riscv.ld.in @@ -1,5 +1,3 @@ -#include "assym.h" - /* Linker scripts are documented here: * https://sourceware.org/binutils/docs/ld/Scripts.html */ OUTPUT_ARCH(riscv) @@ -18,22 +16,20 @@ SECTIONS .boot KERNEL_PHYS : AT(KERNEL_PHYS) ALIGN(4096) { __boot = ABSOLUTE(.); - KEEP(riscv/riscv.ka:start.o) - *(.boot .boot.*) + KEEP(*(.boot)) + *(.boot.text) + *(.boot.data) + *(.boot.bss) . = ALIGN(4096); __eboot = ABSOLUTE(.); } : boot HIDDEN(_boot_size = __eboot - __boot); - .text KERNEL_SPACE_BEGIN + _boot_size : AT(__eboot) ALIGN(4096) + .text KERNEL_VIRT + _boot_size : AT(__eboot) ALIGN(4096) { __kernel_start = ABSOLUTE(.); - __kernel_start_pa = LOADADDR(.text); __text = ABSOLUTE(.); - __text_pa = LOADADDR(.text); - __riscv_boot_pa = LOADADDR(.text); - *(.text.riscv_boot) *(.text .text.*) __etext = ABSOLUTE(.); /* Constructors are used by KASAN to initialize global redzones */ @@ -52,7 +48,6 @@ SECTIONS .data : ALIGN(4096) { __data = ABSOLUTE(.); - __data_pa = LOADADDR(.data); *(.data .data.*) } : data @@ -69,7 +64,6 @@ SECTIONS { /* Load/store instruction offset is 12 bits (sign extended). */ __global_pointer$ = . + 0x800; - __global_pointer$_pa = LOADADDR(.sdata) + 0x800; *(.srodata .srodata.*) *(.sdata .sdata.*) __edata = ABSOLUTE(.); @@ -78,16 +72,12 @@ SECTIONS .bss : { __bss = ABSOLUTE(.); - __boot_stack_pa = LOADADDR(.bss); - *(.bss.boot_stack) *(.sbss .sbss.*) *(.scommon) *(.bss .bss.*) *(COMMON) __ebss = ABSOLUTE(.); - __ebss_pa = LOADADDR(.bss) + SIZEOF(.bss); __kernel_end = ABSOLUTE(.); - __kernel_end_pa = LOADADDR(.bss) + SIZEOF(.bss); } /* Sections to be discarded. */ diff --git a/sys/riscv/start.S b/sys/riscv/start.S index 9aa14170db..d06d46fa39 100644 --- a/sys/riscv/start.S +++ b/sys/riscv/start.S @@ -1,11 +1,14 @@ #include #include +#include #include "assym.h" #define INITSTACK_SIZE 512 - .section .boot + .option nopic + .section .boot,"ax",@progbits + /* * The following entry point is used when booting via SBI firmware. * It must be placed at the beginning of the .boot section. @@ -17,16 +20,9 @@ * - all other registers remain in an undefined state */ _ENTRY(_start) - .option push; - .option norelax; - PTR_LA gp, __global_pointer$_pa; - REG_LI t0, KERNEL_SPACE_BEGIN - REG_LI t1, KERNEL_PHYS - REG_SUB gp, gp, t1 - or gp, gp, t0 - .option pop - - /* + PTR_L gp, _global_pointer + + /* * NOTE: In an actual SMP system, we could have multiple harts * entering the kernel simultaneously. In such case, * we would have to choose the hart to perform the global startup. @@ -34,16 +30,24 @@ _ENTRY(_start) */ /* Move to the initial stack. */ - PTR_LA sp, initstack_end + PTR_LA sp, initstack_end - mv a0, a1 - tail riscv_init + mv a0, a1 + tail riscv_init halt: wfi - j halt + j halt _END(_start) - .section .boot.data + .section .boot.data,"aw",@progbits +_global_pointer: +#if __riscv_xlen == 32 + .long __global_pointer$ +#else + .quad __global_pointer$ +#endif + + .section .boot.bss,"aw",@nobits .align STACK_ALIGN initstack: diff --git a/sys/riscv/trap.c b/sys/riscv/trap.c index 789dffe29a..1bf0caa914 100644 --- a/sys/riscv/trap.c +++ b/sys/riscv/trap.c @@ -252,8 +252,8 @@ __no_profile void trap_handler(ctx_t *ctx) { * frame we consider situation to be critical and panic. * Hopefully sizeof(ctx_t) bytes of unallocated stack space will be enough * to display error message. */ - register_t sp = __sp(); - if ((sp & (PAGESIZE - 1)) < sizeof(ctx_t)) + uintptr_t sp = __sp(); + if (sp < (uintptr_t)td->td_kstack.stk_base + sizeof(ctx_t)) panic("Kernel stack overflow caught at %p!", _REG(ctx, PC)); kframe_saved = td->td_kframe; td->td_kframe = ctx; diff --git a/sys/tests/Makefile b/sys/tests/Makefile index 1170f50323..bc9edb7cb1 100644 --- a/sys/tests/Makefile +++ b/sys/tests/Makefile @@ -8,7 +8,6 @@ SOURCES = \ crash.c \ devfs.c \ kmem.c \ - libfdt.c \ linker_set.c \ mutex.c \ physmem.c \ @@ -35,7 +34,6 @@ SOURCES = \ vfs.c \ vmem.c -OBJECTS += fake_dtb.o CPPFLAGS = -DKL_LOG=KL_TEST include $(TOPDIR)/build/build.kern.mk diff --git a/sys/tests/fake.dts b/sys/tests/fake.dts deleted file mode 100644 index e3e9dc3177..0000000000 --- a/sys/tests/fake.dts +++ /dev/null @@ -1,87 +0,0 @@ -/dts-v1/; - -/ { - model = "MIPS Malta-R"; - compatible = "mti,malta"; - - cpus { - cpu@0 { - compatible = "mti,mips14KEc", "mti,mips14Kc"; - }; - }; - - memory { - device_type = "memory"; - reg = <0x0 0x8000000>; - }; - - root@0 { - #address-cells = <1>; - #size-cells = <1>; - #id-cells = <1>; - - cbus@0 { - compatible = "cbus"; - reg = <0x1f000000 0x100000 0x0>; - #address-cells = <1>; - #size-cells = <1>; - #id-cells = <1>; - - serial@0 { - compatible = "ns16550"; - reg = <0x900 0x40 0x0>; - }; - }; - - pci@0 { - compatible = "pci"; - reg = <0x10000000 0x800000 0x0 - 0x18000000 0x3e00000 0x1>; - - - isa@0 { - reg = <0x0 0x1000 0x0>; - - compatible = "isa"; - #address-cells = <1>; - #size-cells = <1>; - #id-cells = <1>; - #interrupt-cells = <1>; - - rtc@0 { - compatible = "rtc"; - reg = <0x70 0x10 0x0>; - interrupts = <8>; - }; - - atkbdc@0 { - compatible = "atkbdc"; - reg = <0x60 0x1 0x0 - 0x64 0x1 0x1>; - interrupts = <1>; - }; - - pit@0 { - compatible = "pit"; - reg = <0x40 0x10 0x0>; - interrupts = <0>; - }; - - serial@0 { - compatible = "ns16550"; - reg = <0x3f8 0x40 0x0>; - interrupts = <3>; - }; - - serial@1 { - compatible = "ns16550"; - reg = <0x2f8 0x40 0x0>; - interrupts = <4>; - }; - - }; - }; - - }; -}; - diff --git a/sys/tests/libfdt.c b/sys/tests/libfdt.c deleted file mode 100644 index 6ada885d1b..0000000000 --- a/sys/tests/libfdt.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include - -#define BUF_SIZE 64 - -extern uint8_t __fake_dtb_start[]; -static const void *fdt = (const void *)__fake_dtb_start; - -static int test_fdt_get_path(void) { - const char *path = "/root@0/cbus@0/serial@0"; - char buf[BUF_SIZE]; - - int offset = fdt_path_offset(fdt, path); - fdt_get_path(fdt, offset, buf, BUF_SIZE); - - assert(!strcmp(path, buf)); - - return KTEST_SUCCESS; -} - -static int test_fdt_get_name(void) { - const char *path = "/root@0/pci@0/isa@0/serial@1"; - const char *name = "serial@1"; - int len; - - int offset = fdt_path_offset(fdt, path); - const char *retval = fdt_get_name(fdt, offset, &len); - - assert(retval); - assert(len == (int)strlen(name)); - assert(!(strcmp(name, retval))); - - return KTEST_SUCCESS; -} - -static int test_fdt_subnode(void) { - const char *path = "/root@0/pci@0/isa@0"; - const char *name_first = "rtc@0"; - const char *name_next = "atkbdc@0"; - const char *retval; - int offset; - int len; - - offset = fdt_path_offset(fdt, path); - offset = fdt_first_subnode(fdt, offset); - assert(offset != -FDT_ERR_NOTFOUND); - retval = fdt_get_name(fdt, offset, &len); - - assert(retval); - assert(len == (int)strlen(name_first)); - assert(!(strcmp(name_first, retval))); - - offset = fdt_next_subnode(fdt, offset); - assert(offset != -FDT_ERR_NOTFOUND); - retval = fdt_get_name(fdt, offset, &len); - - assert(retval); - assert(len == (int)strlen(name_next)); - assert(!(strcmp(name_next, retval))); - - return KTEST_SUCCESS; -} - -static int test_fdt_getprop(void) { - const char *path = "/root@0/pci@0/isa@0"; - const char *name = "compatible"; - const char *prop; - int offset; - int len; - - offset = fdt_path_offset(fdt, path); - prop = (const char *)fdt_getprop(fdt, offset, name, &len); - - assert(prop); - /* NULL byte */ - assert(len == (int)strlen("isa") + 1); - assert(!strcmp(prop, "isa")); - - return KTEST_SUCCESS; -} - -KTEST_ADD(fdt_get_path, test_fdt_get_path, 0); -KTEST_ADD(fdt_get_name, test_fdt_get_name, 0); -KTEST_ADD(fdt_subnode, test_fdt_subnode, 0); -KTEST_ADD(fdt_getprop, test_fdt_getprop, 0); diff --git a/usr.bin/su/Makefile b/usr.bin/su/Makefile index b0bfc5f91f..d911024ad0 100644 --- a/usr.bin/su/Makefile +++ b/usr.bin/su/Makefile @@ -4,8 +4,7 @@ PROGRAM = su SOURCES = su.c suutil.c FORMAT-EXCLUDE = $(SOURCES) BINMODE = 4755 - -include $(TOPDIR)/build/build.prog.mk - CFLAGS += -Wno-format-nonliteral LDLIBS = -lutil + +include $(TOPDIR)/build/build.prog.mk