Clean up some more 16-bit code and get rid of more m4 macros.
This commit is contained in:
parent
638bac9fc0
commit
af54a4fe47
@ -6,8 +6,6 @@ STRIP=
|
||||
BINDIR?= /boot
|
||||
BINMODE= 444
|
||||
|
||||
M4?= m4
|
||||
|
||||
ORG= 0x600
|
||||
|
||||
mbr: mbr.o
|
||||
@ -19,10 +17,6 @@ mbr: mbr.o
|
||||
objcopy -S -O binary mbr.out ${.TARGET}
|
||||
.endif
|
||||
|
||||
mbr.o: mbr.m4 mbr.s
|
||||
(cd ${.CURDIR}; ${M4} mbr.m4 mbr.s) | \
|
||||
${AS} ${AFLAGS} -o ${.TARGET}
|
||||
|
||||
CLEANFILES+= mbr.out mbr.o
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,51 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 1999 Robert Nordier
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms are freely
|
||||
# permitted provided that the above copyright notice and this
|
||||
# paragraph and the following disclaimer are duplicated in all
|
||||
# such forms.
|
||||
#
|
||||
# This software is provided "AS IS" and without any express or
|
||||
# implied warranties, including, without limitation, the implied
|
||||
# warranties of merchantability and fitness for a particular
|
||||
# purpose.
|
||||
#
|
||||
|
||||
# $FreeBSD$
|
||||
|
||||
define(_al,0x0)dnl
|
||||
define(_cl,0x1)dnl
|
||||
define(_dl,0x2)dnl
|
||||
define(_bl,0x3)dnl
|
||||
define(_ah,0x4)dnl
|
||||
define(_ch,0x5)dnl
|
||||
define(_dh,0x6)dnl
|
||||
define(_bh,0x7)dnl
|
||||
|
||||
define(_ax,0x0)dnl
|
||||
define(_cx,0x1)dnl
|
||||
define(_dx,0x2)dnl
|
||||
define(_bx,0x3)dnl
|
||||
define(_sp,0x4)dnl
|
||||
define(_bp,0x5)dnl
|
||||
define(_si,0x6)dnl
|
||||
define(_di,0x7)dnl
|
||||
|
||||
define(_bx_si,0x0)dnl
|
||||
define(_bx_di,0x1)dnl
|
||||
define(_bp_si,0x2)dnl
|
||||
define(_bp_di,0x3)dnl
|
||||
define(_si_,0x4)dnl
|
||||
define(_di_,0x5)dnl
|
||||
define(_bp_,0x6)dnl
|
||||
define(_bx_,0x7)dnl
|
||||
|
||||
define(cmpbr0,`.byte 0x38; .byte ($1 << 0x3) | $2')dnl
|
||||
define(cmpwi2,`.byte 0x81; .byte 0xb8 | $3; .word $2; .word $1')dnl
|
||||
define(movb0r,`.byte 0x8a; .byte ($2 << 0x3) | $1')dnl
|
||||
define(movb1r,`.byte 0x8a; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
|
||||
define(movw1r,`.byte 0x8b; .byte 0x40 | ($3 << 0x3) | $2; .byte $1')dnl
|
||||
define(movwir,`.byte 0xb8 | $2; .word $1')dnl
|
||||
define(jmpnwi,`.byte 0xe9; .word $1 - . - 0x2')dnl
|
@ -25,34 +25,35 @@
|
||||
.set NDRIVE,0x8 # Drives to support
|
||||
|
||||
.globl start # Entry point
|
||||
.code16
|
||||
|
||||
start: cld # String ops inc
|
||||
xorl %eax,%eax # Zero
|
||||
movl %eax,%es # Address
|
||||
movl %eax,%ds # data
|
||||
xorw %ax,%ax # Zero
|
||||
movw %ax,%es # Address
|
||||
movw %ax,%ds # data
|
||||
cli # Disable interrupts
|
||||
movl %eax,%ss # Set up
|
||||
movwir(LOAD,_sp) # stack
|
||||
movw %ax,%ss # Set up
|
||||
movw $LOAD,%sp # stack
|
||||
sti # Enable interrupts
|
||||
movwir(main-EXEC+LOAD,_si) # Source
|
||||
movwir(main,_di) # Destination
|
||||
movwir(0x200-(main-start),_cx) # Byte count
|
||||
movw $main-EXEC+LOAD,%si # Source
|
||||
movw $main,%di # Destination
|
||||
movw $0x200-(main-start),%cx # Byte count
|
||||
rep # Relocate
|
||||
movsb # code
|
||||
jmpnwi(main-LOAD+EXEC) # To relocated code
|
||||
jmp main-LOAD+EXEC # To relocated code
|
||||
|
||||
main: xorl %esi,%esi # No active partition
|
||||
movwir(partbl,_bx) # Partition table
|
||||
main: xorw %si,%si # No active partition
|
||||
movw $partbl,%bx # Partition table
|
||||
movb $0x4,%cl # Number of entries
|
||||
main.1: cmpbr0(_ch,_bx_) # Null entry?
|
||||
main.1: cmpb %ch,(%bx) # Null entry?
|
||||
je main.2 # Yes
|
||||
jg err_pt # If 0x1..0x7f
|
||||
testl %esi,%esi # Active already found?
|
||||
testw %si,%si # Active already found?
|
||||
jnz err_pt # Yes
|
||||
movl %ebx,%esi # Point to active
|
||||
movw %bx,%si # Point to active
|
||||
main.2: addb $0x10,%bl # Till
|
||||
loop main.1 # done
|
||||
testl %esi,%esi # Active found?
|
||||
testw %si,%si # Active found?
|
||||
jnz main.3 # Yes
|
||||
int $0x18 # BIOS: Diskless boot
|
||||
|
||||
@ -60,27 +61,27 @@ main.3: cmpb $0x80,%dl # Drive valid?
|
||||
jb main.4 # No
|
||||
cmpb $0x80+NDRIVE,%dl # Within range?
|
||||
jb main.5 # Yes
|
||||
main.4: movb0r(_si_,_dl) # Load drive
|
||||
main.5: movb1r(0x1,_si_,_dh) # Load head
|
||||
movw1r(0x2,_si_,_cx) # Load cylinder:sector
|
||||
movwir(LOAD,_bx) # Transfer buffer
|
||||
movwir(0x201,_ax) # BIOS: Read from
|
||||
main.4: movb (%si),%dl # Load drive
|
||||
main.5: movb 0x1(%si),%dh # Load head
|
||||
movw 0x2(%si),%cx # Load cylinder:sector
|
||||
movw $LOAD,%bx # Transfer buffer
|
||||
movw $0x201,%ax # BIOS: Read from
|
||||
int $0x13 # disk
|
||||
jc err_rd # If error
|
||||
cmpwi2(MAGIC,0x1fe,_bx_) # Bootable?
|
||||
cmpw $MAGIC,0x1fe(%bx) # Bootable?
|
||||
jne err_os # No
|
||||
jmp *%ebx # Invoke bootstrap
|
||||
jmp *%bx # Invoke bootstrap
|
||||
|
||||
err_pt: movwir(msg_pt,_si) # "Invalid partition
|
||||
err_pt: movw $msg_pt,%si # "Invalid partition
|
||||
jmp putstr # table"
|
||||
|
||||
err_rd: movwir(msg_rd,_si) # "Error loading
|
||||
err_rd: movw $msg_rd,%si # "Error loading
|
||||
jmp putstr # operating system"
|
||||
|
||||
err_os: movwir(msg_os,_si) # "Missing operating
|
||||
err_os: movw $msg_os,%si # "Missing operating
|
||||
jmp putstr # system"
|
||||
|
||||
putstr.0: movwir(0x7,_bx) # Page:attribute
|
||||
putstr.0: movw $0x7,%bx # Page:attribute
|
||||
movb $0xe,%ah # BIOS: Display
|
||||
int $0x10 # character
|
||||
putstr: lodsb # Get character
|
||||
|
Loading…
Reference in New Issue
Block a user