2012-11-03 46 views
1

我得到59行这样的警告:在收到警告“赋值时将指针整数,未作类型转换”

赋值时将指针整数,未作演员。

我该如何解决?这里是(从http://pastebin.com/BrmjBAS0复制)整个文件:

/* bkerndev - Bran's Kernel Development Tutorial 
* By: Brandon F. ([email protected]) 
* Desc: Global Descriptor Table management 
* 
* Notes: No warranty expressed or implied. Use at own risk. */ 


/* Defines a GDT entry */ 
struct gdt_entry 
{ 
    unsigned short limit_low; 
    unsigned short base_low; 
    unsigned char base_middle; 
    unsigned char access; 
    unsigned char granularity; 
    unsigned char base_high; 
} __attribute__((packed)); 

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

/* Our GDT, with 3 entries, and finally our special GDT pointer */ 
struct gdt_entry gdt[3]; 
struct gdt_ptr gp; 

/* This is in start.asm. We use this to properly reload 
* the new segment registers */ 
extern void _gdt_flush(); 

/* Setup a descriptor in the Global Descriptor Table */ 
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran) 
{ 
    /* Setup the descriptor base address */ 
    gdt[num].base_low = (base & 0xFFFF); 
    gdt[num].base_middle = (base >> 16) & 0xFF; 
    gdt[num].base_high = (base >> 24) & 0xFF; 

    /* Setup the descriptor limits */ 
    gdt[num].limit_low = (limit & 0xFFFF); 
    gdt[num].granularity = ((limit >> 16) & 0x0F); 

    /* Finally, set up the granularity and access flags */ 
    gdt[num].granularity |= (gran & 0xF0); 
    gdt[num].access = access; 
} 

/* Should be called by main. This will setup the special GDT 
* pointer, set up the first 3 entries in our GDT, and then 
* finally call gdt_flush() in our assembler file in order 
* to tell the processor where the new GDT is and update the 
* new segment registers */ 
void gdt_install() 
{ 
    /* Setup the GDT pointer and limit */ 
    gp.limit = (sizeof(struct gdt_entry) * 3) - 1; 
    gp.base = &gdt; 

    /* Our NULL descriptor */ 
    gdt_set_gate(0, 0, 0, 0, 0); 

    /* The second entry is our Code Segment. The base address 
    * is 0, the limit is 4GBytes, it uses 4KByte granularity, 
    * uses 32-bit opcodes, and is a Code Segment descriptor. 
    * Please check the table above in the tutorial in order 
    * to see exactly what each value means */ 
    gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); 

    /* The third entry is our Data Segment. It's EXACTLY the 
    * same as our code segment, but the descriptor type in 
    * this entry's access byte says it's a Data Segment */ 
    gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); 

    /* Flush out the old GDT and install the new changes! */ 
    _gdt_flush(); 
} 
+0

请给我一个线索......代码的哪一行? – Andrew

+1

对不起,我忘了写!这是59,“gp.base = &gdt;”! –

回答

1

OK,让我把这个情境......

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

struct gdt_entry gdt[3]; 
struct gdt_ptr gp; 

gp.base = &gdt; 

整数分配指针(&gdt)( gp.base) - 因此错误:-)

我怀疑你真正想要的(或类似的东西):

struct gdt_ptr 
{ 
    unsigned short limit; 
    struct gdt_entry *base; 
} __attribute__((packed)); 

或者,因为你以后评价该地址作为其分量场,留下的定义是,投下分配

+0

嗯,然后我得到这个警告在同一行:“从不兼容的指针类型的指派” –

+0

你需要指定指针,如果分配是真的 –

+0

@KamilŠrot他不应该宁愿改变'基'的类型为' struct gdt_entry(*)[3]'而不是投射任何东西,如果任务是真的正确(虽然我怀疑它是)? – sepp2k

-1

听说地址应该在size_t不断,但我真要保留地址int也许只是施展它? gp.base = (int) &gdt;

+2

只有'intptr_t'和'uintptr_t'保证保存('void *')指针的值。 – alk

相关问题