flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Extern C, anyone?

Author
Thread Post new topic Reply to topic
Nyrre



Joined: 26 Feb 2006
Posts: 13
Nyrre 18 Mar 2006, 19:18
Hi, it's me again. Smile
I've now programmed a working boot loader, and now I'm moving on to kernel. But I don't want to program my kernel with assembly, because it would be difficult and it would take too long.
And now I'm asking you, that do you know how to extern c to asm-code?
Post 18 Mar 2006, 19:18
View user's profile Send private message Reply with quote
j.vimal



Joined: 19 Mar 2006
Posts: 4
j.vimal 22 Mar 2006, 10:38
Hi there

All you need to do is make a wrapper in Assembly. That would do. Proceed like this:
Code:
Make an ASM file like:

[BITS 32] ;If you are already in PMode, NASM syntax. use32 for FASM.
extern _kernel_main
entry start
;kernel_main is your C function. Note that
;There is a preceding '_'. Because, the C compiler (gcc)
;Adds '_' to all functions in the object file.
;Dunno why. You?

start:
call _kernel_main
hlt ;Not necessary though. 

    


Thats it. Now compile your C code, and just do a linking, putting the above file above all others.

Hope this helps!

Vimal
Post 22 Mar 2006, 10:38
View user's profile Send private message Reply with quote
Nyrre



Joined: 26 Feb 2006
Posts: 13
Nyrre 01 Apr 2006, 18:46
Wow! Thanks. That helped me alot!
Post 01 Apr 2006, 18:46
View user's profile Send private message Reply with quote
Nyrre



Joined: 26 Feb 2006
Posts: 13
Nyrre 02 Apr 2006, 14:14
But I've heard that if you program a kernel with c, you can't use stardard libraries (like stdio.h etc.). Is that true?
Post 02 Apr 2006, 14:14
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 05 Apr 2006, 18:44
Quite true, because the standard library is not magical..

printf for example, in Windows it calls different API calls. In Linux it calls Linux specific functions. That's why you can't use it. Unless you design one yourself for your OS, of course. Wink

Hey, I code some projects in C, but I don't use the standard library, because it bloats my programs and I don't have control over it Wink it's not that difficult without it
Post 05 Apr 2006, 18:44
View user's profile Send private message Reply with quote
Nyrre



Joined: 26 Feb 2006
Posts: 13
Nyrre 26 Apr 2006, 12:31
Oh, could you tell me how to write programs in C without using the standard libraries? I thought that it was impossible. Smile
Post 26 Apr 2006, 12:31
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey 26 Apr 2006, 19:01
Considering that you want to write your os in C and not assembly I think this forum may not be the best one for you. For questions on the C language you would be better served by comp.lang.c. For information on coding on OS you could (and should) try.

http://www.osdever.net/index.php
http://www.nondot.org/sabre/os/articles
alt.os.development

_________________
silkodyssey
Post 26 Apr 2006, 19:01
View user's profile Send private message MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 26 Apr 2006, 21:43
Nyrre wrote:
Oh, could you tell me how to write programs in C without using the standard libraries? I thought that it was impossible. Smile


Not exactly OS-related, but this is the only example that I can think of at the moment: Smile

Richard Heathfield wrote:
An MS-DOS implementation of John Conway's "Game of Life" using no headers, no libraries, no assembly language, no nothing - it's just raw C code. (see wbods50.c)
Post 26 Apr 2006, 21:43
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.