xref: /netbsd/sys/arch/i386/stand/lib/startprog.S (revision 6550d01e)
1/*	$NetBSD: startprog.S,v 1.3 2003/02/01 14:48:18 dsl Exp $	*/
2
3/* starts program in protected mode / flat space
4 with given stackframe
5 needs global variables flatcodeseg and flatdataseg
6 (gdt offsets)
7  derived from: NetBSD:sys/arch/i386/boot/asm.S
8 */
9
10/*
11 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
12 *
13 * Mach Operating System
14 * Copyright (c) 1992, 1991 Carnegie Mellon University
15 * All Rights Reserved.
16 *
17 * Permission to use, copy, modify and distribute this software and its
18 * documentation is hereby granted, provided that both the copyright
19 * notice and this permission notice appear in all copies of the
20 * software, derivative works or modified versions, and any portions
21 * thereof, and that both notices appear in supporting documentation.
22 *
23 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
24 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
25 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
26 *
27 * Carnegie Mellon requests users of this software to return to
28 *
29 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
30 *  School of Computer Science
31 *  Carnegie Mellon University
32 *  Pittsburgh PA 15213-3890
33 *
34 * any improvements or extensions that they make and grant Carnegie Mellon
35 * the rights to redistribute these changes.
36 */
37
38/*
39  Copyright 1988, 1989, 1990, 1991, 1992
40   by Intel Corporation, Santa Clara, California.
41
42                All Rights Reserved
43
44Permission to use, copy, modify, and distribute this software and
45its documentation for any purpose and without fee is hereby
46granted, provided that the above copyright notice appears in all
47copies and that both the copyright notice and this permission notice
48appear in supporting documentation, and that the name of Intel
49not be used in advertising or publicity pertaining to distribution
50of the software without specific, written prior permission.
51
52INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
53INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
54IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
55CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
56LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
57NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
58WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
59*/
60
61#include <machine/asm.h>
62
63/*
64 * startprog(phyaddr,argc,argv,stack)
65 *	start the program on protected mode where phyaddr is the entry point
66 */
67ENTRY(startprog)
68	pushl	%ebp
69	movl	%esp, %ebp
70
71	# prepare a new stack
72	movl	$flatdataseg, %ebx
73	movw	%bx, %es		# for arg copy
74	movl	20(%ebp), %eax	# stack
75	subl	$4,%eax
76	movl	%eax, %edi
77
78	# push some number of args onto the stack
79	movl	12(%ebp), %ecx		# argc
80
81	movl	%ecx, %eax
82	decl	%eax
83	shl	$2, %eax
84	addl	16(%ebp), %eax	# ptr to last arg
85	movl	%eax, %esi
86
87	std			# backwards
88	rep
89	movsl
90
91	cld		# LynxOS depends on it
92
93	movl	8(%ebp), %ecx	# entry
94
95	# set new stackptr (movsl decd sp 1 more -> dummy return address)
96	movw	%bx, %ss
97	movl	%edi, %esp
98
99	# push on our entry address
100	movl	$flatcodeseg, %ebx		# segment
101	pushl	%ebx
102	pushl	%ecx			#entry
103
104	# convert over the other data segs
105	movl	$flatdataseg, %ebx
106	mov	%bx, %ds
107	mov	%bx, %es
108
109	# convert the PC (and code seg)
110	lret
111