GRUB2 + VS2010 Bare bones

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: GRUB2 + VS2010 Bare bones

Post by Nessphoro »

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)
User avatar
Ameise
Member
Member
Posts: 61
Joined: Fri Jul 16, 2010 7:46 am
Location: Chicago

Re: GRUB2 + VS2010 Bare bones

Post by Ameise »

You don't get code/error highlighting anymore, though, as that is dependent upon CL. Or, at least, the two compilers don't match - what you see isn't necessarily what the compiler does.

I simply use stub projects to handle vhd and so forth, so I also can use F5 to start the kernel. I just use CL as the compiler because it means that what I see in the IDE, even errors (the red underlining) matches the output of the compiler.

It may be possible to accomplish proper GCC integration with MSVC, but it would likely require some serious editing of MSBuild scripts - something I don't have much familiarity with.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: GRUB2 + VS2010 Bare bones

Post by Nessphoro »

No, actually you can view errors in the Output window, and with a simple perl script you can get your error highlighting from GCC.
User avatar
Ameise
Member
Member
Posts: 61
Joined: Fri Jul 16, 2010 7:46 am
Location: Chicago

Re: GRUB2 + VS2010 Bare bones

Post by Ameise »

Nessphoro wrote:No, actually you can view errors in the Output window, and with a simple perl script you can get your error highlighting from GCC.
Impossible: Perl is never simple.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Combuster »

Ameise wrote:insults do not quality as ad hominem attacks, unless the argument itself is an insult. Saying "you're dumb" is not an ad-hominem, but saying "You're wrong because you're dumb" is.
If it wasn't for the argument, I'll just conclude that you've been purposefully breaking forum rules then. Not that it matters for your reputation anymore.

You have three members opposing your point of view, of which two seniors. You have zero supporters. Apparently you need to call us names in an attempt to win the debate. I can't show you the light among this madness, but it'll be obvious to the more observant readers that you have lost this debate.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: GRUB2 + VS2010 Bare bones

Post by Fanael »

The only thing this thread is lacking is popcorn.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: GRUB2 + VS2010 Bare bones

Post by Creature »

Combuster wrote:
Ameise wrote:insults do not quality as ad hominem attacks, unless the argument itself is an insult. Saying "you're dumb" is not an ad-hominem, but saying "You're wrong because you're dumb" is.
If it wasn't for the argument, I'll just conclude that you've been purposefully breaking forum rules then. Not that it matters for your reputation anymore.

You have three members opposing your point of view, of which two seniors. You have zero supporters. Apparently you need to call us names in an attempt to win the debate. I can't show you the light among this madness, but it'll be obvious to the more observant readers that you have lost this debate.
Just having finished reading the entire topic, I want to just say that I understand why GCC is proposed as "the most feasible choice" for OSDev, but is this really a debate? Ameise merely stated the reasons that he prefers VC++ (and the accompanying IDE, but this is of lesser importance) over GCC for his OS. Even though most of the people here don't agree to that choice or don't see the use of that, doesn't mean that he should be personally attacked for that. I do not think any less of Ameise after this topic, nor will I question his authority or knowledge in further topics on this forum because of this thread (but then again, I may not fall in the "more observant readers" category). It seems as if all his arguments are merely coming forth from personal opinion, rather than facts. I never read any of his posts in this topic stating that GCC is crap or MSVC is the best, he merely expressed his personal preference.

To get back on topic (well, on topic might not be the right word) and to add to the point of discussion around GCC being designed ("these days") for Linux, I think it's more circumstantial than actually a design choice. GCC is used on, and can target, a load of platforms, but one can't get around the fact that it is shipped with the majority of the Linux distributions out there. One could argue that a consequence of this is that developers using Linux (who are perhaps looking to contribute to a project) lean towards GCC and add features to it. Most of these developers are probably also Linux sympathisants (seeing as "the uninitiated" usually don't use anything other than Windows, and sometimes Macs) and spend more time on features that will sooner or later benefit the OS they are working on, causing these features to develop sooner than other features, making it seem as if it was dedicated to Linux. One could then again argue: if it seems to be dedicated to something (not necessarily Linux) and, be it due to circumstances or not, provides a "favoritism" towards something, is it actually dedicated towards it?

I'm not trying to troll this thread further, but rather to add a different perspective to the previous posts (and hopefully, somehow cool the engines :)).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Solar »

Ameise wrote:
Nessphoro wrote:No, actually you can view errors in the Output window, and with a simple perl script you can get your error highlighting from GCC.
Impossible: Perl is never simple.
=D>

Next round of flaming to commence shortly. Blanket statements == trouble.
Every good solution is obvious once you've found it.
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: GRUB2 + VS2010 Bare bones

Post by gedd »

@Nessphoro

Makefile does not require VS2012, you can also use QT creator, NetBeans, Eclipse, or command line. What is the benefit ?
VHD only woks on Windows 7 (XP & Vista are out)
Where Grub2 ?

I'm not saying you're wrong but I just keep my setup.
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Griwes »

Syntax and error highlighting, as well as autocompletion, in KDevelop are more (or at least similary) awesome than (as) in MSVC, but everyone seems to be saying "blah, KDE IDE" and don't use it... while it is probably best one for *nixes. You don't need MSVC to have decent IDE, with decent highlighting and decent autocompletion, ya know?
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Solar »

Griwes wrote:You don't need MSVC to have decent IDE, with decent highlighting and decent autocompletion, ya know?
I know. Vim is completely sufficient for that. :twisted:
Every good solution is obvious once you've found it.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Griwes »

Eh, you vim followers :D
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
Ameise
Member
Member
Posts: 61
Joined: Fri Jul 16, 2010 7:46 am
Location: Chicago

Re: GRUB2 + VS2010 Bare bones

Post by Ameise »

Creature wrote:
Combuster wrote:
Ameise wrote:insults do not quality as ad hominem attacks, unless the argument itself is an insult. Saying "you're dumb" is not an ad-hominem, but saying "You're wrong because you're dumb" is.
If it wasn't for the argument, I'll just conclude that you've been purposefully breaking forum rules then. Not that it matters for your reputation anymore.

You have three members opposing your point of view, of which two seniors. You have zero supporters. Apparently you need to call us names in an attempt to win the debate. I can't show you the light among this madness, but it'll be obvious to the more observant readers that you have lost this debate.
Just having finished reading the entire topic, I want to just say that I understand why GCC is proposed as "the most feasible choice" for OSDev, but is this really a debate? Ameise merely stated the reasons that he prefers VC++ (and the accompanying IDE, but this is of lesser importance) over GCC for his OS. Even though most of the people here don't agree to that choice or don't see the use of that, doesn't mean that he should be personally attacked for that. I do not think any less of Ameise after this topic, nor will I question his authority or knowledge in further topics on this forum because of this thread (but then again, I may not fall in the "more observant readers" category). It seems as if all his arguments are merely coming forth from personal opinion, rather than facts. I never read any of his posts in this topic stating that GCC is crap or MSVC is the best, he merely expressed his personal preference.

To get back on topic (well, on topic might not be the right word) and to add to the point of discussion around GCC being designed ("these days") for Linux, I think it's more circumstantial than actually a design choice. GCC is used on, and can target, a load of platforms, but one can't get around the fact that it is shipped with the majority of the Linux distributions out there. One could argue that a consequence of this is that developers using Linux (who are perhaps looking to contribute to a project) lean towards GCC and add features to it. Most of these developers are probably also Linux sympathisants (seeing as "the uninitiated" usually don't use anything other than Windows, and sometimes Macs) and spend more time on features that will sooner or later benefit the OS they are working on, causing these features to develop sooner than other features, making it seem as if it was dedicated to Linux. One could then again argue: if it seems to be dedicated to something (not necessarily Linux) and, be it due to circumstances or not, provides a "favoritism" towards something, is it actually dedicated towards it?

I'm not trying to troll this thread further, but rather to add a different perspective to the previous posts (and hopefully, somehow cool the engines :)).
I entirely expected to be flamed and attacked. Doesn't mean I like it, but I expected it. Unpopular opinions are unpopular, and most users here either (or both) use Unix or are developing Unix-like systems. I wasn't expecting the level of hostility for merely using Visual Studio, but whatever. Apparently, having a personal preference is a 'point of view' that needs to be argued against, and that the number of people with opposing or the same point of view matters (Combuster).

It's hard to have facts in regards to something such as 'the developers seem...'... it as certainly been my personal experience (as you said) that they don't seem to care about features that don't directly benefit projects that will inevitably be run on Linux. Whether or not my personal experience is the same as someone else's doesn't warrant them calling me a 'liar' (Combuster), regardless of whether or not said person is a 'senior member' (I don't look favorably upon seniority-based favoritism - just because you're a senior member doesn't mean that you're perfect). It is circumstantial, but the bias becomes evident via circumstance... the vast majority of the software is going to be built for Linux, so it inevitably becomes biased towards Linux. Whether or not that's a good thing is irrelevant and I haven't made a statement as to that. I most certainly, however, never said that GCC was -designed- for Linux originally (as much as Griwes and Brynet seem to claim). I think that they need to tone down the self-righteousness and GCC-fanatiscism a bit and actually read what I write before responding to it (as Brynet has admitted that he read one line, and replied immediately with a personal insult). However, righteousness runs deep, and when someone believes they're right to a strong degree, they are going to attack opposing opinions strongly, and ignore that they themselves are acting in a hypocritical manner (not saying that I'm innocent of that, but not saying other people are, either). I'd offer a truce in that regard, but I've already been rejected in that respect by the opposition group that formed, so I am just going to move on.

---

RE the Perl script, I am interested in seeing how it interoperates with MSVC. I was under the impression that the only means by which to interact with the IDE directly was editing the MSBuild scripts, but I am eager to be proven wrong in that respect. I know that in regards to the PS3 devkit (which can use GCC or SNC) they use heavily edited MSBuild scripts.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by AJ »

Locked.

Although the topic went off the rails a while ago, there are some relevant, objective posts mixed in there, so I'm not going to selectively delete posts and risk removing one side of the argument.

@gedd: Can I suggest that if you wish to provide a tutorial on this way of doing things, you create a wiki page under your own userspace? When you are happy that things work and they are finalised, you can always try to get feedback from the wiki forum on whether to incorporate this in to the main wiki. Despite the flaming, I'm sure that there are some who would find this information useful and it would be better for people to be able to be able to find it written in an objective way on the wiki than at the start of this flamefest.

Cheers,
Adam
Locked