OSDev.org

The Place to Start for Operating System Developers
It is currently Fri May 10, 2024 12:35 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Bare Bones gone wrong... (can't compile)
PostPosted: Fri May 30, 2008 12:26 pm 
Offline
User avatar

Joined: Thu May 29, 2008 2:34 pm
Posts: 13
First of all, hello :) (new member)
I've been trying to get into OS development for some time now. I have almost no experience with assembly (just a few days, I'm reading 'Art of Assembly' in hope of learning it), but I have some experience with C (I'm not a beginner any more, but I'm not really satisfied with my knowledge either), so I thought I'd join the community to learn how operating systems really work. Maybe some day even create my own little os :)

Anyway, I was trying to follow the Bare Bones tutorial from wiki ( http://www.osdev.org/wiki/Bare_bones ) and I understood it rather well (some parts of assembly code I don't understand yet, but I figure I will, once I gain more experience). I have tried to compile it, only to hit a solid brick wall. So, here's my problem (hopefully someone will help), or rather- the log of things I did :

1. When trying to compile kernel.c, I get an error saying :
Code:
kernel.c:1: warning: unused parameter ‘mbd’
kernel.c:1: warning: unused parameter ‘magic’

Of course, this is due to the -Werror switch tutorial said I should use when compiling :)
So, I decided to compile without -Werror ...

2. NASM gave me loader.s with no problems...

3. When I try to link the two files (while passing linker.ld script to ld), I get this :
Code:
loader.o: In function `_loader':
loader.s:(.text+0x14): undefined reference to `_kmain'

the error occures in this part of code :
Code:
call    _kmain

Any idea why this could be?
Thank you in advance.

edit :
Just in case it matters, I will list the versions of programs I'm using :
GNU make : 3.81
gcc : 4.2.3
nasm : 0.99.06-2
ld : 2.18.0.20080103
Under Kubuntu 8.04, with 2.6.24-16 kernel.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 12:43 pm 
Offline
Member
Member

Joined: Mon Mar 24, 2008 1:46 pm
Posts: 98
the

kernel.c:1: warning: unused parameter ‘mbd’
kernel.c:1: warning: unused parameter ‘magic’

are just warnings cos your not using them so dont worry about that.

as for

loader.o: In function `_loader':
loader.s:(.text+0x14): undefined reference to `_kmain'

try removing the _
so

extern _kmain becomes just extern kmain

and
call _kmain is again just call kmain

thats assuming you linking them together correctly. you would really need to post your code and makefiles too see exactley what your doing.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 1:23 pm 
Offline
User avatar

Joined: Thu May 29, 2008 2:34 pm
Posts: 13
Thank you, that DID work.
Still I don't understand why the assembly source called _kmain, when kmain was declared in kernel.c ?

Now, I have a few more questions :
Code:
unsigned char *videoram = (unsigned char *) 0xb8000;

in kernel.c alters video memory, and should be equal to this :
Code:
     
mov ax,#0xb800
mov es,ax
seg es
mov [0],#0x41
seg es
mov [1],#0x1f

This is a BIOS interrupt, right?
Can you point me to a list of BIOS interrupts?
es stands for 'extra segment register', right? But what does that mean :) ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 1:40 pm 
Offline
Member
Member

Joined: Sun Apr 20, 2008 5:32 pm
Posts: 42
Location: Index 0 of the nearest Array
Ok for you first question. A compiler (I don't know which) adds _ to the beginning of functions so you must call them with the _.

That is not an interrupt. That is moving data into ram which is then loaded by the GFX card.

If you are in pmode the interrupts are not avalible but in real mode they are. Like on the resources page in the wiki. Not only does it have what you want (in the software specs section) but also a lot more useful information.

Extra Segment means it doesn't have a job like CS, DS, SS, and the others do. (CS refrences CODE for example and DS refrences DATA) Basically you can use ES for what ever you want. In you case you are using it to hold the spot in ram where video is stored (plus the exact position in the VID ram. By moving 2 spaces up in ram you move 2 1 space on the screen. Even spots in the ram hold charecters and odd spots hold the attribute saying what color it is, plus a bit more.)

_________________
My OS: SOS (Simple Operating System).


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 8:38 pm 
Offline
User avatar

Joined: Tue May 20, 2008 4:52 pm
Posts: 20
Location: St Louis, Missouri, USA
From : http://www.osdev.org/phpBB2/viewtopic.p ... underscore

kscguru wrote:
Gilad wrote:
this was another thing i thought about asking, why the built-in functions and in the headers files they use __


Everything you never wanted to know about those underscores ...

In source code (usually C code), single-underscore is reserved for the OS / system libraries and double-underscore is reserved for the compiler implementation.

This is why (on Linux) you get functions like exit(), which is the POSIX-compatible version that runs atexit() functions, and _exit(), which is a raw syscall that immediately and unconditionally terminates the process. fork() handles all the libc locking, while _fork() is the raw syscall that immediately starts a new process (and probably deadlocks the next time you call into libc because the internal libc locks never get released).

And this is why if you peek at the compiler's header files (e.g. stdint.h), you'll find a lot of macros and types with double-underscores. GCC uses __attribute__ (note the double-underscores) as a language extension, MSVC uses __int64 or __int128 for types that don't exist in the C language. The C specification is very particular about what symbols are allowed in the global namespace, so the compiler puts all its configuration in the compiler-reserved namespace so the compiler's symbols don't conflict with your program.

For the addition of a leading underscore ... most old formats (COFF, upon which Microsoft compilers are based, the old Unix a.out format, MacOSX mach-o) prepend an underscore to all symbol names in C files. I believe this was to avoid accidental (and hard-to-debug) name conflicts between C symbols and temporary assembly symbols generated by the compiler. But when ELF was created, the implementors decided the reasons for doing so were no longer relevant (GCC uses a prefix character that C code cannot generate), so they dropped the implied leading underscore to save a few bytes.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 31, 2008 7:08 am 
Offline
User avatar

Joined: Thu May 29, 2008 2:34 pm
Posts: 13
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 9:18 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
Actually, afaik, the underscore was added in all the original C compilers that were to coexist with Fortran to avoid name collisions with Fortran functions. You should then also be able to declare them as extern "fortran" or something and get the underscore to go that way.

Why Microsoft etc. still do that is a puzzle to me, but probably just compatibility.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:57 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
Quote:
Extra Segment means it doesn't have a job like CS, DS, SS, and the others do.


actually it does... the ES segment is implied for string operations referencing DI (iirc)

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 11:22 am 
Offline
User avatar

Joined: Thu May 29, 2008 2:34 pm
Posts: 13
It seems I've got a lot to learn...
Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

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