MFi386: Get rid of unnecessary use of m4(1) by using cpp(1) instead.

Repocopied by:	joe
This commit is contained in:
nyan 2004-02-13 15:39:59 +00:00
parent a91b5512c4
commit bd3ac210d0
6 changed files with 107 additions and 1893 deletions

View File

@ -3,13 +3,13 @@
PROG= btx.out
INTERNALPROG=
NOMAN=
SRCS= btx.s
SRCS= btx.S
CLEANFILES= btx
M4?= m4
CFLAGS+=-DPC98
.if defined(PAGING)
M4FLAGS+= -DPAGING
CFLAGS+=-DPAGING
.endif
.if defined(BOOT_BTX_NOHANG)
@ -18,16 +18,15 @@ BOOT_BTX_FLAGS=0x1
BOOT_BTX_FLAGS=0x0
.endif
AFLAGS+= --defsym BTX_FLAGS=${BOOT_BTX_FLAGS}
AFLAGS+= --defsym PC98=1
CFLAGS+=-DBTX_FLAGS=${BOOT_BTX_FLAGS}
.if defined(BTX_SERIAL)
BOOT_COMCONSOLE_PORT?= 0x238
BOOT_COMCONSOLE_SPEED?= 9600
B2SIOFMT?= 0x3
M4FLAGS+= -DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \
-DSIOFMT=${B2SIOFMT} -DSIOSPD=${BOOT_COMCONSOLE_SPEED}
CFLAGS+=-DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \
-DSIOFMT=${B2SIOFMT} -DSIOSPD=${BOOT_COMCONSOLE_SPEED}
.endif
ORG= 0x9000
@ -39,8 +38,4 @@ LDFLAGS=-N -e start -Ttext ${ORG}
btx: btx.out
objcopy -S -O binary btx.out ${.TARGET}
btx.o: btx.s
(cd ${.CURDIR}; ${M4} ${M4FLAGS} btx.s) | \
${AS} ${AFLAGS} -o ${.TARGET}
.include <bsd.prog.mk>

View File

@ -71,27 +71,27 @@
#
# Screen defaults and assumptions.
#
.`ifdef' PC98
#ifdef PC98
.set SCR_MAT,0xe1 # Mode/attribute
.else
#else
.set SCR_MAT,0x7 # Mode/attribute
.endif
#endif
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
.`ifdef' PC98
#ifdef PC98
.set BDA_MEM,0x501 # Free memory
.set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags
.set BDA_POS,0x53e # Cursor position
.else
#else
.set BDA_MEM,0x413 # Free memory
.set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
.set BDA_BOOT,0x472 # Boot howto flag
.endif
#endif
#
# Derivations, for brevity.
#
@ -168,7 +168,7 @@ init.4: movb $_ESP0H,TSS_ESP0+1(%di) # Set ESP0
movb $SEL_SDATA,TSS_SS0(%di) # Set SS0
movb $_ESP1H,TSS_ESP1+1(%di) # Set ESP1
movb $_TSSIO,TSS_MAP(%di) # Set I/O bit map base
ifdef(`PAGING',`
#ifdef PAGING
#
# Create page directory.
#
@ -201,25 +201,25 @@ init.6: mov $0x7,%al # Set U:W:P flags
init.7: stosl # Set entry
add %edx,%eax # Next address
loop init.6 # Till done
')
#endif
#
# Bring up the system.
#
mov $0x2820,%bx # Set protected mode
callw setpic # IRQ offsets
lidt idtdesc # Set IDT
ifdef(`PAGING',`
#ifdef PAGING
xor %eax,%eax # Set base
mov $MEM_DIR>>0x8,%ah # of page
mov %eax,%cr3 # directory
')
#endif
lgdt gdtdesc # Set GDT
mov %cr0,%eax # Switch to protected
ifdef(`PAGING',`
#ifdef PAGING
or $0x80000001,%eax # mode and enable paging
',`
#else
or $0x01,%eax # mode
')
#endif
mov %eax,%cr0 #
ljmp $SEL_SCODE,$init.8 # To 32-bit code
.code32
@ -233,13 +233,13 @@ init.8: xorl %ecx,%ecx # Zero
ltr %cx # register
movl $MEM_USR,%edx # User base address
movzwl %ss:BDA_MEM,%eax # Get free memory
.`ifdef' PC98
#ifdef PC98
andl $0x7,%eax
incl %eax
shll $0x11,%eax # To bytes
.else
#else
shll $0xa,%eax # To bytes
.endif
#endif
subl $0x1000,%eax # Less arg space
subl %edx,%eax # Less base
movb $SEL_UDATA,%cl # User data selector
@ -256,9 +256,9 @@ init.8: xorl %ecx,%ecx # Zero
movb $0x7,%cl # Set remaining
init.9: push $0x0 # general
loop init.9 # registers
ifdef(`BTX_SERIAL',`
#ifdef BTX_SERIAL
call sio_init # setup the serial console
')
#endif
popa # and initialize
popl %es # Initialize
popl %ds # user
@ -302,11 +302,11 @@ exit.1: mov $SEL_RDATA,%cl # 16-bit selector
exit.2: xor %ax,%ax # Real mode segment
mov %ax,%ss # Reload SS
mov %ax,%ds # Address data
.`ifdef' PC98
#ifdef PC98
mov $0x1008,%bx # Set real mode
.else
#else
mov $0x7008,%bx # Set real mode
.endif
#endif
callw setpic # IRQ offsets
lidt ivtdesc # Set IVT
#
@ -315,20 +315,20 @@ exit.2: xor %ax,%ax # Real mode segment
sti # Enable interrupts
testb $0x1,btx_hdr+0x7 # Reboot?
exit.3: jz exit.3 # No
.`ifdef' PC98
#ifdef PC98
movb $0xa0,%al
outb %al,$0x35
movb 0,%al
outb %al,$0xf0
exit.4: jmp exit.4
.else
#else
movw $0x1234, BDA_BOOT # Do a warm boot
ljmp $0xf000,$0xfff0 # reboot the machine
.endif
#endif
#
# Set IRQ offsets by reprogramming 8259A PICs.
#
.`ifdef' PC98
#ifdef PC98
setpic: in $0x02,%al # Save master
push %ax # IMR
in $0x0a,%al # Save slave
@ -352,7 +352,7 @@ setpic: in $0x02,%al # Save master
outb %al,$0x0a # IMR
pop %ax # Restore master
outb %al,$0x02 # IMR
.else
#else
setpic: in $0x21,%al # Save master
push %ax # IMR
in $0xa1,%al # Save slave
@ -375,7 +375,7 @@ setpic: in $0x21,%al # Save master
outb %al,$0xa1 # IMR
pop %ax # Restore master
outb %al,$0x21 # IMR
.endif
#endif
retw # To caller
.code32
#
@ -455,7 +455,7 @@ except.2: push $SEL_SDATA # Set up
movl %esp,%ebx # Stack frame
movl $dmpfmt,%esi # Dump format string
movl $MEM_BUF,%edi # Buffer
.`ifdef' PC98
#ifdef PC98
pushl %eax
pushl %edx
wait.1:
@ -482,7 +482,7 @@ wait.2:
movw %ax,(%edx)
popl %edx
popl %eax
.endif
#endif
pushl %edi # Dump to
call dump # buffer
popl %esi # and
@ -751,13 +751,13 @@ v86intn: lodsb # Get int no
v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout?
jne v86intn.2 # no, handle the int normally
movb BDA_KEYFLAGS,%al # get the shift key state
.`ifdef' PC98
#ifdef PC98
andb $0x18,%al # mask off just Ctrl and Alt
cmpb $0x18,%al # are both Ctrl and Alt down?
.else
#else
andb $0xc,%al # mask off just Ctrl and Alt
cmpb $0xc,%al # are both Ctrl and Alt down?
.endif
#endif
jne v86intn.2 # no, handle the int normally
popl %eax # restore EAX
jmp reboot # reboot the machine
@ -794,7 +794,7 @@ intx20: push $0x8 # Int 0x20: IRQ0
jmp int_hw # V86 int 0xe
push $0xf # Int 0x27: IRQ7
jmp int_hw # V86 int 0xf
.`ifdef' PC98
#ifdef PC98
push $0x10 # Int 0x28: IRQ8
jmp int_hw # V86 int 0x10
push $0x11 # Int 0x29: IRQ9
@ -811,7 +811,7 @@ intx20: push $0x8 # Int 0x20: IRQ0
jmp int_hw # V86 int 0x16
push $0x17 # Int 0x2f: IRQ15
jmp int_hw # V86 int 0x17
.else
#else
push $0x70 # Int 0x28: IRQ8
jmp int_hw # V86 int 0x70
push $0x71 # Int 0x29: IRQ9
@ -828,7 +828,7 @@ intx20: push $0x8 # Int 0x20: IRQ0
jmp int_hw # V86 int 0x76
push $0x77 # Int 0x2f: IRQ15
jmp int_hw # V86 int 0x77
.endif
#endif
#
# Reflect hardware interrupts.
#
@ -966,13 +966,13 @@ intx30: cmpl $SYS_EXEC,%eax # Exec system call?
movl $MEM_USR,%eax # User base address
addl 0xc(%esp,1),%eax # Change to user
leal 0x4(%eax),%esp # stack
ifdef(`PAGING',`
#ifdef PAGING
movl %cr0,%eax # Turn
andl $~0x80000000,%eax # off
movl %eax,%cr0 # paging
xorl %eax,%eax # Flush
movl %eax,%cr3 # TLB
')
#endif
popl %eax # Call
call *%eax # program
intx30.1: orb $0x1,%ss:btx_hdr+0x7 # Flag reboot
@ -1076,7 +1076,7 @@ putstr: lodsb # Load char
testb %al,%al # End of string?
jnz putstr.0 # No
ret # To caller
ifdef(`BTX_SERIAL',`
#ifdef BTX_SERIAL
.set SIO_PRT,SIOPRT # Base port
.set SIO_FMT,SIOFMT # 8N1
.set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
@ -1149,7 +1149,7 @@ putchr.1: pushl %eax # Push the character
call sio_putc # Output the character
popa # Restore
ret # To caller
',`
#else
#
# Output character AL to the console.
#
@ -1158,17 +1158,17 @@ putchr: pusha # Save
movb $SCR_MAT,%ah # Mode/attribute
movl $BDA_POS,%ebx # BDA pointer
movw (%ebx),%dx # Cursor position
.`ifdef' PC98
#ifdef PC98
movl $0xa0000,%edi
.else
#else
movl $0xb8000,%edi # Regen buffer (color)
cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
jne putchr.1 # No
xorw %di,%di # Regen buffer (mono)
.endif
#endif
putchr.1: cmpb $0xa,%al # New line?
je putchr.2 # Yes
.`ifdef' PC98
#ifdef PC98
movw %dx,%cx
movb %al,(%edi,%ecx,1) # Write char
addl $0x2000,%ecx
@ -1182,7 +1182,7 @@ putchr.2: movw %dx,%ax
mul %dl
movw %ax,%dx
putchr.3: cmpw $SCR_ROW*SCR_COL*2,%dx
.else
#else
xchgl %eax,%ecx # Save char
movb $SCR_COL,%al # Columns per row
mulb %dh # * row position
@ -1197,28 +1197,28 @@ putchr.3: cmpw $SCR_ROW*SCR_COL*2,%dx
putchr.2: xorb %dl,%dl # Zero column
incb %dh # Bump row
putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
.endif
#endif
jb putchr.4 # No
leal 2*SCR_COL(%edi),%esi # New top line
movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
rep # Scroll
movsl # screen
movb $0x20,%al # Space
.`ifdef' PC98
#ifdef PC98
xorb %ah,%ah
.endif
#endif
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
.`ifdef' PC98
#ifdef PC98
movw $(SCR_ROW-1)*SCR_COL*2,%dx
.else
#else
movb $SCR_ROW-1,%dh # Bottom line
.endif
#endif
putchr.4: movw %dx,(%ebx) # Update position
popa # Restore
ret # To caller
')
#endif
.p2align 4
#

File diff suppressed because it is too large Load Diff

View File

@ -3,14 +3,14 @@
PROG= btxldr.out
INTERNALPROG=
NOMAN=
SRCS= btxldr.s
SRCS= btxldr.S
CLEANFILES= btxldr
M4?= m4
M4FLAGS+= -DLOADER_ADDRESS=${LOADER_ADDRESS} -DPC98
CFLAGS+=-DPC98
CFLAGS+=-DLOADER_ADDRESS=${LOADER_ADDRESS}
.if defined(BTXLDR_VERBOSE)
M4FLAGS+= -DBTXLDR_VERBOSE
CFLAGS+=-DBTXLDR_VERBOSE
.endif
all: btxldr
@ -20,8 +20,4 @@ LDFLAGS=-N -e start -Ttext ${LOADER_ADDRESS}
btxldr: btxldr.out
objcopy -S -O binary btxldr.out ${.TARGET}
btxldr.o: btxldr.s
(cd ${.CURDIR}; ${M4} ${M4FLAGS} btxldr.s ) | \
${AS} ${AFLAGS} -o ${.TARGET}
.include <bsd.prog.mk>

View File

@ -43,24 +43,24 @@
#
# Screen constants.
#
ifdef(`PC98',`
#ifdef PC98
.set SCR_MAT,0xe1 # Mode/attribute
',`
#else
.set SCR_MAT,0x7 # Mode/attribute
')
#endif
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
ifdef(`PC98',`
#ifdef PC98
.set BDA_MEM,0xa1501 # Free memory
.set BDA_POS,0xa153e # Cursor position
',`
#else
.set BDA_MEM,0x413 # Free memory
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
')
#endif
#
# Required by aout gas inadequacy.
#
@ -73,7 +73,7 @@ ifdef(`PC98',`
# BTX program loader for ELF clients.
#
start: cld # String ops inc
ifdef(`PC98',`
#ifdef PC98
cli
gdcwait.1: inb $0x60,%al
testb $0x04,%al
@ -94,28 +94,28 @@ gdcwait.2: inb $0x60,%al
shlw $1,%dx
movl $BDA_POS,%ebx
movw %dx,(%ebx)
')
#endif
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
ifdef(`PC98',`
#ifdef PC98
andl $0x7,%eax
incl %eax
shll $0x11,%eax # in bytes
',`
#else
shll $0xa,%eax # in bytes
')
#endif
movl %eax,%ebp # Base of user stack
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_mem,%esi # Display
call hexout # amount of
call putstr # base memory
')
#endif
lgdt gdtdesc # Load new GDT
#
# Relocate caller's arguments.
#
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_esp,%esi # Display
movl %esp,%eax # caller
call hexout # stack
@ -128,7 +128,7 @@ start.1: movl (%ebx),%eax # Get argument and
call hexout # Display it
loop start.1 # Till done
call putstr # End message
')
#endif
movl $0x48,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
movl 0x18(%esp,1),%esi # Source: bootinfo
@ -138,24 +138,24 @@ start.1: movl (%ebx),%eax # Get argument and
rep # Copy
movsb # it
movl %ebp,0x18(%esp,1) # Update pointer
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_rel_bi,%esi # Display
movl %ebp,%eax # bootinfo
call hexout # relocation
call putstr # message
')
#endif
start_null_bi: movl $0x18,%ecx # Allocate space
subl %ecx,%ebp # for arguments
leal 0x4(%esp,1),%esi # Source
movl %ebp,%edi # Destination
rep # Copy
movsb # them
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_rel_args,%esi # Display
movl %ebp,%eax # argument
call hexout # relocation
call putstr # message
')
#endif
#
# Set up BTX kernel.
#
@ -186,30 +186,30 @@ ifdef(`BTXLDR_VERBOSE',`
addl $MEM_TBL,%edi # address
pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
pushl %ecx # Save image size
')
#endif
rep # Relocate
movsb # BTX
movl %esi,%ebx # Keep place
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_rel_btx,%esi # Restore
popl %eax # parameters
call hexout # and
')
#endif
popl %ebp # display
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl %ebp,%eax # the
call hexout # relocation
call putstr # message
')
#endif
addl $PAG_SIZ,%ebp # Display
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_base,%esi # the
movl %ebp,%eax # user
call hexout # base
call putstr # address
')
#endif
#
# Set up ELF-format client program.
#
@ -219,18 +219,18 @@ ifdef(`BTXLDR_VERBOSE',`
call putstr # message
start.2: jmp start.2 # Hang
start.3:
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_elf,%esi # Display ELF
call putstr # message
movl $m_segs,%esi # Format string
')
#endif
movl $0x2,%edi # Segment count
movl 0x1c(%ebx),%edx # Get e_phoff
addl %ebx,%edx # To pointer
movzwl 0x2c(%ebx),%ecx # Get e_phnum
start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
jne start.6 # No
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl 0x4(%edx),%eax # Display
call hexout # p_offset
movl 0x8(%edx),%eax # Display
@ -240,7 +240,7 @@ ifdef(`BTXLDR_VERBOSE',`
movl 0x14(%edx),%eax # Display
call hexout # p_memsz
call putstr # End message
')
#endif
pushl %esi # Save
pushl %edi # working
pushl %ecx # registers
@ -265,10 +265,10 @@ start.5: popl %ecx # Restore
start.6: addl $0x20,%edx # To next entry
loop start.4 # Till done
start.7:
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
movl $m_done,%esi # Display done
call putstr # message
')
#endif
movl $start.8,%esi # Real mode stub
movl $MEM_STUB,%edi # Destination
movl $start.9-start.8,%ecx # Size
@ -330,17 +330,17 @@ putchr: pusha # Save
movb $SCR_MAT,%ah # Mode/attribute
movl $BDA_POS,%ebx # BDA pointer
movw (%ebx),%dx # Cursor position
ifdef(`PC98',`
#ifdef PC98
movl $0xa0000,%edi # Regen buffer (color)
',`
#else
movl $0xb8000,%edi # Regen buffer (color)
cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
jne putchr.1 # No
xorw %di,%di # Regen buffer (mono)
')
#endif
putchr.1: cmpb $0xa,%al # New line?
je putchr.2 # Yes
ifdef(`PC98',`
#ifdef PC98
movw %dx,%cx
movb %al,(%edi,%ecx,1) # Write char
addl $0x2000,%ecx
@ -354,7 +354,7 @@ putchr.2: movw %dx,%ax
mul %dl
movw %ax,%dx
putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
',`
#else
xchgl %eax,%ecx # Save char
movb $SCR_COL,%al # Columns per row
mulb %dh # * row position
@ -369,20 +369,20 @@ putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
putchr.2: xorb %dl,%dl # Zero column
incb %dh # Bump row
putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
')
#endif
jb putchr.4 # No
leal 2*SCR_COL(%edi),%esi # New top line
movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
rep # Scroll
movsl # screen
movb $' ',%al # Space
ifdef(`PC98',`
#ifdef PC98
xorb %ah,%ah
')
#endif
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
ifdef(`PC98',`
#ifdef PC98
movw $(SCR_ROW-1)*SCR_COL*2,%dx
putchr.4: movw %dx,(%ebx) # Update position
shrw $1,%dx
@ -395,10 +395,10 @@ gdcwait.3: inb $0x60,%al
outb %al,$0x60
movb %dh,%al
outb %al,$0x60
',`
#else
movb $SCR_ROW-1,%dh # Bottom line
putchr.4: movw %dx,(%ebx) # Update position
')
#endif
popa # Restore
ret # To caller
#
@ -441,7 +441,7 @@ gdtdesc: .word gdt.1-gdt-1 # Limit
m_logo: .asciz " \nBTX loader 1.00 "
m_vers: .asciz "BTX version is \0\n"
e_fmt: .asciz "Error: Client format not supported\n"
ifdef(`BTXLDR_VERBOSE',`
#ifdef BTXLDR_VERBOSE
m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
m_esp: .asciz "Arguments passed (esp=\0):\n"
m_args: .asciz"<howto="
@ -464,7 +464,7 @@ m_segs: .asciz "text segment: offset="
.asciz " filesz="
.asciz " memsz=\0\n"
m_done: .asciz "Loading complete\n"
')
#endif
#
# Uninitialized data area.
#

View File

@ -1,471 +0,0 @@
#
# Copyright (c) 1998 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$
#
# Prototype BTX loader program, written in a couple of hours. The
# real thing should probably be more flexible, and in C.
#
#
# Memory locations.
#
.set MEM_STUB,0x600 # Real mode stub
.set MEM_ESP,0x1000 # New stack pointer
.set MEM_TBL,0x5000 # BTX page tables
.set MEM_ENTRY,0x9010 # BTX entry point
.set MEM_DATA,start+0x1000 # Data segment
#
# Segment selectors.
#
.set SEL_SCODE,0x8 # 4GB code
.set SEL_SDATA,0x10 # 4GB data
.set SEL_RCODE,0x18 # 64K code
.set SEL_RDATA,0x20 # 64K data
#
# Paging constants.
#
.set PAG_SIZ,0x1000 # Page size
.set PAG_ENT,0x4 # Page entry size
#
# Screen constants.
#
ifdef(`PC98',`
.set SCR_MAT,0xe1 # Mode/attribute
',`
.set SCR_MAT,0x7 # Mode/attribute
')
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
ifdef(`PC98',`
.set BDA_MEM,0xa1501 # Free memory
.set BDA_POS,0xa153e # Cursor position
',`
.set BDA_MEM,0x413 # Free memory
.set BDA_SCR,0x449 # Video mode
.set BDA_POS,0x450 # Cursor position
')
#
# Required by aout gas inadequacy.
#
.set SIZ_STUB,0x1a # Size of stub
#
# We expect to be loaded by boot2 at the origin defined in ./Makefile.
#
.globl start
#
# BTX program loader for ELF clients.
#
start: cld # String ops inc
ifdef(`PC98',`
cli
gdcwait.1: inb $0x60,%al
testb $0x04,%al
jz gdcwait.1
movb $0xe0,%al
outb %al,$0x62
nop
gdcwait.2: inb $0x60,%al
testb $0x01,%al
jz gdcwait.2
inb $0x62,%al
movb %al,%dl
inb $0x62,%al
movb %al,%dh
inb $0x62,%al
inb $0x62,%al
inb $0x62,%al
shlw $1,%dx
movl $BDA_POS,%ebx
movw %dx,(%ebx)
')
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
ifdef(`PC98',`
andl $0x7,%eax
incl %eax
shll $0x11,%eax # in bytes
',`
shll $0xa,%eax # in bytes
')
movl %eax,%ebp # Base of user stack
ifdef(`BTXLDR_VERBOSE',`
movl $m_mem,%esi # Display
call hexout # amount of
call putstr # base memory
')
lgdt gdtdesc # Load new GDT
#
# Relocate caller's arguments.
#
ifdef(`BTXLDR_VERBOSE',`
movl $m_esp,%esi # Display
movl %esp,%eax # caller
call hexout # stack
call putstr # pointer
movl $m_args,%esi # Format string
leal 0x4(%esp,1),%ebx # First argument
movl $0x6,%ecx # Count
start.1: movl (%ebx),%eax # Get argument and
addl $0x4,%ebx # bump pointer
call hexout # Display it
loop start.1 # Till done
call putstr # End message
')
movl $0x48,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
movl 0x18(%esp,1),%esi # Source: bootinfo
cmpl $0x0, %esi # If the bootinfo pointer
je start_null_bi # is null, don't copy it
movl %ebp,%edi # Destination
rep # Copy
movsb # it
movl %ebp,0x18(%esp,1) # Update pointer
ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_bi,%esi # Display
movl %ebp,%eax # bootinfo
call hexout # relocation
call putstr # message
')
start_null_bi: movl $0x18,%ecx # Allocate space
subl %ecx,%ebp # for arguments
leal 0x4(%esp,1),%esi # Source
movl %ebp,%edi # Destination
rep # Copy
movsb # them
ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_args,%esi # Display
movl %ebp,%eax # argument
call hexout # relocation
call putstr # message
')
#
# Set up BTX kernel.
#
movl $MEM_ESP,%esp # Set up new stack
movl $MEM_DATA,%ebx # Data segment
movl $m_vers,%esi # Display BTX
call putstr # version message
movb 0x5(%ebx),%al # Get major version
addb $'0',%al # Display
call putchr # it
movb $'.',%al # And a
call putchr # dot
movb 0x6(%ebx),%al # Get minor
xorb %ah,%ah # version
movb $0xa,%dl # Divide
divb %dl,%al # by 10
addb $'0',%al # Display
call putchr # tens
movb %ah,%al # Get units
addb $'0',%al # Display
call putchr # units
call putstr # End message
movl %ebx,%esi # BTX image
movzwl 0x8(%ebx),%edi # Compute
orl $PAG_SIZ/PAG_ENT-1,%edi # the
incl %edi # BTX
shll $0x2,%edi # load
addl $MEM_TBL,%edi # address
pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
ifdef(`BTXLDR_VERBOSE',`
pushl %ecx # Save image size
')
rep # Relocate
movsb # BTX
movl %esi,%ebx # Keep place
ifdef(`BTXLDR_VERBOSE',`
movl $m_rel_btx,%esi # Restore
popl %eax # parameters
call hexout # and
')
popl %ebp # display
ifdef(`BTXLDR_VERBOSE',`
movl %ebp,%eax # the
call hexout # relocation
call putstr # message
')
addl $PAG_SIZ,%ebp # Display
ifdef(`BTXLDR_VERBOSE',`
movl $m_base,%esi # the
movl %ebp,%eax # user
call hexout # base
call putstr # address
')
#
# Set up ELF-format client program.
#
cmpl $0x464c457f,(%ebx) # ELF magic number?
je start.3 # Yes
movl $e_fmt,%esi # Display error
call putstr # message
start.2: jmp start.2 # Hang
start.3:
ifdef(`BTXLDR_VERBOSE',`
movl $m_elf,%esi # Display ELF
call putstr # message
movl $m_segs,%esi # Format string
')
movl $0x2,%edi # Segment count
movl 0x1c(%ebx),%edx # Get e_phoff
addl %ebx,%edx # To pointer
movzwl 0x2c(%ebx),%ecx # Get e_phnum
start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
jne start.6 # No
ifdef(`BTXLDR_VERBOSE',`
movl 0x4(%edx),%eax # Display
call hexout # p_offset
movl 0x8(%edx),%eax # Display
call hexout # p_vaddr
movl 0x10(%edx),%eax # Display
call hexout # p_filesz
movl 0x14(%edx),%eax # Display
call hexout # p_memsz
call putstr # End message
')
pushl %esi # Save
pushl %edi # working
pushl %ecx # registers
movl 0x4(%edx),%esi # Get p_offset
addl %ebx,%esi # as pointer
movl 0x8(%edx),%edi # Get p_vaddr
addl %ebp,%edi # as pointer
movl 0x10(%edx),%ecx # Get p_filesz
rep # Set up
movsb # segment
movl 0x14(%edx),%ecx # Any bytes
subl 0x10(%edx),%ecx # to zero?
jz start.5 # No
xorb %al,%al # Then
rep # zero
stosb # them
start.5: popl %ecx # Restore
popl %edi # working
popl %esi # registers
decl %edi # Segments to do
je start.7 # If none
start.6: addl $0x20,%edx # To next entry
loop start.4 # Till done
start.7:
ifdef(`BTXLDR_VERBOSE',`
movl $m_done,%esi # Display done
call putstr # message
')
movl $start.8,%esi # Real mode stub
movl $MEM_STUB,%edi # Destination
movl $start.9-start.8,%ecx # Size
rep # Relocate
movsb # it
ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
.code16
start.8: xorw %ax,%ax # Data
movb $SEL_RDATA,%al # selector
movw %ax,%ss # Reload SS
movw %ax,%ds # Reset
movw %ax,%es # other
movw %ax,%fs # segment
movw %ax,%gs # limits
movl %cr0,%eax # Switch to
decw %ax # real
movl %eax,%cr0 # mode
ljmp $0,$MEM_ENTRY # Jump to BTX entry point
start.9:
.code32
#
# Output message [ESI] followed by EAX in hex.
#
hexout: pushl %eax # Save
call putstr # Display message
popl %eax # Restore
pushl %esi # Save
pushl %edi # caller's
movl $buf,%edi # Buffer
pushl %edi # Save
call hex32 # To hex
xorb %al,%al # Terminate
stosb # string
popl %esi # Restore
hexout.1: lodsb # Get a char
cmpb $'0',%al # Leading zero?
je hexout.1 # Yes
testb %al,%al # End of string?
jne hexout.2 # No
decl %esi # Undo
hexout.2: decl %esi # Adjust for inc
call putstr # Display hex
popl %edi # Restore
popl %esi # caller's
ret # To caller
#
# Output zero-terminated string [ESI] to the console.
#
putstr.0: call putchr # Output char
putstr: lodsb # Load char
testb %al,%al # End of string?
jne putstr.0 # No
ret # To caller
#
# Output character AL to the console.
#
putchr: pusha # Save
xorl %ecx,%ecx # Zero for loops
movb $SCR_MAT,%ah # Mode/attribute
movl $BDA_POS,%ebx # BDA pointer
movw (%ebx),%dx # Cursor position
ifdef(`PC98',`
movl $0xa0000,%edi # Regen buffer (color)
',`
movl $0xb8000,%edi # Regen buffer (color)
cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
jne putchr.1 # No
xorw %di,%di # Regen buffer (mono)
')
putchr.1: cmpb $0xa,%al # New line?
je putchr.2 # Yes
ifdef(`PC98',`
movw %dx,%cx
movb %al,(%edi,%ecx,1) # Write char
addl $0x2000,%ecx
movb %ah,(%edi,%ecx,1) # Write attr
addw $0x2,%dx
jmp putchr.3
putchr.2: movw %dx,%ax
movb $SCR_COL*2,%dl
div %dl
incb %al
mul %dl
movw %ax,%dx
putchr.3: cmpw $SCR_COL*SCR_ROW*2,%dx
',`
xchgl %eax,%ecx # Save char
movb $SCR_COL,%al # Columns per row
mulb %dh # * row position
addb %dl,%al # + column
adcb $0x0,%ah # position
shll %eax # * 2
xchgl %eax,%ecx # Swap char, offset
movw %ax,(%edi,%ecx,1) # Write attr:char
incl %edx # Bump cursor
cmpb $SCR_COL,%dl # Beyond row?
jb putchr.3 # No
putchr.2: xorb %dl,%dl # Zero column
incb %dh # Bump row
putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
')
jb putchr.4 # No
leal 2*SCR_COL(%edi),%esi # New top line
movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
rep # Scroll
movsl # screen
movb $' ',%al # Space
ifdef(`PC98',`
xorb %ah,%ah
')
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
ifdef(`PC98',`
movw $(SCR_ROW-1)*SCR_COL*2,%dx
putchr.4: movw %dx,(%ebx) # Update position
shrw $1,%dx
gdcwait.3: inb $0x60,%al
testb $0x04,%al
jz gdcwait.3
movb $0x49,%al
outb %al,$0x62
movb %dl,%al
outb %al,$0x60
movb %dh,%al
outb %al,$0x60
',`
movb $SCR_ROW-1,%dh # Bottom line
putchr.4: movw %dx,(%ebx) # Update position
')
popa # Restore
ret # To caller
#
# Convert EAX, AX, or AL to hex, saving the result to [EDI].
#
hex32: pushl %eax # Save
shrl $0x10,%eax # Do upper
call hex16 # 16
popl %eax # Restore
hex16: call hex16.1 # Do upper 8
hex16.1: xchgb %ah,%al # Save/restore
hex8: pushl %eax # Save
shrb $0x4,%al # Do upper
call hex8.1 # 4
popl %eax # Restore
hex8.1: andb $0xf,%al # Get lower 4
cmpb $0xa,%al # Convert
sbbb $0x69,%al # to hex
das # digit
orb $0x20,%al # To lower case
stosb # Save char
ret # (Recursive)
.data
.p2align 4
#
# Global descriptor table.
#
gdt: .word 0x0,0x0,0x0,0x0 # Null entry
.word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
.word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
.word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
.word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
gdt.1:
gdtdesc: .word gdt.1-gdt-1 # Limit
.long gdt # Base
#
# Messages.
#
m_logo: .asciz " \nBTX loader 1.00 "
m_vers: .asciz "BTX version is \0\n"
e_fmt: .asciz "Error: Client format not supported\n"
ifdef(`BTXLDR_VERBOSE',`
m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
m_esp: .asciz "Arguments passed (esp=\0):\n"
m_args: .asciz"<howto="
.asciz" bootdev="
.asciz" junk="
.asciz" "
.asciz" "
.asciz" bootinfo=\0>\n"
m_rel_bi: .asciz "Relocated bootinfo (size=48) to \0\n"
m_rel_args: .asciz "Relocated arguments (size=18) to \0\n"
m_rel_btx: .asciz "Relocated kernel (size=\0) to \0\n"
m_base: .asciz "Client base address is \0\n"
m_elf: .asciz "Client format is ELF\n"
m_segs: .asciz "text segment: offset="
.asciz " vaddr="
.asciz " filesz="
.asciz " memsz=\0\n"
.asciz "data segment: offset="
.asciz " vaddr="
.asciz " filesz="
.asciz " memsz=\0\n"
m_done: .asciz "Loading complete\n"
')
#
# Uninitialized data area.
#
buf: # Scratch buffer