Visual Studio: Difference between revisions

Jump to navigation Jump to search
m
Reformat
[unchecked revision][unchecked revision]
No edit summary
m (Reformat)
Line 1:
Yes, itIt is possible to use Microsoft Visual C++ to write OS kernel, however keep in mind that all the Visual C++ compiler is able to output is [[OMF]] format object files, and the linker can only produce [[PE Binaries]], so you will have to either use a bootloader which understands these formats or convert them to, for example, [[ELF]] or flat binary.
 
See also [http://ksrenevasan.blogspot.com/2005/10/writing-multiboot-pe-kernels-using.html Kaushik Srenevasan's blog] to see how you can "[Write] multiboot PE kernels using Visual C++". This is supplemented with [http://ksrenevasan.blogspot.com/2005/10/writing-multiboot-pe-kernels-using_03.html part 2] which explains some of the things not covered in the first part.
Line 13:
'''Note:''' The options and procedures described here are for VS.NET 2003. Similar procedures should work on earlier versions. Consult the MSDN or post to the forum if you have any questions.
 
=== Visual C++ vs Visual Studio ===
Visual C++ refers only to the Microsoft C++ IDE and compiler, where as Visual Studio refers to the entire Microsoft family of compilers and IDEs as a whole. In later version, such as the Visual Studio .NET series, all languages share the same IDE program, but in Visual C++ .NET, compatibility for all other languages are removed completely, except through configuring the IDE to manually use another compiler/assembler.
 
Line 22:
Of course, you could disable the compiler and add a custom build event which runs a shell script and invokes Cygwin. If you are using Visual Studio (not Express), it is possible to use the Visual Studio SDK to create a "makefile project" that allows you to use a custom build script (such as invoking the [[Cygwin]] tool chain) to compile your code, build your image, and launch the emulator (so you can just press F5 for the whole thing to build and the emulator to start). Compiling Bochs with debugging enabled may allow you to use the Visual Studio debugger (including line by line execution) except this hasn't yet been tested.
 
=== Creating the Project: ===
 
For the kernel and any drivers, create a Win32 Project and select DLL, empty project. Choose DLL if you want to have a kernel that can export functions using the standard Win32 method. It is relatively simple to use this to export functions for use by device drivers...
 
=== Custom C++ Runtime ===
 
Since you can't use standard C/C++ runtime in your kernel, you'll need to write some of it's functionality yourself. The following article will help to [[Visual_C++_Runtime|write your custom Visual C++ runtime]]
 
=== Some basic definitions: ===
 
<source lang="c">#define EXTERN extern "C"
Line 56:
I use these to create functions that end up with reasonably undecorated names like <code>_SomeFunction@8</code> instead of <code>?@SomeFunction@YAKK000I@@Z</code> (as a __cdecl normal function would be named...) The macros also allow easy import and export from a DLL.
 
=== Compiler Options ===
 
Here is the meat of this article. These are the compiler options (right-click project, select properties) that I use for my OS.
Line 144:
: Together, they set the [[Section Alignment]] and [[File Alignment]] to 512 bytes. My boot loader is not sophisticated enough to handle these being different. The downside is that restrictions (read-only, etc) on sections are meaningless, as they require page-granularity for hopefully obvious reasons.
 
=== Bootloader Stuff: ===
 
As part of the build process, I use a tool I wrote to rebase all the PE files. The
Line 158:
Another option is to use a separate linker such as [[WLink]] with a linker script such as the one found on the [[Watcom]] page.
 
==== Multiboot ====
To be booted by GRUB, you can make your kernel multiboot. THis involves the embedding of a multiboot header in the first 8K of the image.
This can be done as follows:
Line 191:
</source>
 
=== The Rebase Utility: ===
 
Attached to [[Topic:10632|this thread]] is the source code for a page-granular rebase utility. It changes the base address of any PE file with a relocation section to the nearest page-aligned address and then removes the relocation section. It compiles under Visual Studio .NET 2003 with default settings successfully, but should work fine on any Microsoft compiler.
Line 242:
ret ;No decoration at all
</source>
If you can't work out enable(), I'll give you a free hint:
 
Give up OS dev!
 
== Intrinsics ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu