错误粘贴"" pushl $""和"" 15""不提供有效的预处理令牌

时间:2015-11-07 17:21:59

标签: c gcc assembly compilation c-preprocessor

我试图编译这个来源我得到了这个恼人的错误,而且我不知道为什么会发生错误。我已经搜索过了,但我没有找到任何帮助。

的资源文件

#include <ddk/ntddk.h>
#include <internal/ntoskrnl.h>
#include <internal/ke.h>
#include <internal/i386/segment.h>


#define _STR(x) #x
#define STR(x) _STR(x)


#define IRQ_HANDLER_FIRST(x,y)  \
      void irq_handler_##y (void);   \
       __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
        "pusha\n\t"                     \
        "pushl %ds\n\t"                 \
        "pushl %es\n\t"                 \
        "pushl %fs\n\t"                  \
        "movl  $0xceafbeef,%eax\n\t"      \
        "pushl %eax\n\t"                \
        "movw  $"STR(KERNEL_DS)",%ax\n\t"       \
        "movw  %ax,%ds\n\t"             \
        "movw  %ax,%es\n\t"             \
        "inb   $0x21,%al\n\t"               \
        "orb   $1<<"##x",%al\n\t"       \
        "outb  %al,$0x21\n\t"               \
        "pushl %esp\n\t"                \
        "pushl $"##x"\n\t"              \
        "call  _KiInterruptDispatch\n\t"\
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %fs\n\t"                 \
        "popl  %es\n\t"                 \
        "popl  %ds\n\t"                 \
        "popa\n\t"                      \
        "iret\n\t")

#define IRQ_HANDLER_SECOND(x,y)  \
      void irq_handler_##y (void);   \
       __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
        "pusha\n\t"                     \
        "pushl %ds\n\t"                 \
        "pushl %es\n\t"                 \
        "pushl %fs\n\t"                 \
        "movl  $0xceafbeef,%eax\n\t"      \
        "pushl %eax\n\t"                \
        "movw  $"STR(KERNEL_DS)",%ax\n\t"       \
        "movw  %ax,%ds\n\t"             \
        "movw  %ax,%es\n\t"             \
        "inb   $0xa1,%al\n\t"               \
        "orb   $1<<("##x"-8),%al\n\t"       \
        "outb     %al,$0xa1\n\t"               \
        "pushl %esp\n\t"                \
        "pushl $"##x"\n\t"              \
        "call  _KiInterruptDispatch\n\t"\
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %fs\n\t"                 \
        "popl  %es\n\t"                 \
        "popl  %ds\n\t"                 \
        "popa\n\t"                      \
        "iret\n\t")


IRQ_HANDLER_FIRST ("0",0);
IRQ_HANDLER_FIRST ("1",1);
IRQ_HANDLER_FIRST ("2",2);
IRQ_HANDLER_FIRST ("3",3);
IRQ_HANDLER_FIRST ("4",4);
IRQ_HANDLER_FIRST ("5",5);
IRQ_HANDLER_FIRST ("6",6);
IRQ_HANDLER_FIRST ("7",7);
IRQ_HANDLER_SECOND ("8",8);
IRQ_HANDLER_SECOND ("9",9);
IRQ_HANDLER_SECOND ("10",10);
IRQ_HANDLER_SECOND ("11",11);
IRQ_HANDLER_SECOND ("12",12);
IRQ_HANDLER_SECOND ("13",13);
IRQ_HANDLER_SECOND ("14",14);
IRQ_HANDLER_SECOND ("15",15);

然后我得到类似的东西

ke/i386/irqhand.c:25:9: error: pasting ""orb   $1<<"" and ""5"" does not give a
valid preprocessing token
         "orb   $1<<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:72:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("5",5);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""5"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:72:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("5",5);
 ^
ke/i386/irqhand.c:14:16: error: pasting ""\n\t.global _irq_handler_"" and ""6""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:14:46: error: pasting ""\n\t_irq_handler_"" and ""6"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:25:9: error: pasting ""orb   $1<<"" and ""6"" does not give a
valid preprocessing token
         "orb   $1<<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""6"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:14:16: error: pasting ""\n\t.global _irq_handler_"" and ""7""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:14:46: error: pasting ""\n\t_irq_handler_"" and ""7"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:25:9: error: pasting ""orb   $1<<"" and ""7"" does not give a
valid preprocessing token
         "orb   $1<<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""7"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:41:16: error: pasting ""\n\t.global _irq_handler_"" and ""8""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:41:46: error: pasting ""\n\t_irq_handler_"" and ""8"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:52:9: error: pasting ""orb   $1<<("" and ""8"" does not give a
 valid preprocessing token
         "orb   $1<<("##x"-8),%al\n\t"       \
         ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:55:9: error: pasting ""pushl $"" and ""8"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:41:16: error: pasting ""\n\t.global _irq_handler_"" and ""9""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:76:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("9",9);
 ^

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

摆脱宏定义中的##。在这种情况下,他们是不必要的和非法的。由于错误表明##运算符的结果必须是单个有效的预处理标记,"pushl $""6"是两个标记。

如果没有##,预处理器不会尝试将两个字符串粘贴在一起以形成单个标记。它们将作为单独的字符串标记保留,并在稍后的翻译阶段合并在一起。