mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
userland: support arch specific examples
This commit is contained in:
14
README.adoc
14
README.adoc
@@ -10396,6 +10396,20 @@ help architecture
|
|||||||
|
|
||||||
shows ARM version up to `armv6`, so maybe `armv6` is not implemented?
|
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
|
=== How we got some baremetal stuff to work
|
||||||
|
|
||||||
It is nice when thing just work.
|
It is nice when thing just work.
|
||||||
|
|||||||
9
baremetal/arch/aarch64/el.c
Normal file
9
baremetal/arch/aarch64/el.c
Normal 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;
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ has the OpenBLAS libraries and headers installed.
|
|||||||
[
|
[
|
||||||
'make', common.Newline,
|
'make', common.Newline,
|
||||||
'-j', str(args.nproc), common.Newline,
|
'-j', str(args.nproc), common.Newline,
|
||||||
|
'ARCH={}'.format(args.arch), common.Newline,
|
||||||
'CCFLAGS_SCRIPT={} {}'.format('-I', common.userland_src_dir), common.Newline,
|
'CCFLAGS_SCRIPT={} {}'.format('-I', common.userland_src_dir), common.Newline,
|
||||||
'COMMON_DIR={}'.format(common.root_dir), common.Newline,
|
'COMMON_DIR={}'.format(common.root_dir), common.Newline,
|
||||||
'CC={}'.format(cc), common.Newline,
|
'CC={}'.format(cc), common.Newline,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
.PHONY: all clean mkdir
|
.PHONY: all clean mkdir
|
||||||
|
|
||||||
|
ARCH = $(shell uname -m)
|
||||||
CCFLAGS = -ggdb3 -I$(COMMON_DIR) -O0 -Wall -Werror -Wextra -Wno-unused-function $(CCFLAGS_EXTRA) $(CCFLAGS_SCRIPT)
|
CCFLAGS = -ggdb3 -I$(COMMON_DIR) -O0 -Wall -Werror -Wextra -Wno-unused-function $(CCFLAGS_EXTRA) $(CCFLAGS_SCRIPT)
|
||||||
CFLAGS = -fopenmp -std=c99 $(CCFLAGS) $(CFLAGS_EXTRA)
|
CFLAGS = -fopenmp -std=c99 $(CCFLAGS) $(CFLAGS_EXTRA)
|
||||||
CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA)
|
CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA)
|
||||||
@@ -8,6 +9,7 @@ CXXFLAGS = -std=c++17 $(CCFLAGS) $(CXXFLAGS_EXTRA)
|
|||||||
COMMON_DIR = $(CURDIR)/..
|
COMMON_DIR = $(CURDIR)/..
|
||||||
COMMON_BASENAME = common
|
COMMON_BASENAME = common
|
||||||
COMMON_OBJ = $(OUT_DIR)/$(COMMON_BASENAME)$(OBJ_EXT)
|
COMMON_OBJ = $(OUT_DIR)/$(COMMON_BASENAME)$(OBJ_EXT)
|
||||||
|
IN_EXT_ASM = .S
|
||||||
IN_EXT_C = .c
|
IN_EXT_C = .c
|
||||||
IN_EXT_CXX = .cpp
|
IN_EXT_CXX = .cpp
|
||||||
LIBS = -lm
|
LIBS = -lm
|
||||||
@@ -17,7 +19,7 @@ OUT_DIR = $(CURDIR)
|
|||||||
|
|
||||||
-include params.mk
|
-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)
|
ifeq ($(HAS_EIGEN),y)
|
||||||
CXXFLAGS_EXTRA += -I$(STAGING_DIR)/usr/include/eigen3
|
CXXFLAGS_EXTRA += -I$(STAGING_DIR)/usr/include/eigen3
|
||||||
# TODO: was failing with:
|
# TODO: was failing with:
|
||||||
@@ -50,6 +52,9 @@ all: mkdir $(OUTS)
|
|||||||
$(COMMON_OBJ): $(COMMON_DIR)/$(COMMON_BASENAME)$(IN_EXT_C)
|
$(COMMON_OBJ): $(COMMON_DIR)/$(COMMON_BASENAME)$(IN_EXT_C)
|
||||||
$(CC) $(CFLAGS) -c -o '$@' '$<' $(LIBS)
|
$(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)
|
$(OUT_DIR)/%$(OUT_EXT): %$(IN_EXT_C) $(COMMON_OBJ)
|
||||||
$(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS)
|
$(CC) $(CFLAGS) $(COMMON_OBJ) -o '$@' '$<' $(LIBS)
|
||||||
|
|
||||||
|
|||||||
1
userland/arch/aarch64/Makefile
Symbolic link
1
userland/arch/aarch64/Makefile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../Makefile
|
||||||
8
userland/arch/aarch64/asm_hello.c
Normal file
8
userland/arch/aarch64/asm_hello.c
Normal 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);
|
||||||
|
}
|
||||||
1
userland/arch/aarch64/params.mk
Normal file
1
userland/arch/aarch64/params.mk
Normal file
@@ -0,0 +1 @@
|
|||||||
|
COMMON_DIR = ../../..
|
||||||
1
userland/arch/x86_64/Makefile
Symbolic link
1
userland/arch/x86_64/Makefile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../Makefile
|
||||||
16
userland/arch/x86_64/asm_hello.c
Normal file
16
userland/arch/x86_64/asm_hello.c
Normal 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);
|
||||||
|
}
|
||||||
19
userland/arch/x86_64/freestanding/hello.S
Normal file
19
userland/arch/x86_64/freestanding/hello.S
Normal 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
|
||||||
1
userland/arch/x86_64/params.mk
Normal file
1
userland/arch/x86_64/params.mk
Normal file
@@ -0,0 +1 @@
|
|||||||
|
COMMON_DIR = ../../..
|
||||||
@@ -1 +1 @@
|
|||||||
SUBDIRS := interactive
|
SUBDIRS := interactive arch/$(ARCH)/
|
||||||
|
|||||||
Reference in New Issue
Block a user