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

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

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

#16 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1460
  • View blog
  • Posts: 4,726
  • Joined: 20-March 10

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

Posted 20 January 2018 - 11:49 AM

Yes...

read further and note the other advice given about using unique names for different things so you don't confuse the compiler... ;)
Was This Post Helpful? 0
  • +
  • -

#17 Programmingisnotmything  Icon 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 20 January 2018 - 12:18 PM

Ok I finally did that once I realized you meant that it goes in the c file or kernel.c and not the assembly or kernel.asm, but I'm not sure if I elimated that error or any other errors. However, here are the errors I'm getting:

[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:19:1: warning: parameter names (without types) in function declaration
 void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), i
 ^
/home/username/Documents/My first sample kernel/kernel2.c:19:96: error: ‘keycode’ undeclared here (not in a function)
 int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); 
                                                                     ^
/home/username/Documents/My first sample kernel/kernel2.c:20:13: 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:20:30: error: ‘keyboard_map’ 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:20:43: 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:28: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:28:16: error: ‘IDT_SIZE’ undeclared (first use in this function)
  IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
                ^
/home/username/Documents/My first sample kernel/kernel2.c:28:16: note: each undeclared identifier is reported only once for each function it appears in
/home/username/Documents/My first sample kernel/kernel2.c:32:30: error: ‘load_idt’ undeclared (first use in this function)
         idt_init(write_port, load_idt, IDT);
                              ^
/home/username/Documents/My first sample kernel/kernel2.c:32:18: warning: passing argument 1 of ‘idt_init’ makes integer from pointer without a cast [-Wint-conversion]
         idt_init(write_port, load_idt, IDT);
                  ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:33:17: warning: passing argument 1 of ‘kb_init’ makes integer from pointer without a cast [-Wint-conversion]
         kb_init(write_port);
                 ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:9: warning: parameter names (without types) in function declaration
         int keyboard_handler_main(write_port, read_port, keyboard_map);
         ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: error: conflicting types for ‘keyboard_handler_main’
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c:19:6: note: previous declaration of ‘keyboard_handler_main’ was here
 void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), i
      ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:62:6: error: conflicting types for ‘idt_init’
 void idt_init(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: previous declaration of ‘idt_init’ was here
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘idt_init’:
/home/username/Documents/My first sample kernel/kernel2.c:69:36: error: ‘keyboard_handler’ undeclared (first use in this function)
  keyboard_address = (unsigned long)keyboard_handler;
                                    ^
/home/username/Documents/My first sample kernel/kernel2.c:70: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:112:44: error: ‘IDT_SIZE’ undeclared (first use in this function)
  idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
                                            ^
/home/username/Documents/My first sample kernel/kernel2.c:116:2: warning: implicit declaration of function ‘load_idt’ [-Wimplicit-function-declaration]
  load_idt(idt_ptr);
  ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:119:6: error: conflicting types for ‘kb_init’
 void kb_init(void) 
      ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: previous declaration of ‘kb_init’ was here
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:125:6: error: conflicting types for ‘keyboard_handler_main’
 void keyboard_handler_main(void) {
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: note: previous declaration of ‘keyboard_handler_main’ was here
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘keyboard_handler_main’:
/home/username/Documents/My first sample kernel/kernel2.c:133:21: error: ‘KEYBOARD_STATUS_PORT’ undeclared (first use in this function)
  status = read_port(KEYBOARD_STATUS_PORT);
                     ^
/home/username/Documents/My first sample kernel/kernel2.c:137:38: error: ‘KEYBOARD_DATA_PORT’ undeclared (first use in this function)
                  keycode = read_port(KEYBOARD_DATA_PORT);
                                      ^
[email protected]:~$ 



and here is my current code:

/*
* kernel.c
*/

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

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 idt_init(int write_port, int load_idt, int IDT[]); // function prototype
void kb_init(int write_port); // function prototype
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 void write_port(unsigned short port, unsigned char data);
extern void read_port(unsigned char KEYBOARD_DATA_PORT);

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

	const char *str = "my first kernel";
	char *vidptr =(char*)0xb8000; //video mem begins here.
        idt_init(write_port, load_idt, IDT);
        kb_init(write_port);
        int keyboard_handler_main(write_port, read_port, keyboard_map);
	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 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: 20 January 2018 - 05:08 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#18 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1460
  • View blog
  • Posts: 4,726
  • Joined: 20-March 10

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

Posted 20 January 2018 - 12:26 PM

Err Yeah,

I say things but I'm not entirely sure that you are listening :) ?

Take the errors one by one...

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




notice anything odd about this line of code or something that looks similar to other code in other files... ?? Or even in the same file actually... I refer you back to the unique names things as first postulated by the mercurial modi123_1
Was This Post Helpful? 0
  • +
  • -

#19 Programmingisnotmything  Icon 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 20 January 2018 - 12:41 PM

Should that be this then if nothing else:

void keyboard_handler_main(int write_port(unsigned short port, unsigned char data), int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); // function prototype

This post has been edited by Skydiver: 20 January 2018 - 05:09 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#20 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1460
  • View blog
  • Posts: 4,726
  • Joined: 20-March 10

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

Posted 20 January 2018 - 01:07 PM

Uhh no,


Ok I will hold your hand a little bit...

you have a function called

write_port

you have another function called

keyboard_handler_main

now keyboard_handler_main has 3 parameters yes... ?


Consider the following working program

#include <stdio.h>
#include <stdlib.h>


/*function 1*/
int add(int parameter1, int parameter2)
{
    return parameter1+parameter2;
}

int main()
{
    printf("%d", add(9,9));
    return 0;
}



run it and see what happens ..

now try to compile this....


#include <stdio.h>
#include <stdlib.h>
/*function 2*/

int parameter1(unsigned short half, unsigned short other_half)
{

    return (int)(half+other_half);
}

/*function 1*/
int add(int parameter1(unsigned short half, unsigned short other_half), int parameter2)
{
    return parameter1+parameter2;
}

int main()
{
    printf("%d", add(9,9));
    return 0;
}





so your first error could be fixed on line 19 thus...

void keyboard_handler_main(void); // function prototype



yes ?

This post has been edited by snoopy11: 20 January 2018 - 01:11 PM
Reason for edit:: typo forgot the word 'be'

Was This Post Helpful? 0
  • +
  • -

#21 Programmingisnotmything  Icon 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 20 January 2018 - 04:45 PM

*** Removed huge quote ***

Ok I copied those codes into text files created with Vi and compiled them, like you said. The first program I called parametersexample1.c and the second program I was supposed to expect an error in I called parametersexample2.c, so I could see what you meant and didn't that well. Then, I added the last bit of code you said to my kernel2.c in place of what I originally had and got the following errors:

[email protected]:~$ gcc -m32 -lm -c /home/username/Documents/My\ first\ sample\ kernel/parametersexample2.c -o /home/username/Documents/My\ first\ sample\ kernel/pe2.o
/home/username/Documents/My first sample kernel/parametersexample2.c: In function ‘add’:
/home/username/Documents/My first sample kernel/parametersexample2.c:14:12: warning: return makes integer from pointer without a cast [-Wint-conversion]
     return parameter1+parameter2;
            ^
/home/username/Documents/My first sample kernel/parametersexample2.c: In function ‘main’:
/home/username/Documents/My first sample kernel/parametersexample2.c:19:22: warning: passing argument 1 of ‘add’ makes pointer from integer without a cast [-Wint-conversion]
     printf("%d", add(9,9));
                      ^
/home/username/Documents/My first sample kernel/parametersexample2.c:12:5: note: expected ‘int (*)(short unsigned int,  short unsigned int)’ but argument is of type ‘int’
 int add(int parameter1(unsigned short half, unsigned short other_half), int par
     ^
[email protected]:~$ sudo vi /home/username/Documents/My\ first\ sample\ kernel/kernel2.c
[email protected]:~$ gcc -m32 -lm -c /home/username/Documents/My\ first\ sample\ kernel/parametersexample2.c -o /home/username/Documents/My\ first\ sample\ kernel/pe2.o
/home/username/Documents/My first sample kernel/parametersexample2.c: In function ‘add’:
/home/username/Documents/My first sample kernel/parametersexample2.c:14:12: warning: return makes integer from pointer without a cast [-Wint-conversion]
     return parameter1+parameter2;
            ^
/home/username/Documents/My first sample kernel/parametersexample2.c: In function ‘main’:
/home/username/Documents/My first sample kernel/parametersexample2.c:19:22: warning: passing argument 1 of ‘add’ makes pointer from integer without a cast [-Wint-conversion]
     printf("%d", add(9,9));
                      ^
/home/username/Documents/My first sample kernel/parametersexample2.c:12:5: note: expected ‘int (*)(short unsigned int,  short unsigned int)’ but argument is of type ‘int’
 int add(int parameter1(unsigned short half, unsigned short other_half), int par
     ^
[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:20:13: 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:20:30: error: ‘keyboard_map’ 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:20:43: 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:28: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:28:16: error: ‘IDT_SIZE’ undeclared (first use in this function)
  IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
                ^
/home/username/Documents/My first sample kernel/kernel2.c:28:16: note: each undeclared identifier is reported only once for each function it appears in
/home/username/Documents/My first sample kernel/kernel2.c:32:30: error: ‘load_idt’ undeclared (first use in this function)
         idt_init(write_port, load_idt, IDT);
                              ^
/home/username/Documents/My first sample kernel/kernel2.c:32:18: warning: passing argument 1 of ‘idt_init’ makes integer from pointer without a cast [-Wint-conversion]
         idt_init(write_port, load_idt, IDT);
                  ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:33:17: warning: passing argument 1 of ‘kb_init’ makes integer from pointer without a cast [-Wint-conversion]
         kb_init(write_port);
                 ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:9: warning: parameter names (without types) in function declaration
         int keyboard_handler_main(write_port, read_port, keyboard_map);
         ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: error: conflicting types for ‘keyboard_handler_main’
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c:19:6: note: previous declaration of ‘keyboard_handler_main’ was here
 void keyboard_handler_main(void); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:62:6: error: conflicting types for ‘idt_init’
 void idt_init(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: previous declaration of ‘idt_init’ was here
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘idt_init’:
/home/username/Documents/My first sample kernel/kernel2.c:69:36: error: ‘keyboard_handler’ undeclared (first use in this function)
  keyboard_address = (unsigned long)keyboard_handler;
                                    ^
/home/username/Documents/My first sample kernel/kernel2.c:70: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:112:44: error: ‘IDT_SIZE’ undeclared (first use in this function)
  idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
                                            ^
/home/username/Documents/My first sample kernel/kernel2.c:116:2: warning: implicit declaration of function ‘load_idt’ [-Wimplicit-function-declaration]
  load_idt(idt_ptr);
  ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:119:6: error: conflicting types for ‘kb_init’
 void kb_init(void) 
      ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: previous declaration of ‘kb_init’ was here
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:125:6: error: conflicting types for ‘keyboard_handler_main’
 void keyboard_handler_main(void) {
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: note: previous declaration of ‘keyboard_handler_main’ was here
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘keyboard_handler_main’:
/home/username/Documents/My first sample kernel/kernel2.c:133:21: error: ‘KEYBOARD_STATUS_PORT’ undeclared (first use in this function)
  status = read_port(KEYBOARD_STATUS_PORT);
                     ^
/home/username/Documents/My first sample kernel/kernel2.c:137:38: error: ‘KEYBOARD_DATA_PORT’ undeclared (first use in this function)
                  keycode = read_port(KEYBOARD_DATA_PORT);
                                      ^
[email protected]:~$ 


I don't know exactly what the point of that parameter example exercise, because it didn't use a void parameter, like you suggest I needed or if it fixed the error consider the previous errors are as follows:

[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:19:1: warning: parameter names (without types) in function declaration
 void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), i
 ^
/home/username/Documents/My first sample kernel/kernel2.c:19:96: error: ‘keycode’ undeclared here (not in a function)
 int write_port, int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); 
                                                                     ^
/home/username/Documents/My first sample kernel/kernel2.c:20:13: 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:20:30: error: ‘keyboard_map’ 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:20:43: 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:28: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:28:16: error: ‘IDT_SIZE’ undeclared (first use in this function)
  IDT_entry IDT[IDT_SIZE]; // IDT is an IDT_entry structure.
                ^
/home/username/Documents/My first sample kernel/kernel2.c:28:16: note: each undeclared identifier is reported only once for each function it appears in
/home/username/Documents/My first sample kernel/kernel2.c:32:30: error: ‘load_idt’ undeclared (first use in this function)
         idt_init(write_port, load_idt, IDT);
                              ^
/home/username/Documents/My first sample kernel/kernel2.c:32:18: warning: passing argument 1 of ‘idt_init’ makes integer from pointer without a cast [-Wint-conversion]
         idt_init(write_port, load_idt, IDT);
                  ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:33:17: warning: passing argument 1 of ‘kb_init’ makes integer from pointer without a cast [-Wint-conversion]
         kb_init(write_port);
                 ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: expected ‘int’ but argument is of type ‘void (*)(short unsigned int,  unsigned char)’
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:9: warning: parameter names (without types) in function declaration
         int keyboard_handler_main(write_port, read_port, keyboard_map);
         ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: error: conflicting types for ‘keyboard_handler_main’
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c:19:6: note: previous declaration of ‘keyboard_handler_main’ was here
 void keyboard_handler_main(int write_port, int read_port(KEYBOARD_DATA_PORT), i
      ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:62:6: error: conflicting types for ‘idt_init’
 void idt_init(void)
      ^
/home/username/Documents/My first sample kernel/kernel2.c:17:6: note: previous declaration of ‘idt_init’ was here
 void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘idt_init’:
/home/username/Documents/My first sample kernel/kernel2.c:69:36: error: ‘keyboard_handler’ undeclared (first use in this function)
  keyboard_address = (unsigned long)keyboard_handler;
                                    ^
/home/username/Documents/My first sample kernel/kernel2.c:70: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:112:44: error: ‘IDT_SIZE’ undeclared (first use in this function)
  idt_ptr[0] = (sizeof (struct IDT_entry) * IDT_SIZE) +
                                            ^
/home/username/Documents/My first sample kernel/kernel2.c:116:2: warning: implicit declaration of function ‘load_idt’ [-Wimplicit-function-declaration]
  load_idt(idt_ptr);
  ^
/home/username/Documents/My first sample kernel/kernel2.c: At top level:
/home/username/Documents/My first sample kernel/kernel2.c:119:6: error: conflicting types for ‘kb_init’
 void kb_init(void) 
      ^
/home/username/Documents/My first sample kernel/kernel2.c:18:6: note: previous declaration of ‘kb_init’ was here
 void kb_init(int write_port); // function prototype
      ^
/home/username/Documents/My first sample kernel/kernel2.c:125:6: error: conflicting types for ‘keyboard_handler_main’
 void keyboard_handler_main(void) {
      ^
/home/username/Documents/My first sample kernel/kernel2.c:34:13: note: previous declaration of ‘keyboard_handler_main’ was here
         int keyboard_handler_main(write_port, read_port, keyboard_map);
             ^
/home/username/Documents/My first sample kernel/kernel2.c: In function ‘keyboard_handler_main’:
/home/username/Documents/My first sample kernel/kernel2.c:133:21: error: ‘KEYBOARD_STATUS_PORT’ undeclared (first use in this function)
  status = read_port(KEYBOARD_STATUS_PORT);
                     ^
/home/username/Documents/My first sample kernel/kernel2.c:137:38: error: ‘KEYBOARD_DATA_PORT’ undeclared (first use in this function)
                  keycode = read_port(KEYBOARD_DATA_PORT);
                                      ^
[email protected]:~$ 



and here is my most recent code:

/*
* kernel.c
*/

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

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 idt_init(int write_port, int load_idt, int IDT[]); // function prototype
void kb_init(int write_port); // function prototype
void keyboard_handler_main(void); // function prototype
char vidptr[current_loc++] = keyboard_map[keycode]; // Pointer to a char
unsigned long idt_ptr[2]; // Pointer to a unsigned long

extern void write_port(unsigned short port, unsigned char data);
extern void read_port(unsigned char KEYBOARD_DATA_PORT);

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

	const char *str = "my first kernel";
	char *vidptr =(char*)0xb8000; //video mem begins here.
        idt_init(write_port, load_idt, IDT);
        kb_init(write_port);
        int keyboard_handler_main(write_port, read_port, keyboard_map);
	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 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;
}



I did see check and we did do up to classes in the C++ class I took, but not beyond that from Tony Gaddis's books. I did beyond that though on my own, but never tried to write a program with it because I was lost at that point especially after not having writen a C++ program, since 2014 that I can be sure that I wrote.

*** removed huge quote ***

Should the following be what follows after that:

void idt_init(int write_port, int load_idt, int IDT[]); // function prototype
018
void kb_init(int write_port); // function prototype



and should it be this:

void idt_init(void); // function prototype
018
void kb_init(void); // function prototype


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

Was This Post Helpful? 0
  • +
  • -

#22 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6164
  • View blog
  • Posts: 21,253
  • Joined: 05-May 12

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

Posted 20 January 2018 - 05:06 PM

Programmingisnotmything: Let me repeat what I said all the way back in post #10. There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

#23 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1460
  • View blog
  • Posts: 4,726
  • Joined: 20-March 10

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

Posted 20 January 2018 - 09:13 PM

Yeah....

Time for an allegory... I think...

so a Man builds a house with no idea of how to build a house apart from what he has read in a few books and the on the internet and it falls down...

he meets a guy in a bar and tells his sorry tale to the stranger....

The stranger in the bar turns out to be a House builder and offers to look at the house and provide advice, the Man and stranger go look at the House and the stranger goes into some length of what the man did wrong and why the House fell down....

The man after a while says I didn't understand any of that and says to the stranger can't you just rebuild my House for free as 'Building houses is not my thing'...

The stranger looks at the Man and then at the pile of rubble that was his house and rolls his eyes and walks away..
Was This Post Helpful? 0
  • +
  • -

#24 Programmingisnotmything  Icon 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 26 January 2018 - 09:22 AM

LOL

This post has been edited by Skydiver: 26 January 2018 - 09:31 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#25 Programmingisnotmything  Icon 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 26 January 2018 - 09:42 AM

It was pointed out to me by snoopy11 that the following did not have unique parameters:

void keyboard_handler_main(int write_port(unsigned short port,
unsigned char data), int read_port(KEYBOARD_DATA_PORT), int keyboard_map[keycode]); // function prototype



and should be this:

void keyboard_handler_main(void); // function prototype



, but what about these function prototype parameters:


void idt_init(int write_port, int load_idt, int IDT[]); // function prototype

void kb_init(int write_port); // function prototype



Should they be the following:


void idt_init(void); // function prototype

void kb_init(void); // function prototype


I can see how there parameters wouldn't be unique though as I originallly had them because this:

void idt_init(int write_port, int load_idt, int IDT[]); // function prototype


and this:


void kb_init(int write_port); // function prototype


contain this as at least one of the parameters:

int write_port


,but I don't know if these parameters should be void or what they should be if not void or similar to what I had them as.
Was This Post Helpful? 0
  • +
  • -

#26 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 14038
  • View blog
  • Posts: 56,177
  • Joined: 12-June 08

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

Posted 26 January 2018 - 10:12 AM

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.

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.

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.

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.

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.

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.

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.
Was This Post Helpful? 0
  • +
  • -

#27 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6164
  • View blog
  • Posts: 21,253
  • Joined: 05-May 12

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

Posted 26 January 2018 - 11:21 AM

I think that Tom Gaddis' book is not an effective learning tool for our OP. Probably the author's writing style doesn't match our OP's learning style. If he successfully completed an assembly programming book and sounded confident about his learning (according to post #1), does anybody have any recommendations for what book he should use instead to learn C and/or C++?

Right now, the only thing that comes to mind that makes a good jump from assembly to C is the K&R book because the book assumes that the reader already knows how to program, but needs a primer in how to write programs in C.

But take that with a huge grain of salt. My language learning progression was BASIC, 6502 assembly, Forth, x86 assembly, Pascal, C, 68000 assembly, C++, ...
Was This Post Helpful? 0
  • +
  • -

#28 jimblumberg  Icon User is offline

  • member icon

Reputation: 5467
  • View blog
  • Posts: 17,019
  • Joined: 25-December 09

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

Posted 26 January 2018 - 12:04 PM

Quote

I think that Tom Gaddis' book is not an effective learning tool for our OP.

Not really familiar with this author, however it appears to me that the OP is trying to run before he can even sit up much less walk. IMO this OP is nowhere ready to try to write a kernel, in any language. I suggest that he step away from this program and find a book that teaches the language he is interested in, be it C, C++ or any other language.

Quote from the first post:

Quote

I'm just a Network Admin major with a minor in programming though and I just recently finished writing the sample code in the Modern Assembly book by Daniel Kussworm, which includes the C++ and Assembly sample code for whatever purpose. I wrote the sample code to help me become familiar with writing Assembly optimized C++ programs and read the book, but even though I know how to run both the Assembly and C++ I still don't understand completely what the code is doing yet if I ever will.


If he is interested in C++ I would recommend books designed to learn C++, such as (in reverse order)

C++ Primer by Lajoie/Lippman
Accelerated C++ by Koenig/Moo
C++ Principles and Practice by Stroustrup

For C perhaps something like:

C Programming: A Modern Approach" by K.N. King.
C Primer Plus, 5th Edition By Stephen Prata
And of course the C Bible for reference:
C Programming Language (2nd Edition By B. W. Kernighan & D. M. Ritchie)

Jim
Was This Post Helpful? 1
  • +
  • -

#29 Programmingisnotmything  Icon 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 - 08:45 PM

View PostSkydiver, on 26 January 2018 - 11:21 AM, said:

I think that Tom Gaddis' book is not an effective learning tool for our OP. Probably the author's writing style doesn't match our OP's learning style. If he successfully completed an assembly programming book and sounded confident about his learning (according to post #1), does anybody have any recommendations for what book he should use instead to learn C and/or C++?

Right now, the only thing that comes to mind that makes a good jump from assembly to C is the K&R book because the book assumes that the reader already knows how to program, but needs a primer in how to write programs in C.

But take that with a huge grain of salt. My language learning progression was BASIC, 6502 assembly, Forth, x86 assembly, Pascal, C, 68000 assembly, C++, ...


Actually I didn't feel confident about my x86 assembly programming after completing Daniel Kussworms book and I've forgotten a lot about C or C++ programming, since 2014 because I've had a really difficult time figuring what I want to write a program to do or what to write a program for that hasn't already been done and Gaddis doesn't explain how to write a GUI very well if at all in Starting out with C++. I know this has nothing to do with writing a GUI in C++ though, but eventually, that will be necessary and is a problem especially finding a good explaination for how to do it in Linux.

My language learning goes like this some GWBASIC in high school, Visual Basic 6.0 early in College, UNIX Linux/Shell Scripting Summer 2011, Visual Basic.NET in Fall 2014, C++ Fall 2014, Java Spring 2015, HTML, CSS, XML, and Javascript Spring 2015, and X86 Assembly Fall 2017. All of which I barely find time to use.
Was This Post Helpful? 0
  • +
  • -

#30 Programmingisnotmything  Icon 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:03 PM

View Postjimblumberg, on 26 January 2018 - 12:04 PM, said:

Quote

I think that Tom Gaddis' book is not an effective learning tool for our OP.

Not really familiar with this author, however it appears to me that the OP is trying to run before he can even sit up much less walk. IMO this OP is nowhere ready to try to write a kernel, in any language. I suggest that he step away from this program and find a book that teaches the language he is interested in, be it C, C++ or any other language.

Quote from the first post:

Quote

I'm just a Network Admin major with a minor in programming though and I just recently finished writing the sample code in the Modern Assembly book by Daniel Kussworm, which includes the C++ and Assembly sample code for whatever purpose. I wrote the sample code to help me become familiar with writing Assembly optimized C++ programs and read the book, but even though I know how to run both the Assembly and C++ I still don't understand completely what the code is doing yet if I ever will.


If he is interested in C++ I would recommend books designed to learn C++, such as (in reverse order)

C++ Primer by Lajoie/Lippman
Accelerated C++ by Koenig/Moo
C++ Principles and Practice by Stroustrup

For C perhaps something like:

C Programming: A Modern Approach" by K.N. King.
C Primer Plus, 5th Edition By Stephen Prata
And of course the C Bible for reference:
C Programming Language (2nd Edition By B. W. Kernighan & D. M. Ritchie)

Jim


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 found time or found time to complete later as well as Gaddis's Java Programming book. I was determined and driven to complete Assembly after finding the kernel 101 guide and kernel 201 guide because I realized how important it was to a kernel or to use as part of a kernel, which was something the computer science book I read didn't seem to mention anything about that I completed prior to completing the x86 assembly book and finding the kernal 101 as well as 201 guides. Also, I've completed a book on Computer engineering too, but it doesn't mention how important assembly and c programming are to most kernels and the rest of an operating system. I did know that UNIX was originally written in Assembly though, then converted to B, and then C by reading the intro of a practical guide to UNIX/Linux by Mark G. Sobell for the UNIX/Linux Operating Enviroment class I took in Fall 2010. The only reason I was able to use the vi text editor instead of nano or gedit is because I know so much about UNIX/Linux, since I have an Associate's in UNIX/Linux Networking and Database Administration. I only have a minor in computer programming though, but I need to know so much more to successfully write my own complete kernel and apparently to follow this guide on how to bring, even this kernel up to a command prompt to accept text.
Was This Post Helpful? 0
  • +
  • -

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