#include <linux/module.h>
#include <linux/kernel.h>

static int myinit(void)
{
	pr_info("hello init\n");
	/* 0 for success, any negative value means failure,
	 * E* consts if you want to specify failure cause.
	 * https://www.linux.com/learn/kernel-newbie-corner-loadable-kernel-modules-coming-and-going */
	return 0;
}

static void myexit(void)
{
	pr_info("hello exit\n");
}

module_init(myinit)
module_exit(myexit)
MODULE_LICENSE("GPL");
Assertions! The best way to learn assembly.
#include <lkmc.h>

LKMC_PROLOGUE
    /* Register immediate. */
    mov $1, %rax
    add $2, %rax
    LKMC_ASSERT_EQ(%rax, $3)
LKMC_EPILOGUE
Powered by crosstool-NG:
.global main
main:
    /* 0x20026 == ADP_Stopped_ApplicationExit */
    mov x1, 0x26
    movk x1, 2, lsl 16
    str x1, [sp, 0]

    /* Exit status code. Host QEMU process exits with that status. */
    mov x0, 0
    str x0, [sp, 8]

    /* x1 contains the address of parameter block.
     * Any memory address could be used.
     */
    mov x1, sp

    /* SYS_EXIT */
    mov w0, 0x18

    /* Do the semihosting call on A64. */
    hlt 0xf000

Articles by others on the same topic (0)

There are currently no matching articles.