userland: support arch specific examples

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-11-20 00:00:00 +00:00
parent 454af5d03a
commit 07000300ab
12 changed files with 78 additions and 2 deletions

View File

@@ -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.

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
#include <inttypes.h>
int main(void) {
register uint64_t x0 __asm__ ("x0");
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
printf("%" PRIu64 "\n", x0);
return 0;
}

View File

@@ -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,

View File

@@ -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)

View File

@@ -0,0 +1 @@
../../Makefile

View File

@@ -0,0 +1,8 @@
#include <assert.h>
#include <inttypes.h>
int main(void) {
register uint32_t x0 __asm__ ("x0");
__asm__ ("mov x0, #1;" : : : "%x0");
assert(x0 == 1);
}

View File

@@ -0,0 +1 @@
COMMON_DIR = ../../..

View File

@@ -0,0 +1 @@
../../Makefile

View File

@@ -0,0 +1,16 @@
#include <assert.h>
#include <inttypes.h>
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);
}

View File

@@ -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

View File

@@ -0,0 +1 @@
COMMON_DIR = ../../..

View File

@@ -1 +1 @@
SUBDIRS := interactive
SUBDIRS := interactive arch/$(ARCH)/