loadifs: Multiboot loader for loading arbitrary *.ifs

bridged with qdn.public.qnxrtp.x86
Post Reply
Guest

loadifs: Multiboot loader for loading arbitrary *.ifs

Post by Guest » Thu Mar 13, 2003 3:02 pm

Previously you had to use the DOS loader for selecting
more than 3 *.ifs;
now if you're using GRUB for bootloader, you have a way.

Usage:
root (hd0,x)
kernel /loadifs
module /progra~1/qnx/boot/fs/qnxbase.ifs

Note that you still need FAT/ext2fs filesystem somewhere
to store the above two files. This is limitation of GRUB.
(I'm working on qnx4 filesystem support)


Optionally, if your notebook is confined to 16MB even equipped with 512MB,
this could remedy it if GRUB properly detects them.
--
kabe

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2003-03-13 23:39 JST by <kabe@imux3188>.
# Source directory was `/autofs/home/kabe'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 17989 -rw-rw-r-- loadifs/COPYING
# 601 -rw-rw-r-- loadifs/Makefile
# 232 -rw-rw-r-- loadifs/README
# 1925 -rw-rw-r-- loadifs/boot.S
# 4479 -rw-rw-r-- loadifs/kernel.c
# 5969 -rw-rw-r-- loadifs/kstdio.c
# 1165 -rw-rw-r-- loadifs/kstdio.h
# 7879 -rw-rw-r-- loadifs/loadifs.c
# 3090 -rw-rw-r-- loadifs/multiboot.h
# 3451 -rw-rw-r-- loadifs/package.qpg
# 8482 -rwxrwxr-x loadifs/setalign.c
#
echo=echo
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh22891; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= loadifs/COPYING ==============
if test ! -d 'loadifs'; then
$echo 'x -' 'creating directory' 'loadifs'
mkdir 'loadifs'
fi
if test -f 'loadifs/COPYING' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/COPYING' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/COPYING' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/COPYING' &&
X GNU GENERAL PUBLIC LICENSE
X Version 2, June 1991
X
X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
X 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X Preamble
X
X The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
X
X When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
X
X To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
X
X For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
X
X We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
X
X Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
X
X Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
X
X The precise terms and conditions for copying, distribution and
modification follow.
X
X GNU GENERAL PUBLIC LICENSE
X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X 0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
X
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
X
X 1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
X
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
X
X 2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
X
X a) You must cause the modified files to carry prominent notices
X stating that you changed the files and the date of any change.
X
X b) You must cause any work that you distribute or publish, that in
X whole or in part contains or is derived from the Program or any
X part thereof, to be licensed as a whole at no charge to all third
X parties under the terms of this License.
X
X c) If the modified program normally reads commands interactively
X when run, you must cause it, when started running for such
X interactive use in the most ordinary way, to print or display an
X announcement including an appropriate copyright notice and a
X notice that there is no warranty (or else, saying that you provide
X a warranty) and that users may redistribute the program under
X these conditions, and telling the user how to view a copy of this
X License. (Exception: if the Program itself is interactive but
X does not normally print such an announcement, your work based on
X the Program is not required to print an announcement.)
X
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
X
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
X
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
X
X 3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
X
X a) Accompany it with the complete corresponding machine-readable
X source code, which must be distributed under the terms of Sections
X 1 and 2 above on a medium customarily used for software interchange; or,
X
X b) Accompany it with a written offer, valid for at least three
X years, to give any third party, for a charge no more than your
X cost of physically performing source distribution, a complete
X machine-readable copy of the corresponding source code, to be
X distributed under the terms of Sections 1 and 2 above on a medium
X customarily used for software interchange; or,
X
X c) Accompany it with the information you received as to the offer
X to distribute corresponding source code. (This alternative is
X allowed only for noncommercial distribution and only if you
X received the program in object code or executable form with such
X an offer, in accord with Subsection b above.)
X
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
X
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
X
X 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
X
X 5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
X
X 6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
X
X 7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
X
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
X
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
X
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
X
X 8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
X
X 9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
X
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
X
X 10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
X
X NO WARRANTY
X
X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
X
X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
X
X END OF TERMS AND CONDITIONS
X
X How to Apply These Terms to Your New Programs
X
X If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
X
X To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
X
X <one line to give the program's name and a brief idea of what it does.>
X Copyright (C) 19yy <name of author>
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
X
X
Also add information on how to contact you by electronic and paper mail.
X
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
X
X Gnomovision version 69, Copyright (C) 19yy name of author
X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X This is free software, and you are welcome to redistribute it
X under certain conditions; type `show c' for details.
X
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
X
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
X
X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X <signature of Ty Coon>, 1 April 1989
X Ty Coon, President of Vice
X
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
SHAR_EOF
(set 20 03 02 25 22 06 16 'loadifs/COPYING'; eval "$shar_touch") &&
chmod 0664 'loadifs/COPYING' ||
$echo 'restore of' 'loadifs/COPYING' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/COPYING'`"
test 17989 -eq "$shar_count" ||
$echo 'loadifs/COPYING:' 'original size' '17989,' 'current size' "$shar_count!"
fi
# ============= loadifs/Makefile ==============
if test -f 'loadifs/Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/Makefile' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/Makefile' &&
CC=gcc
#CFLAGS=-Wall -g -I.
CFLAGS=-Wall -O2 -I.
X
# load address in hex
LOADADDR=120000
X
all: loadifs
X
#loadifs: loadifs.out
# objcopy -O binary loadifs.out $@
X
loadifs: boot.S kernel.c kstdio.o loadifs.o
X $(CC) $(CFLAGS) -o $@ -nostdlib -Wl,-N -Wl,-Ttext,$(LOADADDR) \
X boot.S kernel.c loadifs.o kstdio.o $(LDLIBS)
X
clean::
X rm -f core a.out *.o
X rm -f loadifs
X rm -f setalign
X rm -f *.qpr *.qpm *.qpk
X rm -f .#*
X
dump:
X objdump -D --target=binary --architecture=i386 loadifs
X
install: loadifs
X cp -p loadifs /fs/hd0-dos-4/loadifs
X
package: loadifs setalign package.qpg
X packager -u package.qpg
X
SHAR_EOF
(set 20 03 03 13 23 34 42 'loadifs/Makefile'; eval "$shar_touch") &&
chmod 0664 'loadifs/Makefile' ||
$echo 'restore of' 'loadifs/Makefile' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/Makefile'`"
test 601 -eq "$shar_count" ||
$echo 'loadifs/Makefile:' 'original size' '601,' 'current size' "$shar_count!"
fi
# ============= loadifs/README ==============
if test -f 'loadifs/README' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/README' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/README' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/README' &&
"loadifs" is a Multiboot "kernel"
which acts as a QNX IPL, which in turn boots the *.ifs
loaded as a "module" in GRUB.
X
Use GRUB to boot arbitrary *.ifs file:
X
X root (hd0,x)
X kernel /loadifs
X module /boot.ifs
X
kabe@sra-tohoku.co.jp
SHAR_EOF
(set 20 03 02 26 00 24 40 'loadifs/README'; eval "$shar_touch") &&
chmod 0664 'loadifs/README' ||
$echo 'restore of' 'loadifs/README' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/README'`"
test 232 -eq "$shar_count" ||
$echo 'loadifs/README:' 'original size' '232,' 'current size' "$shar_count!"
fi
# ============= loadifs/boot.S ==============
if test -f 'loadifs/boot.S' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/boot.S' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/boot.S' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/boot.S' &&
/* boot.S - bootstrap the kernel */
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#define ASM 1
#include <multiboot.h>
X
X .text
X
X .globl start, _start
X .globl _end
start:
_start:
X jmp multiboot_entry
X
X /* Align 32 bits boundary. */
X .align 16
X
X /* Multiboot header. */
multiboot_header:
X .long MULTIBOOT_HEADER_MAGIC /* magic */
X .long MULTIBOOT_HEADER_FLAGS /* flags */
X /* checksum */
X .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#ifndef __ELF__
X .long multiboot_header /* header_addr */
X .long _start /* load_addr */
X .long 0 /*_edata /* missing one byte?? */ /* load_end_addr */
X .long _end /* allocate stack */ /* bss_end_addr */
X .long multiboot_entry /* entry_addr */
#endif /* ! __ELF__ */
X
multiboot_entry:
X /* Initialize the stack pointer. */
X movl $(stack + STACK_SIZE), %esp
X
X /* Reset EFLAGS. */
X pushl $0
X popf
X
X /* Push the pointer to the Multiboot information structure. */
X pushl %ebx
X /* Push the magic value. */
X pushl %eax
X
X /* Now enter the C main function... */
X call EXT_C(cmain)
X
X /* Halt. */
X .globl halt
halt:
X pushl $halt_message
X call EXT_C(printf)
X
loop: hlt
X jmp loop
X
halt_message:
X .asciz "Halted."
X
X /* Our stack area. */
X .comm stack, STACK_SIZE
X
SHAR_EOF
(set 20 03 02 25 04 58 17 'loadifs/boot.S'; eval "$shar_touch") &&
chmod 0664 'loadifs/boot.S' ||
$echo 'restore of' 'loadifs/boot.S' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/boot.S'`"
test 1925 -eq "$shar_count" ||
$echo 'loadifs/boot.S:' 'original size' '1925,' 'current size' "$shar_count!"
fi
# ============= loadifs/kernel.c ==============
if test -f 'loadifs/kernel.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/kernel.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/kernel.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/kernel.c' &&
/* kernel.c - the C part of the kernel */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#include <multiboot.h>
#include "kstdio.h"
X
/* Macros. */
X
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
X
int verbose = 0;
X
extern void loadifs(int argc, char *argv[], multiboot_info_t *);
X
/* Check if MAGIC is valid and print the Multiboot information structure
X pointed by ADDR. */
void
cmain (unsigned long magic, unsigned long addr)
{
X multiboot_info_t *mbi;
X int argc = 0;
X char *argv[16] = {NULL};
X
X /* Clear the screen. */
X //cls ();
X
X /* Am I booted by a Multiboot-compliant boot loader? */
X if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
X {
X printf ("Invalid magic number: 0x%lx\n", magic);
X return;
X }
X
X /* Set MBI to the address of the Multiboot information structure. */
X mbi = (multiboot_info_t *) addr;
X
X /* split command line to argc/argv */
X if (CHECK_FLAG (mbi->flags, 2))
X {
X register char *p;
X int i;
X for (argc=0,p=(char*)mbi->cmdline; argc<16-1 && *p; )
X {
X while (*p == ' ' || *p == '\t') p++; /*skip heading space*/
X if (*p == '\0') break;
X argv[argc++] = p;
X while (*p && *p != ' ' && *p != '\t') p++;
X if (*p) *p++ = '\0'; /*terminate token*/
X }
X argv[argc] = NULL;
X
X /* parse -vvv verbose option here. */
X for (i=1; i<argc; i++)
X {
X if (argv[0]=='-' && argv[1]=='v')
X {
X char *p;
X for (p = &argv[1]; *p == 'v'; p++)
X verbose++;
X }
X }
X }
X
if (verbose>=2) {
X /* Print out the flags. */
X printf ("flags = 0x%x\n", (unsigned) mbi->flags);
X
X /* Are mem_* valid? */
X if (CHECK_FLAG (mbi->flags, 0))
X printf ("mem_lower = %luKB, mem_upper = %luKB\n",
X mbi->mem_lower, mbi->mem_upper);
X
X /* Is boot_device valid? */
X if (CHECK_FLAG (mbi->flags, 1))
X printf ("boot_device = 0x%lx\n", mbi->boot_device);
X
X /* Is the command line passed? */
X if (CHECK_FLAG (mbi->flags, 2))
X {
X int i;
X /*printf ("cmdline = %s\n", (char *) mbi->cmdline);*/
X for (i=0; i<argc; i++) printf (" argv[%d]=<%s>\n", i, argv);
X }
X /* Are mods_* valid? */
X if (CHECK_FLAG (mbi->flags, 3))
X {
X module_t *mod;
X int i;
X
X printf ("mods_count = %d, mods_addr = 0x%lx\n",
X (int) mbi->mods_count, mbi->mods_addr);
X for (i = 0, mod = (module_t *) mbi->mods_addr;
X i < mbi->mods_count;
X i++, mod += sizeof (module_t))
X printf (" mod_start = 0x%lx, mod_end = 0x%lx, string = %s\n",
X mod->mod_start, mod->mod_end,
X (char *) mod->string);
X }
X
X /* Bits 4 and 5 are mutually exclusive! */
X if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
X {
X printf ("Both bits 4 and 5 are set.\n");
X return;
X }
X
X /* Is the section header table of ELF valid? */
X if (CHECK_FLAG (mbi->flags, 5))
X {
X elf_section_header_table_t *elf_sec = &(mbi->u.elf_sec);
X
X printf ("elf_sec: num = %u, size = 0x%lx,"
X " addr = 0x%lx, shndx = 0x%lx\n",
X (unsigned) elf_sec->num, elf_sec->size,
X elf_sec->addr, elf_sec->shndx);
X }
X
X /* Are mmap_* valid? */
X if (CHECK_FLAG (mbi->flags, 6))
X {
X memory_map_t *mmap;
X
X printf ("mmap_addr = 0x%lx, mmap_length = 0x%lx\n",
X mbi->mmap_addr, mbi->mmap_length);
X for (mmap = (memory_map_t *) mbi->mmap_addr;
X (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
X mmap = (memory_map_t *) ((unsigned long) mmap
X + mmap->size + sizeof (mmap->size)))
X printf (" size = 0x%lx, base_addr = 0x%lx%lx,"
X " length = 0x%lx%lx, type = 0x%lx\n",
X mmap->size,
X mmap->base_addr_high, mmap->base_addr_low,
X mmap->length_high, mmap->length_low,
X mmap->type);
X }
}/*verbose*/
X
X loadifs(argc, argv, mbi);
X
}
X
SHAR_EOF
(set 20 03 02 25 23 39 54 'loadifs/kernel.c'; eval "$shar_touch") &&
chmod 0664 'loadifs/kernel.c' ||
$echo 'restore of' 'loadifs/kernel.c' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/kernel.c'`"
test 4479 -eq "$shar_count" ||
$echo 'loadifs/kernel.c:' 'original size' '4479,' 'current size' "$shar_count!"
fi
# ============= loadifs/kstdio.c ==============
if test -f 'loadifs/kstdio.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/kstdio.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/kstdio.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/kstdio.c' &&
/* kstdio.c - printf() family to use in 32bit raw environment
X * ripped&reformed from Multiboot kernel.c
X */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#include <kstdio.h>
X
/* Some VGA screen stuff. */
/*#define WRAP_BOTTOM_TO_TOP /* "original" behavior */
X
#define COLUMNS 80
#define LINES 24
#define ATTRIBUTE 7 /* VGA character attribute value */
/* Point to the character video memory. */
static /*volatile*/ unsigned char * const video = (void*)0xB8000;
/* VGA I/O port aquired from (short)0040:0063 */
static unsigned vgaport;
X
/* Variables. */
struct {
X int xpos; /* Save the X position. */
X int ypos; /* Save the Y position. */
} scr;
static int _kstdio_init = 0;
#define CHECK_INIT {if (!_kstdio_init) stdio_init();}
X
X
/* 0040:0000 BIOS parameter region */
static volatile unsigned char * const bios40 = (void*)0x0400;
/*
X * 0040:0050: {char col; char row;} current cursor position
X * 0040:0063: {short ioport;} CRT controller base I/O port address
X */
X
/* Forward declarations. */
static void update_cursor(void);
X
static void out8(int port,int value);
static unsigned in8(int port);
X
X
/* you MUST call this before doing anything. */
void
stdio_init(void)
{
X vgaport = bios40[0x63] + (((unsigned)bios40[0x64])<<8);
X /* block cursor */
X out8(vgaport, 0x0a); out8(vgaport+1, 0);
X out8(vgaport, 0x0b); out8(vgaport+1,14);
X /* get current cursor location from BIOS */
X scr.xpos = bios40[0x50];
X scr.ypos = bios40[0x51];
}
X
/* Clear the screen and initialize VIDEO, XPOS and YPOS. */
void
cls (void)
{
X int i;
X CHECK_INIT
X
X /* clear character buffer */
X for (i = 0; i < COLUMNS * LINES * 2; i+=2) {
X video = 0;
X video[i+1] = ATTRIBUTE; /* needed to cursor appear */
X }
X
X scr.xpos = 0;
X scr.ypos = 0;
X update_cursor();
}
X
/* Convert the integer D to a string and save the string in BUF. If
X BASE is equal to 'd', interpret that D is decimal, and if BASE is
X equal to 'x', interpret that D is hexadecimal. */
void
itoa (char *buf, int base, int d)
{
X char *p = buf;
X char *p1, *p2;
X unsigned long ud = d;
X int divisor = 10;
X
X /* If %d is specified and D is minus, put `-' in the head. */
X if (base == 'd' && d < 0)
X {
X *p++ = '-';
X buf++;
X ud = -d;
X }
X else if (base == 'x')
X divisor = 16;
X
X /* Divide UD by DIVISOR until UD == 0. */
X do
X {
X int remainder = ud % divisor;
X
X *p++ = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
X }
X while (ud /= divisor);
X
X /* Terminate BUF. */
X *p = 0;
X
X /* Reverse BUF. */
X p1 = buf;
X p2 = p - 1;
X while (p1 < p2)
X {
X char tmp = *p1;
X *p1 = *p2;
X *p2 = tmp;
X p1++;
X p2--;
X }
}
X
/* Put the character C on the screen. */
void
putchar (int c)
{
X CHECK_INIT
X if (c == '\n' || c == '\r')
X {
X newline:
X scr.xpos = 0;
X scr.ypos++;
X if (scr.ypos >= LINES) {
#ifdef WRAP_BOTTOM_TO_TOP /* "original" behavior */
X scr.ypos = 0;
#else
X /* scroll up */
X register unsigned short *vd, *vs;
X register int len;
X scr.ypos = LINES-1;
X for (vd = (unsigned short *)video,
X vs = (unsigned short *)video + 1 * COLUMNS,
X len = (LINES-1) * COLUMNS;
X len;
X len--)
X *vd++ = *vs++;
X for (len = COLUMNS; len; len--)
X *vd++ = (' ' + (ATTRIBUTE<<8));
#endif
X }
X update_cursor();
X return;
X }
X
X video[(scr.xpos + scr.ypos * COLUMNS) * 2 ] = c & 0xFF;
X video[(scr.xpos + scr.ypos * COLUMNS) * 2 + 1] = ATTRIBUTE;
X
X scr.xpos++;
X if (scr.xpos >= COLUMNS)
X goto newline;
X update_cursor();
}
X
static void
update_cursor(void)
{
X unsigned offset;
X /* update BIOS work area */
X bios40[0x50] = scr.xpos;
X bios40[0x51] = scr.ypos;
X /* update hardware cursor location */
X offset = (scr.ypos) * COLUMNS + scr.xpos;
X out8(vgaport, 0x0e);
X out8(vgaport+1, offset>>8);
X out8(vgaport, 0x0f);
X out8(vgaport+1, offset&0xff);
}
X
/* Format a string and print it on the screen, just like the libc
X function printf. */
void
printf (const char *format, ...)
{
X char **arg = (char **) &format;
X int c;
X char buf[20];
X CHECK_INIT
X
X arg++;
X
X while ((c = *format++) != 0)
X {
X if (c != '%')
X putchar (c);
X else
X {
X char *p;
X
X _redo:
X c = *format++;
X switch (c)
X {
X case 'l': /* just ignore long for now */
X goto _redo;
X case 'd':
X case 'u':
X case 'x':
X itoa (buf, c, *((int *) arg++));
X p = buf;
X goto string;
X break;
X
X case 's':
X p = *arg++;
X if (! p)
X p = "(null)";
X
X string:
X while (*p)
X putchar (*p++);
X break;
X
X default:
X putchar (*((int *) arg++));
X break;
X }
X }
X }
}
X
#if 1 /*NO_BUILTIN_MEMCPY*/
void
memcpy(register void *dst, register const void *src, register unsigned long length)
{
X /* XXX assumes 4byte alignment */
X length = (length+3) & ~3;
X /*printf("memcpy(0x%x, 0x%x, 0x%x)\n", (unsigned)dst,(unsigned)src, (unsigned)length);/**/
X
X while (length) {
X *(long*)dst = *(long*)src;
X dst += sizeof(long);
X src += sizeof(long);
X length -= sizeof(long);
X }
}
#endif
X
static void
out8(int port, int value)
{
X asm volatile ("outb %b1, %w0" : : "N,d" (port), "a,a" (value));
}
static unsigned in8(int port)
{
X unsigned r;
X asm volatile ("inb %w1, %0" : "=a,a" (r) : "N,d" (port));
X return r;
}
SHAR_EOF
(set 20 03 02 26 00 15 10 'loadifs/kstdio.c'; eval "$shar_touch") &&
chmod 0664 'loadifs/kstdio.c' ||
$echo 'restore of' 'loadifs/kstdio.c' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/kstdio.c'`"
test 5969 -eq "$shar_count" ||
$echo 'loadifs/kstdio.c:' 'original size' '5969,' 'current size' "$shar_count!"
fi
# ============= loadifs/kstdio.h ==============
if test -f 'loadifs/kstdio.h' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/kstdio.h' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/kstdio.h' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/kstdio.h' &&
/* kstdio.h - to use in 32bit raw environment
X * ripped&reformed from Multiboot kernel.c
X */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#ifndef _KSTDIO_H_INCLUDED
#define _KSTDIO_H_INCLUDED
X
#ifndef NULL
#define NULL ((void*)0)
#endif
X
void cls (void);
void itoa (char *buf, int base, int d);
void putchar (int c);
void printf (const char *format, ...);
void memcpy(void *dst, const void *src, unsigned long length); /*memcpy builtin?*/
X
#endif
X
SHAR_EOF
(set 20 03 02 25 23 39 54 'loadifs/kstdio.h'; eval "$shar_touch") &&
chmod 0664 'loadifs/kstdio.h' ||
$echo 'restore of' 'loadifs/kstdio.h' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/kstdio.h'`"
test 1165 -eq "$shar_count" ||
$echo 'loadifs/kstdio.h:' 'original size' '1165,' 'current size' "$shar_count!"
fi
# ============= loadifs/loadifs.c ==============
if test -f 'loadifs/loadifs.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/loadifs.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/loadifs.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/loadifs.c' &&
/* loadifs.c: QNX IFS loading dependent things. */
X
#include <multiboot.h>
#include "kstdio.h"
#include <sys/startup.h>
#include <stddef.h> /*offsetof*/
X
/* from kernel.c: */
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
X
extern int verbose; /* set in kernel.c */
X
extern const char _start[], _end[]; /* only address matters */
X
/* local forward decl */
static int overlap(const void *a1, size_t len1, const void *a2, size_t len2);
X
/* QNX */
struct startup_header *qstartup_hdr = NULL;
X
static const char _usage[] __attribute__ ((section("QNX_usage"),unused)) =
X "%C - Multiboot QNX *.ifs loader\n"
X "\n"
X "Options:\n"
X " -v[vv] Verbose.\n"
X "\n"
X "The *.ifs should be loaded as a Multiboot \"module\".\n"
X "\n"
X "Example GRUB setup:\n"
X " root (hd0,0)\n"
X " kernel /loadifs\n"
X " module /progra~1/qnx/boot/fs/qnxbase.ifs\n"
X "";
X
/* called from cmain() multiboot main. */
void
loadifs(int argc, char *argv[], multiboot_info_t *mbi)
{
X printf("\n***** Multiboot QNX Image Filesystem (ifs) loader *****\n");
X
X /* check for ifs as "module", scan for STARTUP_HDR_SIGNATURE */
X qstartup_hdr = NULL;
X if (CHECK_FLAG (mbi->flags, 3)) {
X module_t *mod;
X int i;
X
X if (mbi->mods_count < 1) {
X printf("*** ifs isn't added as module.\n");
X return;
X }
X
X /* assume the first module is the ifs;
X * there's little point in scanning multiple modules */
X mod = (module_t*)mbi->mods_addr;
X for (i=0; ; i+=8) {
X if (i >= 0x1000) {
X /* falloff; not found. */
X printf("*** STARTUP_HDR_SIGNATURE not found from 0x%lx\n", mod->mod_start);
X return;
X }
X qstartup_hdr = (struct startup_header*)(mod->mod_start + i);
X if (qstartup_hdr->signature == STARTUP_HDR_SIGNATURE) {
X break;
X }
X }
X } else {
X int i;
X /* tail-tacked ifs */
X /* grub loads ALL sections (not only prog sections) */
X /* TODO: scan for "QNX_ifs" section */
X if (verbose>=1) printf("No module, trying tail-tacked ifs from 0x%lx\n", (long)_end);
X /* XXX assume loaded boundaries are longword aligned */
X for (i=0; /*i<0x8000*/; i+=4) {
X if (!(i<0x8000)) { /*falloff*/
X qstartup_hdr = NULL;
X break;
X }
X qstartup_hdr = (struct startup_header*)(_end + i);
X if (qstartup_hdr->signature == STARTUP_HDR_SIGNATURE) {
X break;
X }
X }
X }
X if (!qstartup_hdr) {
X printf("*** No ifs found.\n"); return;
X }
X
X if (verbose>=0) {
X printf(" startup_header found at 0x%lx\n", (unsigned long)qstartup_hdr);
X }
X if (verbose>=1) {
X printf(" startup_vaddr=0x%lx image_paddr=0x%lx\n",
X qstartup_hdr->startup_vaddr, qstartup_hdr->image_paddr);
X printf(" ram_paddr=0x%lx ram_size=0x%lx\n",
X qstartup_hdr->ram_paddr, qstartup_hdr->ram_size);
X printf(" startup_size=0x%lx stored_size=0x%lx\n",
X qstartup_hdr->startup_size, qstartup_hdr->stored_size);
X printf(" imagefs_paddr=0x%lx imagefs_size=0x%lx\n",
X qstartup_hdr->imagefs_paddr, qstartup_hdr->imagefs_size);
X printf(" preboot_size=0x%x\n",
X qstartup_hdr->preboot_size);
X }
X
X /* check if compressed ifs could be used as imagefs_paddr
X * from the loaded "module"
X */
X /* overlap check: startup will clobber
X * ->ram_paddr length ram_size (or ->ram_paddr+startup_size len imagefs_size),
X * be sure the already loaded compressed ifs "module" doesn't fall here
X */
X if (!overlap((void*)qstartup_hdr->ram_paddr, qstartup_hdr->ram_size,
X /* compressed ifs region */
X (char*)qstartup_hdr + qstartup_hdr->startup_size,
X qstartup_hdr->stored_size - qstartup_hdr->startup_size)) {
X
X /* no overlap;
X * update the imagefs_paddr to use the loaded "module"
X */
X qstartup_hdr->imagefs_paddr = (unsigned long)qstartup_hdr + qstartup_hdr->startup_size;
X
X } else {
X /* overlaps, so re-tack the ifs after the uncompressed ifs region */
X /* similar things seems to be done inside startup anyway
X * when imagefs_paddr==NULL */
X printf("*** compressed ifs <0x%lx-0x%lx> overlaps ram_paddr <0x%lx-0x%lx>;\n"
X "*** re-transferring to <0x%lx>\n",
X (unsigned long)qstartup_hdr + qstartup_hdr->startup_size,
X (unsigned long)qstartup_hdr + qstartup_hdr->stored_size,
X (unsigned long)qstartup_hdr->ram_paddr,
X (unsigned long)qstartup_hdr->ram_paddr + qstartup_hdr->ram_size,
X (unsigned long)qstartup_hdr->ram_paddr + qstartup_hdr->ram_size
X );
X qstartup_hdr->imagefs_paddr = qstartup_hdr->ram_paddr + qstartup_hdr->ram_size;
X memcpy((void*)qstartup_hdr->imagefs_paddr,
X (char*)qstartup_hdr + qstartup_hdr->startup_size,
X qstartup_hdr->stored_size - qstartup_hdr->startup_size);
X }
X if (verbose>=1) {
X printf(" imagefs_paddr updated to 0x%lx\n",
X qstartup_hdr->imagefs_paddr);
X }
X
X /* Transfer startup to imagefs_addr */
X
X /* overlap check */
X if (overlap((void*)qstartup_hdr->image_paddr, qstartup_hdr->startup_size,
X _start, _end - _start)) {
X printf("*** image_paddr <0x%lx-0x%lx> overlaps loadifs <0x%lx-0x%lx>;\n"
X "*** recompile loadifs for different address\n",
X (unsigned long)qstartup_hdr->image_paddr,
X (unsigned long)qstartup_hdr->image_paddr + qstartup_hdr->startup_size,
X (unsigned long)_start, (unsigned long)_end);
X return;
X }
X if (verbose>=1) printf(" transfer startup to 0x%lx\n", qstartup_hdr->image_paddr);
X memcpy((void*)qstartup_hdr->image_paddr, qstartup_hdr, qstartup_hdr->startup_size);
X
#if 0
X /* transfer compressed imagefs */
X memcpy((void*)(qstartup_hdr->image_paddr + qstartup_hdr->startup_size),
X (char*)qstartup_hdr + qstartup_hdr->startup_size,
X qstartup_hdr->stored_size - qstartup_hdr->startup_size);
#endif
X
X /* now update the new startup */
X qstartup_hdr = (void*)qstartup_hdr->image_paddr;
X
X /* Initialize startup_info */
X {
X struct startup_info_hdr *qinfo;
X qinfo = (struct startup_info_hdr*)(&qstartup_hdr->info);
X
X /* Initialize startup_info_mem */
X if (CHECK_FLAG (mbi->flags, 6)) {
X /* Extract Available memory and fill startup_info_mem */
X register memory_map_t *mbmeminfo;
X register struct startup_info_mem *qmeminfo;
X for (qmeminfo = (struct startup_info_mem*) qinfo,
X mbmeminfo = (memory_map_t*)mbi->mmap_addr
X ;
X (char*)mbmeminfo < (char*) mbi->mmap_addr + mbi->mmap_length
X ;
X ((char*)mbmeminfo) += (offsetof(memory_map_t,base_addr_low) + mbmeminfo->size)
X ) {
X if (verbose>=2) printf(" memory range <0x%lx:0x%lx> type %d at 0x%lx\n",
X mbmeminfo->base_addr_low, mbmeminfo->length_low,
X (int)mbmeminfo->type, (unsigned long)mbmeminfo); /*XXX 32bit only*/
X if (mbmeminfo->type == 1 /*RAM*/) {
X qmeminfo->hdr.type = STARTUP_INFO_MEM;
X qmeminfo->hdr.size = sizeof(*qmeminfo);
X qmeminfo->addr = mbmeminfo->base_addr_low; /*XXX 32bit only*/
X qmeminfo->size = mbmeminfo->length_low; /*XXX 32bit only*/
X if (verbose>=2) printf(" filling meminfo 0x%lx -> <0x%lx:0x%lx>\n",
X (unsigned long)qmeminfo,
X qmeminfo->addr, qmeminfo->size);
X qmeminfo++;
X }
X }
X qinfo = (void*)qmeminfo; /*update*/
X } else {
X /* no Multiboot mmap info. */
X /* should extract from mem_lower, mem_upper */
X printf("*** no mmap info available, halt\n");
X return;
X }
X
X /* TODO fill startup_info_disk */
X /* TODO fill startup_info_box */
X
X /* terminate startup_info* */
X qinfo->type = STARTUP_INFO_SKIP;
X qinfo->size = 0;
X }
X
X /* start startup_vaddr */
X if (verbose>=1) printf("firing startup 0x%lx\n", qstartup_hdr->startup_vaddr);
X ((void (*)(void))qstartup_hdr->startup_vaddr)();
}
X
/* return 1 if two regions overlap */
static int
overlap(const void *a1, size_t len1, const void *a2, size_t len2)
{
X if (a1 <= a2) {
X /* |--a1---|
X * |---a2---- */
X if (a2 < a1+len1) return 1;
X /* |--a1---|
X * |---a2---- */
X return 0;
X } else {
X /* |--a1---
X * |--a2--| */
X if (a1 < a2+len2) return 1;
X /* |--a1---
X * |--a2--| */
X return 0;
X }
}
SHAR_EOF
(set 20 03 03 03 20 47 36 'loadifs/loadifs.c'; eval "$shar_touch") &&
chmod 0664 'loadifs/loadifs.c' ||
$echo 'restore of' 'loadifs/loadifs.c' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs/loadifs.c'`"
test 7879 -eq "$shar_count" ||
$echo 'loadifs/loadifs.c:' 'original size' '7879,' 'current size' "$shar_count!"
fi
# ============= loadifs/multiboot.h ==============
if test -f 'loadifs/multiboot.h' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs/multiboot.h' '(file already exists)'
else
$echo 'x -' extracting 'loadifs/multiboot.h' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs/multiboot.h' &&
/* multiboot.h - the header for Multiboot */
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
/* Macros. */
X
/* The magic number for the Multiboot header. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
X
/* The flags for the Multiboot header. */
#ifdef __ELF__
# define MULTIBOOT_HEADER_FLAGS 0x00000003
#else
# define MULTIBOOT_HEADER_FLAGS 0x00010003
#endif
X
/* The magic number passed by a Multiboot-compliant boot loader. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
X
/* The size of our stack (16KB). */
#define STACK_SIZE 0x4000
X
/* C symbol format. HAVE_ASM_USCORE is defined by configure. */
#ifdef HAVE_ASM_USCORE
# define EXT_C(sym) _ ## sym
#else
# define EXT_C(sym) sym
#endif
X
#ifndef ASM
/* Do not include here in boot.S. */
X
/* Types. */
X
/* The Multiboot header. */
typedef struct multiboot_header
{
X unsigned long magic;
X unsigned long flags;
X unsigned long checksum;
X unsigned long header_addr;
X unsigned long load_addr;
X unsigned long load_end_addr;
X unsigned long bss_end_addr;
X unsigned long entry_addr;
} multiboot_header_t;
X
/* The symbol table for a.out. */
typedef struct aout_symbol_table
{
X unsigned long tabsize;
X unsigned long strsize;
X unsigned long addr;
X unsigned long reserved;
} aout_symbol_table_t;
X
/* The section header table for ELF. */
typedef struct elf_section_header_table
{
X unsigned long num;
X unsigned long size;
X unsigned long addr;
X unsigned long shndx;
} elf_section_header_table_t;
X
/* The Multiboot information. */
typedef struct multiboot_info
{
X unsigned long flags;
X unsigned long mem_lower;
X unsigned long mem_upper;
X unsigned long boot_device;
X unsig

Serge Yuschenko

Re: loadifs: Multiboot loader for loading arbitrary *.ifs

Post by Serge Yuschenko » Mon Mar 17, 2003 3:36 pm

Hi Kabe,

It looks like the script lost its tail. Could you post only missing part?

Thanks,

Serge

Serge Yuschenko

Re: loadifs: Multiboot loader for loading arbitrary *.ifs

Post by Serge Yuschenko » Mon Mar 17, 2003 8:41 pm

Sorry. It was my mistake. I tried to read the message via http://www.openqnx.com/jive/index.jsp. Apparently the interface has a message size limitation. Finally I read the entire message on http://www.openqnx.com.

Serge

Guest

loadifs 1.1: Multiboot loader for loading arbitrary *.ifs

Post by Guest » Thu Dec 04, 2003 3:15 am

Previously you had to use the DOS loader for selecting
more than 3 *.ifs;
now if you're using GRUB for bootloader, you have a way.

Usage:
root (hd0,x)
kernel /loadifs
module /progra~1/qnx/boot/fs/qnxbase.ifs

Note that you still need FAT/ext2fs filesystem somewhere
to store the above two files. This is limitation of GRUB.
(I'm working on qnx4 filesystem support)


Optionally, if your notebook is confined to 16MB even equipped with 512MB,
this could remedy it if GRUB properly detects them.


Changes from 1.0->1.1:
* Use mem_upper, mem_lower if multiboot memory_map wasn't available;
this is needed to read "uppermem" setup in grub
--
kabe

#!/bin/sh
# This is loadifs-1.1, a shell archive (produced by GNU sharutils 4.2.1)
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2003-12-04 12:07 JST by <kabe@sra-tohoku.co.jp>.
# Source directory was `/autofs/home/kabe'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 5071 -rw-rw-r-- loadifs-1.1/CHANGELOG
# 17989 -rw-rw-r-- loadifs-1.1/COPYING
# 1165 -rw-rw-r-- loadifs-1.1/Makefile
# 1530 -rw-rw-r-- loadifs-1.1/README
# 1927 -rw-rw-r-- loadifs-1.1/boot.S
# 4479 -rw-rw-r-- loadifs-1.1/kernel.c
# 5969 -rw-rw-r-- loadifs-1.1/kstdio.c
# 1165 -rw-rw-r-- loadifs-1.1/kstdio.h
# 8670 -rw-rw-r-- loadifs-1.1/loadifs.c
# 3090 -rw-rw-r-- loadifs-1.1/multiboot.h
# 3594 -rw-rw-r-- loadifs-1.1/package.qpg
# 8482 -rwxrwxr-x loadifs-1.1/setalign.c
#
echo=echo
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh02993; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= loadifs-1.1/CHANGELOG ==============
if test ! -d 'loadifs-1.1'; then
$echo 'x -' 'creating directory' 'loadifs-1.1'
mkdir 'loadifs-1.1'
fi
if test -f 'loadifs-1.1/CHANGELOG' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/CHANGELOG' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/CHANGELOG' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/CHANGELOG' &&
(Manually generated from cvs2cl.pl -S --no-wrap output)
X
2003-12-04 11:48 kabe
X
X * CHANGELOG:
X - add.
X
2003-12-01 02:56 kabe
X
X * Makefile, loadifs.c:
X - Generate and add version number diag from package.qpg
X * README:
X - Clarify some wordings.
X
2003-11-29 03:52 kabe
X
X * boot.S, loadifs.c:
X - change startup address diag output to non-verbose
X
2003-10-11 03:41 kabe
X
X * README:
X - add comment for "uppermem"
X * TAGMAP:
X - update to stack corruption issue (ELF doesn't have this problem)
X - more comment around bss_end_addr and GRUB
X
2003-03-24 04:28 kabe
X
X * TAGMAP:
X - Now TAGMAP file is on -rTAGMAP branch only
X * Makefile:
X - (add "make changelog" target using cvs2cl.pl)
X * README, package.qpg:
X - add README that GRUB can gunzip
X
2003-03-18 14:01 kabe
X
X * Makefile, package.qpg:
X - Add "make export" make target
X
2003-03-17 22:14 kabe
X
X * loadifs.c:
X - cleaned usemsg a bit
X
2003-03-17 22:02 kabe
X
X * README:
X - Add comment for GRUB "uppermem" configuration
X * README, loadifs.c:
X Use mbi->mem_upper if memory_map didn't exist.
X This will enable GRUB "uppermem" command to restrict/override
X the memory configuration.
X
2003-03-14 00:05 kabe
X
X * package.qpg:
X - bump packager version to 1.1 after qdn post
X
2003-03-13 23:34 kabe
X
X * Makefile, package.qpg:
X - Add packaging things
X
2003-03-12 20:21 kabe
X
X * setalign.c:
X - properly free strtab, shdrs for "normal" flow
X
2003-03-04 00:00 kabe
X
X * setalign.c:
X - comment 100b
X
2003-03-03 23:05 kabe
X
X * setalign.c:
X - .rodata-ise the optlist array
X - add _rcsid (not very useful on CVS)
X * setalign.c:
X - cleaned up more usemsg, to use B(), I()
X * setalign.c:
X - add -v in usemsg
X * setalign.c:
X - cleaned up the usemsg control codes.
X * setalign.c:
X - Capability to replace the section if it already existed
X - "use" message (with attributes)
X * loadifs.c:
X - New feature: scan for ifs tacked at tail of the file.
X Actually GRUB won't load things not in ELF program header/section, so
X the ifs should be added to loadifs as a section.
X "setalign" program is available to do this.
X - adjusted verboselevel of messages
X
2003-03-03 19:21 kabe
X
X * setalign.c:
X - comment and message fix
X - check return of objdump so it won't loop forever
X * setalign.c:
X - mass change:
X - enable -s<section>=file,align=16 syntax
X - spwan objdump to add the section if the section didn't exist
X * setalign.c:
X - small program to just set the alignment of ELF section
X
2003-02-26 01:07 kabe
X
X * Makefile:
X - clean *.qpr etc
X * loadifs.c:
X - add "-v" option in usemsg
X * Makefile, kstdio.c, loadifs.c:
X - suppress diag messages unless "-v" option
X
2003-02-25 23:39 kabe
X
X * kernel.c, kstdio.h, loadifs.c:
X - Parse mbi->cmdlint to argc,argv and pass it to loadifs().
X - Parse "-vvv" option to "int verbose" global.
X - Only dump Multiboot header info above "-vv".
X * loadifs.c:
X - eliminate warning
X
2003-02-25 22:06 kabe
X
X * COPYING:
X - add GPL "COPYING" file
X
2003-02-25 06:56 kabe
X
X * loadifs.c:
X - insert the QNX_usage section help message by __attribute__ ((section)).
X * Makefile:
X - Generate ELF only, not elf-header-stripped one;
X stock GRUB can load the elf binary directly with proper Multiboot
X headers installed.
X * kstdio.c:
X - get rid of QNX header hw/inout.h
X * kstdio.c:
X - scroll-up, rather than wrap-to-top, at screen bottom
X * boot.S, kernel.c, loadifs.c:
X - Avoid excess copy for compressed ifs; update the imagefs_paddr
X to use the already loaded module address if it's safe to use it
X (doesn't overlap ram_paddr)
X
2003-02-25 02:38 kabe
X
X * Makefile, kernel.c, loadifs.c:
X - moved out QNX IPL things to loadifs.c
X * README:
X - add simple README
X
2003-02-19 08:44 kabe
X
X * kernel.c, kstdio.c:
X - cleanup
X - inherit cursor position from BIOS
X * kstdio.c:
X - Enable local out8() subroutine; it's better not using hw/inout.h
X
2003-02-19 06:06 kabe
X
X * boot.S:
X - FATAL ERROR fixed; stack area is allocated in .bss area,
X which was previously ZERO (original boot.S uses _end).
X Without .bss region, stack=textend+0x4000 will overlap the
X module on textend+0x1000.
X
2003-02-19 03:26 kabe
X
X * kernel.c:
X - (add #if 1 around Multiboot diag, for easy disabling)
X * kstdio.c, kstdio.h:
X - Properly update VGA cursor position
X - Add printf ("%lx") (l qualifier) to satisfy compiler;
X actually is just ignored
X
2003-02-19 01:06 kabe
X
X * boot.S:
X - cleaned up the invervening comment to be trailer comment
X - (export halt() )
X * kernel.c:
X - Eliminate printf() warnings by properly setting format string
X
2003-02-18 06:29 kabe
X
X * Makefile, kernel.c, kstdio.c, kstdio.h:
X - Separated printf() things to kstdio.c
X
2003-02-18 03:38 kabe
X
X * kernel.c:
X - SUCCESS booting
X TODO: check overlap when transferring to imagefs_addr
X TODO: transfer compressed image to "proper" place, avoiding
X relocation in startup
X TODO: startup_info_disk, startup_info_box??
X
2003-02-18 03:24 kabe
X
X * kernel.c:
X - add memcpy()
X * Makefile, kernel.c:
X - Start adding QNX things: detect STARTUP_HDR_SIGNATURE, build startup_info_mem
X - changed target to "loadifs"
X
SHAR_EOF
(set 20 03 12 04 11 50 06 'loadifs-1.1/CHANGELOG'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/CHANGELOG' ||
$echo 'restore of' 'loadifs-1.1/CHANGELOG' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/CHANGELOG'`"
test 5071 -eq "$shar_count" ||
$echo 'loadifs-1.1/CHANGELOG:' 'original size' '5071,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/COPYING ==============
if test -f 'loadifs-1.1/COPYING' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/COPYING' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/COPYING' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/COPYING' &&
X GNU GENERAL PUBLIC LICENSE
X Version 2, June 1991
X
X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
X 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X Preamble
X
X The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
X
X When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
X
X To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
X
X For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
X
X We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
X
X Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
X
X Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
X
X The precise terms and conditions for copying, distribution and
modification follow.
X
X GNU GENERAL PUBLIC LICENSE
X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X 0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
X
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
X
X 1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
X
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
X
X 2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
X
X a) You must cause the modified files to carry prominent notices
X stating that you changed the files and the date of any change.
X
X b) You must cause any work that you distribute or publish, that in
X whole or in part contains or is derived from the Program or any
X part thereof, to be licensed as a whole at no charge to all third
X parties under the terms of this License.
X
X c) If the modified program normally reads commands interactively
X when run, you must cause it, when started running for such
X interactive use in the most ordinary way, to print or display an
X announcement including an appropriate copyright notice and a
X notice that there is no warranty (or else, saying that you provide
X a warranty) and that users may redistribute the program under
X these conditions, and telling the user how to view a copy of this
X License. (Exception: if the Program itself is interactive but
X does not normally print such an announcement, your work based on
X the Program is not required to print an announcement.)
X
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
X
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
X
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
X
X 3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
X
X a) Accompany it with the complete corresponding machine-readable
X source code, which must be distributed under the terms of Sections
X 1 and 2 above on a medium customarily used for software interchange; or,
X
X b) Accompany it with a written offer, valid for at least three
X years, to give any third party, for a charge no more than your
X cost of physically performing source distribution, a complete
X machine-readable copy of the corresponding source code, to be
X distributed under the terms of Sections 1 and 2 above on a medium
X customarily used for software interchange; or,
X
X c) Accompany it with the information you received as to the offer
X to distribute corresponding source code. (This alternative is
X allowed only for noncommercial distribution and only if you
X received the program in object code or executable form with such
X an offer, in accord with Subsection b above.)
X
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
X
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
X
X 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
X
X 5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
X
X 6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
X
X 7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
X
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
X
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
X
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
X
X 8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
X
X 9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
X
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
X
X 10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
X
X NO WARRANTY
X
X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
X
X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
X
X END OF TERMS AND CONDITIONS
X
X How to Apply These Terms to Your New Programs
X
X If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
X
X To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
X
X <one line to give the program's name and a brief idea of what it does.>
X Copyright (C) 19yy <name of author>
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
X
X
Also add information on how to contact you by electronic and paper mail.
X
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
X
X Gnomovision version 69, Copyright (C) 19yy name of author
X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X This is free software, and you are welcome to redistribute it
X under certain conditions; type `show c' for details.
X
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
X
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
X
X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X <signature of Ty Coon>, 1 April 1989
X Ty Coon, President of Vice
X
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
SHAR_EOF
(set 20 03 02 25 22 06 16 'loadifs-1.1/COPYING'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/COPYING' ||
$echo 'restore of' 'loadifs-1.1/COPYING' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/COPYING'`"
test 17989 -eq "$shar_count" ||
$echo 'loadifs-1.1/COPYING:' 'original size' '17989,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/Makefile ==============
if test -f 'loadifs-1.1/Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/Makefile' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/Makefile' &&
CC=gcc
#CFLAGS=-Wall -g -I.
CFLAGS=-Wall -O2 -I.
X
# load address in hex
LOADADDR=120000
X
all: loadifs
X
#loadifs: loadifs.out
# objcopy -O binary loadifs.out $@
X
loadifs: boot.S kernel.c kstdio.o loadifs.o
X $(CC) $(CFLAGS) -o $@ -nostdlib -Wl,-N -Wl,-Ttext,$(LOADADDR) \
X boot.S kernel.c loadifs.o kstdio.o $(LDLIBS)
X
loadifs.o:: version.h
version.h: package.qpg
X echo '/* Automatically generated from package.qpg */' > $@
X sed -ne 's/.*<QPM:ReleaseVersion>\([^<]*\)<.*/#define LOADIFS_VERSION "\1"/p' package.qpg >> $@
clean::
X rm -f version.h
X
clean::
X rm -f *.o a.out core
X rm -f loadifs
X rm -f setalign
X rm -f *.qpr *.qpm *.qpk
X rm -f .#*
X
dump:
X objdump -D --target=binary --architecture=i386 loadifs
X
package: loadifs setalign package.qpg
X packager -u package.qpg
X
# CVSROOT=<cvsroot>/ seems to fail export,
# thus specify explicit cvs -d $CVSROOT
export: package.qpg
X REL=`sed -ne 's/.*<QPM:ReleaseVersion>\([^<]*\)<\/QPM:ReleaseVersion>.*/\1/p' package.qpg`; \
X CVSROOT=`cat CVS/Root`; export CVSROOT; \
X cd ..; \
X cvs -d $$CVSROOT export -rHEAD -d loadifs-$$REL loadifs
X
changelog:
X $$HOME/cvs2cl.pl --file ChangeLog --no-wrap -S
clean::
X rm -f *.bak
X
SHAR_EOF
(set 20 03 12 01 02 31 18 'loadifs-1.1/Makefile'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/Makefile' ||
$echo 'restore of' 'loadifs-1.1/Makefile' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/Makefile'`"
test 1165 -eq "$shar_count" ||
$echo 'loadifs-1.1/Makefile:' 'original size' '1165,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/README ==============
if test -f 'loadifs-1.1/README' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/README' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/README' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/README' &&
====== What is loadifs?
"loadifs" is a Multiboot "kernel"
which acts as a QNX IPL, which in turn boots the *.ifs
loaded as a "module".
X
GRUB is a popular boot loader with Multiboot capability.
X
====== Booting arbitrary *.ifs
Use GRUB to boot arbitrary *.ifs file:
X
X root (hd0,x)
X kernel /loadifs
X module /boot.ifs
X
====== Booting gzipped *.ifs
A bonus using GRUB is that it could load gzipped files.
X
Prepare a compressed image by
X gzip -9 -c /.altboot > /altboot.gz
X
and GRUB will properly load it by
X module /altboot.gz
X
Usually the *.ifs is built with +compress option so it won't gain much
by furthur gzip, so building the ifs withOUT compression may have
better results. (YMMV)
X
====== Specifying available memory
Optionally, if you want to emulate a memory-deprived environment,
or GRUB could not detect the installed memory ("displaymem" to see it),
X uppermem 17408
will emulate an 18MB environment.
Conventional memory takes 1MB so "uppermem" should be 1MB less.
After boot, check the configuration by "pidin info" FreeMem: value.
X
kabe@sra-tohoku.co.jp
X
====== When installed as a QNX package
The package will install loadifs binary as /boot/sys/loadifs,
but this is a mirage by fs-pkg; the real file lives below /pkgs/repository/.
Rather than specifying "kernel /pkgs/repository/....", you would like to
copy the loadifs to more convenient location.
X
======================
Changes from 1.0->1.1:
X * Use mem_upper, mem_lower if multiboot memory_map wasn't available;
X this is needed to read "uppermem" setup in grub
X
SHAR_EOF
(set 20 03 12 04 12 03 04 'loadifs-1.1/README'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/README' ||
$echo 'restore of' 'loadifs-1.1/README' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/README'`"
test 1530 -eq "$shar_count" ||
$echo 'loadifs-1.1/README:' 'original size' '1530,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/boot.S ==============
if test -f 'loadifs-1.1/boot.S' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/boot.S' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/boot.S' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/boot.S' &&
/* boot.S - bootstrap the kernel */
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#define ASM 1
#include <multiboot.h>
X
X .text
X
X .globl start, _start
X .globl _end
start:
_start:
X jmp multiboot_entry
X
X /* Align 32 bits boundary. */
X .align 16
X
X /* Multiboot header. */
multiboot_header:
X .long MULTIBOOT_HEADER_MAGIC /* magic */
X .long MULTIBOOT_HEADER_FLAGS /* flags */
X /* checksum */
X .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#ifndef __ELF__
X .long multiboot_header /* header_addr */
X .long _start /* load_addr */
X .long 0 /*_edata*/ /* missing one byte?? */ /* load_end_addr */
X .long _end /* allocate stack */ /* bss_end_addr */
X .long multiboot_entry /* entry_addr */
#endif /* ! __ELF__ */
X
multiboot_entry:
X /* Initialize the stack pointer. */
X movl $(stack + STACK_SIZE), %esp
X
X /* Reset EFLAGS. */
X pushl $0
X popf
X
X /* Push the pointer to the Multiboot information structure. */
X pushl %ebx
X /* Push the magic value. */
X pushl %eax
X
X /* Now enter the C main function... */
X call EXT_C(cmain)
X
X /* Halt. */
X .globl halt
halt:
X pushl $halt_message
X call EXT_C(printf)
X
loop: hlt
X jmp loop
X
halt_message:
X .asciz "Halted."
X
X /* Our stack area. */
X .comm stack, STACK_SIZE
X
SHAR_EOF
(set 20 03 11 29 03 52 26 'loadifs-1.1/boot.S'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/boot.S' ||
$echo 'restore of' 'loadifs-1.1/boot.S' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/boot.S'`"
test 1927 -eq "$shar_count" ||
$echo 'loadifs-1.1/boot.S:' 'original size' '1927,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/kernel.c ==============
if test -f 'loadifs-1.1/kernel.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/kernel.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/kernel.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/kernel.c' &&
/* kernel.c - the C part of the kernel */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#include <multiboot.h>
#include "kstdio.h"
X
/* Macros. */
X
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
X
int verbose = 0;
X
extern void loadifs(int argc, char *argv[], multiboot_info_t *);
X
/* Check if MAGIC is valid and print the Multiboot information structure
X pointed by ADDR. */
void
cmain (unsigned long magic, unsigned long addr)
{
X multiboot_info_t *mbi;
X int argc = 0;
X char *argv[16] = {NULL};
X
X /* Clear the screen. */
X //cls ();
X
X /* Am I booted by a Multiboot-compliant boot loader? */
X if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
X {
X printf ("Invalid magic number: 0x%lx\n", magic);
X return;
X }
X
X /* Set MBI to the address of the Multiboot information structure. */
X mbi = (multiboot_info_t *) addr;
X
X /* split command line to argc/argv */
X if (CHECK_FLAG (mbi->flags, 2))
X {
X register char *p;
X int i;
X for (argc=0,p=(char*)mbi->cmdline; argc<16-1 && *p; )
X {
X while (*p == ' ' || *p == '\t') p++; /*skip heading space*/
X if (*p == '\0') break;
X argv[argc++] = p;
X while (*p && *p != ' ' && *p != '\t') p++;
X if (*p) *p++ = '\0'; /*terminate token*/
X }
X argv[argc] = NULL;
X
X /* parse -vvv verbose option here. */
X for (i=1; i<argc; i++)
X {
X if (argv[0]=='-' && argv[1]=='v')
X {
X char *p;
X for (p = &argv[1]; *p == 'v'; p++)
X verbose++;
X }
X }
X }
X
if (verbose>=2) {
X /* Print out the flags. */
X printf ("flags = 0x%x\n", (unsigned) mbi->flags);
X
X /* Are mem_* valid? */
X if (CHECK_FLAG (mbi->flags, 0))
X printf ("mem_lower = %luKB, mem_upper = %luKB\n",
X mbi->mem_lower, mbi->mem_upper);
X
X /* Is boot_device valid? */
X if (CHECK_FLAG (mbi->flags, 1))
X printf ("boot_device = 0x%lx\n", mbi->boot_device);
X
X /* Is the command line passed? */
X if (CHECK_FLAG (mbi->flags, 2))
X {
X int i;
X /*printf ("cmdline = %s\n", (char *) mbi->cmdline);*/
X for (i=0; i<argc; i++) printf (" argv[%d]=<%s>\n", i, argv);
X }
X /* Are mods_* valid? */
X if (CHECK_FLAG (mbi->flags, 3))
X {
X module_t *mod;
X int i;
X
X printf ("mods_count = %d, mods_addr = 0x%lx\n",
X (int) mbi->mods_count, mbi->mods_addr);
X for (i = 0, mod = (module_t *) mbi->mods_addr;
X i < mbi->mods_count;
X i++, mod += sizeof (module_t))
X printf (" mod_start = 0x%lx, mod_end = 0x%lx, string = %s\n",
X mod->mod_start, mod->mod_end,
X (char *) mod->string);
X }
X
X /* Bits 4 and 5 are mutually exclusive! */
X if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
X {
X printf ("Both bits 4 and 5 are set.\n");
X return;
X }
X
X /* Is the section header table of ELF valid? */
X if (CHECK_FLAG (mbi->flags, 5))
X {
X elf_section_header_table_t *elf_sec = &(mbi->u.elf_sec);
X
X printf ("elf_sec: num = %u, size = 0x%lx,"
X " addr = 0x%lx, shndx = 0x%lx\n",
X (unsigned) elf_sec->num, elf_sec->size,
X elf_sec->addr, elf_sec->shndx);
X }
X
X /* Are mmap_* valid? */
X if (CHECK_FLAG (mbi->flags, 6))
X {
X memory_map_t *mmap;
X
X printf ("mmap_addr = 0x%lx, mmap_length = 0x%lx\n",
X mbi->mmap_addr, mbi->mmap_length);
X for (mmap = (memory_map_t *) mbi->mmap_addr;
X (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
X mmap = (memory_map_t *) ((unsigned long) mmap
X + mmap->size + sizeof (mmap->size)))
X printf (" size = 0x%lx, base_addr = 0x%lx%lx,"
X " length = 0x%lx%lx, type = 0x%lx\n",
X mmap->size,
X mmap->base_addr_high, mmap->base_addr_low,
X mmap->length_high, mmap->length_low,
X mmap->type);
X }
}/*verbose*/
X
X loadifs(argc, argv, mbi);
X
}
X
SHAR_EOF
(set 20 03 02 25 23 39 54 'loadifs-1.1/kernel.c'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/kernel.c' ||
$echo 'restore of' 'loadifs-1.1/kernel.c' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/kernel.c'`"
test 4479 -eq "$shar_count" ||
$echo 'loadifs-1.1/kernel.c:' 'original size' '4479,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/kstdio.c ==============
if test -f 'loadifs-1.1/kstdio.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/kstdio.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/kstdio.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/kstdio.c' &&
/* kstdio.c - printf() family to use in 32bit raw environment
X * ripped&reformed from Multiboot kernel.c
X */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#include <kstdio.h>
X
/* Some VGA screen stuff. */
/*#define WRAP_BOTTOM_TO_TOP /* "original" behavior */
X
#define COLUMNS 80
#define LINES 24
#define ATTRIBUTE 7 /* VGA character attribute value */
/* Point to the character video memory. */
static /*volatile*/ unsigned char * const video = (void*)0xB8000;
/* VGA I/O port aquired from (short)0040:0063 */
static unsigned vgaport;
X
/* Variables. */
struct {
X int xpos; /* Save the X position. */
X int ypos; /* Save the Y position. */
} scr;
static int _kstdio_init = 0;
#define CHECK_INIT {if (!_kstdio_init) stdio_init();}
X
X
/* 0040:0000 BIOS parameter region */
static volatile unsigned char * const bios40 = (void*)0x0400;
/*
X * 0040:0050: {char col; char row;} current cursor position
X * 0040:0063: {short ioport;} CRT controller base I/O port address
X */
X
/* Forward declarations. */
static void update_cursor(void);
X
static void out8(int port,int value);
static unsigned in8(int port);
X
X
/* you MUST call this before doing anything. */
void
stdio_init(void)
{
X vgaport = bios40[0x63] + (((unsigned)bios40[0x64])<<8);
X /* block cursor */
X out8(vgaport, 0x0a); out8(vgaport+1, 0);
X out8(vgaport, 0x0b); out8(vgaport+1,14);
X /* get current cursor location from BIOS */
X scr.xpos = bios40[0x50];
X scr.ypos = bios40[0x51];
}
X
/* Clear the screen and initialize VIDEO, XPOS and YPOS. */
void
cls (void)
{
X int i;
X CHECK_INIT
X
X /* clear character buffer */
X for (i = 0; i < COLUMNS * LINES * 2; i+=2) {
X video = 0;
X video[i+1] = ATTRIBUTE; /* needed to cursor appear */
X }
X
X scr.xpos = 0;
X scr.ypos = 0;
X update_cursor();
}
X
/* Convert the integer D to a string and save the string in BUF. If
X BASE is equal to 'd', interpret that D is decimal, and if BASE is
X equal to 'x', interpret that D is hexadecimal. */
void
itoa (char *buf, int base, int d)
{
X char *p = buf;
X char *p1, *p2;
X unsigned long ud = d;
X int divisor = 10;
X
X /* If %d is specified and D is minus, put `-' in the head. */
X if (base == 'd' && d < 0)
X {
X *p++ = '-';
X buf++;
X ud = -d;
X }
X else if (base == 'x')
X divisor = 16;
X
X /* Divide UD by DIVISOR until UD == 0. */
X do
X {
X int remainder = ud % divisor;
X
X *p++ = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
X }
X while (ud /= divisor);
X
X /* Terminate BUF. */
X *p = 0;
X
X /* Reverse BUF. */
X p1 = buf;
X p2 = p - 1;
X while (p1 < p2)
X {
X char tmp = *p1;
X *p1 = *p2;
X *p2 = tmp;
X p1++;
X p2--;
X }
}
X
/* Put the character C on the screen. */
void
putchar (int c)
{
X CHECK_INIT
X if (c == '\n' || c == '\r')
X {
X newline:
X scr.xpos = 0;
X scr.ypos++;
X if (scr.ypos >= LINES) {
#ifdef WRAP_BOTTOM_TO_TOP /* "original" behavior */
X scr.ypos = 0;
#else
X /* scroll up */
X register unsigned short *vd, *vs;
X register int len;
X scr.ypos = LINES-1;
X for (vd = (unsigned short *)video,
X vs = (unsigned short *)video + 1 * COLUMNS,
X len = (LINES-1) * COLUMNS;
X len;
X len--)
X *vd++ = *vs++;
X for (len = COLUMNS; len; len--)
X *vd++ = (' ' + (ATTRIBUTE<<8));
#endif
X }
X update_cursor();
X return;
X }
X
X video[(scr.xpos + scr.ypos * COLUMNS) * 2 ] = c & 0xFF;
X video[(scr.xpos + scr.ypos * COLUMNS) * 2 + 1] = ATTRIBUTE;
X
X scr.xpos++;
X if (scr.xpos >= COLUMNS)
X goto newline;
X update_cursor();
}
X
static void
update_cursor(void)
{
X unsigned offset;
X /* update BIOS work area */
X bios40[0x50] = scr.xpos;
X bios40[0x51] = scr.ypos;
X /* update hardware cursor location */
X offset = (scr.ypos) * COLUMNS + scr.xpos;
X out8(vgaport, 0x0e);
X out8(vgaport+1, offset>>8);
X out8(vgaport, 0x0f);
X out8(vgaport+1, offset&0xff);
}
X
/* Format a string and print it on the screen, just like the libc
X function printf. */
void
printf (const char *format, ...)
{
X char **arg = (char **) &format;
X int c;
X char buf[20];
X CHECK_INIT
X
X arg++;
X
X while ((c = *format++) != 0)
X {
X if (c != '%')
X putchar (c);
X else
X {
X char *p;
X
X _redo:
X c = *format++;
X switch (c)
X {
X case 'l': /* just ignore long for now */
X goto _redo;
X case 'd':
X case 'u':
X case 'x':
X itoa (buf, c, *((int *) arg++));
X p = buf;
X goto string;
X break;
X
X case 's':
X p = *arg++;
X if (! p)
X p = "(null)";
X
X string:
X while (*p)
X putchar (*p++);
X break;
X
X default:
X putchar (*((int *) arg++));
X break;
X }
X }
X }
}
X
#if 1 /*NO_BUILTIN_MEMCPY*/
void
memcpy(register void *dst, register const void *src, register unsigned long length)
{
X /* XXX assumes 4byte alignment */
X length = (length+3) & ~3;
X /*printf("memcpy(0x%x, 0x%x, 0x%x)\n", (unsigned)dst,(unsigned)src, (unsigned)length);/**/
X
X while (length) {
X *(long*)dst = *(long*)src;
X dst += sizeof(long);
X src += sizeof(long);
X length -= sizeof(long);
X }
}
#endif
X
static void
out8(int port, int value)
{
X asm volatile ("outb %b1, %w0" : : "N,d" (port), "a,a" (value));
}
static unsigned in8(int port)
{
X unsigned r;
X asm volatile ("inb %w1, %0" : "=a,a" (r) : "N,d" (port));
X return r;
}
SHAR_EOF
(set 20 03 02 26 00 15 10 'loadifs-1.1/kstdio.c'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/kstdio.c' ||
$echo 'restore of' 'loadifs-1.1/kstdio.c' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/kstdio.c'`"
test 5969 -eq "$shar_count" ||
$echo 'loadifs-1.1/kstdio.c:' 'original size' '5969,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/kstdio.h ==============
if test -f 'loadifs-1.1/kstdio.h' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/kstdio.h' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/kstdio.h' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/kstdio.h' &&
/* kstdio.h - to use in 32bit raw environment
X * ripped&reformed from Multiboot kernel.c
X */
/* Copyright (C) 1999 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#ifndef _KSTDIO_H_INCLUDED
#define _KSTDIO_H_INCLUDED
X
#ifndef NULL
#define NULL ((void*)0)
#endif
X
void cls (void);
void itoa (char *buf, int base, int d);
void putchar (int c);
void printf (const char *format, ...);
void memcpy(void *dst, const void *src, unsigned long length); /*memcpy builtin?*/
X
#endif
X
SHAR_EOF
(set 20 03 02 25 23 39 54 'loadifs-1.1/kstdio.h'; eval "$shar_touch") &&
chmod 0664 'loadifs-1.1/kstdio.h' ||
$echo 'restore of' 'loadifs-1.1/kstdio.h' 'failed'
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'loadifs-1.1/kstdio.h'`"
test 1165 -eq "$shar_count" ||
$echo 'loadifs-1.1/kstdio.h:' 'original size' '1165,' 'current size' "$shar_count!"
fi
# ============= loadifs-1.1/loadifs.c ==============
if test -f 'loadifs-1.1/loadifs.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'loadifs-1.1/loadifs.c' '(file already exists)'
else
$echo 'x -' extracting 'loadifs-1.1/loadifs.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'loadifs-1.1/loadifs.c' &&
/* loadifs.c: QNX IFS loading dependent things. */
X
#include <multiboot.h>
#include "kstdio.h"
#include <sys/startup.h>
#include <stddef.h> /*offsetof*/
X
/* from kernel.c: */
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
X
extern int verbose; /* set in kernel.c */
X
extern const char _start[], _end[]; /* only address matters */
X
/* local forward decl */
static int overlap(const void *a1, size_t len1, const void *a2, size_t len2);
X
/* QNX */
struct startup_header *qstartup_hdr = NULL;
X
#include "version.h"
static const char _usage[] __attribute__ ((section("QNX_usage"),unused)) =
X "%C - Multiboot QNX *.ifs loader (" LOADIFS_VERSION ")\n"
X "\n"
X "Options:\n"
X " -v[vv] Verbose.\n"
X "\n"
X "The *.ifs should be loaded as a Multiboot \"module\".\n"
X "\n"
X "Example GRUB setup:\n"
X " root (hd0,0)\n"
X " kernel /loadifs -v\n"
X " module /progra~1/qnx/boot/fs/qnxbase.ifs\n"
X "";
X
/* called from cmain() multiboot main. */
void
loadifs(int argc, char *argv[], multiboot_info_t *mbi)
{
X printf("\n***** Multiboot QNX Image Filesystem (ifs) loader (" LOADIFS_VERSION ") *****\n");
X
X /* check for ifs as "module", scan for STARTUP_HDR_SIGNATURE */
X qstartup_hdr = NULL;
X if (CHECK_FLAG (mbi->flags, 3)) {
X module_t *mod;
X int i;
X
X if (mbi->mods_count < 1) {
X printf("*** ifs isn't added as module.\n");
X return;
X }
X
X /* assume the first module is the ifs;
X * there's little point in scanning multiple modules */
X mod = (module_t*)mbi->mods_addr;
X for (i=0; ; i+=8) {
X if (i >= 0x1000) {
X /* falloff; not found. */
X printf("*** STARTUP_HDR_SIGNATURE not found from 0x%lx\n", mod->mod_start);
X return;
X }
X qstartup_hdr = (struct startup_header*)(mod->mod_start + i);
X if (qstartup_hdr->signature == STARTUP_HDR_SIGNATURE) {
X break;
X }
X }
X } else {
X int i;
X /* tail-tacked ifs */
X /* grub loads ALL sections (not only prog sections) */
X /* TODO: scan for "QNX_ifs" section */
X if (verbose>=1) printf("No module, trying tail-tacked ifs from 0x%lx\n", (long)_end);
X /* XXX assume loaded boundaries are longword aligned */
X for (i=0; /*i<0x8000*/; i+=4) {
X if (!(i<0x8000)) { /*falloff*/
X qstartup_hdr = NULL;
X break;
X }
X qstartup_hdr = (struct startup_header*)(_end + i);
X if (qstartup_hdr->signature == STARTUP_HDR_SIGNATURE) {
X break;
X }
X }
X }
X if (!qstartup_hdr) {
X printf("*** No ifs found.\n"); return;
X }
X
X if (verbose>=0) {
X printf(" startup_header found at 0x%lx\n", (unsigned long)qstartup_hdr);
X }
X if (verbose>=1) {
X printf(" startup_vaddr=0x%lx image_paddr=0x%lx\n",
X qstartup_hdr->startup_vaddr, qstartup_hdr->image_paddr);
X printf(" ram_paddr=0x%lx ram_size=0

Post Reply

Return to “qdn.public.qnxrtp.x86”