Mercurial > lcfOS
annotate cos/kernel/klib.c @ 34:8012221dd740
Fixes for uninitialized data. This causes problems on real machines
author | windel |
---|---|
date | Mon, 16 Jan 2012 13:46:06 +0100 |
parents | 3a6a9b929db0 |
children | 91f91ff07ea8 |
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 { | |
19 while ( (inb(0x64) & 0x02) == 0x02) | |
20 { | |
21 ; | |
22 } | |
23 outb(0x64, 0xFE); | |
24 } | |
25 | |
28 | 26 void halt() |
27 { | |
28 asm volatile("cli"); | |
29 asm volatile("hlt"); | |
30 } | |
31 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
29
diff
changeset
|
32 /* IO port helpers: */ |
24 | 33 void outb(uint16_t port, uint8_t value) |
34 { | |
35 asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)); | |
36 } | |
37 | |
38 uint8_t inb(uint16_t port) | |
39 { | |
40 uint8_t ret; | |
41 asm volatile ("inb %1, %0" : "=a" (ret) : "dN" (port)); | |
42 return ret; | |
43 } | |
44 | |
45 uint16_t inw(uint16_t port) | |
46 { | |
47 uint16_t ret; | |
48 asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port)); | |
49 return ret; | |
50 } | |
51 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
29
diff
changeset
|
52 /* string functions: */ |
24 | 53 int strncmp(const char* s1, const char* s2, int size) |
54 { | |
55 int i; | |
56 for (i=0; i<size; i++) | |
57 { | |
58 if (s1[i] != s2[i]) return 0; | |
59 } | |
60 return 1; | |
61 } | |
62 | |
28 | 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 |