Home | History | Annotate | Line # | Download | only in lib
multiboot.S revision 1.1.10.2
      1  1.1.10.2  mjf /*	$NetBSD: multiboot.S,v 1.1.10.2 2009/01/17 13:28:05 mjf Exp $	*/
      2  1.1.10.2  mjf 
      3  1.1.10.2  mjf /* starts program in protected mode / flat space
      4  1.1.10.2  mjf  with given stackframe
      5  1.1.10.2  mjf  needs global variables flatcodeseg and flatdataseg
      6  1.1.10.2  mjf  (gdt offsets)
      7  1.1.10.2  mjf   derived from: NetBSD:sys/arch/i386/stand/lib/startprog.S
      8  1.1.10.2  mjf  */
      9  1.1.10.2  mjf 
     10  1.1.10.2  mjf /*-
     11  1.1.10.2  mjf  * Copyright (c) 2008 The NetBSD Foundation, Inc.
     12  1.1.10.2  mjf  * All rights reserved.
     13  1.1.10.2  mjf  *
     14  1.1.10.2  mjf  * Redistribution and use in source and binary forms, with or without
     15  1.1.10.2  mjf  * modification, are permitted provided that the following conditions
     16  1.1.10.2  mjf  * are met:
     17  1.1.10.2  mjf  * 1. Redistributions of source code must retain the above copyright
     18  1.1.10.2  mjf  *    notice, this list of conditions and the following disclaimer.
     19  1.1.10.2  mjf  * 2. Redistributions in binary form must reproduce the above copyright
     20  1.1.10.2  mjf  *    notice, this list of conditions and the following disclaimer in the
     21  1.1.10.2  mjf  *    documentation and/or other materials provided with the distribution.
     22  1.1.10.2  mjf  *
     23  1.1.10.2  mjf  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.1.10.2  mjf  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.1.10.2  mjf  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.1.10.2  mjf  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.1.10.2  mjf  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.1.10.2  mjf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.1.10.2  mjf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1.10.2  mjf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.1.10.2  mjf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.1.10.2  mjf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.1.10.2  mjf  * POSSIBILITY OF SUCH DAMAGE.
     34  1.1.10.2  mjf  */
     35  1.1.10.2  mjf 
     36  1.1.10.2  mjf /*
     37  1.1.10.2  mjf  * Ported to boot 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     38  1.1.10.2  mjf  *
     39  1.1.10.2  mjf  * Mach Operating System
     40  1.1.10.2  mjf  * Copyright (c) 1992, 1991 Carnegie Mellon University
     41  1.1.10.2  mjf  * All Rights Reserved.
     42  1.1.10.2  mjf  *
     43  1.1.10.2  mjf  * Permission to use, copy, modify and distribute this software and its
     44  1.1.10.2  mjf  * documentation is hereby granted, provided that both the copyright
     45  1.1.10.2  mjf  * notice and this permission notice appear in all copies of the
     46  1.1.10.2  mjf  * software, derivative works or modified versions, and any portions
     47  1.1.10.2  mjf  * thereof, and that both notices appear in supporting documentation.
     48  1.1.10.2  mjf  *
     49  1.1.10.2  mjf  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     50  1.1.10.2  mjf  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     51  1.1.10.2  mjf  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     52  1.1.10.2  mjf  *
     53  1.1.10.2  mjf  * Carnegie Mellon requests users of this software to return to
     54  1.1.10.2  mjf  *
     55  1.1.10.2  mjf  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     56  1.1.10.2  mjf  *  School of Computer Science
     57  1.1.10.2  mjf  *  Carnegie Mellon University
     58  1.1.10.2  mjf  *  Pittsburgh PA 15213-3890
     59  1.1.10.2  mjf  *
     60  1.1.10.2  mjf  * any improvements or extensions that they make and grant Carnegie Mellon
     61  1.1.10.2  mjf  * the rights to redistribute these changes.
     62  1.1.10.2  mjf  */
     63  1.1.10.2  mjf 
     64  1.1.10.2  mjf /*
     65  1.1.10.2  mjf   Copyright 1988, 1989, 1990, 1991, 1992
     66  1.1.10.2  mjf    by Intel Corporation, Santa Clara, California.
     67  1.1.10.2  mjf 
     68  1.1.10.2  mjf                 All Rights Reserved
     69  1.1.10.2  mjf 
     70  1.1.10.2  mjf Permission to use, copy, modify, and distribute this software and
     71  1.1.10.2  mjf its documentation for any purpose and without fee is hereby
     72  1.1.10.2  mjf granted, provided that the above copyright notice appears in all
     73  1.1.10.2  mjf copies and that both the copyright notice and this permission notice
     74  1.1.10.2  mjf appear in supporting documentation, and that the name of Intel
     75  1.1.10.2  mjf not be used in advertising or publicity pertaining to distribution
     76  1.1.10.2  mjf of the software without specific, written prior permission.
     77  1.1.10.2  mjf 
     78  1.1.10.2  mjf INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
     79  1.1.10.2  mjf INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
     80  1.1.10.2  mjf IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
     81  1.1.10.2  mjf CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
     82  1.1.10.2  mjf LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
     83  1.1.10.2  mjf NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     84  1.1.10.2  mjf WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     85  1.1.10.2  mjf */
     86  1.1.10.2  mjf 
     87  1.1.10.2  mjf #include <machine/asm.h>
     88  1.1.10.2  mjf #define MULTIBOOT_INFO_MAGIC		0x2BADB002
     89  1.1.10.2  mjf 
     90  1.1.10.2  mjf /*
     91  1.1.10.2  mjf  * multiboot(phyaddr,header,stack)
     92  1.1.10.2  mjf  *	start the program on protected mode where phyaddr is the entry point
     93  1.1.10.2  mjf  */
     94  1.1.10.2  mjf ENTRY(multiboot)
     95  1.1.10.2  mjf 	pushl	%ebp
     96  1.1.10.2  mjf 	movl	%esp, %ebp
     97  1.1.10.2  mjf 
     98  1.1.10.2  mjf 	# prepare a new stack
     99  1.1.10.2  mjf 	movl	$flatdataseg, %eax
    100  1.1.10.2  mjf 	movw	%ax, %es		# for arg copy
    101  1.1.10.2  mjf 	movl	16(%ebp), %ebx	# stack
    102  1.1.10.2  mjf 	subl	$4,%ebx
    103  1.1.10.2  mjf 	movl	%ebx, %edi
    104  1.1.10.2  mjf 
    105  1.1.10.2  mjf 	movl	12(%ebp), %ebx	# header
    106  1.1.10.2  mjf 	movl	8(%ebp), %ecx	# entry
    107  1.1.10.2  mjf 
    108  1.1.10.2  mjf 	# set new stackptr (movsl decd sp 1 more -> dummy return address)
    109  1.1.10.2  mjf 	movw	%ax, %ss
    110  1.1.10.2  mjf 	movl	%edi, %esp
    111  1.1.10.2  mjf 
    112  1.1.10.2  mjf 	# push on our entry address
    113  1.1.10.2  mjf 	movl	$flatcodeseg, %eax		# segment
    114  1.1.10.2  mjf 	pushl	%eax
    115  1.1.10.2  mjf 	pushl	%ecx			#entry
    116  1.1.10.2  mjf 
    117  1.1.10.2  mjf 	# convert over the other data segs
    118  1.1.10.2  mjf 	movl	$flatdataseg, %eax
    119  1.1.10.2  mjf 	mov	%ax, %ds
    120  1.1.10.2  mjf 	mov	%ax, %es
    121  1.1.10.2  mjf 
    122  1.1.10.2  mjf 	movl	$MULTIBOOT_INFO_MAGIC, %eax
    123  1.1.10.2  mjf 	# convert the PC (and code seg)
    124  1.1.10.2  mjf 	lret
    125