exporting struct offsets to assembler

From: Andrew Morton (andrewm@uow.edu.au)
Date: Fri Aug 04 2000 - 22:27:42 EDT

  • Next message: Garst R. Reese: "apm not working for me in test5 or test6-pre3"

    This is a little proof-of-concept RFC thing. It demonstrates a
    way to get rid of the magical task_struct structure offsets
    in entry.S (and other places), so things won't break if the
    structure layout (or compiler) changes.

    It uses some compiler tricks to export the structure offset
    into a global absolute symbol and uses that symbol in the
    assembly code.

    This _should_ be arch-independent, but there is one potential
    drawback: Some architectures (eg 68k) will produce better
    code with

            movl 8(a0),d0

    than with

            .globl some_label
            movl some_label(a0),d0

    This can be avoided if the assembler is smart enough with

            move some_label:b(a0),d0

    but I don't know if gas does that.

    --- linux-2.4.0-test6-pre2/kernel/ksyms.c Sun Jul 30 02:28:18 2000
    +++ linux-akpm/kernel/ksyms.c Sat Aug 5 12:09:15 2000
    @@ -540,3 +540,21 @@
     
     EXPORT_SYMBOL(tasklist_lock);
     EXPORT_SYMBOL(pidhash);
    +
    +
    +#define OFFSETOF(struct_name, item) ((unsigned long)&(((struct struct_name *)0)->item))
    +
    +#define EXPORT_ASM_CONSTANT(asm_label, value) \
    + __asm__ __volatile__("\t.equ " #asm_label ",%c0" :: "i" (value) ); \
    + __asm__ __volatile__("\t.globl " #asm_label)
    +
    +#define EXPORT_ASM_STRUCT_OFFSET(asm_label, struct_name, item) \
    + EXPORT_ASM_CONSTANT(asm_label, OFFSETOF(struct_name, item))
    +
    +
    +static void wrapper()
    +{
    + EXPORT_ASM_STRUCT_OFFSET(TS_SIGPENDING, task_struct, sigpending);
    + EXPORT_ASM_STRUCT_OFFSET(TS_NEED_RESCHED, task_struct, need_resched);
    +}
    +
    --- linux-2.4.0-test6-pre2/arch/i386/kernel/entry.S Tue Jul 11 22:21:12 2000
    +++ linux-akpm/arch/i386/kernel/entry.S Sat Aug 5 12:11:20 2000
    @@ -73,10 +73,8 @@
      */
     state = 0
     flags = 4
    -sigpending = 8
     addr_limit = 12
     exec_domain = 16
    -need_resched = 20
     tsk_ptrace = 24
     processor = 52
     
    @@ -215,9 +213,9 @@
             jne handle_softirq
             
     ret_with_reschedule:
    - cmpl $0,need_resched(%ebx)
    + cmpl $0,TS_NEED_RESCHED(%ebx)
             jne reschedule
    - cmpl $0,sigpending(%ebx)
    + cmpl $0,TS_SIGPENDING(%ebx)
             jne signal_return
     restore_all:
             RESTORE_ALL

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.rutgers.edu
    Please read the FAQ at http://www.tux.org/lkml/



    This archive was generated by hypermail 2b29 : Fri Aug 04 2000 - 22:32:44 EDT