nckernel
0.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
arch
x86
src
common.c
Go to the documentation of this file.
1
#include <
sys/types.h
>
2
#include <
stdio.h
>
3
#include <
stdlib.h
>
4
#include <
stddef.h
>
5
#include <
stdint.h
>
6
#include <
unistd.h
>
7
#include <
stdarg.h
>
8
#include <
string.h
>
9
#include <
time.h
>
10
#include <
semaphore.h
>
11
12
#include <
segment.h
>
13
#include <
idt.h
>
14
#include <
pic.h
>
15
#include <
interrupt.h
>
16
#include <
isr.h
>
17
18
#include <
fdc.h
>
19
#include <
video.h
>
20
#include <
serial.h
>
21
#include <
keyboard.h
>
22
23
#include <
paging.h
>
24
25
#include <
arch.h
>
/* panic */
26
#include <
x86.h
>
/* halt */
27
28
#include <
timer_handler.h
>
29
#include <
divide_error_handler.h
>
30
#include <
page_fault_handler.h
>
31
32
#include <
debug.h
>
33
34
static
int
eoi(
int
sub_irq,
void
*
info
,
void
*data)
35
{
36
if
(sub_irq ==
IRQ_NR_FDC
) {
37
static
int
cnt = 0;
38
dbg_printf
(
"========= EOI ==========[%d]\n"
, cnt++);
39
}
40
41
asm
volatile
(
42
"mov $0x20, %%al;"
43
"mov $0x20, %%dx;"
44
"outb %%al, %%dx"
45
:
46
:
47
:
"eax"
,
"edx"
48
);
49
50
return
0;
51
}
52
53
int
arch_init
(
void
)
54
{
55
int
ret;
56
57
segment_init
();
58
interrupt_init
();
59
60
ret =
register_irq
(
IRQ_NR_TIMER
,
LOW_PRIORITY
, eoi,
NULL
);
61
if
(ret < 0) {
62
return
ret;
63
}
64
65
ret =
register_irq
(
IRQ_NR_FDC
,
LOW_PRIORITY
, eoi,
NULL
);
66
if
(ret < 0) {
67
unregister_irq
(
IRQ_NR_TIMER
, eoi,
NULL
);
68
return
ret;
69
}
70
71
ret =
register_irq
(
IRQ_NR_KEYBOARD
,
LOW_PRIORITY
, eoi,
NULL
);
72
if
(ret < 0) {
73
unregister_irq
(
IRQ_NR_FDC
, eoi,
NULL
);
74
unregister_irq
(
IRQ_NR_TIMER
, eoi,
NULL
);
75
return
ret;
76
}
77
78
ret =
register_irq
(
IRQ_NR_PAGE_FAULT
,
NORMAL_PRIORITY
,
79
page_fault_handler
,
NULL
);
80
if
(ret < 0) {
81
unregister_irq
(
IRQ_NR_KEYBOARD
, eoi,
NULL
);
82
unregister_irq
(
IRQ_NR_FDC
, eoi,
NULL
);
83
unregister_irq
(
IRQ_NR_TIMER
, eoi,
NULL
);
84
return
ret;
85
}
86
87
ret =
register_irq
(
IRQ_NR_TIMER
,
NORMAL_PRIORITY
,
timer_handler
,
NULL
);
88
if
(ret < 0) {
89
unregister_irq
(
IRQ_NR_PAGE_FAULT
,
page_fault_handler
,
NULL
);
90
unregister_irq
(
IRQ_NR_KEYBOARD
, eoi,
NULL
);
91
unregister_irq
(
IRQ_NR_FDC
, eoi,
NULL
);
92
unregister_irq
(
IRQ_NR_TIMER
, eoi,
NULL
);
93
return
ret;
94
}
95
96
ret =
register_irq
(
IRQ_NR_DIVIDE
,
NORMAL_PRIORITY
,
divide_error_handler
,
NULL
);
97
if
(ret < 0) {
98
unregister_irq
(
IRQ_NR_TIMER
,
timer_handler
,
NULL
);
99
unregister_irq
(
IRQ_NR_PAGE_FAULT
,
page_fault_handler
,
NULL
);
100
unregister_irq
(
IRQ_NR_KEYBOARD
, eoi,
NULL
);
101
unregister_irq
(
IRQ_NR_FDC
, eoi,
NULL
);
102
unregister_irq
(
IRQ_NR_TIMER
, eoi,
NULL
);
103
return
ret;
104
}
105
106
pic_init
();
107
timer_init
(100);
108
109
return
0;
110
}
111
112
void
__attribute__
((noreturn))
panic
(const
char
*fmt, ...)
113
{
114
va_list
ap;
115
116
va_start
(ap, fmt);
117
vprintf
(fmt, ap);
118
va_end
(ap);
119
120
halt
();
121
}
122
123
void
__attribute__
((noreturn))
halt
(
void
)
124
{
125
asm
(
"1: hlt; jmp 1b;"
::);
126
while
(1) {
127
}
128
}
129
130
void
drivers_init
(
void
)
131
{
132
video_init
();
133
serial_init
();
134
fdc_init
();
135
keyboard_init
();
136
}
137
138
/* End of a file */
Generated on Thu Nov 7 2013 02:45:25 for nckernel by
1.8.4