-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsystem.c
77 lines (64 loc) · 1.36 KB
/
system.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "system.h"
#include "monitor.h"
#include "isr.h"
static void halt(void)
{
asm volatile("hlt");
}
void memcpy(void *dest, const void *src, uint32_t length)
{
const byte_t *srcPtr = (const byte_t *)src;
byte_t *destPtr = (byte_t *)dest;
for(; length != 0; length--)
{
*destPtr++ = *srcPtr++;
}
}
void memset(void *dest, byte_t value, uint32_t length)
{
byte_t *ptr = (byte_t *)dest;
for(; length != 0; length--)
{
*ptr++ = value;
}
}
byte_t inb(uint16_t port)
{
byte_t ret;
asm volatile("inb %1, %0" : "=a" (ret) : "dN" (port));
return ret;
}
void outb(uint16_t port, byte_t value)
{
asm volatile("outb %1, %0" : : "dN" (port), "a" (value));
}
void panic(char *msg, char *file, uint32_t line)
{
interrupt_disable();
monitor_color_set(MONCOLOR_WHITE, MONCOLOR_RED);
monitor_write("PANIC");
monitor_color_reset();
monitor_write(" ");
monitor_writeline(msg);
monitor_write(" (");
monitor_write(file);
monitor_put(':');
monitor_writei(line, 'd');
monitor_writeline(")");
halt();
}
void panic_assert(char *msg, char *file, uint32_t line)
{
interrupt_disable();
monitor_color_set(MONCOLOR_WHITE, MONCOLOR_LBROWN);
monitor_write("ASSERTION FAILED");
monitor_color_reset();
monitor_write(" ");
monitor_writeline(msg);
monitor_write(" (");
monitor_write(file);
monitor_put(':');
monitor_writei(line, 'd');
monitor_writeline(")");
halt();
}