Initial revision

This commit is contained in:
Laurent Vivier 2004-02-15 20:46:45 +00:00
commit 11dd1c201c
32 changed files with 9507 additions and 0 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Laurent Vivier <LaurentVivier@wanadoo.fr>

340
COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
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.
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.
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.
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.
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.
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.
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.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
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".
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.
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.
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.
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:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
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.
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.
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.
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:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
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.
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.
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.
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.
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.
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.
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.
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.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
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.
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.
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.
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.
NO WARRANTY
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.
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.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
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.
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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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.
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:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
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.

3
ChangeLog Normal file
View File

@ -0,0 +1,3 @@
15 Feb 2004 - Laurent Vivier <LaurentVivier@wanadoo.fr>
* First release 0.1

100
Makefile Normal file
View File

@ -0,0 +1,100 @@
#
#
# (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
#
#
PACKAGE = emile
VERSION = 0.1
# kernel arguments
# root filesystem on harddrive
#KERNEL_ARGS="root=/dev/sda7"
# ramdisk
KERNEL_ARGS = "root=/dev/ramdisk ramdisk_size=2048"
# NetBoot
#KERNEL_ARGS = "root=/dev/nfs ip=autoconf"
# ramdisk on 2nd floppy
#KERNEL_ARGS="vga=normal noinitrd load_ramdisk=1 prompt_ramdisk=1 ramdisk_size=16384 root=/dev/fd0 disksize=1.44 flavor=compact"
# tools to use
ifneq ($(shell uname -m),m68k)
CROSS_COMPILE = m68k-linux-
endif
AS=$(CROSS_COMPILE)as
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
OBJCOPY=$(CROSS_COMPILE)objcopy
# base address
BASE_ADDRESS = 0x00200000
all: floppy.img
floppy.img: first/first vmlinuz second/second
cat first/first > floppy.img.X
cat second/second >> floppy.img.X
mv floppy.img.X floppy.img
vmlinux.bin: vmlinux
$(OBJCOPY) -O binary -R .note -R .comment -S vmlinux vmlinux.bin
vmlinuz: vmlinux.bin
cp vmlinux.bin vmlinuz.out
gzip -9 vmlinuz.out
mv vmlinuz.out.gz vmlinuz
first/first::
$(MAKE) -C first OBJCOPY=$(OBJCOPY) LD=$(LD) CC=$(CC) AS=$(AS) \
BASE_ADDRESS=$(BASE_ADDRESS)
second/second::
$(MAKE) -C second OBJCOPY=$(OBJCOPY) LD=$(LD) CC=$(CC) AS=$(AS) \
BASE_ADDRESS=$(BASE_ADDRESS) KERNEL_ARGS=$(KERNEL_ARGS) \
VERSION=$(VERSION)
dump: floppy.img
dd if=floppy.img of=/dev/fd0 bs=512
eject /dev/fd0
clean:
$(MAKE) -C first clean
$(MAKE) -C second clean
rm -f floppy.img floppy.img.X vmlinuz vmlinux.bin
DISTFILES = second/head.S second/MMU.c second/main.c \
second/MMU.h second/console.c second/Makefile \
second/console.h second/printf.c second/MMU_asm.S \
second/uncompress.h second/font_8x16.c \
second/ld.script second/memory.c second/inflate.c \
second/uncompress.c second/misc.c second/bootinfo.h \
second/misc.h second/lowmem.h second/bootinfo.c \
second/glue.h second/memory.h second/glue.S \
second/enter_kernel.S first/first.S first/Makefile \
Makefile COPYING README AUTHORS ChangeLog
dist:
rm -fr $(PACKAGE)-$(VERSION)
mkdir $(PACKAGE)-$(VERSION)
for file in $(DISTFILES); do \
dir=$$(dirname $$file); \
if [ "$$dir" != "" ] ; then \
mkdir -p $(PACKAGE)-$(VERSION)/$$dir; \
fi; \
cp -p $$file $(PACKAGE)-$(VERSION)/$$file; \
done
rm -f $(PACKAGE)-$(VERSION).tar $(PACKAGE)-$(VERSION).tar.bz2
tar cvf $(PACKAGE)-$(VERSION).tar $(PACKAGE)-$(VERSION)
bzip2 -9 $(PACKAGE)-$(VERSION).tar
rm -fr $(PACKAGE)-$(VERSION)

31
README Normal file
View File

@ -0,0 +1,31 @@
EMILE 0.1
(C) 2004 Laurent Vivier
All files are distributed under the terms of GPL license. See COPYING.
This tool allows to generate a floppy bootable on early macintoshes (680x0
based macintoshes).
In the booter, is embedded the kernel found in top directory under the name of
"vmlinux". It has been generated previously in linux source tree with
"make vmlinux". If a ramdisk (ramdisk.gz) is found, it is also added in
the floppy image.
Type "make" to generate the floppy image (floppy.img).
To write the image to floppy you can type "make dump".
This work is based on the penguin booter for mac68k, on linux kernel, and
perhaps on the ppc booter BootX.
Some problems can appear when there is no physical memory in the first bank.
All mechanisms found in "penguin" have not been implemented in EMILE.
You can ask me if one is missing for you :-P
This work has only be tested on a MacIIci with 8 x 4 MB RAM, a Two-Page Display,
and ethernet card sonic.
Have fun
Laurent Vivier <LaurentVivier@wanadoo.fr>
11 Fevrier 2004 ;-)

20
first/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
#
# (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
#
#
all: first
first: first.o
$(OBJCOPY) -O binary first.o first
config.h:
echo ".equ base_address, $(BASE_ADDRESS)" > config.h.X
mv config.h.X config.h
first.o: first.S config.h
$(AS) -o first.o first.S
clean:
rm -f first *.o

1
first/config.h Normal file
View File

@ -0,0 +1 @@
.equ base_address, 0x00200000

102
first/first.S Normal file
View File

@ -0,0 +1,102 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
.include "config.h"
.equ drive_num, 1
.equ fsFromStart, 1
.equ sector_size, 512
.equ sectors_per_track, 18
.equ sides, 2
.equ track_size, sector_size * sectors_per_track
.equ track_number, 80
.equ floppy_size, sides * track_size * track_number
.equ first_level_size, 2 * sector_size
.equ second_level_size, floppy_size - first_level_size
.macro PBEject
.short 0xA017
.endm
.macro PBReadSync
.short 0xA002
.endm
/* Pascal string : length, string */
.macro pString string
pstring_begin_\@:
.byte pstring_end_\@ - pstring_string_\@
pstring_string_\@:
.string "\string"
pstring_end_\@:
.fill 16 - (pstring_end_\@ - pstring_begin_\@) , 1, 0
.endm
/* Structure: "Inside Macintosh: Files", p. 2-57 */
begin:
.short 0x4C4B /* boot blocks signature */
bra start /* entry point to bootcode */
.short 0x4418 /* boot blocks version number */
.short 0x00 /* used internally */
pString "Mac Bootloader" /* System filename */
pstring "Copyright 2004" /* Finder filename */
pString "Laurent Vivier" /* debugger filename */
pString "Distributed " /* debugger filename */
pString "under GNU GPL " /* name of startup screen */
pString "first level " /* name of startup program */
pString "version 1.0 " /* name of system scrap file */
.short 10 /* number of FCBs to allocate */
.short 20 /* number of event queue elements */
.long 0x00004300 /* system heap size on 128K Mac */
.long 0x00000000 /* used internally */
.long 0x00200000 /* system heap size on all machines */
start:
move.l #base_address, %d0
/* save result in the ParamBlockRec.ioBuffer */
lea ioBuffer,%a0
move.l %d0,(%a0)
/* Now, we load the second stage loader */
lea param_block,%a0
PBReadSync
/* call second stage bootloader */
move.l ioBuffer,%a0
jmp (%a0)
param_block:
.long 0 /* qLink : next queue entry */
.short 0 /* qType : queue type */
.short 0 /* ioTrap : routine trap */
.long 0 /* ioCmdAddr: routine address */
.long 0 /* ioCompletion : pointer to completion routine */
.short 0 /* ioResult : result code */
.long 0 /* ioNamePtr : pointer to pathname */
.short drive_num /* ioVRefNum : volume specification */
.short -5 /* ioRefNum: file reference number */
.byte 0 /* ioVersNum : version number */
.byte 0 /* ioPermssn : read/write permission */
.long 0 /* ioMisc : miscellaneaous */
ioBuffer: /* ioBuffer : data buffer */
.long 0
ioReqCount: /* ioReqCount : requested number of bytes */
.long second_level_size
.long 0 /* ioActCount : actual number of bytes */
.short fsFromStart /* ioPosMode : positioning mode and newline char */
ioPosOffset: /* ioPosOffset : positionning offset */
.long first_level_size
end:
.fill 1024 - (end - begin), 1, 0xda

255
second/MMU.c Normal file
View File

@ -0,0 +1,255 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include "MMU.h"
#define GET_TC_ENABLE(TC) (TC & 0x80000000)
#define GET_TC_SRE(TC) (TC & 0x02000000)
#define GET_TC_FCL(TC) (TC & 0x01000000)
#define GET_TC_IS(TC) ((TC & 0x000F0000) >> 16)
#define GET_TC_PAGE_SIZE(TC) (1 << ((TC & 0x00F00000) >> 20))
#define GET_TC_TI(TC) (TC & 0xFFFF)
#define GET_TC_TIA(TC) ((TC & 0xF000) >> 12)
#define GET_TC_TIB(TC) ((TC & 0x0F00) >> 8)
#define GET_TC_TIC(TC) ((TC & 0x00F0) >> 4)
#define GET_TC_TID(TC) (TC & 0x000F)
#define RP_LIMIT_MAX 0x7FFF
#define GET_RP_LIMIT(CRP, max, min) if (CRP[0] & 0x80000000)\
{\
min = (CRP[0] >> 16) & 0x7FFF;\
max = RP_LIMIT_MAX;\
} else {\
min = 0;\
max = (CRP[0] >> 16) & 0x7FFF;\
}
#define GET_RP_DT(CRP) (CRP[0] & 0x3)
#define GET_RP_ADDR(CRP) (CRP[1] & 0xFFFFFFF0)
#define DT_INVALID 0
#define DT_PAGE_DESCRIPTOR 1
#define DT_VALID_4_BYTE 2
#define DT_VALID_8_BYTE 3
#define GET_TD_SF_DT(PD) (PD & 0x3)
#define GET_TD_SF_WP(PD) ((PD >> 2) & 0x1)
#define GET_TD_SF_U(PD) ((PD >> 3) & 0x1)
#define GET_TD_SF_NEXT(PD) (PD & 0xFFFFFFFC)
#define GET_TD_SF_ADDR(PD) (PD & 0xFFFFFF00)
#define GET_TD_LF_LIMIT(PD0, PD1, max, min) if (PD0 & 0x80000000)\
{\
min = (PD0 >> 16) & 0x7FFF;\
max = RP_LIMIT_MAX;\
} else {\
min = 0;\
max = (PD0 >> 16) & 0x7FFF;\
}
#define GET_TD_LF_DT(PD0, PD1) (PD0 & 3)
#define GET_TD_LF_WP(PD0, PD1) ((PD0 >> 2) & 1)
#define GET_TD_LF_U(PD0, PD1) ((PD0 >> 3) & 0x1)
#define GET_TD_LF_M(PD0, PD1) ((PD0 >> 4) & 0x1)
#define GET_TD_LF_CI(PD0, PD1) ((PD0 >> 6) & 0x1)
#define GET_TD_SF_S(PD0, PD1) ((PD0 >> 8) & 0x1)
#define GET_TD_LF_NEXT(PD0, PD1) (PD1 & 0xFFFFFFFC)
#define GET_TD_LF_ADDR(PD0, PD1) (PD1 & 0xFFFFFF00)
static int decode_8_PD(unsigned long *pageBase, unsigned long *pageMask,
unsigned long *attr,
unsigned long logicalAddr, unsigned long TI,
unsigned long PD0, unsigned long PD1);
static int decode_4_PD(unsigned long *pageBase, unsigned long *pageMask,
unsigned long *attr,
unsigned long logicalAddr, unsigned long TI, unsigned long PD)
{
int dt;
unsigned long TC;
int TIA;
unsigned long *root;
int index;
get_TC(&TC);
TIA = GET_TC_TIA(TC);
dt = GET_TD_SF_DT(PD);
switch(dt)
{
case DT_INVALID:
return -1;
case DT_PAGE_DESCRIPTOR:
*attr |= ((PD & 0xFF) >> 2);
*pageBase = GET_TD_SF_ADDR(PD);
return 0;
case DT_VALID_4_BYTE:
*attr |= ((PD & 0x0F) >> 2);
index = logicalAddr >> (32 - TIA);
logicalAddr = logicalAddr << TIA;
*pageMask = (*pageMask) >> TIA;
root = (unsigned long*)GET_TD_SF_NEXT(PD);
return decode_4_PD( pageBase, pageMask, attr,
logicalAddr << TIA, TI << 4,
read_phys(root + index));
case DT_VALID_8_BYTE:
*attr |= ((PD & 0x0F) >> 2);
index = logicalAddr >> (32 - TIA);
*pageMask = (*pageMask) >> TIA;
root = (unsigned long*)GET_TD_SF_NEXT(PD);
return decode_8_PD( pageBase, pageMask, attr,
logicalAddr << TIA, TI << 4,
read_phys(root + index),
read_phys(root + index + 1));
}
return 0;
}
static int decode_8_PD(unsigned long *pageBase, unsigned long *pageMask,
unsigned long *attr,
unsigned long logicalAddr, unsigned long TI,
unsigned long PD0, unsigned long PD1)
{
int dt;
unsigned long TC;
int TIA;
unsigned long *root;
int index;
get_TC(&TC);
TIA = GET_TC_TIA(TC);
dt = GET_TD_LF_DT(PD0, PD1);
switch(dt)
{
case DT_INVALID:
return -1;
case DT_PAGE_DESCRIPTOR:
*attr |= ((PD0 & 0xFFFF) >> 2);
*pageBase = GET_TD_LF_ADDR(PD0, PD1);
return 0;
case DT_VALID_4_BYTE:
*attr |= ((PD0 & 0xFFFF) >> 2);
index = logicalAddr >> (32 - TIA);
logicalAddr = logicalAddr << TIA;
*pageMask = (*pageMask) >> TIA;
root = (unsigned long*)GET_TD_LF_NEXT(PD0, PD1);
return decode_4_PD( pageBase, pageMask, attr,
logicalAddr << TIA, TI << 4,
read_phys(root + index));
case DT_VALID_8_BYTE:
*attr |= ((PD0 & 0xFFFF) >> 2);
index = logicalAddr >> (32 - TIA);
*pageMask = (*pageMask) >> TIA;
root = (unsigned long*)GET_TD_LF_NEXT(PD0, PD1);
return decode_8_PD( pageBase, pageMask, attr,
logicalAddr << TIA, TI << 4,
read_phys(root + index),
read_phys(root + index + 1));
}
return 0;
}
int logical2physicalAttr(unsigned long logicalAddr, unsigned long *physicalAddr, unsigned long *attr)
{
unsigned long TC;
unsigned long CRP[2];
unsigned long pageBase;
unsigned long pageMask = 0xFFFFFFFF;
int TIA;
int max, min;
int dt;
unsigned long* root;
int is;
int index;
int ret = -1;
/* analyse CPU root pointer */
get_CRP(CRP);
dt = GET_RP_DT(CRP);
GET_RP_LIMIT(CRP, max, min);
/* analyse translation control register */
get_TC(&TC);
TIA = GET_TC_TIA(TC);
is = GET_TC_IS(TC);
index = (logicalAddr << is) >> (32 - TIA);
pageMask = pageMask >> (is + TIA);
if ( (index < min) || (index > max) )
return -1;
index = index - min;
root = (unsigned long*)GET_RP_ADDR(CRP);
*attr = 0;
switch(dt)
{
case DT_INVALID:
case DT_PAGE_DESCRIPTOR:
ret = -1;
break;
case DT_VALID_4_BYTE:
ret = decode_4_PD( &pageBase, &pageMask, attr,
logicalAddr << (is + TIA),
GET_TC_TI(TC) << 4,
read_phys(root + index));
break;
case DT_VALID_8_BYTE:
ret = decode_8_PD( &pageBase, &pageMask, attr,
logicalAddr << (is + TIA),
GET_TC_TI(TC) << 4,
read_phys(root + index),
read_phys(root + index + 1));
break;
}
*physicalAddr = pageBase | (logicalAddr & pageMask);
return ret;
}
int logical2physical(unsigned long logicalAddr, unsigned long *physicalAddr)
{
unsigned long attr;
return logical2physicalAttr(logicalAddr, physicalAddr, &attr);
}
unsigned long get_page_size(void)
{
unsigned long TC;
get_TC(&TC);
return GET_TC_PAGE_SIZE(TC);
}

21
second/MMU.h Normal file
View File

@ -0,0 +1,21 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
/* from MMU_asm.S */
void get_TC(unsigned long *TC);
void get_SRP(unsigned long *SRP);
void get_CRP(unsigned long *CRP);
void get_TT0(unsigned long *TT0);
void get_TT1(unsigned long *TT1);
unsigned long read_phys(void *addr);
void write_phys(void *addr, unsigned long value);
/* from MMU.c */
extern unsigned long get_page_size(void);
extern int logical2physicalAttr(unsigned long logical, unsigned long *physicalAddr, unsigned long *attr);
extern int logical2physical(unsigned long logical, unsigned long *physicalAddr);

165
second/MMU_asm.S Normal file
View File

@ -0,0 +1,165 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
.global get_TC
get_TC:
link.w %fp,#0
move.l 8(%fp),%a0
pmove %tc,%a0@
unlk %fp
rts
.global get_SRP
get_SRP:
link.w %fp,#0
move.l 8(%fp),%a0
pmove %srp,%a0@
unlk %fp
rts
.global get_CRP
get_CRP:
link.w %fp,#0
move.l 8(%fp),%a0
pmove %crp,%a0@
unlk %fp
rts
.global get_TT0
get_TT0:
link.w %fp,#0
move.l 8(%fp),%a0
pmove %tt0, %a0@
unlk %fp
rts
.global get_TT1
get_TT1:
link.w %fp,#0
move.l 8(%fp),%a0
pmove %tt1,%a0@
unlk %fp
rts
.global ptest
ptest:
link.w %fp,#-8
move.l 8(%fp),%a0
/* test address */
suba.l %a1, %a1
ptestr #1,(%a0),#7,%a1
/* get result */
move.l 12(%fp),%a0
move.l %a1,(%a0)
lea -8(%fp),%a0
pmove %psr,%a0@
move.w %a0@, %d0
unlk %fp
rts
.TT0: .long 0
.global read_phys
read_phys:
link.w %fp,#-8
/* get the address to read */
move.l 8(%fp),%d0
move.l %d0,%a0
/* save the %TT0 register */
lea .TT0,%a1
pmove %tt0,%a1@
/* compute %TT0 new value */
andi.l #0xFF000000, %d0 /* 8 high bits of address */
ori.l #0x00008207, %d0 /* Enable, Caching allowed, read access
* Ignore Function Code
*/
/* disable interrupts */
move.l %d1,-(%sp)
move %sr,%d1
ori.w #0x0700,%sr
/* set %TT0 with new value */
move.l %d0, -8(%fp)
pmove -8(%fp), %tt0
/* read real memory */
move.l %a0@,%d0
/* restore %tt0 */
pmove %a1@,%tt0
/* restore interrupts */
move %d1, %sr
move.l (%sp)+, %d1
unlk %fp
rts
.global write_phys
write_phys:
link.w %fp,#-8
/* get the address to read */
move.l 8(%fp),%d0
move.l %d0,%a0
move.l 12(%fp),%d2
/* save the %TT0 register */
lea .TT0,%a1
pmove %tt0,%a1@
/* compute %TT0 new value */
andi.l #0xFF000000, %d0 /* 8 high bits of address */
ori.l #0x00008007, %d0 /* Enable, Caching allowed, write access
* Ignore Function Code
*/
/* disable interrupts */
move.l %d1,-(%sp)
move %sr,%d1
ori.w #0x0700,%sr
/* set %TT0 with new value */
move.l %d0, -8(%fp)
pmove -8(%fp), %tt0
/* write real memory */
move.l %d2, %a0@
/* restore %tt0 */
pmove %a1@,%tt0
/* restore interrupts */
move %d1, %sr
move.l (%sp)+, %d1
unlk %fp
rts

46
second/Makefile Normal file
View File

@ -0,0 +1,46 @@
#
#
# (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
#
#
CPPFLAGS = -DKERNEL_ARGS="\"$(KERNEL_ARGS)\"" -DVERSION="\"$(VERSION)\""
CFLAGS = -Wno-multichar -O -m68030 -nostdlib -nodefaultlibs -Wall -Werror
ASFLAGS = -m68030
LS = /bin/ls
AWK = /bin/awk
RAMDISK = ../ramdisk.gz
KERNEL_BIN = ../vmlinux.bin
ZIPPED_KERNEL = ../vmlinuz
KERNEL_SIZE=$(shell $(LS) -l $(KERNEL_BIN) | $(AWK) '{print $$5}')
second: second.o
$(OBJCOPY) -j .text -j .data -j .rodata -j .got -j .got.plt \
-O binary second.o second
OBJS = head.o MMU_asm.o image.o console.o printf.o font_8x16.o memory.o \
uncompress.o MMU.o bootinfo.o misc.o glue.o enter_kernel.o
second.o: $(OBJS) ld.script
$(LD) -T ld.script -Ttext 0x00200000 \
--defsym _KERNEL_SIZE=$(KERNEL_SIZE) -o second.o $(OBJS)
ifeq ($(shell ls $(RAMDISK) 2> /dev/null),$(RAMDISK))
image.o: main.o $(ZIPPED_KERNEL) $(RAMDISK)
$(OBJCOPY) --add-section .image=$(ZIPPED_KERNEL) \
--add-section .ramdisk=$(RAMDISK) main.o image.o ;
else
image.o: main.o $(ZIPPED_KERNEL)
$(OBJCOPY) --add-section .image=$(ZIPPED_KERNEL) main.o image.o;
endif
.S.o:
$(AS) $(ASFLAGS) -o $@ $^
.c.o:
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
clean:
rm -f second *.o

766
second/bootinfo.c Normal file
View File

@ -0,0 +1,766 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
* a lot of parts from penguin booter
* based on bootstrap.c for Atari Linux booter, Copyright 1993 by Arjan Knor
*
*/
#include <string.h>
#include "memory.h"
#include "glue.h"
#include "console.h"
#include "MMU.h"
#include "lowmem.h"
#include "misc.h"
#include "bootinfo.h"
extern unsigned char _ramdisk_start;
extern unsigned char _ramdisk_end;
static char* command_line = KERNEL_ARGS;
static struct bootinfo boot_info = { 0 };
enum {
gestaltProcessorType = 'proc',
gestalt68000 = 1,
gestalt68010 = 2,
gestalt68020 = 3,
gestalt68030 = 4,
gestalt68040 = 5
};
enum {
gestaltMMUType = 'mmu ', /* mmu type */
gestaltNoMMU = 0, /* no MMU */
gestaltAMU = 1, /* address management unit */
gestalt68851 = 2, /* 68851 PMMU */
gestalt68030MMU = 3, /* 68030 built-in MMU */
gestalt68040MMU = 4, /* 68040 built-in MMU */
gestaltEMMU1 = 5 /* Emulated MMU type 1 */
};
enum {
gestaltFPUType = 'fpu ', /* fpu type */
gestaltNoFPU = 0, /* no FPU */
gestalt68881 = 1, /* 68881 FPU */
gestalt68882 = 2, /* 68882 FPU */
gestalt68040FPU = 3 /* 68040 built-in FPU */
};
enum {
gestaltMachineType = 'mach', /* machine type */
gestaltClassic = 1,
gestaltMacXL = 2,
gestaltMac512KE = 3,
gestaltMacPlus = 4,
gestaltMacSE = 5,
gestaltMacII = 6,
gestaltMacIIx = 7,
gestaltMacIIcx = 8,
gestaltMacSE030 = 9,
gestaltPortable = 10,
gestaltMacIIci = 11,
gestaltPowerMac8100_120 = 12,
gestaltMacIIfx = 13,
gestaltMacClassic = 17,
gestaltMacIIsi = 18,
gestaltMacLC = 19,
gestaltMacQuadra900 = 20,
gestaltPowerBook170 = 21,
gestaltMacQuadra700 = 22,
gestaltClassicII = 23,
gestaltPowerBook100 = 24,
gestaltPowerBook140 = 25,
gestaltMacQuadra950 = 26,
gestaltMacLCIII = 27,
gestaltPerforma450 = gestaltMacLCIII,
gestaltPowerBookDuo210 = 29,
gestaltMacCentris650 = 30,
gestaltPowerBookDuo230 = 32,
gestaltPowerBook180 = 33,
gestaltPowerBook160 = 34,
gestaltMacQuadra800 = 35,
gestaltMacQuadra650 = 36,
gestaltMacLCII = 37,
gestaltPowerBookDuo250 = 38,
gestaltAWS9150_80 = 39,
gestaltPowerMac8100_110 = 40,
gestaltAWS8150_110 = gestaltPowerMac8100_110,
gestaltPowerMac5200 = 41,
gestaltPowerMac5260 = gestaltPowerMac5200,
gestaltPerforma5300 = gestaltPowerMac5200,
gestaltPowerMac6200 = 42,
gestaltPerforma6300 = gestaltPowerMac6200,
gestaltMacIIvi = 44,
gestaltMacIIvm = 45,
gestaltPerforma600 = gestaltMacIIvm,
gestaltPowerMac7100_80 = 47,
gestaltMacIIvx = 48,
gestaltMacColorClassic = 49,
gestaltPerforma250 = gestaltMacColorClassic,
gestaltPowerBook165c = 50,
gestaltMacCentris610 = 52,
gestaltMacQuadra610 = 53,
gestaltPowerBook145 = 54,
gestaltPowerMac8100_100 = 55,
gestaltMacLC520 = 56,
gestaltAWS9150_120 = 57,
gestaltPowerMac6400 = 58,
gestaltPerforma6400 = gestaltPowerMac6400,
gestaltPerforma6360 = gestaltPerforma6400,
gestaltMacCentris660AV = 60,
gestaltMacQuadra660AV = gestaltMacCentris660AV,
gestaltPerforma46x = 62,
gestaltPowerMac8100_80 = 65,
gestaltAWS8150_80 = gestaltPowerMac8100_80,
gestaltPowerMac9500 = 67,
gestaltPowerMac9600 = gestaltPowerMac9500,
gestaltPowerMac7500 = 68,
gestaltPowerMac7600 = gestaltPowerMac7500,
gestaltPowerMac8500 = 69,
gestaltPowerMac8600 = gestaltPowerMac8500,
gestaltAWS8550 = gestaltPowerMac7500,
gestaltPowerBook180c = 71,
gestaltPowerBook520 = 72,
gestaltPowerBook520c = gestaltPowerBook520,
gestaltPowerBook540 = gestaltPowerBook520,
gestaltPowerBook540c = gestaltPowerBook520,
gestaltPowerMac5400 = 74,
gestaltPowerMac6100_60 = 75,
gestaltAWS6150_60 = gestaltPowerMac6100_60,
gestaltPowerBookDuo270c = 77,
gestaltMacQuadra840AV = 78,
gestaltPerforma550 = 80,
gestaltPowerBook165 = 84,
gestaltPowerBook190 = 85,
gestaltMacTV = 88,
gestaltMacLC475 = 89,
gestaltPerforma47x = gestaltMacLC475,
gestaltMacLC575 = 92,
gestaltMacQuadra605 = 94,
gestaltMacQuadra630 = 98,
gestaltMacLC580 = 99,
gestaltPerforma580 = gestaltMacLC580,
gestaltPowerMac6100_66 = 100,
gestaltAWS6150_66 = gestaltPowerMac6100_66,
gestaltPowerBookDuo280 = 102,
gestaltPowerBookDuo280c = 103,
gestaltPowerMacLC475 = 104,
gestaltPowerMacPerforma47x = gestaltPowerMacLC475,
gestaltPowerMacLC575 = 105,
gestaltPowerMacPerforma57x = gestaltPowerMacLC575,
gestaltPowerMacQuadra630 = 106,
gestaltPowerMacLC630 = gestaltPowerMacQuadra630,
gestaltPowerMacPerforma63x = gestaltPowerMacQuadra630,
gestaltPowerMac7200 = 108,
gestaltPowerMac7300 = 109,
gestaltPowerMac7100_66 = 112,
gestaltPowerBook150 = 115,
gestaltPowerMacQuadra700 = 116,
gestaltPowerMacQuadra900 = 117,
gestaltPowerMacQuadra950 = 118,
gestaltPowerMacCentris610 = 119,
gestaltPowerMacCentris650 = 120,
gestaltPowerMacQuadra610 = 121,
gestaltPowerMacQuadra650 = 122,
gestaltPowerMacQuadra800 = 123,
gestaltPowerBookDuo2300 = 124,
gestaltPowerBook500PPCUpgrade = 126,
gestaltPowerBook5300 = 128,
gestaltPowerBook1400 = 310,
gestaltPowerBook3400 = 306,
gestaltPowerBook2400 = 307,
gestaltPowerBookG3Series = 312,
gestaltPowerBookG3 = 313,
gestaltPowerBookG3Series2 = 314,
gestaltPowerMacNewWorld = 406,
gestaltPowerMacG3 = 510,
gestaltPowerMac5500 = 512,
gestalt20thAnniversary = gestaltPowerMac5500,
gestaltPowerMac6500 = 513,
gestaltPowerMac4400_160 = 514,
gestaltPowerMac4400 = 515,
gestaltMacOSCompatibility = 1206
};
enum {
gestaltHardwareAttr= 'hdwr', /* hardware attributes */
gestaltHasVIA1 = 0, /* VIA1 exists */
gestaltHasVIA2 = 1, /* VIA2 exists */
gestaltHasRBV = 2,
gestaltHasASC = 3, /* Apple Sound Chip exists */
gestaltHasSCC = 4, /* SCC exists */
gestaltHasOSS = 5,
gestaltHasSCSIDMA = 6,
gestaltHasSCSI = 7, /* SCSI exists */
gestaltHasSWIMIOP = 8,
gestaltHasSCCIOP = 9,
gestaltHasFitch = 10,
gestaltHasIWM = 11,
gestaltHasPWM = 12,
gestaltHasRAMSndBuff = 13,
gestaltHasVideoDAConv = 14,
gestaltHasPGC = 15,
gestaltHasSoftPowerOff = 19, /* Capable of software power off */
gestaltHasSonic = 20,
gestaltHasSCSI961 = 21, /* 53C96 SCSI ctrl on internal bus */
gestaltHasSCSI962 = 22, /* 53C96 SCSI ctrl on external bus */
gestaltHasDAFBVideo = 23,
gestaltHasUniversalROM = 24, /* Do we have a Universal ROM? */
gestaltHasEnhancedLtalk = 30 /* Do we have Enhanced LocalTalk? */
};
#define noErr 0
#if defined(EXTENDED_HW_MAP)
static int
MacHasHardware(unsigned long gestaltBit)
{
long r;
Gestalt(gestaltHardwareAttr, &r);
return ( (r & (1 << gestaltBit)) != 0);
}
#endif /* EXTENDED_HW_MAP */
void bootinfo_init()
{
long proc, fpu, mmu, mach, ram;
memory_map_t map;
int i;
/* I'm a macintosh, I know, I'm sure */
boot_info.machtype = MACH_MAC;
/* get processor type */
Gestalt(gestaltProcessorType, &proc);
/* check FPU */
if (Gestalt('FPUE', &fpu) == noErr)
fpu = 0;
else
Gestalt(gestaltFPUType, &fpu);
/* check MMU */
Gestalt(gestaltMMUType, &mmu);
/* check machine type */
Gestalt(gestaltMachineType, &mach);
boot_info.bi_mac.id = mach;
/* check ram size */
Gestalt('ram ', &ram);
boot_info.bi_mac.memsize = ram / (1024L * 1024L);
/* set processor type */
switch (proc)
{
case gestalt68000:
error("68000 has no MMU.");
break;
case gestalt68010:
error("68010 has no MMU.");
break;
case gestalt68020:
if (mmu != gestalt68851)
error("68020 has no MMU.");
else
boot_info.cputype = CPU_68020;
break;
case gestalt68030:
boot_info.cputype = CPU_68030;
break;
case gestalt68040:
boot_info.cputype = CPU_68040;
break;
default:
error("Unknown processor.");
break;
}
boot_info.bi_mac.cpuid = proc - gestalt68020;
/* Set the FPU info */
switch (fpu)
{
case gestalt68881:
boot_info.cputype |= FPU_68881;
break;
case gestalt68882:
boot_info.cputype |= FPU_68882; break;
break;
case gestalt68040FPU:
boot_info.cputype |= FPU_68040;
break;
case gestaltNoFPU:
default:
break;
}
/* memory structure */
get_memory_map(&map);
for (i = 0; i < map.bank_number; i++)
{
boot_info.memory[i].addr = map.bank[i].address;
boot_info.memory[i].size = map.bank[i].size;
}
boot_info.num_memory = i;
/* ramdisk info */
boot_info.ramdisk_size = (unsigned long)&_ramdisk_end -
(unsigned long)&_ramdisk_start;
boot_info.ramdisk_addr = (unsigned long)&_ramdisk_start;
/* command line */
strncpy(boot_info.command_line, command_line, CL_SIZE);
/* macintosh */
/* video information */
boot_info.bi_mac.videological = console_get_videobase();
logical2physical(console_get_videobase(), &boot_info.bi_mac.videoaddr);
boot_info.bi_mac.videorow = console_get_row_bytes();
boot_info.bi_mac.videodepth = console_get_depth();
boot_info.bi_mac.dimensions = (console_get_height() << 16)
| console_get_width();
/* boot time and time zone */
boot_info.bi_mac.args = 0;
boot_info.bi_mac.boottime = 0;
boot_info.bi_mac.gmtbias = 0;
/* booter version */
boot_info.bi_mac.bootver = 108;
logical2physical(SCCRd, &boot_info.bi_mac.scc);
boot_info.bi_mac.timedbra = TimeDBRA;
boot_info.bi_mac.adbdelay = TimeVIADB;
boot_info.bi_mac.serialmf = 0;
boot_info.bi_mac.serialhsk = 9600;
boot_info.bi_mac.serialgpi = 9600;
/* ROM base */
boot_info.bi_mac.rombase = ROMBase;
#if defined(EXTENDED_HW_MAP)
/* hardware information */
boot_info.bi_mac.HwMap = 0;
/* VIA1 */
if (MacHasHardware(gestaltHasVIA1))
{
boot_info.bi_mac.HwMap |= HW_MAP_VIA1;
logical2physical(VIA1Base, &boot_info.bi_mac.VIA1Base);
}
/* VIA2/RBV/OSS */
if (MacHasHardware(gestaltHasVIA2))
boot_info.bi_mac.HwMap |= HW_MAP_VIA2_VIA;
else if (MacHasHardware(gestaltHasRBV))
boot_info.bi_mac.HwMap |= HW_MAP_VIA2_RBV;
else if (MacHasHardware(gestaltHasOSS))
boot_info.bi_mac.HwMap |= HW_MAP_VIA2_OSS;
if (boot_info.bi_mac.HwMap &
(HW_MAP_VIA2_VIA | HW_MAP_VIA2_RBV | HW_MAP_VIA2_OSS))
{
logical2physical(VIA2Base, &boot_info.bi_mac.VIA2Base);
}
/* ADB */
if (MacHasHardware(gestaltHasSWIMIOP))
{
boot_info.bi_mac.HwMap |= HW_MAP_ADB_IOP;
}
else
{
unsigned long bits = UnivROMBits;
if (bits != -1)
{
bits &= 0x07000000;
bits >>= 24;
if (bits != 0)
{
if ( (bits == 1) || (bits == 2) )
{
boot_info.bi_mac.HwMap |= HW_MAP_ADB_IISI;
}
else
boot_info.bi_mac.HwMap |= HW_MAP_ADB_CUDA;
}
else
{
if (PMgrBase != -1)
{
boot_info.bi_mac.HwMap |= HW_MAP_ADB_PB1;
}
}
}
}
/* ASC */
if (ASCBase != -1)
{
boot_info.bi_mac.HwMap |= HW_MAP_ASC;
logical2physical(ASCBase, &boot_info.bi_mac.ASCBase);
}
/* SCSI 5380 */
if (MacHasHardware(gestaltHasSCSI))
{
boot_info.bi_mac.HwMap |= HW_MAP_SCSI5380;
logical2physical(SCSIBase, &boot_info.bi_mac.SCSIBase);
}
/* SCSI 5380 DMA */
if (MacHasHardware(gestaltHasSCSIDMA))
{
boot_info.bi_mac.HwMap |= HW_MAP_SCSI5380DMA;
logical2physical(SCSIBase, &boot_info.bi_mac.SCSIBase);
}
/* 5396, internal or external */
if ( MacHasHardware(gestaltHasSCSI961) ||
MacHasHardware(gestaltHasSCSI962) )
{
boot_info.bi_mac.HwMap |= HW_MAP_SCSI5396;
logical2physical(SCSIBase, &boot_info.bi_mac.SCSIBase);
}
/* ATA/IDE */
if (HWCfgFlags & 0x0080)
{
if (PMgrBase != -1)
boot_info.bi_mac.HwMap |= HW_MAP_IDE_PB;
else
boot_info.bi_mac.HwMap |= HW_MAP_IDE_QUADRA;
}
/* nubus */
if (Gestalt('sltc', &boot_info.bi_mac.NubusMap) == noErr)
{
if (boot_info.bi_mac.NubusMap != 0)
{
boot_info.bi_mac.HwMap |= HW_MAP_NUBUS;
}
}
/* SCC */
if (MacHasHardware(gestaltHasSCCIOP))
boot_info.bi_mac.HwMap |= HW_MAP_SCC_IOP;
#endif /* EXTENDED_HW_MAP */
}
static char *
add_v2_boot_record(char *dst, unsigned short tag,
unsigned short in_data_size, void *in_data)
{
struct bi2_record *rec;
rec = (struct bi2_record *)dst;
rec->tag = tag;
rec->size = in_data_size + sizeof(struct bi2_record);
memcpy(rec->data, in_data, in_data_size);
return (dst + sizeof(struct bi2_record) + in_data_size);
}
void
set_kernel_bootinfo(char *dst)
{
unsigned long l1, l2, l3;
/* machine type */
l1 = boot_info.machtype;
dst = add_v2_boot_record(dst, V2_BI_MACHTYPE, sizeof(l1), &l1);
/* CPU type */
switch(boot_info.cputype & CPU_MASK)
{
case CPU_68020:
l1 = V2_CPU_68020;
l2 = V2_MMU_68851;
break;
case CPU_68030:
l1 = V2_CPU_68030;
l2 = V2_MMU_68030;
break;
case CPU_68040:
l1 = V2_CPU_68040;
l2 = V2_MMU_68040;
break;
case CPU_68060:
l1 = V2_CPU_68060;
l2 = V2_MMU_68060;
break;
default:
l1 = 0;
l2 = 0;
break;
}
switch(boot_info.cputype & FPU_MASK)
{
case FPU_68881:
l3 = V2_FPU_68881;
break;
case FPU_68882:
l3 = V2_FPU_68882;
break;
case FPU_68040:
l3 = V2_FPU_68040;
break;
case FPU_68060:
l3 = V2_FPU_68060;
break;
default:
l3 = 0;
break;
}
dst = add_v2_boot_record(dst, V2_BI_CPUTYPE, sizeof(l1), &l1);
dst = add_v2_boot_record(dst, V2_BI_FPUTYPE, sizeof(l3), &l3);
dst = add_v2_boot_record(dst, V2_BI_MMUTYPE, sizeof(l2), &l2);
/* Memory chunk */
for(l1 = 0; l1 < boot_info.num_memory; l1++)
{
dst = add_v2_boot_record(dst, V2_BI_MEMCHUNK,
sizeof(struct mem_info),
&boot_info.memory[l1]);
}
/* RAM disk */
if (boot_info.ramdisk_size)
{
struct mem_info mi;
mi.addr = boot_info.ramdisk_addr;
mi.size = boot_info.ramdisk_size;
dst = add_v2_boot_record(dst, V2_BI_RAMDISK, sizeof(mi), &mi);
}
dst = add_v2_boot_record(dst, V2_BI_COMMAND_LINE,
strlen(boot_info.command_line) + 1,
boot_info.command_line);
l1 = boot_info.bi_mac.id;
dst = add_v2_boot_record(dst, V2_BI_MAC_MODEL, sizeof(l1), &l1);
l1 = boot_info.bi_mac.videoaddr;
dst = add_v2_boot_record(dst, V2_BI_MAC_VADDR, sizeof(l1), &l1);
l1 = boot_info.bi_mac.videodepth;
dst = add_v2_boot_record(dst, V2_BI_MAC_VDEPTH, sizeof(l1), &l1);
l1 = boot_info.bi_mac.videorow;
dst = add_v2_boot_record(dst, V2_BI_MAC_VROW, sizeof(l1), &l1);
l1 = boot_info.bi_mac.dimensions;
dst = add_v2_boot_record(dst, V2_BI_MAC_VDIM, sizeof(l1), &l1);
l1 = boot_info.bi_mac.videological;
dst = add_v2_boot_record(dst, V2_BI_MAC_VLOGICAL, sizeof(l1), &l1);
l1 = boot_info.bi_mac.scc;
dst = add_v2_boot_record(dst, V2_BI_MAC_SCCBASE, sizeof(l1), &l1);
l1 = boot_info.bi_mac.boottime;
dst = add_v2_boot_record(dst, V2_BI_MAC_BTIME, sizeof(l1), &l1);
l1 = boot_info.bi_mac.gmtbias;
dst = add_v2_boot_record(dst, V2_BI_MAC_GMTBIAS, sizeof(l1), &l1);
l1 = boot_info.bi_mac.memsize;
dst = add_v2_boot_record(dst, V2_BI_MAC_MEMSIZE, sizeof(l1), &l1);
l1 = boot_info.bi_mac.cpuid;
dst = add_v2_boot_record(dst, V2_BI_MAC_CPUID, sizeof(l1), &l1);
l1 = boot_info.bi_mac.rombase;
dst = add_v2_boot_record(dst, V2_BI_MAC_ROMBASE, sizeof(l1), &l1);
#if defined(EXTENDED_HW_MAP)
/* VIA1 */
if (boot_info.bi_mac.HwMap & HW_MAP_VIA1)
{
l1 = boot_info.bi_mac.VIA1Base;
dst = add_v2_boot_record(dst, V2_BI_MAC_VIA1BASE,
sizeof(l1), &l1);
}
/* VIA2 */
if (boot_info.bi_mac.HwMap & HW_MAP_VIA2_VIA)
l2 = V2_VIA2_VIA;
else if (boot_info.bi_mac.HwMap & HW_MAP_VIA2_RBV)
l2 = V2_VIA2_RBV;
else if (boot_info.bi_mac.HwMap & HW_MAP_VIA2_OSS)
l2 = V2_VIA2_OSS;
if (boot_info.bi_mac.HwMap &
(HW_MAP_VIA2_VIA | HW_MAP_VIA2_RBV | HW_MAP_VIA2_OSS) )
{
l1 = boot_info.bi_mac.VIA2Base;
dst = add_v2_boot_record(dst, V2_BI_MAC_VIA2BASE,
sizeof(l1), &l1);
dst = add_v2_boot_record(dst, V2_BI_MAC_VIA2TYPE,
sizeof(l2), &l2);
}
/* ADB */
if (boot_info.bi_mac.HwMap & HW_MAP_ADB_IOP)
l1 = V2_ADB_IOP;
else if (boot_info.bi_mac.HwMap & HW_MAP_ADB_IISI)
l1 = V2_ADB_IISI;
else if (boot_info.bi_mac.HwMap & HW_MAP_ADB_CUDA)
l1 = V2_ADB_CUDA;
else if (boot_info.bi_mac.HwMap & HW_MAP_ADB_PB1)
l1 = V2_ADB_PB1;
dst = add_v2_boot_record(dst, V2_BI_MAC_ADBTYPE, sizeof(l1), &l1);
/* ASC */
if (boot_info.bi_mac.HwMap & HW_MAP_ASC)
{
l1 = boot_info.bi_mac.ASCBase;
dst = add_v2_boot_record(dst, V2_BI_MAC_ASCBASE,
sizeof(l1), &l1);
}
/* SCSI 5380 */
if (boot_info.bi_mac.HwMap & HW_MAP_SCSI5380)
{
l1 = boot_info.bi_mac.SCSIBase;
dst = add_v2_boot_record(dst, V2_BI_MAC_SCSI5380,
sizeof(l1), &l1);
}
/* SCSI 5380 DMA */
if (boot_info.bi_mac.HwMap & HW_MAP_SCSI5380DMA)
{
l1 = boot_info.bi_mac.SCSIBase;
dst = add_v2_boot_record(dst, V2_BI_MAC_SCSIDMA,
sizeof(l1), &l1);
}
/* SCSI 5396, internal or external */
if (boot_info.bi_mac.HwMap & HW_MAP_SCSI5396)
{
l1 = boot_info.bi_mac.SCSIBase;
dst = add_v2_boot_record(dst, V2_BI_MAC_SCSI5396,
sizeof(l1), &l1);
}
/* ATA/IDE */
if (boot_info.bi_mac.HwMap & HW_MAP_IDE_PB)
{
l1 = V2_IDE_PB;
dst = add_v2_boot_record(dst, V2_BI_MAC_IDETYPE,
sizeof(l1), &l1);
l2 = V2_IDE_BASE;
dst = add_v2_boot_record(dst, V2_BI_MAC_IDEBASE,
sizeof(l2), &l2);
}
else if (boot_info.bi_mac.HwMap & HW_MAP_IDE_QUADRA)
{
l1 = V2_IDE_QUADRA;
dst = add_v2_boot_record(dst, V2_BI_MAC_IDETYPE,
sizeof(l1), &l1);
l2 = V2_IDE_BASE;
dst = add_v2_boot_record(dst, V2_BI_MAC_IDEBASE,
sizeof(l2), &l2);
}
/* NuBus */
if (boot_info.bi_mac.HwMap & HW_MAP_NUBUS)
{
l2 = V2_NUBUS_NORMAL;
dst = add_v2_boot_record(dst, V2_BI_MAC_NUBUS, sizeof(l2), &l2);
l1 = boot_info.bi_mac.NubusMap;
dst = add_v2_boot_record(dst, V2_BI_MAC_SLOTMASK,
sizeof(l1), &l1);
}
/* SCC */
if (boot_info.bi_mac.HwMap & HW_MAP_SCC_IOP)
l1 = V2_SCC_NORMAL;
else
l1 = V2_SCC_IOP;
dst = add_v2_boot_record(dst, V2_BI_MAC_SCCTYPE, sizeof(l1), &l1);
#endif /* EXTENDED_HW_MAP */
/* END */
l1 = 0;
dst = add_v2_boot_record(dst, V2_BI_LAST, 0, &l1);
}

340
second/bootinfo.h Normal file
View File

@ -0,0 +1,340 @@
/*
** asm/setup.h -- Definition of the Linux/m68k boot information structure
**
** Copyright 1992 by Greg Harp
**
** This file is subject to the terms and conditions of the GNU General Public
** License. See the file COPYING in the main directory of this archive
** for more details.
**
** Created 09/29/92 by Greg Harp
**
** 5/2/94 Roman Hodek:
** Added bi_atari part of the machine dependent union bi_un; for now it
** contains just a model field to distinguish between TT and Falcon.
** 26/7/96 Roman Zippel:
** Renamed to setup.h; added some useful macros to allow gcc some
** optimizations if possible.
** 09/02/04 Laurent Vivier
** Remove some parts and add it in EMILE
*/
#ifndef __ASSEMBLY__
struct mem_info {
unsigned long addr; /* physical address of memory chunk */
unsigned long size; /* length of memory chunk (in bytes) */
};
struct bi_Macintosh
{
unsigned long videoaddr;
unsigned long videorow;
unsigned long videodepth;
unsigned long dimensions;
unsigned long args;
unsigned long boottime;
unsigned long gmtbias;
unsigned long bootver;
unsigned long videological;
unsigned long scc;
unsigned long id;
unsigned long memsize;
unsigned long serialmf;
unsigned long serialhsk;
unsigned long serialgpi;
unsigned long printf;
unsigned long printhsk;
unsigned long printgpi;
unsigned long cpuid;
unsigned long rombase;
unsigned long adbdelay;
unsigned long timedbra;
#if defined(EXTENDED_HW_MAP)
#define HW_MAP_VIA1 0x00000001
#define HW_MAP_VIA2_VIA 0x00000002
#define HW_MAP_VIA2_RBV 0x00000004
#define HW_MAP_VIA2_OSS 0x00000008
#define HW_MAP_ADB_IOP 0x00000010
#define HW_MAP_ADB_IISI 0x00000020
#define HW_MAP_ADB_CUDA 0x00000040
#define HW_MAP_ADB_PB1 0x00000080
#define HW_MAP_ASC 0x00000100
#define HW_MAP_SCSI5380 0x00000200
#define HW_MAP_SCSI5380DMA 0x00000400
#define HW_MAP_SCSI5396 0x00000800
#define HW_MAP_IDE_PB 0x00001000
#define HW_MAP_IDE_QUADRA 0x00002000
#define HW_MAP_NUBUS 0x00004000
#define HW_MAP_SCC_IOP 0x00008000
unsigned long HwMap;
unsigned long VIA1Base;
unsigned long VIA2Base;
unsigned long ASCBase;
unsigned long SCSIBase;
unsigned long NubusMap;
#endif
};
#else
#define BI_videoaddr BI_un
#define BI_videorow BI_videoaddr+4
#define BI_videodepth BI_videorow+4
#define BI_dimensions BI_videodepth+4
#define BI_args BI_dimensions+4
#endif
#define NUM_MEMINFO 4
#define MACH_AMIGA 1
#define MACH_ATARI 2
#define MACH_MAC 3
/*
* CPU and FPU types
*/
#define CPUB_68020 0
#define CPUB_68030 1
#define CPUB_68040 2
#define CPUB_68060 3
#define FPUB_68881 5
#define FPUB_68882 6
#define FPUB_68040 7 /* Internal FPU */
#define FPUB_68060 8 /* Internal FPU */
#define CPU_68020 (1<<CPUB_68020)
#define CPU_68030 (1<<CPUB_68030)
#define CPU_68040 (1<<CPUB_68040)
#define CPU_68060 (1<<CPUB_68060)
#define CPU_MASK (31)
#define FPU_68881 (1<<FPUB_68881)
#define FPU_68882 (1<<FPUB_68882)
#define FPU_68040 (1<<FPUB_68040) /* Internal FPU */
#define FPU_68060 (1<<FPUB_68060) /* Internal FPU */
#define FPU_MASK (0xfe0)
#define CL_SIZE (256)
#ifndef __ASSEMBLY__
struct bootinfo {
unsigned long machtype; /* machine type */
unsigned long cputype; /* system CPU & FPU */
struct mem_info memory[NUM_MEMINFO]; /* memory description */
unsigned long num_memory; /* # of memory blocks found */
unsigned long ramdisk_size; /* ramdisk size in 1024 byte blocks */
unsigned long ramdisk_addr; /* address of the ram disk in mem */
char command_line[CL_SIZE]; /* kernel command line parameters */
union {
struct bi_Macintosh bi_mac; /* Mac specific information */
} bi_un;
};
#define bi_mac bi_un.bi_mac
extern struct bootinfo boot_info;
#else /* __ASSEMBLY__ */
BI_machtype = 0
BI_cputype = BI_machtype+4
BI_memory = BI_cputype+4
BI_num_memory = BI_memory+(MI_sizeof*NUM_MEMINFO)
BI_ramdisk_size = BI_num_memory+4
BI_ramdisk_addr = BI_ramdisk_size+4
BI_command_line = BI_ramdisk_addr+4
BI_un = BI_command_line+CL_SIZE
#endif /* __ASSEMBLY__ */
/*
* Stuff for bootinfo interface versioning
*
* At the start of kernel code, a 'struct bootversion' is located. bootstrap
* checks for a matching version of the interface before booting a kernel, to
* avoid user confusion if kernel and bootstrap don't work together :-)
*
* If incompatible changes are made to the bootinfo interface, the major
* number below should be stepped (and the minor reset to 0) for the
* appropriate machine. If a change is backward-compatible, the minor should
* be stepped. "Backwards-compatible" means that booting will work, but
* certain features may not.
*/
#define BOOTINFOV_MAGIC 0x4249561A /* 'BIV^Z' */
#define MK_BI_VERSION(major,minor) (((major)<<16)+(minor))
#define BI_VERSION_MAJOR(v) (((v) >> 16) & 0xffff)
#define BI_VERSION_MINOR(v) ((v) & 0xffff)
#ifndef __ASSEMBLY__
struct bootversion {
unsigned short branch;
unsigned long magic;
struct {
unsigned long machtype;
unsigned long version;
} machversions[1];
};
#endif /* __ASSEMBLY__ */
#define AMIGA_BOOTI_VERSION MK_BI_VERSION( 1, 0 )
#define ATARI_BOOTI_VERSION MK_BI_VERSION( 1, 0 )
#define MAC_BOOTI_VERSION MK_BI_VERSION( 2, 0 )
/************************************************************************
* Version 2 bootinfo structure and new defs
*/
/*
* CPU, FPU and MMU types
*
* Note: we may rely on the following equalities:
*
* CPU_68020 == MMU_68851
* CPU_68030 == MMU_68030
* CPU_68040 == FPU_68040 == MMU_68040 (not strictly, think of 68LC040!)
* CPU_68060 == FPU_68060 == MMU_68060
*/
#define V2_CPUB_68020 0
#define V2_CPUB_68030 1
#define V2_CPUB_68040 2
#define V2_CPUB_68060 3
#define V2_CPU_68020 (1<<V2_CPUB_68020)
#define V2_CPU_68030 (1<<V2_CPUB_68030)
#define V2_CPU_68040 (1<<V2_CPUB_68040)
#define V2_CPU_68060 (1<<V2_CPUB_68060)
#define V2_FPUB_68881 0
#define V2_FPUB_68882 1
#define V2_FPUB_68040 2 /* Internal FPU */
#define V2_FPUB_68060 3 /* Internal FPU */
#define V2_FPUB_SUNFPA 4 /* Sun-3 FPA */
#define V2_FPU_68881 (1<<V2_FPUB_68881)
#define V2_FPU_68882 (1<<V2_FPUB_68882)
#define V2_FPU_68040 (1<<V2_FPUB_68040)
#define V2_FPU_68060 (1<<V2_FPUB_68060)
#define V2_FPU_SUNFPA (1<<V2_FPUB_SUNFPA)
#define V2_MMUB_68851 0
#define V2_MMUB_68030 1 /* Internal MMU */
#define V2_MMUB_68040 2 /* Internal MMU */
#define V2_MMUB_68060 3 /* Internal MMU */
#define V2_MMUB_APOLLO 4 /* Custom Apollo */
#define V2_MMUB_SUN3 5 /* Custom Sun-3 */
#define V2_MMU_68851 (1<<V2_MMUB_68851)
#define V2_MMU_68030 (1<<V2_MMUB_68030)
#define V2_MMU_68040 (1<<V2_MMUB_68040)
#define V2_MMU_68060 (1<<V2_MMUB_68060)
#define V2_MMU_SUN3 (1<<V2_MMUB_SUN3)
#define V2_MMU_APOLLO (1<<V2_MMUB_APOLLO)
struct bi2_record {
unsigned short tag; /* tag ID */
unsigned short size; /* size of record (in bytes) */
unsigned char data[0]; /* data */
};
struct bi2_record_list {
struct bi2_record *bi2_rec;
struct bi2_record_list *next;
};
/*
* Tag Definitions
*
* Machine independent tags start counting from 0x0000
* Machine dependent tags start counting from 0x8000
*/
#define V2_BI_LAST 0x0000 /* last record (sentinel) */
#define V2_BI_MACHTYPE 0x0001 /* machine type (u_long) */
#define V2_BI_CPUTYPE 0x0002 /* cpu type (u_long) */
#define V2_BI_FPUTYPE 0x0003 /* fpu type (u_long) */
#define V2_BI_MMUTYPE 0x0004 /* mmu type (u_long) */
#define V2_BI_MEMCHUNK 0x0005 /* memory chunk address and size */
/* (struct mem_info) */
#define V2_BI_RAMDISK 0x0006 /* ramdisk address and size */
/* (struct mem_info) */
#define V2_BI_COMMAND_LINE 0x0007 /* kernel command line parameters */
/* (string) */
/*
* Macintosh-specific tags
*/
#define V2_BI_MAC_MODEL 0x8000 /* Mac Gestalt ID (model type) */
#define V2_BI_MAC_VADDR 0x8001 /* Mac video base address */
#define V2_BI_MAC_VDEPTH 0x8002 /* Mac video depth */
#define V2_BI_MAC_VROW 0x8003 /* Mac video rowbytes */
#define V2_BI_MAC_VDIM 0x8004 /* Mac video dimensions */
#define V2_BI_MAC_VLOGICAL 0x8005 /* Mac video logical base */
#define V2_BI_MAC_SCCBASE 0x8006 /* Mac SCC base address */
#define V2_BI_MAC_BTIME 0x8007 /* Mac boot time */
#define V2_BI_MAC_GMTBIAS 0x8008 /* Mac GMT timezone offset */
#define V2_BI_MAC_MEMSIZE 0x8009 /* Mac RAM size (sanity check) */
#define V2_BI_MAC_CPUID 0x800a /* Mac CPU type (sanity check) */
#define V2_BI_MAC_ROMBASE 0x800b /* Mac system ROM base address */
/*
* Macintosh hardware profile data - unused, see macintosh.h for
* resonable type values
*/
#define V2_BI_MAC_VIA1BASE 0x8010 /* Mac VIA1 base address (always present) */
#define V2_BI_MAC_VIA2BASE 0x8011 /* Mac VIA2 base address (type varies) */
#define V2_BI_MAC_VIA2TYPE 0x8012 /* Mac VIA2 type (VIA, RBV, OSS) */
#define V2_BI_MAC_ADBTYPE 0x8013 /* Mac ADB interface type */
#define V2_BI_MAC_ASCBASE 0x8014 /* Mac Apple Sound Chip base address */
#define V2_BI_MAC_SCSI5380 0x8015 /* Mac NCR 5380 SCSI (base address, multi) */
#define V2_BI_MAC_SCSIDMA 0x8016 /* Mac SCSI DMA (base address) */
#define V2_BI_MAC_SCSI5396 0x8017 /* Mac NCR 53C96 SCSI (base address, multi) */
#define V2_BI_MAC_IDETYPE 0x8018 /* Mac IDE interface type */
#define V2_BI_MAC_IDEBASE 0x8019 /* Mac IDE interface base address */
#define V2_BI_MAC_NUBUS 0x801a /* Mac Nubus type (none, regular, pseudo) */
#define V2_BI_MAC_SLOTMASK 0x801b /* Mac Nubus slots present */
#define V2_BI_MAC_SCCTYPE 0x801c /* Mac SCC serial type (normal, IOP) */
#define V2_BI_MAC_ETHTYPE 0x801d /* Mac builtin ethernet type (Sonic, MACE */
#define V2_BI_MAC_ETHBASE 0x801e /* Mac builtin ethernet base address */
#define V2_BI_MAC_PMU 0x801f /* Mac power managment / poweroff hardware */
#define V2_BI_MAC_IOP_SWIM 0x8020 /* Mac SWIM floppy IOP */
#define V2_BI_MAC_IOP_ADB 0x8021 /* Mac ADB IOP */
/*
* Type definitions
*/
#define V2_VIA2_VIA 1
#define V2_VIA2_RBV 2
#define V2_VIA2_OSS 3
#define V2_ADB_II 1
#define V2_ADB_IISI 2
#define V2_ADB_CUDA 3
#define V2_ADB_PB1 4
#define V2_ADB_PB2 5
#define V2_ADB_IOP 6
#define V2_IDE_BASE 0x50F1A000
#define V2_IDE_QUADRA 1
#define V2_IDE_PB 2
#define V2_NUBUS_NORMAL 1
#define V2_NUBUS_PSEUDO 2
#define V2_SCC_NORMAL 1
#define V2_SCC_IOP 4
/* End version 2 bootinfo
***********************************************************************/
extern void set_kernel_bootinfo(char *dst);

384
second/console.c Normal file
View File

@ -0,0 +1,384 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include "glue.h"
#include "console.h"
typedef struct console_handler {
unsigned char* base;
unsigned long row_bytes; /* in bytes */
unsigned long depth; /* 8, 16 or 32 */
unsigned long width; /* in pixels */
unsigned long height;
unsigned long siz_w, siz_h;
unsigned long pos_x, pos_y;
} console_handler_t ;
static unsigned char bits_depth2[16] = {
0x00, /* 0 : 0000 -> 00000000 */
0x03, /* 1 : 0001 -> 00000011 */
0x0c, /* 2 : 0010 -> 00001100 */
0x0f, /* 3 : 0011 -> 00001111 */
0x30, /* 4 : 0100 -> 00110000 */
0x33, /* 5 : 0101 -> 00110011 */
0x3c, /* 6 : 0110 -> 00111100 */
0x3f, /* 7 : 0111 -> 00111111 */
0xc0, /* 8 : 1000 -> 11000000 */
0xc3, /* 9 : 1001 -> 11000011 */
0xcc, /* 10 : 1010 -> 11001100 */
0xcf, /* 11 : 1011 -> 11001111 */
0xf0, /* 12 : 1100 -> 11110000 */
0xf3, /* 13 : 1101 -> 11110011 */
0xfc, /* 14 : 1110 -> 11111100 */
0xff /* 15 : 1111 -> 11111111 */
};
static unsigned char bits_depth4[16] = {
0x00, /* 0 : 00 -> 00000000 */
0x0f, /* 1 : 01 -> 00001111 */
0xf0, /* 2 : 10 -> 11110000 */
0xFF /* 3 : 11 -> 11111111 */
};
static unsigned char bits_depth8[16] = {
0x00, /* 0 : 0 -> 00000000 */
0xff /* 0 : 1 -> 11111111 */
};
static console_handler_t console = { 0 }; /* initialized to be in data segment */
extern unsigned char* font_get(int c);
static void
draw_byte_1(unsigned char *glyph, unsigned char *base)
{
int l;
for (l = 0 ; l < 16; l++)
{
*base = ~(*glyph++);
base += console.row_bytes;
}
}
static void
draw_byte_2(unsigned char *glyph, unsigned char *base)
{
int l;
int bits;
for (l = 0 ; l < 16; l++)
{
bits = ~(*glyph++);
*base = bits_depth2[bits >> 4];
*(base+1) = bits_depth2[bits & 0x0F];
base += console.row_bytes;
}
}
static void
draw_byte_4(unsigned char *glyph, unsigned char *base)
{
int l;
int bits;
for (l = 0 ; l < 16; l++)
{
bits = ~(*glyph++);
base[3] = bits_depth4[bits & 0x03];
bits = bits >> 2;
base[2] = bits_depth4[bits & 0x03];
bits = bits >> 2;
base[1] = bits_depth4[bits & 0x03];
bits = bits >> 2;
base[0] = bits_depth4[bits & 0x03];
base += console.row_bytes;
}
}
static void
draw_byte_8(unsigned char *glyph, unsigned char *base)
{
int l;
int bits;
for (l = 0 ; l < 16; l++)
{
bits = ~(*glyph++);
base[7] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[6] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[5] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[4] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[3] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[2] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[1] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[0] = bits_depth8[bits & 0x01];
base += console.row_bytes;
}
}
static void
draw_byte_16(unsigned char *glyph, unsigned char *base)
{
int l;
int bits;
for (l = 0 ; l < 16; l++)
{
bits = *glyph++;
base[15] = base[14] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[13] = base[12] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[11] = base[10] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[9] = base[8] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[7] = base[6] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[5] = base[4] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[3] = base[2] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[1] = base[0] = bits_depth8[bits & 0x01];
base += console.row_bytes;
}
}
static void
draw_byte_24(unsigned char *glyph, unsigned char *base)
{
int l;
int bits;
for (l = 0 ; l < 16; l++)
{
bits = *glyph++;
base[23] = base[22] = base[21] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[20] = base[19] = base[18] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[17] = base[16] = base[15] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[14] = base[13] = base[12] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[11] = base[10] = base[9] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[8] = base[7] = base[6] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[5] = base[4] = base[3] = bits_depth8[bits & 0x01];
bits = bits >> 1;
base[2] = base[1] = base[0] = bits_depth8[bits & 0x01];
base += console.row_bytes;
}
}
static void
draw_byte(unsigned char c, unsigned long locX, unsigned long locY)
{
unsigned char *base;
unsigned char *glyph;
glyph = font_get(c);
base = console.base +
console.row_bytes * locY * 16 +
locX * console.depth;
switch(console.depth)
{
case 1:
draw_byte_1(glyph, base);
break;
case 2:
draw_byte_2(glyph, base);
break;
case 4:
draw_byte_4(glyph, base);
break;
case 8:
draw_byte_8(glyph, base);
break;
case 16:
draw_byte_16(glyph, base);
break;
case 24:
draw_byte_24(glyph, base);
break;
}
}
static void
console_scroll()
{
unsigned long j;
unsigned long *src;
unsigned long *dst;
unsigned long bg32;
/* move up the screen */
src = (unsigned long *)(console.base + console.row_bytes * 16);
dst = (unsigned long *)console.base;
for (j = 0; j < ((console.siz_h-1)*console.row_bytes<<2); j++)
*dst++ = *src++;
/* clear last line */
if (console.depth <= 8)
bg32 = 0xffffffff;
else
bg32 = 0x00000000;
for (j = 0; j < (console.row_bytes << 2); j++)
*dst++ = bg32;
}
void
console_init()
{
glue_display_properties((unsigned long*)&console.base,
&console.row_bytes,
&console.width,
&console.height,
&console.depth);
console.pos_x = 0;
console.pos_y = 0;
console.siz_w = console.width / 8;
console.siz_h = console.height / 16;
console_clear();
}
void
console_put(char c)
{
switch(c) {
case '\r':
console.pos_x = 0;
break;
case '\n':
console.pos_x = 0;
console.pos_y++;
break;
default:
draw_byte((unsigned char)c, console.pos_x++, console.pos_y);
if (console.pos_x >= console.siz_w) {
console.pos_x = 0;
console.pos_y++;
}
}
while (console.pos_y >= console.siz_h) {
console_scroll();
console.pos_y--;
}
}
void
console_print(char *s)
{
while(*s)
console_put(*(s++));
}
void
console_clear()
{
int i,j;
unsigned char bg;
unsigned long bg32;
unsigned long *base = (unsigned long*)console.base;
unsigned char *next;
if (console.depth <= 8)
{
bg = 0xff;
bg32 = 0xffffffff;
}
else
{
bg = 0x00;
bg32 = 0x00000000;
}
for (j = 0; j < console.height; j++)
{
for (i = 0; i < (console.row_bytes >> 2); i++)
*base++ = bg32;
next = (unsigned char*)base;
for (i = i << 2 ; i < console.row_bytes; i++)
*next++ = bg;
}
console.pos_x = 0;
console.pos_y = 0;
}
unsigned long console_get_videobase()
{
return (unsigned long)console.base;
}
unsigned long console_get_row_bytes()
{
return console.row_bytes;
}
unsigned long console_get_depth()
{
return console.depth;
}
unsigned long console_get_width()
{
return console.width;
}
unsigned long console_get_height()
{
return console.height;
}

22
second/console.h Normal file
View File

@ -0,0 +1,22 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
extern void console_init();
extern void console_clear();
extern void console_put(char c);
extern void console_print(char *s);
extern unsigned long console_get_videobase();
extern unsigned long console_get_row_bytes();
extern unsigned long console_get_depth();
extern unsigned long console_get_width();
extern unsigned long console_get_height();
#endif

58
second/enter_kernel.S Normal file
View File

@ -0,0 +1,58 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
.global enter_kernel
enter_kernel:
link.w %fp,#-8
/* get physical start address of kernel */
move.l 8(%fp), %a0
/* size of image to relocate */
move.l 12(%fp), %d0
/* disable interrupts */
ori.w #0x0700,%sr
/* disable MMU */
lea -8(%fp), %a1
pmove %tc, %a1@
bclr #7, %a1@
pmove %a1@, %tc
clr.l %a1@
pmove %a1@, %tt0
pmove %a1@, %tt1
/* copy kernel to 0x1000 */
move.l %a0, %a1
move.l #0x1000, %a2
move.l %d0, %d1
copy_loop:
move.b (%a1)+, (%a2)+
subq.l #1, %d1
bge.s copy_loop
/* disable and flush caches */
lea 0x0808, %a1
movec %a1, %cacr
/* jump into kernel */
move.l #0x1000, %a0
jmp %a0@
/* never comes here... I hope */
unlk %fp
rts

4624
second/font_8x16.c Normal file

File diff suppressed because it is too large Load Diff

140
second/glue.S Normal file
View File

@ -0,0 +1,140 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
/* #include <ConditionalMacros.h>
* #include <Quickdraw.h>
*/
.align 2
.globl glue_display_properties
.type glue_display_properties,@function
/*
* void
* glue_display_properties(unsigned long *base, unsigned long *row_bytes,
* unsigned long *width, unsigned long *height,
* unsigned long *depth)
*/
glue_display_properties:
/*
* GDHandle hdl;
* volatile PixMapPtr pm;
*/
link.w %a6,#-4
movm.l #0x3c,-(%sp)
move.l 8(%a6),%a3
move.l 12(%a6),%a5
move.l 24(%a6),%a4
/* hdl = LMGetMainDevice(); */
move.l 0x08A4,%a0
/* if (hdl == NULL || (**hdl).gdPMap == NULL)
* return;
*/
tst.l %a0
jbeq .exit
move.l (%a0),%a0
tst.l 22(%a0)
jbeq .exit
/* pm = *(**hdl).gdPMap; */
move.l 22(%a0),%a0
/* if (pm->baseAddr == NULL)
* return;
*/
move.l (%a0),-4(%a6)
move.l -4(%a6),%a0
tst.l (%a0)
jbeq .exit
/* *base = (unsigned char *)pm->baseAddr; */
move.l -4(%a6),%a0
move.l (%a0),(%a3)
/* *row_bytes = pm->rowBytes & 0x3fff; */
move.l -4(%a6),%a0
move.w 4(%a0),%d0
and.l #16383,%d0
move.l %d0,(%a5)
/* *width = pm->bounds.right - pm->bounds.left; */
move.l -4(%a6),%a0
move.w 12(%a0),%a2
move.l -4(%a6),%a1
move.l 16(%a6),%a0
sub.w 8(%a1),%a2
move.l %a2,(%a0)
/* *height = pm->bounds.bottom - pm->bounds.top; */
move.l -4(%a6),%a0
move.w 10(%a0),%a2
move.l -4(%a6),%a1
move.l 20(%a6),%a0
sub.w 6(%a1),%a2
move.l %a2,(%a0)
/* *depth = pm->pixelSize; */
move.l -4(%a6),%a0
move.w 32(%a0),%a0
move.l %a0,(%a4)
/* if (*depth == 15) *depth = 16; */
moveq.l #15,%d0
cmp.l %a0,%d0
jbne .not_15
moveq.l #16,%d0
move.l %d0,(%a4)
.not_15:
/* (*base) += pm->bounds.top * *row_bytes; */
move.l -4(%a6),%a0
move.w 6(%a0),%d0
ext.l %d0
muls.l (%a5),%d0
add.l %d0,(%a3)
/* (*base) += pm->bounds.left * ((*depth) >> 3); */
move.l -4(%a6),%a0
move.w 8(%a0),%d1
ext.l %d1
move.l (%a4),%d0
lsr.l #3,%d0
muls.l %d0,%d1
add.l %d1,(%a3)
.exit:
movm.l (%sp)+,#0x3c00
unlk %a6
rts
/* OSErr Gestalt(OSType selector, long * response) */
.global Gestalt
Gestalt:
link %fp, #0
move.l 8(%fp), %d0
dc.w 0xA1AD /* Gestalt */
move.l 12(%fp), %a1
move.l %a0, %a1@
unlk %fp
rts

11
second/glue.h Normal file
View File

@ -0,0 +1,11 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
extern void glue_display_properties(unsigned long *base,
unsigned long *row_bytes,
unsigned long *width, unsigned long *height,
unsigned long *depth);
extern int Gestalt(unsigned long selector, long * response);

34
second/head.S Normal file
View File

@ -0,0 +1,34 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
.global _start
_start:
/* initialize console, so we can debug ;-) */
bsr console_init
/* retrieve machine info before we make the mess */
bsr bootinfo_init;
/* initialize memory, so we can work */
bsr memory_init
/* allocate stack, so we can jump */
pea 0x2000
bsr malloc
add.l #0x2000 - 16, %d0
move.l %d0, %sp
/* begin to work */
bsr main
/* We guess to never come here */
loop:
bra loop

1176
second/inflate.c Normal file

File diff suppressed because it is too large Load Diff

42
second/ld.script Normal file
View File

@ -0,0 +1,42 @@
OUTPUT_ARCH(m68k)
SECTIONS
{
MemTop = 0x0108;
VIA1Base = 0x01D4;
SCCRd = 0x01d8;
ROMBase = 0x02ae;
HWCfgFlags = 0x0B22;
SCSIBase = 0x0C00;
ASCBase = 0x0CC0;
TimeVIADB = 0x0cea;
VIA2Base = 0x0CEC;
TimeDBRA = 0x0D00;
PMgrBase = 0x0D18;
UnivROMBits = 0x0DD4;
/* Read-only sections, merged into text segment: */
.text . :
{
__bootloader_start = .;
*(.text .stub .text.* .gnu.linkonce.t.*)
} =0x4e754e75
. = ALIGN(4);
.data . :
{
*(.data .data1 .data.* .gnu.linkonce.d.*)
}
. = ALIGN(4);
.rodata . :
{
*(.rodata .rodata1 .rodata.* .gnu.linkonce.r.*)
. = ALIGN(4);
_kernel_start = . ;
*(.image)
_kernel_end = . ;
. = ALIGN(4);
_ramdisk_start = . ;
*(.ramdisk)
_ramdisk_end = . ;
}
__bootloader_end = .;
}

20
second/lowmem.h Normal file
View File

@ -0,0 +1,20 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
/* these symbols are defined in ld.script */
extern unsigned long VIA1Base;
extern unsigned long SCCRd;
extern unsigned long ROMBase;
extern unsigned long HWCfgFlags;
extern unsigned long SCSIBase;
extern unsigned long ASCBase;
extern unsigned long VIA2Base;
extern unsigned long PMgrBase;
extern unsigned long UnivROMBits;
extern unsigned short TimeVIADB;
extern unsigned short TimeDBRA;
extern unsigned long MemTop;

78
second/main.c Normal file
View File

@ -0,0 +1,78 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
#include "memory.h"
#include "uncompress.h"
#include "bootinfo.h"
extern char _kernel_start;
extern char _kernel_end;
extern char _KERNEL_SIZE;
extern void enter_kernel(char* addr, unsigned long size);
#define BI_ALLOC_SIZE (4096L) // Allocate 4K for bootinfo
int main(int argc, char** argv)
{
char * kernel;
char* kernel_image_start = &_kernel_start;
unsigned long kernel_image_size = &_kernel_end - &_kernel_start;
unsigned long kernel_size = (unsigned long)&_KERNEL_SIZE;
memory_map_t map;
int i;
printf("Early Macintosh Image LoadEr\n");
printf("EMILE v"VERSION" (c) 2004 Laurent Vivier\n");
printf("This is free software, redistribute it under GPL\n");
printf("Kernel image found at %p\n", kernel_image_start);
printf("Kernel image size is %ld Bytes\n", kernel_image_size);
printf("Physical memory map:\n");
get_memory_map(&map);
for (i = 0; i < map.bank_number; i++)
{
printf("%d: 0x%08lx -> 0x%08lx\n", i, map.bank[i].address
, map.bank[i].address + map.bank[i].size);
}
if (kernel_image_size != 0)
{
/* add KERNEL_ALIGN if we have to align
* and BI_ALLOC_SIZE for bootinfo
*/
kernel = (char*)malloc(kernel_size + 4 + BI_ALLOC_SIZE);
if (kernel == 0)
{
printf("ERROR: cannot allocate %ld bytes\n", kernel_size);
while (1);
}
/* align kernel address to a 4 byte word */
kernel = (unsigned char*)(((unsigned long)kernel + 3) & 0xFFFFFFFC);
uncompress(kernel);
}
else
{
printf("Kernel is missing !!!!\n");
while(1) ;
}
printf("\nOk, booting the kernel.\n");
set_kernel_bootinfo(kernel + kernel_size);
enter_kernel(kernel, kernel_size + BI_ALLOC_SIZE);
return 0;
}

283
second/memory.c Normal file
View File

@ -0,0 +1,283 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
* portion from penguin booter
*
*/
#include <stdio.h>
#include "MMU.h"
#include "memory.h"
#include "lowmem.h"
/* Memory Allocation information */
#define MAX_MEMORY_AREA 4096
typedef struct memory_pool {
memory_area_t area[MAX_MEMORY_AREA];
unsigned long area_number;
} memory_pool_t;
memory_pool_t* pool = NULL;
static int memory_find_area_by_addr(unsigned long start)
{
int i;
for (i = 0; i < pool->area_number; i++)
{
if ( (pool->area[i].address <= start) &&
(start < pool->area[i].address + pool->area[i].size) )
{
return i;
}
}
return -1;
}
static int memory_find_area_by_size(unsigned long size)
{
int i;
for (i = 0; i < pool->area_number; i++)
{
if (size <= pool->area[i].size)
{
return i;
}
}
return -1;
}
static void memory_remove(unsigned long start, unsigned long end)
{
int i;
i = memory_find_area_by_addr(start);
if (i == -1)
return;
/* zone to remove is at start of area */
if (start == pool->area[i].address)
{
if (pool->area[i].size == end - start)
{
/* area can be removed */
pool->area_number--;
pool->area[i].address =
pool->area[pool->area_number].address;
pool->area[i].size = pool->area[pool->area_number].size;
}
else
{
/* we guess end < address + size ... */
pool->area[i].address = end;
pool->area[i].size -= end - start;
}
return;
}
/* zone to remove is at end of area */
if ( end == (pool->area[i].address + pool->area[i].size) )
{
/* we guess start >= address */
pool->area[i].size -= end - start;
return;
}
/* zone is in the middle of an area */
/* split in two parts an existing area */
/* second part : end -> original address + orignal size */
pool->area[pool->area_number].address = end;
pool->area[pool->area_number].size = pool->area[i].size - (end - start);
pool->area_number++;
/* first part : original address -> start */
pool->area[i].size = start - pool->area[i].address;
}
static void memory_add(unsigned long start, unsigned long end)
{
int i;
for (i = 0; i < pool->area_number; i++)
{
/* can we add it at end of existing area */
if ( start == (pool->area[i].address + pool->area[i].size) )
{
int j;
pool->area[i].size += end - start;
/* perhaps, now, we can merge with following area ? */
for (j = 0; j < pool->area_number; j++)
{
if ( end == pool->area[j].address )
{
pool->area[i].size += pool->area[j].size;
pool->area_number--;
pool->area[j].address = pool->area[pool->area_number].address;
pool->area[j].size = pool->area[pool->area_number].size;
return;
}
}
return;
}
/* can we add it at begin of existing area */
if ( end == pool->area[i].address )
{
pool->area[i].address = start;
pool->area[i].size += end - start;
return;
}
}
pool->area[pool->area_number].address = start;
pool->area[pool->area_number].size = end;
pool->area_number++;
}
void memory_init()
{
extern char __bootloader_start;
extern char __bootloader_end;
/* we are currently using the MMU to have only one linear memory area */
/* we put memory pool array at end of Memory */
pool = (memory_pool_t*) (MemTop - sizeof(memory_pool_t));
pool->area_number = 0;
/* add all memory to pool */
memory_add(0, MemTop);
/* remove the pool array */
memory_remove( (unsigned long)pool,
(unsigned long)pool + sizeof(memory_pool_t));
/* remove the booloader image */
memory_remove( (unsigned long)&__bootloader_start,
(unsigned long)&__bootloader_end);
/* remove the final address of the kernel */
memory_remove(0x0000, 0x180000); /* FIXME: why 0x180000 ? */
}
void *malloc(size_t size)
{
unsigned long addr;
int area;
size = ((size + 3) & ~0x3L) + 4; /* reserve 4 bytes to store size */
area = memory_find_area_by_size(size);
if (area == -1)
return NULL;
/* remove area from free memory pool */
addr = pool->area[area].address;
memory_remove(addr, addr + size);
*(unsigned long*)addr = size; /* store size of area in first word */
return (void*)(addr + 4);
}
void free(void *ptr)
{
ptr = ptr - 4;
memory_add((unsigned long)ptr, (unsigned long)ptr + *(unsigned long*)ptr);
}
static void bank_add_mem(memory_map_t* map, unsigned long addr, unsigned long size)
{
int i;
int j;
for (i = 0; i < map->bank_number; i++)
{
if (map->bank[i].address + map->bank[i].size == addr)
{
map->bank[i].size += size;
/* can we merge 2 banks */
for (j = 0; j < map->bank_number; j++)
{
if (map->bank[i].address + map->bank[i].size == map->bank[j].address)
{
map->bank[i].size += map->bank[j].size;
/* remove bank */
map->bank_number--;
map->bank[j].address = map->bank[map->bank_number].address;
map->bank[j].size = map->bank[map->bank_number].size;
}
}
return;
}
else if (addr + size == map->bank[i].address)
{
map->bank[i].address = addr;
map->bank[i].size += size;
return;
}
}
/* not found, create new bank */
if (map->bank_number >= MAX_MEM_MAP_SIZE)
return;
map->bank[map->bank_number].address = addr;
map->bank[map->bank_number].size = size;
map->bank_number++;
}
void get_memory_map(memory_map_t* map)
{
unsigned long logical;
unsigned long physical;
int ps = get_page_size();
map->bank_number = 0;
for (logical = 0; logical < MemTop; logical += ps)
{
if (logical2physical(logical, &physical) == 0)
{
bank_add_mem(map, physical, ps);
}
}
}

24
second/memory.h Normal file
View File

@ -0,0 +1,24 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
* portion from penguin booter
*
*/
/* physical memory information */
#define MAX_MEM_MAP_SIZE 26
typedef struct memory_area {
unsigned long address;
unsigned long size;
} memory_area_t;
typedef struct memory_map {
memory_area_t bank[MAX_MEM_MAP_SIZE];
unsigned long bank_number;
} memory_map_t;
extern void get_memory_map(memory_map_t* map);

58
second/misc.c Normal file
View File

@ -0,0 +1,58 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <unistd.h>
#include <stdio.h>
#include "misc.h"
int strlen(const char* s)
{
int len;
if (!s) return 0;
len = 0;
while (*s++) len++;
return len;
}
void* memset(void* s, int c, size_t n)
{
int i;
char *ss = (char*)s;
for (i=0;i<n;i++) ss[i] = c;
return s;
}
void* memcpy(void* __dest, __const void* __src,
size_t __n)
{
int i;
char *d = (char *)__dest, *s = (char *)__src;
for (i=0;i<__n;i++) d[i] = s[i];
return __dest;
}
char *strncpy (char *__restrict __dest,
__const char *__restrict __src, size_t __n)
{
while ( (*__dest ++ = *__src++) && __n--);
return __dest;
}
void error(char *x)
{
printf("\n\n");
printf(x);
printf("\n\n -- System halted");
while(1); /* Halt */
}

7
second/misc.h Normal file
View File

@ -0,0 +1,7 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
extern void error(char *x);

246
second/printf.c Normal file
View File

@ -0,0 +1,246 @@
/*-
* Copyright (c) 1986, 1988, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this
software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
*
*
* Extracted vsprinf & adapted by BenH for MountX, Wed, June 3 1998.
* Added support for pascal strings.
*/
#include <stdarg.h>
#include <stdio.h>
#include "console.h"
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned char u_char;
#define NBBY 8
static char *ksprintn(u_long ul, int base, int *lenp, int prec);
int sprintf(char * s, const char * format, ...)
{
va_list params;
int r;
va_start(params, format);
r = vsprintf(s, format, params);
va_end(params);
return r;
}
/*
* Scaled down version of sprintf(3).
*/
int
vsprintf(char *buf, const char *cfmt, va_list ap)
{
register const char *fmt = cfmt;
register char *p, *bp;
register int ch, base;
u_long ul;
int lflag, tmp, width, pstring;
int prec, precspec;
char padc;
for (bp = buf; ; ) {
padc = ' ';
width = 0;
prec = 0;
precspec = 0;
pstring = 0;
while ((ch = *(u_char *)fmt++) != '%')
if ((*bp++ = (char)ch) == '\0')
return ((bp - buf) - 1);
lflag = 0;
reswitch: switch (ch = *(u_char *)fmt++) {
case '0':
padc = '0';
goto reswitch;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
for (width = 0;; ++fmt) {
width = width * 10 + ch - '0';
ch = *fmt;
if (ch < '0' || ch > '9')
break;
}
goto reswitch;
case '#':
pstring = 1;
goto reswitch;
case '*':
width = va_arg(ap, int);
goto reswitch;
case '.':
precspec = 1;
if (*fmt == '*') {
prec = va_arg(ap, int);
++fmt;
goto reswitch;
}
for (prec = 0;; ++fmt) {
ch = *fmt;
if (ch < '0' || ch > '9')
break;
prec = prec * 10 + ch - '0';
}
goto reswitch;
case 'l':
lflag = 1;
goto reswitch;
/* case 'b': ... break; XXX */
case 'c':
*bp++ = (char)va_arg(ap, int);
break;
/* case 'r': ... break; XXX */
case 's':
p = va_arg(ap, char *);
if (pstring)
{
prec = precspec ? ((prec < *p) ? prec : *p) : *p;
p++;
precspec = 1;
}
while ((!precspec || (--prec >= 0)) && ((*bp = *p++) != 0))
++bp;
break;
case 'd':
ul = (unsigned long)(lflag ? va_arg(ap, long) : va_arg(ap, int));
if ((long)ul < 0) {
*bp++ = (char)'-';
ul = (unsigned long)(-(long)ul);
}
base = 10;
goto number;
break;
case 'o':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap,
u_int);
base = 8;
goto number;
break;
case 'u':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap,
u_int);
base = 10;
goto number;
break;
case 'p':
*bp++ = '0';
*bp++ = 'x';
ul = (u_long)va_arg(ap, void *);
base = 16;
goto number;
case 'x':
case 'X':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap,
u_int);
base = 16;
number: p = ksprintn(ul, base, &tmp, prec);
if (width && (width -= tmp) > 0)
while (width--)
*bp++ = padc;
while ((ch = *p--) != 0)
*bp++ = (char)ch;
break;
default:
*bp++ = '%';
if (lflag)
*bp++ = 'l';
/* FALLTHROUGH */
case '%':
*bp++ = (char)ch;
}
}
}
/*
* Put a number (base <= 16) in a buffer in reverse order; return an
* optional length and a pointer to the NULL terminated (preceded?)
* buffer.
*/
static char *
ksprintn(u_long ul, int base, int *lenp, int prec)
{ /* A long in base 8, plus NULL. */
char buf[sizeof(long) * NBBY / 3 + 4];
register char *p;
int i;
p = buf;
for(i=0;i<sizeof(buf);i++)
buf[i] = 0;
do {
*++p = "0123456789abcdef"[ul % base];
ul /= base;
} while ((--prec > 0 || ul != 0) && p < buf + sizeof(buf) - 1);
if (lenp)
*lenp = p - buf;
return (p);
}
static char __printf_buffer[2048] = { 0 };
int
printf(const char * format, ...)
{
va_list args;
int len;
va_start(args, format);
len = vsprintf(__printf_buffer, format, args);
va_end(args);
if (len)
console_print(__printf_buffer);
return len;
}

102
second/uncompress.c Normal file
View File

@ -0,0 +1,102 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
#include "console.h"
#include "uncompress.h"
#include "misc.h"
extern char _kernel_start;
extern char _kernel_end;
/*
* gzip declarations
*/
#define OF(args) args
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
static long bytes_out = 0;
static uch *inbuf = 0; /* input buffer */
static uch window[WSIZE] = { 0 }; /* Sliding window buffer */
static unsigned insize = 0; /* valid bytes in inbuf */
static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
static unsigned outcnt = 0; /* bytes in output buffer */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
static uch *output_data = (uch*)0;
static unsigned long output_ptr = 0;
#define Assert(cond,msg)
#define Trace(x)
#define Tracev(x)
#define Tracevv(x)
#define Tracec(c,x)
#define Tracecv(c,x)
#define memzero(s, n) memset ((s), 0, (n))
static int fill_inbuf(void)
{
inbuf = &_kernel_start;
insize = &_kernel_end - &_kernel_start;
inptr = 1;
return inbuf[0];
}
static void gzip_mark(void **ptr)
{
}
static void gzip_release(void **ptr)
{
}
static void flush_window(void);
#define STATIC
#include "inflate.c"
static void flush_window(void)
{
ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
in = window;
out = output_data + output_ptr;
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
console_put('.');
}
unsigned long uncompress(char* buf)
{
output_data = buf;
makecrc();
printf("Uncompressing kernel to %p", buf);
gunzip();
return (unsigned long)output_data - (unsigned long)buf;
}

7
second/uncompress.h Normal file
View File

@ -0,0 +1,7 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
extern unsigned long uncompress(char* buf);