What's wrong with my kernel or other other files or how I'm ru

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

53 Replies - 1624 Views - Last Post: 06 February 2018 - 12:34 PM Rate Topic: -----

#31 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 03 February 2018 - 09:32 PM

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Why do you think removing all a parameters and not having any would be good solution to all things?

Again.. stop.. STOP.. Go pick up a book on c/c++ and work through enough to get the concepts of functions, parameters, variable declaration, data types, etc down.


Quote

parameter names (without types) in function declaration
03
void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), i

The compiler needs parameters need datatypes else it could be anything. What in there doesn't have a type? "KEYBOARD_DATA_PORT". More importantly KEYBOARD_DATA_PORT is never ever EVER declared.

Quote

error: ‘keycode’ undeclared here (not in a function)
06
int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]);

Same thing here. What is 'keycode'? The compiler doesn't know.. it was NEVER DECLARED.

keycode is declared here as far as I know:

keycode = read_port(KEYBOARD_DATA_PORT);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

error: ‘current_loc’ undeclared here (not in a function)
09
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Guess what this means? Hint - the variable was never declared. The compiler doesn't know squat about it.

Not sure how to declare it in order to fix it.

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

11
/home/username/Documents/My first sample kernel/kernel2.c:20:30: error: ‘keyboard_map’ undeclared here (not in a function)
12
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Same thing as above.

I agree with you here, but how should it be declared and here is the only thing close:

int keyboard_handler_main(write_port, read_port, keyboard_map);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

14
/home/username/Documents/My first sample kernel/kernel2.c:20:43: error: ‘keycode’ undeclared here (not in a function)
15
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Same thing as above.

Yea I know and it's a pointer, but how do I fix this?

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

18
/home/username/Documents/My first sample kernel/kernel2.c:28:2: error: unknown type name ‘IDT_entry’
19
IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
20
^

Addressed above about how compilers need data types.

yes I know IDT_entry is a structure though, but how do I fix the rest of this because I can't find a good answer.

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

21
/home/username/Documents/My first sample kernel/kernel2.c:28:16: error: ‘IDT_SIZE’ undeclared (first use in this function)
22
IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.

Take a guess.

I'm not sure what I was trying to do here because I didn't explain it very well in the comment, but how do fix it.

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

5

/home/username/Documents/My first sample kernel/kernel2.c:32:30: error: ‘load_idt’ undeclared (first use in this function)
26
idt_init(write_port, load_idt, IDT);

Take a guess as above.



Again I'm not sure what I was trying to do here because I didn't leave a comment in the code, but how I fix it.

This post has been edited by Skydiver: 04 February 2018 - 07:29 PM
Reason for edit:: Broke up huge quote with inline answers to make inline answers stand out.

Was This Post Helpful? 0
  • +
  • -

#32 jimblumberg   User is online

  • member icon

Reputation: 5615
  • View blog
  • Posts: 17,312
  • Joined: 25-December 09

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 04:22 AM

Quote

Uh I don't know about that, but I do have the Kernighan and Ritchie C Book that I never completed reading as well a C programming by Herbert Schilt I think that I also never completed because I never found time too complete either one of their books, but because I kinda had to complete Tony Gaddis for the C++ class I took in Fall 2014

I myself only consider K&R a reference, not a book to actually learn to program modern C.

Any C book by Herbert Schilt is not worth the paper it was written on and these horrible books should not ever be used to try to learn the C or C++ languages.

Jim
Was This Post Helpful? 1
  • +
  • -

#33 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,528
  • Joined: 05-May 12

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 05:35 AM

In my opinion, K&R was written for people who already know how to program, but wanted to learn how to write code in C. It was not meant to teach how to think like a programmer. It is guided tour of what can be found in the language.
Was This Post Helpful? 1
  • +
  • -

#34 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 08:05 AM

Also I would add,

that in my opinion nothing will teach you to think like a programmer,

some people are just not meant to program you are either good at solving logic problems or you are not.

Things that can help, learning algebra and basic geometry is a great place to start.

I started programming at around the age of ten same time I was exposed to algebra for the first time at school.

I immediately saw the connection, I got it, and started to write programs with clear goals in mind, this was all done in BASIC, I then learned to manipulate memory to create my own sprites using binary to decimal conversion, this was done on graph paper I then moved onto assembler as I found out it could draw graphics faster to the video memory than BASIC could.

Languages are just syntax, and while syntax in your chosen language is important and learning syntax will give you a feel for the language and therefore how to start your program, it will not help you solve logic problems.

I think this particular OP is stuck at the copy/paste programmer level, which is a real shame as this is a particularly bad habit to acquire and a tough one to break once you have started.

Being a copy/paste programmer confines you to the realm of never being able to write unique software that solves a particular problem, you end up being only able to write software that has already been written.
Was This Post Helpful? 3
  • +
  • -

#35 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 02:28 PM

I didn't copy and paste this code I actually typed in each line of code following these guides, made flow charts, debugged them following similar stack exchange issues, and figured out how to run the code following the guide as well as troubleshooting by reading man pages. I did all this if not more and I can't figure out the solution to these errors yet and I was hoping to be pointed in the right direction, which I kind of have and just need to work out the rest for myself I guess.

This post has been edited by Skydiver: 04 February 2018 - 02:28 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#36 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,528
  • Joined: 05-May 12

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 02:34 PM

It looks like your are willing to put in the hardwork to learn, and that you are motivated to do so. I suggest going back a few steps and refreshing your C and C++ knowledge. The issues that you were running into were basic C/C++ programming problems that anybody learning the language encounters. The problem is that you are encountering these issues while you are trying to work on a complex project like a kernel, when you should learned about them while trying to build a simple "guess-the-number-I-thinking" program.
Was This Post Helpful? 1
  • +
  • -

#37 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 03:07 PM

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

error: ‘current_loc’ undeclared here (not in a function)
09
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Guess what this means? Hint - the variable was never declared. The compiler doesn't know squat about it.

Not sure how to declare it in order to fix it.

Actually it was declared here:

vidptr[current_loc++] = 0x07;

and keyboard_map[keycode] here:

char vidptr[current_loc++] = keyboard_map[keycode];

or here as a value of the vidptr[current_loc++] pointer

vidptr[current_loc++] = keyboard_map[keycode];

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

11
/home/username/Documents/My first sample kernel/kernel2.c:20:30: error: ‘keyboard_map’ undeclared here (not in a function)
12
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Same thing as above.

keyboard_map[keycode] is declared as a value of the vidptr[current_loc++] pointer here:

char vidptr[current_loc++] = keyboard_map[keycode];

or here as a value of the vidptr[current_loc++] pointer

vidptr[current_loc++] = keyboard_map[keycode];

int keyboard_handler_main(write_port, read_port, keyboard_map);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

14
/home/username/Documents/My first sample kernel/kernel2.c:20:43: error: ‘keycode’ undeclared here (not in a function)
15
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

Same thing as above.

keycode is declared here as far as I know here:

keycode = read_port(KEYBOARD_DATA_PORT);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

18
/home/username/Documents/My first sample kernel/kernel2.c:28:2: error: unknown type name ‘IDT_entry’
19
IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
20
^

Addressed above about how compilers need data types.

yes I know IDT_entry is a structure though, but how do I fix the rest of this because I can't find a good answer.

It's either declared or mentioned here:

idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
((idt_address & 0xffff) << 16);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

21
/home/username/Documents/My first sample kernel/kernel2.c:28:16: error: ‘IDT_SIZE’ undeclared (first use in this function)
22
IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.

Take a guess.

I'm not sure what I was trying to do here because I didn't explain it very well in the comment, but how do fix it.

It's either declared or mentioned here:

idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
((idt_address & 0xffff) << 16);

View Postmodi123_1, on 26 January 2018 - 10:12 AM, said:

Quote

5

/home/username/Documents/My first sample kernel/kernel2.c:32:30: error: ‘load_idt’ undeclared (first use in this function)
26
idt_init(write_port, load_idt, IDT);

Take a guess as above.

load_idt is declared or mentioned as a variable with a parameter here:
load_idt(idt_ptr);


and

a function here in the kernel2.asm code here:
load_idt:
        call idt_init
        mov edx, [esp + 4]
        lidt [edx]
        sti
        ret


This post has been edited by Skydiver: 04 February 2018 - 07:46 PM
Reason for edit:: Broke up huge quote to make inline responses stand out.

Was This Post Helpful? 0
  • +
  • -

#38 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 03:43 PM

View PostProgrammingisnotmything, on 04 February 2018 - 09:28 PM, said:

I didn't copy and paste this code I actually typed in each line of code following these guides, made flow charts, debugged them following similar stack exchange issues, and figured out how to run the code following the guide as well as troubleshooting by reading man pages.



Well ok... so I'm a little confused to how you don't seem to understand any of what you have written or how it works...

But at least you are reading the docs... good start... you need to review what a function is and how to declare one properly...
Was This Post Helpful? 0
  • +
  • -

#39 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 04:06 PM

Look at this for example..

void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); // function prototype


the above is the your function prototype... and yet your implementation looks like

void keyboard_handler_main(void) {



How is the compiler meant to know what you mean... heck Im struggling to know what you mean..

If I have a function declared as

int myfunc(int information);


I expect it's implementation to be something like this

int myfunc(int information)
{


   information = 9;

   return information;

}


Now to determine what should go in a function header you need to figure out if returns anything and if inside the function if it requires any 'information' to be passed in.

consider this function

void PRINT(void)
{


    printf("%s", "Hello");

}



the function doesnt return anything so it can be declared void, it doesnt require any 'information' to be passed in as all it does is print Hello..

but this function is slightly different

void PRINT(char* information)
{
   
    printf("%s", information);

}


It still doesn't return anything but this time it requires 'information' to be passed in to print out anything at all...

Now you're job is to figure out if any of the functions you create need to return anything and if the functions require any 'information' to be passed into them.
Was This Post Helpful? 0
  • +
  • -

#40 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 05:48 PM

After changing that function prototype back to what I originally had and you suggested I change it back too this is my kernels code now:

/*
* kernel.c
*/

#include <stdio.h>
#include <math.h>
#include "keyboard_map.h"

/* there are 25 lines each of 80 colums: each element takes 2 bytes */

#define LINES 25
#define COLUMNS_IN_LINE 80
#define BYTES_FOR_EACH_ELEMENT 2
#define SCREESIZE BYTES_FOR_EACH_ELEMENT * COLUMNS_IN_LINE * LINES

#define KEYBOARD_DATA_PORT 0x60
#define KEYBOARD_STATUS_PORT 0x64
#define IDT_SIZE 256
#define INTERRUPT_GATE 0x86
#define KERNEL_CODE_SEGMENT_OFFSET 0x08

#define ENTER_KEY_CODE 0x1C


 void idt_init(int write_port, int load_idt(idt_ptr[]), int IDT[]); // function prototype
 void kb_init(int write_port); // function prototype with variable using parameter
 void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); // function prototype
 char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
 unsigned long idt_ptr[2]; // Pointer to a unsigned long

extern unsigned char keyboard_map[128];
extern void keyboard_handler(void);
extern void read_port(unsigned short port); 
extern void write_port(unsigned short port, unsigned char data);
extern void load_idt(unsigned long *idt_ptr);

/* current cursor location */
unsigned int current_loc = 0;
/* video memory begins at address 0xb8000 */
char *vidptr = (char*)0xb8000;


struct IDT_entry
{
        unsigned short int offset_lowerbits;
        unsigned short int selector;
        unsigned char zero;
        unsigned char type_attr;
        unsigned short int offset_higherbits;
};

void kmain(void)
{
	IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.

	const char *str = "my first kernel with keyboard support";
	clear_screen();
	kprint(str);
	kprint_newline();
	kprint_newline();

	char *vidptr =(char*)0xb8000; //video mem begins here.
        idt_init(write_port, load_idt, IDT); // might need to be idt_init();
        kb_init(write_port); // might need to be kb_init();

        int keyboard_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, data), keyboard_map[keycode]);
	unsigned int i = 0;
	unsigned int j = 0;

	/* this loop clears the screen
	* there are 25 lines each of 80 columns; each element takes 2 bytes */
	while(j < 80 * 25 * 2) {
	     /* blank character */
             vidptr[j] = ' ';
	     /* attribute-byte - light grey on black screen */
	     vidptr[j+1] = 0x07;
             j = j + 2;
        }

        j = 0;

        /* this loop writes the string to video memory */
        while(str[j] != '\0') {
             /* the character's ascii */
             vidptr[i] = str[j];
             /* attribute-byte: give character black bg light grey fg */
	     vidptr[i+1] = 0x07;
	     ++j;
	     i = i + 2;
       }
       return;
} 

void idt_init(void)
{
	unsigned long keyboard_address;
	unsigned long idt_address;
	unsigned long idt_ptr[2];
	
	/* populate IDT entry of keyboard's interrupt */
	keyboard_address = (unsigned long)keyboard_handler;
	IDT[0x21].offset_lowerbits = keyboard_address & 0xffff;
	IDT[0x21].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET
*/
	IDT[0x21].zero = 0;
	IDT[0x21].type_attr = 0x8e; /* INTERRUPT_GATE */
	IDT[0x21].offset_higherbits = (keyboard_address &
	0xffff0000) >> 16;
	/* 	Ports
	*	PIC1 PIC2
	*Command 0x20 0xA0
	*Data 0x21 0xA1
*/

	/* ICW1 - begin initialization */
	write_port(0x20 , 0x11);
	write_port(0xA0 , 0x11);

	/* ICW2 - remap offset address of IDT */
	/*
	* In x86 protected mode, we have to remap the PICs beyond
0x20 because
	* Intel have designated the first 32 interrupts as
"reserved" for cpu exceptions
*/
	write_port(0x21 , 0x20);
	write_port(0xA1 , 0x28);

	/* ICW3 - setup cascading */
	write_port(0x21 , 0x00);
	write_port(0xA1 , 0x00);

	/* ICW4 - environment info */
	write_port(0x21 , 0x01);
	write_port(0xA1 , 0x01);
	/* Initialization finished */

	/* mask interrupts */
	write_port(0x21 , 0xff);
	write_port(0xA1 , 0xff);

	/* fill the IDT descriptor */
	idt_address = (unsigned long)IDT ;
	idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
((idt_address & 0xffff) << 16);

	idt_ptr[1] = idt_address >> 16 ;
	load_idt(idt_ptr);
}

void kb_init(void) 
{
	/* 0xFD is 11111101 - enables only IRQ1 (keyboard)*/
	write_port(0x21 , 0xFD);
}

void kprint(const char *str)
{
	unsigned int i=0);
	while (str[i] != '\0') {
		vidptr[current_loc++] = str[i++];
		vidptr[current_loc++] = 0x07;
	}
}

void kprint_newline(void)
{
	unsigned int line_size = BYTES_FOR_ELEMENT * COLUMNS_IN_LINE;
	current_loc = current_loc + (line_size - current_loc % (line_SIZE));
}

void clear_screen(void)
{
	unsigned int i = 0;
	while (i < SCREENSIZE) {
		vidptr[i++] = ' ';
		vidptr[i++] = 0x07;
	}
}


void keyboard_handler_main(void) {
         unsigned char status;
         char keycode;
//         char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
 
         /* write EOI */
         write_port(0x20, 0x20);
 
 status = read_port(KEYBOARD_STATUS_PORT);
         /* Lowest bit of status will be set if buffer is not
 52 empty */
         if (status & 0x01) {
                 keycode = read_port(KEYBOARD_DATA_PORT);
                 if(keycode < 0) 
                         return;
                 vidptr[current_loc++] = keyboard_map[keycode];
                 vidptr[current_loc++] = 0x07;

       }
       return;
}


This post has been edited by Skydiver: 04 February 2018 - 07:13 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#41 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 05:54 PM

and here are my errors:

[email protected]:~$ gcc -m32 -lm -c /home/username/Documents/My\ first\ sample\ kernel/kernel2.c -o /home/username/Documents/My\ first\ sample\ kernel/kc2.o
/home/username/Documents/My first sample kernel/kernel2.c:25:45: error: unknown type name ‘idt_ptr’
  void idt_init(int write_port, int load_idt(idt_ptr[]), int IDT[]); // function pr
                                             ^
/home/username/Documents/My first sample kernel/kernel2.c:25:57: error: expected ‘;’, ‘,’ or ‘)’ before ‘int’
  void idt_init(int write_port, int load_idt(idt_ptr[]), int IDT[]); // function pr
                                                         ^
/home/username/Documents/My first sample kernel/kernel2.c:16:28: error: expected declaration specifiers or ‘...’ before numeric constant
 #define KEYBOARD_DATA_PORT 0x60
                            ^
/home/username/Documents/My first sample kernel/kernel2.c:27:59: note: in expansion of macro ‘KEYBOARD_DATA_PORT’
  void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int
                                                           ^
/home/username/Documents/My first sample kernel/kernel2.c:27:80: error: expected ‘;’, ‘,’ or ‘)’ before ‘int’
 yboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboar
                                                                        ^
/home/username/Documents/My first sample kernel/kernel2.c:28:14: error: ‘current_loc’ undeclared here (not in a function)
  char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
              ^
/home/username/Documents/My first sample kernel/kernel2.c:28:44: error: ‘keycode’ undeclared here (not in a function)
  char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
                                            ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kmain’:
/home/username/Documents/My first sample kernel/kernel2.c:54:2: error: unknown type name ‘IDT_entry’
  IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
  ^
/home/username/Documents/My first sample kernel/kernel2.c:57:2: warning: implicit declaration of function ‘clear_screen’ [-Wimplicit-function-declaration]
  clear_screen();
  ^
/home/username/Documents/My first sample kernel/kernel2.c:58:2: warning: implicit declaration of function ‘kprint’ [-Wimplicit-function-declaration]
  kprint(str);
  ^
/home/username/Documents/My first sample kernel/kernel2.c:59:2: warning: implicit declaration of function ‘kprint_newline’ [-Wimplicit-function-declaration]
  kprint_newline();
  ^
/home/username/Documents/My first sample kernel/kernel2.c:63:9: warning: implicit declaration of function ‘idt_init’ [-Wimplicit-function-declaration]
         idt_init(write_port, load_idt, IDT); // might need to be idt_init();
         ^
/home/username/Documents/My first sample kernel/kernel2.c:64:17: warning: passing argument 1 of ‘kb_init’ makes integer from pointer without a cast [-Wint-conversion]
         kb_init(write_port); // might need to be kb_init();
                 ^
/home/username/Documents/My first sample kernel/kernel2.c:26:7: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
  void kb_init(int write_port); // function prototype with variable using parameter
       ^
/home/username/Documents/My first sample kernel/kernel2.c:66:35: error: expected declaration specifiers or ‘...’ before ‘write_port’
         int keyboard_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, 
                                   ^
/home/username/Documents/My first sample kernel/kernel2.c:66:67: error: expected declaration specifiers or ‘...’ before ‘read_port’
         int keyboard_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, 
                                                                   ^
/home/username/Documents/My first sample kernel/kernel2.c:66:90: error: expected declaration specifiers or ‘...’ before ‘keyboard_map’
 rd_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, data), keyboard_ma
                                                                        ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:94:6: warning: conflicting types for ‘idt_init’
 void idt_init(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:63:9: note: previous implicit declaration of ‘idt_init’ was here
         idt_init(write_port, load_idt, IDT); // might need to be idt_init();
         ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘idt_init’:
/home/username/Documents/My first sample kernel/kernel2.c:102:2: error: ‘IDT’ undeclared (first use in this function)
  IDT[0x21].offset_lowerbits = keyboard_address & 0xffff;
  ^
/home/username/Documents/My first sample kernel/kernel2.c:102:2: note: each undeclared identifier is reported only once for each function it appears in
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:151:6: error: conflicting types for ‘kb_init’
 void kb_init(void) 
      ^
/home/username/Documents/My first sample kernel/kernel2.c:26:7: note: previous declaration of ‘kb_init’ was here
  void kb_init(int write_port); // function prototype with variable using parameter
       ^
/home/username/Documents/My first sample kernel/kernel2.c:157:6: warning: conflicting types for ‘kprint’
 void kprint(const char *str)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:58:2: note: previous implicit declaration of ‘kprint’ was here
  kprint(str);
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kprint’:
/home/username/Documents/My first sample kernel/kernel2.c:159:18: error: expected ‘,’ or ‘;’ before ‘)’ token
  unsigned int i=0);
                  ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:166:6: warning: conflicting types for ‘kprint_newline’
 void kprint_newline(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:59:2: note: previous implicit declaration of ‘kprint_newline’ was here
  kprint_newline();
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kprint_newline’:
/home/username/Documents/My first sample kernel/kernel2.c:168:27: error: ‘BYTES_FOR_ELEMENT’ undeclared (first use in this function)
  unsigned int line_size = BYTES_FOR_ELEMENT * COLUMNS_IN_LINE;
                           ^
/home/username/Documents/My first sample kernel/kernel2.c:169:58: error: ‘line_SIZE’ undeclared (first use in this function)
  current_loc = current_loc + (line_size - current_loc % (line_SIZE));
                                                          ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:172:6: warning: conflicting types for ‘clear_screen’
 void clear_screen(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:57:2: note: previous implicit declaration of ‘clear_screen’ was here
  clear_screen();
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘clear_screen’:
/home/username/Documents/My first sample kernel/kernel2.c:175:13: error: ‘SCREENSIZE’ undeclared (first use in this function)
  while (i < SCREENSIZE) {
             ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘keyboard_handler_main’:
/home/username/Documents/My first sample kernel/kernel2.c:190:9: error: void value not ignored as it ought to be
  status = read_port(KEYBOARD_STATUS_PORT);
         ^
/home/username/Documents/My first sample kernel/kernel2.c:194:26: error: void value not ignored as it ought to be
                  keycode = read_port(KEYBOARD_DATA_PORT);
                          ^
[email protected]:~$ 


This post has been edited by Skydiver: 04 February 2018 - 07:15 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#42 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 06:27 PM

and the errors I get with the new code:

[email protected]:~$ gcc -m32 -lm -c /home/username/Documents/My\ first\ sample\ kernel/kernel2.c -o /home/username/Documents/My\ first\ sample\ kernel/kc2.o
In file included from /home/username/Documents/My first sample kernel/idt.h:9:0,
                 from /home/username/Documents/My first sample kernel/kernel2.c:8:
/home/username/Documents/My first sample kernel/types.h:17:0: warning: "NULL" redefined
 #define NULL                    0L
 ^
In file included from /usr/include/_G_config.h:15:0,
                 from /usr/include/libio.h:31,
                 from /usr/include/stdio.h:74,
                 from /home/username/Documents/My first sample kernel/kernel2.c:5:
/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h:406:0: note: this is the location of the previous definition
 #define NULL ((void *)0)
 ^
/home/username/Documents/My first sample kernel/kernel2.c:27:45: error: unknown type name ‘idt_ptr’
  void idt_init(int write_port, int load_idt(idt_ptr[]), int IDT[]); // function pr
                                             ^
/home/username/Documents/My first sample kernel/kernel2.c:27:57: error: expected ‘;’, ‘,’ or ‘)’ before ‘int’
  void idt_init(int write_port, int load_idt(idt_ptr[]), int IDT[]); // function pr
                                                         ^
/home/username/Documents/My first sample kernel/kernel2.c:18:28: error: expected declaration specifiers or ‘...’ before numeric constant
 #define KEYBOARD_DATA_PORT 0x60
                            ^
/home/username/Documents/My first sample kernel/kernel2.c:29:59: note: in expansion of macro ‘KEYBOARD_DATA_PORT’
  void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int
                                                           ^
/home/username/Documents/My first sample kernel/kernel2.c:29:80: error: expected ‘;’, ‘,’ or ‘)’ before ‘int’
 yboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboar
                                                                        ^
/home/username/Documents/My first sample kernel/kernel2.c:30:14: error: ‘current_loc’ undeclared here (not in a function)
  char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
              ^
/home/username/Documents/My first sample kernel/kernel2.c:30:44: error: ‘keycode’ undeclared here (not in a function)
  char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
                                            ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kmain’:
/home/username/Documents/My first sample kernel/kernel2.c:56:2: error: unknown type name ‘IDT_entry’
  IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
  ^
/home/username/Documents/My first sample kernel/kernel2.c:59:2: warning: implicit declaration of function ‘clear_screen’ [-Wimplicit-function-declaration]
  clear_screen();
  ^
/home/username/Documents/My first sample kernel/kernel2.c:60:2: warning: implicit declaration of function ‘kprint’ [-Wimplicit-function-declaration]
  kprint(str);
  ^
/home/username/Documents/My first sample kernel/kernel2.c:61:2: warning: implicit declaration of function ‘kprint_newline’ [-Wimplicit-function-declaration]
  kprint_newline();
  ^
/home/username/Documents/My first sample kernel/kernel2.c:65:9: warning: implicit declaration of function ‘idt_init’ [-Wimplicit-function-declaration]
         idt_init(write_port, load_idt, IDT); // might need to be idt_init();
         ^
/home/username/Documents/My first sample kernel/kernel2.c:66:17: warning: passing argument 1 of ‘kb_init’ makes integer from pointer without a cast [-Wint-conversion]
         kb_init(write_port); // might need to be kb_init();
                 ^
/home/username/Documents/My first sample kernel/kernel2.c:28:7: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
  void kb_init(int write_port); // function prototype with variable using parameter
       ^
/home/username/Documents/My first sample kernel/kernel2.c:68:35: error: expected declaration specifiers or ‘...’ before ‘write_port’
         int keyboard_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, 
                                   ^
/home/username/Documents/My first sample kernel/kernel2.c:68:67: error: expected declaration specifiers or ‘...’ before ‘read_port’
         int keyboard_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, 
                                                                   ^
/home/username/Documents/My first sample kernel/kernel2.c:68:90: error: expected declaration specifiers or ‘...’ before ‘keyboard_map’
 rd_handler_main(write_port(KEYBOARD_DATA_PORT), read_port(port, data), keyboard_ma
                                                                        ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:96:6: warning: conflicting types for ‘idt_init’
 void idt_init(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:65:9: note: previous implicit declaration of ‘idt_init’ was here
         idt_init(write_port, load_idt, IDT); // might need to be idt_init();
         ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘idt_init’:
/home/username/Documents/My first sample kernel/kernel2.c:104:2: error: ‘IDT’ undeclared (first use in this function)
  IDT[0x21].offset_lowerbits = keyboard_address & 0xffff;
  ^
/home/username/Documents/My first sample kernel/kernel2.c:104:2: note: each undeclared identifier is reported only once for each function it appears in
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:153:6: error: conflicting types for ‘kb_init’
 void kb_init(void) 
      ^
/home/username/Documents/My first sample kernel/kernel2.c:28:7: note: previous declaration of ‘kb_init’ was here
  void kb_init(int write_port); // function prototype with variable using parameter
       ^
/home/username/Documents/My first sample kernel/kernel2.c:159:6: warning: conflicting types for ‘kprint’
 void kprint(const char *str)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:60:2: note: previous implicit declaration of ‘kprint’ was here
  kprint(str);
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kprint’:
/home/username/Documents/My first sample kernel/kernel2.c:161:18: error: expected ‘,’ or ‘;’ before ‘)’ token
  unsigned int i=0);
                  ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:168:6: warning: conflicting types for ‘kprint_newline’
 void kprint_newline(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:61:2: note: previous implicit declaration of ‘kprint_newline’ was here
  kprint_newline();
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘kprint_newline’:
/home/username/Documents/My first sample kernel/kernel2.c:170:27: error: ‘BYTES_FOR_ELEMENT’ undeclared (first use in this function)
  unsigned int line_size = BYTES_FOR_ELEMENT * COLUMNS_IN_LINE;
                           ^
/home/username/Documents/My first sample kernel/kernel2.c:171:58: error: ‘line_SIZE’ undeclared (first use in this function)
  current_loc = current_loc + (line_size - current_loc % (line_SIZE));
                                                          ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:174:6: warning: conflicting types for ‘clear_screen’
 void clear_screen(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:59:2: note: previous implicit declaration of ‘clear_screen’ was here
  clear_screen();
  ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘keyboard_handler_main’:
/home/username/Documents/My first sample kernel/kernel2.c:192:9: error: void value not ignored as it ought to be
  status = read_port(KEYBOARD_STATUS_PORT);
         ^
/home/username/Documents/My first sample kernel/kernel2.c:196:26: error: void value not ignored as it ought to be
                  keycode = read_port(KEYBOARD_DATA_PORT);
                          ^
[email protected]:~$ 


This post has been edited by Skydiver: 04 February 2018 - 07:16 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#43 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 06:32 PM

I never suggested anything of the sort,


look at what parameters do you actually use inside the function and what parameters do you actually return ?

And you're prototype is still different from its implementation..
void keyboard_handler_main(void) {

         unsigned char status;

         char keycode;

//         char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char

  

         /* write EOI */

         write_port(0x20, 0x20);

  

 status = read_port(KEYBOARD_STATUS_PORT);

         /* Lowest bit of status will be set if buffer is not

  empty */
         if (status & 0x01) {

                 keycode = read_port(KEYBOARD_DATA_PORT);

                 if(keycode < 0)

                         return;

                 vidptr[current_loc++] = keyboard_map[keycode];

                 vidptr[current_loc++] = 0x07;

 

       }

       return;

}




I will take a guess at what I think you mean as I am still not convinced that you know what you mean by this mess and perhaps you will gain some insight into self...

int keyboard_handler_main(int current_loc, unsigned char status,char keycode, char* vidptr );


this is your prototype or function defintion.

int keyboard_handler_main(int current_loc, unsigned char status,char keycode, char* vidptr )
{

vidptr[current_loc++] = keyboard_map[keycode]; /*note keyboard_map[] would have to be some global array not the best way of doing things perhaps use a function ?*/

  /* write EOI */

         write_port(0x20, 0x20);/*write_port is an assembler routine but it needs to be defined as extern in the C file*/

  

 status = read_port(KEYBOARD_STATUS_PORT);/* read_port is practically the same situation as write_port but this time it requires a #define in KEYBOARD_STATUS_PORT */

         /* Lowest bit of status will be set if buffer is not

  empty */

  /* Lowest bit of status will be set if buffer is not

  empty */
         if (status & 0x01) {

                 keycode = read_port(KEYBOARD_DATA_PORT);

                 if(keycode < 0)

                         return -1;/* return -1 for error condition*/

                 vidptr[current_loc++] = keyboard_map[keycode];

                 vidptr[current_loc++] = 0x07;

 

       }

       return current_loc; /* return the current location */

}






this would be your implementation...

This is still a mess but at least its a self consistent mess..

What you had is just illogical on any level and you don't seem to understand the basics of syntax or functions so how are you going to write a kernel ?

Ask yourself is this really what you want to do... as right now the aptitude in the level you need to be at in writing a kernel is simply not there.
Was This Post Helpful? 0
  • +
  • -

#44 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,528
  • Joined: 05-May 12

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 04 February 2018 - 07:12 PM

Programmingisnotmything: Please stop quoting the post above yours. We all can see it. There is no need to quote it. Just use the big Reply button or the Fast Reply area. All you are doing is wasting screen real estate and bandwidth. For those following this thread on a small screen device or over metered bandwidth, you are wasting their battery space, time, and money.

I've already told you this in post #10, and in #22. It is this same lack of attention to detail that is biting you in the ass as you tackle this project. Pay attention.
Was This Post Helpful? 0
  • +
  • -

#45 Programmingisnotmything   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 30
  • Joined: 18-September 14

Re: What's wrong with my kernel or other other files or how I'm ru

Posted 05 February 2018 - 07:53 AM

View PostSkydiver, on 04 February 2018 - 07:12 PM, said:

Programmingisnotmything: Please stop quoting the post above yours. We all can see it. There is no need to quote it. Just use the big Reply button or the Fast Reply area. All you are doing is wasting screen real estate and bandwidth. For those following this thread on a small screen device or over metered bandwidth, you are wasting their battery space, time, and money.

I've already told you this in post #10, and in #22. It is this same lack of attention to detail that is biting you in the ass as you tackle this project. Pay attention.


I'm qouting above me for you or anyone else except those I'm replying to and it makes it easier to know what my reply was about you jerk.
Was This Post Helpful? -1
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4