2016-08-08 9 views
1

機能しない、私は私のカーネルのIDTを設定しようとしているが、私は、このリンクエラーを取得しています:NASMマクロが正しく

bin/obj/idt.o: In function `setup_idt': 
idt.c:(.text+0x9b): undefined reference to `interrupt_handler_1' 

エラーがinterrupt_handler_1が定義されていないと言うが、それはありますinterrupt_manager.asmでマクロ:

%macro no_error_code_interrupt_handler 1 
global interrupt_handler_%1 
interrupt_handler_%1: 
    cli 
    push dword 0      ; push 0 as error code 
    push dword %1     ; push the interrupt number 
    jmp  common_interrupt_handler ; jump to the common handler 
%endmacro 

ここではsetyup_idt機能である:

extern void interrupt_handler_1(); 

void setup_idt() 
{ 
    // Set the special idt_pointer 
    idt_pointer.limit = (sizeof(struct InterruptDescriptorTableEntry) * 256) - 1; // Subsract 1 because sizeof doesn't start from 0 
    idt_pointer.address = (uint32)&idt; 

    // Clear the whole idt to zeros 
    memset(&idt, 0, sizeof(struct InterruptDescriptorTableEntry) * 256); 

    for(unsigned int i = 0; i < 256; i++) 
    { 
     idt_set_gate(i, (uint32)&interrupt_handler_1, 0x8, 0x8E); 
    } 

    __asm__ __volatile__("lidt %0": :"m"(idt_pointer)); 

} 

私が間違って作られたのは何?

エクストラ質問:私は何をしたいか

は次のようなものです:私はより良い自分自身を説明してみましょう、私は割り込みハンドラに自動的にGDTのIエントリをリンクするマクロ/別の方法があります:

interrupt_handler [i]が割り込みhandler_だろう
for(unsigned int i = 0; i < 256; i++) 
    { 
     idt_set_gate(i, (uint32)&interrupt_handler_[i], 0x8, 0x8E); 
    } 

[i]はあなたのNASMコードでマクロを展開する必要があるNASMマクロ

+1

リンカーにはマクロが表示されません。関数を使用します。 –

+0

マクロはコードの一部ではありません。組み立てられた実際のコードに展開されるためにマクロを使用する必要があります。 –

+0

@Joachim Pileborg Okey、余分な質問はどうですか? –

答えて

2

に置き換えられます。マクロ定義自体はコードを生成しません。 NASMコードで明示的に使用する必要があります。

%repディレクティブを使用して、異なるパラメータでマクロを繰り返し展開することができます。このような何か:上記のコードは、あなたがこのようなあなたのCコードで使用できるすべての割り込みハンドラのテーブルを作成し

extern common_interrupt_handler 

%macro error_code_interrupt_handler 1 
global interrupt_handler_%1 
interrupt_handler_%1: 
    push dword %1     ; push the interrupt number 
    jmp  common_interrupt_handler ; jump to the common handler 
%endmacro 

%macro no_error_code_interrupt_handler 1 
global interrupt_handler_%1 
interrupt_handler_%1: 
    push dword 0      ; push 0 as error code 
    push dword %1     ; push the interrupt number 
    jmp  common_interrupt_handler ; jump to the common handler 
%endmacro 

; Some CPU exceptions have error codes, some don't 

%assign intnum 0 
%rep 8 - intnum 
    no_error_code_interrupt_handler intnum 
    %assign intnum intnum + 1 
%endrep 

error_code_interrupt_handler 8 
no_error_code_interrupt_handler 9 

%assign intnum 10 
%rep 16 - intnum 
    error_code_interrupt_handler intnum 
    %assign intnum intnum + 1 
%endrep 

no_error_code_interrupt_handler 16 
error_code_interrupt_handler 17 
no_error_code_interrupt_handler 18 
no_error_code_interrupt_handler 19 
no_error_code_interrupt_handler 20 

%assign intnum 21 ; first (currently) unassigned CPU exception 
%rep 32 - intnum 
    no_error_code_interrupt_handler intnum 
    %assign intnum intnum + 1 
%endrep 

%assign intnum 32 ; first user defined interrupt 
%rep 256 - intnum 
    no_error_code_interrupt_handler intnum 
    %assign intnum intnum + 1 
%endrep 

; define a table of interrupt handlers for C code to use 

    global interrupt_handler_table 
interrupt_handler_table: 

%assign intnum 0 
%rep 256 
    dd interrupt_handler_ %+ intnum 
    %assign intnum intnum + 1 
%endrep 

:私はerror_code_interrupt_handlerマクロを作成しました

extern uint32 interrupt_handler_table[256]; 

for(unsigned int i = 0; i < 256; i++) 
{ 
    idt_set_gate(i, interrupt_handler_table[i], 0x8, 0x8E); 
} 

注意エラーコードを生成するCPU例外。また、コードから不要なCLI命令を削除しました。 IDTで割り込みゲートを使用しているので、割り込み許可フラグは自動的にクリアされます。

+0

ありがとう、これは完璧に私を働いた! –