mbr.s revision 47471
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#	$Id: $
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
29start:		cld				# String ops inc
30		xorl %eax,%eax			# Zero
31		movl %eax,%es			# Address
32		movl %eax,%ds			#  data
33		cli				# Disable interrupts
34		movl %eax,%ss			# Set up
35		movwir(LOAD,_sp)		#  stack
36		sti				# Enable interrupts
37		movwir(main-EXEC+LOAD,_si)	# Source
38		movwir(main,_di)		# Destination
39		movwir(0x200-(main-start),_cx)	# Word count
40		rep				# Relocate
41		movsb				#  code
42		jmpnwi(main-LOAD+EXEC)		# To relocated code
43
44main:		xorl %esi,%esi			# No active found
45		movwir(partbl,_bx)		# Partition table
46		movb $0x4,%cl			# Entries
47main.1: 	cmpbr0(_ch,_bx_)		# Null entry?
48		je main.2			# Yes
49		jg err_pt			# If bit 7 unset
50		testl %esi,%esi 		# Active found?
51		jnz err_pt			# Yes
52		movl %ebx,%esi			# Keep place
53main.2: 	addb $0x10,%bl			# Till
54		loop main.1			#  done
55		testl %esi,%esi 		# Active found?
56		jnz main.3			# Yes
57		int $0x18			# BIOS: Diskless boot
58
59main.3: 	cmpb $0x80,%dl			# Drive valid?
60		jb main.4			# No
61		cmpb $0x80+NDRIVE,%dl		# Within range?
62		jb main.5			# Yes
63main.4: 	movb0r(_si_,_dl)		# Load drive
64main.5: 	movb1r(0x1,_si_,_dh)		# Load head
65		movw1r(0x2,_si_,_cx)		# Load cylinder:sector
66		movwir(LOAD,_bx)		# Transfer buffer
67		movwir(0x201,_ax)		# BIOS: Read from
68		int $0x13			#  disk
69		jc err_rd			# If error
70		cmpwi2(MAGIC,0x1fe,_bx_)	# Bootable?
71		jne err_os			# No
72		jmp *%ebx			# Invoke bootstrap
73
74err_pt: 	movwir(msg_pt,_si)		# "Invalid partition
75		jmp putstr			#  table"
76
77err_rd: 	movwir(msg_rd,_si)		# "Error loading
78		jmp putstr			#  operating system"
79
80err_os: 	movwir(msg_os,_si)		# "Missing operating
81		jmp putstr			#  system"
82
83putstr.0:	movwir(0x7,_bx) 		# Page:attribute
84		movb $0xe,%ah			# BIOS: Display
85		int $0x10			#  character
86putstr: 	lodsb				# Get character
87		testb %al,%al			# End of string?
88		jnz putstr.0			# No
89putstr.1:	jmp putstr.1			# Await reset
90
91msg_pt: 	.asciz "Invalid partition table"
92msg_rd: 	.asciz "Error loading operating system"
93msg_os: 	.asciz "Missing operating system"
94
95		.org PT_OFF
96
97partbl: 	.fill 0x10,0x4,0x0		# Partition table
98		.word MAGIC			# Magic number
99