I don't know if this deserves its own topic but here goes:
INSTURCTIONS How to use VC++ 6 to build a kernel.
A:
As we all know VC++ only outputs PE executables.
However inside these there are the normal segments of the program, .text & .data . Along with other sections such as .reloc, etc.
Using part copy we can extract these sections easily and copy them to a disk or disk image.(go to john fines web page to find partcopy).
By default the .text sector is located at 0x1000 and .data sector located at 0x2000 in the *.exe file. (VS .NET 0x200 0x400 instead) We can set the size of these pages by using
/filealign:0x1000 in the linker.
partcopy vskern.exe 1000 200 -f0 200
B:
To set the base of the program use the linker switch /BASE:0x10000
however the .text section will have a base of 0x1000 greater than you set the base to, so you must take this into account when load the kernel into memory.(.data section has offset of 0x2000). Maintain the offsets between sections unless you can change the values.
If this is too much it is possible to merge the sections. /merge:.text = .data
C:
Another section in PE files is the .reloc sector. This provides runtime relocations. We don't want this. So we use the linker switch /FIXED. now our text and data sections will be layed out as is.
D:
All the other options set in gcc for kernels like nostdlib, no rtti can be set in vc too, use the project options.
To exactly whats going on get "PE Explorer". Includes disassembler and can show you clearly the layout of your PE file. Jut search for it on google. If possible get bochs with BFE then you can see exactly whats goin on in the kernel.
I hope this helps, if there are any questions just shout and I'll get back to you. This works so far, but i'm not very far on in my os.
P.S.: I'd like another star, please.
How to use VC++ to make a kernel
Re: How to use VC++ to make a kernel
This is very complicated, actually extremly complicated. There is this linker designed especially for os Dev called ELINK, and the only reason I can't use it properly is because(this is what the author said):
"ELink operates on the assumption that the programmer knows what order the segments are in in the .obj file. Most compilers will give you the option to order the segments by name, in which case you can put the code segment first alphabetically with a name like A_CODE or A_TEXT or whatever and then have the next data segment be B_DATA, or something."
You said something similar with the segments, so do you know how to order the segments.... I'm using BCC32 but VC is simmilar.
"ELink operates on the assumption that the programmer knows what order the segments are in in the .obj file. Most compilers will give you the option to order the segments by name, in which case you can put the code segment first alphabetically with a name like A_CODE or A_TEXT or whatever and then have the next data segment be B_DATA, or something."
You said something similar with the segments, so do you know how to order the segments.... I'm using BCC32 but VC is simmilar.
Re: How to use VC++ to make a kernel
the .text segment is first then
the .data segment then .reloc
data is put before text when merged.
/merge:.text=data
I don't explicitly know how to order the segments in vc++, why try. code first then data seems good to me. Try MSDN.
If use disassemble any file you'll know what order the sections are in.
Why use elink if it dosen't work for you. Why not jloc or alink or any of those.
the .data segment then .reloc
data is put before text when merged.
/merge:.text=data
I don't explicitly know how to order the segments in vc++, why try. code first then data seems good to me. Try MSDN.
If use disassemble any file you'll know what order the sections are in.
Why use elink if it dosen't work for you. Why not jloc or alink or any of those.
Re: How to use VC++ to make a kernel
I'm not big on scripts(i suck), so if you can give me a basic script for a kernel like the example that just prints something on the screen, that would be wicked. Alink doesn't output flat binary.
Re: How to use VC++ to make a kernel
I sent you an email about VC++ and OS Dev before I read this, but can you maybe write a tutorial with step by step instructions for a kernel that just displays "hi" in VC++?
And to get another start you(unfortunitly) have to have 30-35 messages posted, but I don't remember for sure.
K.J.
And to get another start you(unfortunitly) have to have 30-35 messages posted, but I don't remember for sure.
K.J.
Re: How to use VC++ to make a kernel
yeah, that would be good.
This bit of os i'm writing is part of my final year project, which is e-learning operating system stuff.
So I'll be putting together tutorials on most of the stuff i do, so I'll give you a copy of whatever i get done.
I won't be putting that together for a few weeks though.
About bochs.
download page: http://bochs.sourceforge.net/getcurrent.html
download
http://prdownloads.sourceforge.net/boch ... 32-bin.zip
Need BFE to visual debug.
http://www.volny.cz/xmojmr/
This bit of os i'm writing is part of my final year project, which is e-learning operating system stuff.
So I'll be putting together tutorials on most of the stuff i do, so I'll give you a copy of whatever i get done.
I won't be putting that together for a few weeks though.
About bochs.
download page: http://bochs.sourceforge.net/getcurrent.html
download
http://prdownloads.sourceforge.net/boch ... 32-bin.zip
Need BFE to visual debug.
http://www.volny.cz/xmojmr/
Re: How to use VC++ to make a kernel
this isn't a script just options you set in VC.
go to Project->Settings
select the link tab, then add:
/nologo /base:"0x00010000" /entry:"main" /incremental:no /machine:IX86 /nodefaultlib /filealign:0x1000 /fixed
remember the changes in the boot sector.
" /base:"0x00010000" " where i load my kernel, not necessarily where you load yours, or even a good place to load it.
go to Project->Settings
select the link tab, then add:
/nologo /base:"0x00010000" /entry:"main" /incremental:no /machine:IX86 /nodefaultlib /filealign:0x1000 /fixed
remember the changes in the boot sector.
" /base:"0x00010000" " where i load my kernel, not necessarily where you load yours, or even a good place to load it.
Re: How to use VC++ to make a kernel
I had some stuff written up somewhere about VC++ for kernels.
basically you can set all the options and produce a minimal PE executable, kind of flat relocated at 1mb, etc. and basically just skip the header when you load it type thing... i'll see what i can find.
basically you can set all the options and produce a minimal PE executable, kind of flat relocated at 1mb, etc. and basically just skip the header when you load it type thing... i'll see what i can find.
-- Stu --