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

(John tells me there were problems when trying this before,
but it appears to be safe these day.)

OK'ed by:	jhb
Repocopied by:	joe
This commit is contained in:
Ruslan Ermilov 2004-02-11 08:42:38 +00:00
parent 3102ccf30c
commit 846a4356ea
9 changed files with 53 additions and 1925 deletions

View File

@ -3,13 +3,11 @@
PROG= btx.out
INTERNALPROG=
NOMAN=
SRCS= btx.s
SRCS= btx.S
CLEANFILES= btx
M4?= m4
.if defined(PAGING)
M4FLAGS+= -DPAGING
CFLAGS+=-DPAGING
.endif
.if defined(BOOT_BTX_NOHANG)
@ -18,15 +16,15 @@ BOOT_BTX_FLAGS=0x1
BOOT_BTX_FLAGS=0x0
.endif
AFLAGS+= --defsym BTX_FLAGS=${BOOT_BTX_FLAGS}
CFLAGS+=-DBTX_FLAGS=${BOOT_BTX_FLAGS}
.if defined(BTX_SERIAL)
BOOT_COMCONSOLE_PORT?= 0x3f8
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
@ -38,8 +36,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

@ -158,7 +158,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.
#
@ -191,25 +191,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
@ -240,9 +240,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
@ -860,13 +860,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
@ -970,7 +970,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
@ -1043,7 +1043,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.
#
@ -1085,7 +1085,7 @@ putchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
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,13 @@
PROG= btxldr.out
INTERNALPROG=
NOMAN=
SRCS= btxldr.s
SRCS= btxldr.S
CLEANFILES= btxldr
M4?= m4
M4FLAGS+= -DLOADER_ADDRESS=${LOADER_ADDRESS}
CFLAGS+=-DLOADER_ADDRESS=${LOADER_ADDRESS}
.if defined(BTXLDR_VERBOSE)
M4FLAGS+= -DBTXLDR_VERBOSE
CFLAGS+=-DBTXLDR_VERBOSE
.endif
all: btxldr
@ -20,8 +19,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

@ -69,16 +69,16 @@ start: cld # String ops inc
movzwl BDA_MEM,%eax # Get base memory
shll $0xa,%eax # in bytes
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
@ -91,7 +91,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
@ -101,24 +101,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.
#
@ -149,30 +149,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.
#
@ -182,18 +182,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
@ -203,7 +203,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
@ -228,10 +228,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
@ -366,7 +366,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="
@ -389,7 +389,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,396 +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.
#
.set SCR_MAT,0x7 # Mode/attribute
.set SCR_COL,0x50 # Columns per row
.set SCR_ROW,0x19 # Rows per screen
#
# BIOS Data Area locations.
#
.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
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
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
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
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
movb $SCR_COL,%cl # Columns to clear
rep # Clear
stosw # line
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

View File

@ -7,21 +7,20 @@ PROG= ${LDR}.out
INTERNALPROG=
FILES= ${BOOT}
MAN= ${BOOT}.8
SRCS= ${LDR}.s
SRCS= ${LDR}.S
CLEANFILES= ${BOOT}
BOOT= pxeboot
LDR= pxeldr
ORG= 0x7c00
LOADER= loader
M4?= m4
.if defined(BOOT_PXELDR_PROBE_KEYBOARD)
M4FLAGS+= -DPROBE_KEYBOARD
CFLAGS+=-DPROBE_KEYBOARD
.endif
.if defined(BOOT_PXELDR_ALWAYS_SERIAL)
M4FLAGS+= -DALWAYS_SERIAL
CFLAGS+=-DALWAYS_SERIAL
.endif
LOADERBIN= ${.OBJDIR}/../loader/loader.bin
@ -40,10 +39,6 @@ ${LDR}: ${LDR}.out
LDFLAGS+= -N -e start -Ttext ${ORG}
${LDR}.o: ${LDR}.s
(cd ${.CURDIR}; ${M4} ${M4FLAGS} ${LDR}.s) | \
${AS} ${AFLAGS} -o ${.TARGET}
CLEANFILES+= ${LOADER}
${LOADER}: ${LOADERBIN} ${BTXLDR} ${BTXKERN}

View File

@ -110,12 +110,12 @@ start: cld # string ops inc
orb $KARGS_FLAGS_PXE, 0x8(%bx) # kargs->bootflags |=
# KARGS_FLAGS_PXE
popl 0xc(%bx) # kargs->pxeinfo = *PXENV+
ifdef(`ALWAYS_SERIAL',`
#ifdef ALWAYS_SERIAL
#
# set the RBX_SERIAL bit in the howto byte.
orl $RB_SERIAL, (%bx) # enable serial console
')
ifdef(`PROBE_KEYBOARD',`
#endif
#ifdef PROBE_KEYBOARD
#
# Look at the BIOS data area to see if we have an enhanced keyboard. If not,
# set the RBX_SERIAL bit in the howto byte.
@ -123,7 +123,7 @@ ifdef(`PROBE_KEYBOARD',`
jnz keyb # yes, so skip
orl $RB_SERIAL, (%bx) # enable serial console
keyb:
')
#endif
#
# Turn on the A20 address line
#

View File

@ -1,287 +0,0 @@
#
# Copyright (c) 2000 John Baldwin
# 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$
#
# This simple program is a preloader for the normal boot3 loader. It is simply
# prepended to the beginning of a fully built and btxld'd loader. It then
# copies the loader to the address boot2 normally loads it, emulates the
# boot[12] environment (protected mode, a bootinfo struct, etc.), and then jumps
# to the start of btxldr to start the boot process. This method allows a stock
# /boot/loader to be booted over the network via PXE w/o having to write a
# separate PXE-aware client just to load the loader.
#
#
# Memory locations.
#
.set MEM_PAGE_SIZE,0x1000 # memory page size, 4k
.set MEM_ARG,0x900 # Arguments at start
.set MEM_ARG_BTX,0xa100 # Where we move them to so the
# BTX client can see them
.set MEM_ARG_SIZE,0x18 # Size of the arguments
.set MEM_BTX_ADDRESS,0x9000 # where BTX lives
.set MEM_BTX_ENTRY,0x9010 # where BTX starts to execute
.set MEM_BTX_OFFSET,MEM_PAGE_SIZE # offset of BTX in the loader
.set MEM_BTX_CLIENT,0xa000 # where BTX clients live
.set MEM_BIOS_KEYBOARD,0x496 # BDA byte with keyboard bit
#
# a.out header fields
#
.set AOUT_TEXT,0x04 # text segment size
.set AOUT_DATA,0x08 # data segment size
.set AOUT_BSS,0x0c # zero'd BSS size
.set AOUT_SYMBOLS,0x10 # symbol table
.set AOUT_ENTRY,0x14 # entry point
.set AOUT_HEADER,MEM_PAGE_SIZE # size of the a.out header
#
# Flags for kargs->bootflags
#
.set KARGS_FLAGS_PXE,0x2 # flag to indicate booting from
# PXE loader
#
# Boot howto bits
#
.set RB_SERIAL,0x1000 # serial console
#
# Segment selectors.
#
.set SEL_SDATA,0x8 # Supervisor data
.set SEL_RDATA,0x10 # Real mode data
.set SEL_SCODE,0x18 # PM-32 code
.set SEL_SCODE16,0x20 # PM-16 code
#
# BTX constants
#
.set INT_SYS,0x30 # BTX syscall interrupt
#
# Bit in MEM_BIOS_KEYBOARD that is set if an enhanced keyboard is present
#
.set KEYBOARD_BIT,0x10
#
# We expect to be loaded by the BIOS at 0x7c00 (standard boot loader entry
# point)
#
.code16
.globl start
.org 0x0, 0x0
#
# BTX program loader for PXE network booting
#
start: cld # string ops inc
xorw %ax, %ax # zero %ax
movw %ax, %ss # setup the
movw $start, %sp # stack
movw %es, %cx # save PXENV+ segment
movw %ax, %ds # setup the
movw %ax, %es # data segments
andl $0xffff, %ecx # clear upper words
andl $0xffff, %ebx # of %ebx and %ecx
shll $4, %ecx # calculate the offset of
addl %ebx, %ecx # the PXENV+ struct and
pushl %ecx # save it on the stack
movw $welcome_msg, %si # %ds:(%si) -> welcome message
callw putstr # display the welcome message
#
# Setup the arguments that the loader is expecting from boot[12]
#
movw $bootinfo_msg, %si # %ds:(%si) -> boot args message
callw putstr # display the message
movw $MEM_ARG, %bx # %ds:(%bx) -> boot args
movw %bx, %di # %es:(%di) -> boot args
xorl %eax, %eax # zero %eax
movw $(MEM_ARG_SIZE/4), %cx # Size of arguments in 32-bit
# dwords
rep # Clear the arguments
stosl # to zero
orb $KARGS_FLAGS_PXE, 0x8(%bx) # kargs->bootflags |=
# KARGS_FLAGS_PXE
popl 0xc(%bx) # kargs->pxeinfo = *PXENV+
ifdef(`ALWAYS_SERIAL',`
#
# set the RBX_SERIAL bit in the howto byte.
orl $RB_SERIAL, (%bx) # enable serial console
')
ifdef(`PROBE_KEYBOARD',`
#
# Look at the BIOS data area to see if we have an enhanced keyboard. If not,
# set the RBX_SERIAL bit in the howto byte.
testb $KEYBOARD_BIT, MEM_BIOS_KEYBOARD # keyboard present?
jnz keyb # yes, so skip
orl $RB_SERIAL, (%bx) # enable serial console
keyb:
')
#
# Turn on the A20 address line
#
callw seta20 # Turn A20 on
#
# Relocate the loader and BTX using a very lazy protected mode
#
movw $relocate_msg, %si # Display the
callw putstr # relocation message
movl end+AOUT_ENTRY, %edi # %edi is the destination
movl $(end+AOUT_HEADER), %esi # %esi is
# the start of the text
# segment
movl end+AOUT_TEXT, %ecx # %ecx = length of the text
# segment
lgdt gdtdesc # setup our own gdt
cli # turn off interrupts
movl %cr0, %eax # Turn on
orb $0x1, %al # protected
movl %eax, %cr0 # mode
ljmp $SEL_SCODE,$pm_start # long jump to clear the
# instruction pre-fetch queue
.code32
pm_start: movw $SEL_SDATA, %ax # Initialize
movw %ax, %ds # %ds and
movw %ax, %es # %es to a flat selector
rep # Relocate the
movsb # text segment
addl $(MEM_PAGE_SIZE - 1), %edi # pad %edi out to a new page
andl $~(MEM_PAGE_SIZE - 1), %edi # for the data segment
movl end+AOUT_DATA, %ecx # size of the data segment
rep # Relocate the
movsb # data segment
movl end+AOUT_BSS, %ecx # size of the bss
xorl %eax, %eax # zero %eax
addb $3, %cl # round %ecx up to
shrl $2, %ecx # a multiple of 4
rep # zero the
stosl # bss
movl end+AOUT_ENTRY, %esi # %esi -> relocated loader
addl $MEM_BTX_OFFSET, %esi # %esi -> BTX in the loader
movl $MEM_BTX_ADDRESS, %edi # %edi -> where BTX needs to go
movzwl 0xa(%esi), %ecx # %ecx -> length of BTX
rep # Relocate
movsb # BTX
ljmp $SEL_SCODE16,$pm_16 # Jump to 16-bit PM
.code16
pm_16: movw $SEL_RDATA, %ax # Initialize
movw %ax, %ds # %ds and
movw %ax, %es # %es to a real mode selector
movl %cr0, %eax # Turn off
andb $~0x1, %al # protected
movl %eax, %cr0 # mode
ljmp $0,$pm_end # Long jump to clear the
# instruction pre-fetch queue
pm_end: sti # Turn interrupts back on now
#
# Copy the BTX client to MEM_BTX_CLIENT
#
xorw %ax, %ax # zero %ax and set
movw %ax, %ds # %ds and %es
movw %ax, %es # to segment 0
movw $MEM_BTX_CLIENT, %di # Prepare to relocate
movw $btx_client, %si # the simple btx client
movw $(btx_client_end-btx_client), %cx # length of btx client
rep # Relocate the
movsb # simple BTX client
#
# Copy the boot[12] args to where the BTX client can see them
#
movw $MEM_ARG, %si # where the args are at now
movw $MEM_ARG_BTX, %di # where the args are moving to
movw $(MEM_ARG_SIZE/4), %cx # size of the arguments in longs
rep # Relocate
movsl # the words
#
# Save the entry point so the client can get to it later on
#
movl end+AOUT_ENTRY, %eax # load the entry point
stosl # add it to the end of the
# arguments
#
# Now we just start up BTX and let it do the rest
#
movw $jump_message, %si # Display the
callw putstr # jump message
ljmp $0,$MEM_BTX_ENTRY # Jump to the BTX entry point
#
# Display a null-terminated string
#
putstr: lodsb # load %al from %ds:(%si)
testb %al,%al # stop at null
jnz putc # if the char != null, output it
retw # return when null is hit
putc: movw $0x7,%bx # attribute for output
movb $0xe,%ah # BIOS: put_char
int $0x10 # call BIOS, print char in %al
jmp putstr # keep looping
#
# Enable A20
#
seta20: cli # Disable interrupts
seta20.1: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.1 # Yes
movb $0xd1,%al # Command: Write
outb %al,$0x64 # output port
seta20.2: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.2 # Yes
movb $0xdf,%al # Enable
outb %al,$0x60 # A20
sti # Enable interrupts
retw # To caller
#
# BTX client to start btxldr
#
.code32
btx_client: movl $(MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE-4), %esi
# %ds:(%esi) -> end
# of boot[12] args
movl $(MEM_ARG_SIZE/4), %ecx # Number of words to push
std # Go backwards
push_arg: lodsl # Read argument
pushl %eax # Push it onto the stack
loop push_arg # Push all of the arguments
cld # In case anyone depends on this
pushl MEM_ARG_BTX-MEM_BTX_CLIENT+MEM_ARG_SIZE # Entry point of
# the loader
pushl %eax # Emulate a near call
movl $0x1, %eax # 'exec' system call
int $INT_SYS # BTX system call
btx_client_end:
.code16
.p2align 4
#
# Global descriptor table.
#
gdt: .word 0x0,0x0,0x0,0x0 # Null entry
.word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
.word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
.word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE (32-bit)
.word 0xffff,0x0,0x9a00,0x8f # SEL_SCODE16 (16-bit)
gdt.1:
#
# Pseudo-descriptors.
#
gdtdesc: .word gdt.1-gdt-1 # Limit
.long gdt # Base
welcome_msg: .asciz "PXE Loader 1.00\r\n\n"
bootinfo_msg: .asciz "Building the boot loader arguments\r\n"
relocate_msg: .asciz "Relocating the loader and the BTX\r\n"
jump_message: .asciz "Starting the BTX loader\r\n"
.p2align 4
end: