C kernel- printing string not working -


i making c kernel scratch, , literally copied code off of website because code wasn't working confused.

void kmain(void) {     const char *str = "my first kernel";     char *vidptr = (char*)0xb8000;  //video mem begins here.     unsigned int = 0;     unsigned int j = 0;      /* loops clears screen     * there 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;      /* loop writes string video memory */     while(str[j] != '\0') {         /* character's ascii */         vidptr[i] = str[j];         /* attribute-byte: give character black bg , light grey fg */         vidptr[i+1] = 0x07;         ++j;         = + 2;     }     return; } 

when run kernel, prints s screen , nothing else. know kernel booting, because if do

vidptr[0] = 'h'; vidptr[2] = 'e'; vidptr[4] = 'l'; vidptr[6] = 'l'; vidptr[8] = 'o'; 

it works expected. happening?

edit: might code loads kernel (might not have set of registers) grub , other things.

try using volatile keyword variable

ref page: http://wiki.osdev.org/printing_to_screen

// note example write top // line of screen void write_string( int colour, const char *string ) {     volatile char *video = (volatile char*)0xb8000;     while( *string != 0 )     {         *video++ = *string++;         *video++ = colour;     } } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -