24
|
1 #include "kernel.h"
|
|
2
|
|
3 void panic(char *msg)
|
|
4 {
|
|
5 printf("Kernel panic: ");
|
|
6 printf(msg);
|
|
7 magicBochsBreak();
|
|
8 halt();
|
|
9 }
|
|
10
|
26
|
11 void reboot()
|
|
12 {
|
|
13 while ( (inb(0x64) & 0x02) == 0x02)
|
|
14 {
|
|
15 ;
|
|
16 }
|
|
17 outb(0x64, 0xFE);
|
|
18 }
|
|
19
|
28
|
20 void halt()
|
|
21 {
|
|
22 asm volatile("cli");
|
|
23 asm volatile("hlt");
|
|
24 }
|
|
25
|
24
|
26 // IO port helpers:
|
|
27 void outb(uint16_t port, uint8_t value)
|
|
28 {
|
|
29 asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
|
|
30 }
|
|
31
|
|
32 uint8_t inb(uint16_t port)
|
|
33 {
|
|
34 uint8_t ret;
|
|
35 asm volatile ("inb %1, %0" : "=a" (ret) : "dN" (port));
|
|
36 return ret;
|
|
37 }
|
|
38
|
|
39 uint16_t inw(uint16_t port)
|
|
40 {
|
|
41 uint16_t ret;
|
|
42 asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port));
|
|
43 return ret;
|
|
44 }
|
|
45
|
|
46 // string functions:
|
|
47 int strncmp(const char* s1, const char* s2, int size)
|
|
48 {
|
|
49 int i;
|
|
50 for (i=0; i<size; i++)
|
|
51 {
|
|
52 if (s1[i] != s2[i]) return 0;
|
|
53 }
|
|
54 return 1;
|
|
55 }
|
|
56
|
28
|
57 // mem functions:
|
|
58 void memset(void* data, uint8_t value, uint64_t size)
|
|
59 {
|
|
60 uint64_t i;
|
|
61 uint8_t *data2 = (uint8_t*)data;
|
|
62 for (i = 0; i < size; i++)
|
|
63 {
|
|
64 data2[i] = value;
|
|
65 }
|
|
66 }
|
|
67
|