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