annotate cos/kernel/klib.c @ 271:cf7d5fb7d9c8

Reorganization
author Windel Bouwman
date Tue, 20 Aug 2013 18:56:02 +0200
parents 91f91ff07ea8
children
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
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 29
diff changeset
3 /* Panic and shutdown functions */
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
4 void magicBochsBreak()
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
5 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
6 asm volatile("xchg %bx, %bx");
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
7 }
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
8
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
9 void panic(char *msg)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
10 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
11 printf("Kernel panic: ");
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
12 printf(msg);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
13 magicBochsBreak();
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
14 halt();
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
15 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
16
26
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
17 void reboot()
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
18 {
36
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
19 // Use the keyboard to reboot:
26
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
20 while ( (inb(0x64) & 0x02) == 0x02)
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
21 {
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
22 ;
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
23 }
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
24 outb(0x64, 0xFE);
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
25 }
dcce92b1efbc Added mm.c
windel
parents: 24
diff changeset
26
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
27 void halt()
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
28 {
36
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
29 asm volatile("cli"); // Disable interrupts.
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
30 asm volatile("hlt"); // Halt processor
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
31 }
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
32
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 29
diff changeset
33 /* IO port helpers: */
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
34 void outb(uint16_t port, uint8_t value)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
35 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
36 asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
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 uint8_t inb(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 uint8_t ret;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
42 asm volatile ("inb %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 uint16_t inw(uint16_t port)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
47 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
48 uint16_t ret;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
49 asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port));
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
50 return ret;
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
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 29
diff changeset
53 /* string functions: */
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
54 int strncmp(const char* s1, const char* s2, int size)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
55 {
36
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
56 int i;
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
57 for (i=0; i<size; i++)
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
58 {
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
59 if (s1[i] != s2[i]) return 0;
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
60 }
91f91ff07ea8 Removed test variables
windel
parents: 32
diff changeset
61 return 1;
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
62 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
63
28
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
64 void memset(void* data, uint8_t value, uint64_t size)
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
65 {
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
66 uint64_t i;
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
67 uint8_t *data2 = (uint8_t*)data;
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
68 for (i = 0; i < size; i++)
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
69 {
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
70 data2[i] = value;
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
71 }
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
72 }
47b7df514243 Moved Makefiles
windel
parents: 26
diff changeset
73