-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
62 lines (56 loc) · 2.6 KB
/
utils.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <utils.h>
char nl[] = {'\r', '\n', 0x0};
/* Prints string in buffer on the screen */
void __attribute__((fastcall, naked)) print(const char* buffer){
__asm__(
" pusha ;" /* Save all registers */
" mov %cx, %bx ;"
" mov $0x0e, %ah ;" /* Video BIOS service: teletype mode */
" mov $0x0, %si ;"
"loop: ;"
" mov (%bx, %si), %al ;" /* Read character at bx+si position */
" cmp $0x0, %al ;" /* Repeat until end of string (0x0) */
" je end ;"
" int $0x10 ;" /* Call video BIOS service */
" add $0x1, %si ;" /* Advace to the next character */
" jmp loop ;" /* Repeat the procedure */
"end: ;"
" popa ;" /* Restore all registers */
" ret ;" /* Return from this function */
);
}
/* For debugging */
void __attribute__((naked, fastcall)) fatal(const char *msg){
print(msg);
print(NL);
__asm__(
"fatal_halt2: ;" /* Halt the CPU */
" hlt ;" /* Make sure itzz */
" jmp fatal_halt2 ;" /* Remains halted */
);
}
/* Clear the screen and set video colors */
void __attribute__((naked, fastcall)) clear(void){
__asm__(
" pusha ;" /* Push all registers */
" mov $0x0600, %ax ;" /* Video BIOS service: Scroll up */
" mov $0x07, %bh ;" /* Attribute (back/foreground) */
" mov $0x0, %cx ;" /* Upper-left corner */
" mov $0x184f, %dx ;" /* Lower-right corner */
" int $0x10 ;" /* Call video BIOS service */
" mov $0x0200, %ax ;" /* Set cursor position service */
" xor %bh, %bh ;" /* Page number (0) */
" xor %dl, %dl ;" /* Column (0) */
" xor %dh, %dh ;" /* Row (0) */
" int $0x10 ;" /* Call video BIOS service to move cursor */
" popa ;" /* Pop all registers */
" ret ;" /* Return from function */
);
}
void system_halt(){
__asm__(
"sys_halt: ;"
" hlt ;"
" jmp sys_halt ;"
);
}