BareBones64 ?

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.
Post Reply
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

BareBones64 ?

Post by Pype.Clicker »

Still very busy with my Phd thesis and my wedding, but i'm missing you, guys ... and i have to admit it, i'm missing those USB and graphic accelerants and ACPI/APIC too.

I cannot help wishing we had a cleaner beast than x86 to hack with, but well, the world is what it is, right ?

But back on topic. Iirc, there is atm. no such thing like a long-mode GRUB, is it? And there isn't anything like a x86-64 (long mode) barebone in the wiki.

So this is a call for participation. Who has been doing enough attempts with x86-64 and would be willing to give recommendation on how to setup a quick kernel that runs in long mode and that people could start using (i guess out of 32-bit GRUB) in a couple of hours if one has already written down another kernel?

And what would you have to share ?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I think GRUB should support 64-bit mode, personally.

Perhaps you could get the source and then create GRUB-64?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

I guess you could have grub load an elf32 stub which then switches to long mode and relocates an elf64 binary that is provided as a module.

Of course a grub which both switches to long mode for you and is able to relocate an elf64 binary might make a lot more sense, but then I suppose most people here are more interested in writing kernels than boot loaders.

Regards,
John.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post by bluecode »

jnc100 wrote:I guess you could have grub load an elf32 stub which then switches to long mode and relocates an elf64 binary that is provided as a module.
Well I do that and it's around 600 lines of assembly code just for the loader, so it's nothing for a bare bones and the elf is not relocated at all, just the segments are loaded into memory...
Of course a grub which both switches to long mode for you and is able to relocate an elf64 binary might make a lot more sense, ...
The problem with switching to longmode is, that you have to enable paging and it would suck if grub did enable paging imho...

edit: grub2 should be able to load elf64 files properly...
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

bluecode wrote:just the segments are loaded into memory
Sorry, meant load.
bluecode wrote:it's around 600 lines of assembly code just for the loader
Not wanting to get into a discussion on C vs asm, but that would be less in C and possibly more understandable for beginners (who I assume the bare bones tutorial is aimed at).
bluecode wrote:it would suck if grub did enable paging imho...
Grub sets up a gdt to enter pmode, what's wrong with it setting up a small paging setup that maps the kernel and multiboot header? You can always change it later (as we do with the gdt). The only extra information it would need to provide is which physical addresses have been assigned to the kernel etc, but with a bit more work you could even get these from the page tables.

I suppose the physical memory manager (depending on your implementation) would be more difficult to set up with paging enabled, but not impossible. I'm sure if a ready-made long mode was provided by grub, it would be able to be switched on or off by a command line option. I presume we can all agree that having grub be able to parse elf64 would be a good thing, however?

By the way, there's a short discussion on the implementation of loading an elf64 OpenSolaris kernel in grub at http://www.opensolaris.org/jive/thread. ... 5&tstart=0

edit: Multiboot draft for grub2 http://grub.enbug.org/MultibootDraft

Regards,
John.
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:

Post by Combuster »

I think you can just assemble a 32-bit loader stub to a 64-bit ELF object file format. You can put the initialisation code in there (enable longmode and paging then jump to the kernel entry point), then link all the files into a binary image. If you are good with position-independent code, you can write a higherhalf barebones pretty much the same way.

But then again, I never even managed to get PAE working so i might be missing some details.

$.02
"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
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: BareBones64 ?

Post by Candy »

Pype.Clicker wrote:Still very busy with my Phd thesis and my wedding, but i'm missing you, guys ... and i have to admit it, i'm missing those USB and graphic accelerants and ACPI/APIC too.

I cannot help wishing we had a cleaner beast than x86 to hack with, but well, the world is what it is, right ?

But back on topic. Iirc, there is atm. no such thing like a long-mode GRUB, is it? And there isn't anything like a x86-64 (long mode) barebone in the wiki.

So this is a call for participation. Who has been doing enough attempts with x86-64 and would be willing to give recommendation on how to setup a quick kernel that runs in long mode and that people could start using (i guess out of 32-bit GRUB) in a couple of hours if one has already written down another kernel?

And what would you have to share ?
I have my own kernel which works on AMD64 plus a bootloader that works on *FS and that includes long mode booting support. I have an example hello world for long mode and my own kernel. The boot loader contains a simple file called "longmode.asm" that boots to longmode including setting up paging. The longmode kernel, sadly, crashes because of some complexity in getting paging right, but I'm working on that very recently (few days ago). There is a release of the bootloader, hello worlds and mkfs tool that together can make a working system, but it's incompatible in terms of paging setup with my kernel so it's an intermediate version. It's a "finished" version though, the three items are freely exchangeable.

You can probably port most of the long mode code to Grub. As I believe in making all the base code public domain, this is too. You can download it from http://www.sf.net/projects/atlantisos - either the published version or the SVN version. The SVN version boots with a different setup and includes updated paging code in the C part of the bootloader.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Post by quok »

I would definitely be interested in helping with a long mode barebones kernel. Grub2 isn't entirely stable, but it can load an elf64 file and set up long mode for you. Yes, this means enabling paging, but it's really not all that bad. I've got a hello world kernel in long mode already (using Grub2) that I would happily post to the wiki. Also, I'd be willing to help add elf64 support to Grub Legacy should anyone be interested in that.
13postures
Posts: 13
Joined: Sat Apr 28, 2007 1:57 am

Post by 13postures »

quok wrote:Also, I'd be willing to help add elf64 support to Grub Legacy should anyone be interested in that.
There is patch that is supposed make grub legacy load elf64 images. You can find it here:
http://savannah.gnu.org/bugs/?17963

I have never used it, so don't blame me if it doesn't work. :wink:

I currently use grub2 to load elf64 images and it seems to do ok, even though it's behavior is not as smooth as the next version of Multiboot Specification describes.

@quok
I would greatly appreciate it if you could give me your hello world kernel in long mode to experiment.
Post Reply