having problem with one area of guide , vc2005 express work?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Those naming conventions are not THAT bad ;)

Similar to GCC, you need to insure that all sections within the final binary are existent. If these sections are messing (Like .code, .data,. rodata, et al...) then the language may not work correctly.

VC++ is the same here. MSVC++ uses the .CRT section of the final binary image to store all global initializers (Such as an objects ctor, static, or global objects that need to be initialized.) This is primarily only needed if you plan support for classes and objects.

The naming convention is in alphabetical order:

Code: Select all

	.CRT$XCA
	.CRT$XCU
	.CRT$XCZ
Only look close at the last character here - This is the important part. Notice that they are in alphabetical order.

We use these names in the beginning CRT file to create the sections, like so...

Code: Select all

// all data and variables defined above here is in .data section

#pragma data_seg(".CRT$XCA")

// Now, a new section is created - .CRT. All globals and varables defined
// here are placed inside of the .CRT section instead of .data.
The last part - $XCA, is used to help determine the end and beginning parts of the segments. That is, .CRT$XCA is the start of the segment, and is guarantee to always point to the first data element in that segment.

Think of it as an "address" that represents the segment. The LAST character in the name determines WHERE this address is within the segment.

Lets look at the segment names again:

Code: Select all

	.CRT$XCA
	.CRT$XCU
	.CRT$XCZ
In this case, this all declares a single segment - .CRT.

The last character / part determines how it is to be arranged.

.CRT$XCA - ends with character "A" (First character in alphabet), so it points to the starting address of the segment.

.CRT$XCU - ends with character "U". If this was the last name, then this would have pointed to the end of the section. But wait!.....

.CRT$XCZ - "Z" is greater then "U", so now U points to the middle of the .CRT section, and .CRT$XCZ now points to the end ;)

Back to the code...

Code: Select all

// Standard C++ Runtime (STD CRT) __xc_a points to
// beginning of initializer table

#pragma data_seg(".CRT$XCA")
_PVFV __xc_a[] = { NULL };
Here we define a varable inside of the .CRT section. Because of our name, which ends with the character "A", the varables and data are guaranteed to be at the beginning of the .CRT section.

So... __xc_a[] is at the beginning of the .CRT section for MSVC++ to use.

The basic idea here is that we can split the name into two parts seperated by the dollar sign (surprise):

.CRT$XCA << .CRT is the section name
.CRT$XCA << XCA refers to where it is located in that secton



I hope this clarifies things a bit :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
maverick777
Member
Member
Posts: 65
Joined: Wed Nov 14, 2007 3:19 pm

Post by maverick777 »

Yes it does :-) , Im actually about to attempy a keyboard driver in asm , which lets me simply type in characters . then once I have done that Im going to try the same thing again but using C maybe with some inline asm where needed .

Thanks again all
Post Reply