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