1*eea9b1edSmaxv/* $NetBSD: startprog.S,v 1.4 2016/12/04 08:21:08 maxv Exp $ */ 2816bb961Sperry 3816bb961Sperry/* 4816bb961Sperry * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 5816bb961Sperry * 6816bb961Sperry * Mach Operating System 7816bb961Sperry * Copyright (c) 1992, 1991 Carnegie Mellon University 8816bb961Sperry * All Rights Reserved. 9816bb961Sperry * 10816bb961Sperry * Permission to use, copy, modify and distribute this software and its 11816bb961Sperry * documentation is hereby granted, provided that both the copyright 12816bb961Sperry * notice and this permission notice appear in all copies of the 13816bb961Sperry * software, derivative works or modified versions, and any portions 14816bb961Sperry * thereof, and that both notices appear in supporting documentation. 15816bb961Sperry * 16816bb961Sperry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17816bb961Sperry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 18816bb961Sperry * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19816bb961Sperry * 20816bb961Sperry * Carnegie Mellon requests users of this software to return to 21816bb961Sperry * 22816bb961Sperry * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23816bb961Sperry * School of Computer Science 24816bb961Sperry * Carnegie Mellon University 25816bb961Sperry * Pittsburgh PA 15213-3890 26816bb961Sperry * 27816bb961Sperry * any improvements or extensions that they make and grant Carnegie Mellon 28816bb961Sperry * the rights to redistribute these changes. 29816bb961Sperry */ 30816bb961Sperry 31816bb961Sperry/* 32*eea9b1edSmaxv * Copyright 1988, 1989, 1990, 1991, 1992 33*eea9b1edSmaxv * by Intel Corporation, Santa Clara, California. 34*eea9b1edSmaxv * 35*eea9b1edSmaxv * All Rights Reserved 36*eea9b1edSmaxv * 37*eea9b1edSmaxv * Permission to use, copy, modify, and distribute this software and 38*eea9b1edSmaxv * its documentation for any purpose and without fee is hereby 39*eea9b1edSmaxv * granted, provided that the above copyright notice appears in all 40*eea9b1edSmaxv * copies and that both the copyright notice and this permission notice 41*eea9b1edSmaxv * appear in supporting documentation, and that the name of Intel 42*eea9b1edSmaxv * not be used in advertising or publicity pertaining to distribution 43*eea9b1edSmaxv * of the software without specific, written prior permission. 44*eea9b1edSmaxv * 45*eea9b1edSmaxv * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 46*eea9b1edSmaxv * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 47*eea9b1edSmaxv * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 48*eea9b1edSmaxv * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 49*eea9b1edSmaxv * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 50*eea9b1edSmaxv * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 51*eea9b1edSmaxv * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 52816bb961Sperry */ 53816bb961Sperry 54816bb961Sperry#include <machine/asm.h> 55816bb961Sperry 56816bb961Sperry/* 57*eea9b1edSmaxv * Starts program in protected mode / flat space with given stackframe. 58*eea9b1edSmaxv * Needs global variables flatcodeseg and flatdataseg (gdt offsets). 59*eea9b1edSmaxv */ 60*eea9b1edSmaxv 61*eea9b1edSmaxv/* 62816bb961Sperry * startprog(phyaddr, argc, argv, stack) 63816bb961Sperry * start the program on protected mode where phyaddr is the entry point 64816bb961Sperry */ 65816bb961SperryENTRY(startprog) 66816bb961Sperry pushl %ebp 67816bb961Sperry movl %esp,%ebp 68816bb961Sperry 69*eea9b1edSmaxv /* Prepare a new stack */ 70816bb961Sperry movl $flatdataseg,%ebx 71*eea9b1edSmaxv movw %bx,%es /* for arg copy */ 72*eea9b1edSmaxv movl 20(%ebp),%eax /* stack */ 73816bb961Sperry subl $4,%eax 74816bb961Sperry movl %eax,%edi 75816bb961Sperry 76*eea9b1edSmaxv /* Push some number of args onto the stack */ 77*eea9b1edSmaxv movl 12(%ebp),%ecx /* argc */ 78816bb961Sperry movl %ecx,%eax 79816bb961Sperry decl %eax 80816bb961Sperry shl $2,%eax 81*eea9b1edSmaxv addl 16(%ebp),%eax /* ptr to last arg */ 82816bb961Sperry movl %eax,%esi 83816bb961Sperry 84*eea9b1edSmaxv std /* backwards */ 85816bb961Sperry rep 86*eea9b1edSmaxv movsl /* copy %ds:(%esi) -> %es:(%edi) */ 87816bb961Sperry 88*eea9b1edSmaxv cld 89816bb961Sperry 90*eea9b1edSmaxv movl 8(%ebp),%ecx /* entry */ 91816bb961Sperry 92*eea9b1edSmaxv /* Set new stack pointer (movsl decd sp 1 more -> dummy return address) */ 93816bb961Sperry movw %bx,%ss 94816bb961Sperry movl %edi,%esp 95816bb961Sperry 96*eea9b1edSmaxv /* Push on our entry address */ 97*eea9b1edSmaxv movl $flatcodeseg,%ebx 98*eea9b1edSmaxv pushl %ebx /* code segment */ 99*eea9b1edSmaxv pushl %ecx /* phyaddr */ 100816bb961Sperry 101*eea9b1edSmaxv /* Convert over the other data segs */ 102816bb961Sperry movl $flatdataseg,%ebx 10381acacd7Sdsl mov %bx,%ds 10481acacd7Sdsl mov %bx,%es 105816bb961Sperry 106*eea9b1edSmaxv /* Jump to phyaddr, with the new code segment */ 107816bb961Sperry lret 108*eea9b1edSmaxv 109