-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.c
28 lines (24 loc) · 876 Bytes
/
kernel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* kernel.c */
/* Entry point of our kernel */
void kernel_main() {
/* Display "Hello, World!" */
const char *str = "Hello, World!";
/* Call a function to write a string to the screen */
print(str);
/* Hang the CPU */
for (;;);
}
/* Function to write a string to the screen */
void print(const char *str) {
/* VGA text mode buffer starts from address 0xb8000 */
unsigned short *video_memory = (unsigned short *)0xb8000;
/* Attribute byte for our default color scheme */
unsigned char color = 0x0F; // White text on black background
/* Loop through each character of the string */
for (int i = 0; str[i] != '\0'; ++i) {
/* Calculate the index into the VGA buffer */
unsigned short entry = (color << 8) | str[i];
/* Write the character to the buffer */
video_memory[i] = entry;
}
}