-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardware.c
114 lines (102 loc) · 2.03 KB
/
hardware.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* hardware.c
*/
#include <types.h>
extern unsigned int *p_rdtr;
DWord get_eflags(void)
{
register DWord flags;
__asm__ __volatile__(
"pushfl\n\t"
"popl %0"
: "=q"(flags));
return flags;
}
void set_eflags(void)
{
__asm__ __volatile__(
"pushl $0\n\t"
"popfl");
}
void set_idt_reg(Register *idt)
{
__asm__ __volatile__(
"lidtl (%0)"
: /*no output*/
: "r"(idt));
}
void set_gdt_reg(Register *gdt)
{
__asm__ __volatile__(
"lgdtl (%0)"
: /*no output*/
: "r"(gdt));
}
void set_ldt_reg(Selector ldt)
{
__asm__ __volatile__(
"lldtw %0"
: /*no output*/
: "r"(ldt));
}
void set_task_reg(Selector tr)
{
__asm__ __volatile__(
"ltrw %0"
: /*no output*/
: "r"(tr));
}
void return_gate(Word ds, Word ss, DWord esp, Word cs, DWord eip)
{
__asm__ __volatile__(
"mov %0,%%es\n\t"
"mov %0,%%ds\n\t"
"movl %2, %%eax\n\t"
"addl $12, %%eax\n\t"
"movl %5,(%%eax)\n\t"
"pushl %1\n\t" /* user ss */
"pushl %2\n\t" /* user esp */
"pushl %3\n\t" /* user cs */
"pushl %4\n\t" /* user eip */
"lret"
: /*no output*/
: "m"(ds), "m"(ss), "m"(esp), "m"(cs), "m"(eip), "d"(*p_rdtr));
}
/*
* enable_int: Set interruput mask
*
* register 0x21:
* 7 6 5 4 3 2 1 0
* x x x x x x x x
*
* bit 0 : Timer
* bit 1 : Keyboard
* bit 2 : PIC cascading
* bit 3 : 2nd Serial Port
* bit 4 : 1st Serial Port
* bit 5 : Reserved
* bit 6 : Floppy disk
* bit 7 : Reserved
*
*
* x = 0 -> enabled
* x = 1 -> disabled
*/
void enable_int(void)
{
__asm__ __volatile__(
"movb %0,%%al\n\t"
"outb %%al,$0x21\n\t"
"call delay\n\t"
"sti"
: /*no output*/
: "i"(0xfc) /* 0xFF = 11111111 -> all bits disabled */
: "%al");
}
void delay(void)
{
__asm__ __volatile__(
"jmp a\na:\t"
:
:);
}