OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 8:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Running GeekOs on a Mac (Qemu, cross-compiler) [SOLVED]
PostPosted: Thu Oct 25, 2007 9:46 pm 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
Hi,

Anyone can give me a hand on how to get GeekOs to build and run under Qemu?

I started off with building binutils and gcc (target: i386-pc-elf).

I then tried to compile the bkerndev tutorial (very short nonfunctioning kernel, but ver instructive). All gcc steps went fine, as well as assembling using NASM, but in the final linking step, i386-pc-elf-ld did not recognize the NASM assembled file format (I tried assembling both as aout and elf).

If this linking step is not working, I am sure Geekos won't build.

-Is there a way to check the format of the compiled/assembled *.o files to see if they are in the right (elf) format?

-And/or should I have set the target to i386-elf when building the chain? I noticed some folks talk about the 'i386-elf-gcc compiler'...

Thanks!

Sebastian


Last edited by Pixion on Fri Nov 02, 2007 10:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 1:23 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Hi,

1) What is GeekOS? Is this the codename for your own OS? (you don't mention it anywhere ;) )

2) Please post the output of the link command, also your compile/link commands themselves, then we can help you.

3) If you liked Bran's dev tutorials, you could possibly try http://www.jamesmolloy.co.uk, those tutorials initially cover the same stuff in a similar way then move on to other things like paging and a kernel heap (working on a VFS and initrd now). Might help you.

Cheers,

JamesM

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 2:20 am 
Offline
Member
Member
User avatar

Joined: Tue Aug 08, 2006 7:43 am
Posts: 271
Location: Sydney, Australia
GeekOS
http://geekos.sourceforge.net

_________________
The cake is a lie | rackbits.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 3:08 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
-And/or should I have set the target to i386-elf when building the chain? I noticed some folks talk about the 'i386-elf-gcc compiler'...
I'd have expected i586-elf, since that's used in the [wiki]GCC Cross-Compiler[/wiki] tutorial. Even though that one is written against cygwin, it works under linux and might therefore do as well on a mac. It should at least give you the correct configure options etc.

That said, I do use a i386-elf myself (without the -pc-) but its built the same way as in the tutorial above.

_________________
"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 ]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 9:45 am 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
Thanks for the replies.

I found a number of posts on this site that describe the use of a cross compiler for Brian's kernel tutorials. I will try those points first.

But, a target=i386-pc-elf should give the same build as target=i386-elf for binutils and gcc?

Thanks,

Sebastian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 9:51 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
The mac linker is notorious for being crap. Are you sure your ported toolchain is actually calling the *ported linker*? If you missed a $PREFIX somewhere it'll just call /usr/bin/ld...

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:04 am 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
JamesM,

I used the following commands for build/install (both for binutils and gcc, the latter with some further restrictions):

./configure --target=i386-pc-elf --pefix=/usr/local/elf
make
make install

All tools are in /usr/local/elf. I added the underying bin to my PATH and I can invoke the Xcompiler using i386-pc-elf-gcc.

However, when compiling an empty prog (no includes, no lib functions, just void main(){}), during the linker step it complains about a missing *.o file. In the error message it says it looked in the /usr/local/elf/bin/../../ directories, so it is probably well installed. I think this could be a required precompiled library or glue(?) code, which I don't have.

Do you think there is a difference between target=i386-pc-elf and target=i386-elf?

Thanks!

Sebastian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:33 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
...well could you post the error message?

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:39 am 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
I will, but need to switch OS first...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:45 am 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
I will, but need to switch OS first...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 4:08 pm 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
JamesM,

Here the error I got after compiling an empty program (void main(){}):

Code:
s-s-computer:~/Desktop ss$ i386-pc-elf-gcc main.c     
/usr/local/elf/lib/gcc/i386-pc-elf/4.2.1/../../../../i386-pc-elf/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status

I think it has to do with missing glue code (not sure what that is, but I came accross it somewhere).

When compiling with the -c option (no link) and subsequent linking step, I get a valid a.out file. (although the linker defaults the entry point, which should be o.k. I think):



Code:
s-s-computer:~/Desktop ss$ i386-pc-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o main.o main.c
s-s-computer:~/Desktop ss$ i386-pc-elf-ld main.o
i386-pc-elf-ld: warning: cannot find entry symbol _start; defaulting to 08048074
s-s-computer:~/Desktop ss$ i386-pc-elf-objdump -f a.out

a.out:     file format elf32-i386
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x08048074


Also, I was able to get Brian's kernel tuts up and running (after removing the leading _ in the start.asm file and a diferent linker script as discussed elswhere on this site.

Anyway, thanks for your input, I appreciate that people like you spend time in answering questions and especially, writing great tuts! (I will have to read up on your one.)

Sebastian


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:41 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Hi,

I asked a similar question and was told to use -nostdinc and -nostdlib options with LD as well as GCC - seemed to do the trick.

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:51 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
AJ has it right. You're right: the 'glue code' is the problem.

The compiler/linker requires a few things before it will compile 'normal' (not kernel) code properly:

- a C library (@regs: please don't flame me on this, I KNOW you can just 'touch libc.a'.)
- several object files, the most important of which is called crt0.o. Others include crtbegin.o and crtend.o.

Basically the crt0 is the initial code that should be run (before your main() function). The reason for this is the OS needs to set up some standard file descriptors and other things before user code can run. As such GCC expects this file and complains when it is not there.

In a kernel, you don't need this file at all, since you specify yourself what code should run and where the entry point should be. So you can stop GCC looking for it with the flag '-nostdlib'. You should also disable looking for standard header files (which would be linux-based and not healthy) by adding '-nostdinc'.

Hope this helps,

JamesM

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:55 pm 
Offline

Joined: Thu Oct 25, 2007 8:18 pm
Posts: 16
Thanks,

I am now up and running, both w. Brian's kernel and GeekOs!

Sebastian

Here is how to do it:

-On Mac, build cross-compiler & binutils (there are some detailed guidelines on the web that describe this for an 'avr toolchain'):

target=i386-pc-elf, prefix=/usr/local/elf

-During building gcc, you probably get an error around 'libssp'. In that case add the following option during the configure step --disable-libssp and build again.

-Another option is to use Darwinports and download the whole preconfigured source using their CVS (search for i386-elf-gcc on their site).

-Once you have the cross compiler built, and added its prefix to your PATH (add /usr/local/elf/bin to PATH), you are set to go. Note that as you don't have appropriate runtime libraries etc. you will not (yet) be able to compile 'standard' c-programs for this target, but as you are building your own kernel, this is o.k. (see discussion in this thread).

-Now you have a working linker (i386-pc-elf-ld) which actually has the option of using a linker script (the ld that ships w. Xcode on Mac is an adapted version....).

-To build GeekOs, you only need to go in the make file and change the tool prefix:


Code:
# ----------------------------------------------------------------------
# Tools -
#   This section defines programs that are used to build GeekOS.
# ----------------------------------------------------------------------

# Uncomment if cross compiling
#TARGET_CC_PREFIX := i386-elf-

to
Code:
# ----------------------------------------------------------------------
# Tools -
#   This section defines programs that are used to build GeekOS.
# ----------------------------------------------------------------------

# Uncomment if cross compiling
TARGET_CC_PREFIX := i386-pc-elf-



Now make will use your cross-compiler and linker.

-Then get Qemu installed on your Mac

-Set up a standard PC (don't select a large RAM, GeekOs can not deal with that, 8MB is fine, 128MB will crash the kernel)

-Run - and add the code as you go from project to project...

Hope that helps!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 24, 2008 4:23 pm 
Offline
User avatar

Joined: Tue May 20, 2008 4:52 pm
Posts: 20
Location: St Louis, Missouri, USA
Quote:
-During building gcc, you probably get an error around 'libssp'. In that case add the following option during the configure step --disable-libssp and build again


Using the steps in the wiki I ran into this. So, what exactly is libssp? A google of libssp returns download links, no real help there. Also, excuse the thread zombification. I'd rather raise an existing related thread to ask my little question, rather than create another.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 25 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