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