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