mbr.s revision 60822
1#
2# Copyright (c) 1999 Robert Nordier
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms are freely
6# permitted provided that the above copyright notice and this
7# paragraph and the following disclaimer are duplicated in all
8# such forms.
9#
10# This software is provided "AS IS" and without any express or
11# implied warranties, including, without limitation, the implied
12# warranties of merchantability and fitness for a particular
13# purpose.
14#
15
16# $FreeBSD: head/sys/boot/i386/mbr/mbr.s 60822 2000-05-23 12:28:31Z jhb $
17
18# Master boot record
19
20		.set LOAD,0x7c00		# Load address
21		.set EXEC,0x600 		# Execution address
22		.set PT_OFF,0x1be		# Partition table
23		.set MAGIC,0xaa55		# Magic: bootable
24
25		.set NDRIVE,0x8 		# Drives to support
26
27		.globl start			# Entry point
28		.code16
29
30start:		cld				# String ops inc
31		xorw %ax,%ax			# Zero
32		movw %ax,%es			# Address
33		movw %ax,%ds			#  data
34		cli				# Disable interrupts
35		movw %ax,%ss			# Set up
36		movw $LOAD,%sp			#  stack
37		sti				# Enable interrupts
38		movw $main-EXEC+LOAD,%si	# Source
39		movw $main,%di			# Destination
40		movw $0x200-(main-start),%cx	# Byte count
41		rep				# Relocate
42		movsb				#  code
43		jmp main-LOAD+EXEC		# To relocated code
44
45main:		xorw %si,%si			# No active partition
46		movw $partbl,%bx		# Partition table
47		movb $0x4,%cl			# Number of entries
48main.1: 	cmpb %ch,(%bx)			# Null entry?
49		je main.2			# Yes
50		jg err_pt			# If 0x1..0x7f
51		testw %si,%si	 		# Active already found?
52		jnz err_pt			# Yes
53		movw %bx,%si			# Point to active
54main.2: 	addb $0x10,%bl			# Till
55		loop main.1			#  done
56		testw %si,%si	 		# Active found?
57		jnz main.3			# Yes
58		int $0x18			# BIOS: Diskless boot
59
60main.3: 	cmpb $0x80,%dl			# Drive valid?
61		jb main.4			# No
62		cmpb $0x80+NDRIVE,%dl		# Within range?
63		jb main.5			# Yes
64main.4: 	movb (%si),%dl			# Load drive
65main.5: 	movb 0x1(%si),%dh		# Load head
66		movw 0x2(%si),%cx		# Load cylinder:sector
67		movw $LOAD,%bx			# Transfer buffer
68		movw $0x201,%ax			# BIOS: Read from
69		int $0x13			#  disk
70		jc err_rd			# If error
71		cmpw $MAGIC,0x1fe(%bx)		# Bootable?
72		jne err_os			# No
73		jmp *%bx			# Invoke bootstrap
74
75err_pt: 	movw $msg_pt,%si		# "Invalid partition
76		jmp putstr			#  table"
77
78err_rd: 	movw $msg_rd,%si		# "Error loading
79		jmp putstr			#  operating system"
80
81err_os: 	movw $msg_os,%si		# "Missing operating
82		jmp putstr			#  system"
83
84putstr.0:	movw $0x7,%bx	 		# Page:attribute
85		movb $0xe,%ah			# BIOS: Display
86		int $0x10			#  character
87putstr: 	lodsb				# Get character
88		testb %al,%al			# End of string?
89		jnz putstr.0			# No
90putstr.1:	jmp putstr.1			# Await reset
91
92msg_pt: 	.asciz "Invalid partition table"
93msg_rd: 	.asciz "Error loading operating system"
94msg_os: 	.asciz "Missing operating system"
95
96		.org PT_OFF
97
98partbl: 	.fill 0x10,0x4,0x0		# Partition table
99		.word MAGIC			# Magic number
100