Microsoft Visual C++
Microsoft Visual C++
Does anyone have any information on producing a freestanding binary (such as an OS kernel), using MS Visual C++ (7)?
Thanks
Thanks
Re:Microsoft Visual C++
I don't think it's possible, microsoft's compiler isn't designed to do that. You could use it as a code editor though.
srg
srg
Re:Microsoft Visual C++
definitely is possible, i remember reading a paper a while back about making super small binaries by ripping out all the libc stub code and all that. after that you could relativly easily convert PE to whatever as neccessary (or just boot the PE which i think can be done too).
I know as a fact there are some poeple out there using msvc++ for OS dev, it's just a little more annoying than gcc.
proxy
I know as a fact there are some poeple out there using msvc++ for OS dev, it's just a little more annoying than gcc.
proxy
Re:Microsoft Visual C++
Hi,
-Stephen
I use it as an editor, because I like the cod highlighting and auto-indenting. It's much easier to just use GCC to compile the kernel though.srg wrote:I don't think it's possible, microsoft's compiler isn't designed to do that. You could use it as a code editor though.
-Stephen
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Microsoft Visual C++
To my best knowledge, this will require you to tweak the produced file into a binary form yourself (e.g. there will not be something like "-output=binary"). It is also possible (iirc) to tweak MSVC's compiler and linker options so that it uses a cygwin toolchain (you may lose smart error reports, though). Afaik, this is what most people who like the MSVC front-end do when they turn to osdev'ing.
(oh, and please, keep it clear of "you don't need the MSVC for coloring: XXXedit does it way better" stuff, tnx.)
(oh, and please, keep it clear of "you don't need the MSVC for coloring: XXXedit does it way better" stuff, tnx.)
Re:Microsoft Visual C++
Hello, i have written my kernel using the microsoft compiler and linker. I used the Microsoft Visual Studio 2005 Beta 2.
Here are the configurations i made:
But i dont like to use this compiler anymore.
Here are the configurations i made:
Code: Select all
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="MASM"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Yd"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
IgnoreStandardIncludePath="true"
StringPooling="true"
MinimalRebuild="false"
BasicRuntimeChecks="0"
SmallerTypeCheck="false"
RuntimeLibrary="2"
StructMemberAlignment="1"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
UndefineAllPreprocessorDefinitions="true"
OmitDefaultLibName="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
IgnoreImportLibrary="true"
AdditionalOptions="/MACHINE:I386 /FIXED /ALIGN:1024"
LinkIncremental="2"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="false"
SubSystem="1"
EntryPointSymbol="NdosEntryPoint"
BaseAddress="0x70000"
TargetMachine="0"
FixedBaseAddress="2"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="MASM"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Yd"
Optimization="0"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
IgnoreStandardIncludePath="true"
StringPooling="true"
MinimalRebuild="false"
BasicRuntimeChecks="0"
RuntimeLibrary="2"
StructMemberAlignment="1"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
UndefineAllPreprocessorDefinitions="true"
OmitDefaultLibName="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="ml /c /coff AKERNEL.ASM
uild
"
/>
<Tool
Name="VCLinkerTool"
IgnoreImportLibrary="true"
LinkLibraryDependencies="false"
AdditionalOptions="/MACHINE:I386 /FIXED /ALIGN:1024"
AdditionalDependencies="AKERNEL.OBJ"
LinkIncremental="1"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="0"
EnableCOMDATFolding="0"
EntryPointSymbol="NdosEntryPoint"
BaseAddress="0x70000"
TargetMachine="0"
FixedBaseAddress="2"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Microsoft Visual C++
Once again: YES it is possible. You can use MSVC++ compiler, but I had some problem using MS linker (and I think it cannot produce binary file, only PE) but MinGW works fine with MSVS (error reporting is not so good but....).
Currently I'm working on asm (NASM) syntax coloring support for MSVS.NET 2003, so if someone is interested I will publish it on Internet when I finish it.
Currently I'm working on asm (NASM) syntax coloring support for MSVS.NET 2003, so if someone is interested I will publish it on Internet when I finish it.
Re:Microsoft Visual C++
Hello, maybe some of you started write a kernel with MSVC++.
Maybe you want call global class constructors then you can
use this code.
Bye.
Maybe you want call global class constructors then you can
use this code.
Code: Select all
#define NULL 0
typedef void (__cdecl *_PVFV)(void);
#pragma data_seg(".CRT$XCA")
_PVFV __xc_a[] = { NULL };
#pragma data_seg(".CRT$XCZ")
_PVFV __xc_z[] = { NULL };
#pragma data_seg()
#pragma comment(linker, "/merge:.CRT=.data")
void __cdecl _initterm (
_PVFV * pfbegin,
_PVFV * pfend
)
{
while ( pfbegin < pfend )
{
if ( *pfbegin != NULL )
(**pfbegin)();
++pfbegin;
}
}
static _PVFV * pf_atexitlist = 0;
static unsigned max_atexitlist_entries = 0;
static unsigned cur_atexitlist_entries = 0;
void __cdecl _atexit_init(void)
{
max_atexitlist_entries = 32;
pf_atexitlist = (_PVFV *)0x500000; /** use your kernel malloc to allocate space **/
}
void InitializeConstructors()
{
_atexit_init();
_initterm(__xc_a, __xc_z);
}
Re:Microsoft Visual C++
You probably need this two functions too:
You will need this at least if the msvc linker needs these two functions.
Code: Select all
.386P
.MODEL FLAT
.CODE
LOWORD equ [0]
HIWORD equ [4]
__aullrem proc near
assume cs:_TEXT
push ebx
DVND equ [esp + 8]
DVSR equ [esp + 16]
mov eax,HIWORD(DVSR)
or eax,eax
jnz short L1
mov ecx,LOWORD(DVSR)
mov eax,HIWORD(DVND)
xor edx,edx
div ecx
mov eax,LOWORD(DVND)
div ecx
mov eax,edx
xor edx,edx
jmp short L2
L1:
mov ecx,eax
mov ebx,LOWORD(DVSR)
mov edx,HIWORD(DVND)
mov eax,LOWORD(DVND)
L3:
shr ecx,1
rcr ebx,1
shr edx,1
rcr eax,1
or ecx,ecx
jnz short L3
div ebx
mov ecx,eax
mul dword ptr HIWORD(DVSR)
xchg ecx,eax
mul dword ptr LOWORD(DVSR)
add edx,ecx
jc short L4
cmp edx,HIWORD(DVND)
ja short L4
jb short L5
cmp eax,LOWORD(DVND)
jbe short L5
L4:
sub eax,LOWORD(DVSR)
sbb edx,HIWORD(DVSR)
L5:
sub eax,LOWORD(DVND)
sbb edx,HIWORD(DVND)
neg edx
neg eax
sbb edx,0
L2:
pop ebx
ret 16
__aullrem endp
public __aulldiv
__aulldiv proc near
assume cs:_TEXT
push ebx
push esi
DVND equ [esp + 12]
DVSR equ [esp + 20]
mov eax,HIWORD(DVSR)
or eax,eax
jnz short L1
mov ecx,LOWORD(DVSR)
mov eax,HIWORD(DVND)
xor edx,edx
div ecx
mov ebx,eax
mov eax,LOWORD(DVND)
div ecx
mov edx,ebx
jmp short L2
L1:
mov ecx,eax
mov ebx,LOWORD(DVSR)
mov edx,HIWORD(DVND)
mov eax,LOWORD(DVND)
L3:
shr ecx,1
rcr ebx,1
shr edx,1
rcr eax,1
or ecx,ecx
jnz short L3
div ebx
mov esi,eax
mul dword ptr HIWORD(DVSR)
mov ecx,eax
mov eax,LOWORD(DVSR)
mul esi
add edx,ecx
jc short L4
cmp edx,HIWORD(DVND)
ja short L4
jb short L5
cmp eax,LOWORD(DVND)
jbe short L5
L4:
dec esi
L5:
xor edx,edx
mov eax,esi
;
L2:
pop esi
pop ebx
ret 16
__aulldiv endp
_TEXT ends
end
+
END
Re:Microsoft Visual C++
That would be great! I didn't even know that was possible!kataklinger wrote: Once again: YES it is possible. You can use MSVC++ compiler, but I had some problem using MS linker (and I think it cannot produce binary file, only PE) but MinGW works fine with MSVS (error reporting is not so good but....).
Currently I'm working on asm (NASM) syntax coloring support for MSVS.NET 2003, so if someone is interested I will publish it on Internet when I finish it.
If you do post it, please update the Visual C wiki page with a link - or at least tell us how you are approaching it.
Mike
Re:Microsoft Visual C++
??? I'm asking a simple question : "How to use ASM code file in MSVS.NET 2003?". I'm just begining in OS Dev, if you know a web site or a set of tutorials (with code samples, plz) write them!!
Thanks
Thanks
Re:Microsoft Visual C++
AFAIK, short answer: You can't. MSVC++ doesn't come with an assembler, although it might have syntax highlighting.
You may be able to link a COFF object file from NASM with the MS Linker though.
You may be able to link a COFF object file from NASM with the MS Linker though.
Re:Microsoft Visual C++
You certainly can write a kernel using Microsoft's tools, but there are some additional steps. Microsoft compiles Windows and all its drivers using its own tools.
The tools with 2005 .NET are very capable indeed, as they were with 2003 .net, a huge improvement over the VC 6 stuff.
You can control things like alignment, etc as you have seen with the 2005 beta configuration file posted in this thread, and you can get MASM free of charge several places on the 'net if you want MASM instead of NASM or whatever. E.g.:
http://www.masm32.com/
I would download the Visual C++ .NET 2005 Beta 2 if I were you, if you are interested in using MS tools. Certainly you can use MS's linker as well. It's nowhere near as flexible as GAS with its linker scripts, but it's do-able.
After producing your kernel, you will probably need to use MinGW's objcopy to convert from COFF/PE to flat binary. Otherwise you will need a custom bootloader to understand how to load and run the PE, or hack GRUB to do it for you.
There's excellent documentation on PE available at MSDN. Google for "Inside Windows PE format" and you'll find two articles on the inner workings of PE.
Have fun!
The tools with 2005 .NET are very capable indeed, as they were with 2003 .net, a huge improvement over the VC 6 stuff.
You can control things like alignment, etc as you have seen with the 2005 beta configuration file posted in this thread, and you can get MASM free of charge several places on the 'net if you want MASM instead of NASM or whatever. E.g.:
http://www.masm32.com/
I would download the Visual C++ .NET 2005 Beta 2 if I were you, if you are interested in using MS tools. Certainly you can use MS's linker as well. It's nowhere near as flexible as GAS with its linker scripts, but it's do-able.
After producing your kernel, you will probably need to use MinGW's objcopy to convert from COFF/PE to flat binary. Otherwise you will need a custom bootloader to understand how to load and run the PE, or hack GRUB to do it for you.
There's excellent documentation on PE available at MSDN. Google for "Inside Windows PE format" and you'll find two articles on the inner workings of PE.
Have fun!