OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:25 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Creating a 64-bit Kernel Tutorial
PostPosted: Fri Apr 11, 2008 7:23 pm 
Offline
Member
Member
User avatar

Joined: Tue Apr 10, 2007 4:42 pm
Posts: 224
I just finished a rough draft of a tutorial on how to compile and link a 64-bit kernel. It covers compilation, linking (as a higher-half elf64), and three different ways of loading the kernel (including how to include a 32-bit bootstrap into an elf64 executable).

Hope this reduces the number of people who have trouble with x86-64 kernels, like relocation issues and loading. :)

The article is here.

Thoughts/improvements?

_________________
"Sufficiently advanced stupidity is indistinguishable from malice."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 10:33 pm 
Offline
Member
Member

Joined: Wed Apr 09, 2008 6:57 pm
Posts: 63
Looks good to me at a glance :-)

As you know, I had many issues while trying to do this, and you've covered them, which is fantastic. If only you'd written it earlier, it would have saved me a lot of time ;-)

I might have to go back and add to my 32-bit kernel stub, so that it can read the GRUB2 multiboot information tags, because at the moment I've got no support for that... just for the old structure.

Cheers,
Lee


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 7:28 am 
Offline

Joined: Sat Nov 24, 2007 6:41 pm
Posts: 16
Location: loglogdecalog
Sorry to ressurect the thread, but I ran across this thread that describes how opensolaris loads a 64-bit elf into grub. If I'm understanding correctly, they set bit 16 in the multiboot flags, which forces grub to look at the header address fields specified in the multiboot header rather than parse out the elf. So they set all the address info at link time and then give grub physical start/end and entry addresses themselves.

Thoughts? Perhaps something to add to the wiki? (I haven't been approved for editing yet, otherwise I'd love to help.)[/url]

I'm going to try and test this when I get home from work this afternoon.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 8:18 am 
Offline
Member
Member

Joined: Wed Jul 25, 2007 8:45 am
Posts: 391
Location: London, UK
This is what I do on my 64-bit port, works nicely. Doesn't require any special patches to GRUB so it's easy to implement. I have the following in my multiboot header:

Code:
multiboot_header:
   .long MB_KERNEL_MAGIC
   .long (MB_HFLAG_MODALIGN|MB_HFLAG_MEMINFO|MB_HFLAG_KLUDGE)
   .long -(MB_KERNEL_MAGIC + (MB_HFLAG_MODALIGN|MB_HFLAG_MEMINFO|MB_HFLAG_KLUDGE))
   .long KA2P(multiboot_header)
   .long KA2P(__text_start)
   .long KA2P(__data_end)
   .long KA2P(__end)
   .long KA2P(_start)


The KA2P macro just converts a virtual address to a physical address, and the MB_HFLAG defines are as follows:

Code:
/* Flags for the multiboot header */
#define MB_HFLAG_MODALIGN   (1<<0)      /* Align loaded modules on page boundaries */
#define MB_HFLAG_MEMINFO   (1<<1)      /* Memory map */
#define MB_HFLAG_KLUDGE      (1<<16)      /* Use a.out kludge */

_________________
http://alex-smith.me.uk


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 12:29 pm 
Offline

Joined: Sat Nov 24, 2007 6:41 pm
Posts: 16
Location: loglogdecalog
Cool, works for me as well. Interestingly enough, NASM & ld balked when I tried to extern the _start _edata and _end symbols (relocation truncated error), but gas has no problems. Looks like I'm switching assemblers.

Could those with edit permissions add this to the wiki entry?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 3:02 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
slide_rule wrote:
Could those with edit permissions add this to the wiki entry?
I do believe you can do so yourself, http://www.osdev.org/phpBB2/groupcp.php

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 4:12 pm 
Offline

Joined: Sat Nov 24, 2007 6:41 pm
Posts: 16
Location: loglogdecalog
I'd love to, but...
slide_rule wrote:
Perhaps something to add to the wiki? (I haven't been approved for editing yet, otherwise I'd love to help.)

...my membership is still pending.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 5:26 pm 
Offline
Member
Member

Joined: Sat Dec 30, 2006 2:31 pm
Posts: 729
Location: East Coast, USA
Have you tried just logging in yet? I was told at one point in time that as soon as you apply for permission you are given it.

_________________
My OS: Fuzzy Logic


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 9:07 pm 
Offline

Joined: Sat Nov 24, 2007 6:41 pm
Posts: 16
Location: loglogdecalog
Just tried: claims my user name is invalid, so I assume no go just yet. No worries.


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Fri Nov 21, 2008 3:50 am 
Offline

Joined: Fri Nov 21, 2008 3:45 am
Posts: 1
Hi, I build x86_64-pc-elf-gcc and x86_64-pc-linux-ld successfully.
And I use the same link script with your document.

But I set the KERNEL_VMA as 0xFFFF800000000000 (same with linux kernel),
then I meet this error.


x86_64-pc-elf-gcc -Wall -Winline -I./include -fno-stack-protector -O2 -nostdinc -nostdlib -m64 -ffreestanding -nostdlib -mcmodel=large -c printf.c
x86_64-pc-linux-ld -nodefaultlibs -nostdlib -Map link_map.txt --defsym KERNEL_VMA=0xFFFF800000000000 -o main.tmp -T ld-script.ld head.o main.o screen.o io.o printf.o string.o
head.o: In function `_start':
head.asm:(.text+0xd): relocation truncated to fit: R_X86_64_32 against `.text


Could you guess my fault? Gcc Option or ld optioin?


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Fri Nov 21, 2008 2:26 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 22, 2007 12:47 pm
Posts: 1598
Location: New Hampshire, USA
could you post your link.ld and batch/makefile?

_________________
Website: https://Joscor.com


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Sat Nov 22, 2008 10:11 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
wiki wrote:
Enter Protected Mode (or skip this step and enter long mode directly)


I don't think that that should point on the forum. Perhaps the forum thread should be in the See also section or smth like that and your link should point here.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Sun Jan 08, 2017 11:06 am 
Offline

Joined: Sun Jan 08, 2017 10:56 am
Posts: 2
Could you please provide the links for the code of elf.c and elf.h used in the option of using a separate loader for creating the 64 bit kernel?


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Sun Jan 08, 2017 2:05 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 05, 2012 11:23 am
Posts: 616
Location: Germany
vinaychandra wrote:
Could you please provide the links for the code of elf.c and elf.h used in the option of using a separate loader for creating the 64 bit kernel?
This thread is 9 years old..

_________________
Ghost OS - GitHub


Top
 Profile  
 
 Post subject: Re: Creating a 64-bit Kernel Tutorial
PostPosted: Sun Jan 08, 2017 2:07 pm 
Offline

Joined: Sun Jan 08, 2017 10:56 am
Posts: 2
Yes, but this is the link to it i can find and also, the latest modification is a month ago


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group