0

I am starter in os Deving and manage to make a bootloader and then a kernel.I cam successfully jumped to protected mode and transfer the control to kernel.I able to write single characters but printing string is not working.This is my printString() function.

void printString(char * message[]){
 int i;
 for(i = 0; message[i] != '\0'; i++)
 {
     print(message[i]);
 }
}

And My print Character function is here

void print(char *character){
unsigned char *vidmem = (unsigned char *) VIDEO_ADDRESS;
int offset;   //Variable which hold the offset where we want to print our character
offset =  GetCursor(); //Setting our offset to current cursor position

  vidmem[offset+1] = character;
  vidmem[offset+2] = 0x0f;

SetCursor(offset+2);    
}

and this is call to function

printString("manoj");

Please help me I am a starter in os deving

2 Answers2

1

I would recommend keeping track of the X and Y coordinates as (static) globals, and using them for offsets into memory. Also, it shouldn't be offset+1 and offset+2, but rather offset and offset+1. This is in addition to what tangrs said in his answer.

A good tutorial for learning how to print to the screen can be found at http://www.jamesmolloy.co.uk/tutorial_html/3.-The%20Screen.html - he goes into great detail about how to print things. It also is a good place to start learning about OSDev, along with the OSDev forums at http://forum.osdev.org/index.php.

Adrian Collado
  • 699
  • 8
  • 20
0

There's several things wrong with your functions

Firstly, your print function takes a pointer to a character where it looks like you want the character itself.

Secondly, your printString function is really taking a pointer to pointer to char which isn't what you want if you're calling the printString function like printString("Hello World");.

Your compiler should have warned you about these.

Your code should looks something like this

void printString(char * message){
  // ...
}

void print(char character){
  // ...
  vidmem[offset+1] = character;
  // ...  
}
tangrs
  • 9,709
  • 1
  • 38
  • 53
  • Hi tangrs I appreciate your help but your solution is not working – Manoj Singh Negi Jan 12 '14 at 11:23
  • You'll have to be more specific. What happens? – tangrs Jan 12 '14 at 12:11
  • There could be plenty of other things that could go wrong. Is your toolchain correctly set up to access the literal pool? (I.e. assert that `*(volatile char*)"A" == 'A';`). Is `print` actually getting called? Is the video memory being written correctly to? Your `SetCursor` function - is it working correctly? Is the video peripheral initialized correctly? Does being in protected mode mean that you can't access the video memory like this? – tangrs Jan 13 '14 at 07:37
  • my setcursor() is working correctly everything is right i don't know what's wrong – Manoj Singh Negi Jan 15 '14 at 13:44