start_pxe.S revision 1.2
11.2Sdsl/*	$NetBSD: start_pxe.S,v 1.2 2003/10/09 10:36:26 dsl Exp $	*/
21.1Sdsl
31.1Sdsl/*
41.1Sdsl * Copyright 2001 Wasabi Systems, Inc.
51.1Sdsl * All rights reserved.
61.1Sdsl *
71.1Sdsl * Written by Jason R. Thorpe for Wasabi Systems, Inc.
81.1Sdsl *
91.1Sdsl * Redistribution and use in source and binary forms, with or without
101.1Sdsl * modification, are permitted provided that the following conditions
111.1Sdsl * are met:
121.1Sdsl * 1. Redistributions of source code must retain the above copyright
131.1Sdsl *    notice, this list of conditions and the following disclaimer.
141.1Sdsl * 2. Redistributions in binary form must reproduce the above copyright
151.1Sdsl *    notice, this list of conditions and the following disclaimer in the
161.1Sdsl *    documentation and/or other materials provided with the distribution.
171.1Sdsl * 3. All advertising materials mentioning features or use of this software
181.1Sdsl *    must display the following acknowledgement:
191.1Sdsl *	This product includes software developed for the NetBSD Project by
201.1Sdsl *	Wasabi Systems, Inc.
211.1Sdsl * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Sdsl *    or promote products derived from this software without specific prior
231.1Sdsl *    written permission.
241.1Sdsl *
251.1Sdsl * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Sdsl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Sdsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Sdsl * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Sdsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Sdsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Sdsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Sdsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Sdsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Sdsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Sdsl * POSSIBILITY OF SUCH DAMAGE.
361.1Sdsl */
371.1Sdsl
381.1Sdsl/*
391.1Sdsl * PXE startup
401.1Sdsl * parts from sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S
411.1Sdsl *
421.1Sdsl * See PXE SPEC 4.4.5 (pdf page 88)
431.1Sdsl */
441.1Sdsl
451.1Sdsl#include <machine/asm.h>
461.2Sdsl#include <sys/bootblock.h>
471.1Sdsl
481.1Sdsl	.text
491.1SdslENTRY(start)
501.1Sdsl	.code16
511.2Sdsl	/* Boot parameter area in same format as boot and bootxx */
521.2Sdsl	jmp	1f
531.2Sdsl	.balign 4
541.2Sdsl	.long	X86_BOOT_MAGIC_PXE
551.2Sdslbootparams:
561.2Sdsl	.long	1f - bootparams
571.2Sdsl#include <boot_params.S>
581.2Sdsl	.space	4 * 4			/* some spare */
591.2Sdsl1:
601.1Sdsl	# start is loaded at 0x0:0x7c00 but we want 0x7c0:0x0
611.1Sdsl	# ljmp to the next instruction to adjust %cs
621.2Sdsl	ljmp	$0x7c0, $2f
631.2Sdsl2:
641.1Sdsl	# set up %ds
651.1Sdsl	xorl	%eax, %eax
661.1Sdsl	mov	%cs, %ax
671.1Sdsl	mov	%ax, %ds
681.1Sdsl
691.1Sdsl	# set up %ss and %esp
701.1Sdsl	mov	%ax, %ss
711.1Sdsl	movl	$0xfffc, %esp		/* stack at top of 64k segment */
721.1Sdsl
731.2Sdsl	call	gdt_fixup
741.1Sdsl
751.1Sdsl	/* change to protected mode */
761.1Sdsl	calll	_C_LABEL(real_to_prot)
771.1Sdsl	.code32
781.1Sdsl
791.1Sdsl	/* clear bss */
801.1Sdsl	xorl	%eax, %eax
811.1Sdsl	movl	$_C_LABEL(edata), %edi
821.1Sdsl	movl	$_C_LABEL(end), %ecx
831.1Sdsl	subl	%edi, %ecx
841.1Sdsl	cld
851.1Sdsl	rep
861.1Sdsl	stosb
871.1Sdsl
881.1Sdsl	/* ...and call main()! */
891.1Sdsl	call	_C_LABEL(main)
901.1Sdsl
911.1Sdsl	.globl	_C_LABEL(exit)
921.1Sdsl_C_LABEL(exit):
931.1Sdsl	call	_C_LABEL(prot_to_real)
941.1Sdsl	.code16
951.1Sdsl	movw	$efail, %si
961.1Sdsl	call	message
971.1Sdsl
981.1Sdsl#ifdef notyet
991.1Sdsl	/* sleep for 3s = 0x2dc6c0 us */
1001.1Sdsl	movb	$0x86, %ah
1011.1Sdsl	mov	$0x002d, %cx
1021.1Sdsl	mov	$0xc6c0, %dx
1031.1Sdsl	int	$0x15
1041.1Sdsl
1051.1Sdsl	/* call ROM BASIC */
1061.1Sdsl	int	$0x18
1071.1Sdsl#else
1081.2Sdsl10:
1091.1Sdsl	cli
1101.1Sdsl	hlt
1111.2Sdsl	jmp	10b
1121.1Sdsl#endif
1131.1Sdsl
1141.1Sdslefail:	.asciz		"Boot fail\r\n"
115