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

Re: GRUB2 + VS2010 Bare bones

Post by Ameise »

You do know that GCC was there before Linux, don't you? GCC initial release: 1987; Linux initial release: 1991. I think that you are claiming that GCC devs do have some kind of time machine out there...
As brynet, you appear to have missed the two key words: these days. I never claimed that GCC was released after Linux nor that it was originally designed for it, please stop claiming such. I claimed that these days (as in, the last 10 years) GCC is heavily oriented toward Linux - if Linux doesn't require or benefit from something, it won't be added to GCC.
switched*. You do know that you can port GCC/LLVM to your OS, but not MSVC, making you dependent on MS Windows?
Clang supports (or can support in the near future) MSVC extensions. It's also fully possible that CL could be run outside of Windows using something akin to Wine.
You said that it was designed for Linux, which is just bullshit.
I said it was designed, not originally designed. If you disagree that GCC these days (note the key words) is heavily Linux-oriented, explain why.
Fortunately, I can live with that. You've sufficiently demonstrated your lack of clue, without my assistance.
And you've demonstrated a lack of reading comprehension, writing ability, and personal skills. I can live with that.
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 »

Ameise wrote:
You do know that GCC was there before Linux, don't you? GCC initial release: 1987; Linux initial release: 1991. I think that you are claiming that GCC devs do have some kind of time machine out there...
As brynet, you appear to have missed the two key words: these days. I never claimed that GCC was released after Linux nor that it was originally designed for it, please stop claiming such. I claimed that these days (as in, the last 10 years) GCC is heavily oriented toward Linux - if Linux doesn't require or benefit from something, it won't be added to GCC.
Huh.
Huh?

Do you know there is something in POSIX world, that isn't "Linux"?
Ameise wrote:
switched*. You do know that you can port GCC/LLVM to your OS, but not MSVC, making you dependent on MS Windows?
Clang supports (or can support in the near future) MSVC extensions. It's also fully possible that CL could be run outside of Windows using something akin to Wine.
Wine is counter-argument for using it.
Ameise wrote:
You said that it was designed for Linux, which is just bullshit.
I said it was designed, not originally designed. If you disagree that GCC these days (note the key words) is heavily Linux-oriented, explain why.
It's *nix oriented, or, in other words, POSIX oriented.


Once again, *nix/POSIX != Linux.
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 »

Griwes wrote: Huh.
Huh?

Do you know there is something in POSIX world, that isn't "Linux"?
Yes. And the GCC folk may support BSD/any other *nix kernel, but their primary focus is and will continue to be Linux. Please stop speaking to me as though I were 5. I don't care if you have a snarky response such as "stop speaking with the intelligence of one" or some such - I afford you the luxury of assuming you're an intelligent adult and expect the same in return. Brynet already failed at such.
Griwes wrote: Wine is counter-argument for using it.
Not sure what you're trying to say here. Regardless, you haven't made a comment as per Clang.
Griwes wrote: It's *nix oriented, or, in other words, POSIX oriented.


Once again, *nix/POSIX != Linux.
I will state as I said above, please stop assuming that I am ignorant, or I will merely make the same assumptions in kind, and I would prefer not to have to do that. GCC is POSIX oriented, but is even further biased towards Linux development. This is undoubtedly due to the fact that Linux is by far the most widely-distributed Unix-influenced kernel.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by Brynet-Inc »

Ameise wrote:And you've demonstrated a lack of reading comprehension, writing ability, and personal skills. I can live with that.
My comprehension skills are fine, I just choose to stop reading once I reach the bullshit. I'm not sure what my writing skills have to do with my typing skills.

As for my personal skills, not quite sure what you mean. If you mean my qualifications, I'm clearly not clever enough to become a professional Android developer. But, I've been hanging around for a few years, I also just recently became a OpenBSD developer.

We're a little off-topic now, but, if you meant my interpersonal skills.. you're right, they're not so great. I can live with that.
Last edited by Brynet-Inc on Mon Jun 11, 2012 3:20 pm, edited 1 time in total.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
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 »

if Linux doesn't require or benefit from something, it won't be added to GCC.
More factual bull.

Okay so far I've only seen straw men, ad hominems and lies from your argument train. If you don't want to be treated like a 5 year old hypocrite, go fix that.
"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 ]
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 »

I'm quitting this topic, as you fail to read. Flamewars are more productive on IRC, when you don't have to spam forum's database with pointless discussions, where one of sides fail to read. Last few words here:

MSVC is developed for Windows only. You can run it (if you are serious, of course) only on Windows.
GCC and LLVM are both portable, run on all POSIXish platforms, including Windows' Cygwin (which is kind of counter-argument here, just like Wine, but in this case, it is less relevant) and Windows as MinGW.

I hope that is enough for this topic. Let's stop beating a dead horse.
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 »

Combuster wrote:
if Linux doesn't require or benefit from something, it won't be added to GCC.
More factual bull.

Okay so far I've only seen straw men, ad hominems and lies from your argument train. If you don't want to be treated like a 5 year old hypocrite, go fix that.
You've yet to point out a single straw man, ad hominem attack (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.), or lie.

In fact, the last one is quite annoying - please point out a single place where I've lied?

Perhaps you don't know the meaning of the word 'lie'? If I am mistaken about something, that is not a lie but merely incorrect. It is only a lie if the person intentionally distributes false information. So please point out a single lie on my part.
Griwes wrote: I'm quitting this topic, as you fail to read.
I read and responded. Can't say the same for you.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: GRUB2 + VS2010 Bare bones

Post by neon »

Hello,
Reliability : In what fashion is GCC more reliable?
Output Binary Support : Why do I need this?
Portability : Not everyone needs to support platforms other than x86, PPC, and ARM. In fact, most people don't.
Reliability: MSVC is less reliable because the developers that utilize the software do not have control over what Microsoft wants with it. For example, the latest C standard supported by CL is C89 which is awfully out of date. The bigger concern is that of Microsoft's threat to drop C support altogether. GCC is more reliable in this way: it is more standard; updates more; and is working on supporting c++11 and c11 standards.

Output binary support: Sometimes in OS development you might have to support multiple binary formats. Typically you might have to build your own tools for this; but it would be nice to use a single compiler environment.

Portability: A software's' life is heavily dependent on its ability to port to other architectures and software systems. This should be a goal of most projects.

Of course, if this criteria does not apply to your particular situation its fine -- but the points are still valid. IMO proper software should be designed for portability.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
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 »

One could argue that GCC isn't more reliable in regards to programmer's concerns in certain fashions. I've specifically requested features in the past and had them turned down - one was having naked functions (with a _LOCAL_SIZE) parameter. After pointing out to them that MSVC and Clang both support it, I was basically told that it was pointless to have and wouldn't be added, despite it being accepted for non-x86 targets. I'd point out that Microsoft IS working on C++11 standards, it's not as though they are ignoring it. They are ignoring C11 because they consider Visual C++ to be a C++ compiler (hence the name). Practically anything one can do in C one can also do in C++, though, so the differing target doesn't really matter.

In regards to binary, I support PE binaries, and that is also what MSVC puts out. If I was using GCC, I'd use ELF. I'm not attached enough to one or the other to have an opinion on which is better - in fact, in the future I'd like to make a PE->my own format converter.

In regards to portability, I personally only care about the 'big' archs -- x86, PPC, ARM. MSVC can target each of these (and MIPS, apparently?).

As you said, it doesn't always apply to everyone's situation. Clearly, if you want to develop for 68k using ELF binaries, MSVC isn't appropriate. But to say that MSVC isn't ever appropriate as has been suggested would be a fallacy as it implies that everyone has the same requirements (which isn't true).

This is actually my frustration with the above people (other than you) in that I don't like having my requirements dictated to me, and be told that I shouldn't use VC because "so and so" which isn't even relevant to my situation. Just because I am using MSVC doesn't mean that my code isn't portable. I plan on editing Clang at some point to have proper support for MSVC pragmas (which are what I use to handle linkage), which it doesn't have full support for yet. At that point, I just need to write a very simple project/solution parser, and I can build anywhere. I'm not bound to CL, but I am using CL's custom extensions.
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.
Locked