summaryrefslogtreecommitdiffstats
path: root/01_exercise/bootloader.c
blob: 1ba57865fdbe3f149715fee8d4b7bdb8bd9f39c5 (plain) (blame)
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
/* needs to stay the first line */
asm(".code16gcc\njmp $0, $main");

/* space for additional code */

char WRITE_CHARACTER_TTY = 0x0E;

// Syscall found here http://www.ctyme.com/intr/rb-0106.htm
void put(char c) {
    short command = WRITE_CHARACTER_TTY << 8 | c;
    // volatile because there is no output, so the function might get optimized
    // away
    // clang-format off
    asm volatile(
        "int $0x10;"
        ::"a"(command)
    );
    // clang-format on
}

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

// Syscall found here http://www.ctyme.com/intr/rb-1754.htm
char getc() {
    char ret;
    asm("mov $0x00, %%ah;"
        "int $0x16;"
        : "=a"(ret));
    return ret;
}

void main(void) {
    print("Hello!");
    put(getc());
}