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