1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/* $NetBSD: asm.s,v 1.3 1994/10/27 04:21:05 cgd Exp $ */
/*
* source in this file came from
* the 386BSD boot blocks written by Julian Elischer.
*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
*
* Mach Operating System
* Copyright (c) 1992, 1991 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
Copyright 1988, 1989, 1990, 1991, 1992
by Intel Corporation, Santa Clara, California.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appears in all
copies and that both the copyright notice and this permission notice
appear in supporting documentation, and that the name of Intel
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.
INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.file "asm.s"
#include "asm.h"
.text
ENTRY(StartProg)
/* void StartProg(u_long phyaddr, u_long *args)
* start the program in protected mode. phyaddr is the entry point.
*/
#ifndef USE_BUFFER
push %ebp
mov %esp, %ebp
# get things we need into registers
movl 0x8(%ebp), %ecx # entry offset
movl 0x0c(%ebp), %eax # &argv
# make a new stack at 0:0xa0000 (big segs)
mov $KERN_DATA_SEG, %ebx
movw %bx, %ss
movl $0xa0000,%ebx
movl %ebx,%esp
# push some number of args onto the stack
pushl $0 # nominally a cyl offset in the boot.
pushl 0x8(%eax) # argv[2] = bootdev
pushl 0x4(%eax) # argv[1] = howto
pushl $0 # dummy 'return' address
# push on our entry address
mov $KERN_CODE_SEG, %ebx # segment
pushl %ebx
pushl %ecx
# convert over the other data segs
mov $KERN_DATA_SEG, %ebx
movw %bx, %ds
movw %bx, %es
# convert the PC (and code seg)
lret
#else
/* test version - relocating, kernel move (TBD) */
/* if necessary, move ourself out of the way
* move the copy of the kernel to its correct load point
* set up a stack and transfer args to it
* call the entry point
* this is best done in assembly as the potential relocation will
* have a bad effect on non-PIC code.
*/
/* get things we need into registers */
movl 0x8(%ebp), %ecx # entry offset
movl 0x0c(%ebp), %eax # &argv
/* relocate ourselves to <tmp_reloc_org> */
# PhysBcopy(RELOC, tmp_reloc_org, WORK_AREA_SIZE);
mov $RELOC, %esi
mov $tmp_reloc_org, %edi
mov $WORK_AREA_SIZE, %ecx
mov %ds, %ax
mov %ax, %es
rep
movsb
/* TBD - could probably also do this by munging a seg descriptor.
* would it be easier?
*/
ljmp $KERN_CODE_SEG, tmp_reloc_org+$1f
1:
/* now we are PIC - caveats */
/* move the stack pointer to the new copy */
add tmp_reloc_org-xxx, %esp
/* push some number of args onto the stack */
pushl $0 # nominally a cyl offset in the boot.
pushl 0x8(%eax) # argv[2] = bootdev
pushl 0x4(%eax) # argv[1] = howto
pushl $0 # dummy 'return' address
/* push on our entry address */
mov $0x08, %ebx # segment
pushl %ebx
pushl %ecx
/* copy loaded file to its destination (TBD) */
# PhysBcopy(kcopy, korg, ksize);
mov kern_copy_org, %esi
mov boot_area_org, %edi
mov xxxksize, %ecx
mov %ds, %ax
mov %ax, %es
rep
movsb
/* convert the PC (and code seg) */
lret
#endif
/*
* C library -- _setjmp, _longjmp
*
* longjmp(a,v)
* will generate a "return(v)" from the last call to
* setjmp(a)
* by restoring registers from the stack.
* The previous signal state is restored.
*/
ENTRY(setjmp)
movl 4(%esp),%ecx
movl 0(%esp),%edx
movl %edx, 0(%ecx)
movl %ebx, 4(%ecx)
movl %esp, 8(%ecx)
movl %ebp,12(%ecx)
movl %esi,16(%ecx)
movl %edi,20(%ecx)
movl %eax,24(%ecx)
movl $0,%eax
ret
ENTRY(longjmp)
movl 4(%esp),%edx
movl 8(%esp),%eax
movl 0(%edx),%ecx
movl 4(%edx),%ebx
movl 8(%edx),%esp
movl 12(%edx),%ebp
movl 16(%edx),%esi
movl 20(%edx),%edi
cmpl $0,%eax
jne 1f
movl $1,%eax
1: movl %ecx,0(%esp)
ret
|