xref: /plan9/sys/src/9/rb/rebootcode.c (revision f43f8ee646e2cb29aea7fd7bb5fc7318a3f4921f)
1 /*
2  * mips reboot trampoline code
3  */
4 #include	"u.h"
5 #include	"../port/lib.h"
6 #include	"mem.h"
7 #include	"dat.h"
8 #include	"fns.h"
9 #include	"io.h"
10 
11 #define csr8r(r)	(((ulong *)PHYSCONS)[r])
12 #define csr8o(r, v)	(((ulong *)PHYSCONS)[r] = (v))
13 
14 enum {					/* i8250 registers */
15 	Thr		= 0,		/* Transmitter Holding (WO) */
16 	Lsr		= 5,		/* Line Status */
17 };
18 enum {					/* Lsr */
19 	Thre		= 0x20,		/* Thr Empty */
20 };
21 
22 void	putc(int);
23 
24 /*
25  * Copy the new kernel to its correct location in physical memory,
26  * flush caches, ignore TLBs (we're in KSEG0 space), and jump to
27  * the start of the kernel.
28  */
29 void
main(ulong aentry,ulong acode,ulong asize)30 main(ulong aentry, ulong acode, ulong asize)
31 {
32 	void (*kernel)(void);
33 	static ulong entry, code, size;
34 
35 	putc('B'); putc('o'); putc('o'); putc('t');
36 	/* copy args to heap before moving stack to before a.out header */
37 	entry = aentry;
38 	code = acode;
39 	size = asize;
40 	setsp(entry-0x20-4);
41 
42 	memmove((void *)entry, (void *)code, size);
43 
44 	cleancache();
45 	coherence();
46 
47 	/*
48 	 * jump to kernel entry point.
49 	 */
50 	putc(' ');
51 	kernel = (void*)entry;
52 	(*kernel)();			/* off we go - never to return */
53 
54 	putc('?');
55 	putc('!');
56 	for(;;)
57 		;
58 }
59 
60 void
putc(int c)61 putc(int c)
62 {
63 	int i;
64 
65 	for(i = 0; !(csr8r(Lsr) & Thre) && i < 1000000; i++)
66 		;
67 	csr8o(Thr, (uchar)c);
68 	for(i = 0; !(csr8r(Lsr) & Thre) && i < 1000000; i++)
69 		;
70 }
71 
72 long
syscall(Ureg *)73 syscall(Ureg*)
74 {
75 	return -1;
76 }
77 
78 void
trap(Ureg *)79 trap(Ureg *)
80 {
81 }
82