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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/*
* FreeBSD kernel unpacker.
* 1993 by Serge Vakulenko
* modified for FreeBSD 2.1 by Gary Jennejohn - 12FEB95
*/
/*
* FreeBSD(98) port
* 1995 by KATO T. of Nagoya University
*/
#include <machine/cpufunc.h> /* for inb/outb */
#include <sys/reboot.h> /* for RB_SERIAL */
short *videomem;
int curs;
int cols;
int lines;
unsigned int port;
#ifdef PC98
unsigned char bios[0x200];
#else
unsigned char bios[0x100];
#endif
extern int end, edata;
void *storage;
void *inbuf;
void *outbuf;
void *window;
void decompress_kernel (void *dest);
int memcmp (const void *arg1, const void *arg2, unsigned len)
{
unsigned char *a = (unsigned char*) arg1;
unsigned char *b = (unsigned char*) arg2;
for (; len-- > 0; ++a, ++b)
if (*a < *b)
return (-1);
else if (*a > *b)
return (1);
return (0);
}
void *memcpy (void *to, const void *from, unsigned len)
{
char *f = (char*) from;
char *t = (char*) to;
while (len-- > 0)
*t++ = *f++;
return (to);
}
void serial_putchar (unsigned char c)
{
unsigned char stat;
if (c == '\n')
serial_putchar('\r');
#ifdef PC98
do {
stat = inb (COMCONSOLE+2);
} while (!(stat & 0x01));
#else
do {
stat = inb (COMCONSOLE+5);
} while (!(stat & 0x20));
#endif
outb (COMCONSOLE, c);
}
void putchar (unsigned char c)
{
switch (c) {
case '\n': curs = (curs + cols) / cols * cols; break;
#ifdef PC98
default: videomem[curs++] = (c == 0x5c ? 0xfc : c); break;
#else
default: videomem[curs++] = 0x0700 | c; break;
#endif
}
while (curs >= cols*lines) {
int col;
memcpy (videomem, videomem+cols, (lines-1) * cols * 2);
for (col = 0; col < cols; col++)
#ifdef PC98
videomem[(lines - 1) * cols + col] = 0x20;
#else
videomem[(lines - 1) * cols + col] = 0x720;
#endif
curs -= cols;
}
/* set cursor position */
#ifdef PC98
while ((inb(0x60) & 0x04) == 0) {}
outb(0x62, 0x49);
outb(0x60, (curs + 1) & 0xff);
outb(0x60, (curs + 1) >> 8);
#else
outb (port, 0x0e); outb (port+1, curs>>8);
outb (port, 0x0f); outb (port+1, curs);
#endif
}
int use_serial;
void putstr (char *s)
{
while (*s) {
if (use_serial)
serial_putchar (*s++);
else
putchar (*s++);
}
}
void error (char *s)
{
putstr ("\n\n");
putstr (s);
putstr ("\n\n -- System halted");
while (1); /* Halt */
}
void boot (int howto)
{
int l, c, *p;
#ifdef PC98
unsigned short gdc_curaddr;
int i;
#endif
/* clear bss */
for (p = &edata; p < &end; ++p)
*p = 0;
inbuf = (void *)0x20000;
outbuf = (void *)0x30000;
window = (void *)0x40000;
storage = (void *)0x50000;
if (!(use_serial = (howto & RB_SERIAL))) {
#ifdef PC98
videomem = (void*)0xa0000;
cols = 80;
lines = 25;
/* Is FIFO buffer empty ? */
while ((inb(0x60) & 0x04) == 0) {}
outb(0x62, 0xe0); /* CSRR command */
/* T-GDC busy ? */
while ((inb(0x60) & 0x01) == 0) {}
/* read cursor address */
gdc_curaddr = inb(0x62);
gdc_curaddr = (inb(0x62) << 8);
/* ignore rest of data */
for (i = 0; i < 3; i++) {
(void)inb(0x62);
}
l = gdc_curaddr / 80 + 1;
c = 0;
#else
/* Test for monochrome video adapter */
if ((*((unsigned char*) 0x410) & 0x30) == 0x30)
videomem = (void*) 0xb0000; /* monochrome */
else
videomem = (void*) 0xb8000; /* color */
port = *(unsigned short*) 0x463;
cols = *(unsigned short*) 0x44a;
lines = 1 + *(unsigned char*) 0x484;
c = *(unsigned char*) 0x450;
l = *(unsigned char*) 0x451;
#endif
if (lines < 25)
lines = 25;
curs = l*cols + c;
if (curs > lines*cols)
curs = (lines-1) * cols;
}
putstr ("Uncompressing kernel...");
decompress_kernel ((void*) KADDR);
putstr ("done\n");
putstr ("Booting the kernel\n");
}
|