public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@muc.de>
To: Steve Hemond <steve.hemond@sympatico.ca>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Inserting a module (2.6 kernel)
Date: Wed, 09 Jun 2004 11:47:58 +0200	[thread overview]
Message-ID: <m3oentkqpd.fsf@averell.firstfloor.org> (raw)
In-Reply-To: <24Zio-6xX-3@gated-at.bofh.it> (Steve Hemond's message of "Wed, 09 Jun 2004 02:40:08 +0200")

Steve Hemond <steve.hemond@sympatico.ca> writes:

> Hi people,
>
> I am new to kernel module writing and I base myself on the Linux Device Drivers book from O'reilly. I have written this simple module :
>
> #include <linux/module.h>
>
> int init_module(void)
> {
>   printk("<1>Module inserted\n");
>   return 0;
> }
>
> void cleanup_module(void)
> {
>   printk("<1>Module removed\n");
> }
>

For some reason that's probably far too complicated for my little
brain it's getting more and more complicated to write custom
modules for 2.6.

Compile all with:

gcc -O2 -c hello.c -I /path/to/kernel/include

or 

gcc -O2 -mcmodel=kernel -mno-red-zone -c hello.c -I /path/to/kernel/include
if you're using x86-64.

In 2.4 what worked was:

#define MODULE 1
#define __KERNEL__ 1 
#include <linux/module.h>

int init_module(void)
{
        printk("Hello world\n");
        return 0;
}

Then in 2.6 it needed

#define MODULE 1
#define __KERNEL__ 1 
#define KBUILD_MODNAME "hello"
#include <linux/module.h>

int init_module(void)
{
        printk("Hello world\n");
        return 0;
}

Now since 2.6.5 or so it needs: 

/* MODULE is not needed anymore */
#define __KERNEL__1 
#include <linux/module.h>

int init_module(void)
{
        printk("Hello world\n");
        return 0;
}

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
        .name = "hello",
        .init = init_module,
};

I'm sure there will be more surprises in the future. Keep tuned.

-Andi




       reply	other threads:[~2004-06-09  9:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <24Zio-6xX-3@gated-at.bofh.it>
2004-06-09  9:47 ` Andi Kleen [this message]
2004-06-12 21:08   ` Inserting a module (2.6 kernel) Sam Ravnborg
2004-06-09  0:33 Steve Hemond
2004-06-09  0:40 ` Arthur Othieno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3oentkqpd.fsf@averell.firstfloor.org \
    --to=ak@muc.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=steve.hemond@sympatico.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox