Convert btx/lib and do additional cleanups. Again no operational changes.
# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
-# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.7 2004/07/18 23:40:01 dillon Exp $
+# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.8 2004/07/19 01:24:58 dillon Exp $
PROG= boot2
NOMAN=
BTX= ${.CURDIR}/../btx
.endif
+# WARNING! These constants are also defined in bootasm.h
+#
REL1= 0x700
ORG1= 0x7c00
+
+# WARNING! The ORG2 calculation is the origin of boot2.bin relative to
+# the start of the BTX *USER* address space, not the start of physical
+# memory.
+#
ORG2= 0x2000
# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
* purpose.
*
* $FreeBSD: src/sys/boot/i386/boot2/boot1.s,v 1.23 2003/08/22 01:59:28 imp Exp $
- * $DragonFly: src/sys/boot/i386/boot2/Attic/boot1.S,v 1.5 2004/07/18 23:40:01 dillon Exp $
+ * $DragonFly: src/sys/boot/i386/boot2/Attic/boot1.S,v 1.6 2004/07/19 01:24:58 dillon Exp $
*/
#include "../bootasm.h"
movb $0x1,%dh // Block count
callw nread // Read MBR
mov $0x1,%cx // Two passes
-main.1: mov $MEM_BUF+PRT_OFF,%si // Partition table
+main.1: mov $BOOT2_LOAD_BUF+PRT_OFF,%si // Partition table
movb $0x1,%dh // Partition
main.2: cmpb $PRT_BSD,0x4(%si) // Our partition type?
jne main.3 // No
//
// Ok, we have a slice and drive in %dx now, so use that to locate and load
// boot2. %si references the start of the slice we are looking for, so go
-// ahead and load up the first 16 sectors (boot1 + boot2) from that. When
-// we read it in, we conveniently use 0x8c00 as our transfer buffer. Thus,
-// boot1 ends up at 0x8c00, and boot2 starts at 0x8c00 + 0x200 = 0x8e00.
+// ahead and load up the first 16 sectors (boot1 + boot2) from that.
+//
+// When we read it in, we conveniently use BOOT2_LOAD_BUF (0x8c00) as our
+// transfer buffer. Thus, boot1 ends up at 0x8c00, and boot2 starts at
+// 0x8c00 + 0x200 = 0x8e00.
+//
// The first part of boot2 is the disklabel, which is 0x200 bytes long.
// The second part is BTX, which is thus loaded into 0x9000, which is where
// it also runs from. The boot2.bin binary starts right after the end of
// BTX, so we have to figure out where the start of it is and then move the
-// binary to 0xc000. Normally, BTX clients start at MEM_USR, or 0xa000, but
-// when we use btxld to create boot2, we use an entry point of 0x2000. That
-// entry point is relative to MEM_USR; thus boot2.bin starts at 0xc000.
+// binary to 0xc000. Normally, BTX clients start at MEM_BTX_USR, or 0xa000,
+// but when we use btxld to create boot2, we use an entry point of 0x2000.
+// That entry point is relative to MEM_BTX_USR; thus boot2.bin starts
+// at 0xc000.
//
main.5: mov %dx,MEM_ARG // Save args
movb $NSECT,%dh // Sector count
callw nread // Read disk
- mov $MEM_BTX,%bx // BTX
+ mov $MEM_BTX_ORG,%bx // BTX
mov 0xa(%bx),%si // Get BTX length and set
add %bx,%si // %si to start of boot2.bin
- mov $MEM_USR+SIZ_PAG*2,%di // Client page 2
- mov $MEM_BTX+(NSECT-1)*SIZ_SEC,%cx // Byte
+ mov $MEM_BTX_USR+SIZ_PAG*2,%di // Client page 2
+ mov $MEM_BTX_ORG+(NSECT-1)*SIZ_SEC,%cx // Byte
sub %si,%cx // count
rep // Relocate
movsb // client
rep // the end of boot2.bin
stosb // up to 0x10000
callw seta20 // Enable A20
- jmp start+MEM_JMP-MEM_ORG // Start BTX
+ jmp start+MEM_BTX_ENTRY-MEM_ORG // Start BTX
//
// Enable A20 so we can access memory above 1 meg.
//
//
// Trampoline used to call read from within boot1.
//
-nread: mov $MEM_BUF,%bx // Transfer buffer
+nread: mov $BOOT2_LOAD_BUF,%bx // Transfer buffer
mov 0x8(%si),%ax // Get
mov 0xa(%si),%cx // LBA
push %cs // Read from
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $DragonFly: src/sys/boot/i386/Attic/bootasm.h,v 1.1 2004/07/18 23:39:55 dillon Exp $
+ * $DragonFly: src/sys/boot/i386/Attic/bootasm.h,v 1.2 2004/07/19 01:24:57 dillon Exp $
*/
+/*
+ * NOTE: MEM_REL and MEM_ORG also defined in boot2/Makefile
+ */
#define NHRDRV 0x475
#define BOOT0_ORIGIN 0x600 /* boot0 relocated */
#define FAKE 0x800 /* Fake partition entry */
#define LOAD 0x7c00 /* Load address */
-
+#define BOOTINFO_SIZE 0x48 /* bootinfo structure size */
#define MEM_ARG_SIZE 0x18
#define MEM_PAGE_SIZE 0x1000
+#define USR_ARGSPACE 0x1000 /* BTX loader / ttl argspace reserved */
+#define USR_ARGOFFSET (BOOTINFO_SIZE+MEM_ARG_SIZE)
#define MEM_REL 0x700 /* Relocation address */
#define MEM_ARG 0x900 /* Arguments */
#define MEM_ORG 0x7c00 /* Origin */
-#define MEM_BUF 0x8c00 /* Load area */
-#define MEM_BTX 0x9000 /* BTX start */
-#define MEM_JMP 0x9010 /* BTX entry point */
-#define MEM_USR 0xa000 /* Client start */
+
#define BDA_BOOT 0x472 /* Boot howto flag */
#define BDA_MEM 0x413 /* Free memory */
#define BDA_KEYFLAGS 0x417 /* Keyboard shift-state flags */
#define BDA_POS 0x450 /* Cursor position */
#define BDA_KEYBOARD 0x496 /* BDA byte with keyboard bit */
+#define MEM_BTX_ESP 0x1000 /* btxldr top of stack? */
#define MEM_BTX_START 0x1000 /* start of BTX memory */
#define MEM_BTX_ESP0 0x1800 /* Supervisor stack */
#define MEM_BTX_BUF 0x1800 /* Scratch buffer stack */
#define MEM_BTX_TSS 0x1f98 /* TSS */
#define MEM_BTX_MAP 0x2000 /* I/O bit map */
#define MEM_BTX_DIR 0x4000 /* Page directory */
+
+/*
+ * NOTE: page table location is hardwired in /usr/src/usr.sbin/btxld/btx.h
+ */
#define MEM_BTX_TBL 0x5000 /* Page tables */
+
+/*
+ * NOTE: BOOT2_LOAD_BUF also determines where the btx loader and boot2.bin
+ * code are loaded, since they are all in the boot2 file.
+ */
+#define BOOT2_LOAD_BUF 0x8c00 /* boot1 loads boot2 */
#define MEM_BTX_ORG 0x9000 /* base of BTX code */
#define MEM_BTX_ENTRY 0x9010 /* BTX starts execution here */
#define MEM_BTX_USR 0xa000 /* base of BTX client/user memory */
#define MEM_BTX_USR_ARG 0xa100
-#define MEM_BTX_LDR_OFF MEM_PAGE_SIZE /* offset of btx in the loader
-
-/*
- * CDBOOT
- */
-#define MEM_BTX_LDR_OFFSET 0x1000 /* Offset of BTX in the loader */
+#define MEM_BTX_LDR_OFF MEM_PAGE_SIZE /* offset of btx in the loader */
* purpose.
*
* $FreeBSD: src/sys/boot/i386/btx/btx/btx.s,v 1.32 2002/10/08 18:19:02 jhb Exp $
- * $DragonFly: src/sys/boot/i386/btx/btx/Attic/btx.S,v 1.5 2004/07/18 23:40:04 dillon Exp $
+ * $DragonFly: src/sys/boot/i386/btx/btx/Attic/btx.S,v 1.6 2004/07/19 01:25:00 dillon Exp $
*/
#include "../../bootasm.h"
*/
movb $SEL_TSS,%cl # Set task
ltr %cx # register
+ /*
+ * XXX We should NOT use BDA_MEM here. Use a fixed location
+ * instead.
+ */
movl $MEM_BTX_USR,%edx # User base address
movzwl %ss:BDA_MEM,%eax # Get free memory
shll $0xa,%eax # To bytes
- subl $0x1000,%eax # Less arg space
+ subl $USR_ARGSPACE,%eax # Less arg space
subl %edx,%eax # Less base
movb $SEL_UDATA,%cl # User data selector
pushl %ecx # Set SS
* purpose.
*
* $FreeBSD: src/sys/boot/i386/btx/btxldr/Makefile,v 1.17 2004/04/27 19:45:16 ru Exp $
- * $DragonFly: src/sys/boot/i386/btx/btxldr/Attic/btxldr.S,v 1.1 2004/06/25 00:38:38 dillon Exp $
+ * $DragonFly: src/sys/boot/i386/btx/btxldr/Attic/btxldr.S,v 1.2 2004/07/19 01:25:01 dillon Exp $
*/
/*
* real thing should probably be more flexible, and in C.
*/
+#include "../../bootasm.h"
/*
* 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 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.
*/
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
- shll $0xa,%eax # in bytes
+ shll $0xa,%eax # Convert to bytes
movl %eax,%ebp # Base of user stack
#ifdef BTXLDR_VERBOSE
movl $m_mem,%esi # Display
loop start.1 # Till done
call putstr # End message
#endif
- movl $0x48,%ecx # Allocate space
+ /*
+ * Arguments: (entry, boothowto, bootdev, 0, 0, 0, bootinfo)
+ * 0x00, 0x04, 0x08, 0x18
+ *
+ * sizeof(bootinfo) == 0x48 (BOOTINFO_SIZE)
+ * sizeof arguments == 0x18 (MEM_ARG_SIZE)
+ * total arguments == 0x60 bytes (USR_ARGOFFSET)
+ */
+
+ movl $BOOTINFO_SIZE,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
movl 0x18(%esp,1),%esi # Source: bootinfo
cmpl $0x0, %esi # If the bootinfo pointer
/*
* Set up BTX kernel.
*/
- movl $MEM_ESP,%esp # Set up new stack
+ movl $MEM_BTX_ESP,%esp # Set up new stack
movl $MEM_DATA,%ebx # Data segment
movl $m_vers,%esi # Display BTX
call putstr # version message
orl $PAG_SIZ/PAG_ENT-1,%edi # the
incl %edi # BTX
shll $0x2,%edi # load
- addl $MEM_TBL,%edi # address
+ addl $MEM_BTX_TBL,%edi # address
pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
#ifdef BTXLDR_VERBOSE
call putstr # message
#endif
movl $start.8,%esi # Real mode stub
- movl $MEM_STUB,%edi # Destination
+ movl $BOOT0_ORIGIN,%edi # Destination
movl $start.9-start.8,%ecx # Size
rep # Relocate
movsb # it
- ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
+ ljmp $SEL_RCODE,$BOOT0_ORIGIN # To 16-bit code
.code16
start.8: xorw %ax,%ax # Data
movb $SEL_RDATA,%al # selector
movl %cr0,%eax # Switch to
decw %ax # real
movl %eax,%cr0 # mode
- ljmp $0,$MEM_ENTRY # Jump to BTX entry point
+ ljmp $0,$MEM_BTX_ENTRY # Jump to BTX entry point
start.9:
.code32
/*
-#
-# 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.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $
+ * $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxcsu.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
-# $FreeBSD: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxcsu.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
+/*
+ * BTX C startup code (ELF).
+ */
-#
-# BTX C startup code (ELF).
-#
+#include "../../bootasm.h"
-#
-# Globals.
-#
+ /*
+ * Globals.
+ */
.global _start
-#
-# Constants.
-#
- .set ARGADJ,0xfa0 # Argument adjustment
-#
-# Client entry point.
-#
+
+ /*
+ * Client entry point.
+ */
_start: movl %eax,__base # Set base address
- movl %esp,%eax # Set
- addl $ARGADJ,%eax # argument
- movl %eax,__args # pointer
+ movl %esp,%eax # Get base of arguments
+ addl $USR_ARGSPACE-USR_ARGOFFSET,%eax
+ movl %eax,__args
call main # Invoke client main()
call exit # Invoke client exit()
-#
-# Data.
-#
+
+ /*
+ * Data
+ */
.comm __base,4 # Client base address
.comm __args,4 # Client arguments
+++ /dev/null
-#
-# 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: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxcsu.s,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-#
-# BTX C startup code (ELF).
-#
-
-#
-# Globals.
-#
- .global _start
-#
-# Constants.
-#
- .set ARGADJ,0xfa0 # Argument adjustment
-#
-# Client entry point.
-#
-_start: movl %eax,__base # Set base address
- movl %esp,%eax # Set
- addl $ARGADJ,%eax # argument
- movl %eax,__args # pointer
- call main # Invoke client main()
- call exit # Invoke client exit()
-#
-# Data.
-#
- .comm __base,4 # Client base address
- .comm __args,4 # Client arguments
-#
-# 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: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxsys.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-#
-# BTX system calls.
-#
-
-#
-# Globals.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $
+ * $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxsys.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
+
+/*
+ * BTX system calls.
+ */
+
+#include "../../bootasm.h"
+
+ /*
+ * Globals.
+ */
.global __exit
.global __exec
-#
-# Constants.
-#
+
+ /*
+ * Constants.
+ */
.set INT_SYS,0x30 # Interrupt number
-#
-# System call: exit
-#
+
+ /*
+ * System call: exit
+ */
__exit: xorl %eax,%eax # BTX system
int $INT_SYS # call 0x0
-#
-# System call: exec
-#
+
+ /*
+ * System call: exec
+ */
__exec: movl $0x1,%eax # BTX system
int $INT_SYS # call 0x1
+
+
+++ /dev/null
-#
-# 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: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxsys.s,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-#
-# BTX system calls.
-#
-
-#
-# Globals.
-#
- .global __exit
- .global __exec
-#
-# Constants.
-#
- .set INT_SYS,0x30 # Interrupt number
-#
-# System call: exit
-#
-__exit: xorl %eax,%eax # BTX system
- int $INT_SYS # call 0x0
-#
-# System call: exec
-#
-__exec: movl $0x1,%eax # BTX system
- int $INT_SYS # call 0x1
-#
-# 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.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $
+ * $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxv86.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
-# $FreeBSD: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxv86.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
+/*
+ * BTX V86 interface.
+ */
-#
-# BTX V86 interface.
-#
+#include "../../bootasm.h"
-#
-# Globals.
-#
+ /*
+ * Globals.
+ */
.global __v86int
-#
-# Fields in V86 interface structure.
-#
+
+ /*
+ * Fields in V86 interface structure.
+ */
.set V86_CTL,0x0 # Control flags
.set V86_ADDR,0x4 # Int number/address
.set V86_ES,0x8 # V86 ES
.set V86_EBP,0x2c # V86 EBP
.set V86_ESI,0x30 # V86 ESI
.set V86_EDI,0x34 # V86 EDI
-#
-# Other constants.
-#
+
+ /*
+ * Other constants.
+ */
.set INT_V86,0x31 # Interrupt number
.set SIZ_V86,0x38 # Size of V86 structure
-#
-# V86 interface function.
-#
+
+ /*
+ * V86 interface function.
+ */
__v86int: popl __v86ret # Save return address
pushl $__v86 # Push pointer
call __v86_swap # Load V86 registers
addl $0x4,%esp # Discard pointer
pushl __v86ret # Restore return address
ret # To user
-#
-# Swap V86 and user registers.
-#
+
+ /*
+ * Swap V86 and user registers.
+ */
__v86_swap: xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
xchgl %eax,V86_EAX(%ebp) # Swap EAX
xchgl %ecx,V86_ECX(%ebp) # Swap ECX
xchgl %edi,V86_EDI(%ebp) # Swap EDI
xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
ret # To caller
-#
-# V86 interface structure.
-#
+
+ /*
+ * V86 interface structure.
+ */
.comm __v86,SIZ_V86
.comm __v86ret,4
+
+++ /dev/null
-#
-# 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: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $
-# $DragonFly: src/sys/boot/i386/btx/lib/Attic/btxv86.s,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-#
-# BTX V86 interface.
-#
-
-#
-# Globals.
-#
- .global __v86int
-#
-# Fields in V86 interface structure.
-#
- .set V86_CTL,0x0 # Control flags
- .set V86_ADDR,0x4 # Int number/address
- .set V86_ES,0x8 # V86 ES
- .set V86_DS,0xc # V86 DS
- .set V86_FS,0x10 # V86 FS
- .set V86_GS,0x14 # V86 GS
- .set V86_EAX,0x18 # V86 EAX
- .set V86_ECX,0x1c # V86 ECX
- .set V86_EDX,0x20 # V86 EDX
- .set V86_EBX,0x24 # V86 EBX
- .set V86_EFL,0x28 # V86 eflags
- .set V86_EBP,0x2c # V86 EBP
- .set V86_ESI,0x30 # V86 ESI
- .set V86_EDI,0x34 # V86 EDI
-#
-# Other constants.
-#
- .set INT_V86,0x31 # Interrupt number
- .set SIZ_V86,0x38 # Size of V86 structure
-#
-# V86 interface function.
-#
-__v86int: popl __v86ret # Save return address
- pushl $__v86 # Push pointer
- call __v86_swap # Load V86 registers
- int $INT_V86 # To BTX
- call __v86_swap # Load user registers
- addl $0x4,%esp # Discard pointer
- pushl __v86ret # Restore return address
- ret # To user
-#
-# Swap V86 and user registers.
-#
-__v86_swap: xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
- xchgl %eax,V86_EAX(%ebp) # Swap EAX
- xchgl %ecx,V86_ECX(%ebp) # Swap ECX
- xchgl %edx,V86_EDX(%ebp) # Swap EDX
- xchgl %ebx,V86_EBX(%ebp) # Swap EBX
- pushl %eax # Save
- pushf # Put eflags
- popl %eax # in EAX
- xchgl %eax,V86_EFL(%ebp) # Swap
- pushl %eax # Put EAX
- popf # in eflags
- movl 0x8(%esp,1),%eax # Load EBP
- xchgl %eax,V86_EBP(%ebp) # Swap
- movl %eax,0x8(%esp,1) # Save EBP
- popl %eax # Restore
- xchgl %esi,V86_ESI(%ebp) # Swap ESI
- xchgl %edi,V86_EDI(%ebp) # Swap EDI
- xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
- ret # To caller
-#
-# V86 interface structure.
-#
- .comm __v86,SIZ_V86
- .comm __v86ret,4
# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
-# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.7 2004/07/18 23:40:01 dillon Exp $
+# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.8 2004/07/19 01:24:58 dillon Exp $
PROG= boot2
NOMAN=
BTX= ${.CURDIR}/../btx
.endif
+# WARNING! These constants are also defined in bootasm.h
+#
REL1= 0x700
ORG1= 0x7c00
+
+# WARNING! The ORG2 calculation is the origin of boot2.bin relative to
+# the start of the BTX *USER* address space, not the start of physical
+# memory.
+#
ORG2= 0x2000
# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
* purpose.
*
* $FreeBSD: src/sys/boot/i386/boot2/boot1.s,v 1.23 2003/08/22 01:59:28 imp Exp $
- * $DragonFly: src/sys/boot/pc32/boot2/boot1.S,v 1.5 2004/07/18 23:40:01 dillon Exp $
+ * $DragonFly: src/sys/boot/pc32/boot2/boot1.S,v 1.6 2004/07/19 01:24:58 dillon Exp $
*/
#include "../bootasm.h"
movb $0x1,%dh // Block count
callw nread // Read MBR
mov $0x1,%cx // Two passes
-main.1: mov $MEM_BUF+PRT_OFF,%si // Partition table
+main.1: mov $BOOT2_LOAD_BUF+PRT_OFF,%si // Partition table
movb $0x1,%dh // Partition
main.2: cmpb $PRT_BSD,0x4(%si) // Our partition type?
jne main.3 // No
//
// Ok, we have a slice and drive in %dx now, so use that to locate and load
// boot2. %si references the start of the slice we are looking for, so go
-// ahead and load up the first 16 sectors (boot1 + boot2) from that. When
-// we read it in, we conveniently use 0x8c00 as our transfer buffer. Thus,
-// boot1 ends up at 0x8c00, and boot2 starts at 0x8c00 + 0x200 = 0x8e00.
+// ahead and load up the first 16 sectors (boot1 + boot2) from that.
+//
+// When we read it in, we conveniently use BOOT2_LOAD_BUF (0x8c00) as our
+// transfer buffer. Thus, boot1 ends up at 0x8c00, and boot2 starts at
+// 0x8c00 + 0x200 = 0x8e00.
+//
// The first part of boot2 is the disklabel, which is 0x200 bytes long.
// The second part is BTX, which is thus loaded into 0x9000, which is where
// it also runs from. The boot2.bin binary starts right after the end of
// BTX, so we have to figure out where the start of it is and then move the
-// binary to 0xc000. Normally, BTX clients start at MEM_USR, or 0xa000, but
-// when we use btxld to create boot2, we use an entry point of 0x2000. That
-// entry point is relative to MEM_USR; thus boot2.bin starts at 0xc000.
+// binary to 0xc000. Normally, BTX clients start at MEM_BTX_USR, or 0xa000,
+// but when we use btxld to create boot2, we use an entry point of 0x2000.
+// That entry point is relative to MEM_BTX_USR; thus boot2.bin starts
+// at 0xc000.
//
main.5: mov %dx,MEM_ARG // Save args
movb $NSECT,%dh // Sector count
callw nread // Read disk
- mov $MEM_BTX,%bx // BTX
+ mov $MEM_BTX_ORG,%bx // BTX
mov 0xa(%bx),%si // Get BTX length and set
add %bx,%si // %si to start of boot2.bin
- mov $MEM_USR+SIZ_PAG*2,%di // Client page 2
- mov $MEM_BTX+(NSECT-1)*SIZ_SEC,%cx // Byte
+ mov $MEM_BTX_USR+SIZ_PAG*2,%di // Client page 2
+ mov $MEM_BTX_ORG+(NSECT-1)*SIZ_SEC,%cx // Byte
sub %si,%cx // count
rep // Relocate
movsb // client
rep // the end of boot2.bin
stosb // up to 0x10000
callw seta20 // Enable A20
- jmp start+MEM_JMP-MEM_ORG // Start BTX
+ jmp start+MEM_BTX_ENTRY-MEM_ORG // Start BTX
//
// Enable A20 so we can access memory above 1 meg.
//
//
// Trampoline used to call read from within boot1.
//
-nread: mov $MEM_BUF,%bx // Transfer buffer
+nread: mov $BOOT2_LOAD_BUF,%bx // Transfer buffer
mov 0x8(%si),%ax // Get
mov 0xa(%si),%cx // LBA
push %cs // Read from
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $DragonFly: src/sys/boot/pc32/bootasm.h,v 1.1 2004/07/18 23:39:55 dillon Exp $
+ * $DragonFly: src/sys/boot/pc32/bootasm.h,v 1.2 2004/07/19 01:24:57 dillon Exp $
*/
+/*
+ * NOTE: MEM_REL and MEM_ORG also defined in boot2/Makefile
+ */
#define NHRDRV 0x475
#define BOOT0_ORIGIN 0x600 /* boot0 relocated */
#define FAKE 0x800 /* Fake partition entry */
#define LOAD 0x7c00 /* Load address */
-
+#define BOOTINFO_SIZE 0x48 /* bootinfo structure size */
#define MEM_ARG_SIZE 0x18
#define MEM_PAGE_SIZE 0x1000
+#define USR_ARGSPACE 0x1000 /* BTX loader / ttl argspace reserved */
+#define USR_ARGOFFSET (BOOTINFO_SIZE+MEM_ARG_SIZE)
#define MEM_REL 0x700 /* Relocation address */
#define MEM_ARG 0x900 /* Arguments */
#define MEM_ORG 0x7c00 /* Origin */
-#define MEM_BUF 0x8c00 /* Load area */
-#define MEM_BTX 0x9000 /* BTX start */
-#define MEM_JMP 0x9010 /* BTX entry point */
-#define MEM_USR 0xa000 /* Client start */
+
#define BDA_BOOT 0x472 /* Boot howto flag */
#define BDA_MEM 0x413 /* Free memory */
#define BDA_KEYFLAGS 0x417 /* Keyboard shift-state flags */
#define BDA_POS 0x450 /* Cursor position */
#define BDA_KEYBOARD 0x496 /* BDA byte with keyboard bit */
+#define MEM_BTX_ESP 0x1000 /* btxldr top of stack? */
#define MEM_BTX_START 0x1000 /* start of BTX memory */
#define MEM_BTX_ESP0 0x1800 /* Supervisor stack */
#define MEM_BTX_BUF 0x1800 /* Scratch buffer stack */
#define MEM_BTX_TSS 0x1f98 /* TSS */
#define MEM_BTX_MAP 0x2000 /* I/O bit map */
#define MEM_BTX_DIR 0x4000 /* Page directory */
+
+/*
+ * NOTE: page table location is hardwired in /usr/src/usr.sbin/btxld/btx.h
+ */
#define MEM_BTX_TBL 0x5000 /* Page tables */
+
+/*
+ * NOTE: BOOT2_LOAD_BUF also determines where the btx loader and boot2.bin
+ * code are loaded, since they are all in the boot2 file.
+ */
+#define BOOT2_LOAD_BUF 0x8c00 /* boot1 loads boot2 */
#define MEM_BTX_ORG 0x9000 /* base of BTX code */
#define MEM_BTX_ENTRY 0x9010 /* BTX starts execution here */
#define MEM_BTX_USR 0xa000 /* base of BTX client/user memory */
#define MEM_BTX_USR_ARG 0xa100
-#define MEM_BTX_LDR_OFF MEM_PAGE_SIZE /* offset of btx in the loader
-
-/*
- * CDBOOT
- */
-#define MEM_BTX_LDR_OFFSET 0x1000 /* Offset of BTX in the loader */
+#define MEM_BTX_LDR_OFF MEM_PAGE_SIZE /* offset of btx in the loader */
* purpose.
*
* $FreeBSD: src/sys/boot/i386/btx/btx/btx.s,v 1.32 2002/10/08 18:19:02 jhb Exp $
- * $DragonFly: src/sys/boot/pc32/btx/btx/btx.S,v 1.5 2004/07/18 23:40:04 dillon Exp $
+ * $DragonFly: src/sys/boot/pc32/btx/btx/btx.S,v 1.6 2004/07/19 01:25:00 dillon Exp $
*/
#include "../../bootasm.h"
*/
movb $SEL_TSS,%cl # Set task
ltr %cx # register
+ /*
+ * XXX We should NOT use BDA_MEM here. Use a fixed location
+ * instead.
+ */
movl $MEM_BTX_USR,%edx # User base address
movzwl %ss:BDA_MEM,%eax # Get free memory
shll $0xa,%eax # To bytes
- subl $0x1000,%eax # Less arg space
+ subl $USR_ARGSPACE,%eax # Less arg space
subl %edx,%eax # Less base
movb $SEL_UDATA,%cl # User data selector
pushl %ecx # Set SS
* purpose.
*
* $FreeBSD: src/sys/boot/i386/btx/btxldr/Makefile,v 1.17 2004/04/27 19:45:16 ru Exp $
- * $DragonFly: src/sys/boot/pc32/btx/btxldr/btxldr.S,v 1.1 2004/06/25 00:38:38 dillon Exp $
+ * $DragonFly: src/sys/boot/pc32/btx/btxldr/btxldr.S,v 1.2 2004/07/19 01:25:01 dillon Exp $
*/
/*
* real thing should probably be more flexible, and in C.
*/
+#include "../../bootasm.h"
/*
* 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 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.
*/
movl $m_logo,%esi # Identify
call putstr # ourselves
movzwl BDA_MEM,%eax # Get base memory
- shll $0xa,%eax # in bytes
+ shll $0xa,%eax # Convert to bytes
movl %eax,%ebp # Base of user stack
#ifdef BTXLDR_VERBOSE
movl $m_mem,%esi # Display
loop start.1 # Till done
call putstr # End message
#endif
- movl $0x48,%ecx # Allocate space
+ /*
+ * Arguments: (entry, boothowto, bootdev, 0, 0, 0, bootinfo)
+ * 0x00, 0x04, 0x08, 0x18
+ *
+ * sizeof(bootinfo) == 0x48 (BOOTINFO_SIZE)
+ * sizeof arguments == 0x18 (MEM_ARG_SIZE)
+ * total arguments == 0x60 bytes (USR_ARGOFFSET)
+ */
+
+ movl $BOOTINFO_SIZE,%ecx # Allocate space
subl %ecx,%ebp # for bootinfo
movl 0x18(%esp,1),%esi # Source: bootinfo
cmpl $0x0, %esi # If the bootinfo pointer
/*
* Set up BTX kernel.
*/
- movl $MEM_ESP,%esp # Set up new stack
+ movl $MEM_BTX_ESP,%esp # Set up new stack
movl $MEM_DATA,%ebx # Data segment
movl $m_vers,%esi # Display BTX
call putstr # version message
orl $PAG_SIZ/PAG_ENT-1,%edi # the
incl %edi # BTX
shll $0x2,%edi # load
- addl $MEM_TBL,%edi # address
+ addl $MEM_BTX_TBL,%edi # address
pushl %edi # Save load address
movzwl 0xa(%ebx),%ecx # Image size
#ifdef BTXLDR_VERBOSE
call putstr # message
#endif
movl $start.8,%esi # Real mode stub
- movl $MEM_STUB,%edi # Destination
+ movl $BOOT0_ORIGIN,%edi # Destination
movl $start.9-start.8,%ecx # Size
rep # Relocate
movsb # it
- ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
+ ljmp $SEL_RCODE,$BOOT0_ORIGIN # To 16-bit code
.code16
start.8: xorw %ax,%ax # Data
movb $SEL_RDATA,%al # selector
movl %cr0,%eax # Switch to
decw %ax # real
movl %eax,%cr0 # mode
- ljmp $0,$MEM_ENTRY # Jump to BTX entry point
+ ljmp $0,$MEM_BTX_ENTRY # Jump to BTX entry point
start.9:
.code32
/*
-#
-# 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.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $
+ * $DragonFly: src/sys/boot/pc32/btx/lib/btxcsu.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
-# $FreeBSD: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/pc32/btx/lib/btxcsu.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
+/*
+ * BTX C startup code (ELF).
+ */
-#
-# BTX C startup code (ELF).
-#
+#include "../../bootasm.h"
-#
-# Globals.
-#
+ /*
+ * Globals.
+ */
.global _start
-#
-# Constants.
-#
- .set ARGADJ,0xfa0 # Argument adjustment
-#
-# Client entry point.
-#
+
+ /*
+ * Client entry point.
+ */
_start: movl %eax,__base # Set base address
- movl %esp,%eax # Set
- addl $ARGADJ,%eax # argument
- movl %eax,__args # pointer
+ movl %esp,%eax # Get base of arguments
+ addl $USR_ARGSPACE-USR_ARGOFFSET,%eax
+ movl %eax,__args
call main # Invoke client main()
call exit # Invoke client exit()
-#
-# Data.
-#
+
+ /*
+ * Data
+ */
.comm __base,4 # Client base address
.comm __args,4 # Client arguments
-#
-# 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: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $
-# $DragonFly: src/sys/boot/pc32/btx/lib/btxsys.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
-
-#
-# BTX system calls.
-#
-
-#
-# Globals.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $
+ * $DragonFly: src/sys/boot/pc32/btx/lib/btxsys.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
+
+/*
+ * BTX system calls.
+ */
+
+#include "../../bootasm.h"
+
+ /*
+ * Globals.
+ */
.global __exit
.global __exec
-#
-# Constants.
-#
+
+ /*
+ * Constants.
+ */
.set INT_SYS,0x30 # Interrupt number
-#
-# System call: exit
-#
+
+ /*
+ * System call: exit
+ */
__exit: xorl %eax,%eax # BTX system
int $INT_SYS # call 0x0
-#
-# System call: exec
-#
+
+ /*
+ * System call: exec
+ */
__exec: movl $0x1,%eax # BTX system
int $INT_SYS # call 0x1
+
+
-#
-# 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.
-#
+/*
+ * 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: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $
+ * $DragonFly: src/sys/boot/pc32/btx/lib/btxv86.S,v 1.4 2004/07/19 01:25:02 dillon Exp $
+ */
-# $FreeBSD: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $
-# $DragonFly: src/sys/boot/pc32/btx/lib/btxv86.S,v 1.3 2003/11/10 06:08:35 dillon Exp $
+/*
+ * BTX V86 interface.
+ */
-#
-# BTX V86 interface.
-#
+#include "../../bootasm.h"
-#
-# Globals.
-#
+ /*
+ * Globals.
+ */
.global __v86int
-#
-# Fields in V86 interface structure.
-#
+
+ /*
+ * Fields in V86 interface structure.
+ */
.set V86_CTL,0x0 # Control flags
.set V86_ADDR,0x4 # Int number/address
.set V86_ES,0x8 # V86 ES
.set V86_EBP,0x2c # V86 EBP
.set V86_ESI,0x30 # V86 ESI
.set V86_EDI,0x34 # V86 EDI
-#
-# Other constants.
-#
+
+ /*
+ * Other constants.
+ */
.set INT_V86,0x31 # Interrupt number
.set SIZ_V86,0x38 # Size of V86 structure
-#
-# V86 interface function.
-#
+
+ /*
+ * V86 interface function.
+ */
__v86int: popl __v86ret # Save return address
pushl $__v86 # Push pointer
call __v86_swap # Load V86 registers
addl $0x4,%esp # Discard pointer
pushl __v86ret # Restore return address
ret # To user
-#
-# Swap V86 and user registers.
-#
+
+ /*
+ * Swap V86 and user registers.
+ */
__v86_swap: xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
xchgl %eax,V86_EAX(%ebp) # Swap EAX
xchgl %ecx,V86_ECX(%ebp) # Swap ECX
xchgl %edi,V86_EDI(%ebp) # Swap EDI
xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP
ret # To caller
-#
-# V86 interface structure.
-#
+
+ /*
+ * V86 interface structure.
+ */
.comm __v86,SIZ_V86
.comm __v86ret,4
+