startprog.S revision 1.3.172.1 1 1.3.172.1 skrll /* $NetBSD: startprog.S,v 1.3.172.1 2016/12/05 10:54:53 skrll 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.172.1 skrll * Copyright 1988, 1989, 1990, 1991, 1992
33 1.3.172.1 skrll * by Intel Corporation, Santa Clara, California.
34 1.3.172.1 skrll *
35 1.3.172.1 skrll * All Rights Reserved
36 1.3.172.1 skrll *
37 1.3.172.1 skrll * Permission to use, copy, modify, and distribute this software and
38 1.3.172.1 skrll * its documentation for any purpose and without fee is hereby
39 1.3.172.1 skrll * granted, provided that the above copyright notice appears in all
40 1.3.172.1 skrll * copies and that both the copyright notice and this permission notice
41 1.3.172.1 skrll * appear in supporting documentation, and that the name of Intel
42 1.3.172.1 skrll * not be used in advertising or publicity pertaining to distribution
43 1.3.172.1 skrll * of the software without specific, written prior permission.
44 1.3.172.1 skrll *
45 1.3.172.1 skrll * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 1.3.172.1 skrll * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 1.3.172.1 skrll * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 1.3.172.1 skrll * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 1.3.172.1 skrll * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 1.3.172.1 skrll * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 1.3.172.1 skrll * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 1.3.172.1 skrll */
53 1.1 perry
54 1.1 perry #include <machine/asm.h>
55 1.1 perry
56 1.1 perry /*
57 1.3.172.1 skrll * Starts program in protected mode / flat space with given stackframe.
58 1.3.172.1 skrll * Needs global variables flatcodeseg and flatdataseg (gdt offsets).
59 1.3.172.1 skrll */
60 1.3.172.1 skrll
61 1.3.172.1 skrll /*
62 1.3.172.1 skrll * 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.172.1 skrll movl %esp,%ebp
68 1.1 perry
69 1.3.172.1 skrll /* Prepare a new stack */
70 1.3.172.1 skrll movl $flatdataseg,%ebx
71 1.3.172.1 skrll movw %bx,%es /* for arg copy */
72 1.3.172.1 skrll movl 20(%ebp),%eax /* stack */
73 1.1 perry subl $4,%eax
74 1.3.172.1 skrll movl %eax,%edi
75 1.1 perry
76 1.3.172.1 skrll /* Push some number of args onto the stack */
77 1.3.172.1 skrll movl 12(%ebp),%ecx /* argc */
78 1.3.172.1 skrll movl %ecx,%eax
79 1.1 perry decl %eax
80 1.3.172.1 skrll shl $2,%eax
81 1.3.172.1 skrll addl 16(%ebp),%eax /* ptr to last arg */
82 1.3.172.1 skrll movl %eax,%esi
83 1.1 perry
84 1.3.172.1 skrll std /* backwards */
85 1.1 perry rep
86 1.3.172.1 skrll movsl /* copy %ds:(%esi) -> %es:(%edi) */
87 1.1 perry
88 1.3.172.1 skrll cld
89 1.1 perry
90 1.3.172.1 skrll movl 8(%ebp),%ecx /* entry */
91 1.1 perry
92 1.3.172.1 skrll /* Set new stack pointer (movsl decd sp 1 more -> dummy return address) */
93 1.3.172.1 skrll movw %bx,%ss
94 1.3.172.1 skrll movl %edi,%esp
95 1.1 perry
96 1.3.172.1 skrll /* Push on our entry address */
97 1.3.172.1 skrll movl $flatcodeseg,%ebx
98 1.3.172.1 skrll pushl %ebx /* code segment */
99 1.3.172.1 skrll pushl %ecx /* phyaddr */
100 1.1 perry
101 1.3.172.1 skrll /* Convert over the other data segs */
102 1.3.172.1 skrll movl $flatdataseg,%ebx
103 1.3.172.1 skrll mov %bx,%ds
104 1.3.172.1 skrll mov %bx,%es
105 1.1 perry
106 1.3.172.1 skrll /* Jump to phyaddr, with the new code segment */
107 1.1 perry lret
108 1.3.172.1 skrll
109