我遇到链接问题(在Makefile中使用ld -m32 ....命令)我自己的'核心。我在wikibooks上发现了它。 我收到错误:
intr.o: In function `set_intr_gate':
intr.c:(.text+0x17): undefined reference to `idt'
intr.c:(.text+0x1e): undefined reference to `idt'
intr.o: In function `set_trap_gate':
intr.c:(.text+0x47): undefined reference to `idt'
intr.c:(.text+0x4e): undefined reference to `idt'
intr.o: In function `set_system_gate':
intr.c:(.text+0x77): undefined reference to `idt'
intr.o:intr.c:(.text+0x7e): more undefined references to `idt' follow
make: *** [kernel.bin] Error 1
这些是我的'代码:
start.asm(最后带有_idt声明的bootloader):
[BITS 32]
[SECTION .text]
EXTERN code,bss,end
mboot:
dd 0x1BADB002
dd 0x10001
dd -(0x1BADB002+0x10001)
dd mboot
dd code
dd bss
dd end
dd _start
GLOBAL _start
_start:
cli
mov esp,kstack+4096
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
lgdt [gdt_descr]
jmp .1
.1:
push dword 0
push dword 0
push dword 0
push dword L6
;EXTERN _start_kernel
EXTERN start_kernel
;push dword _start_kernel
push dword start_kernel
ret
L6:
jmp L6
[SECTION .bss]
kstack: resd 1024
[SECTION .data]
gdt_descr:
dw 256*8-1
dd _gdt
GLOBAL _gdt
_gdt:
dd 0,0
dd 0x0000FFFF,0x00CF9A00
dd 0x0000FFFF,0x00CF9200
dd 0,0
times 254 dd 0,0
lidt [idt_descr]
idt_descr:
dw 256*8-1
dd _idt
GLOBAL _idt
_idt:
times 256 dd 0,0
intr.h:
#ifndef __INTR_H
#define __INTR_H
typedef struct desc_struct
{
long a,b;
} desc_table[256];
extern desc_table gdt,idt;
void set_intr_gate(int n,void * addr);
void set_trap_gate(int n,void * addr);
void set_system_gate(int n,void * addr);
#endif
intr.c:
#include "intr.h"
#define _set_gate(gate_addr,type,dpl,addr) \
__asm__("movw %%dx,%%ax\n\t" \
"movw %0,%%dx\n\t" \
"movl %%eax,%1\n\t" \
"movl %%edx,%2\n\t" \
::"i"((short)(0x8000+(dpl<<13)+(type<<8))), \
"o"(*((char *)(gate_addr))), \
"o"(*(4+(char *)(gate_addr))), \
"d"((char *)(addr)),"a"(0x00080000))
void set_intr_gate(int n,void * addr)
{
_set_gate(&idt[n],14,0,addr);
}
void set_trap_gate(int n,void * addr)
{
_set_gate(&idt[n],15,0,addr);
}
void set_system_gate(int n,void * addr)
{
_set_gate(&idt[n],15,3,addr);
}
我没有把我的kernel.c放在没有那些intr.c和.h的情况下工作得很好。我不知道问题出在哪里。提前谢谢!
编辑: 删除下划线有帮助。