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