pax_global_header 0000666 0000000 0000000 00000000064 14032332560 0014510 g ustar 00root root 0000000 0000000 52 comment=df1f421d8acca90ae3a9ea312fe867c29d1e8f5b
LICENSE 0000664 0000000 0000000 00000104515 14032332560 0012067 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. 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
them 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 prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. 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.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey 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;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
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.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
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.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
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
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
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 3 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, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program 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, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU 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 Lesser General
Public License instead of this License. But first, please read
.
README.md 0000664 0000000 0000000 00000000221 14032332560 0012326 0 ustar 00root root 0000000 0000000 Inside is a standard C library for those who need to bootstrap from nothing.
As all of the pieces inside will work with M2-Planet and mescc-tools aarch64/ 0000775 0000000 0000000 00000000000 14032332560 0012304 5 ustar 00root root 0000000 0000000 aarch64/ELF-aarch64-debug.hex2 0000664 0000000 0000000 00000006405 14032332560 0016021 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### Copyright (C) 2020 deesix
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
B7 00 # e_machine Indicating AArch64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
%ELF_section_headers>ELF_base 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
40 00 # e_shentsize size of a section header table
05 00 # e_shnum number of entries in section table
02 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text
aarch64/ELF-aarch64.hex2 0000664 0000000 0000000 00000006405 14032332560 0014735 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### Copyright (C) 2020 deesix
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
B7 00 # e_machine Indicating AArch64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text
aarch64/Linux/ 0000775 0000000 0000000 00000000000 14032332560 0013403 5 ustar 00root root 0000000 0000000 aarch64/Linux/bootstrap.c 0000664 0000000 0000000 00000006353 14032332560 0015573 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2020 deesix
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"PUSH_X0"
"SET_X1_FROM_SP"
"SET_X2_TO_1"
"SET_X8_TO_SYS_READ"
"SYSCALL"
"SET_X1_TO_0"
"CMP_X1_X0"
"POP_X0"
"SKIP_INST_NE"
"SET_X0_TO_MINUS_1");
}
void fputc(char s, FILE* f)
{
asm("SET_X0_FROM_BP" "SUB_X0_8"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X2_TO_1"
"SET_X8_TO_SYS_WRITE"
"SYSCALL");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open(char* name, int flag, int mode)
{
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X3_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_TO_FCNTL_H_AT_FDCWD"
"SET_X8_TO_SYS_OPENAT"
"SYSCALL");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
if('w' == mode[0])
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
f = open(filename, 577 , 384);
}
else
{ /* Everything else is a read */
f = open(filename, 0, 0);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_CLOSE"
"SYSCALL");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_BRK"
"SYSCALL");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_EXIT"
"SYSCALL");
}
aarch64/Linux/fcntl.h 0000664 0000000 0000000 00000002506 14032332560 0014665 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2020 deesix
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X3_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_TO_FCNTL_H_AT_FDCWD"
"SET_X8_TO_SYS_OPENAT"
"SYSCALL");
}
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
aarch64/Linux/unistd.h 0000664 0000000 0000000 00000010650 14032332560 0015064 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* Copyright (C) 2020 deesix
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_TO_0"
"SET_X3_FROM_X0"
"SET_X0_TO_FCNTL_H_AT_FDCWD"
"SET_X8_TO_SYS_FACCESSAT"
"SYSCALL");
}
int chdir(char* path)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_CHDIR"
"SYSCALL");
}
int fchdir(int fd)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_FCHDIR"
"SYSCALL");
}
void _exit(int value);
int fork()
{
asm("SET_X0_TO_0"
"SET_X1_FROM_X0"
"SET_X2_FROM_X0"
"SET_X3_FROM_X0"
"SET_X4_FROM_X0"
"SET_X5_FROM_X0"
"SET_X6_FROM_X0"
"SET_X0_TO_17"
"SET_X8_TO_SYS_CLONE"
"SYSCALL");
}
int waitpid (int pid, int* status_ptr, int options)
{
asm("SET_X0_TO_MINUS_1"
"SET_X3_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_WAIT4"
"SYSCALL");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_EXECVE"
"SYSCALL");
}
int read(int fd, char* buf, unsigned count)
{
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_READ"
"SYSCALL");
}
int write(int fd, char* buf, unsigned count)
{
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_WRITE"
"SYSCALL");
}
int lseek(int fd, int offset, int whence)
{
asm("SET_X0_TO_MINUS_1"
"SET_X3_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_LSEEK"
"SYSCALL");
}
int close(int fd)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_CLOSE"
"SYSCALL");
}
int _getcwd(char* buf, int size)
{
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_GETCWD"
"SYSCALL");
}
char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
return buf;
}
char* getwd(char* buf)
{
return getcwd(buf, __PATH_MAX);
}
char* get_current_dir_name()
{
return getcwd(malloc(__PATH_MAX), __PATH_MAX);
}
int brk(void *addr)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_BRK"
"SYSCALL");
}
int chmod(char *pathname, int mode)
{
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
"SET_X2_FROM_X0"
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X1_FROM_X0"
"SET_X0_TO_0"
"SET_X3_FROM_X0"
"SET_X0_TO_FCNTL_H_AT_FDCWD"
"SET_X8_TO_SYS_FCHMODAT"
"SYSCALL");
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
"SET_X8_TO_SYS_UNAME"
"SYSCALL");
}
aarch64/aarch64_defs.M1 0000664 0000000 0000000 00000007624 14032332560 0014745 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2020 deesix
## Copyright (C) 2020 Sanne Wouda
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
DEFINE NULL 0000000000000000
# Stack (x18 as SP, 64 bits per element)
DEFINE PUSH_X0 408e1ff8
DEFINE PUSH_X1 418e1ff8
DEFINE PUSH_X16 508e1ff8
DEFINE PUSH_BP 518e1ff8
DEFINE PUSH_LR 5e8e1ff8
DEFINE POP_X0 408640f8
DEFINE POP_X1 418640f8
DEFINE POP_X16 508640f8
DEFINE POP_BP 518640f8
DEFINE POP_LR 5e8640f8
DEFINE INIT_SP f2030091 # mov x18, sp
# Jump/branch/call/return
DEFINE BR_X16 00021fd6
DEFINE BLR_X16 00023fd6
DEFINE RETURN c0035fd6
DEFINE CBZ_X0_PAST_BR a00000b4
DEFINE CBNZ_X0_PAST_BR a00000b5
DEFINE SKIP_INST_EQ 40000054
DEFINE SKIP_INST_NE 41000054
DEFINE SKIP_INST_LT 4b000054
DEFINE SKIP_INST_LE 4d000054
DEFINE SKIP_INST_GT 4c000054
DEFINE SKIP_INST_GE 4a000054
DEFINE SKIP_INST_LO 43000054
DEFINE SKIP_INST_LS 49000054
DEFINE SKIP_INST_HS 42000054
DEFINE SKIP_INST_HI 48000054
DEFINE SKIP_32_DATA 02000014
# Load literals (PC-relative)
DEFINE LOAD_W0_AHEAD 40000098
DEFINE LOAD_W1_AHEAD 41000018
DEFINE LOAD_W2_AHEAD 42000018
DEFINE LOAD_W16_AHEAD 50000018
# Load/store/dereference
DEFINE LDR_X0_[SP] 400240f9
DEFINE STR_X0_[X1] 200000f9
DEFINE STR_BYTE_W0_[X1] 20000039
DEFINE DEREF_X0 000040f9
DEFINE DEREF_X0_BYTE 00004039
# Move data between registers
DEFINE SET_X0_FROM_BP e00311aa
DEFINE SET_X1_FROM_X0 e10300aa
DEFINE SET_X1_FROM_SP e10312aa
DEFINE SET_X2_FROM_X0 e20300aa
DEFINE SET_X3_FROM_X0 e30300aa
DEFINE SET_X4_FROM_X0 e40300aa
DEFINE SET_X5_FROM_X0 e50300aa
DEFINE SET_X6_FROM_X0 e60300aa
DEFINE SET_X16_FROM_X0 f00300aa
DEFINE SET_X16_FROM_SP f00312aa
DEFINE SET_BP_FROM_X16 f10310aa
DEFINE SET_BP_FROM_SP f10312aa
# Move constant to register
DEFINE SET_X0_TO_0 000080d2
DEFINE SET_X0_TO_1 200080d2
DEFINE SET_X0_TO_17 200280d2
DEFINE SET_X0_TO_MINUS_1 00008092
DEFINE SET_W0_TO_MINUS_1 00008012
DEFINE SET_X1_TO_0 010080d2
DEFINE SET_X1_TO_2 410080d2
DEFINE SET_X1_TO_8 010180d2
DEFINE SET_X2_TO_1 220080d2
DEFINE SET_X0_TO_FCNTL_H_AT_FDCWD 600c8092
# Arith/logic/relational
DEFINE ADD_X0_X1_X0 2000008b
DEFINE ADD_X0_BP_X0 2002008b
DEFINE ADD_X1_SP_8 41220091
DEFINE SUB_X0_X1_X0 200000cb
DEFINE SUB_X0_X0_X1 000001cb
DEFINE SUB_X0_8 002000d1
DEFINE SUB_X0_16 004000d1
DEFINE SUB_X0_24 006000d1
DEFINE MSUB_X0_X0_X2_X1 0084029b
DEFINE MUL_X0_X1_X0 207c009b
DEFINE SDIV_X0_X1_X0 200cc09a
DEFINE SDIV_X2_X1_X0 220cc09a
DEFINE UDIV_X0_X1_X0 2008c09a
DEFINE UDIV_X2_X1_X0 2208c09a
DEFINE LSHIFT_X0_X0_X2 0020c29a
DEFINE LSHIFT_X0_X1_X0 2020c09a
DEFINE LOGICAL_RSHIFT_X0_X1_X0 2024c09a
DEFINE ARITH_RSHIFT_X0_X1_X0 2028c09a
DEFINE MVN_X0 e00320aa
DEFINE AND_X0_X1_X0 2000008a
DEFINE OR_X0_X1_X0 200000aa
DEFINE XOR_X0_X1_X0 000001ca
DEFINE CMP_X1_X0 3f0000eb
# Syscall
DEFINE SET_X8_TO_SYS_BRK c81a80d2
DEFINE SET_X8_TO_SYS_CHDIR 280680d2
DEFINE SET_X8_TO_SYS_CLONE 881b80d2
DEFINE SET_X8_TO_SYS_CLOSE 280780d2
DEFINE SET_X8_TO_SYS_EXECVE a81b80d2
DEFINE SET_X8_TO_SYS_EXIT a80b80d2
DEFINE SET_X8_TO_SYS_FACCESSAT 080680d2
DEFINE SET_X8_TO_SYS_FCHDIR 480680d2
DEFINE SET_X8_TO_SYS_FCHMODAT a80680d2
DEFINE SET_X8_TO_SYS_GETCWD 280280d2
DEFINE SET_X8_TO_SYS_LSEEK c80780d2
DEFINE SET_X8_TO_SYS_OPENAT 080780d2
DEFINE SET_X8_TO_SYS_READ e80780d2
DEFINE SET_X8_TO_SYS_UNAME 081480d2
DEFINE SET_X8_TO_SYS_WAIT4 882080d2
DEFINE SET_X8_TO_SYS_WRITE 080880d2
DEFINE SYSCALL 010000d4
aarch64/libc-core.M1 0000664 0000000 0000000 00000002275 14032332560 0014350 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2020 deesix
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
INIT_SP
LDR_X0_[SP]
ADD_X1_SP_8
SET_BP_FROM_SP
PUSH_X0
PUSH_X1
SET_X1_TO_2
ADD_X0_X1_X0
SET_X1_TO_8
MUL_X0_X1_X0
ADD_X0_BP_X0
PUSH_X0
LOAD_W16_AHEAD
SKIP_32_DATA
&FUNCTION_main
BLR_X16
POP_X1
POP_X1
POP_X1
PUSH_X0 ; Put return on the stack
PUSH_X0 ; So that _exit has it
PUSH_X0 ; So that _exit has it
:FUNCTION_exit
:FUNCTION__exit
SET_X0_FROM_BP
SUB_X0_8
DEREF_X0
SET_X8_TO_SYS_EXIT
SYSCALL
aarch64/libc-full.M1 0000664 0000000 0000000 00000002531 14032332560 0014355 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2020 deesix
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
INIT_SP
LDR_X0_[SP]
ADD_X1_SP_8
SET_BP_FROM_SP
PUSH_X0
PUSH_X1
SET_X1_TO_2
ADD_X0_X1_X0
SET_X1_TO_8
MUL_X0_X1_X0
ADD_X0_BP_X0
PUSH_X0
;; Setup for FILE*
LOAD_W16_AHEAD
SKIP_32_DATA
&FUNCTION___init_io
BLR_X16
;; Call main
LOAD_W16_AHEAD
SKIP_32_DATA
&FUNCTION_main
BLR_X16
POP_X1
POP_X1
POP_X1
PUSH_X0 ; Put return on the stack
PUSH_X0 ; So that _exit has it
PUSH_X0 ; So that _exit has it
:FUNCTION_exit
LOAD_W16_AHEAD
SKIP_32_DATA
&FUNCTION___kill_io
BLR_X16
:FUNCTION__exit
SET_X0_FROM_BP
SUB_X0_8
DEREF_X0
SET_X8_TO_SYS_EXIT
SYSCALL
amd64/ 0000775 0000000 0000000 00000000000 14032332560 0011767 5 ustar 00root root 0000000 0000000 amd64/ELF-amd64-debug.hex2 0000664 0000000 0000000 00000006324 14032332560 0015167 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
3E 00 # e_machine Indicating AMD64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
%ELF_section_headers>ELF_base 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
40 00 # e_shentsize size of a section header table
05 00 # e_shnum number of entries in section table
02 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text
amd64/ELF-amd64.hex2 0000664 0000000 0000000 00000006324 14032332560 0014103 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
3E 00 # e_machine Indicating AMD64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text
amd64/Linux/ 0000775 0000000 0000000 00000000000 14032332560 0013066 5 ustar 00root root 0000000 0000000 amd64/Linux/bootstrap.c 0000664 0000000 0000000 00000006474 14032332560 0015262 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %0"
"PUSH_RAX"
"LOAD_EFFECTIVE_ADDRESS_rsi %0"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL"
"LOAD_IMMEDIATE_rbx %0"
"CMP"
"POP_RAX"
"JUMP_NE %FUNCTION_fgetc_Done"
"LOAD_IMMEDIATE_rax %-1"
":FUNCTION_fgetc_Done");
}
void fputc(char s, FILE* f)
{
asm("LOAD_IMMEDIATE_rax %1"
"LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open(char* name, int flag, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %2"
"SYSCALL");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
if('w' == mode[0])
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
f = open(filename, 577 , 384);
}
else
{ /* Everything else is a read */
f = open(filename, 0, 0);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %3"
"SYSCALL");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("LOAD_RSP_IMMEDIATE_into_rax %8"
"PUSH_RAX"
"LOAD_IMMEDIATE_rax %12"
"POP_RBX"
"COPY_rbx_to_rdi"
"SYSCALL");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("POP_RBX"
"POP_RDI"
"LOAD_IMMEDIATE_rax %0x3C"
"SYSCALL");
}
amd64/Linux/fcntl.h 0000664 0000000 0000000 00000002350 14032332560 0014345 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %2"
"SYSCALL");
}
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
amd64/Linux/unistd.h 0000664 0000000 0000000 00000010412 14032332560 0014543 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %21"
"SYSCALL");
}
int chdir(char* path)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %80"
"SYSCALL");
}
int fchdir(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %81"
"SYSCALL");
}
void _exit(int value);
int fork()
{
asm("LOAD_IMMEDIATE_rax %57"
"LOAD_IMMEDIATE_rdi %0"
"SYSCALL");
}
int waitpid (int pid, int* status_ptr, int options)
{
/* Uses wait4 with struct rusage *ru set to NULL */
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_r10 %0"
"LOAD_IMMEDIATE_rax %61"
"SYSCALL");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %59"
"SYSCALL");
}
int read(int fd, char* buf, unsigned count)
{ /*maybe*/
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %0"
"SYSCALL");
}
int write(int fd, char* buf, unsigned count)
{/*maybe*/
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %1"
"SYSCALL");
}
int lseek(int fd, int offset, int whence)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %8"
"SYSCALL");
}
int close(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %3"
"SYSCALL");
}
int _getcwd(char* buf, int size)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %79"
"SYSCALL");
}
char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
return buf;
}
char* getwd(char* buf)
{
return getcwd(buf, __PATH_MAX);
}
char* get_current_dir_name()
{
return getcwd(malloc(__PATH_MAX), __PATH_MAX);
}
int brk(void *addr)
{
asm("LOAD_RSP_IMMEDIATE_into_rax %8"
"PUSH_RAX"
"LOAD_IMMEDIATE_rax %12"
"POP_RBX"
"COPY_rbx_to_rdi"
"SYSCALL");
}
int chmod(char *pathname, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %90"
"SYSCALL");
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %63"
"SYSCALL");
}
amd64/amd64_defs.M1 0000664 0000000 0000000 00000005661 14032332560 0014112 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2017 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
DEFINE ADD_IMMEDIATE_to_rax 4805
DEFINE ADD_IMMEDIATE_to_rbp 4881C5
DEFINE ADD_rax_to_rbx 4801C3
DEFINE ADD_rbp_to_rax 4801E8
DEFINE ADD_rbx_to_rax 4801D8
DEFINE AND_rax_rbx 4821D8
DEFINE CALL_IMMEDIATE E8
DEFINE CALL_rax FFD0
DEFINE CMP 4839C3
DEFINE COPY_rax_to_rcx 4889C1
DEFINE COPY_rax_to_rdi 4889C7
DEFINE COPY_rbx_to_rax 4889D8
DEFINE COPY_rbp_to_rax 4889E8
DEFINE COPY_rbx_to_rdi 4889DF
DEFINE COPY_rdi_to_rbp 4889FD
DEFINE COPY_rsp_to_rbp 4889E5
DEFINE COPY_RSP_to_RDI 4889E7
DEFINE CQTO 4899
DEFINE DIVIDE_rax_by_rbx_into_rax 48F7F3
DEFINE DIVIDES_rax_by_rbx_into_rax 48F7FB
DEFINE JUMP E9
DEFINE JUMP_EQ 0F84
DEFINE JUMP_NE 0F85
DEFINE LOAD_BASE_ADDRESS_rax 488D85
DEFINE LOAD_BYTE 0FBE00
DEFINE LOAD_EFFECTIVE_ADDRESS_rax 488D8424
DEFINE LOAD_EFFECTIVE_ADDRESS_rdi 488DBC24
DEFINE LOAD_EFFECTIVE_ADDRESS_rdx 488D9424
DEFINE LOAD_EFFECTIVE_ADDRESS_rsi 488DB424
DEFINE LOAD_IMMEDIATE_r10 48C7C2
DEFINE LOAD_IMMEDIATE_rax 48C7C0
DEFINE LOAD_IMMEDIATE_rbx 48C7C3
DEFINE LOAD_IMMEDIATE_rdi 48C7C7
DEFINE LOAD_IMMEDIATE_rdx 48C7C2
DEFINE LOAD_IMMEDIATE_rsi 48C7C6
DEFINE LOAD_INTEGER 488B00
DEFINE LOAD_INTEGER_rdi 488B3F
DEFINE LOAD_INTEGER_rdx 488B12
DEFINE LOAD_INTEGER_rsi 488B36
DEFINE LOAD_RSP_IMMEDIATE_into_rax 488B8424
DEFINE MODULUS_rax_from_rbx_into_rbx 48F7F3
DEFINE MODULUSS_rax_from_rbx_into_rbx 48F7FB
DEFINE MOVE_rbx_to_rax 4889D8
DEFINE MOVE_rdx_to_rax 4889D0
DEFINE MOVEZX 480FB6C0
DEFINE MOVESX 4863C0
DEFINE MULTIPLY_rax_by_rbx_into_rax 48F7EB
DEFINE MULTIPLYS_rax_by_rbx_into_rax 48F7E3
DEFINE NULL 0000000000000000
DEFINE NOT_rax 48F7D0
DEFINE OR_rax_rbx 4809D8
DEFINE POP_RAX 58
DEFINE POP_RBP 5D
DEFINE POP_RBX 5B
DEFINE POP_RDI 5F
DEFINE PUSH_RAX 50
DEFINE PUSH_RBP 55
DEFINE PUSH_RBX 53
DEFINE PUSH_RDI 57
DEFINE RETURN C3
DEFINE SAL_rax_Immediate8 48C1E0
DEFINE SHL_rax_cl 48D3E0
DEFINE SAL_rax_cl 48D3F0
DEFINE SHR_rax_cl 48D3E8
DEFINE SAR_rax_cl 48D3F8
DEFINE SETA 0F97C0
DEFINE SETAE 0F93C0
DEFINE SETB 0F92C0
DEFINE SETBE 0F96C0
DEFINE SETE 0F94C0
DEFINE SETG 0F9FC0
DEFINE SETGE 0F9DC0
DEFINE SETL 0F9CC0
DEFINE SETLE 0F9EC0
DEFINE SETNE 0F95C0
DEFINE STORE_CHAR 8803
DEFINE STORE_INTEGER 488903
DEFINE SUBTRACT_rax_from_rbx_into_rbx 4829C3
DEFINE SYSCALL 0F05
DEFINE TEST 4885C0
DEFINE XCHG_rax_rbx 4893
DEFINE XOR_rbx_rax_into_rax 4831D8
amd64/libc-core.M1 0000664 0000000 0000000 00000003007 14032332560 0014025 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
COPY_rsp_to_rbp ; Protect rsp
;; Prepare argv
LOAD_BASE_ADDRESS_rax %8 ; ARGV_address = RBP + 8
PUSH_RAX ; Put argv on the stack
;; Prepare envp
COPY_rbp_to_rax ; Address we need to load from
LOAD_INTEGER ; Get ARGC
ADD_IMMEDIATE_to_rax %2 ; OFFSET = ARGC + 2
SAL_rax_Immediate8 !3 ; OFFSET = OFFSET * WORDSIZE
ADD_rbp_to_rax ; ENVP_address = RSP + OFFSET
PUSH_RAX ; Put envp on the stack
;; Stack offset
ADD_IMMEDIATE_to_rbp %8 ; Fix rbp
;; Perform the main loop
CALL_IMMEDIATE %FUNCTION_main
PUSH_RAX ; Put return value on the stack
PUSH_RAX ; So that _exit gets it
:FUNCTION_exit
:FUNCTION__exit
POP_RBX
POP_RDI
LOAD_IMMEDIATE_rax %0x3C
SYSCALL
amd64/libc-full.M1 0000664 0000000 0000000 00000003144 14032332560 0014041 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
COPY_rsp_to_rbp ; Protect rsp
;; Prepare argv
LOAD_BASE_ADDRESS_rax %8 ; ARGV_address = RBP + 8
PUSH_RAX ; Put argv on the stack
;; Prepare envp
COPY_rbp_to_rax ; Address we need to load from
LOAD_INTEGER ; Get ARGC
ADD_IMMEDIATE_to_rax %2 ; OFFSET = ARGC + 2
SAL_rax_Immediate8 !3 ; OFFSET = OFFSET * WORDSIZE
ADD_rbp_to_rax ; ENVP_address = RSP + OFFSET
PUSH_RAX ; Put envp on the stack
;; Stack offset
ADD_IMMEDIATE_to_rbp %8 ; Fix rbp
;; Setup for FILE*
CALL_IMMEDIATE %FUNCTION___init_io
;; Perform the main loop
CALL_IMMEDIATE %FUNCTION_main
PUSH_RAX ; Put return value on the stack
PUSH_RAX ; So that _exit gets it
:FUNCTION_exit
CALL_IMMEDIATE %FUNCTION___kill_io
:FUNCTION__exit
POP_RBX
POP_RDI
LOAD_IMMEDIATE_rax %0x3C
SYSCALL
armv7l/ 0000775 0000000 0000000 00000000000 14032332560 0012264 5 ustar 00root root 0000000 0000000 armv7l/ELF-armv7l-debug.hex2 0000664 0000000 0000000 00000005650 14032332560 0015762 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
28 00 # e_machine Indicating 32bit ARM
01 00 00 00 # e_version Indicating original elf
&ELF_text # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
%ELF_section_headers>ELF_base # e_shoff Address of section header table
00 02 00 05 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
28 00 # e_shentsize size of a section header table
05 00 # e_shnum number of entries in section table
02 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 01 00 # ph_alignment
:ELF_text
armv7l/ELF-armv7l.hex2 0000664 0000000 0000000 00000005650 14032332560 0014676 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
28 00 # e_machine Indicating 32bit ARM
01 00 00 00 # e_version Indicating original elf
&ELF_text # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
00 00 00 00 # e_shoff Address of section header table
00 02 00 05 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 01 00 # ph_alignment
:ELF_text
armv7l/Linux/ 0000775 0000000 0000000 00000000000 14032332560 0013363 5 ustar 00root root 0000000 0000000 armv7l/Linux/bootstrap.c 0000664 0000000 0000000 00000006412 14032332560 0015547 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"{R0} PUSH_ALWAYS"
"'0' SP R1 NO_SHIFT MOVE_ALWAYS"
"!1 R2 LOADI8_ALWAYS"
"!3 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS"
"!0 CMPI8 R0 IMM_ALWAYS"
"{R0} POP_ALWAYS"
"!0 R0 MVNI8_EQUAL");
}
void fputc(char s, FILE* f)
{
asm("!8 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!4 R1 SUB R12 ARITH_ALWAYS"
"!1 R2 LOADI8_ALWAYS"
"!4 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open(char* name, int flag, int mode)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!5 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
if('w' == mode[0])
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
f = open(filename, 577 , 384);
}
else
{ /* Everything else is a read */
f = open(filename, 0, 0);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!6 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!45 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!1 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
armv7l/Linux/fcntl.h 0000664 0000000 0000000 00000002365 14032332560 0014650 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!5 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
armv7l/Linux/unistd.h 0000664 0000000 0000000 00000010334 14032332560 0015043 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!33 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int chdir(char* path)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!12 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int fchdir(int fd)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!133 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
void _exit(int value);
int fork()
{
asm("!2 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int waitpid (int pid, int* status_ptr, int options)
{
asm("!114 R7 LOADI8_ALWAYS"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("!11 R7 LOADI8_ALWAYS"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
int read(int fd, char* buf, unsigned count)
{
asm("!3 R7 LOADI8_ALWAYS"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
int write(int fd, char* buf, unsigned count)
{
asm("!4 R7 LOADI8_ALWAYS"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
int lseek(int fd, int offset, int whence)
{
asm("!19 R7 LOADI8_ALWAYS"
"!12 R2 SUB R12 ARITH_ALWAYS"
"!0 R2 LOAD32 R2 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
int close(int fd)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!6 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int _getcwd(char* buf, int size)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!183 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
return buf;
}
char* getwd(char* buf)
{
return getcwd(buf, __PATH_MAX);
}
char* get_current_dir_name()
{
return getcwd(malloc(__PATH_MAX), __PATH_MAX);
}
int brk(void *addr)
{
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!45 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}
int chmod(char *pathname, int mode)
{
asm("!15 R7 LOADI8_ALWAYS"
"!8 R1 SUB R12 ARITH_ALWAYS"
"!0 R1 LOAD32 R1 MEMORY"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
asm("!122 R7 LOADI8_ALWAYS"
"!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"SYSCALL_ALWAYS");
}
armv7l/armv7l_defs.M1 0000664 0000000 0000000 00000004466 14032332560 0014706 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of stage0.
##
## stage0 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 3 of the License, or
## (at your option) any later version.
##
## stage0 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 stage0. If not, see .
# M2-Planet standards
DEFINE NULL 00000000
# Registers
DEFINE R0 0
DEFINE R1 1
DEFINE R2 2
DEFINE R3 3
DEFINE R4 4
DEFINE R5 5
DEFINE R6 6
DEFINE R7 7
DEFINE R8 8
DEFINE R9 9
DEFINE R10 A
DEFINE R11 B
DEFINE R12 C
DEFINE BP C
DEFINE R13 D
DEFINE SP D
DEFINE R14 E
DEFINE LR E
DEFINE R15 F
DEFINE PC F
# Register masks for push/pop16
DEFINE {R0} 0100
DEFINE {R1} 0200
DEFINE {R2} 0400
DEFINE {R3} 0800
DEFINE {R4} 1000
DEFINE {R11} 0008
DEFINE {BP} 0010
DEFINE {LR} 0040
# Bitshift constants
DEFINE NO_SHIFT 0
DEFINE LEFT 1
DEFINE RIGHT 3
DEFINE ARITH_RIGHT 5
# LOAD/STORE
DEFINE MEMORY E5
DEFINE STORE32 08
DEFINE STORE8 0C
DEFINE LOAD32 09
DEFINE LOAD8 0D
DEFINE LOADI8_ALWAYS 0A0E3
DEFINE LOADI8_G 0A0C3
DEFINE LOADI8_GE 0A0A3
DEFINE LOADI8_EQUAL 0A003
DEFINE LOADI8_NE 0A013
DEFINE LOADI8_LE 0A0D3
DEFINE LOADI8_L 0A0B3
DEFINE LOADI8_HI 0A083
DEFINE LOADI8_HS 0A023
DEFINE LOADI8_LS 0A093
DEFINE LOADI8_LO 0A033
# JUMP/BRANCH
DEFINE JUMP_ALWAYS EA
DEFINE JUMP_EQUAL 0A
DEFINE JUMP_NE 1A
DEFINE CALL_ALWAYS EB
DEFINE CALL_REG_ALWAYS FF2FE1
DEFINE RETURN FF2FE1
# Data movement
DEFINE MOVE_ALWAYS A0E1
DEFINE MVN_ALWAYS 0E0E1
DEFINE MVN_LT 0E0B1
DEFINE MVNI8_EQUAL 0E003
DEFINE PUSH_ALWAYS 2DE9
DEFINE POP_ALWAYS BDE8
# Arithmetic/logic
DEFINE AUX_ALWAYS E1
DEFINE IMM_ALWAYS E3
DEFINE ARITH_ALWAYS E2
DEFINE ARITH_GE A2
DEFINE ARITH_LT B2
DEFINE ARITH_NE 12
DEFINE ARITH2_ALWAYS E0
DEFINE ARITH2_GE A0
DEFINE ADC 0A
DEFINE ADCS 0B
DEFINE ADD 08
DEFINE ADDS 09
DEFINE AND 00
DEFINE CMP 005
DEFINE CMPI8 005
DEFINE MUL 0
DEFINE MULS 1
DEFINE OR 08
DEFINE SHIFT A0
DEFINE SUB 04
DEFINE RSUB 06
DEFINE XOR 02
# SYSCALL
DEFINE SYSCALL_ALWAYS 000000EF
armv7l/libc-core.M1 0000664 0000000 0000000 00000011675 14032332560 0014334 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
;; Prepare argv
!4 R0 ADD BP ARITH_ALWAYS ; ARGV_address = BP + 4
{R0} PUSH_ALWAYS ; Put argv on the stack
;; Prepare envp
'0' BP R0 NO_SHIFT MOVE_ALWAYS ; Address we need to load from
!0 R0 LOAD32 R0 MEMORY ; Get ARGC
!2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2
'0' R0 R0 '1' MOVE_ALWAYS ; OFFSET = OFFSET * WORDSIZE
'0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = BP + OFFSET
{R0} PUSH_ALWAYS ; Put envp on the stack
;; Stack offset
!4 BP ADD BP ARITH_ALWAYS ; Fix BP
^~FUNCTION_main CALL_ALWAYS ; Jump right into main
{R1} POP_ALWAYS ; Fix stack
{R1} POP_ALWAYS ; Fix stack
{R1} POP_ALWAYS ; Fix stack
{R0} PUSH_ALWAYS ; put return on the stack
{R0} PUSH_ALWAYS ; So that _exit will have it
{R0} PUSH_ALWAYS ; So that _exit will have it
:FUNCTION_exit
:FUNCTION__exit
!4 R0 SUB R12 ARITH_ALWAYS
!0 R0 LOAD32 R0 MEMORY
!1 R7 LOADI8_ALWAYS
SYSCALL_ALWAYS ; exit
# Unsigned Divide
:divide
{R4} PUSH_ALWAYS ; Protect R4
{R3} PUSH_ALWAYS ; Protect R3
{R2} PUSH_ALWAYS ; Protect R2
'0' R0 R3 NO_SHIFT MOVE_ALWAYS ; MOV R3,R0
'0' R1 R2 NO_SHIFT MOVE_ALWAYS ; MOV R2,R1
!0 R0 LOADI8_ALWAYS ; MOV R0,#0
!0 CMPI8 R2 IMM_ALWAYS ; CMP R2,#0
!1 R0 SUB R0 ARITH_LT ; SUBLT R0,R0,#1
!0 CMPI8 R3 IMM_ALWAYS ; CMP R3,#0
!0 R3 RSUB R3 ARITH_LT ; RSBLT R3,R3,#0
'0' R0 R0 MVN_LT ; MVNLT R0,R0
'0' R0 R4 NO_SHIFT MOVE_ALWAYS ; MOV R4,R0
!32 R0 LOADI8_ALWAYS ; MOV R0,#32.
!0 R1 LOADI8_ALWAYS ; MOV R1,#0
:divide_loop
'0' R2 R2 ADDS R2 ARITH2_ALWAYS ; ADDS R2,R2,R2
'0' R1 R1 ADCS R1 ARITH2_ALWAYS ; ADCS R1,R1,R1
'0' R3 CMP R1 AUX_ALWAYS ; CMP R1,R3
'0' R3 R1 SUB R1 ARITH2_GE ; SUBGE R1,R1,R3
!1 R2 ADD R2 ARITH_GE ; ADDGE R2,R2,#1
!1 R0 SUB R0 ARITH_ALWAYS ; SUB R0,R0,#1
!0 CMPI8 R0 IMM_ALWAYS ; CMP R0,#0
^~divide_loop JUMP_NE ; BNE loop
'0' R2 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R2
{R2} POP_ALWAYS ; Restore R2
{R3} POP_ALWAYS ; Restore R3
{R4} POP_ALWAYS ; Restore R4
'1' LR RETURN
# Signed Divide
:divides
{R4} PUSH_ALWAYS ; Protect R4
{R3} PUSH_ALWAYS ; Protect R3
{R2} PUSH_ALWAYS ; Protect R2
'0' R0 R3 NO_SHIFT MOVE_ALWAYS ; MOV R3,R0
'0' R1 R2 NO_SHIFT MOVE_ALWAYS ; MOV R2,R1
!0 R0 LOADI8_ALWAYS ; MOV R0,#0
!0 CMPI8 R2 IMM_ALWAYS ; CMP R2,#0
!0 R2 RSUB R2 ARITH_LT ; RSBLT R2,R2,#0
!1 R0 SUB R0 ARITH_LT ; SUBLT R0,R0,#1
!0 CMPI8 R3 IMM_ALWAYS ; CMP R3,#0
!0 R3 RSUB R3 ARITH_LT ; RSBLT R3,R3,#0
'0' R0 R0 MVN_LT ; MVNLT R0,R0
'0' R0 R4 NO_SHIFT MOVE_ALWAYS ; MOV R4,R0
!32 R0 LOADI8_ALWAYS ; MOV R0,#32.
!0 R1 LOADI8_ALWAYS ; MOV R1,#0
:divides_loop
'0' R2 R2 ADDS R2 ARITH2_ALWAYS ; ADDS R2,R2,R2
'0' R1 R1 ADCS R1 ARITH2_ALWAYS ; ADCS R1,R1,R1
'0' R3 CMP R1 AUX_ALWAYS ; CMP R1,R3
'0' R3 R1 SUB R1 ARITH2_GE ; SUBGE R1,R1,R3
!1 R2 ADD R2 ARITH_GE ; ADDGE R2,R2,#1
!1 R0 SUB R0 ARITH_ALWAYS ; SUB R0,R0,#1
!0 CMPI8 R0 IMM_ALWAYS ; CMP R0,#0
^~divides_loop JUMP_NE ; BNE loop
!0 CMPI8 R4 IMM_ALWAYS ; CMP R4,#0
!0 R2 RSUB R2 ARITH_NE ; RSBNE R2,R2,#0
'0' R2 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R2
{R2} POP_ALWAYS ; Restore R2
{R3} POP_ALWAYS ; Restore R3
{R4} POP_ALWAYS ; Restore R4
'1' LR RETURN
# Unsigned Modulus
:modulus
{LR} PUSH_ALWAYS ; Prepare to leverage divide
^~divide CALL_ALWAYS ; Use divide
'0' R1 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R1
{LR} POP_ALWAYS ; Prepare for return
'1' LR RETURN
# Signed Modulus
:moduluss
{LR} PUSH_ALWAYS ; Prepare to leverage divide
^~divides CALL_ALWAYS ; Use divides
'0' R1 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R1
{LR} POP_ALWAYS ; Prepare for return
'1' LR RETURN
armv7l/libc-full.M1 0000664 0000000 0000000 00000012024 14032332560 0014333 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
;; Prepare argv
!4 R0 ADD BP ARITH_ALWAYS ; ARGV_address = BP + 4
{R0} PUSH_ALWAYS ; Put argv on the stack
;; Prepare envp
'0' BP R0 NO_SHIFT MOVE_ALWAYS ; Address we need to load from
!0 R0 LOAD32 R0 MEMORY ; Get ARGC
!2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2
'0' R0 R0 '1' MOVE_ALWAYS ; OFFSET = OFFSET * WORDSIZE
'0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = BP + OFFSET
{R0} PUSH_ALWAYS ; Put envp on the stack
;; Stack offset
!4 BP ADD BP ARITH_ALWAYS ; Fix BP
^~FUNCTION___init_io CALL_ALWAYS ; Setup for FILE*
^~FUNCTION_main CALL_ALWAYS ; Jump right into main
{R1} POP_ALWAYS ; Fix stack
{R1} POP_ALWAYS ; Fix stack
{R1} POP_ALWAYS ; Fix stack
{R0} PUSH_ALWAYS ; put return on the stack
{R0} PUSH_ALWAYS ; So that _exit will have it
{R0} PUSH_ALWAYS ; So that _exit will have it
:FUNCTION_exit
^~FUNCTION___kill_io CALL_ALWAYS
:FUNCTION__exit
!4 R0 SUB R12 ARITH_ALWAYS
!0 R0 LOAD32 R0 MEMORY
!1 R7 LOADI8_ALWAYS
SYSCALL_ALWAYS ; exit
# Unsigned Divide
:divide
{R4} PUSH_ALWAYS ; Protect R4
{R3} PUSH_ALWAYS ; Protect R3
{R2} PUSH_ALWAYS ; Protect R2
'0' R0 R3 NO_SHIFT MOVE_ALWAYS ; MOV R3,R0
'0' R1 R2 NO_SHIFT MOVE_ALWAYS ; MOV R2,R1
!0 R0 LOADI8_ALWAYS ; MOV R0,#0
!0 CMPI8 R2 IMM_ALWAYS ; CMP R2,#0
!1 R0 SUB R0 ARITH_LT ; SUBLT R0,R0,#1
!0 CMPI8 R3 IMM_ALWAYS ; CMP R3,#0
!0 R3 RSUB R3 ARITH_LT ; RSBLT R3,R3,#0
'0' R0 R0 MVN_LT ; MVNLT R0,R0
'0' R0 R4 NO_SHIFT MOVE_ALWAYS ; MOV R4,R0
!32 R0 LOADI8_ALWAYS ; MOV R0,#32.
!0 R1 LOADI8_ALWAYS ; MOV R1,#0
:divide_loop
'0' R2 R2 ADDS R2 ARITH2_ALWAYS ; ADDS R2,R2,R2
'0' R1 R1 ADCS R1 ARITH2_ALWAYS ; ADCS R1,R1,R1
'0' R3 CMP R1 AUX_ALWAYS ; CMP R1,R3
'0' R3 R1 SUB R1 ARITH2_GE ; SUBGE R1,R1,R3
!1 R2 ADD R2 ARITH_GE ; ADDGE R2,R2,#1
!1 R0 SUB R0 ARITH_ALWAYS ; SUB R0,R0,#1
!0 CMPI8 R0 IMM_ALWAYS ; CMP R0,#0
^~divide_loop JUMP_NE ; BNE loop
'0' R2 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R2
{R2} POP_ALWAYS ; Restore R2
{R3} POP_ALWAYS ; Restore R3
{R4} POP_ALWAYS ; Restore R4
'1' LR RETURN
# Signed Divide
:divides
{R4} PUSH_ALWAYS ; Protect R4
{R3} PUSH_ALWAYS ; Protect R3
{R2} PUSH_ALWAYS ; Protect R2
'0' R0 R3 NO_SHIFT MOVE_ALWAYS ; MOV R3,R0
'0' R1 R2 NO_SHIFT MOVE_ALWAYS ; MOV R2,R1
!0 R0 LOADI8_ALWAYS ; MOV R0,#0
!0 CMPI8 R2 IMM_ALWAYS ; CMP R2,#0
!0 R2 RSUB R2 ARITH_LT ; RSBLT R2,R2,#0
!1 R0 SUB R0 ARITH_LT ; SUBLT R0,R0,#1
!0 CMPI8 R3 IMM_ALWAYS ; CMP R3,#0
!0 R3 RSUB R3 ARITH_LT ; RSBLT R3,R3,#0
'0' R0 R0 MVN_LT ; MVNLT R0,R0
'0' R0 R4 NO_SHIFT MOVE_ALWAYS ; MOV R4,R0
!32 R0 LOADI8_ALWAYS ; MOV R0,#32.
!0 R1 LOADI8_ALWAYS ; MOV R1,#0
:divides_loop
'0' R2 R2 ADDS R2 ARITH2_ALWAYS ; ADDS R2,R2,R2
'0' R1 R1 ADCS R1 ARITH2_ALWAYS ; ADCS R1,R1,R1
'0' R3 CMP R1 AUX_ALWAYS ; CMP R1,R3
'0' R3 R1 SUB R1 ARITH2_GE ; SUBGE R1,R1,R3
!1 R2 ADD R2 ARITH_GE ; ADDGE R2,R2,#1
!1 R0 SUB R0 ARITH_ALWAYS ; SUB R0,R0,#1
!0 CMPI8 R0 IMM_ALWAYS ; CMP R0,#0
^~divides_loop JUMP_NE ; BNE loop
!0 CMPI8 R4 IMM_ALWAYS ; CMP R4,#0
!0 R2 RSUB R2 ARITH_NE ; RSBNE R2,R2,#0
'0' R2 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R2
{R2} POP_ALWAYS ; Restore R2
{R3} POP_ALWAYS ; Restore R3
{R4} POP_ALWAYS ; Restore R4
'1' LR RETURN
# Unsigned Modulus
:modulus
{LR} PUSH_ALWAYS ; Prepare to leverage divide
^~divide CALL_ALWAYS ; Use divide
'0' R1 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R1
{LR} POP_ALWAYS ; Prepare for return
'1' LR RETURN
# Signed Modulus
:moduluss
{LR} PUSH_ALWAYS ; Prepare to leverage divide
^~divides CALL_ALWAYS ; Use divides
'0' R1 R0 NO_SHIFT MOVE_ALWAYS ; MOV R0,R1
{LR} POP_ALWAYS ; Prepare for return
'1' LR RETURN
bootstrappable.c 0000664 0000000 0000000 00000007144 14032332560 0014247 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#include
#define TRUE 1
#define FALSE 0
void require(int bool, char* error)
{
if(!bool)
{
fputs(error, stderr);
exit(EXIT_FAILURE);
}
}
int match(char* a, char* b)
{
if((NULL == a) && (NULL == b)) return TRUE;
if(NULL == a) return FALSE;
if(NULL == b) return FALSE;
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}
int in_set(int c, char* s)
{
/* NULL set is always false */
if(NULL == s) return FALSE;
while(0 != s[0])
{
if(c == s[0]) return TRUE;
s = s + 1;
}
return FALSE;
}
/* INTERNAL ONLY */
int __index_number(char* s, char c)
{
int i = 0;
while(s[i] != c)
{
i = i + 1;
if(0 == s[i]) return -1;
}
return i;
}
/* INTERNAL ONLY */
int __toupper(int c)
{
if(in_set(c, "abcdefghijklmnopqrstuvwxyz")) return (c & 0xDF);
return c;
}
/* INTERNAL ONLY */
int __set_reader(char* set, int mult, char* input)
{
int n = 0;
int i = 0;
int hold;
int negative_p = FALSE;
if(input[0] == '-')
{
negative_p = TRUE;
i = i + 1;
}
while(in_set(input[i], set))
{
n = n * mult;
hold = __index_number(set, __toupper(input[i]));
/* Input managed to change between in_set and index_number */
if(-1 == hold) return 0;
n = n + hold;
i = i + 1;
}
/* loop exited before NULL and thus invalid input */
if(0 != input[i]) return 0;
if(negative_p)
{
n = 0 - n;
}
return n;
}
int strtoint(char *a)
{
int result = 0;
/* If NULL string */
if(0 == a[0])
{
result = 0;
}
/* Deal with binary*/
else if ('0' == a[0] && 'b' == a[1])
{
result = __set_reader("01", 2, a+2);
}
/* Deal with hex */
else if ('0' == a[0] && 'x' == a[1])
{
result = __set_reader("0123456789ABCDEFabcdef", 16, a+2);
}
/* Deal with octal */
else if('0' == a[0])
{
result = __set_reader("01234567", 8, a+1);
}
/* Deal with decimal */
else
{
result = __set_reader("0123456789", 10, a);
}
/* Deal with sign extension for 64bit hosts */
if(0 != (0x80000000 & result)) result = (0xFFFFFFFF << 31) | result;
return result;
}
char* int2str(int x, int base, int signed_p)
{
require(1 < base, "int2str doesn't support a base less than 2\n");
require(37 > base, "int2str doesn't support a base more than 36\n");
/* Be overly conservative and save space for 32binary digits and padding null */
char* p = calloc(34, sizeof(char));
/* if calloc fails return null to let calling code deal with it */
if(NULL == p) return p;
p = p + 32;
unsigned i;
int sign_p = FALSE;
char* table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if(signed_p && (10 == base) && (0 != (x & 0x80000000)))
{
/* Truncate to 31bits */
i = -x & 0x7FFFFFFF;
if(0 == i) return "-2147483648";
sign_p = TRUE;
} /* Truncate to 32bits */
else i = x & (0x7FFFFFFF | (1 << 31));
do
{
p[0] = table[i % base];
p = p - 1;
i = i / base;
} while(0 < i);
if(sign_p)
{
p[0] = '-';
p = p - 1;
}
return p + 1;
}
bootstrappable.h 0000664 0000000 0000000 00000001724 14032332560 0014252 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
/* Essential common CONSTANTS*/
#define TRUE 1
#define FALSE 0
/* Universally useful functions */
void require(int bool, char* error);
int match(char* a, char* b);
int in_set(int c, char* s);
int strtoint(char *a);
char* int2str(int x, int base, int signed_p);
gcc_req.h 0000664 0000000 0000000 00000001351 14032332560 0012630 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
typedef unsigned long SCM;
knight/ 0000775 0000000 0000000 00000000000 14032332560 0012340 5 ustar 00root root 0000000 0000000 knight/ELF-knight.hex2 0000664 0000000 0000000 00000002137 14032332560 0015023 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
knight/Linux/ 0000775 0000000 0000000 00000000000 14032332560 0013437 5 ustar 00root root 0000000 0000000 knight/Linux/bootstrap.c 0000664 0000000 0000000 00000005631 14032332560 0015625 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("LOAD R0 R14 0"
"LOADI R1 -1"
"COPY R2 R15"
"PUSHR R1 R15"
"MOVE R1 R2"
"LOADI R2 1"
"SYS_READ"
"POPR R1 R15"
"JUMP.Z R0 @FUNCTION_FGETC_DONE"
"SR0I R1 24"
":FUNCTION_FGETC_DONE"
"MOVE R0 R1");
}
void fputc(char s, FILE* f)
{
asm("LOAD R0 R14 0"
"SL0I R0 24"
"COPY R1 R15"
"PUSHR R0 R15"
"LOAD R0 R14 4"
"LOADI R2 1"
"SYS_WRITE"
"POPR R1 R15");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open(char* name, int flag, int mode)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_OPEN"
"FALSE R2");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
if('w' == mode[0])
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
f = open(filename, 577 , 384);
}
else
{ /* Everything else is a read */
f = open(filename, 0, 0);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("LOAD R0 R14 0"
"SYS_CLOSE");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("LOAD R0 R14 0"
"ADDU R0 R12 R0"
"SWAP R0 R12");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("LOAD R0 R14 0"
"SYS_EXIT");
}
knight/Linux/fcntl.h 0000664 0000000 0000000 00000002122 14032332560 0014713 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_OPEN");
}
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
knight/Linux/unistd.h 0000664 0000000 0000000 00000006157 14032332560 0015127 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"SYS_ACCESS");
}
int chdir(char* path)
{
asm("LOAD R0 R14 0"
"SYS_CHDIR");
}
int fchdir(int fd)
{
asm("LOAD R0 R14 0"
"SYS_FCHDIR");
}
void _exit(int value);
int fork()
{
asm("SYS_FORK");
}
int waitpid (int pid, int* status_ptr, int options)
{
/* Uses wait4 with struct rusage *ru set to NULL */
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"FALSE R3"
"SYS_WAIT4");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_EXECVE");
}
int read(int fd, char* buf, unsigned count)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_READ");
}
int write(int fd, char* buf, unsigned count)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_WRITE");
}
int lseek(int fd, int offset, int whence)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"SYS_LSEEK");
}
int close(int fd)
{
asm("LOAD R0 R14 0"
"SYS_CLOSE");
}
int _getcwd(char* buf, int size)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"SYS_GETCWD");
}
char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
return buf;
}
char* getwd(char* buf)
{
return getcwd(buf, __PATH_MAX);
}
char* get_current_dir_name()
{
return getcwd(malloc(__PATH_MAX), __PATH_MAX);
}
/********************************************************************************
* All memory past the text segment and stack are always allocated to heap *
* purposes and thus no syscalls are needed for brk *
********************************************************************************/
int brk(void *addr)
{
asm("LOAD R0 R14 0"
"ADDU R0 R12 R0"
"SWAP R0 R12");
}
int chmod(char *pathname, int mode)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"SYS_CHMOD");
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
asm("LOAD R0 R14 0"
"SYS_UNAME");
}
knight/Native/ 0000775 0000000 0000000 00000000000 14032332560 0013566 5 ustar 00root root 0000000 0000000 knight/Native/bootstrap.c 0000664 0000000 0000000 00000005322 14032332560 0015751 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0x1100
// CONSTANT stdout 0x1101
// CONSTANT stderr 0
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("LOAD R1 R14 0"
"FGETC");
}
void fputc(char s, FILE* f)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"FPUTC");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open_read(int filename)
{
asm("LOAD R0 R14 0"
"FOPEN_READ");
}
FILE* open_write(int filename)
{
asm("LOAD R0 R14 0"
"FOPEN_WRITE");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
int fd = 0;
if(match(filename, "STDIN") || match(filename, "tape_01"))
{
fd = 0x1100;
}
else if(match(filename, "STDOUT") || match(filename, "tape_02"))
{
fd = 0x1101;
}
if('w' == mode[0])
{
f = open_write(fd);
}
else
{ /* Everything else is a read */
f = open_read(fd);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("LOAD R0 R14 0"
"FCLOSE");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("LOAD R0 R14 0"
"ADDU R0 R12 R0"
"SWAP R0 R12");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("LOAD R0 R14 0"
"HALT");
}
knight/Native/fcntl.h 0000664 0000000 0000000 00000002266 14032332560 0015053 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
if((0 != flag) && (0 != mode))
{
asm("LOAD R0 R14 0"
"FOPEN_WRITE");
return 0x1101;
}
else
{
asm("LOAD R0 R14 0"
"FOPEN_READ");
return 0x1100;
}
}
#define STDIN_FILENO 0x1100
#define STDOUT_FILENO 0x1101
#define STDERR_FILENO 0
knight/Native/unistd.h 0000664 0000000 0000000 00000006251 14032332560 0015251 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
#define EOF 0xFFFFFFFF
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
/* Completely meaningless in bare metal */
return 0;
}
int chdir(char* path)
{
/* Completely meaningless in bare metal */
return 0;
}
int fchdir(int fd)
{
/* Completely meaningless in bare metal */
return 0;
}
int fork()
{
/* Completely meaningless in bare metal */
return 0;
}
int waitpid (int pid, int* status_ptr, int options)
{
/* Completely meaningless in bare metal */
return 0;
}
int execve(char* file_name, char** argv, char** envp)
{
/* Completely meaningless in bare metal */
return 0;
}
int __read(int fd)
{
asm("LOAD R1 R14 0"
"FGETC");
}
int read(int fd, char* buf, unsigned count)
{
unsigned i = 0;
int c;
while(i < count)
{
c = __read(fd);
if(EOF == c) break;
buf[i] = c;
i = i + 1;
}
return i;
}
void __write(char s, int fd)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"FPUTC");
}
int write(int fd, char* buf, unsigned count)
{
unsigned i = 0;
while(i < count)
{
__write(buf[i], fd);
i = i + 1;
}
}
int lseek(int fd, int offset, int whence)
{
asm("LOAD R0 R14 0"
"LOAD R1 R14 4"
"LOAD R2 R14 8"
"FSEEK");
}
int close(int fd)
{
asm("LOAD R0 R14 0"
"FCLOSE");
}
int _getcwd(char* buf, int size)
{
/* Completely meaningless in bare metal */
return 0;
}
char* getcwd(char* buf, unsigned size)
{
/* Completely meaningless in bare metal */
return 0;
}
char* getwd(char* buf)
{
/* Completely meaningless in bare metal */
return 0;
}
char* get_current_dir_name()
{
/* Completely meaningless in bare metal */
return 0;
}
/********************************************************************************
* We are running on bare metal. Just don't go past the end of install RAM *
********************************************************************************/
int brk(void *addr)
{
asm("LOAD R0 R14 0"
"ADDU R0 R12 R0"
"SWAP R0 R12");
}
int chmod(char *pathname, int mode)
{
/* Completely meaningless in bare metal */
return 0;
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
/* Completely meaningless in bare metal */
return 0;
}
knight/knight-native_defs.M1 0000664 0000000 0000000 00000012514 14032332560 0016313 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of stage0.
##
## stage0 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 3 of the License, or
## (at your option) any later version.
##
## stage0 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 stage0. If not, see .
#Registers
DEFINE R0 0
DEFINE R1 1
DEFINE R2 2
DEFINE R3 3
DEFINE R4 4
DEFINE R5 5
DEFINE R6 6
DEFINE R7 7
DEFINE R8 8
DEFINE R9 9
DEFINE R10 A
DEFINE R11 B
DEFINE R12 C
DEFINE R13 D
DEFINE R14 E
DEFINE R15 F
# 4OP Integer Group
DEFINE ADD.CI 0100
DEFINE ADD.CO 0101
DEFINE ADD.CIO 0102
DEFINE ADDU.CI 0103
DEFINE ADDU.CO 0104
DEFINE ADDU.CIO 0105
DEFINE SUB.BI 0106
DEFINE SUB.BO 0107
DEFINE SUB.BIO 0108
DEFINE SUBU.BI 0109
DEFINE SUBU.BO 010A
DEFINE SUBU.BIO 010B
DEFINE MULTIPLY 010C
DEFINE MULTIPLYU 010D
DEFINE DIVIDE 010E
DEFINE DIVIDEU 010F
DEFINE MUX 0110
DEFINE NMUX 0111
DEFINE SORT 0112
DEFINE SORTU 0113
# 3OP Integer Group
DEFINE ADD 05000
DEFINE ADDU 05001
DEFINE SUB 05002
DEFINE SUBU 05003
DEFINE CMP 05004
DEFINE CMPU 05005
DEFINE MUL 05006
DEFINE MULH 05007
DEFINE MULU 05008
DEFINE MULUH 05009
DEFINE DIV 0500A
DEFINE MOD 0500B
DEFINE DIVU 0500C
DEFINE MODU 0500D
DEFINE MAX 05010
DEFINE MAXU 05011
DEFINE MIN 05012
DEFINE MINU 05013
DEFINE AND 05020
DEFINE OR 05021
DEFINE XOR 05022
DEFINE NAND 05023
DEFINE NOR 05024
DEFINE XNOR 05025
DEFINE MPQ 05026
DEFINE LPQ 05027
DEFINE CPQ 05028
DEFINE BPQ 05029
DEFINE SAL 05030
DEFINE SAR 05031
DEFINE SL0 05032
DEFINE SR0 05033
DEFINE SL1 05034
DEFINE SR1 05035
DEFINE ROL 05036
DEFINE ROR 05037
DEFINE LOADX 05038
DEFINE LOADX8 05039
DEFINE LOADXU8 0503A
DEFINE LOADX16 0503B
DEFINE LOADXU16 0503C
DEFINE LOADX32 0503D
DEFINE LOADXU32 0503E
DEFINE STOREX 05048
DEFINE STOREX8 05049
DEFINE STOREX16 0504A
DEFINE STOREX32 0504B
DEFINE CMPJUMP.G 05050
DEFINE CMPJUMP.GE 05051
DEFINE CMPJUMP.E 05052
DEFINE CMPJUMP.NE 05053
DEFINE CMPJUMP.LE 05054
DEFINE CMPJUMP.L 05055
DEFINE CMPJUMPU.G 05060
DEFINE CMPJUMPU.GE 05061
DEFINE CMPJUMPU.LE 05064
DEFINE CMPJUMPU.L 05065
# 2OP Integer Group
DEFINE NEG 090000
DEFINE ABS 090001
DEFINE NABS 090002
DEFINE SWAP 090003
DEFINE COPY 090004
DEFINE MOVE 090005
DEFINE NOT 090006
DEFINE BRANCH 090100
DEFINE CALL 090101
DEFINE PUSHR 090200
DEFINE PUSH8 090201
DEFINE PUSH16 090202
DEFINE PUSH32 090203
DEFINE POPR 090280
DEFINE POP8 090281
DEFINE POPU8 090282
DEFINE POP16 090283
DEFINE POPU16 090284
DEFINE POP32 090285
DEFINE POPU32 090286
DEFINE CMPSKIP.G 090300
DEFINE CMPSKIP.GE 090301
DEFINE CMPSKIP.E 090302
DEFINE CMPSKIP.NE 090303
DEFINE CMPSKIP.LE 090304
DEFINE CMPSKIP.L 090305
DEFINE CMPSKIPU.G 090380
DEFINE CMPSKIPU.GE 090381
DEFINE CMPSKIPU.LE 090384
DEFINE CMPSKIPU.L 090385
# 1OP Group
DEFINE READPC 0D00000
DEFINE READSCID 0D00001
DEFINE FALSE 0D00002
DEFINE TRUE 0D00003
DEFINE JSR_COROUTINE 0D01000
DEFINE RET 0D01001
DEFINE PUSHPC 0D02000
DEFINE POPPC 0D02001
# 2OPI Group
DEFINE SET.G E10000
DEFINE SET.GE E10001
DEFINE SET.E E10002
DEFINE SET.NE E10003
DEFINE SET.LE E10004
DEFINE SET.L E10005
DEFINE ADDI E1000E
DEFINE ADDUI E1000F
DEFINE SUBI E10010
DEFINE SUBUI E10011
DEFINE CMPI E10012
DEFINE LOAD E10013
DEFINE LOAD8 E10014
DEFINE LOADU8 E10015
DEFINE LOAD16 E10016
DEFINE LOADU16 E10017
DEFINE LOAD32 E10018
DEFINE LOADU32 E10019
DEFINE CMPUI E1001F
DEFINE STORE E10020
DEFINE STORE8 E10021
DEFINE STORE16 E10022
DEFINE STORE32 E10023
DEFINE ANDI E100B0
DEFINE ORI E100B1
DEFINE XORI E100B2
DEFINE NANDI E100B3
DEFINE NORI E100B4
DEFINE XNORI E100B5
DEFINE CMPJUMPI.G E100C0
DEFINE CMPJUMPI.GE E100C1
DEFINE CMPJUMPI.E E100C2
DEFINE CMPJUMPI.NE E100C3
DEFINE CMPJUMPI.LE E100C4
DEFINE CMPJUMPI.L E100C5
DEFINE CMPJUMPUI.G E100D0
DEFINE CMPJUMPUI.GE E100D1
DEFINE CMPJUMPUI.LE E100D4
DEFINE CMPJUMPUI.L E100D5
# 1OPI Group
DEFINE JUMP.C E0002C0
DEFINE JUMP.B E0002C1
DEFINE JUMP.O E0002C2
DEFINE JUMP.G E0002C3
DEFINE JUMP.GE E0002C4
DEFINE JUMP.E E0002C5
DEFINE JUMP.NE E0002C6
DEFINE JUMP.LE E0002C7
DEFINE JUMP.L E0002C8
DEFINE JUMP.Z E0002C9
DEFINE JUMP.NZ E0002CA
DEFINE JUMP.P E0002CB
DEFINE JUMP.NP E0002CC
DEFINE CALLI E0002D0
DEFINE LOADI E0002D1
DEFINE LOADUI E0002D2
DEFINE SALI E0002D3
DEFINE SARI E0002D4
DEFINE SL0I E0002D5
DEFINE SR0I E0002D6
DEFINE SL1I E0002D7
DEFINE SR1I E0002D8
DEFINE LOADR E0002E0
DEFINE LOADR8 E0002E1
DEFINE LOADRU8 E0002E2
DEFINE LOADR16 E0002E3
DEFINE LOADRU16 E0002E4
DEFINE LOADR32 E0002E5
DEFINE LOADRU32 E0002E6
DEFINE STORER E0002F0
DEFINE STORER8 E0002F1
DEFINE STORER16 E0002F2
DEFINE STORER32 E0002F3
DEFINE CMPSKIPI.G E000A00
DEFINE CMPSKIPI.GE E000A01
DEFINE CMPSKIPI.E E000A02
DEFINE CMPSKIPI.NE E000A03
DEFINE CMPSKIPI.LE E000A04
DEFINE CMPSKIPI.L E000A05
DEFINE CMPSKIPUI.G E000A10
DEFINE CMPSKIPUI.GE E000A11
DEFINE CMPSKIPUI.LE E000A14
DEFINE CMPSKIPUI.L E000A15
# 0OPI Group
DEFINE JUMP 3C00
# HALCODE Group
DEFINE FOPEN_READ 42100000
DEFINE FOPEN_WRITE 42100001
DEFINE FCLOSE 42100002
DEFINE REWIND 42100003
DEFINE FSEEK 42100004
DEFINE FGETC 42100100
DEFINE FPUTC 42100200
DEFINE HAL_MEM 42110000
# 0OP Group
DEFINE NULL 00000000
DEFINE HALT FFFFFFFF
knight/knight_defs.M1 0000664 0000000 0000000 00000013075 14032332560 0015032 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of stage0.
##
## stage0 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 3 of the License, or
## (at your option) any later version.
##
## stage0 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 stage0. If not, see .
#Registers
DEFINE R0 0
DEFINE R1 1
DEFINE R2 2
DEFINE R3 3
DEFINE R4 4
DEFINE R5 5
DEFINE R6 6
DEFINE R7 7
DEFINE R8 8
DEFINE R9 9
DEFINE R10 A
DEFINE R11 B
DEFINE R12 C
DEFINE R13 D
DEFINE R14 E
DEFINE R15 F
# 4OP Integer Group
DEFINE ADD.CI 0100
DEFINE ADD.CO 0101
DEFINE ADD.CIO 0102
DEFINE ADDU.CI 0103
DEFINE ADDU.CO 0104
DEFINE ADDU.CIO 0105
DEFINE SUB.BI 0106
DEFINE SUB.BO 0107
DEFINE SUB.BIO 0108
DEFINE SUBU.BI 0109
DEFINE SUBU.BO 010A
DEFINE SUBU.BIO 010B
DEFINE MULTIPLY 010C
DEFINE MULTIPLYU 010D
DEFINE DIVIDE 010E
DEFINE DIVIDEU 010F
DEFINE MUX 0110
DEFINE NMUX 0111
DEFINE SORT 0112
DEFINE SORTU 0113
# 3OP Integer Group
DEFINE ADD 05000
DEFINE ADDU 05001
DEFINE SUB 05002
DEFINE SUBU 05003
DEFINE CMP 05004
DEFINE CMPU 05005
DEFINE MUL 05006
DEFINE MULH 05007
DEFINE MULU 05008
DEFINE MULUH 05009
DEFINE DIV 0500A
DEFINE MOD 0500B
DEFINE DIVU 0500C
DEFINE MODU 0500D
DEFINE MAX 05010
DEFINE MAXU 05011
DEFINE MIN 05012
DEFINE MINU 05013
DEFINE AND 05020
DEFINE OR 05021
DEFINE XOR 05022
DEFINE NAND 05023
DEFINE NOR 05024
DEFINE XNOR 05025
DEFINE MPQ 05026
DEFINE LPQ 05027
DEFINE CPQ 05028
DEFINE BPQ 05029
DEFINE SAL 05030
DEFINE SAR 05031
DEFINE SL0 05032
DEFINE SR0 05033
DEFINE SL1 05034
DEFINE SR1 05035
DEFINE ROL 05036
DEFINE ROR 05037
DEFINE LOADX 05038
DEFINE LOADX8 05039
DEFINE LOADXU8 0503A
DEFINE LOADX16 0503B
DEFINE LOADXU16 0503C
DEFINE LOADX32 0503D
DEFINE LOADXU32 0503E
DEFINE STOREX 05048
DEFINE STOREX8 05049
DEFINE STOREX16 0504A
DEFINE STOREX32 0504B
DEFINE CMPJUMP.G 05050
DEFINE CMPJUMP.GE 05051
DEFINE CMPJUMP.E 05052
DEFINE CMPJUMP.NE 05053
DEFINE CMPJUMP.LE 05054
DEFINE CMPJUMP.L 05055
DEFINE CMPJUMPU.G 05060
DEFINE CMPJUMPU.GE 05061
DEFINE CMPJUMPU.LE 05064
DEFINE CMPJUMPU.L 05065
# 2OP Integer Group
DEFINE NEG 090000
DEFINE ABS 090001
DEFINE NABS 090002
DEFINE SWAP 090003
DEFINE COPY 090004
DEFINE MOVE 090005
DEFINE NOT 090006
DEFINE BRANCH 090100
DEFINE CALL 090101
DEFINE PUSHR 090200
DEFINE PUSH8 090201
DEFINE PUSH16 090202
DEFINE PUSH32 090203
DEFINE POPR 090280
DEFINE POP8 090281
DEFINE POPU8 090282
DEFINE POP16 090283
DEFINE POPU16 090284
DEFINE POP32 090285
DEFINE POPU32 090286
DEFINE CMPSKIP.G 090300
DEFINE CMPSKIP.GE 090301
DEFINE CMPSKIP.E 090302
DEFINE CMPSKIP.NE 090303
DEFINE CMPSKIP.LE 090304
DEFINE CMPSKIP.L 090305
DEFINE CMPSKIPU.G 090380
DEFINE CMPSKIPU.GE 090381
DEFINE CMPSKIPU.LE 090384
DEFINE CMPSKIPU.L 090385
# 1OP Group
DEFINE READPC 0D00000
DEFINE READSCID 0D00001
DEFINE FALSE 0D00002
DEFINE TRUE 0D00003
DEFINE JSR_COROUTINE 0D01000
DEFINE RET 0D01001
DEFINE PUSHPC 0D02000
DEFINE POPPC 0D02001
# 2OPI Group
DEFINE SET.G E10000
DEFINE SET.GE E10001
DEFINE SET.E E10002
DEFINE SET.NE E10003
DEFINE SET.LE E10004
DEFINE SET.L E10005
DEFINE ADDI E1000E
DEFINE ADDUI E1000F
DEFINE SUBI E10010
DEFINE SUBUI E10011
DEFINE CMPI E10012
DEFINE LOAD E10013
DEFINE LOAD8 E10014
DEFINE LOADU8 E10015
DEFINE LOAD16 E10016
DEFINE LOADU16 E10017
DEFINE LOAD32 E10018
DEFINE LOADU32 E10019
DEFINE CMPUI E1001F
DEFINE STORE E10020
DEFINE STORE8 E10021
DEFINE STORE16 E10022
DEFINE STORE32 E10023
DEFINE ANDI E100B0
DEFINE ORI E100B1
DEFINE XORI E100B2
DEFINE NANDI E100B3
DEFINE NORI E100B4
DEFINE XNORI E100B5
DEFINE CMPJUMPI.G E100C0
DEFINE CMPJUMPI.GE E100C1
DEFINE CMPJUMPI.E E100C2
DEFINE CMPJUMPI.NE E100C3
DEFINE CMPJUMPI.LE E100C4
DEFINE CMPJUMPI.L E100C5
DEFINE CMPJUMPUI.G E100D0
DEFINE CMPJUMPUI.GE E100D1
DEFINE CMPJUMPUI.LE E100D4
DEFINE CMPJUMPUI.L E100D5
# 1OPI Group
DEFINE JUMP.C E0002C0
DEFINE JUMP.B E0002C1
DEFINE JUMP.O E0002C2
DEFINE JUMP.G E0002C3
DEFINE JUMP.GE E0002C4
DEFINE JUMP.E E0002C5
DEFINE JUMP.NE E0002C6
DEFINE JUMP.LE E0002C7
DEFINE JUMP.L E0002C8
DEFINE JUMP.Z E0002C9
DEFINE JUMP.NZ E0002CA
DEFINE JUMP.P E0002CB
DEFINE JUMP.NP E0002CC
DEFINE CALLI E0002D0
DEFINE LOADI E0002D1
DEFINE LOADUI E0002D2
DEFINE SALI E0002D3
DEFINE SARI E0002D4
DEFINE SL0I E0002D5
DEFINE SR0I E0002D6
DEFINE SL1I E0002D7
DEFINE SR1I E0002D8
DEFINE LOADR E0002E0
DEFINE LOADR8 E0002E1
DEFINE LOADRU8 E0002E2
DEFINE LOADR16 E0002E3
DEFINE LOADRU16 E0002E4
DEFINE LOADR32 E0002E5
DEFINE LOADRU32 E0002E6
DEFINE STORER E0002F0
DEFINE STORER8 E0002F1
DEFINE STORER16 E0002F2
DEFINE STORER32 E0002F3
DEFINE CMPSKIPI.G E000A00
DEFINE CMPSKIPI.GE E000A01
DEFINE CMPSKIPI.E E000A02
DEFINE CMPSKIPI.NE E000A03
DEFINE CMPSKIPI.LE E000A04
DEFINE CMPSKIPI.L E000A05
DEFINE CMPSKIPUI.G E000A10
DEFINE CMPSKIPUI.GE E000A11
DEFINE CMPSKIPUI.LE E000A14
DEFINE CMPSKIPUI.L E000A15
# 0OPI Group
DEFINE JUMP 3C00
# HALCODE Group
DEFINE SYS_READ 42000000
DEFINE SYS_WRITE 42000001
DEFINE SYS_OPEN 42000002
DEFINE SYS_CLOSE 42000003
DEFINE SYS_LSEEK 42000008
DEFINE SYS_ACCESS 42000015
DEFINE SYS_FORK 42000039
DEFINE SYS_EXECVE 4200003B
DEFINE SYS_EXIT 4200003C
DEFINE SYS_WAIT4 4200003D
DEFINE SYS_UNAME 4200003F
DEFINE SYS_GETCWD 4200004F
DEFINE SYS_CHDIR 42000050
DEFINE SYS_FCHDIR 42000051
DEFINE SYS_CHMOD 4200005A
# 0OP Group
DEFINE NOP 00000000
DEFINE HALT FFFFFFFF
# M2-Planet Standard
DEFINE NULL 00000000
knight/libc-core.M1 0000664 0000000 0000000 00000002256 14032332560 0014403 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
;; Kernel Setup R12 as HEAP pointer after end of the stack
;; Kernel Setup R15 as Stack pointer after the initial stack frame
;; Default stack frame is:
;; ARGC, ARGV, ENVP, NULL
SUBI R14 R15 16 ; Set our base pointer
;; Perform the main loop
LOADR R0 4
JUMP 4
&FUNCTION_main
CALL R0 R15
COPY R14 R15 ; Setup base pointer
PUSHR R0 R15 ; Put return on the stack
:FUNCTION_exit
:FUNCTION__exit
LOAD R0 R14 0
SYS_EXIT
knight/libc-full.M1 0000664 0000000 0000000 00000002460 14032332560 0014412 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
;; Kernel Setup R12 as HEAP pointer after end of the stack
;; Kernel Setup R15 as Stack pointer after the initial stack frame
;; Default stack frame is:
;; ARGC, ARGV, ENVP, NULL
SUBI R14 R15 16 ; Set our base pointer
;; Setup for FILE*
LOADR R0 4
JUMP 4
&FUNCTION___init_io
CALL R0 R15
;; Perform the main loop
LOADR R0 4
JUMP 4
&FUNCTION_main
CALL R0 R15
COPY R14 R15 ; Setup base pointer
PUSHR R0 R15 ; Put return on the stack
:FUNCTION_exit
LOADR R0 4
JUMP 4
&FUNCTION___kill_io
CALL R0 R15
:FUNCTION__exit
LOAD R0 R14 0
SYS_EXIT
knight/libc-native-file.M1 0000664 0000000 0000000 00000002552 14032332560 0015655 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
;; Prep TAPE_02
LOADUI R0 0x1101
FOPEN_WRITE
;; Prep TAPE_01
LOADUI R0 0x1100
FOPEN_READ
LOADR R15 4
JUMP 4
&STACK ; Setup initial stack pointer
COPY R14 R15 ; Setup initial base pointer
LOADR32 R12 @HEAP ; Setup HEAP pointer
ADD R12 R12 R15 ; After Stack ends
;; Setup for FILE*
LOADR R0 4
JUMP 4
&FUNCTION___init_io
CALL R0 R15
LOADR R0 4
JUMP 4
&FUNCTION_main
CALL R0 R15
:FUNCTION_exit
LOADR R0 4
JUMP 4
&FUNCTION___kill_io
CALL R0 R15
:FUNCTION__exit
HALT ; Stop the machine
;; Our default heap offset (how big our stack ia)
:HEAP
'00100000'
knight/libc-native.M1 0000664 0000000 0000000 00000002201 14032332560 0014727 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
; Setup initial stack pointer
LOADR R15 4
JUMP 4
&STACK
LOADR32 R12 @HEAP ; Setup HEAP pointer
ADD R12 R12 R15 ; After Stack
; Setup initial base pointer
COPY R14 R15
; Perform the main loop
LOADR R0 4
JUMP 4
&FUNCTION_main
CALL R0 R15
:FUNCTION_exit
:FUNCTION__exit
HALT ; Stop the machine
;; Our default heap pointer (offset from start of stack)
:HEAP
'00100000'
stddef.h 0000664 0000000 0000000 00000001443 14032332560 0012500 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#define NULL 0
typedef long ptrdiff_t;
typedef ulong size_t;
stdio.c 0000664 0000000 0000000 00000015132 14032332560 0012344 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#include
#include
#include
#include
/* Required constants */
/* For file I/O*/
#define EOF 0xFFFFFFFF
#define BUFSIZ 0x1000
/* For lseek */
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
/* Actual format of FILE */
struct __IO_FILE
{
int fd;
int bufmode; /* O_RDONLY = 0, O_WRONLY = 1 */
int bufpos;
int file_pos;
int buflen;
char* buffer;
struct __IO_FILE* next;
struct __IO_FILE* prev;
};
/* Now give us the FILE we all love */
typedef struct __IO_FILE FILE;
/* Required variables */
FILE* stdin;
FILE* stdout;
FILE* stderr;
FILE* __list;
void __init_io()
{
__list = NULL;
stdin = calloc(1, sizeof(FILE));
stdin->fd = STDIN_FILENO;
stdin->bufmode = O_RDONLY;
stdin->buflen = 1;
stdin->buffer = calloc(2, sizeof(char));
stdout = calloc(1, sizeof(FILE));
stdout->fd = STDOUT_FILENO;
stdout->bufmode = O_WRONLY;
stdout->buflen = 512;
stdout->buffer = calloc(514, sizeof(char));
stderr = calloc(1, sizeof(FILE));
stderr->fd = STDERR_FILENO;
stderr->bufmode = O_WRONLY;
stderr->buflen = 512;
stderr->buffer = calloc(514, sizeof(char));
}
/* Flush all IO on exit */
int fflush(FILE* stream);
void __kill_io()
{
fflush(stdout);
fflush(stderr);
while(NULL != __list)
{
fflush(__list);
__list = __list->next;
}
}
/* Standard C functions */
/* Getting */
int fgetc(FILE* f)
{
/* Only read on read buffers */
if(O_WRONLY == f->bufmode) return EOF;
/* Deal with stdin */
if(STDIN_FILENO == f->fd)
{
f->bufpos = 0;
int r = read(f->fd, f->buffer, 1);
/* Catch special case of STDIN gets nothing (AN EOF) */
if(0 == r) return EOF;
}
/* Catch EOF */
if(f->buflen <= f->bufpos) return EOF;
/* Deal with standard case */
int ret = f->buffer[f->bufpos];
f->bufpos = f->bufpos + 1;
/* Ensure 0xFF doesn't return EOF */
return (ret & 0xFF);
}
int getchar()
{
return fgetc(stdin);
}
char* fgets(char* str, int count, FILE* stream)
{
int i = 0;
int ch;
while(i < count)
{
ch = fgetc(stream);
if(EOF == ch) break;
str[i] = ch;
i = i + 1;
if('\n' == ch) break;
}
return str;
}
/* Putting */
void fputc(char s, FILE* f)
{
/* Only write on write buffers */
if(O_RDONLY == f->bufmode) return;
/* Add to buffer */
f->buffer[f->bufpos] = s;
f->bufpos = f->bufpos + 1;
/* Flush if full or '\n' */
if(f->bufpos == f->buflen) fflush(f);
else if(('\n' == s) && (2 >= f->fd)) fflush(f);
}
void putchar(char s)
{
fputc(s, stdout);
}
int fputs(char const* str, FILE* stream)
{
while(0 != str[0])
{
fputc(str[0], stream);
str = str + 1;
}
return 0;
}
int puts(char const* str)
{
fputs(str, stdout);
fputc('\n', stdout);
return 0;
}
/* File management */
FILE* fopen(char const* filename, char const* mode)
{
int f;
FILE* fi = calloc(1, sizeof(FILE));
fi->next = __list;
if(NULL != __list) __list->prev = fi;
__list = fi;
int size;
if('w' == mode[0]) f = open(filename, O_WRONLY|O_CREAT|O_TRUNC , 00600);
else f = open(filename, 0, 0); /* Everything else is a read */
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
if('w' == mode[0])
{
/* Buffer as much as possible */
fi->buffer = malloc(BUFSIZ * sizeof(char));
fi->buflen = BUFSIZ;
fi->bufmode = O_WRONLY;
}
else
{
/* Get enough buffer to read it all */
size = lseek(f, 0, SEEK_END);
fi->buffer = malloc((size + 1) * sizeof(char));
fi->buflen = size;
fi->bufmode = O_RDONLY;
/* Now read it all */
lseek(f, 0, SEEK_SET);
read(f, fi->buffer, size);
}
fi->fd = f;
return fi;
}
int fflush(FILE* stream)
{
/* We only need to flush on writes */
if(O_RDONLY == stream->bufmode) return 0;
/* If nothing to flush */
if(0 ==stream->bufpos) return 0;
/* The actual flushing */
int error = write(stream->fd, stream->buffer, stream->bufpos);
/* Keep track of position */
stream->file_pos = stream->file_pos + stream->bufpos;
stream->bufpos = 0;
return error;
}
int fclose(FILE* stream)
{
/* Deal with STDIN, STDOUT and STDERR */
/* No close for you */
if(2 >= stream->fd) return 0;
/* We only need to flush on writes */
if(O_WRONLY == stream->bufmode)
{
fflush(stream);
}
/* Need to keep the File Descriptor for a moment */
int fd = stream->fd;
/* Remove from __list */
if(NULL != stream->prev) stream->prev->next = stream->next;
if(NULL != stream->next) stream->next->prev = stream->prev;
/* Deal with special case of first node in __list */
if (__list == stream) __list = __list->next;
/* Free up the buffer and struct used for FILE */
free(stream->buffer);
free(stream);
/* Do the actual closing */
return close(fd);
}
/* File Positioning */
int ungetc(int ch, FILE* stream)
{
/* Deal with STDIN, STDOUT and STDERR */
/* No ungetc for you */
if(2 >= stream->fd) return EOF;
/* You can't unget on a write stream! */
if(O_WRONLY == stream->bufmode) return EOF;
/* Don't underflow */
if(0 == stream->bufpos) return EOF;
/* Don't let crap be shoved into read stream */
if(stream->buffer[stream->bufpos - 1] != ch) return EOF;
stream->bufpos = stream->bufpos - 1;
return ch;
}
long ftell(FILE* stream)
{
/* Deal with STDIN, STDOUT and STDERR */
/* No ftell for you */
if(2 >= stream->fd) return 0;
/* Deal with buffered output */
if(O_WRONLY == stream->bufmode) return stream->file_pos + stream->bufpos;
/* Deal with read */
return stream->bufpos;
}
int fseek(FILE* f, long offset, int whence)
{
/* Deal with STDIN, STDOUT and STDERR */
/* No seek and destroy missions */
if(2 >= f->fd) return 0;
/* Deal with ugly case */
if(O_WRONLY == f->bufmode)
{
fflush(f);
return lseek(f->fd, offset, whence);
}
/* Deal with read mode */
int pos;
if(SEEK_SET == whence)
{
pos = offset;
}
else if(SEEK_CUR == whence)
{
pos = f->bufpos + offset;
}
else if(SEEK_END == whence)
{
pos = f->buflen + offset;
}
else return -1;
if(pos < 0) return -1;
if(pos > f->buflen) return -1;
f->bufpos = pos;
return pos;
}
void rewind(FILE* f)
{
fseek(f, 0, SEEK_SET);
}
stdio.h 0000664 0000000 0000000 00000003610 14032332560 0012347 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#include
#include
#include
#include
/* Required constants */
/* For file I/O*/
#define EOF -1
#define BUFSIZ 4096
/* For lseek */
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
/* Actual format of FILE */
struct __IO_FILE
{
int fd;
int bufmode; /* 0 = no buffer, 1 = read, 2 = write */
int bufpos;
int buflen;
char* buffer;
};
/* Now give us the FILE we all love */
typedef struct __IO_FILE FILE;
/* Required variables */
extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
/* Standard C functions */
/* Getting */
extern int fgetc(FILE* f);
extern int getchar();
extern char* fgets(char* str, int count, FILE* stream);
/* Putting */
extern void fputc(char s, FILE* f);
extern void putchar(char s);
extern int fputs(char const* str, FILE* stream);
extern int puts(char const* str);
/* File management */
extern FILE* fopen(char const* filename, char const* mode);
extern int fclose(FILE* stream);
extern int fflush(FILE* stream);
/* File Positioning */
extern int ungetc(int ch, FILE* stream);
extern long ftell(FILE* stream);
extern int fseek(FILE* f, long offset, int whence);
extern void rewind(FILE* f);
stdlib.c 0000664 0000000 0000000 00000002711 14032332560 0012502 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
void exit(int value);
long _malloc_ptr;
long _brk_ptr;
void free(void* l)
{
return;
}
void* malloc(unsigned size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
return ptr;
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
stdlib.h 0000664 0000000 0000000 00000001775 14032332560 0012520 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
extern void exit(int value);
extern long _malloc_ptr;
extern long _brk_ptr;
extern void free(void* l);
extern void* malloc(unsigned size);
extern void* memset(void* ptr, int value, int num);
extern void* calloc(int count, int size);
string.c 0000664 0000000 0000000 00000007765 14032332560 0012545 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
char* strcpy(char* dest, char const* src)
{
int i = 0;
while (0 != src[i])
{
dest[i] = src[i];
i = i + 1;
}
dest[i] = 0;
return dest;
}
char* strncpy(char* dest, char const* src, size_t count)
{
if(0 == count) return dest;
size_t i = 0;
while(0 != src[i])
{
dest[i] = src[i];
i = i + 1;
if(count == i) return dest;
}
while(i <= count)
{
dest[i] = 0;
i = i + 1;
}
return dest;
}
char* strcat(char* dest, char const* src)
{
int i = 0;
int j = 0;
while(0 != dest[i]) i = i + 1;
while(0 != src[j])
{
dest[i] = src[j];
i = i + 1;
j = j + 1;
}
dest[i] = 0;
return dest;
}
char* strncat(char* dest, char const* src, size_t count)
{
size_t i = 0;
size_t j = 0;
while(0 != dest[i]) i = i + 1;
while(0 != src[j])
{
if(count == j)
{
dest[i] = 0;
return dest;
}
dest[i] = src[j];
i = i + 1;
j = j + 1;
}
dest[i] = 0;
return dest;
}
size_t strlen(char const* str )
{
size_t i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
size_t strnlen_s(char const* str, size_t strsz )
{
size_t i = 0;
while(0 != str[i])
{
if(strsz == i) return i;
i = i + 1;
}
return i;
}
int strcmp(char const* lhs, char const* rhs )
{
int i = 0;
while(0 != lhs[i])
{
if(lhs[i] != rhs[i]) return lhs[i] - rhs[i];
i = i + 1;
}
return lhs[i] - rhs[i];
}
int strncmp(char const* lhs, char const* rhs, size_t count)
{
size_t i = 0;
while(count > i)
{
if(0 == lhs[i]) break;
if(lhs[i] != rhs[i]) return lhs[i] - rhs[i];
i = i + 1;
}
return 0;
}
char* strchr(char const* str, int ch)
{
char* p = str;
while(ch != p[0])
{
if(0 == p[0]) return NULL;
p = p + 1;
}
if(0 == p[0]) return NULL;
return p;
}
char* strrchr(char const* str, int ch)
{
char* p = str;
int i = 0;
while(0 != p[i]) i = i + 1;
while(ch != p[i])
{
if(0 == i) return NULL;
i = i - 1;
}
return (p + i);
}
size_t strspn(char const* dest, char const* src)
{
if(0 == dest[0]) return 0;
int i = 0;
while(NULL != strchr(src, dest[i])) i = i + 1;
return i;
}
size_t strcspn(char const* dest, char const* src)
{
int i = 0;
while(NULL == strchr(src, dest[i])) i = i + 1;
return i;
}
char* strpbrk(char const* dest, char const* breakset)
{
char* p = dest;
char* s;
while(0 != p[0])
{
s = strchr(breakset, p[0]);
if(NULL != s) return strchr(p, s[0]);
p = p + 1;
}
return p;
}
void* memset(void* dest, int ch, size_t count)
{
if(NULL == dest) return dest;
size_t i = 0;
char* s = dest;
while(i < count)
{
s[i] = ch;
i = i + 1;
}
return dest;
}
void* memcpy(void* dest, void const* src, size_t count)
{
if(NULL == dest) return dest;
if(NULL == src) return NULL;
char* s1 = dest;
char const* s2 = src;
size_t i = 0;
while(i < count)
{
s1[i] = s2[i];
i = i + 1;
}
return dest;
}
void* memmove(void* dest, void const* src, size_t count)
{
if (dest < src) return memcpy (dest, src, count);
char *p = dest;
char const *q = src;
count = count - 1;
while (count >= 0)
{
p[count] = q[count];
count = count - 1;
}
return dest;
}
int memcmp(void const* lhs, void const* rhs, size_t count)
{
if(0 == count) return 0;
size_t i = 0;
char const* s1 = lhs;
char const* s2 = rhs;
while(s1[i] == s2[i])
{
i = i + 1;
if(count == i) return count;
}
return (s1[i] - s2[i]);
}
void* memchr( void const* ptr, int ch, size_t count );
string.h 0000664 0000000 0000000 00000003300 14032332560 0012527 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include
/* String manipulation */
char* strcpy(char* dest, char const* src);
char* strncpy(char* dest, char const* src, size_t count);
char* strcat(char* dest, char const* src);
char* strncat(char* dest, char const* src, size_t count);
/* String examination */
size_t strlen(char const* str );
size_t strnlen_s(char const* str, size_t strsz );
int strcmp(char const* lhs, char const* rhs );
int strncmp(char const* lhs, char const* rhs, size_t count);
char* strchr(char const* str, int ch);
char* strrchr(char const* str, int ch);
size_t strspn(char const* dest, char const* src);
size_t strcspn(char const* dest, char const* src);
char* strpbrk(char const* dest, char const* breakset);
/* Memory manipulation */
void* memset(void* dest, int ch, size_t count );
void* memcpy(void* dest, void const* src, size_t count );
void* memmove(void* dest, void const* src, size_t count );
int memcmp(void const* lhs, void const* rhs, size_t count );
void* memchr( void const* ptr, int ch, size_t count );
sys/ 0000775 0000000 0000000 00000000000 14032332560 0011672 5 ustar 00root root 0000000 0000000 sys/types.h 0000664 0000000 0000000 00000001551 14032332560 0013211 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#include "../gcc_req.h"
typedef SCM ulong;
typedef long ssize_t;
typedef int pid_t;
typedef long intptr_t;
typedef ulong uintptr_t;
typedef long clock_t;
x86/ 0000775 0000000 0000000 00000000000 14032332560 0011501 5 ustar 00root root 0000000 0000000 x86/ELF-x86-debug.hex2 0000664 0000000 0000000 00000005642 14032332560 0014415 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
03 00 # e_machine Indicating 386
01 00 00 00 # e_version Indicating original elf
&ELF_text # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
%ELF_section_headers>ELF_base # e_shoff Address of section header table
00 00 00 00 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
28 00 # e_shentsize size of a section header table
05 00 # e_shnum number of entries in section table
02 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_alignment
:ELF_text
x86/ELF-x86.hex2 0000664 0000000 0000000 00000005642 14032332560 0013331 0 ustar 00root root 0000000 0000000 ### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen
### This file is part of M2-Planet.
###
### M2-Planet 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 3 of the License, or
### (at your option) any later version.
###
### M2-Planet 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 M2-Planet. If not, see .
### stage0's hex2 format
### ! 1 byte relative
### $ 2 byte address
### @ 2 byte relative
### & 4 byte address
### % 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
03 00 # e_machine Indicating 386
01 00 00 00 # e_version Indicating original elf
&ELF_text # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_alignment
:ELF_text
x86/Linux/ 0000775 0000000 0000000 00000000000 14032332560 0012600 5 ustar 00root root 0000000 0000000 x86/Linux/bootstrap.c 0000664 0000000 0000000 00000006361 14032332560 0014767 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
// CONSTANT NULL 0
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
// CONSTANT TRUE 1
// CONSTANT FALSE 0
int fgetc(FILE* f)
{
asm("LOAD_IMMEDIATE_eax %3"
"LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"PUSH_ebx"
"COPY_esp_to_ecx"
"LOAD_IMMEDIATE_edx %1"
"INT_80"
"TEST"
"POP_eax"
"JUMP_NE8 !FUNCTION_fgetc_Done"
"LOAD_IMMEDIATE_eax %-1"
":FUNCTION_fgetc_Done");
}
void fputc(char s, FILE* f)
{
asm("LOAD_IMMEDIATE_eax %4"
"LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_IMMEDIATE_edx %1"
"INT_80");
}
void fputs(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}
FILE* open(char* name, int flag, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %5"
"INT_80");
}
FILE* fopen(char* filename, char* mode)
{
FILE* f;
if('w' == mode[0])
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
f = open(filename, 577 , 384);
}
else
{ /* Everything else is a read */
f = open(filename, 0, 0);
}
/* Negative numbers are error codes */
if(0 > f)
{
return 0;
}
return f;
}
int close(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_IMMEDIATE_eax %6"
"INT_80");
}
int fclose(FILE* stream)
{
int error = close(stream);
return error;
}
int brk(void *addr)
{
asm("LOAD_ESP_IMMEDIATE_into_eax %4"
"PUSH_eax"
"LOAD_IMMEDIATE_eax %45"
"POP_ebx"
"INT_80");
}
long _malloc_ptr;
long _brk_ptr;
void* malloc(int size)
{
if(NULL == _brk_ptr)
{
_brk_ptr = brk(0);
_malloc_ptr = _brk_ptr;
}
if(_brk_ptr < _malloc_ptr + size)
{
_brk_ptr = brk(_malloc_ptr + size);
if(-1 == _brk_ptr) return 0;
}
long old_malloc = _malloc_ptr;
_malloc_ptr = _malloc_ptr + size;
return old_malloc;
}
int strlen(char* str )
{
int i = 0;
while(0 != str[i]) i = i + 1;
return i;
}
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}
void exit(int value)
{
asm("POP_ebx"
"POP_ebx"
"LOAD_IMMEDIATE_eax %1"
"INT_80");
}
x86/Linux/fcntl.h 0000664 0000000 0000000 00000002346 14032332560 0014064 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 00100
#define S_IXUSR 00100
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_IRWXU 00700
#define O_TRUNC 001000
int open(char* name, int flag, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %5"
"INT_80");
}
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
x86/Linux/unistd.h 0000664 0000000 0000000 00000010224 14032332560 0014256 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet 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 3 of the License, or
* (at your option) any later version.
*
* M2-Planet 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 M2-Planet. If not, see .
*/
#define NULL 0
#define __PATH_MAX 4096
void* malloc(unsigned size);
int access(char* pathname, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %8"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %4"
"LOAD_INTEGER_ecx"
"LOAD_IMMEDIATE_eax %33"
"INT_80");
}
int chdir(char* path)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_IMMEDIATE_eax %12"
"INT_80");
}
int fchdir(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_IMMEDIATE_eax %133"
"INT_80");
}
/* Defined in the libc */
void _exit(int value);
int fork()
{
asm("LOAD_IMMEDIATE_eax %2"
"LOAD_IMMEDIATE_ebx %0"
"INT_80");
}
int waitpid (int pid, int* status_ptr, int options)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %7"
"INT_80");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %11"
"INT_80");
}
int read(int fd, char* buf, unsigned count) {
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %3"
"INT_80");
}
int write(int fd, char* buf, unsigned count) {
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %4"
"INT_80");
}
int lseek(int fd, int offset, int whence)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %12"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %8"
"LOAD_INTEGER_ecx"
"LOAD_EFFECTIVE_ADDRESS_edx %4"
"LOAD_INTEGER_edx"
"LOAD_IMMEDIATE_eax %19"
"INT_80");
}
int close(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_IMMEDIATE_eax %6"
"INT_80");
}
int _getcwd(char* buf, int size)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %8"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %4"
"LOAD_INTEGER_ecx"
"LOAD_IMMEDIATE_eax %183"
"INT_80");
}
char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
return buf;
}
char* getwd(char* buf)
{
return getcwd(buf, __PATH_MAX);
}
char* get_current_dir_name()
{
return getcwd(malloc(__PATH_MAX), __PATH_MAX);
}
int brk(void *addr)
{
asm("LOAD_ESP_IMMEDIATE_into_eax %4"
"PUSH_eax"
"LOAD_IMMEDIATE_eax %45"
"POP_ebx"
"INT_80");
}
int chmod(char *pathname, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %8"
"LOAD_INTEGER_ebx"
"LOAD_EFFECTIVE_ADDRESS_ecx %4"
"LOAD_INTEGER_ecx"
"LOAD_IMMEDIATE_eax %15"
"INT_80");
}
struct utsname
{
char sysname[65]; /* Operating system name (e.g., "Linux") */
char nodename[65]; /* Name within "some implementation-defined network" */
char release[65]; /* Operating system release (e.g., "2.6.28") */
char version[65]; /* Operating system version */
char machine[65]; /* Hardware identifier */
};
int uname(struct utsname* unameData)
{
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
"LOAD_INTEGER_ebx"
"LOAD_IMMEDIATE_eax %109"
"INT_80");
}
x86/libc-core.M1 0000664 0000000 0000000 00000003203 14032332560 0013535 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
COPY_esp_to_ebp ; Protect esp
;; Prepare argv
LOAD_BASE_ADDRESS_eax %4 ; ARGV_address = EBP + 4
PUSH_eax ; Put argv on the stack
;; Prepare envp
COPY_ebp_to_eax ; Address we need to load from
LOAD_INTEGER ; Get ARGC
ADD_IMMEDIATE_to_eax %2 ; OFFSET = ARGC + 2
SAL_eax_Immediate8 !2 ; OFFSET = OFFSET * WORDSIZE
ADD_ebp_to_eax ; ENVP_address = ESP + OFFSET
PUSH_eax ; Put envp on the stack
;; Stack offset
ADD_IMMEDIATE_to_ebp %4 ; Fix ebp
;; Perform the main loop
CALL_IMMEDIATE %FUNCTION_main
PUSH_eax ; Put return on stack
PUSH_eax ; so that _exit gets the value
;; Exit to kernel
:FUNCTION_exit
:FUNCTION__exit
COPY_eax_to_ebx ; Using the return code given by main
LOAD_IMMEDIATE_eax %1 ; Syscall exit
INT_80 ; Exit with that code
x86/libc-full.M1 0000664 0000000 0000000 00000003134 14032332560 0013552 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2016 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
:_start
COPY_esp_to_ebp ; Protect esp
;; Prepare argv
LOAD_BASE_ADDRESS_eax %4 ; ARGV_address = EBP + 4
PUSH_eax ; Put argv on the stack
;; Prepare envp
COPY_ebp_to_eax ; Address we need to load from
LOAD_INTEGER ; Get ARGC
ADD_IMMEDIATE_to_eax %2 ; OFFSET = ARGC + 2
SAL_eax_Immediate8 !2 ; OFFSET = OFFSET * WORDSIZE
ADD_ebp_to_eax ; ENVP_address = ESP + OFFSET
PUSH_eax ; Put envp on the stack
;; Stack offset
ADD_IMMEDIATE_to_ebp %4 ; Fix ebp
;; Setup for FILE*
CALL_IMMEDIATE %FUNCTION___init_io
;; Perform the main loop
CALL_IMMEDIATE %FUNCTION_main
PUSH_eax ; Put return on stack
PUSH_eax ; so that _exit gets the value
:FUNCTION_exit
CALL_IMMEDIATE %FUNCTION___kill_io
:FUNCTION__exit
POP_ebx
POP_ebx
LOAD_IMMEDIATE_eax %1
INT_80
x86/x86_defs.M1 0000664 0000000 0000000 00000005534 14032332560 0013335 0 ustar 00root root 0000000 0000000 ## Copyright (C) 2017 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet 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 3 of the License, or
## (at your option) any later version.
##
## M2-Planet 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 M2-Planet. If not, see .
DEFINE ADD_IMMEDIATE_to_eax 81C0
DEFINE ADD_IMMEDIATE_to_ebp 81C5
DEFINE ADD_eax_to_ebx 01C3
DEFINE ADD_ebp_to_eax 01E8
DEFINE ADD_ebx_to_eax 01D8
DEFINE AND_eax_ebx 21D8
DEFINE CALL_IMMEDIATE E8
DEFINE CALL_eax FFD0
DEFINE CMP 39C3
DEFINE COPY_eax_to_ebx 89C3
DEFINE COPY_eax_to_ecx 89C1
DEFINE COPY_ebp_to_eax 89E8
DEFINE COPY_ebx_to_eax 89D8
DEFINE COPY_ebx_to_edx 89DA
DEFINE COPY_ecx_to_ebp 89CD
DEFINE COPY_edi_to_ebp 89fd
DEFINE COPY_esp_to_ebp 89E5
DEFINE COPY_esp_to_ecx 89E1
DEFINE COPY_esp_to_edi 89E7
DEFINE CDTQ 99
DEFINE DIVIDE_eax_by_ebx_into_eax F7FB
DEFINE DIVIDES_eax_by_ebx_into_eax F7F3
DEFINE INT_80 CD80
DEFINE JUMP E9
DEFINE JUMP_EQ 0F84
DEFINE JUMP_NE 0F85
DEFINE JUMP_EQ8 74
DEFINE JUMP_NE8 75
DEFINE LOAD_BASE_ADDRESS_eax 8D85
DEFINE LOAD_BYTE 0FBE00
DEFINE LOAD_EFFECTIVE_ADDRESS 8D8424
DEFINE LOAD_EFFECTIVE_ADDRESS_ebx 8D9C24
DEFINE LOAD_EFFECTIVE_ADDRESS_ecx 8D8C24
DEFINE LOAD_EFFECTIVE_ADDRESS_edx 8D9424
DEFINE LOAD_ESP_IMMEDIATE_into_eax 8B8424
DEFINE LOAD_IMMEDIATE_eax B8
DEFINE LOAD_IMMEDIATE_ebx BB
DEFINE LOAD_IMMEDIATE_ecx B9
DEFINE LOAD_IMMEDIATE_edx BA
DEFINE LOAD_INTEGER 8B00
DEFINE LOAD_INTEGER_ebx 8B1B
DEFINE LOAD_INTEGER_ecx 8B09
DEFINE LOAD_INTEGER_edx 8B12
DEFINE MODULUS_eax_from_ebx_into_ebx F7FB
DEFINE MODULUSS_eax_from_ebx_into_ebx F7F3
DEFINE MOVEZBL 0FB6C0
DEFINE MOVE_ebx_to_eax 89D8
DEFINE MOVE_ecx_to_eax 89C8
DEFINE MOVE_edx_to_eax 89D0
DEFINE MULTIPLY_eax_by_ebx_into_eax F7EB
DEFINE MULTIPLYS_eax_by_ebx_into_eax F7E3
DEFINE NULL 00000000
DEFINE NOT_eax F7D0
DEFINE OR_eax_ebx 09D8
DEFINE POP_eax 58
DEFINE POP_ebx 5B
DEFINE POP_ebp 5D
DEFINE POP_edi 5F
DEFINE PUSH_eax 50
DEFINE PUSH_ebx 53
DEFINE PUSH_ebp 55
DEFINE PUSH_edi 57
DEFINE RETURN C3
DEFINE SAL_eax_Immediate8 C1E0
DEFINE SHL_eax_cl D3E0
DEFINE SAL_eax_cl D3F0
DEFINE SHR_eax_cl D3E8
DEFINE SAR_eax_cl D3F8
DEFINE SETA 0F97C0
DEFINE SETAE 0F93C0
DEFINE SETB 0F92C0
DEFINE SETBE 0F96C0
DEFINE SETE 0F94C0
DEFINE SETLE 0F9EC0
DEFINE SETL 0F9CC0
DEFINE SETGE 0F9DC0
DEFINE SETG 0F9FC0
DEFINE SETNE 0F95C0
DEFINE STORE_CHAR 8803
DEFINE STORE_INTEGER 8903
DEFINE SUBTRACT_eax_from_ebx_into_ebx 29C3
DEFINE TEST 85C0
DEFINE XCHG_eax_ebx 93
DEFINE XOR_ebx_eax_into_eax 31D8