Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 循环引用与低级汇编_C_Assembly_Operating System_Osdev - Fatal编程技术网

C 循环引用与低级汇编

C 循环引用与低级汇编,c,assembly,operating-system,osdev,C,Assembly,Operating System,Osdev,我有一个名为idt.c的文件,在这个文件中,我需要从汇编中调用函数idt\u load。现在,除了需要从程序集文件访问变量,idtp,并且该变量在idt.c中声明之外,这一切都很好 这不起作用,因为链接器会告诉我idt_load未定义或idtp未定义。我怎样才能让它工作 idt.c的相关部分 struct idt_entry { unsigned short base_lo; unsigned short sel; unsigned char always0; u

我有一个名为
idt.c
的文件,在这个文件中,我需要从汇编中调用函数
idt\u load
。现在,除了需要从程序集文件访问变量,
idtp
,并且该变量在idt.c中声明之外,这一切都很好

这不起作用,因为链接器会告诉我idt_load未定义或idtp未定义。我怎样才能让它工作

idt.c的相关部分

struct idt_entry
{
    unsigned short base_lo;
    unsigned short sel;
    unsigned char always0;
    unsigned char flags;
    unsigned short base_hi;
} __attribute__((packed));

struct idt_ptr
{
    unsigned short limit;
    unsigned int base;
} __attribute__((packed));


struct idt_entry idt[256];
struct idt_ptr idtp;

extern void idt_load();

//Later in the code...
idt_load();
idt.asm

global idt_load
extern idtp
idt_load:
    lidt [idtp]
    ret

有两件事需要考虑:

  • idt
    属于什么类型?(答:它是指向
    idt\u条目的指针
    ,或者严格地说,它是地址的名称
    idt[0]

  • 如何声明asm文件中指针的外部引用

  • 获取所有这些内容的最简单方法是使用适当的标志(至少在gcc中我认为是-s)编译C代码,并查看生成的汇编代码


    您没有任何循环引用,只需要让链接器知道您想要引用名为
    idt

    的C代码中定义的内存,只是为了好玩,为什么不向我们展示解决方案呢?