Making a small/simple OS in C - some errors

There are many different operating systems; which one will you choose?

Making a small/simple OS in C - some errors

Post by Arightwizard on Sat May 28, 2011 8:05 pm
([msg=57825]see Making a small/simple OS in C - some errors[/msg])

Sup. I've been working on an OS in C, (and still the mission idea (sorry, goatboy, btw, didnt notice you said to email it and yet i pm'ed.)) as a part time/side thing. Of course I can't just start from complete scratch, because of my inexperience in C, so I use snippets of other people's kernel code mixed with my own (I don't intend to sell it, just for my personal use, so I guess I can do that).

The process (in Ubuntu) I go through is as follows:

1. Write kernel.c, loader.s
2. Generate a pad file
3. Download other people's "stage1", "stage2", and "linker.ld" files (linker.ld to link everything)
4. Compile [gcc]
5. Link [ld]
6. Test.

However, on the linking process I get the following errors regarding kernel.o [compiled kernel.c]
Command:
Code: Select all
ld -T linker.ld -o kernel.bin loader.o kernel.o



Error:
Code: Select all
kernel.o: In function `kmain':
kernel.c:(.text+0x47): undefined reference to `gets'


My code for kernel.c (Compiled into kernel.o):

Code: Select all
#define WHITE_TXT 0x07 // white on black text
#include <stdio.h>
unsigned int k_printf(char *message, unsigned int line);
void k_clear_screen();
void update_cursor(int row, int col);
void kmain( void* mbd, unsigned int magic )
{
   if ( magic != 0x2BADB002 )
   {

   }

   char * boot_loader_name =(char*) ((long*)mbd)[16];

   /* Print a letter to screen to see everything is working: */
   unsigned char *videoram = (unsigned char *) 0xb8000;
   videoram[1] = 0x07; /* forground, background color. */

// TERMINAL TIMMMEEEEE!!!!!
char input[150];
k_clear_screen();
k_printf("Welcome to my simple OS! \nType some text and I'll echo it back for you: ", 4);
gets(input);
k_printf("You typed: %s", 6);

}

void k_clear_screen() // clear the entire text screen

{

   char *vidmem = (char *) 0xb8000;

   unsigned int i=0;

   while(i < (80*25*2))

   {

      vidmem[i]=' ';

      i++;

      vidmem[i]=WHITE_TXT;

      i++;

   };

};

unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
*message++;
} else {
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
return(1);
};


Code part with gets():
Code: Select all
// TERMINAL TIMMMEEEEE!!!!!
char input[150];
k_clear_screen();
k_printf("Welcome to my simple OS! \nType some text and I'll echo it back for you: ", 4);
gets(input);
k_printf("You typed: %s", 6);


PS: Yes, I know it's unsafe to use gets() instead of fgets(), but I haven't gotten far enough into development where it matters yet.

Anyone know how to fix this/what the problem even is? thanks!
The universe is mind over matter, meaning that consciousness precedes existence in general.
This means that if enough people start thinking that the world will end...it will.
Cool.
***IRRELEVANT SCIENCE FTW!!!***
Arightwizard
New User
New User
 
Posts: 14
Joined: Thu Jun 25, 2009 12:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by fashizzlepop on Sat May 28, 2011 9:43 pm
([msg=57828]see Re: Making a small/simple OS in C - some errors[/msg])

Is that even legal in this simple of an OS? I would try another function instead. Or just delete that piece and see if it will compile and print out that other stuff first.

OS developing is incredibly intense. If you say you are inexperienced in C, learn C first extremely well. You will FAIL miserably if you can't even use pointers and other techniques popular in C.

So, go learn C.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by Arightwizard on Sat May 28, 2011 10:07 pm
([msg=57835]see Re: Making a small/simple OS in C - some errors[/msg])

fashizzlepop wrote:Is that even legal in this simple of an OS? I would try another function instead. Or just delete that piece and see if it will compile and print out that other stuff first.

OS developing is incredibly intense. If you say you are inexperienced in C, learn C first extremely well. You will FAIL miserably if you can't even use pointers and other techniques popular in C.

So, go learn C.


The other parts worked, I kinda did this step-by-step (Write a little, compile, test, repeat) to make sure I knew exactly where I was messing up if anything did mess up.

And I'm not really planning to succeed (even if I do, I DEFINITELY don't plan for a GUI to be involved... But, I think this would be a good learning experience for me, I've always learned in a way that, I have to completely drown myself in the language to understand. So an OS, with no outside support for functions, is a great way for me to learn some C.

I've tried other functions, too, like getchar, but those fail as well. I guess I'll try other functions like scanf or whatever else.
Thanks, if you didn't mention that it probably isn't possible in a simple environment, I probably wouldn't've thought about it, and kept trying to use gets().
The universe is mind over matter, meaning that consciousness precedes existence in general.
This means that if enough people start thinking that the world will end...it will.
Cool.
***IRRELEVANT SCIENCE FTW!!!***
Arightwizard
New User
New User
 
Posts: 14
Joined: Thu Jun 25, 2009 12:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by fashizzlepop on Sat May 28, 2011 10:14 pm
([msg=57836]see Re: Making a small/simple OS in C - some errors[/msg])

Having code that takes input from the keyboard means your kernel has to have keyboard support, which most likely it doesn't have.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by Arightwizard on Sat May 28, 2011 10:21 pm
([msg=57837]see Re: Making a small/simple OS in C - some errors[/msg])

fashizzlepop wrote:Having code that takes input from the keyboard means your kernel has to have keyboard support, which most likely it doesn't have.




....I'm completely....completely retarded. No lie.
I didn't think about it, but I guessed C code, when compiled, would implement required components (like keyboard support ones) for the functions used and included.

lol see? This is a good learning experience so far, for C and for OS designing that I can use for future reference if I ever become serious about it.
The universe is mind over matter, meaning that consciousness precedes existence in general.
This means that if enough people start thinking that the world will end...it will.
Cool.
***IRRELEVANT SCIENCE FTW!!!***
Arightwizard
New User
New User
 
Posts: 14
Joined: Thu Jun 25, 2009 12:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by fashizzlepop on Sat May 28, 2011 10:30 pm
([msg=57838]see Re: Making a small/simple OS in C - some errors[/msg])

I think it will end up slowing you down since you will be way lost on most of it. IMHO
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by Arightwizard on Sat May 28, 2011 10:39 pm
([msg=57839]see Re: Making a small/simple OS in C - some errors[/msg])

fashizzlepop wrote:I think it will end up slowing you down since you will be way lost on most of it. IMHO


actually i'm working on it right now, it seems simple - just need to handle the qwerty key mapping, stop any interrupts, and whatever else. Thanks again, though.

Once again though, I don't plan for this succeed past a certain point - I know I'ma fuck it up at one point, a 13 year old kid like me can't possibly code a full blown, functional OS. [Oh, yeah, btw, I'm a little kid. Probably not too shocking.] But, what's the point of not starting to try at a certain point? - I mean, in case I plan to design a serious one later, I may as well start now just in case.
The universe is mind over matter, meaning that consciousness precedes existence in general.
This means that if enough people start thinking that the world will end...it will.
Cool.
***IRRELEVANT SCIENCE FTW!!!***
Arightwizard
New User
New User
 
Posts: 14
Joined: Thu Jun 25, 2009 12:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by neuromanta on Sat May 28, 2011 11:10 pm
([msg=57840]see Re: Making a small/simple OS in C - some errors[/msg])

I think you have massive misconceptions about the definition of an OS as well. The OS kernel implements the low level hardware handling (luckily it can rely on the services of the BIOS), and the higher layers of the OS gives some basic applications with which the user can work. For example in the case of GNU/Linux, the Linux is the kernel and the basic applications (like cat, echo, ls, etc.) comes from the GNU system. I don't want to pour cold water on you (cuz I like your enthusiasm), but what you did is not even close to being an OS.
User avatar
neuromanta
Poster
Poster
 
Posts: 302
Joined: Mon Nov 30, 2009 9:29 am
Location: Hungary
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by Arightwizard on Sat May 28, 2011 11:19 pm
([msg=57841]see Re: Making a small/simple OS in C - some errors[/msg])

neuromanta wrote:I think you have massive misconceptions about the definition of an OS as well. The OS kernel implements the low level hardware handling (luckily it can rely on the services of the BIOS), and the higher layers of the OS gives some basic applications with which the user can work. For example in the case of GNU/Linux, the Linux is the kernel and the basic applications (like cat, echo, ls, etc.) comes from the GNU system. I don't want to pour cold water on you (cuz I like your enthusiasm), but what you did is not even close to being an OS.


I just figured (for now) I'd save time by trying to mix the two. I'd still consider it an OS, though, because an OS is just "operating system" - so, software the computer with which the computer uses to perform, just, whatever. So even if I mix the kernel with the terminal (if I can call it that at this stage lol), it'd still be, by my definition, an OS.

But, I said "(for now)" in this post, meaning that later on, I'll try to separate them so it actually functions like a regular OS...IF I make it that far.
The universe is mind over matter, meaning that consciousness precedes existence in general.
This means that if enough people start thinking that the world will end...it will.
Cool.
***IRRELEVANT SCIENCE FTW!!!***
Arightwizard
New User
New User
 
Posts: 14
Joined: Thu Jun 25, 2009 12:20 pm
Blog: View Blog (0)


Re: Making a small/simple OS in C - some errors

Post by fashizzlepop on Sun May 29, 2011 12:01 am
([msg=57843]see Re: Making a small/simple OS in C - some errors[/msg])

I like the enthusiasm as well. You also seem pretty knowledgeable for a beginner.

I think it's appropriate to call it an OS.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Next

Return to Operating Systems

Who is online

Users browsing this forum: No registered users and 0 guests

cron