2 * FreeBSD kernel unpacker.
3 * 1993 by Serge Vakulenko
4 * modified for FreeBSD 2.1 by Gary Jennejohn - 12FEB95
8 #include <sys/reboot.h> /* for RB_SERIAL */
10 #include <machine/cpufunc.h> /* for inb/outb */
18 unsigned char bios[0x100];
20 extern int end, edata;
26 void decompress_kernel (void *dest);
28 int memcmp (const void *arg1, const void *arg2, unsigned len)
30 unsigned char *a = (unsigned char*) arg1;
31 unsigned char *b = (unsigned char*) arg2;
33 for (; len-- > 0; ++a, ++b)
41 void *memcpy (void *to, const void *from, unsigned len)
43 char *f = (char*) from;
51 void serial_putchar (unsigned char c)
58 stat = inb (COMCONSOLE+5);
59 } while (!(stat & 0x20));
64 void putchar (unsigned char c)
67 case '\n': curs = (curs + cols) / cols * cols; break;
68 default: videomem[curs++] = 0x0700 | c; break;
70 while (curs >= cols*lines) {
73 memcpy (videomem, videomem+cols, (lines-1) * cols * 2);
74 for (col = 0; col < cols; col++)
75 videomem[(lines - 1) * cols + col] = 0x720;
78 /* set cursor position */
79 outb (port, 0x0e); outb (port+1, curs>>8);
80 outb (port, 0x0f); outb (port+1, curs);
89 serial_putchar (*s++);
99 putstr ("\n\n -- System halted");
100 while (1); /* Halt */
103 void boot (int howto)
108 for (p = &edata; p < &end; ++p)
111 inbuf = (void *)0x20000;
112 outbuf = (void *)0x30000;
113 window = (void *)0x40000;
114 storage = (void *)0x50000;
116 if (!(use_serial = (howto & RB_SERIAL))) {
117 /* Test for monochrome video adapter */
118 if ((*((unsigned char*) 0x410) & 0x30) == 0x30)
119 videomem = (void*) 0xb0000; /* monochrome */
121 videomem = (void*) 0xb8000; /* color */
123 port = *(unsigned short*) 0x463;
124 cols = *(unsigned short*) 0x44a;
125 lines = 1 + *(unsigned char*) 0x484;
126 c = *(unsigned char*) 0x450;
127 l = *(unsigned char*) 0x451;
132 if (curs > lines*cols)
133 curs = (lines-1) * cols;
136 putstr ("Uncompressing kernel...");
137 decompress_kernel ((void*) KADDR);
139 putstr ("Booting the kernel\n");