From: "John S. Fine" Newsgroups: comp.os.msdos.djgpp Subject: Re: struct problem Date: Thu, 21 Oct 1999 10:17:15 -0400 Lines: 67 Message-ID: <380F206B.8AE@erols.com> References: <7umn1a$q3o AT cs DOT vu DOT nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: 2P0Qxu0dFsz7nSXUMwQVWY/DCbEq/y1JQP/vkjMOjyY= X-Complaints-To: abuse AT rcn DOT com NNTP-Posting-Date: 21 Oct 1999 14:19:49 GMT X-Mailer: Mozilla 3.01 (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Fokkema, DBRA, 1043730 wrote: > I've got a nasty (so it seems to me) problem with structs. I have this nice > kernel with some descriptors in the gdt I couldn't follow most of what you said, and the 'ed parts of your code contain the parts that are the problem, so I can't give you an exact answer. What you are trying to do, is very difficult. You want to initialize a GDT descriptor at compile time with an offset that is not known until link time. If that value in the descriptor were a contiguous 32-bits then it would be easy. But that value is a 24-bit field seperate from an 8-bit field. You may know that the entire value fits in 24-bits (maybe even 16) but there is no way for the compiler to communicate that to the linker in COFF format. In the linker I wrote (JLOC), I put special support for descriptors, because I write a lot of code in which I need to init descriptors at compile time and that is so hard to get through ordinary linkers. One kludge I used before I wrote that linker was to have a version of the descriptor structure in which the middle dword is defined as a single value. (Make sure you use __attribute__((packed)) so that a long can be placed at offset 2 in a struct). I then init it with address+(attributes<<24). Since attributes is a compile time constant, it is no problem; And since the field is a long, COFF format handles not knowing the address until link time. (You still need to make sure the address fits in 24-bits.) BTW, the descriptor needs a linear address. The linker will give you an offset. If there is a difference between those, you must handle that as well. > sizeof(tss) - 1, (long) &tssexception00, 0x21, SDTTSSNB0, GDXU1B32, 0x00, ... > gdt.c:48: initializer element for `gdt[6].baselow' is not computable at load > time I assume .baselow is not a long. You have given it a long to put there. The compiler can't do the cast because it doesn't know the value. The linker can't do that because that is an operation COFF format doesn't support. (If the offset fits in 16 bits then .obj format supports that. If it needs 24 bits then .obj doesn't support it either) > Well, gdt[6] is my tss descriptor (see above) and baselow obviously is > (long) &tssexception00. So the address of my struct is somehow not computable > from the respect of gcc. Can someone help me out please? I can't imagine I am > the only one trying to define a tss inside the kernel address space and use > a pointer to reference it in the gdt. Almost everyone initializes that type of descriptor at run time, even though the values are known at link time. I use my own linker to make this easy, but I always put the descriptors in an ASM file. I don't remember whether the method I use to communicate the descriptor from ASM to my linker could be duplicated in C. You can download my linker and read its documentation if you want to try that method. -- http://www.erols.com/johnfine/ http://www.geocities.com/SiliconValley/Peaks/8600/