first commit
This commit is contained in:
5
.gitignore
vendored
Executable file
5
.gitignore
vendored
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
out/*
|
||||||
|
build/*
|
||||||
|
*.img
|
||||||
|
*.elf
|
||||||
|
bx_enh_dbg.ini
|
||||||
674
COPYING
Executable file
674
COPYING
Executable file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
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.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
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
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
58
Makefile
Executable file
58
Makefile
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
iso := 'disk.img'
|
||||||
|
|
||||||
|
include := './include'
|
||||||
|
|
||||||
|
mbr_source_files := $(wildcard src/mbr/*.s)
|
||||||
|
vbr_source_files := $(wildcard src/vbr/*.s)
|
||||||
|
stage2_source_files := $(wildcard src/stage2/*.s)
|
||||||
|
boottest_source_files := $(wildcard src/miniboot32/*.s)
|
||||||
|
|
||||||
|
mbr_binary_files := $(patsubst src/mbr/%.s, build/%.bin, $(mbr_source_files))
|
||||||
|
vbr_binary_files := $(patsubst src/vbr/%.s, build/%.bin, $(vbr_source_files))
|
||||||
|
stage2_binary_files := $(patsubst src/stage2/%.s, build/%.bin, $(stage2_source_files))
|
||||||
|
boottest_binary_files := $(patsubst src/miniboot32/%.s, build/%.bin, $(boottest_source_files))
|
||||||
|
|
||||||
|
build_dir := 'build'
|
||||||
|
|
||||||
|
qemu_args := -L ./bin/ -bios bios.bin -cpu pentium3 -m 64 -S -s -monitor stdio -nic none
|
||||||
|
.PHONY: all mbr vbr stage2 boottest clean run run_bochs iso
|
||||||
|
|
||||||
|
all: $(iso) $(mbr_binary_files) $(vbr_binary_files) $(stage2_binary_files)
|
||||||
|
mbr: $(mbr_binary_files)
|
||||||
|
vbr: $(vbr_binary_files)
|
||||||
|
stage2: $(stage2_binary_files)
|
||||||
|
boottest: $(boottest_binary_files)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rvf $(build_dir)/*
|
||||||
|
@rm -rvf $(iso)
|
||||||
|
|
||||||
|
run: $(iso)
|
||||||
|
@sudo qemu-system-i386 $(qemu_args) -hda $(iso)
|
||||||
|
|
||||||
|
run_bochs: $(iso)
|
||||||
|
@bochs -q
|
||||||
|
|
||||||
|
iso: $(iso)
|
||||||
|
@file disk.img
|
||||||
|
|
||||||
|
build/%.bin: src/mbr/%.s
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@nasm -i$(include) -Wall -f bin $< -o $@
|
||||||
|
|
||||||
|
build/%.bin: src/vbr/%.s
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@nasm -i$(include) -Wall -f bin $< -o $@
|
||||||
|
|
||||||
|
build/%.bin: src/stage2/%.s
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@nasm -i$(include) -Wall -f bin $< -o $@
|
||||||
|
|
||||||
|
build/%.bin: src/miniboot32/%.s
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@nasm -i$(include) -Wall -f bin $< -o $@
|
||||||
|
|
||||||
|
$(iso): $(mbr_binary_files) $(vbr_binary_files) $(stage2_binary_files) $(boottest_binary_files)
|
||||||
|
@echo root access needed to create disk image...
|
||||||
|
@sudo scripts/create-disk.sh
|
||||||
|
|
||||||
0
bin/.keepdir
Executable file
0
bin/.keepdir
Executable file
BIN
bin/bios.bin
Executable file
BIN
bin/bios.bin
Executable file
Binary file not shown.
BIN
bin/vgabios.bin
Executable file
BIN
bin/vgabios.bin
Executable file
Binary file not shown.
40
bochsrc.txt
Executable file
40
bochsrc.txt
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
# configuration file generated by Bochs
|
||||||
|
plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, gameport=true, iodebug=true
|
||||||
|
config_interface: textconfig
|
||||||
|
display_library: x
|
||||||
|
memory: host=32, guest=32
|
||||||
|
boot: disk
|
||||||
|
floppy_bootsig_check: disabled=0
|
||||||
|
# no floppya
|
||||||
|
# no floppyb
|
||||||
|
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||||
|
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=0, heads=0, spt=0, sect_size=512, model="Generic 1234", biosdetect=auto, translation=auto
|
||||||
|
ata0-slave: type=none
|
||||||
|
ata1: enabled=false
|
||||||
|
ata2: enabled=false
|
||||||
|
ata3: enabled=false
|
||||||
|
pci: enabled=1, chipset=i440fx
|
||||||
|
vga: extension=vbe, update_freq=5, realtime=1
|
||||||
|
cpu: count=1:1:1, ips=1000000, quantum=16, model=p3_katmai, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||||
|
print_timestamps: enabled=0
|
||||||
|
debugger_log: -
|
||||||
|
magic_break: enabled=0
|
||||||
|
port_e9_hack: enabled=0
|
||||||
|
private_colormap: enabled=0
|
||||||
|
clock: sync=none, time0=local, rtc_sync=0
|
||||||
|
# no cmosimage
|
||||||
|
log: -
|
||||||
|
logprefix: %t%e%d
|
||||||
|
debug: action=ignore
|
||||||
|
info: action=report
|
||||||
|
error: action=report
|
||||||
|
panic: action=ask
|
||||||
|
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
|
||||||
|
mouse: type=ps2, enabled=false, toggle=ctrl+mbutton
|
||||||
|
speaker: enabled=true, mode=system
|
||||||
|
parport1: enabled=true, file=none
|
||||||
|
parport2: enabled=false
|
||||||
|
com1: enabled=true, mode=null
|
||||||
|
com2: enabled=false
|
||||||
|
com3: enabled=false
|
||||||
|
com4: enabled=false
|
||||||
10
debug/8086_gdb/.gdbinit
Executable file
10
debug/8086_gdb/.gdbinit
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
set tdesc filename target.xml
|
||||||
|
set arch i8086
|
||||||
|
set disassembly-flavor intel
|
||||||
|
target remote localhost:1234
|
||||||
|
|
||||||
|
display/i $cs*16+$pc
|
||||||
|
b *0x7c00
|
||||||
|
set $cs = 0xf000
|
||||||
|
set $pc = 0xfff0
|
||||||
|
c
|
||||||
112
debug/8086_gdb/target.xml
Executable file
112
debug/8086_gdb/target.xml
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- Copyright (C) 2010-2017 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Copying and distribution of this file, with or without modification,
|
||||||
|
are permitted in any medium without royalty provided the copyright
|
||||||
|
notice and this notice are preserved. -->
|
||||||
|
<target/>
|
||||||
|
<!DOCTYPE target SYSTEM "gdb-target.dtd">
|
||||||
|
<architecture>i8086</architecture>
|
||||||
|
<feature name="org.gnu.gdb.i386.core">
|
||||||
|
<flags id="i386_eflags" size="4">
|
||||||
|
<field name="CF" start="0" end="0"/>
|
||||||
|
<field name="" start="1" end="1"/>
|
||||||
|
<field name="PF" start="2" end="2"/>
|
||||||
|
<field name="AF" start="4" end="4"/>
|
||||||
|
<field name="ZF" start="6" end="6"/>
|
||||||
|
<field name="SF" start="7" end="7"/>
|
||||||
|
<field name="TF" start="8" end="8"/>
|
||||||
|
<field name="IF" start="9" end="9"/>
|
||||||
|
<field name="DF" start="10" end="10"/>
|
||||||
|
<field name="OF" start="11" end="11"/>
|
||||||
|
<field name="NT" start="14" end="14"/>
|
||||||
|
<field name="RF" start="16" end="16"/>
|
||||||
|
<field name="VM" start="17" end="17"/>
|
||||||
|
<field name="AC" start="18" end="18"/>
|
||||||
|
<field name="VIF" start="19" end="19"/>
|
||||||
|
<field name="VIP" start="20" end="20"/>
|
||||||
|
<field name="ID" start="21" end="21"/>
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<reg name="eax" bitsize="32" type="int32"/>
|
||||||
|
<reg name="ecx" bitsize="32" type="int32"/>
|
||||||
|
<reg name="edx" bitsize="32" type="int32"/>
|
||||||
|
<reg name="ebx" bitsize="32" type="int32"/>
|
||||||
|
<reg name="esp" bitsize="32" type="data_ptr"/>
|
||||||
|
<reg name="ebp" bitsize="32" type="data_ptr"/>
|
||||||
|
<reg name="esi" bitsize="32" type="int32"/>
|
||||||
|
<reg name="edi" bitsize="32" type="int32"/>
|
||||||
|
|
||||||
|
<reg name="eip" bitsize="32" type="code_ptr"/>
|
||||||
|
<reg name="eflags" bitsize="32" type="i386_eflags"/>
|
||||||
|
|
||||||
|
<reg name="cs" bitsize="32" type="int32"/>
|
||||||
|
<reg name="ss" bitsize="32" type="int32"/>
|
||||||
|
<reg name="ds" bitsize="32" type="int32"/>
|
||||||
|
<reg name="es" bitsize="32" type="int32"/>
|
||||||
|
<reg name="fs" bitsize="32" type="int32"/>
|
||||||
|
<reg name="gs" bitsize="32" type="int32"/>
|
||||||
|
|
||||||
|
<reg name="st0" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st1" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st2" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st3" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st4" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st5" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st6" bitsize="80" type="i387_ext"/>
|
||||||
|
<reg name="st7" bitsize="80" type="i387_ext"/>
|
||||||
|
|
||||||
|
<reg name="fctrl" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="fstat" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="ftag" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="fiseg" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="fioff" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="foseg" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="fooff" bitsize="32" type="int" group="float"/>
|
||||||
|
<reg name="fop" bitsize="32" type="int" group="float"/>
|
||||||
|
</feature>
|
||||||
|
<feature name="org.gnu.gdb.i386.32bit.sse">
|
||||||
|
<vector id="v4f" type="ieee_single" count="4"/>
|
||||||
|
<vector id="v2d" type="ieee_double" count="2"/>
|
||||||
|
<vector id="v16i8" type="int8" count="16"/>
|
||||||
|
<vector id="v8i16" type="int16" count="8"/>
|
||||||
|
<vector id="v4i32" type="int32" count="4"/>
|
||||||
|
<vector id="v2i64" type="int64" count="2"/>
|
||||||
|
<union id="vec128">
|
||||||
|
<field name="v4_float" type="v4f"/>
|
||||||
|
<field name="v2_double" type="v2d"/>
|
||||||
|
<field name="v16_int8" type="v16i8"/>
|
||||||
|
<field name="v8_int16" type="v8i16"/>
|
||||||
|
<field name="v4_int32" type="v4i32"/>
|
||||||
|
<field name="v2_int64" type="v2i64"/>
|
||||||
|
<field name="uint128" type="uint128"/>
|
||||||
|
</union>
|
||||||
|
<flags id="i386_mxcsr" size="4">
|
||||||
|
<field name="IE" start="0" end="0"/>
|
||||||
|
<field name="DE" start="1" end="1"/>
|
||||||
|
<field name="ZE" start="2" end="2"/>
|
||||||
|
<field name="OE" start="3" end="3"/>
|
||||||
|
<field name="UE" start="4" end="4"/>
|
||||||
|
<field name="PE" start="5" end="5"/>
|
||||||
|
<field name="DAZ" start="6" end="6"/>
|
||||||
|
<field name="IM" start="7" end="7"/>
|
||||||
|
<field name="DM" start="8" end="8"/>
|
||||||
|
<field name="ZM" start="9" end="9"/>
|
||||||
|
<field name="OM" start="10" end="10"/>
|
||||||
|
<field name="UM" start="11" end="11"/>
|
||||||
|
<field name="PM" start="12" end="12"/>
|
||||||
|
<field name="FZ" start="15" end="15"/>
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>
|
||||||
|
<reg name="xmm1" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm2" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm3" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm4" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm5" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm6" bitsize="128" type="vec128"/>
|
||||||
|
<reg name="xmm7" bitsize="128" type="vec128"/>
|
||||||
|
|
||||||
|
<reg name="mxcsr" bitsize="32" type="i386_mxcsr" group="vector"/>
|
||||||
|
</feature>
|
||||||
|
</target>
|
||||||
9
debug/x86_ddd/.gdbinit
Executable file
9
debug/x86_ddd/.gdbinit
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
target remote localhost:1234
|
||||||
|
set architecture i386
|
||||||
|
set disassembly-flavor intel
|
||||||
|
|
||||||
|
display/x $eip
|
||||||
|
display/x $esp
|
||||||
|
display/x $ebp
|
||||||
|
|
||||||
|
graph display `x /16xw ($ebp - (16*4))`
|
||||||
8
debug/x86_gdb/.gdbinit
Executable file
8
debug/x86_gdb/.gdbinit
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
target remote localhost:1234
|
||||||
|
set architecture i386
|
||||||
|
set disassembly-flavor intel
|
||||||
|
layout asm
|
||||||
|
|
||||||
|
display/x $eip
|
||||||
|
display/x $esp
|
||||||
|
display/x $ebp
|
||||||
35
docs/examples.txt
Executable file
35
docs/examples.txt
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
Partition 1 offset = LBA 0x800
|
||||||
|
= 0x100000
|
||||||
|
bsSectorSize = 512
|
||||||
|
|
||||||
|
first_fat_sector = bsResSector
|
||||||
|
= 32 => (32*512) = 0x4000
|
||||||
|
= 0x100000 + 0x4000
|
||||||
|
= 0x104000
|
||||||
|
|
||||||
|
total_fat_sectors = fat_sectors * number_of_FATs
|
||||||
|
= 2001 * 2
|
||||||
|
= 4002
|
||||||
|
|
||||||
|
total_fat_size = total_fat_sectors * bsSectorSize
|
||||||
|
= 0x1F4400
|
||||||
|
|
||||||
|
first_data_sector = FatStartSector + FatAreaSize
|
||||||
|
= 0x104000 + 0x1F4400
|
||||||
|
= 0x2F8400
|
||||||
|
|
||||||
|
FAT table look up
|
||||||
|
|
||||||
|
if the cluster we got from the table entry was cluster 354
|
||||||
|
fat_sector = 354 / 128
|
||||||
|
= 2
|
||||||
|
fat_entry = 354 mod 128
|
||||||
|
= 98
|
||||||
|
|
||||||
|
so we load the 3rd (indexed from 0) fat table sector and read the 98th entry
|
||||||
|
for the cluster chain.
|
||||||
|
|
||||||
|
// bad fake code below
|
||||||
|
fat_table_offset = (first_fat_sector + 2) * 512
|
||||||
|
fat_table = *(fat_table_offset)
|
||||||
|
disk_read(fat_table[98])
|
||||||
127
docs/seabios_config
Executable file
127
docs/seabios_config
Executable file
@@ -0,0 +1,127 @@
|
|||||||
|
#
|
||||||
|
# Automatically generated file; DO NOT EDIT.
|
||||||
|
# SeaBIOS Configuration
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# General Features
|
||||||
|
#
|
||||||
|
# CONFIG_COREBOOT is not set
|
||||||
|
CONFIG_QEMU=y
|
||||||
|
# CONFIG_CSM is not set
|
||||||
|
CONFIG_QEMU_HARDWARE=y
|
||||||
|
# CONFIG_XEN is not set
|
||||||
|
CONFIG_THREADS=y
|
||||||
|
CONFIG_RELOCATE_INIT=y
|
||||||
|
CONFIG_BOOTMENU=y
|
||||||
|
CONFIG_BOOTSPLASH=y
|
||||||
|
CONFIG_BOOTORDER=y
|
||||||
|
# CONFIG_ENTRY_EXTRASTACK is not set
|
||||||
|
CONFIG_MALLOC_UPPERMEMORY=y
|
||||||
|
CONFIG_ROM_SIZE=0
|
||||||
|
|
||||||
|
#
|
||||||
|
# Hardware support
|
||||||
|
#
|
||||||
|
CONFIG_ATA=y
|
||||||
|
# CONFIG_ATA_DMA is not set
|
||||||
|
# CONFIG_ATA_PIO32 is not set
|
||||||
|
CONFIG_AHCI=y
|
||||||
|
CONFIG_SDCARD=y
|
||||||
|
# CONFIG_VIRTIO_BLK is not set
|
||||||
|
# CONFIG_VIRTIO_SCSI is not set
|
||||||
|
# CONFIG_PVSCSI is not set
|
||||||
|
# CONFIG_ESP_SCSI is not set
|
||||||
|
# CONFIG_LSI_SCSI is not set
|
||||||
|
# CONFIG_MEGASAS is not set
|
||||||
|
# CONFIG_MPT_SCSI is not set
|
||||||
|
CONFIG_FLOPPY=y
|
||||||
|
CONFIG_FLASH_FLOPPY=y
|
||||||
|
# CONFIG_NVME is not set
|
||||||
|
CONFIG_PS2PORT=y
|
||||||
|
CONFIG_USB=y
|
||||||
|
CONFIG_USB_UHCI=y
|
||||||
|
CONFIG_USB_OHCI=y
|
||||||
|
CONFIG_USB_EHCI=y
|
||||||
|
CONFIG_USB_XHCI=y
|
||||||
|
CONFIG_USB_MSC=y
|
||||||
|
CONFIG_USB_UAS=y
|
||||||
|
CONFIG_USB_HUB=y
|
||||||
|
CONFIG_USB_KEYBOARD=y
|
||||||
|
CONFIG_USB_MOUSE=y
|
||||||
|
CONFIG_SERIAL=y
|
||||||
|
CONFIG_SERCON=y
|
||||||
|
CONFIG_LPT=y
|
||||||
|
CONFIG_RTC_TIMER=y
|
||||||
|
CONFIG_HARDWARE_IRQ=y
|
||||||
|
CONFIG_USE_SMM=y
|
||||||
|
CONFIG_CALL32_SMM=y
|
||||||
|
CONFIG_MTRR_INIT=y
|
||||||
|
CONFIG_PMTIMER=y
|
||||||
|
CONFIG_TSC_TIMER=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# BIOS interfaces
|
||||||
|
#
|
||||||
|
CONFIG_DRIVES=y
|
||||||
|
CONFIG_CDROM_BOOT=y
|
||||||
|
CONFIG_CDROM_EMU=y
|
||||||
|
CONFIG_PCIBIOS=y
|
||||||
|
CONFIG_APMBIOS=y
|
||||||
|
CONFIG_PNPBIOS=y
|
||||||
|
CONFIG_OPTIONROMS=y
|
||||||
|
CONFIG_PMM=y
|
||||||
|
CONFIG_BOOT=y
|
||||||
|
CONFIG_KEYBOARD=y
|
||||||
|
CONFIG_KBD_CALL_INT15_4F=y
|
||||||
|
CONFIG_MOUSE=y
|
||||||
|
CONFIG_S3_RESUME=y
|
||||||
|
CONFIG_VGAHOOKS=y
|
||||||
|
CONFIG_DISABLE_A20=y
|
||||||
|
# CONFIG_WRITABLE_UPPERMEMORY is not set
|
||||||
|
# CONFIG_TCGBIOS is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# BIOS Tables
|
||||||
|
#
|
||||||
|
CONFIG_PIRTABLE=y
|
||||||
|
CONFIG_MPTABLE=y
|
||||||
|
CONFIG_SMBIOS=y
|
||||||
|
CONFIG_ACPI=y
|
||||||
|
CONFIG_ACPI_DSDT=y
|
||||||
|
CONFIG_FW_ROMFILE_LOAD=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# VGA ROM
|
||||||
|
#
|
||||||
|
# CONFIG_NO_VGABIOS is not set
|
||||||
|
# CONFIG_VGA_STANDARD_VGA is not set
|
||||||
|
# CONFIG_VGA_CIRRUS is not set
|
||||||
|
# CONFIG_VGA_ATI is not set
|
||||||
|
CONFIG_VGA_BOCHS=y
|
||||||
|
# CONFIG_VGA_GEODEGX2 is not set
|
||||||
|
# CONFIG_VGA_GEODELX is not set
|
||||||
|
# CONFIG_DISPLAY_BOCHS is not set
|
||||||
|
# CONFIG_VGA_RAMFB is not set
|
||||||
|
CONFIG_VGA_BOCHS_STDVGA=y
|
||||||
|
# CONFIG_VGA_BOCHS_VMWARE is not set
|
||||||
|
# CONFIG_VGA_BOCHS_QXL is not set
|
||||||
|
# CONFIG_VGA_BOCHS_VIRTIO is not set
|
||||||
|
CONFIG_BUILD_VGABIOS=y
|
||||||
|
CONFIG_VGA_STDVGA_PORTS=y
|
||||||
|
CONFIG_VGA_FIXUP_ASM=y
|
||||||
|
# CONFIG_VGA_ALLOCATE_EXTRA_STACK is not set
|
||||||
|
CONFIG_VGA_EXTRA_STACK_SIZE=512
|
||||||
|
CONFIG_VGA_VBE=y
|
||||||
|
CONFIG_VGA_PCI=y
|
||||||
|
# CONFIG_OVERRIDE_PCI_ID is not set
|
||||||
|
CONFIG_VGA_VID=0x1234
|
||||||
|
CONFIG_VGA_DID=0x1111
|
||||||
|
|
||||||
|
#
|
||||||
|
# Debugging
|
||||||
|
#
|
||||||
|
CONFIG_DEBUG_LEVEL=1
|
||||||
|
# CONFIG_DEBUG_SERIAL is not set
|
||||||
|
# CONFIG_DEBUG_SERIAL_MMIO is not set
|
||||||
|
CONFIG_DEBUG_IO=y
|
||||||
20
include/config.inc
Executable file
20
include/config.inc
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
%define SECTOR_SIZE 512
|
||||||
|
%define STAGE2_SECTOR_COUNT 0x40
|
||||||
|
; 32 KiB
|
||||||
|
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
||||||
21
include/entry.inc
Executable file
21
include/entry.inc
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; 8KiB from 0x2500 -> 0x500
|
||||||
|
%define STACK_START 0x2500
|
||||||
|
%define MBR_ENTRY 0x7A00
|
||||||
|
%define VBR_ENTRY 0x7C00
|
||||||
|
%define STAGE2_ENTRY 0x7E00
|
||||||
95
include/errors.inc
Executable file
95
include/errors.inc
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; Errors
|
||||||
|
; 12 Errors, 5 in use
|
||||||
|
%define MBR_ERROR_DISK_T_ERR 'a'
|
||||||
|
%define MBR_ERROR_NO_INT32E 'b'
|
||||||
|
%define MBR_ERROR_NO_NO_BOOT_PART 'c'
|
||||||
|
%define MBR_ERROR_DISK_READ_ERR 'd'
|
||||||
|
%define MBR_ERROR_NO_VBR_SIG 'e'
|
||||||
|
%define MBR_ERROR_RESERVED_f 'f'
|
||||||
|
%define MBR_ERROR_RESERVED_g 'g'
|
||||||
|
%define MBR_ERROR_RESERVED_h 'h'
|
||||||
|
%define MBR_ERROR_RESERVED_i 'i'
|
||||||
|
%define MBR_ERROR_RESERVED_j 'j'
|
||||||
|
%define MBR_ERROR_RESERVED_k 'k'
|
||||||
|
%define MBR_ERROR_RESERVED_l 'l'
|
||||||
|
|
||||||
|
; 12 Error
|
||||||
|
%define VBR_ERROR_WRONG_FAT_SIZE 'm'
|
||||||
|
%define VBR_ERROR_NO_SIGNATURE 'n'
|
||||||
|
%define VBR_ERROR_DISK_READ_ERR 'o'
|
||||||
|
%define VBR_ERROR_RESERVED_p 'p'
|
||||||
|
%define VBR_ERROR_RESERVED_q 'q'
|
||||||
|
%define VBR_ERROR_RESERVED_r 'r'
|
||||||
|
%define VBR_ERROR_RESERVED_s 's'
|
||||||
|
%define VBR_ERROR_RESERVED_t 't'
|
||||||
|
%define VBR_ERROR_RESERVED_u 'u'
|
||||||
|
%define VBR_ERROR_RESERVED_v 'v'
|
||||||
|
%define VBR_ERROR_RESERVED_w 'w'
|
||||||
|
%define VBR_ERROR_RESERVED_x 'x'
|
||||||
|
|
||||||
|
; 26 errors, 8 in use
|
||||||
|
%define STAGE2_A20_FAILED 'A'
|
||||||
|
%define STAGE2_SIGNATURE_MISSING 'B'
|
||||||
|
%define STAGE2_MM_E820_NO_SUPPORT 'C'
|
||||||
|
%define STAGE2_MM_E820_MISC_ERR 'D'
|
||||||
|
%define STAGE2_MM_E820_NONSTANDARD 'E'
|
||||||
|
%define STAGE2_MM_E820_NO_SMAP 'F'
|
||||||
|
%define STAGE2_MBR_DISK_READ_ERROR 'G'
|
||||||
|
%define STAGE2_FAT32_INIT_ERROR 'H'
|
||||||
|
%define STAGE2_FAT32_NO_FILE 'I'
|
||||||
|
%define STAGE2_FAT32_END_OF_CHAIN 'J'
|
||||||
|
%define STAGE2_ERROR_RESERVED_K 'K'
|
||||||
|
%define STAGE2_ERROR_RESERVED_L 'L'
|
||||||
|
%define STAGE2_ERROR_RESERVED_M 'M'
|
||||||
|
%define STAGE2_ERROR_RESERVED_N 'N'
|
||||||
|
%define STAGE2_ERROR_RESERVED_O 'O'
|
||||||
|
%define STAGE2_ERROR_RESERVED_P 'P'
|
||||||
|
%define STAGE2_ERROR_RESERVED_Q 'Q'
|
||||||
|
%define STAGE2_ERROR_RESERVED_R 'R'
|
||||||
|
%define STAGE2_ERROR_RESERVED_S 'S'
|
||||||
|
%define STAGE2_ERROR_RESERVED_T 'T'
|
||||||
|
%define STAGE2_ERROR_RESERVED_U 'U'
|
||||||
|
%define STAGE2_ERROR_RESERVED_V 'V'
|
||||||
|
%define STAGE2_ERROR_RESERVED_W 'W'
|
||||||
|
%define STAGE2_ERROR_RESERVED_X 'X'
|
||||||
|
%define STAGE2_ERROR_RESERVED_Y 'Y'
|
||||||
|
%define STAGE2_ERROR_RESERVED_Z 'Z'
|
||||||
|
|
||||||
|
|
||||||
|
%macro ERROR 1
|
||||||
|
mov al, %1
|
||||||
|
jmp error
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
||||||
|
error:
|
||||||
|
; color 0x4F is white on red
|
||||||
|
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
||||||
|
mov dx, 0xB800
|
||||||
|
mov fs, dx
|
||||||
|
|
||||||
|
; the characters are two bytes in the order of 0xb8000: byte c, byte attribute
|
||||||
|
; since x86 is le, we store the attribute in the MSB of dx
|
||||||
|
mov dh, 0x4F
|
||||||
|
mov dl, al
|
||||||
|
mov word [fs:0x0000], dx
|
||||||
|
|
||||||
|
.stop:
|
||||||
|
hlt
|
||||||
|
jmp short error.stop
|
||||||
86
include/fat32/bpb.inc
Executable file
86
include/fat32/bpb.inc
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; BPB Information
|
||||||
|
; Off. Hex Off. Size Description
|
||||||
|
; 0 0x00 3 The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP. (The 3C value may be different.)
|
||||||
|
; 3 0x03 8 OEM identifier.
|
||||||
|
; 11 0x0B 2 The number of Bytes per sector (remember, all numbers are in the little-endian format).
|
||||||
|
; 13 0x0D 1 Number of sectors per cluster.
|
||||||
|
; 14 0x0E 2 Number of reserved sectors. The boot record sectors are included in this value.
|
||||||
|
; 16 0x10 1 Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2.
|
||||||
|
; 17 0x11 2 Number of directory entries (must be set so that the root directory occupies entire sectors).
|
||||||
|
; 19 0x13 2 The total sectors in the logical volume.
|
||||||
|
; If this value is 0, it means there are more than 65535 sectors in the volume,
|
||||||
|
; and the actual count is stored in the Large Sector Count entry at 0x20.
|
||||||
|
;
|
||||||
|
; 21 0x15 1 This Byte indicates the media descriptor type.
|
||||||
|
; 22 0x16 2 Number of sectors per FAT. FAT12/FAT16 only.
|
||||||
|
; 24 0x18 2 Number of sectors per track.
|
||||||
|
; 26 0x1A 2 Number of heads or sides on the storage media.
|
||||||
|
; 28 0x1C 4 Number of hidden sectors. (i.e. the LBA of the beginning of the partition.)
|
||||||
|
; 32 0x20 4 Large sector count. This field is set if there are more than 65535 sectors in the volume,
|
||||||
|
; resulting in a value which does not fit in the Number of Sectors entry at 0x13.
|
||||||
|
|
||||||
|
;-- BPB (BIOS Parameter Block)
|
||||||
|
%define bsOemName bx+0x03
|
||||||
|
%define bsBytesPerSect bx+0x0B
|
||||||
|
%define bsSecsPerClust bx+0x0D
|
||||||
|
%define bsResSectors bx+0x0E
|
||||||
|
%define bsFATs bx+0x10
|
||||||
|
%define bsRootDirEnts bx+0x11
|
||||||
|
%define bsSectors bx+0x13
|
||||||
|
%define bsMedia bx+0x15
|
||||||
|
%define bsSectPerFAT1216 bx+0x16
|
||||||
|
%define bsSectPerTrack bx+0x18
|
||||||
|
%define bsHeads bx+0x1A
|
||||||
|
%define bsHidden bx+0x1C
|
||||||
|
%define bsSectorHuge bx+0x20
|
||||||
|
;-- End BPB
|
||||||
|
|
||||||
|
; EBPB Information (FAT32)
|
||||||
|
; Off. Hex Off. Size Description
|
||||||
|
; 36 0x024 4 Sectors per FAT. The size of the FAT in sectors.
|
||||||
|
; 40 0x028 2 Flags.
|
||||||
|
; 42 0x02A 2 FAT version number. The high byte is the major version and the low byte is the minor version. FAT drivers should respect this field.
|
||||||
|
; 44 0x02C 4 The cluster number of the root directory. Often this field is set to 2.
|
||||||
|
; 48 0x030 2 The sector number of the FSInfo structure.
|
||||||
|
; 50 0x032 2 The sector number of the backup boot sector.
|
||||||
|
; 52 0x034 12 Reserved. When the volume is formated these bytes should be zero.
|
||||||
|
; 64 0x040 1 Drive number. The values here are identical to the values returned by the BIOS interrupt 0x13. 0x00 for a floppy disk and 0x80 for hard disks.
|
||||||
|
; 65 0x041 1 Flags in Windows NT. Reserved otherwise.
|
||||||
|
; 66 0x042 1 Signature (must be 0x28 or 0x29).
|
||||||
|
; 67 0x043 4 Volume ID 'Serial' number. Used for tracking volumes between computers. You can ignore this if you want.
|
||||||
|
; 71 0x047 11 Volume label string. This field is padded with spaces.
|
||||||
|
; 82 0x052 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use.
|
||||||
|
; 90 0x05A 420 Boot code.
|
||||||
|
; 510 0x1FE 2 Bootable partition signature 0xAA55.
|
||||||
|
|
||||||
|
;-- EBPB (Extended BIOS Parameter Block)
|
||||||
|
%define bsSectorsPerFAT bx+0x24
|
||||||
|
%define bsFlags bx+0x28
|
||||||
|
%define bsFATVersion bx+0x2A
|
||||||
|
%define bsRootDirCluster bx+0x2C
|
||||||
|
%define bsFSInfoCluster bx+0x30
|
||||||
|
%define bsBackupBootSector bx+0x32
|
||||||
|
%define bsReserved1 bx+0x34
|
||||||
|
%define bsDriveNumber bx+0x40
|
||||||
|
%define bsNTFlags bx+0x41
|
||||||
|
%define bsFATSignature bx+0x42
|
||||||
|
%define bsVolumeSerial bx+0x43
|
||||||
|
%define bsVolumeLabel bx+0x47
|
||||||
|
%define bsSystemIdent bx+0x52
|
||||||
|
;-- End EBPB
|
||||||
228
include/fat32/fat32_structures.inc
Executable file
228
include/fat32/fat32_structures.inc
Executable file
@@ -0,0 +1,228 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; ## FAT32 Info ##
|
||||||
|
; total_sectors = bsSectorsHuge
|
||||||
|
; fat_size = bsSectorsPerFat
|
||||||
|
;
|
||||||
|
; first_data_sector = bsResSectors + (bsFATs * bsSectPerFAT);
|
||||||
|
; total_data_sectors = bsSectorsHuge - (bsResSectors + (bsFATs * bsSectPerFAT));
|
||||||
|
; total_clusters = total_data_sectors / bsSectsPerClust
|
||||||
|
; first_fat_sector = bsResSectors
|
||||||
|
;
|
||||||
|
; ## FAT32 Table information ##
|
||||||
|
;
|
||||||
|
; fat_offset = active_cluster * 4
|
||||||
|
; fat_sector = first_fat_sector + (fat_offset / sector_size)
|
||||||
|
; entry_offset = fat_offset % sector_size
|
||||||
|
;
|
||||||
|
; table_value = fat_table[entry_offset] & 0x0FFF_FFFF
|
||||||
|
;
|
||||||
|
; ## FAT32 Directory Entries ##
|
||||||
|
; root_dir_cluster = bsRootDirCluster
|
||||||
|
; root_dir_sectors = ? (this is varible on FAT32 since the root dir is a cluster chain)
|
||||||
|
; first_sector_of_cluster = ((cluster - 2) * bsSectPerClust) + first_data_sector;
|
||||||
|
|
||||||
|
; BPB Information
|
||||||
|
; Size Description
|
||||||
|
; 8 OEM identifier.
|
||||||
|
; 2 The number of Bytes per sector (remember, all numbers are in the little-endian format).
|
||||||
|
; 1 Number of sectors per cluster.
|
||||||
|
; 2 Number of reserved sectors. The boot record sectors are included in this value.
|
||||||
|
; 1 Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2.
|
||||||
|
; 2 Number of directory entries (must be set so that the root directory occupies entire sectors).
|
||||||
|
; 2 The total sectors in the logical volume.
|
||||||
|
; If this value is 0, it means there are more than 65535 sectors in the volume,
|
||||||
|
; and the actual count is stored in the Large Sector Count entry at 0x20.
|
||||||
|
;
|
||||||
|
; 1 This Byte indicates the media descriptor type.
|
||||||
|
; 2 Number of sectors per FAT. FAT12/FAT16 only.
|
||||||
|
; 2 Number of sectors per track.
|
||||||
|
; 2 Number of heads or sides on the storage media.
|
||||||
|
; 4 Number of hidden sectors. (i.e. the LBA of the beginning of the partition.)
|
||||||
|
; 4 Large sector count. This field is set if there are more than 65535 sectors in the volume,
|
||||||
|
; resulting in a value which does not fit in the Number of Sectors entry at 0x13.
|
||||||
|
|
||||||
|
struc FAT32_bpb_t
|
||||||
|
.ident_8 resb 8
|
||||||
|
.bytes_per_sector_16 resb 2
|
||||||
|
.sectors_per_cluster_8 resb 1
|
||||||
|
.reserved_sectors_16 resb 2
|
||||||
|
.fat_count_8 resb 1
|
||||||
|
.dir_entry_count_16 resb 2
|
||||||
|
.sector_count_16 resb 2
|
||||||
|
.media_desc_8 resb 1
|
||||||
|
.sectors_per_fat_16 resb 2
|
||||||
|
.sectors_per_track_16 resb 2
|
||||||
|
.head_count_16 resb 2
|
||||||
|
.hidden_sectors_32 resb 4
|
||||||
|
.sector_count_32 resb 4
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; EBPB Information (FAT32)
|
||||||
|
; Size Description
|
||||||
|
; 4 Sectors per FAT. The size of the FAT in sectors.
|
||||||
|
; 2 Flags.
|
||||||
|
; 2 FAT version number. The high byte is the major version and the low byte is the minor version. FAT drivers should respect this field.
|
||||||
|
; 4 The cluster number of the root directory. Often this field is set to 2.
|
||||||
|
; 2 The sector number of the FSInfo structure.
|
||||||
|
; 2 The sector number of the backup boot sector.
|
||||||
|
; 12 Reserved. When the volume is formated these bytes should be zero.
|
||||||
|
; 1 Drive number. The values here are identical to the values returned by the BIOS interrupt 0x13. 0x00 for a floppy disk and 0x80 for hard disks.
|
||||||
|
; 1 Flags in Windows NT. Reserved otherwise.
|
||||||
|
; 1 Signature (must be 0x28 or 0x29).
|
||||||
|
; 4 Volume ID 'Serial' number. Used for tracking volumes between computers. You can ignore this if you want.
|
||||||
|
; 11 Volume label string. This field is padded with spaces.
|
||||||
|
; 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use.
|
||||||
|
|
||||||
|
struc FAT32_ebpb_t
|
||||||
|
.sectors_per_fat_32 resb 4
|
||||||
|
.fat32_flags_16 resb 2
|
||||||
|
.fat32_version_16 resb 2
|
||||||
|
.root_dir_cluster_32 resb 4
|
||||||
|
.fsinfo_sector_16 resb 2
|
||||||
|
.backup_boot_sector_16 resb 2
|
||||||
|
.reserved1 resb 12
|
||||||
|
.drive_number_8 resb 1
|
||||||
|
.nt_flags_8 resb 1
|
||||||
|
.signature_8 resb 1
|
||||||
|
.volume_serial_32 resb 4
|
||||||
|
.volume_label resb 11
|
||||||
|
.system_ident resb 8
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; ## Standard 8.3 structure ###
|
||||||
|
; Offset Length (Bytes) Description
|
||||||
|
; 0 11 8.3 file name. The first 8 characters are the name and the last 3 are the extension.
|
||||||
|
; 11 1 File Atrributes
|
||||||
|
; READ_ONLY=0x01
|
||||||
|
; HIDDEN=0x02
|
||||||
|
; SYSTEM=0x04
|
||||||
|
; VOLUME_ID=0x08
|
||||||
|
; DIRECTORY=0x10
|
||||||
|
; ARCHIVE=0x20
|
||||||
|
; LFN=READ_ONLY|HIDDEN|SYSTEM|VOLUME_ID == 0x0F
|
||||||
|
;
|
||||||
|
; 12 1 NT Reserved
|
||||||
|
; 13 1 Creation time in tenths of a second.
|
||||||
|
; 14 2 File creation time, Hour 5 bits, Minutes 6 bits, Seconds 5 Bits, multiply seconds by 2
|
||||||
|
; 16 2 File creation date, Year 7 bits, month 4 bits, day 5 bits
|
||||||
|
; 18 2 Last Accessed date. same format at creation date
|
||||||
|
; 20 2 High 16 bits of entry's first cluster
|
||||||
|
; 22 2 Last modification time. same format at creation time
|
||||||
|
; 24 2 Last modification date. same format as creation date
|
||||||
|
; 26 2 Low 16 bits of entry's first cluster
|
||||||
|
; 28 4 File size in bytes
|
||||||
|
|
||||||
|
struc FAT32_SFN_t
|
||||||
|
.label resb 11
|
||||||
|
.attributes_8 resb 1
|
||||||
|
.nt_res_8 resb 1
|
||||||
|
.csec_8 resb 1
|
||||||
|
.ctime_16 resb 2
|
||||||
|
.cdate_16 resb 2
|
||||||
|
.adate_16 resb 2
|
||||||
|
.cluster_16_high resb 2
|
||||||
|
.mtime_16 resb 2
|
||||||
|
.mdate_16 resb 2
|
||||||
|
.cluster_16_low resb 2
|
||||||
|
.size_32 resb 4
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; ## Long file name (LFN) structure format ##
|
||||||
|
;
|
||||||
|
; 0 1 The order of this entry in the sequence of long file name entries. This value helps you to know where in the file's name the characters from this entry should be placed.
|
||||||
|
; 1 10 The first 5, 2-byte characters of this entry.
|
||||||
|
; 11 1 Attribute. Always equals 0x0F. (the long file name attribute)
|
||||||
|
; 12 1 Long entry type. Zero for name entries.
|
||||||
|
; 13 1 Checksum generated of the short file name when the file was created. The short filename can change without changing the long filename in cases where the partition is mounted on a system which does not support long filenames.
|
||||||
|
; 14 12 The next 6, 2-byte characters of this entry.
|
||||||
|
; 26 2 Always zero.
|
||||||
|
; 28 4 The final 2, 2-byte characters of this entry.
|
||||||
|
;
|
||||||
|
; LFN entries are always placed immediately before their respective 8.3 entry
|
||||||
|
;
|
||||||
|
; LAST_LFN_ENTRY == 0x40
|
||||||
|
; Max of 20 in sequence == 0x14
|
||||||
|
|
||||||
|
struc FAT32_LFN_t
|
||||||
|
.order resb 1
|
||||||
|
.lfn_first5 resb 10
|
||||||
|
.attributes_8 resb 1
|
||||||
|
.zero1 resb 1
|
||||||
|
.checksum resb 1
|
||||||
|
.lfn_next6 resb 12
|
||||||
|
.zero2 resb 2
|
||||||
|
.lfn_last2 resb 4
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; FSInfo
|
||||||
|
; 0 0x0 4 Lead signature (must be 0x41615252 to indicate a valid FSInfo structure)
|
||||||
|
; 4 0x4 480 Reserved, these bytes should never be used
|
||||||
|
; 484 0x1E4 4 Another signature (must be 0x61417272)
|
||||||
|
; 488 0x1E8 4 Contains the last known free cluster count on the volume. If the value is 0xFFFFFFFF, then the free count is unknown and must be computed.
|
||||||
|
; However, this value might be incorrect and should at least be range checked (<= volume cluster count)
|
||||||
|
;
|
||||||
|
; 492 0x1EC 4 Indicates the cluster number at which the filesystem driver should start looking for available clusters.
|
||||||
|
; If the value is 0xFFFFFFFF, then there is no hint and the driver should start searching at 2.
|
||||||
|
; Typically this value is set to the last allocated cluster number. As the previous field, this value should be range checked.
|
||||||
|
;
|
||||||
|
; 496 0x1F0 12 Reserved
|
||||||
|
; 508 0x1FC 4 Trail signature (0xAA550000)
|
||||||
|
|
||||||
|
struc FAT32_FSInfo_t
|
||||||
|
.head_signature_32 resd 1
|
||||||
|
.reserved1 resb 480
|
||||||
|
.body_signature_32 resd 1
|
||||||
|
.free_cluster_count_32 resd 1
|
||||||
|
.first_avail_cluster_32 resd 1
|
||||||
|
.reserved2 resd 3
|
||||||
|
.tail_signature_32 resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
|
||||||
|
; 32 bytes
|
||||||
|
struc FAT32_State_t
|
||||||
|
.first_root_dir_sector_32 resd 1
|
||||||
|
.first_data_sector_32 resd 1
|
||||||
|
.first_fat_sector_32 resd 1
|
||||||
|
.fat_size_32 resd 1
|
||||||
|
.active_cluster_32 resd 1
|
||||||
|
.active_FAT_cluster_32 resd 1
|
||||||
|
.active_dir_cluster_32 resd 1
|
||||||
|
.active_drive_lba_32 resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; 16 bytes
|
||||||
|
struc FAT32_NextClusterData_t
|
||||||
|
.fat_offset resd 1
|
||||||
|
.fat_sector resd 1
|
||||||
|
.entry_offset resd 1
|
||||||
|
.reserved_1 resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; FAT32 Attributes
|
||||||
|
%define FAT32_ATTR_RO 0x01
|
||||||
|
%define FAT32_ATTR_HIDDEN 0x02
|
||||||
|
%define FAT32_ATTR_SYSTEM 0x04
|
||||||
|
%define FAT32_ATTR_VOLID 0x08
|
||||||
|
%define FAT32_ATTR_DIR 0x10
|
||||||
|
%define FAT32_ATTR_ARC 0x20
|
||||||
|
|
||||||
|
; LFN == RO | HIDDEN | SYSTEM | VOLID == 0x0F
|
||||||
|
%define FAT32_ATTR_LFN 0x0F
|
||||||
|
|
||||||
|
|
||||||
208
include/memory.inc
Executable file
208
include/memory.inc
Executable file
@@ -0,0 +1,208 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; ## Generic Low mem map (from osdev wiki) ##
|
||||||
|
; start end size type description
|
||||||
|
; Low Memory (the first MiB)
|
||||||
|
; 0x00000000 0x000003FF 1 KiB RAM - partially unusable Real Mode IVT (Interrupt Vector Table)
|
||||||
|
; 0x00000400 0x000004FF 256 bytes RAM - partially unusable BDA (BIOS data area)
|
||||||
|
; 0x00000500 0x00007BFF almost 30 KiB RAM - free for use Conventional memory
|
||||||
|
; 0x00007C00 0x00007DFF 512 bytes RAM - partially unusable OS BootSector
|
||||||
|
; 0x00007E00 0x0007FFFF 480.5 KiB RAM - free for use Conventional memory
|
||||||
|
; 0x00080000 0x0009FFFF 128 KiB RAM - partially unusable EBDA (Extended BIOS Data Area)
|
||||||
|
; 0x000A0000 0x000FFFFF 384 KiB various (unusable) Video memory, ROM Area
|
||||||
|
|
||||||
|
; ## A rough overview of high mem ##
|
||||||
|
; Idealy this needs to be probed with the E820 functions
|
||||||
|
; # Start # End # size # description
|
||||||
|
;
|
||||||
|
; 0x00100000 0x00EFFFFF 0x00E00000 (14 MiB) RAM -- free for use (if it exists) Extended memory
|
||||||
|
; 0x00F00000 0x00FFFFFF 0x00100000 (1 MiB) Possible memory mapped hardware ISA Memory Hole 15-16MB
|
||||||
|
; 0x01000000 ???????? ??? (whatever exists) RAM -- free for use More Extended memory
|
||||||
|
; 0xC0000000 (sometimes) 0xFFFFFFFF 0x40000000 (1 GiB) Memory mapped PCI devices, PnP NVRAM?, IO APIC/s, local APIC/s, BIOS, ...
|
||||||
|
; 0x0000000100000000 ??? ??? (whatever exists) RAM -- free for use (PAE/64bit)/More Extended memory
|
||||||
|
; ???????????????? ??? ??? Potentially usable for memory mapped PCI devices in modern hardware (but typically not, due to backward compatibility)
|
||||||
|
|
||||||
|
; 0x2700 -> 0x28FF
|
||||||
|
%define disk_buffer 0x2700
|
||||||
|
; 0x2900 -> 0x2AFF
|
||||||
|
%define fat_buffer 0x2900
|
||||||
|
; 0x2B00 -> 0x2CFF
|
||||||
|
%define dir_buffer 0x2B00
|
||||||
|
|
||||||
|
; copy of partition table, 72 bytes
|
||||||
|
%define partition_table 0x3000
|
||||||
|
%define partition_table_SIZE 72
|
||||||
|
|
||||||
|
; copy of FAT32 BPB, 33 bytes (+1 to the next value to align to uint16_t)
|
||||||
|
;0x3048
|
||||||
|
%define fat32_bpb 0x3050
|
||||||
|
%define fat32_bpb_SIZE 33
|
||||||
|
|
||||||
|
; copy of FAT32 EBPB, 54 bytes
|
||||||
|
;0x306A
|
||||||
|
%define fat32_ebpb 0x3070
|
||||||
|
%define fat32_ebpb_SIZE 54
|
||||||
|
|
||||||
|
; FAT32 FSInfo, 512 bytes
|
||||||
|
;0x30A2
|
||||||
|
%define fat32_fsinfo 0x30B0
|
||||||
|
%define fat32_fsinfo_SIZE 512
|
||||||
|
|
||||||
|
; some stored state for the fat32 driver
|
||||||
|
;0x32A2
|
||||||
|
%define fat32_state 0x32B0
|
||||||
|
%define fat32_state_SIZE 32
|
||||||
|
|
||||||
|
; next free space is 0x32D0
|
||||||
|
%define fat32_nc_data 0x32D0
|
||||||
|
%define fat32_nc_data_size 16
|
||||||
|
|
||||||
|
; lba_packet for raw_disk_read
|
||||||
|
%define lba_packet 0x4000
|
||||||
|
|
||||||
|
%define BIOSMemoryMap 0x4200
|
||||||
|
%define SteviaInfo 0x4400
|
||||||
|
|
||||||
|
|
||||||
|
; High memory addresses for loading kernel (for use with unreal mode and 32bit override)
|
||||||
|
|
||||||
|
; file load buffer at 16MB
|
||||||
|
%define HMEM_load_buffer 0x1000000
|
||||||
|
|
||||||
|
|
||||||
|
;PhysicalAddress = Segment * 16 + Offset
|
||||||
|
%define SEG_TO_LINEAR(s,o) ((s << 4) + o)
|
||||||
|
|
||||||
|
; Offset = physical / (Segment * 16)
|
||||||
|
%define LINEAR_TO_OFFSET(p,s) ((p / (s << 4)))
|
||||||
|
|
||||||
|
; Seg = (physical - offset) / 16
|
||||||
|
%define LINEAR_TO_SEGMENT(p,o) ((p - o) >> 4)
|
||||||
|
|
||||||
|
; create normalized linear addres from seg:off (16:4)
|
||||||
|
; Segement = linear >> 4 (top 16 bits)
|
||||||
|
; offset = linear & 0x0F (low 4 bits)
|
||||||
|
|
||||||
|
; 20 bytes, passed to loaded kernel
|
||||||
|
struc SteviaInfoStruct_t
|
||||||
|
.MemoryMapPtr resd 1
|
||||||
|
.MemoryMapEntries resd 1
|
||||||
|
.BPBDataPtr resd 1
|
||||||
|
.EBPBDataPtr resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow u32 - Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh u32 - High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow u32 - Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh u32 - High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type u32 - Address type of this range.
|
||||||
|
; 20 ExtType u32 - ACPI 3.0 extended type
|
||||||
|
struc AddressRangeDescStruct_t
|
||||||
|
.BaseAddrLow resd 1
|
||||||
|
.BaseAddrHigh resd 1
|
||||||
|
.LengthLow resd 1
|
||||||
|
.LengthHigh resd 1
|
||||||
|
.Type resd 1
|
||||||
|
.ExtType resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; moves argument into eax then pushes lower 16bits then upper 16 bits of of argument to stack
|
||||||
|
; eax is clobbered
|
||||||
|
%macro PUSH_DWORD 1
|
||||||
|
mov eax, %1
|
||||||
|
push ax
|
||||||
|
shr eax, 16
|
||||||
|
push ax
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
; same as PUSH_DWORD except no arguments, pushes EAX directly
|
||||||
|
%macro PUSH_DWORD_EAX 0
|
||||||
|
push ax
|
||||||
|
shr eax, 16
|
||||||
|
push ax
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
; pops upper 16bits then lower 16bits into eax
|
||||||
|
; eax is clobbered
|
||||||
|
%macro POP_DWORD_EAX 0
|
||||||
|
xor eax, eax
|
||||||
|
pop ax
|
||||||
|
shl eax, 16
|
||||||
|
pop ax
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
; moves data on stack referenced by bp to eax
|
||||||
|
; stack must be organized as follows (tl;dr push lower 16bits first ie. PUSH_DWORD macro)
|
||||||
|
; MOV_DWORD_EAX 2
|
||||||
|
; STACK TOP (0x0)
|
||||||
|
; upper_uint16 [bp-4]
|
||||||
|
; lower_uint16 [bp-2]
|
||||||
|
; --- [bp] ---
|
||||||
|
; ...
|
||||||
|
; STACK BOTTOM
|
||||||
|
;
|
||||||
|
; first argument == starting offset from bp for lower 16bits
|
||||||
|
%macro MOV_DWORD_EAX 1
|
||||||
|
mov ax, [bp-(%1+2)]
|
||||||
|
shl eax, 16
|
||||||
|
mov ax, [bp-%1]
|
||||||
|
; eax contains dword from stack
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
%macro DEBUG_HCF 0
|
||||||
|
DEBUG_LOOP:
|
||||||
|
hlt
|
||||||
|
jmp short DEBUG_LOOP
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
|
||||||
|
; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||||
|
kmemset:
|
||||||
|
push di ; function uses di, so save it.
|
||||||
|
|
||||||
|
mov cx, [bp - 2] ; size_t len
|
||||||
|
mov al, [bp - 4] ; uint8_t val
|
||||||
|
mov di, [bp - 6] ; void * ptr
|
||||||
|
|
||||||
|
cld
|
||||||
|
rep stosb
|
||||||
|
.endf:
|
||||||
|
mov ax, [bp - 6] ; return pointer to dest
|
||||||
|
pop di ; restore di
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, size_t len);
|
||||||
|
; not overlap safe
|
||||||
|
kmemcpy:
|
||||||
|
push di
|
||||||
|
push si ; di, si are callee save
|
||||||
|
|
||||||
|
mov cx, [bp - 2] ; length
|
||||||
|
mov si, [bp - 4] ; source
|
||||||
|
mov di, [bp - 6] ; dest
|
||||||
|
|
||||||
|
cld ; ensure we are incrementing
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
mov ax, [bp - 6] ; return pointer to dest
|
||||||
|
pop si
|
||||||
|
pop di
|
||||||
|
ret
|
||||||
59
include/partition_table.inc
Executable file
59
include/partition_table.inc
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
; Partition table entry format
|
||||||
|
; Off. Size. Description
|
||||||
|
;0x00 1 Drive attributes (bit 7 set = active or bootable)
|
||||||
|
;0x01 3 CHS Address of partition start
|
||||||
|
;0x04 1 Partition type
|
||||||
|
;0x05 3 CHS address of last partition sector
|
||||||
|
;0x08 4 LBA of partition start
|
||||||
|
;0x0C 4 Number of sectors in partition
|
||||||
|
|
||||||
|
struc PartEntry_t
|
||||||
|
.attributes resb 1
|
||||||
|
.chs_start resb 3
|
||||||
|
.part_type resb 1
|
||||||
|
.chs_end resb 3
|
||||||
|
.lba_start resb 4
|
||||||
|
.lba_length resb 4
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
struc PartTable_t
|
||||||
|
.partition1 resb 16
|
||||||
|
.partition2 resb 16
|
||||||
|
.partition3 resb 16
|
||||||
|
.partition4 resb 16
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
|
||||||
|
;Offset Size Description
|
||||||
|
; 0 1 size of packet (16 bytes)
|
||||||
|
; 1 1 always 0
|
||||||
|
; 2 2 number of sectors to transfer (max 127 on some BIOSes)
|
||||||
|
; 4 4 transfer buffer (0xFFFF:0xFFFF)
|
||||||
|
; 8 4 lower 32-bits of starting 48-bit LBA
|
||||||
|
; 12 4 upper 32-bits of starting 48-bit LBA
|
||||||
|
; needs to be aligned to a uint32_t
|
||||||
|
struc LBAPkt_t
|
||||||
|
.size resb 1
|
||||||
|
.res0 resb 1
|
||||||
|
.xfer_size resw 1
|
||||||
|
.offset resw 1
|
||||||
|
.segment resw 1
|
||||||
|
.lower_lba resd 1
|
||||||
|
.upper_lba resd 1
|
||||||
|
endstruc
|
||||||
196
scripts/create-disk.sh
Executable file
196
scripts/create-disk.sh
Executable file
@@ -0,0 +1,196 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright (C) 2020 Bradley Claus
|
||||||
|
#
|
||||||
|
# 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if ! [ $(id -u) = 0 ]; then
|
||||||
|
echo "Script must be run as root!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mbr_file=build/mbr.bin
|
||||||
|
vbr_file=build/vbr.bin
|
||||||
|
stage2_file=build/stage2.bin
|
||||||
|
boottest_file=build/BOOT_386.bin
|
||||||
|
|
||||||
|
mount_point=/tmp/stevia_disk
|
||||||
|
|
||||||
|
if ! [ -e disk.img ]; then
|
||||||
|
# create raw disk image with 128MiB of space
|
||||||
|
dd if=/dev/zero of=disk.img bs=512 count=262144
|
||||||
|
sync
|
||||||
|
else
|
||||||
|
echo "Removing old disk image..."
|
||||||
|
rm -rfv disk.img
|
||||||
|
dd if=/dev/zero of=disk.img bs=512 count=262144
|
||||||
|
sync
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
if [ -e $mbr_file ] && [ -e $vbr_file ]; then
|
||||||
|
# get next loop device and mount it
|
||||||
|
ld=$(losetup -f)
|
||||||
|
losetup -b 512 $ld disk.img
|
||||||
|
|
||||||
|
# create a DOS disk, with 1 FAT32 partition that is bootable, part1 starts at sector 2048
|
||||||
|
sfdisk $ld < scripts/loop_setup.sfdisk
|
||||||
|
|
||||||
|
# partprobe the image
|
||||||
|
partprobe $ld
|
||||||
|
|
||||||
|
# get first partition
|
||||||
|
firstpart=$(lsblk -ilp -o NAME $ld | tr '\n' ' ' | awk '{print $3}')
|
||||||
|
mkfs.vfat -v -F32 $firstpart
|
||||||
|
|
||||||
|
# copy MBR while preserving partition table
|
||||||
|
dd if=$mbr_file of=$ld bs=1 count=440
|
||||||
|
# copy MBR 0xAA55
|
||||||
|
dd if=$mbr_file of=$ld bs=1 seek=510 skip=510 count=2
|
||||||
|
|
||||||
|
# copy VBR to partition 1 while preserving partition information
|
||||||
|
# copy jmp short entry; nop
|
||||||
|
dd if=$vbr_file of=$firstpart bs=1 count=3
|
||||||
|
# copy bootcode
|
||||||
|
dd if=$vbr_file of=$firstpart bs=1 seek=90 skip=90 count=420
|
||||||
|
# copy 0xAA55
|
||||||
|
dd if=$vbr_file of=$firstpart bs=1 seek=510 skip=510 count=2
|
||||||
|
|
||||||
|
#stage2 to sectors 1-64
|
||||||
|
dd if=$stage2_file of=$ld bs=512 seek=1
|
||||||
|
|
||||||
|
# copy boot32 boot test file to disk image
|
||||||
|
if ! [ -e $mount_point ]; then
|
||||||
|
mkdir $mount_point
|
||||||
|
fi
|
||||||
|
mount $firstpart $mount_point
|
||||||
|
|
||||||
|
if [ -e $boottest_file ]; then
|
||||||
|
cp -v $boottest_file $mount_point
|
||||||
|
else
|
||||||
|
echo "unable to find boot32.bin!"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# detach loop device
|
||||||
|
umount $mount_point
|
||||||
|
sync
|
||||||
|
losetup -d $ld
|
||||||
|
|
||||||
|
# chown to the real user to prevent issues with reading/writing the file later
|
||||||
|
SUDOUSER=$(logname)
|
||||||
|
chown --from=root:root ${SUDOUSER}:$(id $SUDOUSER -g) disk.img
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "unable to find MBR/VBR binaries!"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
# requires util-linux from homebrew
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
sfdisk_path="/usr/local/opt/util-linux/sbin/sfdisk"
|
||||||
|
if [ -e $mbr_file ] && [ -e $vbr_file ]; then
|
||||||
|
# use hdiutil to attach our empty disk image
|
||||||
|
ld_path_raw=$(hdiutil attach -readwrite -imagekey diskimage-class=CRawDiskImage -nomount -blocksize 512 -noverify disk.img)
|
||||||
|
ld=$(echo $ld_path_raw | sed s:/dev/::)
|
||||||
|
ld_path="/dev/$ld"
|
||||||
|
|
||||||
|
# create a DOS disk, with 1 FAT32 partition
|
||||||
|
if ! [ -e $sfdisk_path ]; then
|
||||||
|
echo "sfdisk utility was not found...We cannot use diskutil to make disks due to the fact that it only makes Hybrid MBR's & GPT disks...blame Apple"
|
||||||
|
exit 4
|
||||||
|
else
|
||||||
|
$sfdisk_path $ld_path < scripts/loop_setup.sfdisk
|
||||||
|
fi
|
||||||
|
|
||||||
|
# give stuff a chance to settle, macOS has problems here
|
||||||
|
sync
|
||||||
|
sleep .5
|
||||||
|
|
||||||
|
# reattch the raw image file since macOS doesn't have a partprobe...
|
||||||
|
# this is the only way I know to get macOS to reprobe the disk
|
||||||
|
hdiutil eject $ld
|
||||||
|
unset ld_path
|
||||||
|
unset ld
|
||||||
|
unset ld_path_raw
|
||||||
|
|
||||||
|
ld_path_raw=$(hdiutil attach -readwrite -imagekey diskimage-class=CRawDiskImage -nomount -blocksize 512 -noverify disk.img)
|
||||||
|
ld=$(echo $ld_path_raw | grep "FDisk_partition_scheme" | awk '{print $1}' | sed s:/dev/::)
|
||||||
|
ld_path="/dev/$ld"
|
||||||
|
|
||||||
|
if ! [ -b /dev/$ld ]; then
|
||||||
|
echo "Unable to remount disk! exitting before I do some damage!"
|
||||||
|
exit 5
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get first partition and format as FAT32
|
||||||
|
firstpart=$(diskutil list $ld | grep 1: | awk '{print $6}')
|
||||||
|
firstpart_direct="r$firstpart"
|
||||||
|
|
||||||
|
newfs_msdos -F 32 /dev/$firstpart_direct
|
||||||
|
sync
|
||||||
|
|
||||||
|
# copy MBR while preserving partition table
|
||||||
|
dd if=$mbr_file of=$ld_path bs=1 count=440 conv=sync
|
||||||
|
# copy MBR 0xAA55
|
||||||
|
dd if=$mbr_file of=$ld_path bs=1 seek=510 skip=510 count=2 conv=sync
|
||||||
|
|
||||||
|
# copy VBR to partition 1 while preserving partition information
|
||||||
|
# copy jmp short entry; nop
|
||||||
|
dd if=$vbr_file of=/dev/$firstpart bs=1 count=3 conv=sync
|
||||||
|
# copy bootcode
|
||||||
|
dd if=$vbr_file of=/dev/$firstpart bs=1 seek=90 skip=90 count=420 conv=sync
|
||||||
|
# copy 0xAA55
|
||||||
|
dd if=$vbr_file of=/dev/$firstpart bs=1 seek=510 skip=510 count=2 conv=sync
|
||||||
|
|
||||||
|
#stage2 to sectors 1-64
|
||||||
|
dd if=$stage2_file of=$ld_path bs=512 seek=1 conv=sync
|
||||||
|
|
||||||
|
#sync pending dd stuff
|
||||||
|
sync
|
||||||
|
|
||||||
|
# copy boot32 boot test file to disk image
|
||||||
|
if ! [ -e $mount_point ]; then
|
||||||
|
mkdir $mount_point
|
||||||
|
else
|
||||||
|
echo "$mount_point exists! clearing contents..."
|
||||||
|
rm -rfv $mount_point
|
||||||
|
mkdir $mount_point
|
||||||
|
fi
|
||||||
|
mount -t msdos /dev/$firstpart $mount_point
|
||||||
|
|
||||||
|
if [ -e $boottest_file ]; then
|
||||||
|
cp -v $boottest_file $mount_point
|
||||||
|
else
|
||||||
|
echo "unable to find boot32.bin!"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# detach loop device
|
||||||
|
sync
|
||||||
|
umount /dev/$firstpart
|
||||||
|
hdiutil eject $ld
|
||||||
|
|
||||||
|
# chown to the real user to prevent issues with reading/writing the file later
|
||||||
|
SUDOUSER=$(logname)
|
||||||
|
chown ${SUDOUSER}:staff disk.img
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "unable to find MBR/VBR binaries!"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Unknown.
|
||||||
|
echo "Unknown OS type! Supported build hosts systems are GNU/Linux and macOS."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
4
scripts/loop_setup.sfdisk
Executable file
4
scripts/loop_setup.sfdisk
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
label: dos
|
||||||
|
unit: sectors
|
||||||
|
|
||||||
|
start= 2048, type=b, bootable
|
||||||
239
src/mbr/mbr.s
Executable file
239
src/mbr/mbr.s
Executable file
@@ -0,0 +1,239 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[BITS 16]
|
||||||
|
[ORG 0x7A00]
|
||||||
|
[CPU KATMAI]
|
||||||
|
jmp short init
|
||||||
|
nop
|
||||||
|
|
||||||
|
%include "entry.inc"
|
||||||
|
init:
|
||||||
|
cli ; We do not want to be interrupted
|
||||||
|
|
||||||
|
xor ax, ax ; 0 AX
|
||||||
|
mov ds, ax ; Set segment registers to 0
|
||||||
|
mov es, ax ; *
|
||||||
|
|
||||||
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
|
mov sp, STACK_START
|
||||||
|
|
||||||
|
mov ch, 0x01 ; 256 WORDs in MBR (512 bytes), 0x0100 in cx
|
||||||
|
mov si, 0x7C00 ; Current MBR Address (loaded here by BIOS)
|
||||||
|
mov di, MBR_ENTRY ; New MBR Address (our new relocation address)
|
||||||
|
rep movsw ; copy 512 bytes from 0x0000:7c00 to 0x0000:0600
|
||||||
|
|
||||||
|
jmp 0:main
|
||||||
|
nop
|
||||||
|
|
||||||
|
%include "config.inc"
|
||||||
|
%include "memory.inc"
|
||||||
|
%include "partition_table.inc"
|
||||||
|
%include "errors.inc"
|
||||||
|
|
||||||
|
main:
|
||||||
|
sti
|
||||||
|
mov [boot_drive], dl ; BIOS passes drive number in DL
|
||||||
|
|
||||||
|
.check_disk:
|
||||||
|
cmp dl, 0x80
|
||||||
|
jae main.find_active
|
||||||
|
ERROR MBR_ERROR_DISK_T_ERR
|
||||||
|
|
||||||
|
.check_extentions:
|
||||||
|
xor ax, ax
|
||||||
|
mov bx, 0x55AA
|
||||||
|
mov dl, byte [boot_drive]
|
||||||
|
int 0x13
|
||||||
|
jnc main.find_active
|
||||||
|
ERROR MBR_ERROR_NO_INT32E ; no extended function support
|
||||||
|
|
||||||
|
.find_active:
|
||||||
|
mov bx, PartEntry1 ; base = first partition
|
||||||
|
mov cx, 4 ; there are only 4 entries
|
||||||
|
.find_active_L0:
|
||||||
|
mov al, byte [bx + PartEntry_t.attributes]
|
||||||
|
test al, 0x80 ; 0x80 == 1000_0000b
|
||||||
|
jnz main.active_found
|
||||||
|
|
||||||
|
add bx, 0x10 ; add 16 bytes to offset
|
||||||
|
loop main.find_active_L0
|
||||||
|
ERROR MBR_ERROR_NO_NO_BOOT_PART
|
||||||
|
|
||||||
|
.active_found:
|
||||||
|
mov ax, bx
|
||||||
|
sub ax, DiskSig ; leaves us with the offset relative from start of table
|
||||||
|
; this gives us an offset from the begining of the partition table
|
||||||
|
mov word [part_offset], ax ; update part_offset
|
||||||
|
.read_data:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
;uint8_t read_disk_raw(size_t count, uint16_t buf_segment, uint16_t buf_offset,
|
||||||
|
; uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
||||||
|
mov eax, dword [bx + PartEntry_t.lba_start]
|
||||||
|
ror eax, 16
|
||||||
|
push ax
|
||||||
|
|
||||||
|
ror eax, 16
|
||||||
|
push ax
|
||||||
|
|
||||||
|
mov ax, VBR_ENTRY
|
||||||
|
push ax
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
push ax ; segment = 0
|
||||||
|
|
||||||
|
mov ax, 1
|
||||||
|
push ax
|
||||||
|
|
||||||
|
call read_disk_raw
|
||||||
|
leave
|
||||||
|
|
||||||
|
jnc main.goto_vbr
|
||||||
|
ERROR MBR_ERROR_DISK_READ_ERR ; error in LBA read
|
||||||
|
.goto_vbr:
|
||||||
|
cmp word [VBR_ENTRY + 0x1FE], 0xAA55
|
||||||
|
je main.sig_ok
|
||||||
|
ERROR MBR_ERROR_NO_VBR_SIG ; no signature present
|
||||||
|
|
||||||
|
.sig_ok:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
mov ax, partition_table_SIZE ; 72 bytes of data
|
||||||
|
push ax
|
||||||
|
mov ax, DiskSig ; start of partition table
|
||||||
|
push ax
|
||||||
|
mov ax, partition_table ; defined in memory.inc
|
||||||
|
push ax
|
||||||
|
call kmemcpy ; copy partition table to memory
|
||||||
|
leave
|
||||||
|
|
||||||
|
xor ah, ah ; Set Video mode BIOS function
|
||||||
|
mov al, 0x02 ; 16 color 80x25 Text mode
|
||||||
|
int 0x10 ; Call video interrupt
|
||||||
|
|
||||||
|
mov ah, 0x05 ; Select active display page BIOS function
|
||||||
|
xor al, al ; page 0
|
||||||
|
int 0x10 ; call video interrupt
|
||||||
|
|
||||||
|
mov si, word [part_offset]
|
||||||
|
mov dl, byte [boot_drive]
|
||||||
|
jmp 0:0x7C00
|
||||||
|
|
||||||
|
; Wrapper for AH=0x42 INT13h (Extended Read)
|
||||||
|
;
|
||||||
|
; BIOS call details
|
||||||
|
; AH = 42h
|
||||||
|
; DL = drive number
|
||||||
|
; DS:SI -> disk address packet
|
||||||
|
;
|
||||||
|
; Return:
|
||||||
|
; CF clear if successful
|
||||||
|
; AH = 00h
|
||||||
|
; CF set on error
|
||||||
|
; AH = error code
|
||||||
|
; disk address packet's block count field set to number of blocks
|
||||||
|
; successfully transferred
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
||||||
|
; bp-0 = call frame
|
||||||
|
; bp-2 = upper_lower_lba
|
||||||
|
; bp-4 = lower_lower_lba
|
||||||
|
; bp-6 = offset
|
||||||
|
; bp-8 = segment
|
||||||
|
; bp-10 = count
|
||||||
|
; bp-12 = ret ptr
|
||||||
|
read_disk_raw:
|
||||||
|
push si
|
||||||
|
|
||||||
|
; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
mov ax, 0x10
|
||||||
|
push ax ; len = 16 bytes
|
||||||
|
xor ax, ax
|
||||||
|
push ax ; val = 0
|
||||||
|
mov ax, lba_packet
|
||||||
|
push ax ; dest = lba_packet address
|
||||||
|
|
||||||
|
call kmemset
|
||||||
|
leave
|
||||||
|
|
||||||
|
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
||||||
|
mov word [lba_packet + LBAPkt_t.xfer_size], STAGE2_SECTOR_COUNT
|
||||||
|
|
||||||
|
mov ax, [bp-2]
|
||||||
|
shl eax, 16
|
||||||
|
mov ax, [bp-4]
|
||||||
|
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
||||||
|
|
||||||
|
mov ax, [bp-6]
|
||||||
|
mov word [lba_packet + LBAPkt_t.offset], ax
|
||||||
|
|
||||||
|
mov ax, [bp-8]
|
||||||
|
mov word [lba_packet + LBAPkt_t.segment], ax
|
||||||
|
|
||||||
|
mov si, lba_packet
|
||||||
|
mov ah, 0x42
|
||||||
|
mov dl, byte [boot_drive]
|
||||||
|
int 0x13
|
||||||
|
jnc read_disk_raw.endf
|
||||||
|
|
||||||
|
mov al, 'B'
|
||||||
|
jmp error
|
||||||
|
.endf:
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
|
||||||
|
; #############
|
||||||
|
;
|
||||||
|
; Locals
|
||||||
|
;
|
||||||
|
; #############
|
||||||
|
|
||||||
|
boot_drive:
|
||||||
|
db 0x00
|
||||||
|
mbr_reserved1:
|
||||||
|
db 0x00
|
||||||
|
|
||||||
|
; OFFSET from BEGINING of partition table, ie. DiskSig (-6 from PartEntry1)
|
||||||
|
part_offset:
|
||||||
|
dw 0x0000
|
||||||
|
|
||||||
|
%assign bytes_remaining (440 - ($ - $$))
|
||||||
|
%warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes)
|
||||||
|
times ((512 - 72) - ($ - $$)) nop ; Fill the rest of sector with nop
|
||||||
|
|
||||||
|
DiskSig:
|
||||||
|
times 4 db 0x00
|
||||||
|
Reserved1:
|
||||||
|
db 0x00
|
||||||
|
Reserved2:
|
||||||
|
db 0x00
|
||||||
|
|
||||||
|
PartEntry1:
|
||||||
|
times 16 db 0x00
|
||||||
|
PartEntry2:
|
||||||
|
times 16 db 0x00
|
||||||
|
PartEntry3:
|
||||||
|
times 16 db 0x00
|
||||||
|
PartEntry4:
|
||||||
|
times 16 db 0x00
|
||||||
|
BootSig:
|
||||||
|
dw 0xAA55 ; Add boot signature at the end of bootloader
|
||||||
554
src/miniboot32/BOOT_386.s
Executable file
554
src/miniboot32/BOOT_386.s
Executable file
@@ -0,0 +1,554 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[BITS 32]
|
||||||
|
[ORG 0x100000]
|
||||||
|
[CPU KATMAI]
|
||||||
|
|
||||||
|
jmp short start32
|
||||||
|
nop
|
||||||
|
|
||||||
|
; Unless noted otherwise, functions will be the standard x86 cdecl used in GCC
|
||||||
|
|
||||||
|
; In cdecl, subroutine arguments are passed on the stack.
|
||||||
|
; Integer values and memory addresses are returned in the EAX register,
|
||||||
|
; floating point values in the ST0 x87 register.
|
||||||
|
; Registers EAX, ECX, and EDX are caller-saved,
|
||||||
|
; and the rest are callee-saved.
|
||||||
|
; The x87 floating point registers ST0 to ST7 must be empty (popped or freed)
|
||||||
|
; when calling a new function, and ST1 to ST7 must be empty on exiting a function.
|
||||||
|
; ST0 must also be empty when not used for returning a value.
|
||||||
|
;
|
||||||
|
; EXAMPLE: to call uint8_t* kmemset(uint8_t* dest, uint8_t val, uint8_t size);
|
||||||
|
; => kmemset(*((char*) 0xb8000), 'F', (80*25))
|
||||||
|
;
|
||||||
|
; push ebp ; save old call frame pointer
|
||||||
|
; mov ebp, esp ; new call frame pointer
|
||||||
|
; push 0x000007D0 ; push args RTL, EBP - 4
|
||||||
|
; push 'F' ; * EBP - 8
|
||||||
|
; push 0x000b8000 ; * EBP - 12
|
||||||
|
; call kmemset ; call function, this also places a return pointer on stack
|
||||||
|
; add esp, 12 ; remove call arguments from stack frame
|
||||||
|
; mov esp, ebp ; restore stack frame pointer (callee saves EBP)
|
||||||
|
; pop ebp ; restore call frame pointer
|
||||||
|
;
|
||||||
|
;
|
||||||
|
|
||||||
|
; 33 bytes BPB + 26 Byte EBPB
|
||||||
|
struc BPBStruct
|
||||||
|
.OemName resb 8
|
||||||
|
.BytesPerSect resw 1
|
||||||
|
.SecsPerClust resb 1
|
||||||
|
.ResSectors resw 1
|
||||||
|
.FATs resb 1
|
||||||
|
.RootDirEnts resw 1
|
||||||
|
.Sectors resw 1
|
||||||
|
.Media resb 1
|
||||||
|
.SectPerFAT resw 1
|
||||||
|
.SectPerTrack resw 1
|
||||||
|
.Heads resw 1
|
||||||
|
.Hidden resd 1
|
||||||
|
.SectorHuge resd 1
|
||||||
|
; begin EBPB
|
||||||
|
.DriveNumber resb 1
|
||||||
|
.NTReserved resb 1
|
||||||
|
.Signature resb 1
|
||||||
|
.VolumeID resd 1
|
||||||
|
.VolumeLabel resb 11
|
||||||
|
.SysIdent resb 8
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; 12 bytes
|
||||||
|
struc FSInfoStruct
|
||||||
|
.first_root_dir_sector resw 1
|
||||||
|
.last_root_dir_sector resw 1
|
||||||
|
.root_dir_len resw 1
|
||||||
|
.first_data_sector resw 1
|
||||||
|
.active_cluster resw 1
|
||||||
|
.active_FAT_cluster resw 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; 20 bytes
|
||||||
|
struc KInfoStruct
|
||||||
|
.load_address resd 1
|
||||||
|
.file_len resd 1
|
||||||
|
.file_name resb 8
|
||||||
|
.file_ext resb 3
|
||||||
|
.reserved1 resb 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow u32 - Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh u32 - High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow u32 - Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh u32 - High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type u32 - Address type of this range.
|
||||||
|
; 20 ExtType u32 - ACPI 3.0 extended type
|
||||||
|
struc AddressRangeDescStruct
|
||||||
|
.BaseAddrLow resd 1
|
||||||
|
.BaseAddrHigh resd 1
|
||||||
|
.LengthLow resd 1
|
||||||
|
.LengthHigh resd 1
|
||||||
|
.Type resd 1
|
||||||
|
.ExtType resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; 20 bytes, passed to loaded kernel
|
||||||
|
struc CBootInfoStruct
|
||||||
|
.MemoryMapPtr resd 1
|
||||||
|
.MemoryMapEntries resd 1
|
||||||
|
.BPBDataPtr resd 1
|
||||||
|
.FSInfoPtr resd 1
|
||||||
|
.KInfoPtr resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
;;;
|
||||||
|
; Errors
|
||||||
|
; 0 = unused
|
||||||
|
; 1 = No CPUID support on this platform (VM or some very old hardware?)
|
||||||
|
; 2 = magic signature not found at end of file
|
||||||
|
; 3 = Unexpected/unhandled artithmetic overflow/carry
|
||||||
|
;;;
|
||||||
|
|
||||||
|
%define MAX_BYTES (1024 * 8)
|
||||||
|
|
||||||
|
%define VGA_BUF 0xb8000
|
||||||
|
;black BG/Green FG
|
||||||
|
%define TTY_COLOR 0x0200
|
||||||
|
;black BG/Red FG
|
||||||
|
%define TTY_ERR_CLR 0x0400
|
||||||
|
;subtract 1 for max array values
|
||||||
|
%define VGA_MAX_Y 25
|
||||||
|
%define VGA_MAX_X 80
|
||||||
|
|
||||||
|
; VGA memory is row-major => offset = (row * MAX_Colums) + colum
|
||||||
|
; macro array is counted from 0,0 = 1,1 => 79,24 is the last usable space in a page
|
||||||
|
%define VGA_OFFSET(x,y) (((y*VGA_MAX_X) + x)*2)
|
||||||
|
|
||||||
|
start32:
|
||||||
|
mov ax, 0x10
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax
|
||||||
|
mov ss, ax ; load data registers with 2nd GDT selector
|
||||||
|
mov esp, stack_top
|
||||||
|
mov ebp, esp
|
||||||
|
|
||||||
|
; debugger hack because gdb doesn't like to switch register sizes
|
||||||
|
; issue a set $eax = 1 to continue
|
||||||
|
%ifdef DEBUG_HACK
|
||||||
|
mov eax, 0
|
||||||
|
.gdb_hack:
|
||||||
|
test eax, eax
|
||||||
|
jz start32.gdb_hack
|
||||||
|
%endif
|
||||||
|
|
||||||
|
mov eax, dword [BOOT_SIG]
|
||||||
|
cmp eax, 0xA0B0C0D0
|
||||||
|
jz start32.signature_present
|
||||||
|
|
||||||
|
mov al, "2"
|
||||||
|
call error
|
||||||
|
|
||||||
|
|
||||||
|
.signature_present:
|
||||||
|
call check_cpuid
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
lea eax, [welcome_cstr]
|
||||||
|
push eax
|
||||||
|
call vga_puts
|
||||||
|
leave
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
lea eax, [version_cstr]
|
||||||
|
push eax
|
||||||
|
call vga_puts
|
||||||
|
leave
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
lea eax, [datetime_cstr]
|
||||||
|
push eax
|
||||||
|
call vga_puts
|
||||||
|
leave
|
||||||
|
|
||||||
|
mov eax, VGA_BUF
|
||||||
|
add eax, VGA_OFFSET(78, 24)
|
||||||
|
mov dword [eax], 0x2f4b2f4f
|
||||||
|
hlt
|
||||||
|
|
||||||
|
; Early error printer. Prints 'ERR: X' where X is an error code in al
|
||||||
|
error:
|
||||||
|
mov eax, VGA_BUF
|
||||||
|
add eax, VGA_OFFSET(73, 24)
|
||||||
|
|
||||||
|
mov dword [eax], 0x4f524f45
|
||||||
|
add eax, 0x2
|
||||||
|
mov dword [eax], 0x4f3a4f52
|
||||||
|
add eax, 0x2
|
||||||
|
mov dword [eax], 0x4f204f20
|
||||||
|
add eax, 0x2
|
||||||
|
mov byte [eax], al
|
||||||
|
hlt
|
||||||
|
|
||||||
|
check_cpuid:
|
||||||
|
; flip cpuid id bit (bit 21) to check for cpuid support
|
||||||
|
|
||||||
|
; copy flags to eax via stack
|
||||||
|
pushfd
|
||||||
|
pop eax
|
||||||
|
|
||||||
|
mov ecx, eax ; copy to ecx for compare
|
||||||
|
|
||||||
|
xor eax, 1 << 21 ; xor eax with the 21st bit set
|
||||||
|
|
||||||
|
push eax ; push new flags and pop to flags register
|
||||||
|
popfd
|
||||||
|
|
||||||
|
pushfd
|
||||||
|
pop eax
|
||||||
|
|
||||||
|
cmp eax, ecx ; can we change the bit?
|
||||||
|
je .no_cpuid
|
||||||
|
ret
|
||||||
|
.no_cpuid:
|
||||||
|
mov al, "1"
|
||||||
|
call error
|
||||||
|
|
||||||
|
; int vga_puts(char* str)
|
||||||
|
;
|
||||||
|
; INPUT:
|
||||||
|
; str: C-Sytle string
|
||||||
|
;
|
||||||
|
; OUTPUT:
|
||||||
|
; EAX = characters printed
|
||||||
|
;
|
||||||
|
vga_puts:
|
||||||
|
; prolog, EBP = SFP (Stack frame pointer), [EBP-4] = char* str
|
||||||
|
push edi
|
||||||
|
push esi
|
||||||
|
push ebx
|
||||||
|
|
||||||
|
.get_str_len:
|
||||||
|
mov edi, [ebp - 4]
|
||||||
|
|
||||||
|
xor ecx, ecx ; ECX = 0
|
||||||
|
not ecx ; ECX = -1 == 0xFFFFFFFF
|
||||||
|
xor eax, eax ; search for al = 0x0
|
||||||
|
cld
|
||||||
|
repne scasb ; deincrement ecx while searching for al
|
||||||
|
not ecx ; the inverse of a neg number = abs(x) - 1
|
||||||
|
dec ecx ; ECX contains the length of the string - nul byte at end
|
||||||
|
|
||||||
|
|
||||||
|
mov edi, VGA_BUF ; load dest index with VGA buffer + calculated offset
|
||||||
|
mov esi, [ebp -4] ; load source index with src string
|
||||||
|
|
||||||
|
; ECX = string length
|
||||||
|
; ESI = source string to print
|
||||||
|
; EDI = destination in the VGA buffer
|
||||||
|
.print_char:
|
||||||
|
cmp ecx, 0x0
|
||||||
|
jle vga_puts.endf
|
||||||
|
|
||||||
|
cmp byte [vga_buf_pos_x], 80
|
||||||
|
je vga_puts.end_of_line
|
||||||
|
|
||||||
|
cmp byte [vga_buf_pos_y], 25
|
||||||
|
je vga_puts.scroll_up
|
||||||
|
|
||||||
|
cmp byte [esi], 0x20
|
||||||
|
jl vga_puts.special_character_switch
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
|
||||||
|
xor eax, eax
|
||||||
|
mov al, [vga_buf_pos_y]
|
||||||
|
push eax ; vga_pos_y
|
||||||
|
|
||||||
|
xor eax, eax
|
||||||
|
mov al, [vga_buf_pos_x]
|
||||||
|
push eax ; vga_pos_x
|
||||||
|
|
||||||
|
; uint16_t vga_calc_offset(uint8_t vga_pos_x, uint8_t vga_pos_y)
|
||||||
|
call vga_calc_offset
|
||||||
|
leave
|
||||||
|
|
||||||
|
xor bx, bx
|
||||||
|
mov bl, byte [esi]
|
||||||
|
or bx, TTY_COLOR ; create VGA character
|
||||||
|
|
||||||
|
mov [edi+eax], bx
|
||||||
|
inc esi
|
||||||
|
inc byte [vga_buf_pos_x]
|
||||||
|
|
||||||
|
|
||||||
|
dec ecx
|
||||||
|
jmp vga_puts.print_char ; loop until ECX == 0
|
||||||
|
|
||||||
|
.end_of_line:
|
||||||
|
; advance to next row
|
||||||
|
inc byte [vga_buf_pos_y]
|
||||||
|
mov byte [vga_buf_pos_x], 0
|
||||||
|
jmp vga_puts.print_char
|
||||||
|
.scroll_up:
|
||||||
|
; after 25 rows, move to next page (either swap pages [memcpy] or erase page 0)
|
||||||
|
mov byte [vga_buf_pos_x], 0
|
||||||
|
mov byte [vga_buf_pos_y], 0
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
|
||||||
|
mov eax, 0x7D0
|
||||||
|
push eax ; 1 VGA page = 0x7D0 elements
|
||||||
|
|
||||||
|
xor eax, eax
|
||||||
|
push eax ; we want to blank the page with 0x0000
|
||||||
|
|
||||||
|
mov eax, VGA_BUF
|
||||||
|
push eax ; load vga buffer base (0xb8000)
|
||||||
|
|
||||||
|
; uint16_t* kmemset_word(void* dest, uint16_t val, size_t len);
|
||||||
|
call kmemset_byte
|
||||||
|
leave
|
||||||
|
|
||||||
|
jmp vga_puts.print_char
|
||||||
|
|
||||||
|
.special_character_switch:
|
||||||
|
|
||||||
|
cmp byte[esi], 0xA
|
||||||
|
je vga_puts.handle_LF
|
||||||
|
|
||||||
|
cmp byte[esi], 0xD
|
||||||
|
je vga_puts.handle_CR
|
||||||
|
|
||||||
|
; Default case
|
||||||
|
.special_character_endp:
|
||||||
|
dec ecx
|
||||||
|
inc esi
|
||||||
|
|
||||||
|
jmp vga_puts.print_char
|
||||||
|
|
||||||
|
.handle_LF:
|
||||||
|
; advance to next row
|
||||||
|
inc byte [vga_buf_pos_y]
|
||||||
|
jmp vga_puts.special_character_endp
|
||||||
|
|
||||||
|
.handle_CR:
|
||||||
|
mov byte [vga_buf_pos_x], 0
|
||||||
|
jmp vga_puts.special_character_endp
|
||||||
|
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
pop ebx
|
||||||
|
pop esi
|
||||||
|
pop edi
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
; short vga_get_xy(void)
|
||||||
|
;
|
||||||
|
; INPUT:
|
||||||
|
;
|
||||||
|
; OUTPUT:
|
||||||
|
; EAX = xy_pos
|
||||||
|
; > x = xy_pos && 0xFF00
|
||||||
|
; y = xy_pos && 0x00FF
|
||||||
|
; 2 MSB of EAX are 0.
|
||||||
|
;
|
||||||
|
vga_get_xy:
|
||||||
|
.endf:
|
||||||
|
ret
|
||||||
|
|
||||||
|
; void vga_set_xy(short xy_pos)
|
||||||
|
; xy_pos is a byte packed word (16bit value), MSB is x, LSB is y
|
||||||
|
; => x = xy_pos && 0xFF00
|
||||||
|
; y = xy_pos && 0x00FF
|
||||||
|
;
|
||||||
|
; INPUT:
|
||||||
|
; xy_pos
|
||||||
|
;
|
||||||
|
; OUTPUT:
|
||||||
|
; NONE
|
||||||
|
;
|
||||||
|
vga_set_xy:
|
||||||
|
.endf:
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint16_t vga_calc_offset(uint8_t vga_pos_x, uint8_t vga_pos_y)
|
||||||
|
; VGA_OFFSET(x,y) == (((y*VGA_MAX_X) + x)*2)
|
||||||
|
vga_calc_offset:
|
||||||
|
xor eax, eax
|
||||||
|
xor edx, edx
|
||||||
|
|
||||||
|
mov edx, [ebp-4]
|
||||||
|
mov ax, VGA_MAX_X
|
||||||
|
mul dx ; DX:AX contains (y*VGA_MAX_X)
|
||||||
|
jc vga_calc_offset.artithmetic_error
|
||||||
|
|
||||||
|
mov edx, [ebp-8]
|
||||||
|
add ax, dx
|
||||||
|
jc vga_calc_offset.artithmetic_error
|
||||||
|
|
||||||
|
mov dx, 0x02
|
||||||
|
mul dx ; DX:AX contains (y*VGA_MAX_X) + x) * 2
|
||||||
|
jnc vga_calc_offset.endf
|
||||||
|
|
||||||
|
.artithmetic_error:
|
||||||
|
mov al, '3'
|
||||||
|
call error
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
; (e)AX contains the offset
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint32_t* kmemset(void* dest, uint32_t val, size_t len);
|
||||||
|
kmemset_dword:
|
||||||
|
push edi ; function uses edi, so save it.
|
||||||
|
; [ebp] = previous call frame
|
||||||
|
mov ecx, [ebp - 4] ; size_t len
|
||||||
|
|
||||||
|
mov eax, [ebp - 8] ; uint32_t val
|
||||||
|
|
||||||
|
mov edi, [ebp - 12] ; void * ptr
|
||||||
|
; [ebp - 16] = return adress
|
||||||
|
; [ebp - 20] = saved EDI
|
||||||
|
rep stosd
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp - 12] ; return pointer to dest
|
||||||
|
pop edi ; restore edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint16_t* kmemset(void* dest, uint16_t val, size_t len);
|
||||||
|
kmemset_word:
|
||||||
|
push edi ; function uses edi, so save it.
|
||||||
|
; [ebp] = previous call frame
|
||||||
|
mov ecx, [ebp - 4] ; size_t len
|
||||||
|
|
||||||
|
mov ax, [ebp - 8] ; uint16_t val
|
||||||
|
|
||||||
|
mov edi, [ebp - 12] ; void * ptr
|
||||||
|
; [ebp - 16] = return adress
|
||||||
|
; [ebp - 20] = saved EDI
|
||||||
|
rep stosw
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp - 12] ; return pointer to dest
|
||||||
|
pop edi ; restore edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||||
|
kmemset_byte:
|
||||||
|
push edi ; function uses edi, so save it.
|
||||||
|
; [ebp] = previous call frame
|
||||||
|
mov ecx, [ebp - 4] ; size_t len
|
||||||
|
|
||||||
|
mov al, [ebp - 8] ; uint8_t val
|
||||||
|
|
||||||
|
mov edi, [ebp - 12] ; void * ptr
|
||||||
|
; [ebp - 16] = return adress
|
||||||
|
; [ebp - 20] = saved EDI
|
||||||
|
rep stosb
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp - 12] ; return pointer to dest
|
||||||
|
pop edi ; restore edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint32_t* kmemset(uint32_t* dest, uint32_t* src, size_t len);
|
||||||
|
kmemcpy_dword:
|
||||||
|
push edi
|
||||||
|
push esi ; edi, esi are callee save
|
||||||
|
|
||||||
|
mov edi, [ebp-12] ; dest
|
||||||
|
mov esi, [ebp-8] ; source
|
||||||
|
mov ecx, [ebp-4] ; length
|
||||||
|
|
||||||
|
cld ; ensure we are incrementing
|
||||||
|
rep movsd
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp-12] ; return pointer to dest
|
||||||
|
pop esi
|
||||||
|
pop edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint16_t* kmemset(uint16_t* dest, uint16_t* src, size_t len);
|
||||||
|
kmemcpy_word:
|
||||||
|
push edi
|
||||||
|
push esi ; edi, esi are callee save
|
||||||
|
|
||||||
|
mov edi, [ebp-12] ; dest
|
||||||
|
mov esi, [ebp-8] ; source
|
||||||
|
mov ecx, [ebp-4] ; length
|
||||||
|
|
||||||
|
cld ; ensure we are incrementing
|
||||||
|
rep movsw
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp-12] ; return pointer to dest
|
||||||
|
pop esi
|
||||||
|
pop edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, size_t len);
|
||||||
|
; not overlap safe
|
||||||
|
kmemcpy_byte:
|
||||||
|
push edi
|
||||||
|
push esi ; edi, esi are callee save
|
||||||
|
|
||||||
|
mov edi, [ebp-12] ; dest
|
||||||
|
mov esi, [ebp-8] ; source
|
||||||
|
mov ecx, [ebp-4] ; length
|
||||||
|
|
||||||
|
cld ; ensure we are incrementing
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
.endf:
|
||||||
|
mov eax, [ebp-12] ; return pointer to dest
|
||||||
|
pop esi
|
||||||
|
pop edi
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Static Values
|
||||||
|
vga_buf_pos_x:
|
||||||
|
db 0x00
|
||||||
|
vga_buf_pos_y:
|
||||||
|
db 0x00
|
||||||
|
|
||||||
|
; Strings
|
||||||
|
%define StrCRLF_NUL 0Dh, 0Ah, 00h
|
||||||
|
welcome_cstr:
|
||||||
|
db 'CBoot Stage3', StrCRLF_NUL
|
||||||
|
version_cstr:
|
||||||
|
db 'CBoot v0.0.3 ', 'NASM - ', __NASM_VER__, StrCRLF_NUL
|
||||||
|
datetime_cstr:
|
||||||
|
db 'Assembled - ', __DATE__, ' ', __TIME__, StrCRLF_NUL
|
||||||
|
|
||||||
|
ALIGN 16, db 0
|
||||||
|
stack_bottom:
|
||||||
|
times (512 * 8) db 0x00 ; 4KiB stack
|
||||||
|
stack_top:
|
||||||
|
|
||||||
|
%assign bytes_remaining ((MAX_BYTES - 4) - ($ - $$))
|
||||||
|
%warning boot32 has bytes_remaining bytes remaining for code (MAX: MMAX_BYTES)
|
||||||
|
|
||||||
|
times ((MAX_BYTES - 4) - ($ - $$)) db 0xFE
|
||||||
|
BOOT_SIG: dd 0xA0B0C0D0
|
||||||
1182
src/stage2/stage2.s
Executable file
1182
src/stage2/stage2.s
Executable file
File diff suppressed because it is too large
Load Diff
219
src/vbr/vbr.s
Executable file
219
src/vbr/vbr.s
Executable file
@@ -0,0 +1,219 @@
|
|||||||
|
; Copyright (C) 2020 Bradley Claus
|
||||||
|
;
|
||||||
|
; 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[BITS 16]
|
||||||
|
[ORG 0x7C00]
|
||||||
|
[CPU KATMAI]
|
||||||
|
jmp short init
|
||||||
|
nop
|
||||||
|
|
||||||
|
bpb_start:
|
||||||
|
; fill BPB area with 0x00 since we skip writing this part to disk
|
||||||
|
; but we need it for the 'jmp short entry; nop' above
|
||||||
|
times 33 db 0x00
|
||||||
|
|
||||||
|
ebpb_start:
|
||||||
|
; fill BPB area with 0x00 since we skip writing this part to disk
|
||||||
|
; but we need it for the 'jmp short entry; nop' above
|
||||||
|
times 54 db 0x00
|
||||||
|
|
||||||
|
%include "entry.inc"
|
||||||
|
init:
|
||||||
|
cli ; We do not want to be interrupted
|
||||||
|
|
||||||
|
xor ax, ax ; 0 AX
|
||||||
|
mov ds, ax ; Set segment registers to 0
|
||||||
|
mov es, ax ; *
|
||||||
|
|
||||||
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
|
mov sp, STACK_START ; Setup stack
|
||||||
|
mov bp, sp ; base ptr = stack ptr
|
||||||
|
|
||||||
|
mov bx, VBR_ENTRY ; move BP to the new start of the initial boot sector
|
||||||
|
|
||||||
|
jmp 0:main ; fix up cs:ip just in case and jump to relocated code
|
||||||
|
|
||||||
|
%include "config.inc"
|
||||||
|
%include "errors.inc"
|
||||||
|
%include "memory.inc"
|
||||||
|
|
||||||
|
%include "partition_table.inc"
|
||||||
|
|
||||||
|
%include "fat32/bpb.inc"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
sti ; all done with inital setup and relocation, reenable interupts
|
||||||
|
mov [bsDriveNumber], dl ; BIOS passes drive number in DL
|
||||||
|
mov [partition_offset], si ; save passed partition entry offset
|
||||||
|
|
||||||
|
.check_FAT_size:
|
||||||
|
cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16
|
||||||
|
ja main.load_stage2
|
||||||
|
|
||||||
|
ERROR VBR_ERROR_WRONG_FAT_SIZE
|
||||||
|
|
||||||
|
; read sectors 1-63 to stage2 entry point
|
||||||
|
.load_stage2:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
;uint8_t read_disk_raw(size_t count, uint16_t buf_segment, uint16_t buf_offset,
|
||||||
|
; uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
push ax ; upper_lower_lba = 0
|
||||||
|
|
||||||
|
mov ax , 1
|
||||||
|
push ax ; lower_lower_lba = 1
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
push ax ; offset = 0
|
||||||
|
|
||||||
|
; 07E0:0
|
||||||
|
mov ax, STAGE2_ENTRY
|
||||||
|
shr ax, 4
|
||||||
|
push ax ; segment = 7E0
|
||||||
|
|
||||||
|
mov ax, STAGE2_SECTOR_COUNT
|
||||||
|
push ax
|
||||||
|
|
||||||
|
call read_disk_raw
|
||||||
|
leave
|
||||||
|
|
||||||
|
.check_sig:
|
||||||
|
mov ax, 0x7E0
|
||||||
|
mov fs, ax
|
||||||
|
cmp dword [fs:0x7FFC], 0xDEADBEEF
|
||||||
|
je main.sig_ok
|
||||||
|
|
||||||
|
ERROR VBR_ERROR_NO_SIGNATURE ; no signature present in stage2
|
||||||
|
|
||||||
|
.sig_ok:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
mov ax, fat32_bpb_SIZE ; size in byte
|
||||||
|
push ax
|
||||||
|
mov ax, bpb_start ; start of bpb
|
||||||
|
push ax
|
||||||
|
mov ax, fat32_bpb ; defined in memory.inc, destination
|
||||||
|
push ax
|
||||||
|
call kmemcpy ; copy bpb to memory
|
||||||
|
leave
|
||||||
|
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
mov ax, fat32_ebpb_SIZE ; 72 bytes of data
|
||||||
|
push ax
|
||||||
|
mov ax, ebpb_start ; start of ebpb
|
||||||
|
push ax
|
||||||
|
mov ax, fat32_ebpb ; defined in memory.inc, destination
|
||||||
|
push ax
|
||||||
|
call kmemcpy ; copy ebpb to memory
|
||||||
|
leave
|
||||||
|
|
||||||
|
mov si, [partition_offset]
|
||||||
|
mov dl, [bsDriveNumber]
|
||||||
|
jmp 0:0x7E00
|
||||||
|
|
||||||
|
stop:
|
||||||
|
hlt
|
||||||
|
jmp short stop
|
||||||
|
|
||||||
|
; Wrapper for AH=0x42 INT13h (Extended Read)
|
||||||
|
;
|
||||||
|
; BIOS call details
|
||||||
|
; AH = 42h
|
||||||
|
; DL = drive number
|
||||||
|
; DS:SI -> disk address packet
|
||||||
|
;
|
||||||
|
; Return:
|
||||||
|
; CF clear if successful
|
||||||
|
; AH = 00h
|
||||||
|
; CF set on error
|
||||||
|
; AH = error code
|
||||||
|
; disk address packet's block count field set to number of blocks
|
||||||
|
; successfully transferred
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
||||||
|
; bp-0 = call frame
|
||||||
|
; bp-2 = upper_lower_lba
|
||||||
|
; bp-4 = lower_lower_lba
|
||||||
|
; bp-6 = offset
|
||||||
|
; bp-8 = segment
|
||||||
|
; bp-10 = count
|
||||||
|
; bp-12 = ret ptr
|
||||||
|
read_disk_raw:
|
||||||
|
push si
|
||||||
|
|
||||||
|
; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
mov ax, 0x10
|
||||||
|
push ax ; len = 16 bytes
|
||||||
|
xor ax, ax
|
||||||
|
push ax ; val = 0
|
||||||
|
mov ax, lba_packet
|
||||||
|
push ax ; dest = lba_packet address
|
||||||
|
|
||||||
|
call kmemset
|
||||||
|
leave
|
||||||
|
|
||||||
|
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
||||||
|
mov word [lba_packet + LBAPkt_t.xfer_size], STAGE2_SECTOR_COUNT
|
||||||
|
|
||||||
|
mov ax, [bp-2]
|
||||||
|
shl eax, 16
|
||||||
|
mov ax, [bp-4]
|
||||||
|
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
||||||
|
|
||||||
|
mov ax, [bp-6]
|
||||||
|
mov word [lba_packet + LBAPkt_t.offset], ax
|
||||||
|
|
||||||
|
mov ax, [bp-8]
|
||||||
|
mov word [lba_packet + LBAPkt_t.segment], ax
|
||||||
|
|
||||||
|
mov si, lba_packet
|
||||||
|
mov ah, 0x42
|
||||||
|
mov dl, byte [bsDriveNumber]
|
||||||
|
int 0x13
|
||||||
|
jnc read_disk_raw.endf
|
||||||
|
|
||||||
|
ERROR VBR_ERROR_DISK_READ_ERR
|
||||||
|
.endf:
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
; Data
|
||||||
|
|
||||||
|
; #############
|
||||||
|
;
|
||||||
|
; Locals
|
||||||
|
;
|
||||||
|
; #############
|
||||||
|
|
||||||
|
; offset from the begining of sector 0 to the active partition.
|
||||||
|
partition_offset:
|
||||||
|
dw 0x0000
|
||||||
|
|
||||||
|
%assign bytes_remaining (420 - ($ - $$))
|
||||||
|
%warning VBR has bytes_remaining bytes remaining for code (MAX: 420 bytes)
|
||||||
|
|
||||||
|
times (510 - ($ - $$)) nop ; Fill the rest of sector with nop
|
||||||
|
|
||||||
|
BootSig:
|
||||||
|
dw 0xAA55 ; Add boot signature at the end of bootloader
|
||||||
Reference in New Issue
Block a user