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