199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Robert Nordier
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms are freely
199767f8919635c4928607450d9e0abb932109ceToomas Soome * permitted provided that the above copyright notice and this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * paragraph and the following disclaimer are duplicated in all
199767f8919635c4928607450d9e0abb932109ceToomas Soome * such forms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This software is provided "AS IS" and without any express or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * implied warranties, including, without limitation, the implied
199767f8919635c4928607450d9e0abb932109ceToomas Soome * warranties of merchantability and fitness for a particular
199767f8919635c4928607450d9e0abb932109ceToomas Soome * purpose.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <bootargs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define RBX_MUTE 0x10 /* -m */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define OPT_SET(opt) (1 << (opt))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Prototype BTX loader program, written in a couple of hours. The
199767f8919635c4928607450d9e0abb932109ceToomas Soome * real thing should probably be more flexible, and in C.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Memory locations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_STUB,0x600 # Real mode stub
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_ESP,0x1000 # New stack pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_TBL,0x5000 # BTX page tables
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_ENTRY,0x9010 # BTX entry point
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_DATA,start+0x1000 # Data segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Segment selectors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SCODE,0x8 # 4GB code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SDATA,0x10 # 4GB data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RCODE,0x18 # 64K code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RDATA,0x20 # 64K data
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Paging constants.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PAG_SIZ,0x1000 # Page size
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PAG_ENT,0x4 # Page entry size
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Screen constants.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_MAT,0x7 # Mode/attribute
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_COL,0x50 # Columns per row
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_ROW,0x19 # Rows per screen
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BIOS Data Area locations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_MEM,0x413 # Free memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_SCR,0x449 # Video mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_POS,0x450 # Cursor position
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Required by aout gas inadequacy.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SIZ_STUB,0x1a # Size of stub
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We expect to be loaded by boot2 at the origin defined in ./Makefile.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl start
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BTX program loader for ELF clients.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart: cld # String ops inc
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $OPT_SET(RBX_MUTE), 4(%esp) # Check first argument
199767f8919635c4928607450d9e0abb932109ceToomas Soome setnz muted # for RBX_MUTE, set flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_logo,%esi # Identify
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # ourselves
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl BDA_MEM,%eax # Get base memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll $0xa,%eax # in bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax,%ebp # Base of user stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_mem,%esi # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # amount of
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # base memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome lgdt gdtdesc # Load new GDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Relocate caller's arguments.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_esp,%esi # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esp,%eax # caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_args,%esi # Format string
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x4(%esp),%ebx # First argument
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $0x6,%ecx # Count
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.1: movl (%ebx),%eax # Get argument and
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $0x4,%ebx # bump pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # Display it
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop start.1 # Till done
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # End message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl BA_BOOTINFO+4(%esp),%esi # Source: bootinfo
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpl $0x0, %esi # If the bootinfo pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome je start_null_bi # is null, don't copy it
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl BI_SIZE(%esi),%ecx # Allocate space
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl %ecx,%ebp # for bootinfo
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%edi # Destination
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Copy
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb # it
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,BA_BOOTINFO+4(%esp) # Update pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %edi,%ebp # Restore base pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_rel_bi,%esi # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%eax # bootinfo
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # relocation
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart_null_bi: movl $BOOTARGS_SIZE,%ecx # Fixed size of arguments
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $KARGS_FLAGS_EXTARG, BA_BOOTFLAGS+4(%esp) # Check for extra data
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz start_fixed # Skip if the flag is not set
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl BOOTARGS_SIZE+4(%esp),%ecx # Add size of variable args
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart_fixed: subl $ARGOFF,%ebp # Place args at fixed offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x4(%esp),%esi # Source
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%edi # Destination
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Copy
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb # them
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_rel_args,%esi # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%eax # argument
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # relocation
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Set up BTX kernel.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_ESP,%esp # Set up new stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_DATA,%ebx # Data segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_vers,%esi # Display BTX
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # version message
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb 0x5(%ebx),%al # Get major version
199767f8919635c4928607450d9e0abb932109ceToomas Soome addb $'0',%al # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putchr # it
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $'.',%al # And a
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putchr # dot
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb 0x6(%ebx),%al # Get minor
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorb %ah,%ah # version
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0xa,%dl # Divide
199767f8919635c4928607450d9e0abb932109ceToomas Soome divb %dl,%al # by 10
199767f8919635c4928607450d9e0abb932109ceToomas Soome addb $'0',%al # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putchr # tens
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %ah,%al # Get units
199767f8919635c4928607450d9e0abb932109ceToomas Soome addb $'0',%al # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putchr # units
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # End message
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebx,%esi # BTX image
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl 0x8(%ebx),%edi # Compute
199767f8919635c4928607450d9e0abb932109ceToomas Soome orl $PAG_SIZ/PAG_ENT-1,%edi # the
199767f8919635c4928607450d9e0abb932109ceToomas Soome incl %edi # BTX
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll $0x2,%edi # load
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $MEM_TBL,%edi # address
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edi # Save load address
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl 0xa(%ebx),%ecx # Image size
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Save image size
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Relocate
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb # BTX
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esi,%ebx # Keep place
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_rel_btx,%esi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # parameters
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # and
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ebp # display
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%eax # the
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # relocation
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $PAG_SIZ,%ebp # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_base,%esi # the
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebp,%eax # user
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # base
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Set up ELF-format client program.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpl $0x464c457f,(%ebx) # ELF magic number?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je start.3 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $e_fmt,%esi # Display error
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.2: jmp start.2 # Hang
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.3:
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_elf,%esi # Display ELF
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_segs,%esi # Format string
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $0x2,%edi # Segment count
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x1c(%ebx),%edx # Get e_phoff
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %ebx,%edx # To pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl 0x2c(%ebx),%ecx # Get e_phnum
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne start.6 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x4(%edx),%eax # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # p_offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x8(%edx),%eax # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # p_vaddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x10(%edx),%eax # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # p_filesz
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x14(%edx),%eax # Display
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hexout # p_memsz
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # End message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %esi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edi # working
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x4(%edx),%esi # Get p_offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %ebx,%esi # as pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x8(%edx),%edi # Get p_vaddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %ebp,%edi # as pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x10(%edx),%ecx # Get p_filesz
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb # segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 0x14(%edx),%ecx # Any bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl 0x10(%edx),%ecx # to zero?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz start.5 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorb %al,%al # Then
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # them
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.5: popl %ecx # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %edi # working
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome decl %edi # Segments to do
199767f8919635c4928607450d9e0abb932109ceToomas Soome je start.7 # If none
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.6: addl $0x20,%edx # To next entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop start.4 # Till done
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.7:
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $m_done,%esi # Display done
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # message
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $start.8,%esi # Real mode stub
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_STUB,%edi # Destination
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $start.9-start.8,%ecx # Size
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Relocate
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb # it
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.8: xorw %ax,%ax # Data
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_RDATA,%al # selector
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%ss # Reload SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%ds # Reset
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%es # other
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%fs # segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%gs # limits
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %cr0,%eax # Switch to
199767f8919635c4928607450d9e0abb932109ceToomas Soome decw %ax # real
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax,%cr0 # mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $0,$MEM_ENTRY # Jump to BTX entry point
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart.9:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output message [ESI] followed by EAX in hex.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomehexout: pushl %eax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # Display message
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %esi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edi # caller's
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $buf,%edi # Buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex32 # To hex
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorb %al,%al # Terminate
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # string
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehexout.1: lodsb # Get a char
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $'0',%al # Leading zero?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je hexout.1 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al,%al # End of string?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne hexout.2 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome decl %esi # Undo
199767f8919635c4928607450d9e0abb932109ceToomas Soomehexout.2: decl %esi # Adjust for inc
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # Display hex
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %edi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # caller's
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output zero-terminated string [ESI] to the console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputstr.0: call putchr # Output char
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputstr: lodsb # Load char
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al,%al # End of string?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne putstr.0 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output character AL to the console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr: testb $1,muted # Check muted
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz putchr.5 # do a nop
199767f8919635c4928607450d9e0abb932109ceToomas Soome pusha # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %ecx,%ecx # Zero for loops
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_MAT,%ah # Mode/attribute
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $BDA_POS,%ebx # BDA pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw (%ebx),%dx # Cursor position
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $0xb8000,%edi # Regen buffer (color)
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne putchr.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %di,%di # Regen buffer (mono)
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.1: cmpb $0xa,%al # New line?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je putchr.2 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%ecx # Save char
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_COL,%al # Columns per row
199767f8919635c4928607450d9e0abb932109ceToomas Soome mulb %dh # * row position
199767f8919635c4928607450d9e0abb932109ceToomas Soome addb %dl,%al # + column
199767f8919635c4928607450d9e0abb932109ceToomas Soome adcb $0x0,%ah # position
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll %eax # * 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%ecx # Swap char, offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,(%edi,%ecx,1) # Write attr:char
199767f8919635c4928607450d9e0abb932109ceToomas Soome incl %edx # Bump cursor
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $SCR_COL,%dl # Beyond row?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jb putchr.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.2: xorb %dl,%dl # Zero column
199767f8919635c4928607450d9e0abb932109ceToomas Soome incb %dh # Bump row
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jb putchr.4 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 2*SCR_COL(%edi),%esi # New top line
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Scroll
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsl # screen
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $' ',%al # Space
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_COL,%cl # Columns to clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosw # line
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_ROW-1,%dh # Bottom line
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.4: movw %dx,(%ebx) # Update position
199767f8919635c4928607450d9e0abb932109ceToomas Soome popa # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.5: ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Convert EAX, AX, or AL to hex, saving the result to [EDI].
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex32: pushl %eax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome shrl $0x10,%eax # Do upper
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex16 # 16
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex16: call hex16.1 # Do upper 8
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex16.1: xchgb %ah,%al # Save/restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex8: pushl %eax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome shrb $0x4,%al # Do upper
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex8.1 # 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex8.1: andb $0xf,%al # Get lower 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $0xa,%al # Convert
199767f8919635c4928607450d9e0abb932109ceToomas Soome sbbb $0x69,%al # to hex
199767f8919635c4928607450d9e0abb932109ceToomas Soome das # digit
199767f8919635c4928607450d9e0abb932109ceToomas Soome orb $0x20,%al # To lower case
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # Save char
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # (Recursive)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .p2align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global descriptor table.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt: .word 0x0,0x0,0x0,0x0 # Null entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt.1:
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdtdesc: .word gdt.1-gdt-1 # Limit
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long gdt # Base
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Messages.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_logo: .asciz " \nBTX loader 1.00 "
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_vers: .asciz "BTX version is \0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomee_fmt: .asciz "Error: Client format not supported\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTXLDR_VERBOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_mem: .asciz "Starting in protected mode (base mem=\0)\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_esp: .asciz "Arguments passed (esp=\0):\n"
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soomem_args: .asciz "<howto="
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soome .asciz " bootdev="
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soome .asciz " junk="
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soome .asciz " "
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soome .asciz " "
5cbe397111597bc67a2d5d429b52a503f55a14b3Toomas Soome .asciz " bootinfo=\0>\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_rel_bi: .asciz "Relocated bootinfo (size=48) to \0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_rel_args: .asciz "Relocated arguments (size=18) to \0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_rel_btx: .asciz "Relocated kernel (size=\0) to \0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_base: .asciz "Client base address is \0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_elf: .asciz "Client format is ELF\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_segs: .asciz "text segment: offset="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " vaddr="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " filesz="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " memsz=\0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz "data segment: offset="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " vaddr="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " filesz="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz " memsz=\0\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soomem_done: .asciz "Loading complete\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomemuted: .byte 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Uninitialized data area.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomebuf: # Scratch buffer