OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 12:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: printf, etc()
PostPosted: Sun Mar 03, 2002 4:49 am 
I need basic functions like printf(), etc.
Where can I get public (GNU?) printf-functions. Be aware of that I would pe pleased to have printf()-functions that I can easily implement in my kernel. I had several printf()-functions which had problems with some headers, etc.

regards!


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Sun Mar 03, 2002 5:44 am 
Goto:
http://www.execpc.com/~geezer/osd/libc/index.htm

and scroll down to Problematic functions in the C library. There are three files there. Get them all and you have a printf function.

K.J.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Sun Mar 03, 2002 8:39 pm 
There's a problem. stdarg.h includes the header file _va_list.h which I do not have.
And this is not a printf() function but a do_printf (different syntax)


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Mon Mar 04, 2002 1:26 am 
Quote:
There's a problem. stdarg.h includes the header file _va_list.h which I do not have.


Your compiler should provide the <stdarg.h> header file somewhere which provides definitions of va_list, va_begin, va_arg and va_end. Copy that file into the directory where you keep your own library header files.

Quote:
And this is not a printf() function but a do_printf (different syntax)


It shouldn't be too hard to work out how to make a printf() function which wraps do_printf(). (Hint: write vprintf() first, then write printf() in terms of vprintf().)


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Mon Mar 04, 2002 2:30 am 
Allright, I used the libc stdarg.h and now the do_printf() function seems to work... .
I now will have to get the printf() function working... .


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Mon Mar 04, 2002 3:23 am 
Jippie, I nearly have my printf() function... .
I'll just have to do some tricky stuff, that's all... .
I took the screen.c by df, thanks to him!


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Thu Mar 14, 2002 3:47 am 
I'm new to OSDEV and C but im picking it up as I go along, I'm using John Fine's Bootloader and as a kernel im using the one the guy wrote in this topic > http://www.mega-tokyo.com/cgi-bin/yabb/YaBB.pl?board=OS_FAQ;action=display;num=1012029411 <

it works ok, then I put the do_prinf files in with it, at first it complained about there being files missing, since i dunno how to specify my own include directory I changed all the #include <~~~> to #include "~~~" and have the files it needs in the same directory as the kernel source.
 whenever I use the function do_printf with do_printf("This is a test"); it tells me i dont have enougth arguments and refuses to compile, when I call the function printf with the same arguments the linker bombs out with this:
[glow=red,2,300]test.o(.text+0x14a):test.c: undefined reference to `_printf'[/glow]

heres my compiling procedure:
[glow=red,2,300]gcc -c test.c -o test.o
nasm -f coff test.asm -o test1.o
ld --oformat binary -e 0xFF800000 test1.o test.o
[/glow]

note: my kernel is called test.c at the moment and the test.asm  just seems to call the main routine in the C file.

I'm using: Nasm, DJGPP on a AMD-486-133 running Win98


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Thu Mar 14, 2002 5:07 am 
This linker message implies that you haven't got a printf function. do_printf is the core of printf, vprintf, sprintf, vsprintf, fprintf and vfprintf; each of the printf's are just wrappers around it. You have to write each of these yourself (starting with printf).


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Thu Mar 14, 2002 6:05 am 
Here's my printf function(you have to supply what line # to start displaying the text on):

unsigned int k_printf(char *message, unsigned int line)
{
     char *vidmem = (char *) 0xb8000;
     unsigned int i=0;

     i=(line*80*2);

     while(*message!=0) // 24h
     {
           if(*message==0x2F)
           {
                 *message++;
                 if(*message==0x6e)
                 {
                       line++;
                       i=(line*80*2);
                       *message++;
                       if(*message==0)
                       {
                             return(1);
                       };
                 };
           };
           vidmem[i]=*message;
           *message++;
           i++;
           vidmem[i]=0x7;
           i++;
     };

     return(1);
};


Then call it like this:
k_printf("Hello World!", 0); // first line

It can handle the "/n" for a newline but can't print out a variable like a real printf function.

Whatever5k: if you have complete a printf function, could please email it to me([email protected])?

K.J.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Thu Mar 14, 2002 7:56 am 
Well, i looked in the doprintf.c and found this procedure/function:
[glow=red,2,300]int printf(const char *fmt, ...)
{
     va_list args;
     int ret_val;

     va_start(args, fmt);
     ret_val = vprintf(fmt, args);
     va_end(args);
     return ret_val;
}[/glow]
thats what i was trying to call.
eitherway k_printf didnt seem to work for me, i used it within the main C file and as an external included file.
I can write to the screen though using:
[glow=red,2,300]  char *vidmem = (char *) 0xb8000;
 vidmem[0]='T';
[/glow]

Like I said before, I'm only learning so any help would be apreciated.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Fri Mar 15, 2002 1:33 am 
So what's the problem then? You've got do_printf and printf... Are you aware that you need to put doprintf.o on the linker command line (which means compiling doprintf.c)?

IIRC Chris Giese's do_printf function requires another function (which you write) to actually put the text on the screen. That function is one of the parameters to do_printf. It should be obvious from looking at the do_printf source.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Sun Mar 17, 2002 6:12 pm 
firstly the k_printf function works now, I used a linker script and now it works.
secondly, I compiled doprintf.c and got a warning about memcpy confliction, but i got the doprintf.o from it anyway :)
I now try and link it with my programs using the following line:
[glow=red,2,300]ld -T kernel.lk --oformat binary -e 0xFF800000 kernel1.o kernel.o inc\doprintf.o[/glow]
and i get this as a reply:
[glow=green,2,300]kernel.o(.text+0x1c8):kernel.c: undefined reference to `_printf'
inc\doprintf.o(.text+0x3ee):doprintf.c: undefined reference to `_strlen'
[/glow]

note: doprintf.o and all source and headers for it are in the inc directory of my kernels directory. and im using [glow=red,2,300]#include "inc\_printf.h"[/glow] to call it.

Also, I would apreciate it if someone could tell me how to specify an include directory so i didnt have to change #include <~~~> to #include "~~~" all the time.

Thanks in advance.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Sun Mar 17, 2002 11:32 pm 
Quote:
I now try and link it with my programs using the following line:
[glow=red,2,300]ld -T kernel.lk --oformat binary -e 0xFF800000 kernel1.o kernel.o inc\doprintf.o[/glow]
and i get this as a reply:
[glow=green,2,300]kernel.o(.text+0x1c8):kernel.c: undefined reference to `_printf'
inc\doprintf.o(.text+0x3ee):doprintf.c: undefined reference to `_strlen'
[/glow]

Do you actually have a printf function in any of your source files? doprintf.c doesn't include it; you have to write your own. You'll also need to write the strlen function.

To specify an include directory with gcc, use the -I<dir> option.


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Tue Mar 19, 2002 1:36 pm 
I got my doprintf from here
http://www.execpc.com/~geezer/osd/code/lib/stdio/doprintf.c which is on this page : http://www.execpc.com/~geezer/osd/snippets.htm
within doprintf.c there seems to be a function:
[glow=red,2,300]int printf(const char *fmt, ...)[/glow]
which is near the bottom on the file.

Any ideas?


Top
  
 
 Post subject: Re: printf, etc()
PostPosted: Wed Mar 20, 2002 12:10 am 
Read the source code. The bottom 7 functions are enclosed within a #if 0/#endif block, so they will be ignored by the compiler. Remove the #if 0/#endif (and the main() function) and all will be well.

Note the comment above vprintf_help:
Code:
/*****************************************************************************
PRINTF
You must write your own putchar()
*****************************************************************************/
int vprintf_help(unsigned c, void **ptr)
{
     putchar(c);
     return 0 ;
}


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 66 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