小编Ale*_*kov的帖子

在汇编程序中编写x86_64 linux内核模块

我尝试在nasm中编写简单的内核模块(v3.6),但insmod说我:

$ sudo insmod  ./hello.ko
insmod: ERROR: could not insert module ./hello.ko: Invalid module format
$ echo $?
1
Run Code Online (Sandbox Code Playgroud)

我编译我的代码:

$ nasm -f elf64 -o hello.m hello.asm
$ ld -m elf_x86_64 -r -o hello.ko hello.m
Run Code Online (Sandbox Code Playgroud)

和我的模块代码:

section .modinfo
    __mod_kernel_version db "kernel_version=3.6.8", 0
    __mod_license        db "license=GPL", 0
    __mod_author         db "author=actics", 0
    __mod_description    db "description=hello world module in nasm", 0


section .data
    init_mess    db "init_module", 10, 0
    cleanup_mess db "cleanup_module", 10, 0


section .text
    global init_module
    global cleanup_module

    extern printk

init_module:
    push …
Run Code Online (Sandbox Code Playgroud)

assembly x86-64 kernel-module linux-kernel

8
推荐指数
1
解决办法
2823
查看次数

ANTLR中的布尔和算术表达式语法

我正在尝试为算术和布尔表达式编写语法.我不明白我做错了什么.对于我的语法,ANTLR说:

[致命]规则logic_atom由于从alts 1,2可到达的递归规则调用而具有非LL(*)决策.通过左因子分解或使用语法谓词或使用backtrack = true选项来解析.

但我不能做左派因素.而且我不想触摸arith_expr,因为为此,我有一个代码.

错误 logic_atom : LBR logic_expr RBR | cmp_expr ;

我的代码:

grammar ArithmeticInterpreter;

options { 
    output = AST;
    language = C;
}
//options{greedy=true;}:

axiom : lines EOF! ;
lines : line (SEP! line)* ;
line  : (def_var | print_expr | scan_expr)? ;

def_var    : VARIABLE ASSIGMENT^ logic_expr ;
print_expr : PRINT_KEYW^ arith_expr ;
scan_expr  : SCAN_KEYW^ VARIABLE ;

arith_expr : ((PLS | MNS)^)? term ((PLS | MNS)^ term)*;
term       : power ((MLP | …
Run Code Online (Sandbox Code Playgroud)

compiler-construction grammar antlr antlr3

5
推荐指数
1
解决办法
3276
查看次数