annotate cos/kernel/klib.c @ 28:47b7df514243

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