startup.s,v

来自「TCP-IP红宝书源代码」· S,V 代码 · 共 677 行

S,V
677
字号
head	1.8;
access;
symbols;
locks
	dls:1.8; strict;
comment	@# @;


1.8
date	97.09.21.19.29.30;	author dls;	state Dist;
branches;
next	1.7;

1.7
date	94.10.24.19.34.45;	author dls;	state Old;
branches;
next	1.6;

1.6
date	94.08.25.01.18.01;	author dls;	state Fix;
branches;
next	1.5;

1.5
date	94.05.06.03.12.23;	author dls;	state Works;
branches;
next	1.4;

1.4
date	94.05.01.03.20.26;	author dls;	state Works;
branches;
next	1.3;

1.3
date	94.04.30.04.04.37;	author dls;	state Works;
branches;
next	1.2;

1.2
date	94.04.26.15.15.20;	author dls;	state Works;
branches;
next	1.1;

1.1
date	94.03.28.18.07.53;	author dls;	state Works;
branches;
next	;


desc
@@


1.8
log
@pre-3e code
@
text
@/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@@(#)srt0.c	5.3 (Berkeley) 4/28/91
 */

/*
 * Startup code for standalone system
 * Non-relocating version -- for programs which are loaded by boot
 * Relocating version for boot
 * Small relocating version for "micro" boot
 */

/*#include "i386/include/limits.h" */
/* #include "sys/reboot.h" */
#define	B_MAGIC			0
#define	BOOT_MAGIC	0xB00DEF01
#define	B_LEN			4

	.data
	.globl	_gdt
	.globl	_gdtr
	.globl	_idt
	.globl	_idtr
_gdt:	.space	64	# must equal NGD*8 (64 = 8 segments)
_gdtr:	.word	63	# sizeof _gdt -1 (in bytes)
	.long	_gdt
_idt:	.space	384	# must equal NID*8 (384 == 48 vectors)
_idtr:	.word	383	# size of _idt -1 (in bytes)
	.long	_idt

	.globl _cpudelay

_cpudelay:	.long	1
	.text
	.align 2
	.globl	_end
	.globl	_edata
	.globl	_nulluser
	.globl	_bootdev
	.globl	_cyloffset
	.globl	_lidt

	.globl	__zero			# artificial value for entry point
	.set	__zero,0

#ifdef SMALL
	/* where the disklabel goes if we have one */
	.globl	_disklabel
_disklabel:
	.space 512
#endif

entry:	.globl	entry
	.globl	_start

#if	defined(REL) && !defined(SMALL)

#define	KBDATA	0x60		/* kbd data port */
#define	KBSTAT	0x64		/* kbd status/cmd port */
#define	KBS_IFULL	0x02	/* kbd input buffer full, not ready */

#define	WAIT_IRDY \
1:	inb	$KBSTAT,%al; \
	andb	$KBS_IFULL,%al; \
	jnz	1b

	/* enable gate a20! yecchh!! */
	WAIT_IRDY
	movb	$0xd1,%al
	outb	%al,$KBSTAT
	WAIT_IRDY
	movb	$0xdf,%al
	outb	%al,$KBDATA

	/* send a NOP to 8042 to wait for A20 command to complete */
	WAIT_IRDY
	movb    $0xff,%al
	NOP
	outb    %al,$KBSTAT
	NOP
	WAIT_IRDY


	/* relocate program and enter at symbol "_start" */

	#movl	$entry-BRELOC,%esi	# from beginning of ram
	movl	$__zero,%esi
	#movl	$entry,%edi		# to relocated area
	movl	$BRELOC,%edi		# to relocated area
	movl	$_edata-BRELOC,%ecx	# this much
#	movl	$64*1024,%ecx
	cld
	rep
	movsb
	# relocate program counter to relocation base
	pushl	$_start
	ret
#endif

_start:

	/* setup stack pointer */

#ifdef REL
	/*
	 * Copy our arguments to a safe place.
	 * Note that boot blocks don't use CALL.
	 */
#ifndef SMALL
	popl	%ecx		/* pop EIP word left by CALL */
#endif
	popl	%edx
	popl	%ebx
	popl	%eax
#ifdef SMALL
	movl	$SMRELOC-4,%esp
#else
	/* copy boot parameters if present (bios disk parameters should be) */
	movl	%esp,%esi		# params should be at top of old stack
	movl	$BRELOC-4,%esp		# new stack
	cmpl	$BOOT_MAGIC,B_MAGIC(%esi)
	jne	1f
	movl	B_LEN(%esi),%ecx	# length of parameters
	subl	%ecx,%esp		# make space on stack
	movl	%esp,%edi
	cld
	rep
	movsb
1:
#endif
	pushl	%eax
	pushl	%ebx
	pushl	%edx

#else /* REL */
	/* save old stack state */
	movl	%esp,savearea
	movl	%ebp,savearea+4
	movl	$SMRELOC-0x2400,%esp	/* Why move sp? */
#endif /* REL */

#ifdef SMALL
	/* retrieve BIOS disk parameters before we trash too much */
	.globl	_getbiosgeom
	call	_getbiosgeom
#endif
	/* clear memory as needed */

	movl	%esp,%esi
#ifdef	REL

	/*
	 * Clear Bss and up to 64K heap
	 */
	movl	$64*1024,%ebx
	movl	$_end,%eax	# should be movl $_end-_edata but ...
	subl	$_edata,%eax
	addl	%ebx,%eax
	pushl	%eax
	pushl	$_edata
	call	_bzero

	/*
	 * Clear 64K of stack
	 */
	movl	%esi,%eax
	subl	%ebx,%eax
	subl	$5*4,%ebx
	pushl	%ebx
	pushl	%eax
	call	_bzero
#else
	movl	$_edata,%edx
	movl	%esp,%eax
	subl	%edx,%eax
	pushl	%edx
	pushl	%esp
	call	_bzero
#endif
	movl	%esi,%esp

	pushl	$0
	popf

	movl	%esp,%ebp
	call	_setsegs
	lgdt	_gdtr
	/*
	 * reload segment registers; we do code segment by a far
	 * jump
	 */
	ljmp	$0x8,$gdt1	/* CS descriptor 1 */
gdt1:
	movl	$0x10,%eax	/* DS descriptor 2 */
	movw	%ax,%ds
	movw	%ax,%es
	movl	$0x18,%eax	/* SS descriptor 3 */
	movw	%ax,%ss
	movl	_initsp,%esp	/* set new stack pointer base */
	movl	%esp,%ebp

	call	_nulluser
	call	_halt
	jmp	_start

	.data
_bootdev:	.long	0
_cyloffset:	.long	0
savearea:	.long	0,0	# sp & bp to return to
/*
 * _delay - spin-loop delay in units of 10 microseconds
 */
	.text
	.globl _delay
_delay:
	pushl	%ebp
	movl	%esp,%ebp
	movl	8(%ebp),%eax
L4:
	decl	%eax
	jle	L3
	movl	_cpudelay,%edx
L2:
	decl	%edx
	jge	L2
	jmp	L4
L3:
	leave
	ret

	.globl	_inb
_inb:	movl	4(%esp),%edx
	xorl	%eax,%eax	# clr eax
	inb	%dx,%al
	ret

	.globl	_inw
_inw:	movl	4(%esp),%edx
	xorl	%eax,%eax	# clr eax
	inw	%dx,%ax
	ret

	.globl	_outb
_outb:	movl	4(%esp),%edx
	movl	8(%esp),%eax
	outb	%al,%dx
	ret

	.globl	_outw
_outw:	movl	4(%esp),%edx
	movl	8(%esp),%eax
	outw	%ax,%dx
	ret

#ifndef SMALL
	.globl	_rtcin
_rtcin:	movl	4(%esp),%eax
	outb	%al,$0x70
	subl	%eax,%eax	# clr eax
	inb	$0x71,%al
	ret
#endif

	.globl ___udivsi3
___udivsi3:
	movl 4(%esp),%eax
	xorl %edx,%edx
	divl 8(%esp)
	ret

	.globl ___divsi3
___divsi3:
	movl 4(%esp),%eax
	xorl %edx,%edx
	cltd
	idivl 8(%esp)
	ret

	#
	# bzero (base,cnt)
	#

	.globl _bzero
_bzero:
	pushl	%edi
	movl	8(%esp),%edi
	movl	12(%esp),%ecx
	movb	$0x00,%al
	cld
	rep
	stosb
	popl	%edi
	ret

	#
	# bcopy(src, dst, count)
	#

	.globl	_bcopy
_bcopy:
	pushl	%esi
	pushl	%edi
	movl	12(%esp),%esi
	movl	16(%esp),%edi
L1:
	movl	20(%esp),%ecx
	cld
	rep
	movsb
	popl	%edi
	popl	%esi
	ret

	# insw(port,addr,cnt)
	.globl	_insw
_insw:
	pushl	%edi
	movw	8(%esp),%dx
	movl	12(%esp),%edi
	movl	16(%esp),%ecx
	cld
	.byte 0x66,0xf2,0x6d	# rep insw
	movl	%edi,%eax
	popl	%edi
	ret

	# outsw(port,addr,cnt)
	.globl	_outsw
_outsw:
	pushl	%esi
	movw	8(%esp),%dx
	movl	12(%esp),%esi
	movl	16(%esp),%ecx
	cld
	.byte 0x66,0xf2,0x6f	# rep outsw
	movl	%esi,%eax
	popl	%esi
	ret

	#
	# lidt() - load interrupt descriptor table from _idtr
	#
_lidt:
	lidt	_idtr
	ret

@


1.7
log
@*** empty log message ***
@
text
@d123 2
a124 2
	# movl	$_edata-BRELOC,%ecx	# this much
	movl	$64*1024,%ecx
d237 1
a237 1
	jmp	1b
d243 3
d248 15
d379 1
@


1.6
log
@*** empty log message ***
@
text
@d46 5
a50 2
#include "i386/include/limits.h"
#include "sys/reboot.h"
d237 1
a237 1
	jmp	1f
d248 1
a248 1
	subl	%eax,%eax	# clr eax
d252 6
d264 6
d318 2
a319 2
	movl	12(%esp),%edi
	movl	16(%esp),%esi
a328 19
	#
	# wcopy (src,dst,cnt)
	# NOTE: byte order; is like bcopy(), not blkcopy()
	#

	.globl	_wcopy
_wcopy:
	pushl	%esi
	pushl	%edi
	movl	12(%esp),%esi
	movl	16(%esp),%edi
	movl	20(%esp),%ecx
	cld
	rep
	movsw
	popl	%edi
	popl	%esi
	ret

a360 1

@


1.5
log
@*** empty log message ***
@
text
@a1 8
 * Copyright (c) 1992 Berkeley Software Design, Inc. All rights reserved.
 * The Berkeley Software Design Inc. software License Agreement specifies
 * the terms and conditions for redistribution.
 *
 *	BSDI $Id: startup.s,v 1.5 1994/05/05 19:01:04 dls Old dls $
 */

/*-
a68 2
	.globl	__rtt
	.globl	_exit
a214 4
#ifndef	SMALL
	call	_kbdreset	/* resets keyboard */
#endif

d233 1
a233 2
	sti
	call	_hose
a240 3
#ifndef	SMALL
	.globl _kgetc
#endif
a242 31
__rtt:
#ifndef	SMALL
	call	_kgetc
#else
_exit:
	pushl	$131072
	call	_delay
	popl	%eax
#endif
	movl	$-7,%eax
	jmp	1f
#ifndef	SMALL
_exit:
	call	_kgetc
#endif
	movl	4(%esp),%eax
1:
#ifdef	REL
#ifndef SMALL
	call	_reset_cpu
#endif
	movw	$0x1234,%ax
	movw	%ax,0x472	# warm boot
	movl	$0,%esp		# segment violation
	ret
#else
	movl	savearea,%esp
	movl	savearea+4,%ebp
	ret
#endif

d296 1
a296 2
	# bcopy (src,dst,cnt)
	# NOTE: does not (yet) handle overlapped copies
d303 20
d328 1
a328 1
	movsb
@


1.4
log
@*** empty log message ***
@
text
@d6 1
a6 1
 *	BSDI $Id: startup.s,v 1.3 1994/04/30 04:04:37 dls Works dls $
d229 1
d240 1
a240 1
/*	movw	%ax,%es */
@


1.3
log
@,
@
text
@d6 1
a6 1
 *	BSDI $Id: startup.s,v 1.2 1994/04/26 15:15:20 dls Works dls $
a80 1
	.globl	_lgdt
d229 16
a244 2
	call	_init386
	movl	_initsp,%esp	/* set up new stack pointer */
a385 17
	ret

	#
	# lgdt() - load global descriptor table from _gdtr
	#
_lgdt:
	lgdt	_gdtr
	#
	# reload segment registers; we do code segment by a far
	# jump; then the rest
/*	ljmp	gdt1 */
	NOP
gdt1:	xor	%eax,%eax
	movw	$0x18,%ax	/* DS descriptor 3 */
	movw	%ax,%ds
	movw	$0x10,%ax	/* SS descriptor 2 */
	movw	%ax,%ss
@


1.2
log
@*** empty log message ***
@
text
@d6 1
a6 1
 *	BSDI $Id: startup.s,v 1.1 1994/03/28 18:07:53 dls Works dls $
a232 1
	call	_prints
a233 1
	int	$7
d383 1
a383 1
	jmp	1f
d385 1
a385 1
1:	xor	%eax,%eax
@


1.1
log
@Initial revision
@
text
@d6 1
a6 1
 *	BSDI $Id: srt0.s,v 1.6 1993/02/23 18:04:19 karels Exp $
d58 11
a68 1
	.align	2
d81 2
d95 1
a95 1
	.globl	start
d125 1
a125 1
	/* relocate program and enter at symbol "start" */
d137 1
a137 1
	pushl	$start
d141 1
a141 1
start:
d230 2
d233 4
d375 24
@

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?