-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.h
More file actions
149 lines (135 loc) · 2.83 KB
/
system.h
File metadata and controls
149 lines (135 loc) · 2.83 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef _SYSTEM_H_
#define _SYSTEM_H_
#include "mybool.h"
/* play_sound: plays sound at frequency freq */
static void
play_sound (unsigned short freq)
{
__asm__ __volatile__ ("mov $0xB6, %%al;"
"out %%al, $0x43;"
"mov %0, %%ax;"
"out %%al, $0x42;" /* output low byte */
"mov %%ah, %%al;" /* move high byte to low */
"out %%al, $0x42;" /* output high byte */
"in $0x61, %%al;" /* turn on note */
"or $0x03, %%al;"
"out %%al, $0x61;"
:
: "r"(freq)
);
}
/* stop_sound: stops pc buzzer; internal pc speaker */
static void
stop_sound (void)
{
__asm__ __volatile__ ("in $0x61, %al;and $0xFC, %al;out %al, $0x61;");
}
/* is_timer_active: checks if a timer is already active; returns bool */
static bool_t
is_timer_active (void)
{
bool_t ret = true;
__asm__ goto ("int $0x15; jc %l1"
:
: "a"(0x8600)
:
: carry_set
);
quit:
return ret;
carry_set:
__asm__ ("clc");
ret = false;
goto quit;
}
/* async_timer: creates a timer that does not halt code execution */
static bool_t
async_timer (short hbits, short lbits)
{
bool_t ret = true;
__asm__ goto ("int $0x15; jc %l3"
:
: "a"(0x8300), "c"(hbits), "d"(lbits)
:
: carry_set
);
quit:
return ret;
carry_set:
__asm__ ("clc");
ret = false;
goto quit;
}
/* timer: creates a timer; halts program execution until time expires */
static bool_t
timer (short hbits, short lbits)
{
bool_t ret = true;
__asm__ goto ("int $0x15; jc %l3"
:
: "a"(0x8600), "c"(hbits), "d"(lbits)
:
: carry_set
);
quit:
return ret;
carry_set:
__asm__ ("clc");
ret = false;
goto quit;
}
/* reboot: warm reboot; restarts the computer */
static void reboot(void);
#define reboot() __asm__ __volatile__ ("ljmpw $0xFFFF, $0x0000")
/* inb: get __port value */
static unsigned char
inb (unsigned short int __port)
{
unsigned char _v;
__asm__ __volatile__ ("inb %1,%0":"=a" (_v):"Nd" (__port));
return _v;
}
/* outb: output __value to __port */
static void
outb (unsigned char __value, unsigned short int __port)
{
__asm__ __volatile__ ("outb %0,%1"::"a" (__value), "Nd" (__port));
}
/* read_cmos: read __index of CMOS memory; returns byte */
static unsigned char
read_cmos (unsigned char __index)
{
unsigned char _byte;
__asm__ ("cli");
outb (__index, 0x70);
_byte = inb (__index);
__asm__ ("sti");
return _byte;
}
/* clear_cmos: wipe cmos; resetting back to factory */
static void
clear_cmos (void)
{
outb(0x2e, 0x70); /* write to port 0x70 */
timer(0x002a, 0x4080);
outb(0xff, 0x71);
}
/* init_graphics: clear screen and set graphics mode */
static void
init_graphics (unsigned short int __mode)
{
__asm__ __volatile__("int $0x10"::"a"(0x0000 | __mode));
}
/* boot_startup: initalize stack */
static void
boot_startup (void)
{
__asm__ __volatile__ (
"xor %ax,%ax;"
"mov %ax,%ds;"
"mov %ax,%es;"
"mov %ax,%fs;"
"mov $0x8000,%esp;"
);
}
#endif