From 07000300ab56854694fea54d4c188df80b8915df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 20 Nov 2018 00:00:00 +0000 Subject: [PATCH] userland: support arch specific examples --- README.adoc | 14 ++++++++++++++ baremetal/arch/aarch64/el.c | 9 +++++++++ build-userland | 1 + userland/Makefile | 7 ++++++- userland/arch/aarch64/Makefile | 1 + userland/arch/aarch64/asm_hello.c | 8 ++++++++ userland/arch/aarch64/params.mk | 1 + userland/arch/x86_64/Makefile | 1 + userland/arch/x86_64/asm_hello.c | 16 ++++++++++++++++ userland/arch/x86_64/freestanding/hello.S | 19 +++++++++++++++++++ userland/arch/x86_64/params.mk | 1 + userland/params.mk | 2 +- 12 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 baremetal/arch/aarch64/el.c create mode 120000 userland/arch/aarch64/Makefile create mode 100644 userland/arch/aarch64/asm_hello.c create mode 100644 userland/arch/aarch64/params.mk create mode 120000 userland/arch/x86_64/Makefile create mode 100644 userland/arch/x86_64/asm_hello.c create mode 100644 userland/arch/x86_64/freestanding/hello.S create mode 100644 userland/arch/x86_64/params.mk diff --git a/README.adoc b/README.adoc index 5413531..cd13a27 100644 --- a/README.adoc +++ b/README.adoc @@ -10396,6 +10396,20 @@ help architecture shows ARM version up to `armv6`, so maybe `armv6` is not implemented? +=== ARM EL + +Find the ARM EL: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc + +Prints the EL at the beginning of a baremetal simulation: + +.... +./run --arch aarch64 --baremetal arch/aarch64/el +.... + +Source: link:baremetal/arch/aarch64/el.c[] + +The lower ELs are not mandatory, and in gem5 at least you can configure the lowest EL with configuration options TODO which, example. + === How we got some baremetal stuff to work It is nice when thing just work. diff --git a/baremetal/arch/aarch64/el.c b/baremetal/arch/aarch64/el.c new file mode 100644 index 0000000..be7019d --- /dev/null +++ b/baremetal/arch/aarch64/el.c @@ -0,0 +1,9 @@ +#include +#include + +int main(void) { + register uint64_t x0 __asm__ ("x0"); + __asm__ ("mrs x0, CurrentEL;" : : : "%x0"); + printf("%" PRIu64 "\n", x0); + return 0; +} diff --git a/build-userland b/build-userland index ca6c012..3a7e527 100755 --- a/build-userland +++ b/build-userland @@ -58,6 +58,7 @@ has the OpenBLAS libraries and headers installed. [ 'make', common.Newline, '-j', str(args.nproc), common.Newline, + 'ARCH={}'.format(args.arch), common.Newline, 'CCFLAGS_SCRIPT={} {}'.format('-I', common.userland_src_dir), common.Newline, 'COMMON_DIR={}'.format(common.root_dir), common.Newline, 'CC={}'.format(cc), common.Newline, diff --git a/userland/Makefile b/userland/Makefile index 2ede102..a02e229 100644 --- a/userland/Makefile +++ b/userland/Makefile @@ -1,5 +1,6 @@ .PHONY: all clean mkdir +ARCH = $(shell uname -m) CCFLAGS = -ggdb3 -I$(COMMON_DIR) -O0 -Wall -Werror -Wextra -Wno-unused-function $(CCFLAGS_EXTRA) $(CCFLAGS_SCRIPT) CFLAGS = -fopenmp -std=c99 $(CCFLAGS) $(CFLAGS_EXTRA) CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA) @@ -8,6 +9,7 @@ CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA) COMMON_DIR = $(CURDIR)/.. COMMON_BASENAME = common COMMON_OBJ = $(OUT_DIR)/$(COMMON_BASENAME)$(OBJ_EXT) +IN_EXT_ASM = .S IN_EXT_C = .c IN_EXT_CXX = .cpp LIBS = -lm @@ -17,7 +19,7 @@ OUT_DIR = $(CURDIR) -include params.mk -OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT))))) +OUTS := $(foreach IN_EXT,$(IN_EXT_ASM) $(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT))))) ifeq ($(HAS_EIGEN),y) CXXFLAGS_EXTRA += -I$(STAGING_DIR)/usr/include/eigen3 # TODO: was failing with: @@ -50,6 +52,9 @@ all: mkdir $(OUTS) $(COMMON_OBJ): $(COMMON_DIR)/$(COMMON_BASENAME)$(IN_EXT_C) $(CC) $(CFLAGS) -c -o '$@' '$<' $(LIBS) +$(OUT_DIR)/%$(OUT_EXT): %$(IN_EXT_ASM) $(COMMON_OBJ) + $(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS) + $(OUT_DIR)/%$(OUT_EXT): %$(IN_EXT_C) $(COMMON_OBJ) $(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS) diff --git a/userland/arch/aarch64/Makefile b/userland/arch/aarch64/Makefile new file mode 120000 index 0000000..94aaae2 --- /dev/null +++ b/userland/arch/aarch64/Makefile @@ -0,0 +1 @@ +../../Makefile \ No newline at end of file diff --git a/userland/arch/aarch64/asm_hello.c b/userland/arch/aarch64/asm_hello.c new file mode 100644 index 0000000..3765aea --- /dev/null +++ b/userland/arch/aarch64/asm_hello.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) { + register uint32_t x0 __asm__ ("x0"); + __asm__ ("mov x0, #1;" : : : "%x0"); + assert(x0 == 1); +} diff --git a/userland/arch/aarch64/params.mk b/userland/arch/aarch64/params.mk new file mode 100644 index 0000000..4a24c37 --- /dev/null +++ b/userland/arch/aarch64/params.mk @@ -0,0 +1 @@ +COMMON_DIR = ../../.. diff --git a/userland/arch/x86_64/Makefile b/userland/arch/x86_64/Makefile new file mode 120000 index 0000000..94aaae2 --- /dev/null +++ b/userland/arch/x86_64/Makefile @@ -0,0 +1 @@ +../../Makefile \ No newline at end of file diff --git a/userland/arch/x86_64/asm_hello.c b/userland/arch/x86_64/asm_hello.c new file mode 100644 index 0000000..6002371 --- /dev/null +++ b/userland/arch/x86_64/asm_hello.c @@ -0,0 +1,16 @@ +#include +#include + +int main(void) { + uint32_t in = 1; + uint32_t out = 0; + __asm__ ( + "movl %1, %%eax;" + "inc %%eax;" + "movl %%eax, %0" + : "=m" (out) + : "m" (in) + : "%eax" + ); + assert(out == in + 1); +} diff --git a/userland/arch/x86_64/freestanding/hello.S b/userland/arch/x86_64/freestanding/hello.S new file mode 100644 index 0000000..f58f967 --- /dev/null +++ b/userland/arch/x86_64/freestanding/hello.S @@ -0,0 +1,19 @@ +.data + s: + .ascii "hello\n" + len = . - s +.text + .global _start + _start: + + /* Write. */ + mov $1, %rax + mov $1, %rdi + mov $s, %rsi + mov $len, %rdx + syscall + + /* Exit. */ + mov $60, %rax + mov $0, %rdi + syscall diff --git a/userland/arch/x86_64/params.mk b/userland/arch/x86_64/params.mk new file mode 100644 index 0000000..4a24c37 --- /dev/null +++ b/userland/arch/x86_64/params.mk @@ -0,0 +1 @@ +COMMON_DIR = ../../.. diff --git a/userland/params.mk b/userland/params.mk index f2ee443..eb2a8ce 100644 --- a/userland/params.mk +++ b/userland/params.mk @@ -1 +1 @@ -SUBDIRS := interactive +SUBDIRS := interactive arch/$(ARCH)/