xref: /plan9-contrib/sys/src/9/loongson/rebootcode.c (revision a81c3ea0c7f009a3088ab7fe55ea9013d9d77a74)
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)	(((uchar*)PHYSCONS)[r])
12 #define csr8o(r, v)	(((uchar*)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 void	go(void*);
24 ulong	_argc;
25 ulong	_env;
26 
27 /*
28  * Copy the new kernel to its correct location in physical memory,
29  * flush caches, ignore TLBs (we're in KSEG0 space), and jump to
30  * the start of the kernel.
31  */
32 void
main(ulong aentry,ulong acode,ulong asize,ulong argc)33 main(ulong aentry, ulong acode, ulong asize, ulong argc)
34 {
35 	void *kernel;
36 	static ulong entry, code, size;
37 
38 	putc('B'); putc('o'); putc('o'); putc('t');
39 	/* copy args to heap before moving stack to before a.out header */
40 	entry = aentry;
41 	code = acode;
42 	size = asize;
43 	_argc = argc;		/* argc passed to kernel */
44 	_env = (ulong)&((char**)CONFARGV)[argc];
45 	setsp(entry-0x20-4);
46 
47 	memmove((void *)entry, (void *)code, size);
48 
49 	cleancache();
50 	coherence();
51 
52 	/*
53 	 * jump to kernel entry point.
54 	 */
55 	putc(' ');
56 	kernel = (void*)entry;
57 	go(kernel);			/* off we go - never to return */
58 
59 	putc('?');
60 	putc('!');
61 	for(;;)
62 		;
63 }
64 
65 void
putc(int c)66 putc(int c)
67 {
68 	int i;
69 
70 	for(i = 0; !(csr8r(Lsr) & Thre) && i < 1000000; i++)
71 		;
72 	csr8o(Thr, (uchar)c);
73 	for(i = 0; !(csr8r(Lsr) & Thre) && i < 1000000; i++)
74 		;
75 }
76 
77 long
syscall(Ureg *)78 syscall(Ureg*)
79 {
80 	return -1;
81 }
82 
83 void
trap(Ureg *)84 trap(Ureg *)
85 {
86 }
87