Skip to content

Commit 0700030

Browse files
committed
userland: support arch specific examples
1 parent 454af5d commit 0700030

File tree

12 files changed

+78
-2
lines changed

12 files changed

+78
-2
lines changed

README.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10396,6 +10396,20 @@ help architecture
1039610396

1039710397
shows ARM version up to `armv6`, so maybe `armv6` is not implemented?
1039810398

10399+
=== ARM EL
10400+
10401+
Find the ARM EL: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
10402+
10403+
Prints the EL at the beginning of a baremetal simulation:
10404+
10405+
....
10406+
./run --arch aarch64 --baremetal arch/aarch64/el
10407+
....
10408+
10409+
Source: link:baremetal/arch/aarch64/el.c[]
10410+
10411+
The lower ELs are not mandatory, and in gem5 at least you can configure the lowest EL with configuration options TODO which, example.
10412+
1039910413
=== How we got some baremetal stuff to work
1040010414

1040110415
It is nice when thing just work.

baremetal/arch/aarch64/el.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
4+
int main(void) {
5+
register uint64_t x0 __asm__ ("x0");
6+
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
7+
printf("%" PRIu64 "\n", x0);
8+
return 0;
9+
}

build-userland

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ has the OpenBLAS libraries and headers installed.
5858
[
5959
'make', common.Newline,
6060
'-j', str(args.nproc), common.Newline,
61+
'ARCH={}'.format(args.arch), common.Newline,
6162
'CCFLAGS_SCRIPT={} {}'.format('-I', common.userland_src_dir), common.Newline,
6263
'COMMON_DIR={}'.format(common.root_dir), common.Newline,
6364
'CC={}'.format(cc), common.Newline,

userland/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.PHONY: all clean mkdir
22

3+
ARCH = $(shell uname -m)
34
CCFLAGS = -ggdb3 -I$(COMMON_DIR) -O0 -Wall -Werror -Wextra -Wno-unused-function $(CCFLAGS_EXTRA) $(CCFLAGS_SCRIPT)
45
CFLAGS = -fopenmp -std=c99 $(CCFLAGS) $(CFLAGS_EXTRA)
56
CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA)
@@ -8,6 +9,7 @@ CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA)
89
COMMON_DIR = $(CURDIR)/..
910
COMMON_BASENAME = common
1011
COMMON_OBJ = $(OUT_DIR)/$(COMMON_BASENAME)$(OBJ_EXT)
12+
IN_EXT_ASM = .S
1113
IN_EXT_C = .c
1214
IN_EXT_CXX = .cpp
1315
LIBS = -lm
@@ -17,7 +19,7 @@ OUT_DIR = $(CURDIR)
1719

1820
-include params.mk
1921

20-
OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))))
22+
OUTS := $(foreach IN_EXT,$(IN_EXT_ASM) $(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))))
2123
ifeq ($(HAS_EIGEN),y)
2224
CXXFLAGS_EXTRA += -I$(STAGING_DIR)/usr/include/eigen3
2325
# TODO: was failing with:
@@ -50,6 +52,9 @@ all: mkdir $(OUTS)
5052
$(COMMON_OBJ): $(COMMON_DIR)/$(COMMON_BASENAME)$(IN_EXT_C)
5153
$(CC) $(CFLAGS) -c -o '$@' '$<' $(LIBS)
5254

55+
$(OUT_DIR)/%$(OUT_EXT): %$(IN_EXT_ASM) $(COMMON_OBJ)
56+
$(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS)
57+
5358
$(OUT_DIR)/%$(OUT_EXT): %$(IN_EXT_C) $(COMMON_OBJ)
5459
$(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS)
5560

userland/arch/aarch64/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile

userland/arch/aarch64/asm_hello.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <assert.h>
2+
#include <inttypes.h>
3+
4+
int main(void) {
5+
register uint32_t x0 __asm__ ("x0");
6+
__asm__ ("mov x0, #1;" : : : "%x0");
7+
assert(x0 == 1);
8+
}

userland/arch/aarch64/params.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMMON_DIR = ../../..

userland/arch/x86_64/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile

userland/arch/x86_64/asm_hello.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
#include <inttypes.h>
3+
4+
int main(void) {
5+
uint32_t in = 1;
6+
uint32_t out = 0;
7+
__asm__ (
8+
"movl %1, %%eax;"
9+
"inc %%eax;"
10+
"movl %%eax, %0"
11+
: "=m" (out)
12+
: "m" (in)
13+
: "%eax"
14+
);
15+
assert(out == in + 1);
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.data
2+
s:
3+
.ascii "hello\n"
4+
len = . - s
5+
.text
6+
.global _start
7+
_start:
8+
9+
/* Write. */
10+
mov $1, %rax
11+
mov $1, %rdi
12+
mov $s, %rsi
13+
mov $len, %rdx
14+
syscall
15+
16+
/* Exit. */
17+
mov $60, %rax
18+
mov $0, %rdi
19+
syscall

0 commit comments

Comments
 (0)