flat assembler
Message board for the users of flat assembler.

Index > Linux > [SOLVED] Kernel modules in assembly (2.6.x)

Author
Thread Post new topic Reply to topic
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7 03 Jun 2006, 18:00
Hi,
i tried to make ,,Hello world'' kernel module (for 2.6.x kernel).
Code (based on ,,modul_dev_fasm'' by BogDro):

Code:
format ELF

public  init_module
public  cleanup_module
extrn   printk

;==============================================================
section '.text' executable
init_module:
        push    ebx ecx edx esi
        push    msg
        call    printk
        add     esp,4

        xor     eax, eax
        pop     esi edx ecx ebx
        ret

cleanup_module:
        ret

;=============================================================
section '.data' writeable
; printk codes
;    <0> Kernel Emergency
;    <1> Kernel Alert
;    <2> Kernel Critical Condition
;    <3> Kernel Error
;    <4> Kernel Warning
;    <5> Kernel Notice
;    <6> Kernel Info
;    <7> Kernel Debug
    
msg db "<1> Hello world!",10,0

;=============================================================

section '.modinfo'
__module_kernel_version db      "vermagic=2.6.17-beyond-git1 preempt mod_unload K7 REGPARM 4KSTACKS gcc-4.1", 0
__module_license        db      "license=GPL", 0
__module_author         db      "author=p7", 0
__module_description    db      "description=Hello World", 0
__module_depends        db      "depends=",0

    

But it doesn't work. Crying or Very sad
hello_world# insmod ./hello_world.o shows:
Quote:
insmod: error inserting './hello_world.o': -1 Invalid module format

syslogd shows:
Quote:
No module found in object

Maybe someone know what is needed to make this module loaded?

_________________
best regards
p7


Last edited by polygon7 on 27 Aug 2006, 19:34; edited 1 time in total
Post 03 Jun 2006, 18:00
View user's profile Send private message Visit poster's website Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 514
Location: Czech republic, Slovak republic
Feryno 05 Jun 2006, 08:33
Years ago, I read article by mammon_ in asmjournal (apj_8) about loadable kernel modules and I tried it, but without success too.
I suppose that kernel module loader checks module info whether it match kernel version and maybe the date too.
1 stupid question: Have you copied it into lib/modules/... and tried depmod before insmod (did module name appear in modules.dep file)? I tried everything years ago, but nothing made it to work... but it was on my Linux asm early begins, maybe some trivial error in code...
Post 05 Jun 2006, 08:33
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7 05 Jun 2006, 20:14
Feryno wrote:
Years ago, I read article by mammon_ in asmjournal (apj_8) about loadable kernel modules and I tried it, but without success too.
I suppose that kernel module loader checks module info whether it match kernel version and maybe the date too.
1 stupid question: Have you copied it into lib/modules/... and tried depmod before insmod (did module name appear in modules.dep file)? I tried everything years ago, but nothing made it to work... but it was on my Linux asm early begins, maybe some trivial error in code...

I know about mammon article, but his code don't work in 2.6.x.
Kernel version is the same, so this is not that error.

BogDro on Polish fasm forum says that there are some problems with makefiles and link stage.
Modules, for example: some_module.ko, are maked from some_module.o files and some_module.mod.o files.
But there is a question... how *.mod.o files are created (they are needed for correct module linking)?

_________________
best regards
p7
Post 05 Jun 2006, 20:14
View user's profile Send private message Visit poster's website Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 11 Aug 2006, 10:57
iirc starting from 2.6.x the kernel uses a "new module format", you see the change inthe name, in the old days the moudles ended with .o, now they end in .ko (kernel object).
Afaik basically all "out side" modules invoke the kernel Makefile system with various options (ie nvidias driver compiles part of it self but also provides a binary blob (=the propitary part) which is simply linked in). I'd suggest you take a look at nvidias drivers (download the latest and run with "./NVIDIA-something -x" to extract the sfx (iirc, use '-h' if it doesn't work)) - they also show how to link in "external" objects (in nividia's case, source less files).

Here's some info that might help (only scimmed thorugh them though)
http://www.captain.at/programming/kernel-2.6/
http://www.tldp.org/LDP/lkmpg/2.6/html/x380.html
http://linuxdevices.com/articles/AT4389927951.html
Post 11 Aug 2006, 10:57
View user's profile Send private message Visit poster's website Reply with quote
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7 11 Aug 2006, 11:13
scientica wrote:
iirc starting from 2.6.x the kernel uses a "new module format", you see the change inthe name, in the old days the moudles ended with .o, now they end in .ko (kernel object).
Afaik basically all "out side" modules invoke the kernel Makefile system with various options (ie nvidias driver compiles part of it self but also provides a binary blob (=the propitary part) which is simply linked in). I'd suggest you take a look at nvidias drivers (download the latest and run with "./NVIDIA-something -x" to extract the sfx (iirc, use '-h' if it doesn't work)) - they also show how to link in "external" objects (in nividia's case, source less files).

Here's some info that might help (only scimmed thorugh them though)
http://www.captain.at/programming/kernel-2.6/
http://www.tldp.org/LDP/lkmpg/2.6/html/x380.html
http://linuxdevices.com/articles/AT4389927951.html

Thank you. Smile

_________________
best regards
p7
Post 11 Aug 2006, 11:13
View user's profile Send private message Visit poster's website Reply with quote
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7 27 Aug 2006, 19:33
Problem solved, BogDro makes 2.6 module in fasm Very Happy
http://rudy.mif.pg.gda.pl/~bogdro/linux/sys_tut_linux.html#s04

_________________
best regards
p7
Post 27 Aug 2006, 19:33
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.