File: i16_setup.S

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (81 lines) | stat: -rw-r--r-- 2,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright (c) 1995-1997 University of Utah and the Flux Group.
 * 
 * This file is part of the OSKit Linux Boot Loader, which is free software,
 * also known as "open source;" you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL), version 2, as published
 * by the Free Software Foundation (FSF).
 * 
 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */

#include <oskit/x86/asm.h>

/* NOTE! These had better be the same as in bootsect.s! */
#include <linux/config.h>

#define INITSEG    DEF_INITSEG	/* we move boot here - out of the way */
#define SYSSEG     DEF_SYSSEG	/* system loaded at 0x10000 (65536). */
#define SETUPSEG   DEF_SETUPSEG	/* this is the current segment */

#define HIGHSECS	5	/* nr of sectors loaded at INITSEG */

#define STACK_SIZE 4096

	.text
	.code16

/*
 * Entrypoint from Linux boot loaders such as LILO.
 *
 * Note that whereas in the Linux 16-bit boot code,
 * the 'bootsect' and 'setup' fragments are compiled and linked separately,
 * in this code they are linked into one big small-model binary image.
 * This means that, whereas the Linux setup code expects to run at 9020:0000,
 * this setup code wants to run at 9000:0200.
 * Since LILO and other Linux boot loaders will be starting us at 9020:0000,
 * we need to fix the CS and EIP early on to conform to our environment.
 * That's what the ljmp instruction below is for.
 */
setup_entry:
	cld

	/* Move the rest of the linuxboot code and data up from SYSSEG.  */
	movw	$SYSSEG,%ax
	movw	%ax,%ds
	movw	$INITSEG,%ax
	movw	%ax,%es
	xorw	%si,%si
	movw	$HIGHSECS*512,%di
	movl	$EXT(edata)-HIGHSECS*512,%ecx
	rep
	movsb

	/* Jump to the segment we want to be running in.  */
	ljmp	$INITSEG,$0f
0:
	movw	%ax,%ds

	/* Switch to a stack in the same segment as everything else.  */
	movw	%ax,%ss
	movl	$stack+STACK_SIZE,%esp
	.comm	stack,STACK_SIZE

	/* Clear our BSS segment.  */
	movl	$EXT(edata),%edi
	movl	$EXT(end),%ecx
	subw	%di,%cx
	xorb	%al,%al
	cld
	rep
	stosb

	/* Make backtraces terminate */
	xorl	%ebp,%ebp

	jmp	EXT(i16_bios_main)