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