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