I think it is my duty to at least attempt to stop this shitstorm,
Why don't we take the best out of both worlds?
I personally love code highlighting in VS2012 - but I also love GCC's flexibility. No biggie, OSDevers are h4ax0rs anyway, so lets hack something together.
Keep in mind that these are the steps from the beginning, as it happened for me.
1: Well, first you need to get a copy of Visual Studio 2012, duh, and cygwin.
2: Make an elf cross-compiler (Plenty info about this in the wiki)
3: Make yourself a VHD (Hint:
Windows Loopback Alternative), also I saved it as C:\os\harddrive.vhd
Extra h4x0r points, installing grub onto it from a hex editor, lol.
0: Get GRUB binaries
1. Put first 446 (440) bytes of stage1 to your MBR.
2. Patch this code:
- store byte 80h at 40h (it's variative; you can pass it) ; boot_drive field
- store word 2000h at 42h ; kernel_address field
- store dword 1 at 44h ; kernel_sector field
- store word 200h at 48h ; kernel_segment field
3. Put fat_stage1_5 (or other stage1_5) after MBR (starting from sector number 1).
4. Patch this code:
- store dword 2 at 200h+1F8h ; start field of kernelblock
- store word size_of_stage1_5_in_sectors-1 at 200h+1FCh ; len field of kernelblock
- store word 220h at 200h+1FEh ; seg field of kernelblock
- store byte partition_number_where_stage2_is_located at 200h+219h ; 0 - first primary partition, etc.
- store byte 80h at 200h+21Ah (it's variative too)
(200h is location of stage1_5 on the disk where you are storing it)
5. Ensure that path (and name) of stage2 stored at 200h+21Bh is correct.
6: Make your menu.lst
Code: Select all
title My OS
root (hd0,0)
kernel /kernel.bin
( Now is the part where your setup might differentiate from mine. Here my OS's files are located in C:\OS, C:\gcc\cross\bin has the cross binaries, and cygwin path should be self-explanatory)
4: Create a makefile in C:\OS
Code: Select all
PROJECT_DIRS := source
TARGET :=i586-elf-
PATH :=/cygdrive/c/gcc/cross/bin
PATH_OUT:=/cygdrive/f/
SRC_DIR :=source
CPP_FILES := $(shell find . -name *.cpp)
ASM_FILES :=$(shell find . -name *.asm)
OBJ_FILES := $(subst source/,obj/,$(patsubst %.asm,%.o,$(ASM_FILES))) $(subst source/,obj/,$(patsubst %.cpp,%.o,$(CPP_FILES)))
LD_FLAGS := -T /cygdrive/c/OS/linker.ld
CC_FLAGS := -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector -O3 -fleading-underscore -c -std=c++0x -ggdb -fpermissive -I source/
kernel.bin: $(OBJ_FILES)
$(PATH)/$(TARGET)ld $(LD_FLAGS) -o /cygdrive/c/OS/kernel.bin $(OBJ_FILES) -Map f.map
/cygdrive/c/cygwin/bin/cp /cygdrive/c/OS/kernel.bin $(PATH_OUT)
obj/%.o: source/%.cpp
$(PATH)/$(TARGET)g++ $(CC_FLAGS) -o $@ $<
obj/%.o: source/%.asm
/cygdrive/c/cygwin/bin/nasm -f elf -o $@ $<
Some settings are personal ( -fleading-underscore) and I really like the c++0x standard, too. Oh and it doesn't take changed in .h files into account - whoops.
Also, $(PATH_OUT) is where the kernel will be copied on compile.
5: Create a linked file linker.ld (in C:\OS)
Code: Select all
ENTRY(loader)
SECTIONS{
. = 0xC0100000;
.text : AT(ADDR(.text) - 0xC0000000) {
*(.text)
}
.data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
*(.data)
*(.rodata*)
}
.bss : AT(ADDR(.bss) - 0xC0000000) {
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
_KernelMemoryEnd=.;
}
Please note again, this linker script is for
my OS, your settings might be different.
6: Create a NMake Project in Visual Studio, with the following settings
Debugging:
- Command: C:\Windows\SysWOW64\cmd.exe (Or whatever cmd you can use, I used this one because 64 bit doesn't work with VS?)
Command arguments: /c "C:\OS\DEBUG.bat"
NMake:
- Build Command Line:C:\cygwin\bin\bash --login -c "make -C /cygdrive/c/OS/"
Include search path:C:\OS\source (Important!!!!!!1111one)
7:
Script for attaching (Saved as VHDScriptAttach.txt) :
Code: Select all
select vdisk file=c:\os\harddrive.vhd
attach vdisk
Script for detaching (Saved as VHDScriptDetach.txt) :
Code: Select all
select vdisk file=c:\os\harddrive.vhd
detach vdisk
DEBUG.bat:
Code: Select all
diskpart -s C:\OS\VHDScriptDetach.txt
qemu.exe -hda C:\OS\Harddrive.vhd -vga std -sdl
diskpart -s C:\OS\VHDScriptAttach.txt
Final thoughts:
Now you can F6 and F5 in VS2012, and have your OS booted and compiled without hassle. And also you have access to the OS's harddrive during dev time - isn't that cool.
I know this isn't perfect, constructive criticism is always welcome and encouraged. If you are willing to polish this info and post it on the Wiki, the community will be forever grateful (or I will be - kind of - as I don't want to do it right now)