Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:26:41+00:00 2026-06-15T16:26:41+00:00

I try write simple kernel module (v3.6) in nasm, but insmod say me: $

  • 0

I try write simple kernel module (v3.6) in nasm, but insmod say me:

$ sudo insmod  ./hello.ko
insmod: ERROR: could not insert module ./hello.ko: Invalid module format
$ echo $?
1

I compile my code with:

$ nasm -f elf64 -o hello.m hello.asm
$ ld -m elf_x86_64 -r -o hello.ko hello.m

and my module code:

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 rbp
    mov rbp, rsp

    xor rax, rax
    mov rdi, init_mess
    call printk

    xor rax, rax
    mov rsp, rbp
    pop rbp
    ret

cleanup_module:
    push rbp
    mov rbp, rsp

    xor rax, rax
    mov rdi, cleanup_mess
    call printk

    xor rax, rax
    mov rsp, rbp
    pop rbp
    ret

Please help. In internets i found 1 link with equal code for 2.4, but he doesnt work too
My system – archlinux with 3.6.8 kernel

UPDATE:
in nasm forum i find thread with interesting solution. It’s work for me, if my module do return 0 and exit 🙂 But if i try add “extern printk” the insmod say me next:

ERROR: could not insert module hello.ko: Invalid parameters

What i’m doing wrong? my code:

[bits 64]

global init_module
global cleanup_module

;extern printk

section .modinfo
    __mod_description8  db   'description=Simple module',0
    align 16,db 0
    __mod_author7       db   'author=That´s me',0
    __mod_license6      db   'license=GPL',0
    align 16,db 0
    __module_depends    db   'depends=',0
    align 32,db 0
    __mod_vermagic5     db   'vermagic=3.6.8-1-ARCH SMP preempt mod_unload modversions ',0   ;from a .ko module of my system

section __versions
    ____versions      db   0xdf, 0xbc, 0xbf, 0x8c, 0, 0, 0, 0, "module_layout"   ;from a .ko module of my system
    align 64,db 0

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


section .text

init_module:
    xor rax, rax
    ret

cleanup_module:
    xor rax, rax
    ret

section .gnu.linkonce.this_module
    times 24 db 0
__name:         db  'Simple', 0
    times (0x168 - 24 - 7) db 0
__init_module:      dq  init_module
    times 0x2ac db 0
__cleanup_module:   dq  cleanup_module
    times 1152 db 0

this code work with:
nasm -f elf64 hello.asm -o hello.o

but if i uncomment printk this no working!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:26:42+00:00Added an answer on June 15, 2026 at 4:26 pm

    What I did was write a small C wrapper using the standard module macros and link it with the main module code that’s written in asm. Use the normal kernel build system to build it.

    module.c:

        #include <linux/module.h>
        MODULE_AUTHOR("A. U. Thor");
        MODULE_DESCRIPTION("Description");
        MODULE_LICENSE("GPL");
        extern int asm_init(void);
        int main_init(void)
        {
            return asm_init();
        }
        module_init(main_init);
    

    main.asm:

        [bits 64]
        global asm_init
        asm_init:
            xor rax, rax
            ret
    

    Makefile:

    obj-m += test.o
    test-objs := module.o main.o
    $(KBUILD_EXTMOD)/main.o: main.asm
            nasm -f elf64 -o $@ $^
    
    obj-m += memory_asm.o
    memory_asm-objs := module.o main.o
    $(KBUILD_EXTMOD)/main.o: $(src)/main.asm
        nasm -f elf64 -o $@ $^ && echo "" > $(src)/.main.o.cmd
    

    Build using command: make -C <path_to_kernel_src> M=$PWD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a simple try/catch statement, but I keep on getting
I want to try write a simple kernel in C# like cosmos, just for
hello i got a problem, whenever i try to write any simple thing inside
I try to write a simple user script to enlarge the picture when you
I try to write the following in latex: \begin{itemize} \item \textbf{insert(element|text)} inserts the element
I try to write :ab in Vim for faster coding but the question is
I try to write a site with CodeIgniter but I've a problem with PHP.
I try to write some simple rules and I get this ambiguity rule: field1
I try to write a simple MFC - Word Automation to save for every
I'm getting an error that Constraint is not in scope, when I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.