Visual Studio: Difference between revisions

Jump to navigation Jump to search
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Add information on compiling/debugging with i686-elf cross compiler toolchains)
m (Bot: Replace deprecated source tag with syntaxhighlight)
Line 8:
 
MinGW32's objcopy should do the job (parameters go something like this: -x -g -X -S -Obinary kernel.bin). But you don't have to strip any information from PE file, the other option is to set section alignment in memory to 0x200 which is generally equal to the section alignment on disk and do some math:
<sourcesyntaxhighlight lang="asm">
mov eax, [es:0x3c] ; PE header pointer in MZ header
mov ecx, [es:eax+0x28] ; AddressOfEntryPoint in PE header
</syntaxhighlight>
</source>
 
where es is loaded with base address of your [[PE Binaries|PE]] file in memory, ecx will be loaded with the entry point relative to base address of PE file. Of course, if this is protected mode with a flat 4GB address space, use a register instead of using ES.
Line 96:
* On the '''GDB startup commands''' tab, under ''The following GDB commands will be run AFTER selecting a target:'' enter the following
 
<sourcesyntaxhighlight lang="c">
symbol-file kernel.elf
add-symbol-file boot_sect.elf 0x7c00
directory $(RemoteSourceDir)/src
</syntaxhighlight>
</source>
: These will load the symbols for your kernel and bootsector respectively, allowing you to debug through the sourcecode in your debugger.
Line 136:
== Some basic definitions: ==
 
<sourcesyntaxhighlight lang="c">#define EXTERN extern "C"
#define EXPORT EXTERN __declspec(dllexport) // exported from DLL
#define IMPORT EXTERN __declspec(dllimport) // imported from DLL
Line 156:
}
}
</syntaxhighlight>
</source>
 
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.
Line 265:
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:
<sourcesyntaxhighlight lang="cpp">
//Entry point goes here
 
Line 293:
(uint32_t)&entry - BASE_ADDR + LOADBASE
};
</syntaxhighlight>
</source>
 
== The Rebase Utility ==
Line 323:
 
This is why if you intend to do 64 bit development in MSVC++ you should have an external assembly layer (seperate versions for 32 bit and 64 bit), or use somewhat more limited intrinsics, and for asm if you want to avoid name decoration you need to declare them in a header file like this:
<sourcesyntaxhighlight lang="cpp">
#ifdef __cplusplus //if this is C++
extern "C" { //declare as C functions
Line 332:
} //and if it was C++ we need to close the brackets
#endif
</syntaxhighlight>
</source>
And in your asm layer:
<sourcesyntaxhighlight lang="asm">
BITS 32 ;32 bit version
@disable@0:
Line 345:
cli
ret ;No decoration at all
</syntaxhighlight>
</source>
 
== Intrinsics ==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu