Mercurial > lcfOS
annotate cos/kernel/klib.c @ 299:674789d9ff37
Added a doc
author | Windel Bouwman |
---|---|
date | Sun, 01 Dec 2013 18:37:23 +0100 |
parents | 91f91ff07ea8 |
children |
rev | line source |
---|---|
24 | 1 #include "kernel.h" |
2 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
29
diff
changeset
|
3 /* Panic and shutdown functions */ |
29 | 4 void magicBochsBreak() |
5 { | |
6 asm volatile("xchg %bx, %bx"); | |
7 } | |
8 | |
24 | 9 void panic(char *msg) |
10 { | |
11 printf("Kernel panic: "); | |
12 printf(msg); | |
13 magicBochsBreak(); | |
14 halt(); | |
15 } | |
16 | |
26 | 17 void reboot() |
18 { | |
36 | 19 // Use the keyboard to reboot: |
26 | 20 while ( (inb(0x64) & 0x02) == 0x02) |
21 { | |
22 ; | |
23 } | |
24 outb(0x64, 0xFE); | |
25 } | |
26 | |
28 | 27 void halt() |
28 { | |
36 | 29 asm volatile("cli"); // Disable interrupts. |
30 asm volatile("hlt"); // Halt processor | |
28 | 31 } |
32 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
29
diff
changeset
|
33 /* IO port helpers: */ |
24 | 34 void outb(uint16_t port, uint8_t value) |
35 { | |
36 asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)); | |
37 } | |
38 | |
39 uint8_t inb(uint16_t port) | |
40 { | |
41 uint8_t ret; | |
42 asm volatile ("inb %1, %0" : "=a" (ret) : "dN" (port)); | |
43 return ret; | |
44 } | |
45 | |
46 uint16_t inw(uint16_t port) | |
47 { | |
48 uint16_t ret; | |
49 asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port)); | |
50 return ret; | |
51 } | |
52 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
29
diff
changeset
|
53 /* string functions: */ |
24 | 54 int strncmp(const char* s1, const char* s2, int size) |
55 { | |
36 | 56 int i; |
57 for (i=0; i<size; i++) | |
58 { | |
59 if (s1[i] != s2[i]) return 0; | |
60 } | |
61 return 1; | |
24 | 62 } |
63 | |
28 | 64 void memset(void* data, uint8_t value, uint64_t size) |
65 { | |
66 uint64_t i; | |
67 uint8_t *data2 = (uint8_t*)data; | |
68 for (i = 0; i < size; i++) | |
69 { | |
70 data2[i] = value; | |
71 } | |
72 } | |
73 |