summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
blob: ec18738c84cd4d11254aa014897fcaccf56a7ff4 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
__asm__(".code16gcc\n");

void vga_graphics_write_at_offset(char, short);
void vga_graphics_write(char);
void vga_graphics_write_with_attr(char, char);
void vga_graphics_write_str(char*);

static short CURSOR_LOC = 0;

void _start() {
  vga_graphics_write_with_attr('a', 1);
  vga_graphics_write_with_attr('/', 2);
  vga_graphics_write_with_attr('b', 3);
  char foo[] = "hello how are you";
  vga_graphics_write_str(foo);
  while(1) { }
}

void vga_graphics_write_str(char* str) {
  while(*str) {
    vga_graphics_write(*str++);
  }
}

void vga_graphics_write_with_attr(char value, char attr) {
  vga_graphics_write_at_offset(value, CURSOR_LOC++);
  vga_graphics_write_at_offset(attr, CURSOR_LOC++);
}

void vga_graphics_write(char value) {
  vga_graphics_write_at_offset(value, CURSOR_LOC);
  CURSOR_LOC += 2;
}

void vga_graphics_write_at_offset(char value, short offset) {
  __asm__(
    "mov %0, %%al          \n"
    "mov %1, %%di          \n"
    "mov %%al, %%gs:(%%di) \n"
    : :"r"(value), "r"(offset) : "%ax", "%di");
}