xref: /netbsd-src/sys/arch/x68k/stand/common/execkern.S (revision 8a8f936f250a330d54f8a24ed0e92aadf9743a7b)
1|
2|	execute NetBSD kernel
3|
4|	written by Yasha (ITOH Yasufumi)
5|	public domain
6|
7|	$NetBSD: execkern.S,v 1.2 2001/06/12 16:57:27 minoura Exp $
8
9/* XXX this value is from <machine/exec_aout.h> */
10#define __LDPGSZ	8192
11
12#define MFP		0x00E88000	/* MFP */
13#define MFP_IERA	(MFP+0x07)	/* (B) interrupt enable reg A */
14#define MFP_IERB	(MFP+0x09)	/* (B) interrupt enable reg B */
15#define MFP_RSR		(MFP+0x2B)	/* (B) USART receiver status reg */
16
17#ifndef SRAM_MEMSZ
18#define SRAM		0x00ED0000	/* SRAM start addr */
19#define SRAM_MEMSZ	(SRAM + 8)	/* (L) size of main memory */
20#endif
21
22|	%a3+0	kernel image top address (a.out header is excluded)
23|	%a3+4	load address
24|	%a3+8	text size
25|	%a3+12	data size
26|	%a3+16	bss size
27|	%a3+20	symbol size
28|	%a3+24	(reserved) (%d5)
29|	%a3+28	bootdev (%d6)
30|	%a3+32	boothowto (%d7)
31|	%a3+36	entry address (absolute address)
32
33#ifndef XK_NO_C_INTERFACE
34	.text
35	.even
36ENTRY_NOPROFILE(exec_kernel)
37	addql	#4,%sp
38	moveal	%sp@+,%a3		| struct execkern_arg *
39#endif
40
41	moveal	%a3@+,%a0		| image address
42	moveal	%a3@+,%a1		| load address
43	movel	%a1,%d3
44
45	|
46	| copy image
47	|
48
49	| copy text segment
50	movel	%a3@+,%d0		| text size
51	movel	%d0,%d1
52	jbsr	copy
53
54	| clear gap between text and data
55	negl	%d1
56	andil	#__LDPGSZ-1,%d1
57	movel	%d1,%d0			| gap size between text and data
58	jbsr	clear
59
60	| copy data segment
61	movel	%a3@+,%d0		| data size
62	jbsr	copy
63
64	| clear bss
65	movel	%a3@+,%d0		| bss size
66	jbsr	clear
67
68	| copy symbol table
69	movel	%a3@+,%d0		| symbol table size
70	movel	%d0,%a1@+
71	beqs	Lnotable
72	jbsr	copy
73
74	| copy string table size
75	movel	%a0@+,%d0
76	movel	%d0,%a1@+
77	beqs	Lnotable
78
79	| copy string table
80	subql	#4,%d0			| table size is already copied
81	jbsr	copy
82
83Lnotable:
84
85	| stop MFP interrupts (for compatibility)
86	clrb	MFP_IERA
87	clrb	MFP_IERB
88	clrb	MFP_RSR
89
90	|
91	| execute kernel
92	| start(load_addr, mem_max, kernel_end)
93	|
94	movel	%a1,%d0
95	addql	#3,%d0
96	andib	#0xFC,%d0
97	subl	%d3,%d0
98	movel	%d0,%sp@-		| arg #3 (kernel size)
99	movel	SRAM_MEMSZ,%sp@-	| arg #2 (RAM size from SRAM)
100	movel	%d3,%sp@-		| arg #1 (load address)
101
102#if 0
103	movel	%a3@+,%d5		| (reserved)
104	movel	%a3@+,%d6		| boot device
105	movel	%a3@+,%d7		| boot howto
106
107	movel	%a3@+,%a0		| entry address
108#else	/* optimized */
109	moveml	%a3@+,%d5-%d7/%a0
110#endif
111
112	| clear unused registers
113	moveq	#0,%d0
114	moveq	#0,%d1
115	moveq	#0,%d2
116	moveq	#0,%d3
117	moveq	#0,%d4
118	moveal	%d0,%a1
119	moveal	%d0,%a2
120	moveal	%d0,%a3
121	moveal	%d0,%a4
122	moveal	%d0,%a5
123	moveal	%d0,%a6
124
125	jsr	%a0@			| execute NetBSD kernel
126	| NOTREACHED
127
128	| ??? returned from kernel -- issue software reset
129	subal	%a1,%a1
130	moveml	0x00ff0000,#0x0101	| get RESET vectors (%d0: ssp, %a0: pc)
131	moveml	#0x0101,%a1@		| put them at 0x00000000 (for Xellent)
132	.long	0x4E7B9801		| movec	%a1,%vbr
133	jmp	%a0@			| go to reset address
134
135
136|
137| utility routines
138|
139
140| copy %d0 bytes from higher (%a0) to lower (%a1) address
1411:	moveb	%a0@+,%a1@+
142copy:	subql	#1,%d0
143	bpls	1b
144	rts
145
146| clear %d0 bytes at %a1
147| do nothing if %d0 is zero
1481:	clrb	%a1@+
149clear:	subql	#1,%d0
150	bpls	1b
151	rts
152