Primary boot for ustarfs.

Supports floppy only.
This commit is contained in:
minoura 2001-09-28 15:22:21 +00:00
parent 446e0c768b
commit d83cae1ca8
3 changed files with 279 additions and 0 deletions

View File

@ -0,0 +1,54 @@
# $NetBSD: Makefile,v 1.1 2001/09/28 15:22:21 minoura Exp $
.include <bsd.own.mk>
BOOT= boot_ustar
VERSION=1.0
# text and bss addresses in hex
TEXT= 002000 # Primary (me)
BOOT_TEXT= 006000 # Secondary (/boot)
PROG= $(BOOT)
BINDIR= /usr/mdec
STRIPFLAG=
BINMODE= 444
MKMAN= no
OBJCOPY?= objcopy
COMMONDIR= ${.CURDIR}/../common
LIBIOCS= ${.CURDIR}/../libiocs
#.PATH: ${COMMONDIR}
#SRCS= boot_ustar.S exec_image.S
SRCS= boot_ustar.S
CPPFLAGS+= -DTEXTADDR="0x$(TEXT)" -DBOOT_TEXTADDR="0x$(BOOT_TEXT)"
CPPFLAGS+= -DBOOT=\"$(BOOT)\" -DBOOT_VERS=\"$(VERSION)\"
CPPFLAGS+= -I${COMMONDIR} -I${LIBIOCS}
AFLAGS= ${CFLAGS:M-[ID]*}
.if ${OBJECT_FMT} == "ELF"
LDFLAGS= -n -Bstatic -T ${.CURDIR}/${BOOT}.ldscript
LDFLAGS+= -noinhibit-exec # XXX
.else
LDFLAGS= -n -Bstatic -Ttext ${TEXT}
.endif
CLEANFILES= $(BOOT).x s.x x.s x.o
$(BOOT): $(OBJS)
$(LD) $(LDFLAGS) -o $(BOOT).x $(OBJS) $(LDADD)
@$(NM) --target=a.out-m68k-netbsd $(BOOT).x | sed -n '/T first_kbyte/p'
@if [ `(echo ibase=16; \
$(NM) --target=a.out-m68k-netbsd $(BOOT).x | sed -n 's/T first_kbyte/-$(TEXT)-400/p' | \
tr a-f A-F) | bc` -gt 0 ];\
then echo '$(BOOT): first_kbyte exceeds the first killobyte'; exit 1; fi
@$(SIZE) --target=a.out-m68k-netbsd $(BOOT).x
@if [ `(echo ibase=16; \
$(NM) --target=a.out-m68k-netbsd $(BOOT).x | sed -n 's/D _edata/-$(TEXT)-2000/p' | tr a-f A-F) |\
bc` -gt 0 ];\
then echo '$(BOOT): text+data is too large'; exit 1; fi
@$(OBJCOPY) -I a.out-m68k-netbsd -O binary $(BOOT).x $(BOOT)
.include <bsd.prog.mk>

View File

@ -0,0 +1,176 @@
| file: boot_ustar.S
| author: chapuni(webmaster@chapuni.com)
| Yasha(itohy@netbsd.org)
| minoura@netbsd.org
|
| $NetBSD: boot_ustar.S,v 1.1 2001/09/28 15:22:22 minoura Exp $
| supports floppy only
#include <sys/reboot.h>
#include <machine/asm.h>
#include <machine/bootinfo.h>
#include "iocscall.h"
#define BOOT_ERROR(s) jbsr boot_error; .asciz s; .even
#define READ_BUFFER 0x000e0000
.text
ASENTRY_NOPROFILE(start)
ASENTRY_NOPROFILE(top)
bras _ASM_LABEL(entry0)
.ascii "SHARP/"
.ascii "X680x0"
.word 0x8199,0x94e6,0x82ea,0x82bd
.word 0x8e9e,0x82c9,0x82cd,0x8cbb
.word 0x8ec0,0x93a6,0x94f0,0x8149
.word 0
ASENTRY_NOPROFILE(entry0)
IOCS(__BOOTINF)
lsll #8,%d0 | clear MSByte
lsrl #8,%d0 |
|
| 0x80...0x8F SASI
| 0x90...0x93 Floppy
| 0xED0000...0xED3FFE SRAM
| others ROM (SCSI?)
|
movel %d0,%d1
clrb %d1
tstl %d1
jne boot_dev_unsupported
bra _ASM_LABEL(entry)
| Disklabel= 404bytes
| Since LABELLOFFSET in <machine/disklabel.h> is 0x40,
| entry must be after 0x000001d4 (0x000021d4)
nop
GLOBAL(disklabel)
.space 404
ASENTRY_NOPROFILE(entry)
|
| SASI or Floppy
|
movel %d0,%d4
andib #0xFC,%d0
cmpib #0x90,%d0
jne boot_dev_unsupported | boot from SASI?
|
| Floppy
| read first 64KB (XXX: CONSTANT!!)
|
andib #0x03,%d0 | drive # (head=0)
jbsr check_fd_format
moveb %d4,%d2
lslw #8,%d2
moveq #0x70,%d1
orw %d2,%d1 | PDA*256 + MODE
movel %d0,%d2 | read position (first sector)
movel #65536,%d3 | read bytes
moval #(BOOT_TEXTADDR-8192-0x200-32),%a1
moval %a1,%a4 | save buffer addr
IOCS(__B_READ)
jra boot_read_done
#include "chkfmt.s"
boot_dev_unsupported:
BOOT_ERROR("unsupported boot device")
booterr_msg: .ascii "\r\n\n"
.ascii BOOT
.asciz ": "
reboot_msg: .asciz "\r\n[Hit key to reboot]"
.even
ASENTRY_NOPROFILE(boot_error)
lea %pc@(booterr_msg),%a1
IOCS(__B_PRINT)
moveal %sp@+,%a1
IOCS(__B_PRINT)
lea %pc@(reboot_msg),%a1
IOCS(__B_PRINT)
| wait for a key press (or release of a modifier)
IOCS(__B_KEYINP)
| issue software reset
trap #10
| NOTREACHED
boot_read_done:
lea %a4@(8192),%a1 | USTAR header
#if 0 /* too big to fit */
cmpl #0x55535441,%a1@ | filename `USTA
bne error_invalidname
#endif
cmpl #0x522e766f,%a1@(4) | R.vo...'
bne error_invalidname
cmpl #0x00757374,%a1@(256) | magic `\0ust'
bne error_invalidfs
cmpl #0x61722020,%a1@(260) | magic `ar '
bne error_invalidfs
lea %a1@(0x200),%a2 | a.out header
movml %a2@+,%d0-%d4/%a5
addal #8,%a2 | start of text
#if 0
cmpal #BOOT_TEXTADDR,%a5
bne error_invalidboot
#endif
cmpl #0x00870107,%d0 | a.out magic
bne error_invalidmagic
addl %d2,%d1 | a_text+a_data
movl %d3,%d4 | save a_bss
addl %d1,%d3 | a_text+a_data+a_bss
/* clear out bss */
lea %a2@(%d1),%a3
1: movb #0,%a3@+
subl #1,%d4
bne 1b
andil #3,%d4
swap %d4
addil #(B_DEVMAGIC+X68K_MAJOR_FD),%d4
movl #RB_SINGLE,%sp@- | boothowto
movl %d4,%sp@- | bootdev
movl %d3,%sp@- | size
pea %a5@ | entry
pea %a5@ | executed
pea %a5@ | loaded
jbsr _C_LABEL(exec_image)
error_invalidname:
error_invalidfs:
error_invalidmagic: BOOT_ERROR("Invalid boot disk")
|
| void memcpy(void *dst, const void *src, size_t count);
|
| small and slow memcpy...
| THIS FUNCTION DOES NOT CONFORM THE ANSI STANDARD
|
ENTRY_NOPROFILE(memcpy)
lea %sp@(12),%a1
movel %a1@,%d1 | count
| jeq Lmcpret
moveal %a1@-,%a0 | src
moveal %a1@-,%a1 | dest
1: moveb %a0@+,%a1@+
subql #1,%d1
jne 1b
Lmcpret:
| movel %sp@(8),%d0 | uncomment this to conform ANSI
rts
#include "exec_image.S"
ASGLOBAL(first_kbyte)

View File

@ -0,0 +1,49 @@
OUTPUT_FORMAT("a.out-m68k-netbsd", "a.out-m68k-netbsd",
"a.out-m68k-netbsd")
OUTPUT_ARCH(m68k)
ENTRY(start)
SEARCH_DIR(/usr/lib);
/*__DYNAMIC = 0; */
PROVIDE (__stack = 0);
SECTIONS
{
. = 0x00002000;
.text :
{
CREATE_OBJECT_SYMBOLS
*(.text)
*(.rodata)
/* The next six sections are for SunOS dynamic linking. The order
is important. */
*(.dynrel)
*(.hash)
*(.dynsym)
*(.dynstr)
*(.rules)
*(.need)
etext = .;
_etext = .;
}
/* . = ALIGN(0x2000); */
.data :
{
/* The first three sections are for SunOS dynamic linking. */
*(.dynamic)
*(.got)
*(.plt)
*(.data)
*(.linux-dynamic) /* For Linux dynamic linking. */
CONSTRUCTORS
edata = .;
_edata = .;
}
.bss :
{
__bss_start = .;
*(.bss)
*(COMMON)
end = ALIGN(4) ;
_end = ALIGN(4) ;
}
/DISCARD/ : { *(.ident) *(.stab) *(.stabstr) }
}