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