Please explain errors in kernel?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
St8ic

Please explain errors in kernel?

Post by St8ic »

I get these errors when compiling my kernel with TCC and I was just wondering if anyone could try and explain what they mean? Thanks.

Error kernel.c 1: Unable to open include file 'k_defines.h'
Error io.h 29: Declaration syntax error
Error io.h 30: Declaration syntax error
Error io.h 31: Declaration syntax error
Error kernel.c 27: Declaration syntax error
Error kernel.c 62: Expression syntax in function k_printf
Error kernel.c 104: Expression syntax in function panic

so what do these errors mean? What would you recomend doing to avoid these?
Schol-R-LEA

RE:Please explain errors in kernel?

Post by Schol-R-LEA »

There's no way to know, without seeing the source. On the first error, the best bet is that the compiler can't open the file 'k_defines.h', either because it can't be opened, or because isn't in the include path for whatever reason. The following errors are probably unrelated: the 'Declaration syntax error's are badly formed declarations of some kind, while the 'Expression syntax in function xxx' are dues to poorly written function calls - again, without seeing the code, there's no way to say what's wrong with them.

If you could show the relevant lines of the code (each error has the line number where the error occurred, following the file name), we might be able to help.
St8ic

RE:Please explain errors in kernel?

Post by St8ic »

I solved one of them by taking out the underscore in k_defines.c.
I solved three of them by taking out in-line comments
These are the ones that are left.

+----------+------+---------------------------
| File     | Line | Offending code
+----------+------+------------------------------------------------------------
| io.h     | 29   |inline void outportb(unsigned int port, unsigned char value);
| io.h     | 30   |inline void outportw(unsigned int port, unsigned int value);
| io.h     | 31   |inline unsigned char inportb(unsigned short port);
+----------+------+------------------------------------------------------------

Thanks alot again!
carbonBased

RE:Please explain errors in kernel?

Post by carbonBased »

There's nothing wrong with these prototypes.  You might want to remove "inline" simply because it's not part of the ANSI C language.

Anyone'll tell you, however, that line numbers from C errors aren't necessarily accurate.  A problem above the "offending code" could, in fact, be the culprit.

However, with all due respect, if you had to post here to realize that you were including a file that didn't even exist, you might want to take on a project that's _slightly less huge_!

Cheers,
Jeff
St8ic

RE:Please explain errors in kernel?

Post by St8ic »

Thanks so much!

I removed the "inline"'s and it worked perfectly! Thanks again!

(P.S. It's not that I was trying to include a file that didn't exist, it was just that the file name of it was nine characters. Still a very ignorant mistake, but at least I wasn't trying to include a file that wasn't there.)
carbonBased

RE:Please explain errors in kernel?

Post by carbonBased »

Ahh, okay... fair enough.

Are you running in a full DOS environment, btw?  Because if you're running a windows command prompt, there are compilers out there that will support long file names, and might make your job a bit easier :)

Cheers,
Jeff
St8ic

Errors, errors everywhere...

Post by St8ic »

After getting my kernel compiling I had troubles with these other files...
I scanned them for what made the other ones error, but it looks good.
---------------------------------------------------------------------------
io.c:
This file has one error in line 42. It says "Expression syntax in function inportb". The Offending area is:

asm volatile("inb %w1,%b0"
: "=a"(ret_val)    <- This line
: "d"(port));
return ret_val;
----------------------------------------------------------------------------
paging.c:
This file has six errors. Offending lines go like this:

line 42: volatile unsigned long address=0; "Expression syntax in function int_paging"

line 43: unsigned int i; "Expression syntax in function int_paging"

line 44: for(i=0; i<1023; i++) "Undefined symbol 'i' in function int_paging"

line 46: page_table[i] = address | 3; "Undefined symbol 'address' in function int_paging"

line 50: page_directory[0] = page_table; "Non-portable pointer assignment in function int_paging"

line 58: write_cr3(page_directory); "Type mis-match in parameter 1 in call to 'write_cr3' in function int_paging"
------------------------------------------------------------------------------
idt.c:
A whopping 25 errors.

can you just tell me what it means when it says:

Size of structure or array not known in function AddInt
Undefined symbol 'intgate' in function AddInt
Undefined structure 'i386_descriptor' in function AddInt

for like every single line!?

Thanks for any help you can supply,
St8ic
Schol-R-LEA

RE:Errors, errors everywhere...

Post by Schol-R-LEA »

The first four errors in int_paging() (lines 42, 43, 44, and 46) appear to be cascade problems of some kind, though I can't say for certain. Check to make sure that there isn't a mistake in any of the lines above them (a missing brace, for example). I can tell you that once the two declarations are fixed, the other two should be as well.

Can you show us the declarations of write_cr3(), page_directory and page_table? My first thought about both line 50 was that you needed type cast, but without seeing what the types of the two variables are, I couldn't be sure what was getting cast to what, assuming that the assignment is valid to begin with. Similarly, I'd need to know what argument(s) write_cr3() expects to see why it wasn't working with page_directory .

Could you post the whole int_paging() function, please, and perhaps the ones before and after it in the source file as well? It would put a lot of this in context.
St8ic

init_paging

Post by St8ic »

Here is the init_paging function:

void init_paging()
{
     page_table = page_directory + 0x1000;
    
     volatile unsigned long address=0;
     unsigned int i;
    
     for(i=0; i<1023; i++)
     {
          page_table[i] = address | 3;  
          address+= 4096;
     }

     page_directory[0] = page_table;    
     page_directory[0] = page_directory[0] | 3;

     for(i=1; i<1023; i++)
     {
          page_directory[i] = 0 | 2;
     }

     write_cr3(page_directory);
     enable_paging();
    
}

Anything else you need to see? Thanks alot.
carbonBased

RE:init_paging

Post by carbonBased »

Uhm... that still doesn't show the definitions of page_table and page_directory, as was asked.

They are defined somewhere, right?

This line:
page_table = page_directory + 0x1000;

Doesn't seem like it could possibly be valid, unless each were ints, 'cept later on you use page_directory as an array.  That line, no doubt, needs some form of type cast...

Cheers,
Jeff
St8ic

RE:init_paging

Post by St8ic »

Ya, page_table and page_directory are defined right above init_paging like this:

unsigned long *page_directory = (unsigned long *)0xFFF00000;
unsigned long *page_table;

What would you suggest doing to remedy this situation?
Schol-R-LEA

RE:init_paging

Post by Schol-R-LEA »

Remember, page table entries are not just pointers to pages; they have additional fields as well. The assignment

     page_directory[0] = page_table;

is incorrect; you need to create a complete page table entry for page_table, and put it in page_directory[0]. Even if you assume that page_table is correctly aligned on a page boundary, you'd still need to cast the pointer; it would be wiser, however, to mask the lower 12 bits as well:

     page_directory[0] = ((unsigned long) page_table) & 0xFFFF000;

and then set the page control fields (p, r/w, u/s, acc, d, avail) as needed.

I would recommend creating two type definitions, ptable and ptable_entry (or whatever name you'd prefer to use), and change the declarations like so:

typedef unsigned long ptable_entry;
typedef ptable_entry *ptable;

ptable page_table, page_directory;
// ...
ptable_entry address;

This should help make the code clearer later.

(Actually, I'd define ptable_entry as a bitfield struct,

typedef struct PTE {
       unsigned long present:1;
       unsigned long read_write:1;
       unsigned long user_accessible:1;
       unsigned long reserved1:2;
       unsigned long accessed:1;
       unsigned long dirty:1;
       unsigned long reserved2:2;
       unsigned long available:4;
       unsigned long frame_address:20;
} ptable_entry;

but that's a design preference which is not very relevant).
Schol-R-LEA

Oh, you *did* set those bits. My mistake.

Post by Schol-R-LEA »

I'd have used

page_directory[0] |= 3;

but that's just an aesthetic preference.
Post Reply