xref: /openbsd-src/sys/arch/i386/stand/boot/srt0.S (revision 8162193374858e8d7dceca506657f13b21b8be44)
1*81621933Sguenther/*	$OpenBSD: srt0.S,v 1.17 2022/12/08 01:25:45 guenther Exp $	*/
2df1f5d3aSweingart
3779812deSmickey/*
4779812deSmickey * Copyright (c) 1997 Michael Shalayeff
5df1f5d3aSweingart * All rights reserved.
6df1f5d3aSweingart *
7df1f5d3aSweingart * Redistribution and use in source and binary forms, with or without
8df1f5d3aSweingart * modification, are permitted provided that the following conditions
9df1f5d3aSweingart * are met:
10df1f5d3aSweingart * 1. Redistributions of source code must retain the above copyright
11df1f5d3aSweingart *    notice, this list of conditions and the following disclaimer.
12df1f5d3aSweingart * 2. Redistributions in binary form must reproduce the above copyright
13df1f5d3aSweingart *    notice, this list of conditions and the following disclaimer in the
14df1f5d3aSweingart *    documentation and/or other materials provided with the distribution.
15df1f5d3aSweingart *
16779812deSmickey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17779812deSmickey * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18779812deSmickey * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19df1f5d3aSweingart * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20df1f5d3aSweingart * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21df1f5d3aSweingart * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22df1f5d3aSweingart * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23df1f5d3aSweingart * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24df1f5d3aSweingart * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25df1f5d3aSweingart * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26df1f5d3aSweingart * SUCH DAMAGE.
27df1f5d3aSweingart *
28df1f5d3aSweingart */
29028d5550Sweingart#include <machine/asm.h>
30d95e68c6Sdrahn#include <assym.h>
31d95e68c6Sdrahn
32d95e68c6Sdrahn#define BOOTSTACK 0xfffc
33df1f5d3aSweingart
34*81621933Sguenther	.globl	end
35*81621933Sguenther	.globl	edata
36*81621933Sguenther	.globl	boot
37*81621933Sguenther	.globl	_rtt
38*81621933Sguenther	.globl	bios_bootdev
39*81621933Sguenther	.globl	pmm_init
40d95e68c6Sdrahn	.globl	Gdtr
411e251da8Smickey
421e251da8Smickey	.text
4322621c31Sjsing	.align	16
44d95e68c6Sdrahn	.code16
45d95e68c6Sdrahn	.globl	_start
46d95e68c6Sdrahn_start:
47d95e68c6Sdrahn	popl %eax
48d95e68c6Sdrahn	cmpl $BOOTMAGIC, %eax
49d95e68c6Sdrahn	je	1f
501e251da8Smickey#ifdef DEBUG
511e251da8Smickey	movl	$0xb80a0, %ebx
52e7df74d8Sgrange	addr32 movl $0x07420742, (%ebx)
531e251da8Smickey#endif
54d95e68c6Sdrahn1:
55d95e68c6Sdrahn	popl %edx
56d95e68c6Sdrahn	cli
57d95e68c6Sdrahn	pushl	%cs
58d95e68c6Sdrahn	popl	%ds
59d95e68c6Sdrahn	addr32 data32 lgdt	(Gdtr - LINKADDR)
60d95e68c6Sdrahn	movl	%cr0, %eax
61d95e68c6Sdrahn	orl $CR0_PE, %eax
62d95e68c6Sdrahn	data32 movl %eax, %cr0
63d95e68c6Sdrahn	data32 ljmp $8, $1f
64d95e68c6Sdrahn1:
65d95e68c6Sdrahn	.code32
66d95e68c6Sdrahn	movl	$0x10,%eax
67d95e68c6Sdrahn	mov	%ax,%ds
68d95e68c6Sdrahn	mov	%ax,%ss
69d95e68c6Sdrahn	mov	%ax,%es
70d95e68c6Sdrahn	mov	%ax,%fs
71d95e68c6Sdrahn	mov	%ax,%gs
72d95e68c6Sdrahn	movl	$BOOTSTACK,%esp
73d95e68c6Sdrahn	pushl	%edx
74*81621933Sguenther	movl	%edx, bios_bootdev
75d95e68c6Sdrahn
76d95e68c6Sdrahn	/* Now do it all */
771e251da8Smickey#ifdef DEBUG
781e251da8Smickey	movl	$0xb80a4, %ebx
791e251da8Smickey	movl	$0x07520752, (%ebx)
801e251da8Smickey#endif
811e251da8Smickey	/* zero .bss */
821e251da8Smickey	xorl	%eax, %eax
83*81621933Sguenther	movl	$end, %ecx
84*81621933Sguenther	subl	$edata,%ecx
85*81621933Sguenther	movl	$edata, %edi
861e251da8Smickey	cld
871e251da8Smickey	rep;	stosb
881e251da8Smickey
89*81621933Sguenther	call	pmm_init
90*81621933Sguenther	call	boot
911e251da8Smickey
92*81621933Sguenther	jmp	_rtt
93