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