So, VS can only emit PE executables. I don't want any creepy hack to inject a multiboot header in it, so I wrote a custom bootloader for PE executables on a FAT16 hard disk.
I've been successful (at least, it seems to work), to build a file interface like fopen, fread, fseek in real mode ASM. Then I loaded the executable sections to the ImageBase address. The problem is that the code contains references to strange memory addresses.
For example main:
Code: Select all
int main()
{
print("Hello world from the 64-bit kernel.");
return 0;
}
Code: Select all
00000490 4883EC28 sub rsp,byte +0x28
00000494 488D0D650F0000 lea rcx,[rel 0x1400]
0000049B E8A0FFFFFF call dword 0x440
000004A0 33C0 xor eax,eax
000004A2 4883C428 add rsp,byte +0x28
000004A6 C3 ret
My linker command line is:
Code: Select all
/OUT:".\krnl.exe" /NXCOMPAT:NO /PDB:".\krnl.pdb" /DYNAMICBASE /MAPINFO:EXPORTS /FIXED:NO /LARGEADDRESSAWARE /BASE:"0x100000" /MACHINE:X64 /ENTRY:"main" /WINMD:NO /OPT:REF /SAFESEH:NO /INCREMENTAL:NO /PGD:".\krnl.pgd" /SUBSYSTEM:NATIVE /MAP":Kernel.map" /OPT:ICF /ERRORREPORT:QUEUE /NOLOGO /ALIGN:4096 /NODEFAULTLIB /TLBID:1
What does "/DRIVER" do to the ultimate executable?
Thanks in advance.
Update:
Just upgraded from VS2012 RC to the final release. The problem with /DRIVER is now solved. But relocations are still there...