exec_image.S revision 1.3 1 /* $NetBSD: exec_image.S,v 1.3 2024/01/07 07:58:34 isaki Exp $ */
2
3 /*
4 * Copyright (c) 2001 Minoura Makoto.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <machine/asm.h>
29
30 #ifndef LASTADDR
31 #define LASTADDR (0x00ed0008)
32 #endif
33
34 .text
35 .even
36
37 ENTRY_NOPROFILE(exec_image)
38 || void exec_image(loaded,executed,entry,size,bootdev,boothowto)
39 || unsigned int loaded;
40 || unsigned int executed;
41 || unsigned int entry;
42 || int size;
43 || int bootdev;
44 || int boothowto;
45 addl #4,%sp | throw away the return address
46 moveml %sp@+,%a4-%a6
47 moveml %sp@+,%d5-%d7
48
49 /* copy the trampoline to the last physical page. */
50 moval LASTADDR,%sp | tmpstack from end of physmem
51 lea %sp@(-4096),%a3 | use last phys page as tramp
52
53 movl #(end_trampoline-trampoline),%sp@-
54 pea %pc@(trampoline)
55 pea %a3@
56 jbsr _C_LABEL(memcpy) | memcpy() is still alive
57 lea %sp@(12),%sp
58
59 jmp %a3@ | jump to tramp
60
61 ASENTRY_NOPROFILE(trampoline)
62 || %a4: loaded
63 || %a5: executed
64 || %a6: entry
65 || %d5: size
66 || %d6: bootdev
67 || %d7: boothowto
68 movl %d5,%sp@- | push last arg (esym)
69 movel LASTADDR,%sp@- | second arg (physsize)
70 pea %a5@ | first arg (firstpa)
71
72 cmpl %a4,%a5 | if (l == x)
73 beq L1 | copy not required
74
75 /* this may overwrite the trap vectors; disable interrupt. */
76 oriw #0x2700,%sr
77
78 L0: movb %a4@+,%a5@+ | copy kern to x
79 subql #1,%d5
80 bne L0
81
82 L1:
83 movq #0,%d0 | reg arg (unused)
84 movq #0,%d1 | reg arg (unused)
85 movq #0,%d2 | reg arg (unused)
86 movq #0,%d3 | reg arg (unused)
87 movq #0,%d4 | reg arg (unused)
88 movq #0,%d5 | reg arg (unused)
89 | bootdev(%d6) is already set
90 | boothowto(%d7) is already set
91 moval %a6,%a0 | entry
92 moval %d0,%a1 | reg arg (unused)
93 moval %d0,%a2 | reg arg (unused)
94 moval %d0,%a3 | reg arg (unused)
95 moval %d0,%a4 | reg arg (unused)
96 moval %d0,%a5 | reg arg (unused)
97 moval %d0,%a6 | reg arg (unused)
98 movec %a1,%vbr | clear vbr
99
100 jsr %a0@ | here we go!
101
102 /* NOTREACHED */
103 end_trampoline:
104