Kernels 101 – Let’s write a Kernel (2014)
unsigned int i = 0;
unsigned int j = 0;/* this loops 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 and light grey fg */
vidptr[i+1] = 0x07;
++j;
i = i + 2;
}
return;
}
All our kernel will do is clear the screen and write to it the string “my first kernel”. To print the character s in green color on black background, we will store the character s in the first byte of the video memory address and the value 0x02 in the second byte.
Source: arjunsreedharan.org