Compare commits

...

1 Commits

Author SHA1 Message Date
The ReactOS Team
17319a2af5 This commit was manufactured by cvs2svn to create branch 'ROS'.
svn path=/branches/ROS/; revision=3070
2002-06-13 20:37:16 +00:00
4604 changed files with 0 additions and 1073812 deletions

View File

@@ -1,50 +0,0 @@
Changes in v1.3.1 (6/8/2002)
- Implemented MmAllocateMemoryAtAddress()
- Fixed Linux boot code to go through the memory manager to allocate memory at 1MB
Changes in v1.3 (6/5/2002)
- Added protected mode exception handling in case FreeLoader crashes
- Reworked memory manager to use all of extended memory
- Reworked UI code, now supports multiple text-mode resolutions
Changes in v1.2.2 (5/4/2002)
- Fixed memory leak in menu.c
Changes in v1.2.1 (5/3/2002)
- Makefile updates
- Optimized the Makefile
- Removed recursive make functionality (builds much faster now)
- Places all output into one single directory
- Added automagically generated dependencies
Changes in v1.2 (4/30/2002)
- All Linux kernels are supported (zImage & bzImage, loaded high & low)
- Initrd support
- FreeLoader now compiles under Mingw32 instead of just DJGPP, but
the Mingw32 linker seems to output a corrupt binary.
Changes in v1.01 (4/28/2002)
- Fixed FAT short file name buffer overflow that was causing
some long filenames not to work correctly.
Changes in v1.0 (4/24/2002)
- FreeLoader version 1.0!
- Supports booting ReactOS
- Supports booting Linux bzImage kernels
- No initrd support (yet)
- No zImage support (yet)
- No ext2 file system support (yet)
- Supports FAT & ISO-9660 file systems
- Forward slashes '/' as well as backslashes '\' can be used
for path names in FAT & ISO-9600
- Fixed bug in LBA code where it was only reading one sector
even if you asked for more
- Fixed bug in FAT code, was also present in ISO-9660 code where
it wasn't incrementing the buffer address correctly

View File

@@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@@ -1,176 +0,0 @@
; FreeLoader by Brian Palmer
; FREELDR.INI - FreeLoader Initialization file
;
; Each line must be less than 1024 characters long
; and must be either a section heading (i.e. [section_name])
; or a setting (i.e. name=value) or a blank line.
; Comments start with a ';' character.
; Background colors can be any one of the following:
; Black
; Blue
; Green
; Cyan
; Red
; Magenta
; Brown
; Gray
; Text colors can be any one of the background
; colors and any of the following:
; DarkGray
; LightBlue
; LightGreen
; LightCyan
; LightRed
; LightMagenta
; Yellow
; White
; [FREELOADER] Section Commands:
;
; MessageBox - displays the specified text in a message box upon bootup
; MessageLine - adds a new line of text to a message box (must come before MessageBox command)
; TitleText - text that is displayed in the title box
; StatusBarColor - color of status bar's background
; StatusBarTextColor - color of status bar's text
; BackdropTextColor - color of the backdrop's fill
; BackdropColor - color of the backdrop's background
; BackdropFillStyle - backdrop fill style - can be Light, Medium, or Dark
; TitleBoxTextColor - title box text color
; TitleBoxColor - title box background color
; MessageBoxTextColor - message box text color
; MessageBoxColor - message box background color
; MenuTextColor - menu text color
; MenuColor - menu color
; TextColor - normal text color
; SelectedTextColor - selected text color
; SelectedColor - selected text background color
; TimeOut - sets the timeout (in seconds) before the first OS listed gets booted automagically
; [OS-General] Section Commands:
;
; BootType - sets the boot type: ReactOS, Linux, BootSector, Partition, Drive
; BootDrive - sets the boot drive: 0 - first floppy, 1 - second floppy, 0x80 - first hard disk, 0x81 - second hard disk
; BootPartition - sets the boot partition
; [BootSector OSType] Section Commands:
;
; BootSector - sets the filename of the bootsector to be loaded
; [ReactOS OSType] Section Commands:
;
; SystemPath - sets the system root path (must be a valid ARC - Path):
; multi(0)disk(0)rdisk(0)partition(1)\reactos
; multi(0)disk(0)fdisk(0)
; Options - sets the command line options for the kernel being booted
; Kernel - sets the kernel filename
; Driver - sets the name of one or more drivers to be loaded (one entry per driver)
[FREELOADER]
MessageLine=Welcome to FreeLoader!
MessageLine=Copyright (c) 2002 by Brian Palmer <brianp@sginet.com>
MessageLine=
MessageBox=Edit your FREELDR.INI file to change your boot settings.
OS=ReactOS (HD)
OS=ReactOS (Floppy)
;OS=ReactOS (Debug)
OS=Linux
OS=LinuxInitrd
OS=3<> Floppy (A:)
OS=Microsoft Windows (C:)
OS=Drive D:
DefaultOS=ReactOS (Floppy)
TimeOut=10
; DisplayMode can be:
; NORMAL_VGA for 80x25
; EXTENDED_VGA for 80x50 on VGA 80x43 on EGA
; 0x501C for 80x28
; 0x501E for 80x30
; 0x5022 for 80x34
; 0x502B for 80x43
; 0x503C for 80x60
[Display]
DisplayMode=NORMAL_VGA
TitleText=Boot Menu
StatusBarColor=Cyan
StatusBarTextColor=Black
BackdropTextColor=White
BackdropColor=Blue
BackdropFillStyle=Medium
TitleBoxTextColor=White
TitleBoxColor=Red
MessageBoxTextColor=White
MessageBoxColor=Blue
MenuTextColor=White
MenuColor=Blue
TextColor=Yellow
SelectedTextColor=Black
SelectedColor=Gray
; Load ReactOS from harddisk (drive C:)
[ReactOS (HD)]
Name="ReactOS (HardDrive)"
BootType=ReactOS
SystemPath=multi(0)disk(0)rdisk(0)partition(1)\reactos
Options=/DEBUGPORT=SCREEN
Kernel=\REACTOS\SYSTEM32\NTOSKRNL.EXE
Hal=\REACTOS\SYSTEM32\HAL.DLL
Driver=\REACTOS\SYSTEM32\DRIVERS\IDE.SYS
Driver=\REACTOS\SYSTEM32\DRIVERS\VFATFS.SYS
; Load ReactOS from floppy (drive A:)
[ReactOS (Floppy)]
Name="ReactOS (Floppy)"
BootType=ReactOS
SystemPath=multi(0)disk(0)fdisk(0)
Options=/DEBUGPORT=SCREEN
Kernel=\reactos\NTOSKRNL.EXE
Hal=\reactos\HAL.DLL
Driver=\reactos\IDE.SYS
Driver=\reactos\VFATFS.SYS
;[ReactOS (Debug)]
;Name="ReactOS (Debug)"
;BootType=ReactOS
;BootDrive=0
;Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=19200
;Kernel=\NTOSKRNL.EXE
;Hal=\HAL.DLL
;Driver=\DRIVERS\IDE.SYS
;Driver=\DRIVERS\VFATFS.SYS
[Linux]
Name="Debian Linux 2.2.17"
BootType=Linux
BootDrive=0
Kernel=/vmlinuz
CommandLine="root=/dev/sdb1"
[Linux]
Name="Linux w/Initrd"
BootType=Linux
BootDrive=0x80
BootPartition=1
Kernel=/vmlinuz
Initrd=/initrd.gz
CommandLine=
[3<> Floppy (A:)]
Name="3<> Floppy (A:)"
BootType=Drive
BootDrive=0
[Microsoft Windows (C:)]
Name="Microsoft Windows (C:)"
BootType=Drive
BootDrive=0x80
[Drive D:]
Name="Drive D:"
BootType=Partition
BootDrive=0x81
BootPartition=1

View File

@@ -1,3 +0,0 @@
*.exe
*.bin
*.h

View File

@@ -1,50 +0,0 @@
#
# FreeLoader
# Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
RM = cmd /C del
NASM_CMD = nasm
BIN2C = ../tools/bin2c
TOOLSDIR = ../tools
.PHONY : clean
all: $(BIN2C) fat.bin fat32.bin isoboot.bin
$(BIN2C) :
@$(MAKE) --no-print-directory -C $(TOOLSDIR)
fat.bin : fat.asm $(BIN2C)
@echo ===================================================== Assembling fat
@$(NASM_CMD) -o fat.bin -f bin fat.asm
@$(BIN2C) fat.bin fat.h fat_data
fat32.bin : fat32.asm $(BIN2C)
@echo ===================================================== Assembling fat32
@$(NASM_CMD) -o fat32.bin -f bin fat32.asm
@$(BIN2C) fat32.bin fat32.h fat32_data
isoboot.bin : isoboot.asm
@echo ===================================================== Assembling isoboot
@$(NASM_CMD) -o isoboot.bin -f bin isoboot.asm
clean:
@-$(RM) *.bin
@-$(RM) *.h
@echo Clean ALL done.

View File

@@ -1,380 +0,0 @@
; FAT.ASM
; FAT12/16 Boot Sector
; Copyright (c) 1998, 2001, 2002 Brian Palmer
; This is a FAT12/16 file system boot sector
; that searches the entire root directory
; for the file freeldr.sys and loads it into
; memory.
;
; The stack is set to 0000:7BF2 so that the first
; WORD pushed will be placed at 0000:7BF0
;
; The DWORD at 0000:7BFC or BP-04h is the logical
; sector number of the start of the data area.
;
; The DWORD at 0000:7BF8 or BP-08h is the total
; sector count of the boot drive as reported by
; the computers bios.
;
; The WORD at 0000:7BF6 or BP-0ah is the offset
; of the ReadSectors function in the boot sector.
;
; The WORD at 0000:7BF4 or BP-0ch is the offset
; of the ReadCluster function in the boot sector.
;
; The WORD at 0000:7BF2 or BP-0eh is the offset
; of the PutChars function in the boot sector.
;
; When it locates freeldr.sys on the disk it will
; load the first sector of the file to 0000:8000
; With the help of this sector we should be able
; to load the entire file off the disk, no matter
; how fragmented it is.
;
; We load the entire FAT table into memory at
; 7000:0000. This improves the speed of floppy disk
; boots dramatically.
BootSectorStackTop equ 0x7bf2
DataAreaStartHigh equ 0x2
DataAreaStartLow equ 0x4
BiosCHSDriveSize equ 0x6
BiosCHSDriveSizeHigh equ 0x6
BiosCHSDriveSizeLow equ 0x8
ReadSectorsOffset equ 0xa
ReadClusterOffset equ 0xc
PutCharsOffset equ 0xe
org 7c00h
segment .text
bits 16
start:
jmp short main
nop
OEMName db 'FrLdr1.0'
BytesPerSector dw 512
SectsPerCluster db 1
ReservedSectors dw 1
NumberOfFats db 2
MaxRootEntries dw 224
TotalSectors dw 2880
MediaDescriptor db 0f0h
SectorsPerFat dw 9
SectorsPerTrack dw 18
NumberOfHeads dw 2
HiddenSectors dd 0
TotalSectorsBig dd 0
BootDrive db 0
Reserved db 0
ExtendSig db 29h
SerialNumber dd 00000000h
VolumeLabel db 'NO NAME '
FileSystem db 'FAT12 '
main:
xor ax,ax
mov ss,ax
mov bp,7c00h
mov sp,BootSectorStackTop ; Setup a stack
mov ds,ax ; Make DS correct
mov es,ax ; Make ES correct
mov [BYTE bp+BootDrive],dl ; Save the boot drive
GetDriveParameters:
mov ah,08h
mov dl,[BYTE bp+BootDrive] ; Get boot drive in dl
int 13h ; Request drive parameters from the bios
jnc CalcDriveSize ; If the call succeeded then calculate the drive size
; If we get here then the call to the BIOS failed
; so just set CHS equal to the maximum addressable
; size
mov cx,0ffffh
mov dh,cl
CalcDriveSize:
; Now that we have the drive geometry
; lets calculate the drive size
mov bl,ch ; Put the low 8-bits of the cylinder count into BL
mov bh,cl ; Put the high 2-bits in BH
shr bh,6 ; Shift them into position, now BX contains the cylinder count
and cl,3fh ; Mask off cylinder bits from sector count
; CL now contains sectors per track and DH contains head count
movzx eax,dh ; Move the heads into EAX
movzx ebx,bx ; Move the cylinders into EBX
movzx ecx,cl ; Move the sectors per track into ECX
inc eax ; Make it one based because the bios returns it zero based
inc ebx ; Make the cylinder count one based also
mul ecx ; Multiply heads with the sectors per track, result in edx:eax
mul ebx ; Multiply the cylinders with (heads * sectors) [stored in edx:eax already]
; We now have the total number of sectors as reported
; by the bios in eax, so store it in our variable
mov [BYTE bp-BiosCHSDriveSize],eax
; Now we must find our way to the first sector of the root directory
xor ax,ax
xor cx,cx
mov al,[BYTE bp+NumberOfFats] ; Number of fats
mul WORD [BYTE bp+SectorsPerFat] ; Times sectors per fat
add ax,WORD [BYTE bp+HiddenSectors]
adc dx,WORD [BYTE bp+HiddenSectors+2] ; Add the number of hidden sectors
add ax,WORD [BYTE bp+ReservedSectors] ; Add the number of reserved sectors
adc dx,cx ; Add carry bit
mov WORD [BYTE bp-DataAreaStartLow],ax ; Save the starting sector of the root directory
mov WORD [BYTE bp-DataAreaStartHigh],dx ; Save it in the first 4 bytes before the boot sector
mov si,WORD [BYTE bp+MaxRootEntries] ; Get number of root dir entries in SI
pusha ; Save 32-bit logical start sector of root dir
; DX:AX now has the number of the starting sector of the root directory
; Now calculate the size of the root directory
mov ax,0020h ; Size of dir entry
mul si ; Times the number of entries
mov bx,[BYTE bp+BytesPerSector]
add ax,bx
dec ax
div bx ; Divided by the size of a sector
; AX now has the number of root directory sectors
add [BYTE bp-DataAreaStartLow],ax ; Add the number of sectors of the root directory to our other value
adc [BYTE bp-DataAreaStartHigh],cx ; Now the first 4 bytes before the boot sector contain the starting sector of the data area
popa ; Restore root dir logical sector start to DX:AX
LoadRootDirSector:
mov bx,7e0h ; We will load the root directory sector
mov es,bx ; Right after the boot sector in memory
xor bx,bx ; We will load it to [0000:7e00h]
xor cx,cx ; Zero out CX
inc cx ; Now increment it to 1, we are reading one sector
xor di,di ; Zero out di
push es ; Save ES because it will get incremented by 20h
call ReadSectors ; Read the first sector of the root directory
pop es ; Restore ES (ES:DI = 07E0:0000)
SearchRootDirSector:
cmp [es:di],ch ; If the first byte of the directory entry is zero then we have
jz ErrBoot ; reached the end of the directory and FREELDR.SYS is not here so reboot
pusha ; Save all registers
mov cl,0xb ; Put 11 in cl (length of filename in directory entry)
mov si,filename ; Put offset of filename string in DS:SI
repe cmpsb ; Compare this directory entry against 'FREELDR SYS'
popa ; Restore all the registers
jz FoundFreeLoader ; If we found it then jump
dec si ; SI holds MaxRootEntries, subtract one
jz ErrBoot ; If we are out of root dir entries then reboot
add di,BYTE +0x20 ; Increment DI by the size of a directory entry
cmp di,0200h ; Compare DI to 512 (DI has offset to next dir entry, make sure we haven't gone over one sector)
jc SearchRootDirSector ; If DI is less than 512 loop again
jmp short LoadRootDirSector ; Didn't find FREELDR.SYS in this directory sector, try again
FoundFreeLoader:
; We found freeldr.sys on the disk
; so we need to load the first 512
; bytes of it to 0000:8000
; ES:DI has dir entry (ES:DI == 07E0:XXXX)
mov ax,WORD [es:di+1ah] ; Get start cluster
push ax ; Save start cluster
push WORD 800h ; Put 800h on the stack and load it
pop es ; Into ES so that we load the cluster at 0000:8000
call ReadCluster ; Read the cluster
pop ax ; Restore start cluster of FreeLoader
; Save the addresses of needed functions so
; the helper code will know where to call them.
mov WORD [BYTE bp-ReadSectorsOffset],ReadSectors ; Save the address of ReadSectors
mov WORD [BYTE bp-ReadClusterOffset],ReadCluster ; Save the address of ReadCluster
mov WORD [BYTE bp-PutCharsOffset],PutChars ; Save the address of PutChars
; Now AX has start cluster of FreeLoader and we
; have loaded the helper code in the first 512 bytes
; of FreeLoader to 0000:8000. Now transfer control
; to the helper code. Skip the first three bytes
; because they contain a jump instruction to skip
; over the helper code in the FreeLoader image.
;jmp 0000:8003h
jmp 8003h
; Reads cluster number in AX into [ES:0000]
ReadCluster:
; StartSector = ((Cluster - 2) * SectorsPerCluster) + ReservedSectors + HiddenSectors;
dec ax ; Adjust start cluster by 2
dec ax ; Because the data area starts on cluster 2
xor ch,ch
mov cl,BYTE [BYTE bp+SectsPerCluster]
mul cx ; Times sectors per cluster
add ax,[BYTE bp-DataAreaStartLow] ; Add start of data area
adc dx,[BYTE bp-DataAreaStartHigh] ; Now we have DX:AX with the logical start sector of OSLOADER.SYS
xor bx,bx ; We will load it to [ES:0000], ES loaded before function call
mov cl,BYTE [BYTE bp+SectsPerCluster]
call ReadSectors
ret
; Displays an error message
; And reboots
ErrBoot:
mov si,msgFreeLdr ; FreeLdr not found message
call PutChars ; Display it
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
Reboot:
xor ax,ax
int 16h ; Wait for a keypress
int 19h ; Reboot
PutChars:
lodsb
or al,al
jz short Done
mov ah,0eh
mov bx,07h
int 10h
jmp short PutChars
Done:
retn
; Displays a bad boot message
; And reboots
BadBoot:
mov si,msgDiskError ; Bad boot disk message
call PutChars ; Display it
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
jmp short Reboot
; Reads logical sectors into [ES:BX]
; DX:AX has logical sector number to read
; CX has number of sectors to read
ReadSectors:
cmp dx,WORD [BYTE bp-BiosCHSDriveSizeHigh]; Check if they are reading a sector within CHS range
jb ReadSectorsCHS ; Yes - go to the old CHS routine
cmp ax,WORD [BYTE bp-BiosCHSDriveSizeLow]; Check if they are reading a sector within CHS range
jbe ReadSectorsCHS ; Yes - go to the old CHS routine
ReadSectorsLBA:
pushad ; Save logical sector number & sector count
o32 push byte 0
push dx ; Put 64-bit logical
push ax ; block address on stack
push es ; Put transfer segment on stack
push bx ; Put transfer offset on stack
push byte 1 ; Set transfer count to 1 sector
push byte 0x10 ; Set size of packet to 10h
mov si,sp ; Setup disk address packet on stack
; We are so totally out of space here that I am forced to
; comment out this very beautifully written piece of code
; It would have been nice to have had this check...
;CheckInt13hExtensions: ; Now make sure this computer supports extended reads
; mov ah,0x41 ; AH = 41h
; mov bx,0x55aa ; BX = 55AAh
; mov dl,[BYTE bp+BootDrive] ; DL = drive (80h-FFh)
; int 13h ; IBM/MS INT 13 Extensions - INSTALLATION CHECK
; jc PrintDiskError ; CF set on error (extensions not supported)
; cmp bx,0xaa55 ; BX = AA55h if installed
; jne PrintDiskError
; test cl,1 ; CX = API subset support bitmap
; jz PrintDiskError ; Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
; Good, we're here so the computer supports LBA disk access
; So finish the extended read
mov dl,[BYTE bp+BootDrive] ; Drive number
mov ah,42h ; Int 13h, AH = 42h - Extended Read
int 13h ; Call BIOS
jc BadBoot ; If the read failed then abort
add sp,0x10 ; Remove disk address packet from stack
popad ; Restore sector count & logical sector number
inc ax ; Increment Sector to Read
jnz NoCarry
inc dx
NoCarry:
mov dx,es
add dx,byte 20h ; Increment read buffer for next sector
mov es,dx
loop ReadSectorsLBA ; Read next sector
ret
; Reads logical sectors into [ES:BX]
; DX:AX has logical sector number to read
; CX has number of sectors to read
; CarryFlag set on error
ReadSectorsCHS:
pushad
xchg ax,cx
xchg ax,dx
xor dx,dx
div WORD [BYTE bp+SectorsPerTrack]
xchg ax,cx
div WORD [BYTE bp+SectorsPerTrack] ; Divide logical by SectorsPerTrack
inc dx ; Sectors numbering starts at 1 not 0
xchg cx,dx
div WORD [BYTE bp+NumberOfHeads] ; Number of heads
mov dh,dl ; Head to DH, drive to DL
mov dl,[BYTE bp+BootDrive] ; Drive number
mov ch,al ; Cylinder in CX
ror ah,1 ; Low 8 bits of cylinder in CH, high 2 bits
ror ah,1 ; in CL shifted to bits 6 & 7
or cl,ah ; Or with sector number
mov ax,0201h
int 13h ; DISK - READ SECTORS INTO MEMORY
; AL = number of sectors to read, CH = track, CL = sector
; DH = head, DL = drive, ES:BX -> buffer to fill
; Return: CF set on error, AH = status (see AH=01h), AL = number of sectors read
jc BadBoot
popad
inc ax ;Increment Sector to Read
jnz NoCarryCHS
inc dx
NoCarryCHS:
push bx
mov bx,es
add bx,byte 20h
mov es,bx
pop bx
; Increment read buffer for next sector
loop ReadSectorsCHS ; Read next sector
ret
msgDiskError db 'Disk error',0dh,0ah,0
msgFreeLdr db 'FREELDR.SYS not found',0dh,0ah,0
; Sorry, need the space...
;msgAnyKey db 'Press any key to restart',0dh,0ah,0
msgAnyKey db 'Press any key',0dh,0ah,0
filename db 'FREELDR SYS'
times 510-($-$$) db 0 ; Pad to 510 bytes
dw 0aa55h ; BootSector signature

View File

@@ -1,494 +0,0 @@
; FAT32.ASM
; FAT32 Boot Sector
; Copyright (c) 1998, 2000, 2001, 2002 Brian Palmer
org 7c00h
segment .text
bits 16
start:
jmp short main
nop
OEMName db 'FrLdr1.0'
BytesPerSector dw 512
SectsPerCluster db 0
ReservedSectors dw 32
NumberOfFats db 2
MaxRootEntries dw 0 ; Always zero for FAT32 volumes
TotalSectors dw 0 ; Always zero for FAT32 volumes
MediaDescriptor db 0f8h
SectorsPerFat dw 0 ; Always zero for FAT32 volumes
SectorsPerTrack dw 0
NumberOfHeads dw 0
HiddenSectors dd 0
TotalSectorsBig dd 0
; FAT32 Inserted Info
SectorsPerFatBig dd 0
ExtendedFlags dw 0
FSVersion dw 0
RootDirStartCluster dd 0
FSInfoSector dw 0
BackupBootSector dw 6
Reserved1 times 12 db 0
; End FAT32 Inserted Info
BootDrive db 0
Reserved db 0
ExtendSig db 29h
SerialNumber dd 00000000h
VolumeLabel db 'NO NAME '
FileSystem db 'FAT32 '
main:
xor ax,ax ; Setup segment registers
mov ds,ax ; Make DS correct
mov es,ax ; Make ES correct
mov ss,ax ; Make SS correct
mov bp,7c00h
mov sp,7c00h ; Setup a stack
CheckSectorsPerFat:
cmp WORD [BYTE bp+SectorsPerFat],byte 0x00 ; Check the old 16-bit value of SectorsPerFat
jnz CheckFailed ; If it is non-zero then exit with an error
CheckTotalSectors: ; Check the old 16-bit value of TotalSectors & MaxRootEntries
cmp DWORD [BYTE bp+MaxRootEntries],byte 0x00; by comparing the DWORD at offset MaxRootEntries to zero
jnz CheckFailed ; If it is non-zero then exit with an error
CheckFileSystemVersion:
cmp WORD [BYTE bp+FSVersion],byte 0x00 ; Check the file system version word
jna GetDriveParameters ; It is zero, so continue
CheckFailed:
jmp PrintFileSystemError ; If it is not zero then exit with an error
GetDriveParameters:
mov ax,0800h
mov dl,[BYTE bp+BootDrive] ; Get boot drive in dl
int 13h ; Request drive parameters from the bios
jnc CalcDriveSize ; If the call succeeded then calculate the drive size
; If we get here then the call to the BIOS failed
; so just set CHS equal to the maximum addressable
; size
mov cx,0ffffh
mov dh,cl
CalcDriveSize:
; Now that we have the drive geometry
; lets calculate the drive size
mov bl,ch ; Put the low 8-bits of the cylinder count into BL
mov bh,cl ; Put the high 2-bits in BH
shr bh,6 ; Shift them into position, now BX contains the cylinder count
and cl,3fh ; Mask off cylinder bits from sector count
; CL now contains sectors per track and DH contains head count
movzx eax,dh ; Move the heads into EAX
movzx ebx,bx ; Move the cylinders into EBX
movzx ecx,cl ; Move the sectors per track into ECX
inc eax ; Make it one based because the bios returns it zero based
inc ebx ; Make the cylinder count one based also
mul ecx ; Multiply heads with the sectors per track, result in edx:eax
mul ebx ; Multiply the cylinders with (heads * sectors) [stored in edx:eax already]
; We now have the total number of sectors as reported
; by the bios in eax, so store it in our variable
mov [BiosCHSDriveSize],eax
LoadExtraBootCode:
; First we have to load our extra boot code at
; sector 14 into memory at [0000:7e00h]
mov eax,0eh
add eax,DWORD [BYTE bp+HiddenSectors] ; Add the number of hidden sectors
mov cx,1
xor bx,bx
mov es,bx ; Read sector to [0000:7e00h]
mov bx,7e00h
call ReadSectors
jmp StartSearch
; Reads logical sectors into [ES:BX]
; EAX has logical sector number to read
; CX has number of sectors to read
ReadSectors:
cmp eax,DWORD [BiosCHSDriveSize] ; Check if they are reading a sector outside CHS range
jae ReadSectorsLBA ; Yes - go to the LBA routine
; If at all possible we want to use LBA routines because
; They are optimized to read more than 1 sector per read
pushad ; Save logical sector number & sector count
CheckInt13hExtensions: ; Now check if this computer supports extended reads
mov ah,0x41 ; AH = 41h
mov bx,0x55aa ; BX = 55AAh
mov dl,[BYTE bp+BootDrive] ; DL = drive (80h-FFh)
int 13h ; IBM/MS INT 13 Extensions - INSTALLATION CHECK
jc ReadSectorsCHS ; CF set on error (extensions not supported)
cmp bx,0xaa55 ; BX = AA55h if installed
jne ReadSectorsCHS
test cl,1 ; CX = API subset support bitmap
jz ReadSectorsCHS ; Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
popad ; Restore sector count & logical sector number
ReadSectorsLBA:
pushad ; Save logical sector number & sector count
cmp cx,64 ; Since the LBA calls only support 0x7F sectors at a time we will limit ourselves to 64
jbe ReadSectorsSetupDiskAddressPacket ; If we are reading less than 65 sectors then just do the read
mov cx,64 ; Otherwise read only 64 sectors on this loop iteration
ReadSectorsSetupDiskAddressPacket:
mov [LBASectorsRead],cx
o32 push byte 0
push eax ; Put 64-bit logical block address on stack
push es ; Put transfer segment on stack
push bx ; Put transfer offset on stack
push cx ; Set transfer count
push byte 0x10 ; Set size of packet to 10h
mov si,sp ; Setup disk address packet on stack
mov dl,[BYTE bp+BootDrive] ; Drive number
mov ah,42h ; Int 13h, AH = 42h - Extended Read
int 13h ; Call BIOS
jc PrintDiskError ; If the read failed then abort
add sp,0x10 ; Remove disk address packet from stack
popad ; Restore sector count & logical sector number
movzx ebx,WORD [LBASectorsRead]
add eax,ebx ; Increment sector to read
shr ebx,4
mov dx,es
add dx,bx ; Setup read buffer for next sector
mov es,dx
xor bx,bx
sub cx,[LBASectorsRead]
jnz ReadSectorsLBA ; Read next sector
ret
LBASectorsRead:
dw 0
; Reads logical sectors into [ES:BX]
; EAX has logical sector number to read
; CX has number of sectors to read
ReadSectorsCHS:
popad ; Get logical sector number & sector count off stack
ReadSectorsCHSLoop:
pushad
xor edx,edx
movzx ecx,WORD [BYTE bp+SectorsPerTrack]
div ecx ; Divide logical by SectorsPerTrack
inc dl ; Sectors numbering starts at 1 not 0
mov cl,dl ; Sector in CL
mov edx,eax
shr edx,16
div WORD [BYTE bp+NumberOfHeads] ; Divide logical by number of heads
mov dh,dl ; Head in DH
mov dl,[BYTE bp+BootDrive] ; Drive number in DL
mov ch,al ; Cylinder in CX
ror ah,1 ; Low 8 bits of cylinder in CH, high 2 bits
ror ah,1 ; in CL shifted to bits 6 & 7
or cl,ah ; Or with sector number
mov ax,0201h
int 13h ; DISK - READ SECTORS INTO MEMORY
; AL = number of sectors to read, CH = track, CL = sector
; DH = head, DL = drive, ES:BX -> buffer to fill
; Return: CF set on error, AH = status (see AH=01h), AL = number of sectors read
jc PrintDiskError ; If the read failed then abort
popad
inc eax ; Increment Sector to Read
mov dx,es
add dx,byte 20h ; Increment read buffer for next sector
mov es,dx
loop ReadSectorsCHSLoop ; Read next sector
ret
; Displays a disk error message
; And reboots
PrintDiskError:
mov si,msgDiskError ; Bad boot disk message
call PutChars ; Display it
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
jmp Reboot
; Displays a file system error message
; And reboots
PrintFileSystemError:
mov si,msgFileSystemError ; FreeLdr not found message
call PutChars ; Display it
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
Reboot:
xor ax,ax
int 16h ; Wait for a keypress
int 19h ; Reboot
PutChars:
lodsb
or al,al
jz short Done
mov ah,0eh
mov bx,07h
int 10h
jmp short PutChars
Done:
retn
BiosCHSDriveSize dd 0
msgDiskError db 'Disk error',0dh,0ah,0
msgFileSystemError db 'File system error',0dh,0ah,0
msgAnyKey db 'Press any key to restart',0dh,0ah,0
times 510-($-$$) db 0 ; Pad to 510 bytes
dw 0aa55h ; BootSector signature
; End of bootsector
;
; Now starts the extra boot code that we will store
; at sector 14 on a FAT32 volume
;
; To remain multi-boot compatible with other operating
; systems we must not overwrite anything other than
; the bootsector which means we will have to use
; a different sector like 14 to store our extra boot code
StartSearch:
; Now we must get the first cluster of the root directory
mov eax,DWORD [BYTE bp+RootDirStartCluster]
cmp eax,0ffffff8h ; Check to see if this is the last cluster in the chain
jb ContinueSearch ; If not continue, if so then we didn't find freeldr.sys
jmp PrintFileNotFound
ContinueSearch:
mov bx,2000h
mov es,bx ; Read cluster to [2000:0000h]
call ReadCluster ; Read the cluster
; Now we have to find our way through the root directory to
; The OSLOADER.SYS file
xor bx,bx
mov bl,[BYTE bp+SectsPerCluster]
shl bx,4 ; BX = BX * 512 / 32
mov ax,2000h ; We loaded at 2000:0000
mov es,ax
xor di,di
mov si,filename
mov cx,11
rep cmpsb ; Compare filenames
jz FoundFile ; If same we found it
dec bx
jnz FindFile
jmp PrintFileNotFound
FindFile:
mov ax,es ; We didn't find it in the previous dir entry
add ax,2 ; So lets move to the next one
mov es,ax ; And search again
xor di,di
mov si,filename
mov cx,11
rep cmpsb ; Compare filenames
jz FoundFile ; If same we found it
dec bx ; Keep searching till we run out of dir entries
jnz FindFile ; Last entry?
; Get the next root dir cluster and try again until we run out of clusters
mov eax,DWORD [BYTE bp+RootDirStartCluster]
call GetFatEntry
mov [BYTE bp+RootDirStartCluster],eax
jmp StartSearch
FoundFile:
; Display "Loading FreeLoader..." message
mov si,msgLoading ; Loading message
call PutChars ; Display it
xor di,di ; ES:DI has dir entry
xor dx,dx
mov ax,WORD [es:di+14h] ; Get start cluster high word
shl eax,16
mov ax,WORD [es:di+1ah] ; Get start cluster low word
CheckStartCluster:
cmp eax,2 ; Check and see if the start cluster starts at cluster 2 or above
jnb CheckEndCluster ; If so then continue
jmp PrintFileSystemError ; If not exit with error
CheckEndCluster:
cmp eax,0ffffff8h ; Check and see if the start cluster is and end of cluster chain indicator
jb InitializeLoadSegment ; If not then continue
jmp PrintFileSystemError ; If so exit with error
InitializeLoadSegment:
mov bx,800h
mov es,bx
LoadFile:
cmp eax,0ffffff8h ; Check to see if this is the last cluster in the chain
jae LoadFileDone ; If so continue, if not then read the next one
push eax
xor bx,bx ; Load ROSLDR starting at 0000:8000h
push es
call ReadCluster
pop es
xor bx,bx
mov bl,[BYTE bp+SectsPerCluster]
shl bx,5 ; BX = BX * 512 / 16
mov ax,es ; Increment the load address by
add ax,bx ; The size of a cluster
mov es,ax
pop eax
push es
call GetFatEntry ; Get the next entry
pop es
jmp LoadFile ; Load the next cluster (if any)
LoadFileDone:
mov dl,[BYTE bp+BootDrive]
xor ax,ax
push ax ; We loaded at 0000:8000
push WORD 8000h ; We will do a far return to 0000:8000h
retf ; Transfer control to ROSLDR
; Returns the FAT entry for a given cluster number
; On entry EAX has cluster number
; On return EAX has FAT entry for that cluster
GetFatEntry:
shl eax,2 ; EAX = EAX * 4 (since FAT32 entries are 4 bytes)
mov ecx,eax ; Save this for later in ECX
xor edx,edx
movzx ebx,WORD [BYTE bp+BytesPerSector]
push ebx
div ebx ; FAT Sector Number = EAX / BytesPerSector
movzx ebx,WORD [BYTE bp+ReservedSectors]
add eax,ebx ; FAT Sector Number += ReservedSectors
mov ebx,DWORD [BYTE bp+HiddenSectors]
add eax,ebx ; FAT Sector Number += HiddenSectors
pop ebx
dec ebx
and ecx,ebx ; FAT Offset Within Sector = ECX % BytesPerSector
; EAX holds logical FAT sector number
; ECX holds FAT entry offset
; Now we have to check the extended flags
; to see which FAT is the active one
; and use it, or if they are mirrored then
; no worries
movzx ebx,WORD [BYTE bp+ExtendedFlags] ; Get extended flags and put into ebx
and bx,0x0f ; Mask off upper 8 bits, now we have active fat in bl
jz LoadFatSector ; If fat is mirrored then skip fat calcs
cmp bl,[BYTE bp+NumberOfFats] ; Compare bl to number of fats
jb GetActiveFatOffset
jmp PrintFileSystemError ; If bl is bigger than numfats exit with error
GetActiveFatOffset:
push eax ; Save logical FAT sector number
mov eax,[BYTE bp+SectorsPerFatBig] ; Get the number of sectors occupied by one fat in eax
mul ebx ; Multiplied by the active FAT index we have in ebx
pop edx ; Get logical FAT sector number
add eax,edx ; Add the current FAT sector offset
LoadFatSector:
push ecx
; EAX holds logical FAT sector number
; Check if we have already loaded it
cmp eax,DWORD [FatSectorInCache]
je LoadFatSectorAlreadyLoaded
mov DWORD [FatSectorInCache],eax
mov bx,7000h
mov es,bx
xor bx,bx ; We will load it to [7000:0000h]
mov cx,1
call ReadSectors
LoadFatSectorAlreadyLoaded:
mov bx,7000h
mov es,bx
pop ecx
mov eax,DWORD [es:ecx] ; Get FAT entry
and eax,0fffffffh ; Mask off reserved bits
ret
FatSectorInCache: ; This variable tells us which sector we currently have in memory
dd 0ffffffffh ; There is no need to re-read the same sector if we don't have to
; Reads cluster number in EAX into [ES:0000]
ReadCluster:
; StartSector = ((Cluster - 2) * SectorsPerCluster) + ReservedSectors + HiddenSectors;
dec eax
dec eax
xor edx,edx
movzx ebx,BYTE [BYTE bp+SectsPerCluster]
mul ebx
push eax
xor edx,edx
movzx eax,BYTE [BYTE bp+NumberOfFats]
mul DWORD [BYTE bp+SectorsPerFatBig]
movzx ebx,WORD [BYTE bp+ReservedSectors]
add eax,ebx
add eax,DWORD [BYTE bp+HiddenSectors]
pop ebx
add eax,ebx ; EAX now contains the logical sector number of the cluster
xor bx,bx ; We will load it to [ES:0000], ES loaded before function call
movzx cx,BYTE [BYTE bp+SectsPerCluster]
call ReadSectors
ret
; Displays a file not found error message
; And reboots
PrintFileNotFound:
mov si,msgFreeLdr ; FreeLdr not found message
call PutChars ; Display it
mov si,msgAnyKey ; Press any key message
call PutChars ; Display it
jmp Reboot
msgFreeLdr db 'FREELDR.SYS not found',0dh,0ah,0
filename db 'FREELDR SYS'
msgLoading db 'Loading FreeLoader...',0dh,0ah,0
times 1022-($-$$) db 0 ; Pad to 1022 bytes
dw 0aa55h ; BootSector signature

View File

@@ -1,960 +0,0 @@
; ****************************************************************************
;
; isolinux.asm
;
; A program to boot Linux kernels off a CD-ROM using the El Torito
; boot standard in "no emulation" mode, making the entire filesystem
; available. It is based on the SYSLINUX boot loader for MS-DOS
; floppies.
;
; Copyright (C) 1994-2001 H. Peter Anvin
;
; 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, Inc., 675 Mass Ave, Cambridge MA 02139,
; USA; either version 2 of the License, or (at your option) any later
; version; incorporated herein by reference.
;
; ****************************************************************************
;
; THIS FILE IS A MODIFIED VERSION OF ISOLINUX.ASM
; MODIFICATION DONE BY MICHAEL K TER LOUW
; LAST UPDATED 3-9-2002
; SEE "COPYING" FOR INFORMATION ABOUT THE LICENSE THAT APPLIES TO THIS RELEASE
;
; ****************************************************************************
;
; This file is a modified version of ISOLINUX.ASM.
; Modification done by Eric Kohl
; Last update 04-25-2002
;
; ****************************************************************************
; Note: The Makefile builds one version with DEBUG_MESSAGES automatically.
;%define DEBUG_MESSAGES ; Uncomment to get debugging messages
; ---------------------------------------------------------------------------
; BEGIN THE BIOS/CODE/DATA SEGMENT
; ---------------------------------------------------------------------------
absolute 0400h
serial_base resw 4 ; Base addresses for 4 serial ports
absolute 0413h
BIOS_fbm resw 1 ; Free Base Memory (kilobytes)
absolute 046Ch
BIOS_timer resw 1 ; Timer ticks
absolute 0472h
BIOS_magic resw 1 ; BIOS reset magic
absolute 0484h
BIOS_vidrows resb 1 ; Number of screen rows
;
; Memory below this point is reserved for the BIOS and the MBR
;
absolute 1000h
trackbuf resb 8192 ; Track buffer goes here
trackbufsize equ $-trackbuf
; trackbuf ends at 3000h
struc open_file_t
file_sector resd 1 ; Sector pointer (0 = structure free)
file_left resd 1 ; Number of sectors left
endstruc
struc dir_t
dir_lba resd 1 ; Directory start (LBA)
dir_len resd 1 ; Length in bytes
dir_clust resd 1 ; Length in clusters
endstruc
MAX_OPEN_LG2 equ 2 ; log2(Max number of open files)
MAX_OPEN equ (1 << MAX_OPEN_LG2)
SECTORSIZE_LG2 equ 11 ; 2048 bytes/sector (El Torito requirement)
SECTORSIZE equ (1 << SECTORSIZE_LG2)
CR equ 13 ; Carriage Return
LF equ 10 ; Line Feed
absolute 5000h ; Here we keep our BSS stuff
DriveNo resb 1 ; CD-ROM BIOS drive number
DiskError resb 1 ; Error code for disk I/O
RetryCount resb 1 ; Used for disk access retries
TimeoutCount resb 1 ; Timeout counter
ISOFlags resb 1 ; Flags for ISO directory search
RootDir resb dir_t_size ; Root directory
CurDir resb dir_t_size ; Current directory
ISOFileName resb 64 ; ISO filename canonicalization buffer
ISOFileNameEnd equ $
alignb open_file_t_size
Files resb MAX_OPEN*open_file_t_size
section .text
org 7000h
start:
cli ; Disable interrupts
xor ax, ax ; ax = segment zero
mov ss, ax ; Initialize stack segment
mov sp, start ; Set up stack
mov ds, ax ; Initialize other segment registers
mov es, ax
mov fs, ax
mov gs, ax
sti ; Enable interrupts
cld ; Increment pointers
mov cx, 2048 >> 2 ; Copy the bootsector
mov si, 0x7C00 ; from 0000:7C00
mov di, 0x7000 ; to 0000:7000
rep movsd ; copy the program
jmp 0:relocate ; jump into relocated code
relocate:
; Display the banner and copyright
%ifdef DEBUG_MESSAGES
mov si, isolinux_banner ; si points to hello message
call writestr ; display the message
mov si,copyright_str
call writestr
%endif
; Make sure the keyboard buffer is empty
.kbd_buffer_test:
call pollchar
jz .kbd_buffer_empty
call getchar
jmp .kbd_buffer_test
.kbd_buffer_empty:
; Display the 'Press key' message and wait for a maximum of 5 seconds
call crlf
mov si, presskey_msg ; si points to 'Press key' message
call writestr ; display the message
mov byte [TimeoutCount], 5
.next_second:
mov eax, [BIOS_timer] ; load current tick counter
add eax, 19 ;
.poll_again:
call pollchar
jnz .boot_cdrom
mov ebx, [BIOS_timer]
cmp eax, ebx
jnz .poll_again
mov si, dot_msg ; print '.'
call writestr
dec byte [TimeoutCount] ; decrement timeout counter
jz .boot_harddisk
jmp .next_second
.boot_harddisk:
; Boot first harddisk (drive 0x80)
mov ax, 0201h
mov dx, 0080h
mov cx, 0001h
mov bx, 7C00h
int 13h
jnc .go_hd
jmp kaboom
.go_hd:
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov dx, 0080h
jmp 0:0x7C00
.boot_cdrom:
; Save and display the boot drive number
mov [DriveNo], dl
%ifdef DEBUG_MESSAGES
mov si, startup_msg
call writemsg
mov al, dl
call writehex2
call crlf
%endif
; Now figure out what we're actually doing
; Note: use passed-in DL value rather than 7Fh because
; at least some BIOSes will get the wrong value otherwise
mov ax, 4B01h ; Get disk emulation status
mov dl, [DriveNo]
mov si, spec_packet
int 13h
jc near spec_query_failed ; Shouldn't happen (BIOS bug)
mov dl, [DriveNo]
cmp [sp_drive], dl ; Should contain the drive number
jne near spec_query_failed
%ifdef DEBUG_MESSAGES
mov si, spec_ok_msg
call writemsg
mov al, byte [sp_drive]
call writehex2
call crlf
%endif
found_drive:
; Get drive information
mov ah, 48h
mov dl, [DriveNo]
mov si, drive_params
int 13h
jnc params_ok
mov si, nosecsize_msg
call writemsg
params_ok:
; Check for the sector size (should be 2048, but
; some BIOSes apparently think we're 512-byte media)
;
; FIX: We need to check what the proper behaviour
; is for getlinsec when the BIOS thinks the sector
; size is 512!!! For that, we need such a BIOS, though...
%ifdef DEBUG_MESSAGES
mov si, secsize_msg
call writemsg
mov ax, [dp_secsize]
call writehex4
call crlf
%endif
;
; Clear Files structures
;
mov di, Files
mov cx, (MAX_OPEN*open_file_t_size)/4
xor eax, eax
rep stosd
;
; Now, we need to sniff out the actual filesystem data structures.
; mkisofs gave us a pointer to the primary volume descriptor
; (which will be at 16 only for a single-session disk!); from the PVD
; we should be able to find the rest of what we need to know.
;
get_fs_structures:
mov eax, 16 ; Primary Volume Descriptor (sector 16)
mov bx, trackbuf
call getonesec
mov eax, [trackbuf+156+2]
mov [RootDir+dir_lba],eax
mov [CurDir+dir_lba],eax
%ifdef DEBUG_MESSAGES
mov si, rootloc_msg
call writemsg
call writehex8
call crlf
%endif
mov eax,[trackbuf+156+10]
mov [RootDir+dir_len],eax
mov [CurDir+dir_len],eax
%ifdef DEBUG_MESSAGES
mov si, rootlen_msg
call writemsg
call writehex8
call crlf
%endif
add eax,SECTORSIZE-1
shr eax,SECTORSIZE_LG2
mov [RootDir+dir_clust],eax
mov [CurDir+dir_clust],eax
%ifdef DEBUG_MESSAGES
mov si, rootsect_msg
call writemsg
call writehex8
call crlf
%endif
; Look for the "X86" directory, and if found,
; make it the current directory instead of the root
; directory.
mov di,isolinux_dir
mov al,02h ; Search for a directory
call searchdir_iso
jnz .dir_found
mov si,no_dir_msg
call writemsg
jmp kaboom
.dir_found:
mov [CurDir+dir_len],eax
mov eax,[si+file_left]
mov [CurDir+dir_clust],eax
xor eax,eax ; Free this file pointer entry
xchg eax,[si+file_sector]
mov [CurDir+dir_lba],eax
mov di, isolinux_bin ; di points to Isolinux filename
call searchdir ; look for the file
jnz .isolinux_opened ; got the file
mov si, no_isolinux_msg ; si points to error message
call writemsg ; display the message
jmp kaboom ; fail boot
.isolinux_opened:
push si ; save file pointer
%ifdef DEBUG_MESSAGES
mov si, filelen_msg
call writemsg
call writehex8
call crlf
%endif
mov bx, 0x8000 ; bx = load address
pop si ; si = file pointer
mov cx, 0xFFFF ; load the whole file
call getfssec ; get the first sector
mov dl, [DriveNo] ; dl = boot drive
jmp 0:0x8000 ; jump into OSLoader
;
; searchdir:
;
; Open a file
;
; On entry:
; DS:DI = filename
; If successful:
; ZF clear
; SI = file pointer
; DX:AX or EAX = file length in bytes
; If unsuccessful
; ZF set
;
;
; searchdir_iso is a special entry point for ISOLINUX only. In addition
; to the above, searchdir_iso passes a file flag mask in AL. This is useful
; for searching for directories.
;
alloc_failure:
xor ax,ax ; ZF <- 1
ret
searchdir:
xor al,al
searchdir_iso:
mov [ISOFlags],al
call allocate_file ; Temporary file structure for directory
jnz alloc_failure
push es
push ds
pop es ; ES = DS
mov si,CurDir
cmp byte [di],'\' ; If filename begins with slash
jne .not_rooted
inc di ; Skip leading slash
mov si,RootDir ; Reference root directory instead
.not_rooted:
mov eax,[si+dir_clust]
mov [bx+file_left],eax
mov eax,[si+dir_lba]
mov [bx+file_sector],eax
mov edx,[si+dir_len]
.look_for_slash:
mov ax,di
.scan:
mov cl,[di]
inc di
and cl,cl
jz .isfile
cmp cl,'\'
jne .scan
mov [di-1],byte 0 ; Terminate at directory name
mov cl,02h ; Search for directory
xchg cl,[ISOFlags]
push di
push cx
push word .resume ; Where to "return" to
push es
.isfile:
xchg ax,di
.getsome:
; Get a chunk of the directory
mov si,trackbuf
pushad
xchg bx,si
mov cx,1 ; load one sector
call getfssec
popad
.compare:
movzx eax, byte [si] ; Length of directory entry
cmp al, 33
jb .next_sector
mov cl, [si+25]
xor cl, [ISOFlags]
test cl, byte 8Eh ; Unwanted file attributes!
jnz .not_file
pusha
movzx cx, byte [si+32] ; File identifier length
add si, byte 33 ; File identifier offset
call iso_compare_names
popa
je .success
.not_file:
sub edx, eax ; Decrease bytes left
jbe .failure
add si, ax ; Advance pointer
.check_overrun:
; Did we finish the buffer?
cmp si, trackbuf+trackbufsize
jb .compare ; No, keep going
jmp short .getsome ; Get some more directory
.next_sector:
; Advance to the beginning of next sector
lea ax, [si+SECTORSIZE-1]
and ax, ~(SECTORSIZE-1)
sub ax, si
jmp short .not_file ; We still need to do length checks
.failure:
%ifdef DEBUG_MESSAGES
mov si, findfail_msg
call writemsg
call crlf
%endif
xor eax, eax ; ZF = 1
mov [bx+file_sector], eax
pop es
ret
.success:
mov eax, [si+2] ; Location of extent
mov [bx+file_sector], eax
mov eax, [si+10] ; Data length
push eax
add eax, SECTORSIZE-1
shr eax, SECTORSIZE_LG2
mov [bx+file_left], eax
pop eax
mov edx, eax
shr edx, 16
and bx, bx ; ZF = 0
mov si, bx
pop es
ret
.resume:
; We get here if we were only doing part of a lookup
; This relies on the fact that .success returns bx == si
xchg edx, eax ; Directory length in edx
pop cx ; Old ISOFlags
pop di ; Next filename pointer
mov byte [di-1], '\' ; restore the backslash in the filename
mov [ISOFlags], cl ; Restore the flags
jz .failure ; Did we fail? If so fail for real!
jmp .look_for_slash ; Otherwise, next level
;
; allocate_file: Allocate a file structure
;
; If successful:
; ZF set
; BX = file pointer
; In unsuccessful:
; ZF clear
;
allocate_file:
push cx
mov bx, Files
mov cx, MAX_OPEN
.check:
cmp dword [bx], byte 0
je .found
add bx, open_file_t_size ; ZF = 0
loop .check
; ZF = 0 if we fell out of the loop
.found:
pop cx
ret
;
; iso_compare_names:
; Compare the names DS:SI and DS:DI and report if they are
; equal from an ISO 9660 perspective. SI is the name from
; the filesystem; CX indicates its length, and ';' terminates.
; DI is expected to end with a null.
;
; Note: clobbers AX, CX, SI, DI; assumes DS == ES == base segment
;
iso_compare_names:
; First, terminate and canonicalize input filename
push di
mov di, ISOFileName
.canon_loop:
jcxz .canon_end
lodsb
dec cx
cmp al, ';'
je .canon_end
and al, al
je .canon_end
stosb
cmp di, ISOFileNameEnd-1 ; Guard against buffer overrun
jb .canon_loop
.canon_end:
cmp di, ISOFileName
jbe .canon_done
cmp byte [di-1], '.' ; Remove terminal dots
jne .canon_done
dec di
jmp short .canon_end
.canon_done:
mov [di], byte 0 ; Null-terminate string
pop di
mov si, ISOFileName
.compare:
lodsb
mov ah, [di]
inc di
and ax, ax
jz .success ; End of string for both
and al, al ; Is either one end of string?
jz .failure ; If so, failure
and ah, ah
jz .failure
or ax, 2020h ; Convert to lower case
cmp al, ah
je .compare
.failure:
and ax, ax ; ZF = 0 (at least one will be nonzero)
.success:
ret
;
; getfssec: Get multiple clusters from a file, given the file pointer.
;
; On entry:
; ES:BX -> Buffer
; SI -> File pointer
; CX -> Cluster count; 0FFFFh = until end of file
; On exit:
; SI -> File pointer (or 0 on EOF)
; CF = 1 -> Hit EOF
;
getfssec:
cmp cx, [si+file_left]
jna .ok_size
mov cx, [si+file_left]
.ok_size:
mov bp, cx
push cx
push si
mov eax, [si+file_sector]
call getlinsec
xor ecx, ecx
pop si
pop cx
add [si+file_sector], ecx
sub [si+file_left], ecx
ja .not_eof ; CF = 0
xor ecx, ecx
mov [si+file_sector], ecx ; Mark as unused
xor si,si
stc
.not_eof:
ret
; INT 13h, AX=4B01h, DL=<passed in value> failed.
; Try to scan the entire 80h-FFh from the end.
spec_query_failed:
mov si,spec_err_msg
call writemsg
mov dl, 0FFh
.test_loop:
pusha
mov ax, 4B01h
mov si, spec_packet
mov byte [si], 13 ; Size of buffer
int 13h
popa
jc .still_broken
mov si, maybe_msg
call writemsg
mov al, dl
call writehex2
call crlf
cmp byte [sp_drive], dl
jne .maybe_broken
; Okay, good enough...
mov si, alright_msg
call writemsg
mov [DriveNo], dl
.found_drive:
jmp found_drive
; Award BIOS 4.51 apparently passes garbage in sp_drive,
; but if this was the drive number originally passed in
; DL then consider it "good enough"
.maybe_broken:
cmp byte [DriveNo], dl
je .found_drive
.still_broken: dec dx
cmp dl, 80h
jnb .test_loop
fatal_error:
mov si, nothing_msg
call writemsg
.norge:
jmp short .norge
; Information message (DS:SI) output
; Prefix with "isolinux: "
;
writemsg:
push ax
push si
mov si, isolinux_str
call writestr
pop si
call writestr
pop ax
ret
;
; crlf: Print a newline
;
crlf:
mov si, crlf_msg
; Fall through
;
; writestr: write a null-terminated string to the console, saving
; registers on entry.
;
writestr:
pushfd
pushad
.top:
lodsb
and al, al
jz .end
call writechr
jmp short .top
.end:
popad
popfd
ret
;
; writehex[248]: Write a hex number in (AL, AX, EAX) to the console
;
writehex2:
pushfd
pushad
shl eax, 24
mov cx, 2
jmp short writehex_common
writehex4:
pushfd
pushad
shl eax, 16
mov cx, 4
jmp short writehex_common
writehex8:
pushfd
pushad
mov cx, 8
writehex_common:
.loop:
rol eax, 4
push eax
and al, 0Fh
cmp al, 10
jae .high
.low:
add al, '0'
jmp short .ischar
.high:
add al, 'A'-10
.ischar:
call writechr
pop eax
loop .loop
popad
popfd
ret
;
; Write a character to the screen. There is a more "sophisticated"
; version of this in the subsequent code, so we patch the pointer
; when appropriate.
;
writechr:
pushfd
pushad
mov ah, 0Eh
xor bx, bx
int 10h
popad
popfd
ret
;
; Get one sector. Convenience entry point.
;
getonesec:
mov bp, 1
; Fall through to getlinsec
;
; Get linear sectors - EBIOS LBA addressing, 2048-byte sectors.
;
; Note that we can't always do this as a single request, because at least
; Phoenix BIOSes has a 127-sector limit. To be on the safe side, stick
; to 32 sectors (64K) per request.
;
; Input:
; EAX - Linear sector number
; ES:BX - Target buffer
; BP - Sector count
;
getlinsec:
mov si,dapa ; Load up the DAPA
mov [si+4],bx
mov bx,es
mov [si+6],bx
mov [si+8],eax
.loop:
push bp ; Sectors left
cmp bp,byte 32
jbe .bp_ok
mov bp,32
.bp_ok:
mov [si+2],bp
push si
mov dl,[DriveNo]
mov ah,42h ; Extended Read
call xint13
pop si
pop bp
movzx eax,word [si+2] ; Sectors we read
add [si+8],eax ; Advance sector pointer
sub bp,ax ; Sectors left
shl ax,SECTORSIZE_LG2-4 ; 2048-byte sectors -> segment
add [si+6],ax ; Advance buffer pointer
and bp,bp
jnz .loop
mov eax,[si+8] ; Next sector
ret
; INT 13h with retry
xint13:
mov byte [RetryCount], 6
.try:
pushad
int 13h
jc .error
add sp, byte 8*4 ; Clean up stack
ret
.error:
mov [DiskError], ah ; Save error code
popad
dec byte [RetryCount]
jnz .try
.real_error:
mov si, diskerr_msg
call writemsg
mov al, [DiskError]
call writehex2
mov si, ondrive_str
call writestr
mov al, dl
call writehex2
call crlf
; Fall through to kaboom
;
; kaboom: write a message and bail out. Wait for a user keypress,
; then do a hard reboot.
;
kaboom:
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
sti
mov si, err_bootfailed
call writestr
call getchar
cli
mov word [BIOS_magic], 0 ; Cold reboot
jmp 0F000h:0FFF0h ; Reset vector address
getchar:
.again:
mov ah, 1 ; Poll keyboard
int 16h
jz .again
.kbd:
xor ax, ax ; Get keyboard input
int 16h
.func_key:
ret
;
; pollchar: check if we have an input character pending (ZF = 0)
;
pollchar:
pushad
mov ah,1 ; Poll keyboard
int 16h
popad
ret
isolinux_banner db CR, LF, 'Loading IsoBoot...', CR, LF, 0
copyright_str db ' Copyright (C) 1994-2002 H. Peter Anvin', CR, LF, 0
presskey_msg db 'Press any key to boot from CD', 0
dot_msg db '.',0
%ifdef DEBUG_MESSAGES
startup_msg: db 'Starting up, DL = ', 0
spec_ok_msg: db 'Loaded spec packet OK, drive = ', 0
secsize_msg: db 'Sector size appears to be ', 0
rootloc_msg: db 'Root directory location: ', 0
rootlen_msg: db 'Root directory length: ', 0
rootsect_msg: db 'Root directory length(sectors): ', 0
fileloc_msg: db 'FreeLdr.sys location: ', 0
filelen_msg: db 'FreeLdr.sys length: ', 0
filesect_msg: db 'FreeLdr.sys length(sectors): ', 0
findfail_msg: db 'Failed to find file!', 0
%endif
nosecsize_msg: db 'Failed to get sector size, assuming 0800', CR, LF, 0
spec_err_msg: db 'Loading spec packet failed, trying to wing it...', CR, LF, 0
maybe_msg: db 'Found something at drive = ', 0
alright_msg: db 'Looks like it might be right, continuing...', CR, LF, 0
nothing_msg: db 'Failed to locate CD-ROM device; boot failed.', CR, LF, 0
isolinux_str db 'IsoBoot: ', 0
crlf_msg db CR, LF, 0
diskerr_msg: db 'Disk error ', 0
ondrive_str: db ', drive ', 0
err_bootfailed db CR, LF, 'Boot failed: press a key to retry...'
isolinux_dir db '\REACTOS', 0
no_dir_msg db 'Could not find the REACTOS directory.', CR, LF, 0
isolinux_bin db 'FREELDR.SYS', 0
no_isolinux_msg db 'Could not find the file FREELDR.SYS.', CR, LF, 0
;
; El Torito spec packet
;
align 8, db 0
spec_packet: db 13h ; Size of packet
sp_media: db 0 ; Media type
sp_drive: db 0 ; Drive number
sp_controller: db 0 ; Controller index
sp_lba: dd 0 ; LBA for emulated disk image
sp_devspec: dw 0 ; IDE/SCSI information
sp_buffer: dw 0 ; User-provided buffer
sp_loadseg: dw 0 ; Load segment
sp_sectors: dw 0 ; Sector count
sp_chs: db 0,0,0 ; Simulated CHS geometry
sp_dummy: db 0 ; Scratch, safe to overwrite
;
; EBIOS drive parameter packet
;
align 8, db 0
drive_params: dw 30 ; Buffer size
dp_flags: dw 0 ; Information flags
dp_cyl: dd 0 ; Physical cylinders
dp_head: dd 0 ; Physical heads
dp_sec: dd 0 ; Physical sectors/track
dp_totalsec: dd 0,0 ; Total sectors
dp_secsize: dw 0 ; Bytes per sector
dp_dpte: dd 0 ; Device Parameter Table
dp_dpi_key: dw 0 ; 0BEDDh if rest valid
dp_dpi_len: db 0 ; DPI len
db 0
dw 0
dp_bus: times 4 db 0 ; Host bus type
dp_interface: times 8 db 0 ; Interface type
db_i_path: dd 0,0 ; Interface path
db_d_path: dd 0,0 ; Device path
db 0
db_dpi_csum: db 0 ; Checksum for DPI info
;
; EBIOS disk address packet
;
align 8, db 0
dapa: dw 16 ; Packet size
.count: dw 0 ; Block count
.off: dw 0 ; Offset of buffer
.seg: dw 0 ; Segment of buffer
.lba: dd 0 ; LBA (LSW)
dd 0 ; LBA (MSW)
times 2048-($-$$) nop ; Pad to file offset 2048

View File

@@ -1,466 +0,0 @@
;
; Win2k FAT32 Boot Sector
;
; Brian Palmer <brianp@sginet.com>
;
;
; The BP register is initialized to 0x7c00, the start of
; the boot sector. The SP register is initialized to
; 0x7bf4, leaving 12 bytes of data storage space above
; the stack.
;
; The DWORD that gets stored at 0x7bf4 is 0xffffffff ??
;
; The DWORD that gets stored at 0x7bf8 is the count of
; total sectors of the volume, calculated from the BPB.
;
; The DWORD that gets stored at 0x7bfc is the logical
; sector number of the start of the data area.
;
org 7c00h
segment .text
bits 16
start:
jmp short main
nop
OEMName db 'MSWIN4.0'
BytesPerSector dw 512
SectsPerCluster db 1
ReservedSectors dw 1
NumberOfFats db 2
MaxRootEntries dw 0 ;512 - Always zero for FAT32 volumes
TotalSectors dw 0 ;2880 - Always zero for FAT32 volumes
MediaDescriptor db 0f8h
SectorsPerFat dw 0 ;9 - Always zero for FAT32 volumes
SectorsPerTrack dw 18
NumberOfHeads dw 2
HiddenSectors dd 0
TotalSectorsBig dd 0
; FAT32 Inserted Info
SectorsPerFatBig dd 0
ExtendedFlags dw 0
FSVersion dw 0
RootDirStartCluster dd 0
FSInfoSector dw 0
BackupBootSector dw 6
Reserved1 times 12 db 0
; End FAT32 Inserted Info
BootDrive db 80h
Reserved db 0
ExtendSig db 29h
SerialNumber dd 00000000h
VolumeLabel db 'NO NAME '
FileSystem db 'FAT32 '
main:
00007C5A 33C9 xor cx,cx
00007C5C 8ED1 mov ss,cx ; Setup the stack
00007C5E BCF47B mov sp,0x7bf4 ; Give us 12 bytes of space above the stack
00007C61 8EC1 mov es,cx
00007C63 8ED9 mov ds,cx
00007C65 BD007C mov bp,0x7c00
00007C68 884E02 mov [bp+0x2],cl ; Zero out the nop instruction?? (3rd byte of the boot sector)
00007C6B 8A5640 mov dl,[bp+BootDrive]
00007C6E B408 mov ah,0x8
00007C70 CD13 int 0x13 ; Int 13, func 8 - Get Drive Parameters
00007C72 7305 jnc drive_param_ok ; If no error jmp
drive_param_error:
00007C74 B9FFFF mov cx,0xffff ; We couldn't determine the drive parameters
00007C77 8AF1 mov dh,cl ; So just set the CHS to 0xff
drive_param_ok:
00007C79 660FB6C6 movzx eax,dh ; Store the number of heads in eax
00007C7D 40 inc ax ; Make it one-based because the bios returns it zero-based
00007C7E 660FB6D1 movzx edx,cl ; Store the sectors per track in edx
00007C82 80E23F and dl,0x3f ; Mask off the cylinder bits
00007C85 F7E2 mul dx ; Multiply the sectors per track with the heads, result in dx:ax
00007C87 86CD xchg cl,ch ; Switch the cylinder with the sectors
00007C89 C0ED06 shr ch,0x6 ; Move the top two cylinder bits down where they should be
00007C8C 41 inc cx ; Make it one-based because the bios returns it zero-based
00007C8D 660FB7C9 movzx ecx,cx
00007C91 66F7E1 mul ecx ; Multiply the cylinders with (heads * sectors) [stored in dx:ax already]
00007C94 668946F8 mov [bp-0x8],eax ; This value is the number of total sectors on the disk, so save it for later
00007C98 837E1600 cmp word [bp+TotalSectors],byte +0x0 ; Check the old 16-bit value of TotalSectors
00007C9C 7538 jnz print_ntldr_error_message ; If it is non-zero then exit with an error
00007C9E 837E2A00 cmp word [bp+FSVersion],byte +0x0 ; Check the file system version word
00007CA2 7732 ja print_ntldr_error_message ; If it is not zero then exit with an error
;
; We are now ready to load our second sector of boot code
; But first, a bit of undocumented information about how
; Win2k stores it's second sector of boot code.
;
; The FAT32 filesystem was designed so that you can store
; multiple sectors of boot code. The boot sector of a FAT32
; volume is actually three sectors long. Microsoft extended
; the BPB so much that you can't fit enough code in the
; boot sector to make it work. So they extended it. Sector 0
; is the traditional boot sector, sector 1 is the FSInfo sector,
; and sector 2 is used to store extra boot code to make up
; for the lost space the BPB takes.
;
; Now this creates an interesting problem. Suppose for example
; that the user has Win98 and Win2k installed. The Win2k
; boot sector is stored at sector 0 and the Win98 boot sector is
; stored as BOOTSECT.DOS on the file system. Now if Win2k were
; to store it's second sector of boot code in sector 2 like
; the fat spec says to do then when you try to dual boot back
; to Win98 the Win98 boot sector will load Win2k's second
; sector of boot code. Understand? ;-)
;
; To get around this problem Win2k stores it's second sector
; of boot code elsewhere. This sector is always stored at sector 13
; on the file system. Now don't ask me what happens when you don't
; have enough reserved sectors to store it, but I've never seen a
; FAT32 volume that didn't have at least 32 reserved sectors.
;
00007CA4 668B461C mov eax,[bp+HiddenSectors] ; Get the count of hidden sectors
00007CA8 6683C00C add eax,byte +0xc ; Add 12 to that value so that we are loading the 13th sector of the volume
00007CAC BB0080 mov bx,0x8000 ; Read the sector to address 0x8000
00007CAF B90100 mov cx,0x1 ; Read just one sector
00007CB2 E82B00 call read_sectors ; Read it
00007CB5 E94803 jmp 0x8000 ; Jump to the next sector of boot code
print_disk_error_message:
00007CB8 A0FA7D mov al,[DISK_ERR_offset_from_0x7d00]
putchars:
00007CBB B47D mov ah,0x7d
00007CBD 8BF0 mov si,ax
get_another_char:
00007CBF AC lodsb
00007CC0 84C0 test al,al
00007CC2 7417 jz reboot
00007CC4 3CFF cmp al,0xff
00007CC6 7409 jz print_reboot_message
00007CC8 B40E mov ah,0xe
00007CCA BB0700 mov bx,0x7
00007CCD CD10 int 0x10
00007CCF EBEE jmp short get_another_char
print_reboot_message:
00007CD1 A0FB7D mov al,[RESTART_ERR_offset_from_0x7d00]
00007CD4 EBE5 jmp short putchars
print_ntldr_error_message:
00007CD6 A0F97D mov al,[NTLDR_ERR_offset_from_0x7d00]
00007CD9 EBE0 jmp short putchars
reboot:
00007CDB 98 cbw
00007CDC CD16 int 0x16
00007CDE CD19 int 0x19
read_sectors:
00007CE0 6660 pushad
00007CE2 663B46F8 cmp eax,[bp-0x8]
00007CE6 0F824A00 jc near 0x7d34
00007CEA 666A00 o32 push byte +0x0
00007CED 6650 push eax
00007CEF 06 push es
00007CF0 53 push bx
00007CF1 666810000100 push dword 0x10010
00007CF7 807E0200 cmp byte [bp+0x2],0x0
00007CFB 0F852000 jnz near 0x7d1f
00007CFF B441 mov ah,0x41
00007D01 BBAA55 mov bx,0x55aa
00007D04 8A5640 mov dl,[bp+BootDrive]
00007D07 CD13 int 0x13
00007D09 0F821C00 jc near 0x7d29
00007D0D 81FB55AA cmp bx,0xaa55
00007D11 0F851400 jnz near 0x7d29
00007D15 F6C101 test cl,0x1
00007D18 0F840D00 jz near 0x7d29
00007D1C FE4602 inc byte [bp+0x2]
00007D1F B442 mov ah,0x42
00007D21 8A5640 mov dl,[bp+BootDrive]
00007D24 8BF4 mov si,sp
00007D26 CD13 int 0x13
00007D28 B0F9 mov al,0xf9
00007D2A 6658 pop eax
00007D2C 6658 pop eax
00007D2E 6658 pop eax
00007D30 6658 pop eax
00007D32 EB2A jmp short 0x7d5e
00007D34 6633D2 xor edx,edx
00007D37 660FB74E18 movzx ecx,word [bp+SectorsPerTrack]
00007D3C 66F7F1 div ecx
00007D3F FEC2 inc dl
00007D41 8ACA mov cl,dl
00007D43 668BD0 mov edx,eax
00007D46 66C1EA10 shr edx,0x10
00007D4A F7761A div word [bp+NumberOfHeads]
00007D4D 86D6 xchg dl,dh
00007D4F 8A5640 mov dl,[bp+BootDrive]
00007D52 8AE8 mov ch,al
00007D54 C0E406 shl ah,0x6
00007D57 0ACC or cl,ah
00007D59 B80102 mov ax,0x201
00007D5C CD13 int 0x13
00007D5E 6661 popad
00007D60 0F8254FF jc near print_disk_error_message
00007D64 81C30002 add bx,0x200
00007D68 6640 inc eax
00007D6A 49 dec cx
00007D6B 0F8571FF jnz near read_sectors
00007D6F C3 ret
NTLDR db 'NTLDR '
filler times 49 db 0
NTLDR_ERR db 0dh,0ah,'NTLDR is missing',0ffh
DISK_ERR db 0dh,0ah,'Disk error',0ffh
RESTART_ERR db 0dh,0ah,'Press any key to restart',0dh,0ah
more_filler times 16 db 0
NTLDR_offset_from_0x7d00 db 0
NTLDR_ERR_offset_from_0x7d00 db 0ach
DISK_ERR_offset_from_0x7d00 db 0bfh
RESTART_ERR_offset_from_0x7d00 db 0cch
dw 0
dw 0aa55h
;
; And that ends the code that makes up the traditional boot sector
; From here on out is a disassembly of the extra sector of boot
; code required for a FAT32 volume. Win2k stores this code at
; sector 13 on the file system.
;
00008000 660FB64610 movzx eax,byte [bp+NumberOfFats] ; Put the number of fats into eax
00008005 668B4E24 mov ecx,[bp+SectorsPerFatBig] ; Put the count of sectors per fat into ecx
00008009 66F7E1 mul ecx ; Multiply them, edx:eax = (eax * ecx)
0000800C 6603461C add eax,[bp+HiddenSectors] ; Add the hidden sectors to eax
00008010 660FB7560E movzx edx,word [bp+ReservedSectors] ; Put the count of reserved sectors into edx
00008015 6603C2 add eax,edx ; Add it to eax
00008018 668946FC mov [bp-0x4],eax ; eax now contains the start of the data area, so save it for later
0000801C 66C746F4FFFFFFFF mov dword [bp-0xc],0xffffffff ; Save 0xffffffff for later??
00008024 668B462C mov eax,[bp+RootDirStartCluster] ; Put the starting cluster of the root directory into eax
00008028 6683F802 cmp eax,byte +0x2 ; Check and see if the root directory starts at cluster 2 or above
0000802C 0F82A6FC jc near print_ntldr_error_message ; If not exit with error
00008030 663DF8FFFF0F cmp eax,0xffffff8 ; Check and see if the root directory start cluster is and end of cluster chain indicator
00008036 0F839CFC jnc near print_ntldr_error_message ; If so exit with error
search_root_directory_cluster:
0000803A 6650 push eax ; Save root directory start cluster on stack
0000803C 6683E802 sub eax,byte +0x2 ; Adjust it because the first two fat entries are unused so the third entry marks the first data area cluster
00008040 660FB65E0D movzx ebx,byte [bp+SectsPerCluster] ; Put the number of sectors per cluster in ebx
00008045 8BF3 mov si,bx ; Now store it also in si register
00008047 66F7E3 mul ebx ; Multiply sectors per cluster with root directory start cluster
0000804A 660346FC add eax,[bp-0x4] ; Add the start sector of the data area
read_directory_sector:
0000804E BB0082 mov bx,0x8200 ; We now have the start sector of the root directory, so load it to 0x8200
00008051 8BFB mov di,bx ; Put the address of the root directory sector in di also
00008053 B90100 mov cx,0x1 ; Read one sector
00008056 E887FC call read_sectors ; Perform the read
check_entry_for_ntldr:
00008059 382D cmp [di],ch ; Check the first byte of the root directory entry for zero
0000805B 741E jz ntldr_not_found ; If so then NTLDR is missing so exit with error
0000805D B10B mov cl,0xb ; Put the value 11 in cl so we can compare an 11-byte filename
0000805F 56 push si ; Save si (which contains the number of sectors per cluster)
00008060 BE707D mov si,NTLDR ;0x7d70 ; Check and see if "NTLDR" is the first file entry
00008063 F3A6 repe cmpsb ; Do the compare
00008065 5E pop si ; Restore sectors per cluster into si
00008066 741B jz ntldr_found ; If we found it then continue, else check next entry
00008068 03F9 add di,cx ; Add 0 to di? the next entry is 0x15 bytes away
0000806A 83C715 add di,byte +0x15 ; Add 0x15 to di
0000806D 3BFB cmp di,bx ; Check to see if we have reached the end of our sector we loaded, read_sectors sets bx = end address of data loaded
0000806F 72E8 jc check_entry_for_ntldr ; If we haven't reached the end then check the next entry
00008071 4E dec si ; decrement si, si holds the number of sectors per cluster
00008072 75DA jnz read_directory_sector ; If it's not zero then search the next sector for NTLDR
00008074 6658 pop eax ; If we got here that means we didn't find NTLDR in the previous root directory cluster, so restore eax with the start cluster
00008076 E86500 call get_fat_entry ; Get the next cluster in the fat chain
00008079 72BF jc search_root_directory_cluster ; If we reached end-of-file marker then don't jump, otherwise continue search
ntldr_not_found:
0000807B 83C404 add sp,byte +0x4
0000807E E955FC jmp print_ntldr_error_message
ntldr_load_segment_address dw 0x2000
ntldr_found:
00008083 83C404 add sp,byte +0x4 ; Adjust stack to remove root directory start cluster
00008086 8B7509 mov si,[di+0x9] ; Put start cluster high word in si
00008089 8B7D0F mov di,[di+0xf] ; Put start cluster low word in di
0000808C 8BC6 mov ax,si ; Put high word in ax
0000808E 66C1E010 shl eax,0x10 ; Shift it into position
00008092 8BC7 mov ax,di ; Put low word in ax, now eax contains start cluster of NTLDR
00008094 6683F802 cmp eax,byte +0x2 ; Check and see if the start cluster of NTLDR starts at cluster 2 or above
00008098 0F823AFC jc near print_ntldr_error_message ; If not exit with error
0000809C 663DF8FFFF0F cmp eax,0xffffff8 ; Check and see if the start cluster of NTLDR is and end of cluster chain indicator
000080A2 0F8330FC jnc near print_ntldr_error_message ; If so exit with error
load_next_ntldr_cluster:
000080A6 6650 push eax ; Save NTLDR start cluster for later
000080A8 6683E802 sub eax,byte +0x2 ; Adjust it because the first two fat entries are unused so the third entry marks the first data area cluster
000080AC 660FB64E0D movzx ecx,byte [bp+SectsPerCluster] ; Put the sectors per cluster into ecx
000080B1 66F7E1 mul ecx ; Multiply sectors per cluster by the start cluster, we now have the logical start sector
000080B4 660346FC add eax,[bp-0x4] ; Add the start of the data area logical sector
000080B8 BB0000 mov bx,0x0 ; Load NTLDR to offset zero
000080BB 06 push es ; Save es
000080BC 8E068180 mov es,[ntldr_load_segment_address] ; Get the segment address to load NTLDR to
000080C0 E81DFC call read_sectors ; Load the first cluster
000080C3 07 pop es ; Restore es
000080C4 6658 pop eax ; Restore eax to NTLDR start cluster
000080C6 C1EB04 shr bx,0x4 ; bx contains the amount of data we transferred, so divide it by 16
000080C9 011E8180 add [ntldr_load_segment_address],bx ; Add that value to the segment
000080CD E80E00 call get_fat_entry ; Get the next cluster in eax
000080D0 0F830200 jnc near jump_to_ntldr ; If we have reached the end of file then lets get to NTLDR
000080D4 72D0 jc load_next_ntldr_cluster ; If not, then load another cluster
jump_to_ntldr:
000080D6 8A5640 mov dl,[bp+BootDrive] ; Put the boot drive in dl
000080D9 EA00000020 jmp 0x2000:0x0 ; Jump to NTLDR
get_fat_entry:
000080DE 66C1E002 shl eax,0x2 ; Multiply cluster by 4
000080E2 E81100 call load_fat_sector ; Load the fat sector
000080E5 26668B01 mov eax,[es:bx+di] ; Get the fat entry
000080E9 6625FFFFFF0F and eax,0xfffffff ; Mask off the most significant 4 bits
000080EF 663DF8FFFF0F cmp eax,0xffffff8 ; Compare it to end of file marker to set the flags correctly
000080F5 C3 ret ; Return to caller
load_fat_sector:
000080F6 BF007E mov di,0x7e00 ; We will load the fat sector to 0x7e00
000080F9 660FB74E0B movzx ecx,word [bp+SectsPerCluster] ; Get the sectors per cluster
000080FE 6633D2 xor edx,edx ; We will divide (cluster * 4) / sectorspercluster
00008101 66F7F1 div ecx ; eax is already set before we get to this routine
00008104 663B46F4 cmp eax,[bp-0xc] ; Compare eax to 0xffffffff (initially, we set this value later)
00008108 743A jz load_fat_sector_end ; If it is the same return
0000810A 668946F4 mov [bp-0xc],eax ; Update that value
0000810E 6603461C add eax,[bp+HiddenSectors] ; Add the hidden sectors
00008112 660FB74E0E movzx ecx,word [bp+ReservedSectors] ; Add the reserved sectors
00008117 6603C1 add eax,ecx ; To the hidden sectors + the value we computed earlier
0000811A 660FB75E28 movzx ebx,word [bp+ExtendedFlags] ; Get extended flags and put into ebx
0000811F 83E30F and bx,byte +0xf ; Mask off upper 8 bits
00008122 7416 jz load_fat_sector_into_memory ; If fat is mirrored then skip fat calcs
00008124 3A5E10 cmp bl,[bp+NumberOfFats] ; Compare bl to number of fats
00008127 0F83ABFB jnc near print_ntldr_error_message ; If bl is bigger than numfats exit with error
0000812B 52 push dx ; Save dx
0000812C 668BC8 mov ecx,eax ; Put the current fat sector offset into ecx
0000812F 668B4624 mov eax,[bp+SectorsPerFatBig] ; Get the number of sectors occupied by one fat
00008133 66F7E3 mul ebx ; Multiplied by the active fat index
00008136 6603C1 add eax,ecx ; Add the current fat sector offset
00008139 5A pop dx ; Restore dx
load_fat_sector_into_memory:
0000813A 52 push dx ; Save dx, what is so important in dx??
0000813B 8BDF mov bx,di ; Put 0x7e00 in bx
0000813D B90100 mov cx,0x1 ; Load one sector
00008140 E89DFB call read_sectors ; Perform the read
00008143 5A pop dx ; Restore dx
load_fat_sector_end:
00008144 8BDA mov bx,dx ; Put it into bx, what is this value??
00008146 C3 ret ; Return
00008147 0000 add [bx+si],al
00008149 0000 add [bx+si],al
0000814B 0000 add [bx+si],al
0000814D 0000 add [bx+si],al
0000814F 0000 add [bx+si],al
00008151 0000 add [bx+si],al
00008153 0000 add [bx+si],al
00008155 0000 add [bx+si],al
00008157 0000 add [bx+si],al
00008159 0000 add [bx+si],al
0000815B 0000 add [bx+si],al
0000815D 0000 add [bx+si],al
0000815F 0000 add [bx+si],al
00008161 0000 add [bx+si],al
00008163 0000 add [bx+si],al
00008165 0000 add [bx+si],al
00008167 0000 add [bx+si],al
00008169 0000 add [bx+si],al
0000816B 0000 add [bx+si],al
0000816D 0000 add [bx+si],al
0000816F 0000 add [bx+si],al
00008171 0000 add [bx+si],al
00008173 0000 add [bx+si],al
00008175 0000 add [bx+si],al
00008177 0000 add [bx+si],al
00008179 0000 add [bx+si],al
0000817B 0000 add [bx+si],al
0000817D 0000 add [bx+si],al
0000817F 0000 add [bx+si],al
00008181 0000 add [bx+si],al
00008183 0000 add [bx+si],al
00008185 0000 add [bx+si],al
00008187 0000 add [bx+si],al
00008189 0000 add [bx+si],al
0000818B 0000 add [bx+si],al
0000818D 0000 add [bx+si],al
0000818F 0000 add [bx+si],al
00008191 0000 add [bx+si],al
00008193 0000 add [bx+si],al
00008195 0000 add [bx+si],al
00008197 0000 add [bx+si],al
00008199 0000 add [bx+si],al
0000819B 0000 add [bx+si],al
0000819D 0000 add [bx+si],al
0000819F 0000 add [bx+si],al
000081A1 0000 add [bx+si],al
000081A3 0000 add [bx+si],al
000081A5 0000 add [bx+si],al
000081A7 0000 add [bx+si],al
000081A9 0000 add [bx+si],al
000081AB 0000 add [bx+si],al
000081AD 0000 add [bx+si],al
000081AF 0000 add [bx+si],al
000081B1 0000 add [bx+si],al
000081B3 0000 add [bx+si],al
000081B5 0000 add [bx+si],al
000081B7 0000 add [bx+si],al
000081B9 0000 add [bx+si],al
000081BB 0000 add [bx+si],al
000081BD 0000 add [bx+si],al
000081BF 0000 add [bx+si],al
000081C1 0000 add [bx+si],al
000081C3 0000 add [bx+si],al
000081C5 0000 add [bx+si],al
000081C7 0000 add [bx+si],al
000081C9 0000 add [bx+si],al
000081CB 0000 add [bx+si],al
000081CD 0000 add [bx+si],al
000081CF 0000 add [bx+si],al
000081D1 0000 add [bx+si],al
000081D3 0000 add [bx+si],al
000081D5 0000 add [bx+si],al
000081D7 0000 add [bx+si],al
000081D9 0000 add [bx+si],al
000081DB 0000 add [bx+si],al
000081DD 0000 add [bx+si],al
000081DF 0000 add [bx+si],al
000081E1 0000 add [bx+si],al
000081E3 0000 add [bx+si],al
000081E5 0000 add [bx+si],al
000081E7 0000 add [bx+si],al
000081E9 0000 add [bx+si],al
000081EB 0000 add [bx+si],al
000081ED 0000 add [bx+si],al
000081EF 0000 add [bx+si],al
000081F1 0000 add [bx+si],al
000081F3 0000 add [bx+si],al
000081F5 0000 add [bx+si],al
000081F7 0000 add [bx+si],al
000081F9 0000 add [bx+si],al
000081FB 0000 add [bx+si],al
000081FD 0055AA add [di-0x56],dl ; We can't forget the infamous boot signature

View File

@@ -1,249 +0,0 @@
;
; The BP register is initialized to 0x7c00, the start of
; the boot sector. The SP register is initialized to
; 0x7bf0, leaving 16 bytes of data storage space above
; the stack.
;
; The DWORD that gets stored at 0x7bfc is the logical
; sector number of the start of the data area.
;
; The DWORD that gets stored at 0x7bf8 is ????????
;
; The DWORD that gets stored at 0x7bf4 is ????????
;
; The DWORD that gets stored at 0x7bf0 is ????????
;
org 7c00h
segment .text
bits 16
start:
jmp short main
nop
OEMName db 'MSWIN4.0'
BytesPerSector dw 512
SectsPerCluster db 1
ReservedSectors dw 1
NumberOfFats db 2
MaxRootEntries dw 0 ;512 - Always zero for FAT32 volumes
TotalSectors dw 0 ;2880 - Always zero for FAT32 volumes
MediaDescriptor db 0f8h
SectorsPerFat dw 0 ;9 - Always zero for FAT32 volumes
SectorsPerTrack dw 18
NumberOfHeads dw 2
HiddenSectors dd 0
TotalSectorsBig dd 0
BootDrive db 80h
Reserved db 0
ExtendSig db 29h
SerialNumber dd 00000000h
VolumeLabel db 'NO NAME '
FileSystem db 'FAT16 '
main:
00007C3E 33C9 xor cx,cx
00007C40 8ED1 mov ss,cx ; Setup stack
00007C42 BCF07B mov sp,0x7bf0 ; Give us 16 bytes (4 dwords) of space above stack
00007C45 8ED9 mov ds,cx
00007C47 B80020 mov ax,0x2000
00007C4A 8EC0 mov es,ax ; Setup ES:0000 == 2000:0000
00007C4C FC cld
00007C4D BD007C mov bp,0x7c00
00007C50 384E24 cmp [bp+BootDrive],cl ; Compare the boot drive to zero (I think they are testing for a hard disk drive number)
00007C53 7D24 jnl floppy_boot ; Nope, it's a floppy, skip partition table tests
00007C55 8BC1 mov ax,cx ; Move zero to AX
00007C57 99 cwd ; DX:AX now contains zero
00007C58 E83C01 call read_one_sector ; Try to read in the MBR sector
00007C5B 721C jc floppy_boot ; Read failed, continue
00007C5D 83EB3A sub bx,byte +0x3a ; BX comes back with 512, make it equal to 454 (offset of partition table in MBR)
00007C60 66A11C7C mov eax,[HiddenSectors] ; Put HiddenSectors in EAX
find_our_partition:
00007C64 26663B07 cmp eax,[es:bx] ; Compare partition table entry's start sector to HiddenSectors
00007C68 268A57FC mov dl,[es:bx-0x4] ; Get partition type byte for this entry
00007C6C 7506 jnz next_partition_entry ; If partition start sector != HiddenSectors then skip this entry
00007C6E 80CA02 or dl,0x2 ; Set the second bit in partition type?? I guess this makes types 4 & 6 identical
00007C71 885602 mov [bp+0x2],dl ; Save it on top of nop instruction (3rd byte of boot sector)
next_partition_entry:
00007C74 80C310 add bl,0x10 ; Add 16 to bl (offset of next entry in partition table)
00007C77 73EB jnc find_our_partition ; Jump back until we hit the end of the partition table
; We now have our partition type at 0000:7C02
; If the type was 4 or 6 then that byte is 6
; I can't imagine why the boot sector needs to store
; this information, but hopefully I will uncover it
; as I further disassemble this boot sector.
floppy_boot:
00007C79 33C9 xor cx,cx ; Zero out CX
00007C7B 8A4610 mov al,[bp+NumberOfFats] ; Get the number of FATs in AL (usually 2)
00007C7E 98 cbw ; Sign extend it into AX (AX == 2)
00007C7F F76616 mul word [bp+NumberOfFats] ; Multiply it with NumberOfFats PLUS the low byte of MaxRootEntries!!??
00007C82 03461C add ax,[bp+HiddenSectors] ; Result is in DX:AX
00007C85 13561E adc dx,[bp+HiddenSectors+2] ; Add HiddenSectors to DX:AX
00007C88 03460E add ax,[bp+ReservedSectors] ; Add ReservedSectors to DX:AX
00007C8B 13D1 adc dx,cx ; CX still contains zero
00007C8D 8B7611 mov si,[bp+MaxRootEntries] ; Get MaxRootEntries in SI
00007C90 60 pusha ; Save all registers (right now DX:AX has starting sector of root dir)
00007C91 8946FC mov [bp-0x4],ax ; Save the starting sector of the root directory
00007C94 8956FE mov [bp-0x2],dx ; Save it in the first 4 bytes before the boot sector
00007C97 B82000 mov ax,0x20 ; AX == 32 (size of a directory entry)
00007C9A F7E6 mul si ; Multiply it with MaxRootEntries (DX:AX == length in bytes of root directory)
00007C9C 8B5E0B mov bx,[bp+BytesPerSector] ; Get the BytesPerSector in BX
00007C9F 03C3 add ax,bx ; Add it to AX (what if this addition carries? MS should 'adc dx,0' shouldn't they?)
00007CA1 48 dec ax ; Subtract one (basically rounding up)
00007CA2 F7F3 div bx ; Divide DX:AX (length of root dir in bytes) by the size of a sector
00007CA4 0146FC add [bp-0x4],ax ; Add the number of sectors of the root directory to our other value
00007CA7 114EFE adc [bp-0x2],cx ; Now the first 4 bytes before the boot sector contain the starting sector of the data area
00007CAA 61 popa ; Restore all registers (DX:AX has start sector of root dir)
load_root_dir_sector:
00007CAB BF0000 mov di,0x0 ; Zero out di
00007CAE E8E600 call read_one_sector ; Read the first sector of the root directory
00007CB1 7239 jc print_disk_error_message ; Read failed, print disk error and reboot
search_directory:
00007CB3 26382D cmp [es:di],ch ; If the first byte of the directory entry is zero then we have reached the end
00007CB6 7417 jz print_ntldr_error_message; of the directory and NTLDR is not here so reboot
00007CB8 60 pusha ; Save all registers
00007CB9 B10B mov cl,0xb ; Put 11 in cl (length of filename in directory entry)
00007CBB BEA17D mov si,NTLDR ; Put offset of filename string in DS:SI
00007CBE F3A6 repe cmpsb ; Compare this directory entry against 'NTLDR '
00007CC0 61 popa ; Restore all the registers
00007CC1 7432 jz found_ntldr ; If we found NTLDR then jump
00007CC3 4E dec si ; SI holds MaxRootEntries, subtract one
00007CC4 7409 jz print_ntldr_error_message; If we are out of root dir entries then reboot
00007CC6 83C720 add di,byte +0x20 ; Increment DI by the size of a directory entry
00007CC9 3BFB cmp di,bx ; Compare DI to BX (DI has offset to next dir entry, BX has address of end of directory sector in memory)
00007CCB 72E6 jc search_directory ; If DI is less than BX loop again
00007CCD EBDC jmp short load_root_dir_sector ; Didn't find NTLDR in this directory sector, try again
print_ntldr_error_message:
00007CCF A0FB7D mov al,[NTLDR_ERR_offset_from_0x7d00]
putchars:
00007CD2 B47D mov ah,0x7d
00007CD4 8BF0 mov si,ax
get_another_char:
00007CD6 AC lodsb
00007CD7 98 cbw
00007CD8 40 inc ax
00007CD9 740C jz print_reboot_message
00007CDB 48 dec ax
00007CDC 7413 jz reboot
00007CDE B40E mov ah,0xe
00007CE0 BB0700 mov bx,0x7
00007CE3 CD10 int 0x10
00007CE5 EBEF jmp short get_another_char
print_reboot_message:
00007CE7 A0FD7D mov al,[RESTART_ERR_offset_from_0x7d00]
00007CEA EBE6 jmp short putchars
print_disk_error_message:
00007CEC A0FC7D mov al,[DISK_ERR_offset_from_0x7d00]
00007CEF EBE1 jmp short putchars
reboot:
00007CF1 CD16 int 0x16
00007CF3 CD19 int 0x19
found_ntldr:
00007CF5 268B551A mov dx,[es:di+0x1a] ; Get NTLDR start cluster in DX
00007CF9 52 push dx ; Save it on the stack
00007CFA B001 mov al,0x1 ; Read 1 cluster? Or is this one sector?
00007CFC BB0000 mov bx,0x0 ; ES:BX is the load address (2000:0000)
00007CFF E83B00 call read_cluster ; Do the read
00007D02 72E8 jc print_disk_error_message ; If it failed then reboot
00007D04 5B pop bx ; Get the start cluster of NTLDR in BX
00007D05 8A5624 mov dl,[bp+BootDrive] ; Get boot drive in DL
00007D08 BE0B7C mov si,0x7c0b
00007D0B 8BFC mov di,sp
00007D0D C746F03D7D mov word [bp-0x10],read_cluster
00007D12 C746F4297D mov word [bp-0xc],0x7d29
00007D17 8CD9 mov cx,ds
00007D19 894EF2 mov [bp-0xe],cx
00007D1C 894EF6 mov [bp-0xa],cx
00007D1F C606967DCB mov byte [0x7d96],0xcb
00007D24 EA03000020 jmp 0x2000:0x3
00007D29 0FB6C8 movzx cx,al
00007D2C 668B46F8 mov eax,[bp-0x8]
00007D30 6603461C add eax,[bp+HiddenSectors]
00007D34 668BD0 mov edx,eax
00007D37 66C1EA10 shr edx,0x10
00007D3B EB5E jmp short 0x7d9b
read_cluster:
00007D3D 0FB6C8 movzx cx,al
00007D40 4A dec dx
00007D41 4A dec dx
00007D42 8A460D mov al,[bp+SectsPerCluster]
00007D45 32E4 xor ah,ah
00007D47 F7E2 mul dx
00007D49 0346FC add ax,[bp-0x4]
00007D4C 1356FE adc dx,[bp-0x2]
00007D4F EB4A jmp short 0x7d9b
read_sectors:
00007D51 52 push dx
00007D52 50 push ax
00007D53 06 push es
00007D54 53 push bx
00007D55 6A01 push byte +0x1
00007D57 6A10 push byte +0x10
00007D59 91 xchg ax,cx
00007D5A 8B4618 mov ax,[bp+SectorsPerTrack]
00007D5D 96 xchg ax,si
00007D5E 92 xchg ax,dx
00007D5F 33D2 xor dx,dx
00007D61 F7F6 div si
00007D63 91 xchg ax,cx
00007D64 F7F6 div si
00007D66 42 inc dx
00007D67 87CA xchg cx,dx
00007D69 F7761A div word [bp+NumberOfHeads]
00007D6C 8AF2 mov dh,dl
00007D6E 8AE8 mov ch,al
00007D70 C0CC02 ror ah,0x2
00007D73 0ACC or cl,ah
00007D75 B80102 mov ax,0x201
00007D78 807E020E cmp byte [bp+0x2],0xe
00007D7C 7504 jnz 0x7d82
00007D7E B442 mov ah,0x42
00007D80 8BF4 mov si,sp
00007D82 8A5624 mov dl,[bp+BootDrive]
00007D85 CD13 int 0x13
00007D87 61 popa
00007D88 61 popa
00007D89 720B jc 0x7d96
00007D8B 40 inc ax
00007D8C 7501 jnz 0x7d8f
00007D8E 42 inc dx
00007D8F 035E0B add bx,[bp+BytesPerSector]
00007D92 49 dec cx
00007D93 7506 jnz 0x7d9b
00007D95 F8 clc
00007D96 C3 ret
read_one_sector:
00007D97 41 inc cx
00007D98 BB0000 mov bx,0x0
00007D9B 60 pusha
00007D9C 666A00 o32 push byte +0x0
00007D9F EBB0 jmp short 0x7d51
NTLDR db 'NTLDR '
NTLDR_ERR db 0dh,0ah,'NTLDR is missing',0ffh
DISK_ERR db 0dh,0ah,'Disk error',0ffh
RESTART_ERR db 0dh,0ah,'Press any key to restart',0dh,0ah
filler times 18 db 0
NTLDR_offset_from_0x7d00 db 0
NTLDR_ERR_offset_from_0x7d00 db 0ach
DISK_ERR_offset_from_0x7d00 db 0bfh
RESTART_ERR_offset_from_0x7d00 db 0cch
dw 0
dw 0aa55h

View File

@@ -1,295 +0,0 @@
#
# FreeLoader
# Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#############################################
# CHANGE THESE FOR YOUR OUTPUT
#
TARGET = i386
# Debugging information on (bigger binary)
DEBUG = yes
# Debugging information off (smaller binary)
#DEBUG = no
OBJDIR = obj
OUTPUT_DIR = $(OBJDIR)/$(TARGET)
#############################################
# COMPILER AND LINKER PROGRAMS
#
TOOLSDIR = $(SRCDIR)/../tools
CC = gcc
LD = ld
AR = ar
NM = nm
RM = $(TOOLSDIR)/rdel
CP = $(TOOLSDIR)/rcopy
MKDIR = $(TOOLSDIR)/rmkdir
RMDIR = $(TOOLSDIR)/rrmdir
NASM_CMD = nasm
OBJCOPY = objcopy
DEPTOOL = $(TOOLSDIR)/deptool
HOSTTOOL = $(TOOLSDIR)/hosttype
TOOLS = $(DEPTOOL) $(HOSTTOOL)
HOST = $(shell $(HOSTTOOL))
#-----------------------------------------------------------------------------------------------------
# TEST IF WE ARE IN THE TARGET DIRECTORY
# IF NOT WE WILL CHANGE TO THE TARGET DIRECTORY AND RUN MAKE FROM THERE
#-----------------------------------------------------------------------------------------------------
#ifeq (,$(filter $(CURDIR)/$(OUTPUT_DIR),$(notdir $(CURDIR))))
ifneq ($(CURDIR), $(SRCDIR)/$(OUTPUT_DIR))
SRCDIR = $(CURDIR)
.SUFFIXES:
#############################################
# VARIABLE TO CHANGE TO TARGET DIRECTORY AND INVOKE MAKE FROM THERE
#
MAKETARGET = $(MAKE) --no-print-directory -C $(OUTPUT_DIR) \
-f ../../Makefile SRCDIR=$(CURDIR) $(MAKECMDGOALS)
.PHONY: CHANGE_TO_TARGET
CHANGE_TO_TARGET: $(OBJDIR) $(OBJDIR)/$(TARGET)
@$(MAKE) --no-print-directory -C $(TOOLSDIR)
@echo Calculating source file dependencies...
+@$(MAKETARGET)
$(OBJDIR):
@echo Creating directory: $(OBJDIR)
@$(MKDIR) $(OBJDIR)
$(OBJDIR)/$(TARGET): $(OBJDIR)
@echo Creating directory: $(OBJDIR)/$(TARGET)
@$(MKDIR) $(OBJDIR)/$(TARGET)
Makefile : ;
% :: CHANGE_TO_TARGET
#############################################
.PHONY : clean
clean:
@$(MAKE) --no-print-directory -C $(TOOLSDIR)
@echo Cleaning directory $(OBJDIR)/$(TARGET)
@-$(RM) $(OBJDIR)/$(TARGET)/*
@echo Removing directory $(OBJDIR)/$(TARGET)
@-$(RMDIR) $(OBJDIR)/$(TARGET)
@-$(RMDIR) $(OBJDIR)
@echo Clean ALL done.
#############################################
#-----------------------------------------------------------------------------------------------------
# END MAGIC TARGET DIRECTORY CHANGE STUFF
#-----------------------------------------------------------------------------------------------------
else
#############################################
# COMPILER COMMAND LINE OPTIONS
#
COMPILER_OPTIONS = -Wall -nostdlib -nostdinc -fno-builtin -O1 -MD
#############################################
# COMPILER DEFINES
#
ifeq ($(DEBUG),yes)
COMPILER_DEFINES = -DDEBUG
else
COMPILER_DEFINES =
endif
#############################################
# INCLUDE DIRECTORY OPTIONS
#
COMPILER_INCLUDES = -I$(SRCDIR)/include
#############################################
# COMPILER FLAGS
#
CFLAGS = $(COMPILER_OPTIONS) \
$(COMPILER_DEFINES) \
$(COMPILER_INCLUDES)
#############################################
# LINKER COMMAND LINE OPTIONS
#
#LINKER_OPTIONS = -N -Ttext=0x8000 --oformat=binary -s
LINKER_OPTIONS = -N -Ttext=0x8000 -s
#############################################
# LINKER FLAGS
#
LFLAGS = $(LINKER_OPTIONS)
#############################################
# NASM FLAGS
#
ifeq ($(HOST), dos)
NASMFLAGS = -f coff
else
ifeq ($(HOST), win32)
NASMFLAGS = -f win32
else
NASMFLAGS = -f elf
endif
endif
#############################################
# LIST ALL THE OBJECT FILE GROUPS
#
# fathelp.o must come first in the link line because it contains bootsector helper code
# arch.o must come second in the link line because it contains the startup code
ARCH_OBJS = fathelp.o \
arch.o \
i386idt.o \
i386trap.o \
boot.o \
linux.o \
mb.o \
mem.o \
diskint13.o \
rtlcode.o \
biosvid.o
RTL_OBJS = memory.o \
print.o \
stdlib.o \
string.o \
list.o
FS_OBJS = fs.o \
fat.o \
iso.o
UI_OBJS = tui.o \
tuimenu.o \
ui.o \
gui.o
REACTOS_OBJS= reactos.o \
arcname.o \
hwdetect.o \
reghive.o \
registry.o
COMM_OBJS = rs232.o \
portio.o
DISK_OBJS = disk.o \
geometry.o \
partition.o
MM_OBJS = mm.o \
meminit.o
CACHE_OBJS = cache.o \
blocklist.o
INIFILE_OBJS= inifile.o \
ini_init.o \
parse.o
VIDEO_OBJS = video.o \
vidmode.o
FREELDR_OBJS= freeldr.o \
miscboot.o \
options.o \
linuxboot.o \
multiboot.o \
debug.o \
oslist.o \
version.o
#############################################
# ALL THE OBJECTS
#
OBJS = $(ARCH_OBJS) \
$(RTL_OBJS) \
$(FS_OBJS) \
$(UI_OBJS) \
$(REACTOS_OBJS) \
$(COMM_OBJS) \
$(DISK_OBJS) \
$(MM_OBJS) \
$(CACHE_OBJS) \
$(INIFILE_OBJS) \
$(VIDEO_OBJS) \
$(FREELDR_OBJS)
#############################################
# SET THE VPATH SO MAKE CAN FIND THE SOURCE FILES
#
VPATH = $(SRCDIR)/ \
$(SRCDIR)/arch/$(TARGET) \
$(SRCDIR)/rtl \
$(SRCDIR)/fs \
$(SRCDIR)/ui \
$(SRCDIR)/reactos \
$(SRCDIR)/comm \
$(SRCDIR)/disk \
$(SRCDIR)/mm \
$(SRCDIR)/cache \
$(SRCDIR)/inifile \
$(SRCDIR)/video \
$(SRCDIR)/include
#############################################
all : freeldr.sys
@echo Make ALL done.
#############################################
freeldr.sys : $(OBJS)
@echo ===================================================== LINKING $@
# @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o freeldr.sys $(OBJS)
@$(LD) $(LFLAGS) -Map freeldr.map -o freeldr.exe $(OBJS)
@$(OBJCOPY) -O binary freeldr.exe freeldr.sys
#############################################
%.o :: %.c
@echo ===================================================== Compiling $*
@$(CC) $(CFLAGS) -o $@ -c $<
@$(DEPTOOL) $*.d
%.o :: %.S
@echo ===================================================== Assembling $*
@$(CC) $(CFLAGS) -o $@ -c $<
@$(DEPTOOL) $*.d
%.o :: %.asm
@echo ===================================================== Assembling $*
@$(NASM_CMD) $(NASMFLAGS) -o $@ $<
#############################################
# Include the automagically generated dependencies
-include $(OBJS:%.o=%.d)
#############################################
endif

View File

@@ -1,293 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
EXTERN(RealEntryPoint)
cli
/* Setup segment registers */
xorw %ax,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movw %ax,%ss
/* Setup a stack */
movw stack16,%sp
sti
/* Init pmode */
call switch_to_prot
.code32
/* Store the boot drive */
movb %dl,(_BootDrive)
/* GO! */
call _BootMain
call switch_to_real
.code16
int $0x19
/* We should never get here */
stop:
jmp stop
/*
* Switches the processor to protected mode
* it destroys eax
*/
EXTERN(switch_to_prot)
.code16
cli /* None of these */
/* Get the return address off the stack */
popw (code32ret)
/* Save 16-bit stack pointer */
movw %sp,stack16
/* Load the GDT */
lgdt gdtptr
/* Load the IDT */
lidt i386idtptr
/* Enable Protected Mode */
mov %cr0,%eax
orl $CR0_PE_SET,%eax
mov %eax,%cr0
/* Clear prefetch queue & correct CS */
ljmp $PMODE_CS, $inpmode
.code32
inpmode:
/* Setup segment selectors */
movw $PMODE_DS,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movw %ax,%ss
movl stack32,%esp
/* Put the return address back onto the stack */
pushl (code32ret)
/* Now return in p-mode! */
ret
/*
* Switches the processor back to real mode
* it destroys eax
*/
EXTERN(switch_to_real)
.code32
/* Get the return address off the stack */
popl (code16ret)
/* Save 32-bit stack pointer */
movl %esp,stack32
/* jmp to 16-bit segment to set the limit correctly */
ljmp $RMODE_CS, $switch_to_real16
switch_to_real16:
.code16
/* Restore segment registers to correct limit */
movw $RMODE_DS,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movw %ax,%ss
/* Disable Protected Mode */
mov %cr0,%eax
andl $CR0_PE_CLR,%eax
mov %eax,%cr0
/* Clear prefetch queue & correct CS */
ljmp $0, $inrmode
inrmode:
movw %cs,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movw %ax,%ss
movw stack16,%sp
/* Put the return address back onto the stack */
pushw (code16ret)
/* Load IDTR with real mode value */
lidt rmode_idtptr
sti /* These are ok now */
/* Now return in r-mode! */
ret
/*
* Needed for enabling the a20 address line
*/
.code16
empty_8042:
.word 0x00eb,0x00eb // jmp $+2, jmp $+2
inb $0x64,%al
testb $0x02,%al
jnz empty_8042
ret
/*
* Enable the A20 address line (to allow access to over 1mb)
*/
EXTERN(_EnableA20)
.code32
pushal
call switch_to_real
.code16
call empty_8042
movb $0xD1,%al // command write
outb %al,$0x64
call empty_8042
mov $0xDF,%al // A20 on
out %al,$0x60
call empty_8042
call switch_to_prot
.code32
popal
ret
/*
* Disable the A20 address line
*/
EXTERN(_DisableA20)
.code32
pushal
call switch_to_real
.code16
call empty_8042
movb $0xD1,%al // command write
outb %al,$0x64
call empty_8042
mov $0xDD,%al // A20 off
out %al,$0x60
call empty_8042
call switch_to_prot
.code32
popal
ret
/* 16-bit stack pointer */
stack16:
.word STACK16ADDR
/* 32-bit stack pointer */
stack32:
.long STACK32ADDR
/* 16-bit return address */
code16ret:
.long 0
/* 32-bit return address */
code32ret:
.long 0
.p2align 2 /* force 4-byte alignment */
gdt:
/* NULL Descriptor */
.word 0x0000
.word 0x0000
.word 0x0000
.word 0x0000
/* 32-bit flat CS */
.word 0xFFFF
.word 0x0000
.word 0x9A00
.word 0x00CF
/* 32-bit flat DS */
.word 0xFFFF
.word 0x0000
.word 0x9200
.word 0x00CF
/* 16-bit real mode CS */
.word 0xFFFF
.word 0x0000
.word 0x9E00
.word 0x0000
/* 16-bit real mode DS */
.word 0xFFFF
.word 0x0000
.word 0x9200
.word 0x0000
/* GDT table pointer */
gdtptr:
.word 0x27 /* Limit */
.long gdt /* Base Address */
/* Real-mode IDT pointer */
rmode_idtptr:
.word 0x3ff /* Limit */
.long 0 /* Base Address */
EXTERN(_BootDrive)
.long 0

View File

@@ -1,588 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
* Portions from Linux video.S - Display adapter & video mode setup, version 2.13 (14-May-99)
* Copyright (C) 1995 -- 1999 Martin Mares <mj@ucw.cz>
* Based on the original setup.S code (C) Linus Torvalds and Mats Anderson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
/*
* VOID BiosSetVideoMode(ULONG VideoMode);
*/
BiosVideoMode:
.long 0
EXTERN(_BiosSetVideoMode)
.code32
pushal
/* Get BIOS video mode */
movl 0x24(%esp),%eax
movl %eax,BiosVideoMode
call switch_to_real
.code16
/* Int 0x10, AH = 0x00 - Set Current Video Mode, also clears the screen */
movb $0x00,%ah
movb BiosVideoMode,%al
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSetVideoFont8x8(VOID);
*/
EXTERN(_BiosSetVideoFont8x8)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1112 - Load 8x8 Font */
movw $0x1112,%ax
xorb %bl,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSetVideoFont8x14(VOID);
*/
EXTERN(_BiosSetVideoFont8x14)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1111 - Load 8x16 Font */
movw $0x1111,%ax
xorb %bl,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSetVideoFont8x16(VOID);
*/
EXTERN(_BiosSetVideoFont8x16)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1114 - Load 8x16 Font */
movw $0x1114,%ax
xorb %bl,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSelectAlternatePrintScreen(VOID);
*/
EXTERN(_BiosSelectAlternatePrintScreen)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AH = 0x12 - Select alternate print screen routine */
movb $0x12,%ah
movb $0x20,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosDisableCursorEmulation(VOID);
*/
EXTERN(_BiosDisableCursorEmulation)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AH = 0x12 - Disable cursor emulation */
movw $0x1201,%ax
movb $0x34,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosDefineCursor(ULONG StartScanLine, ULONG EndScanLine);
*/
BiosDefineCursorStartScanLine:
.long 0
BiosDefineCursorEndScanLine:
.long 0
EXTERN(_BiosDefineCursor)
.code32
pushal
/* Get cursor scan line positions */
movl 0x24(%esp),%eax
movl %eax,BiosDefineCursorStartScanLine
movl 0x28(%esp),%eax
movl %eax,BiosDefineCursorEndScanLine
call switch_to_real
.code16
/* Int 0x10, AH = 0x01 - Set Text-Mode Cursor Shape */
movb $0x01,%ah
movb $0x03,%al // Current video mode in AL for buggy AMI 386 BIOS
movb BiosDefineCursorStartScanLine,%ch
movb BiosDefineCursorEndScanLine,%cl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* ULONG BiosDetectVideoCard(VOID);
*/
BiosDetectVideoCardReturnValue:
.long 0
EXTERN(_BiosDetectVideoCard)
.code32
pushal
movl $0x00,BiosDetectVideoCardReturnValue
call switch_to_real
.code16
/* Int 0x10, AH = 0x12 - Get EGA Info */
movb $0x12,%ah
movb $0x10,%bl
int $0x10
movl $0x00,BiosDetectVideoCardReturnValue
cmpb $0x10,%bl
je BiosDetectVideoCardDone
/* Int 0x10, AX = 0x1A00 - Get Display Combination Code */
movw $0x1a00,%ax
int $0x10
cmpb $0x1a,%al
je BiosDetectVideoCardVga
movl $0x01,BiosDetectVideoCardReturnValue
jmp BiosDetectVideoCardDone
BiosDetectVideoCardVga:
movl $0x02,BiosDetectVideoCardReturnValue
BiosDetectVideoCardDone:
call switch_to_prot
.code32
popal
movl BiosDetectVideoCardReturnValue,%eax
ret
/*
* VOID BiosSet200ScanLines(VOID);
*/
EXTERN(_BiosSet200ScanLines)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1200 - Set Vertical Resolution */
movw $0x1200,%ax
movb $0x30,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSet350ScanLines(VOID);
*/
EXTERN(_BiosSet350ScanLines)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1201 - Set Vertical Resolution */
movw $0x1201,%ax
movb $0x30,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSet400ScanLines(VOID);
*/
EXTERN(_BiosSet400ScanLines)
.code32
pushal
call switch_to_real
.code16
/* Int 0x10, AX = 0x1202 - Set Vertical Resolution */
movw $0x1202,%ax
movb $0x30,%bl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSet480ScanLines(VOID);
*/
EXTERN(_BiosSet480ScanLines)
.code32
pushal
call switch_to_real
.code16
movw $0x03CC,%dx // Get CRTC port
inb %dx,%al
movb $0xD4,%dl
rorb $0x01,%al
jc set48a
movb $0xB4,%dl
set48a:
movw $0x0C11,%ax // Vertical sync end (also unlocks CR0-7)
call outidx
movw $0x0B06,%ax // Vertical total
call outidx
movw $0x3E07,%ax // (vertical) overflow
call outidx
movw $0xEA10,%ax // Vertical sync start
call outidx
movw $0xDF12,%ax // Vertical display end
call outidx
movw $0xE715,%ax // Vertical blank start
call outidx
movw $0x0416,%ax // Vertical blank end
call outidx
push %dx
movb $0xCC,%dl // Misc output register (read)
inb %dx,%al
movb $0xC2,%dl // (write)
andb $0x0D,%al // Preserve clock select bits and color bit
orb $0xE2,%al // Set correct sync polarity
outb %al,%dx
pop %dx
call switch_to_prot
.code32
popal
ret
/*
* VOID BiosSetVideoDisplayEnd(VOID);
*/
EXTERN(_BiosSetVideoDisplayEnd)
.code32
pushal
call switch_to_real
.code16
movw $0x03CC,%dx // Get CRTC port
inb %dx,%al
movb $0xD4,%dl
rorb $0x01,%al
jc set48a
movb $0xB4,%dl
setvde:
movw $0xDF12,%ax // Vertical display end
call outidx
call switch_to_prot
.code32
popal
ret
/*
* Write to indexed VGA register (AL=index, AH=data, DX=index reg. port)
*/
outidx:
.code16
outb %al,%dx
push %ax
movb %ah,%al
incw %dx
outb %al,%dx
decw %dx
pop %ax
ret
/*
* VOID VideoSetTextCursorPosition(ULONG X, ULONG Y);
*/
EXTERN(_VideoSetTextCursorPosition)
.code32
pushal
/* Get cursor positions */
movb 0x24(%esp),%dl
movb 0x28(%esp),%dh
call switch_to_real
.code16
/* Update the cursor position */
movb $2,%ah
movb $0,%bh
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID VideoHideTextCursor(VOID);
*/
EXTERN(_VideoHideTextCursor)
.code32
pushal
call switch_to_real
.code16
/* Hide the cursor */
movb $1,%ah
movw $0x2000,%cx
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* VOID VideoShowTextCursor(VOID);
*/
EXTERN(_VideoShowTextCursor)
.code32
pushal
call switch_to_real
.code16
/* Show the cursor */
movb $1,%ah
movb $0x0d,%ch
movb $0x0e,%cl
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* ULONG VideoGetTextCursorPositionX(VOID);
*/
VideoGetTextCursorPositionXReturnValue:
.long 0
EXTERN(_VideoGetTextCursorPositionX)
.code32
pushal
movl $0x00,VideoGetTextCursorPositionXReturnValue
call switch_to_real
.code16
/* Get the cursor position */
movb $3,%ah
movb $0,%bh
int $0x10
/* Save return value */
movzbl %dl,%edx
movl %edx,VideoGetTextCursorPositionXReturnValue
call switch_to_prot
.code32
popal
/* Restore return value */
movl VideoGetTextCursorPositionXReturnValue,%eax
ret
/*
* ULONG VideoGetTextCursorPositionY(VOID);
*/
VideoGetTextCursorPositionYReturnValue:
.long 0
EXTERN(_VideoGetTextCursorPositionY)
.code32
pushal
movl $0x00,VideoGetTextCursorPositionYReturnValue
call switch_to_real
.code16
/* Get the cursor position */
movb $3,%ah
movb $0,%bh
int $0x10
/* Save return value */
movzbl %dh,%edx
movl %edx,VideoGetTextCursorPositionYReturnValue
call switch_to_prot
.code32
popal
/* Restore return value */
movl VideoGetTextCursorPositionYReturnValue,%eax
ret

View File

@@ -1,46 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
EXTERN(_ChainLoadBiosBootSectorCode)
.code32
call switch_to_real
.code16
/* Set the boot drive */
movb (_BootDrive),%dl
/* Load segment registers */
cli
movw $0x0000,%bx
movw %bx,%ds
movw %bx,%es
movw %bx,%fs
movw %bx,%gs
movw %bx,%ss
movw $0x7C00,%sp
ljmpl $0x0000,$0x7C00

View File

@@ -1,549 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
/*
* BOOL BiosInt13Read(ULONG Drive, ULONG Head, ULONG Track, ULONG Sector, ULONG SectorCount, PVOID Buffer);
*/
_biosdisk_drive:
.long 0
_biosdisk_head:
.long 0
_biosdisk_track:
.long 0
_biosdisk_sector:
.long 0
_biosdisk_nsects:
.long 0
_biosdisk_buffer:
.long 0
_biosdisk_retval:
.long 0
_biosdisk_retrycount:
.byte 0
_biosdisk_error_code:
.byte 0
EXTERN(_BiosInt13Read)
.code32
pushal
/* Get parameters */
movl 0x24(%esp),%eax
movl %eax,_biosdisk_drive
movl 0x28(%esp),%eax
movl %eax,_biosdisk_head
movl 0x2c(%esp),%eax
movl %eax,_biosdisk_track
movl 0x30(%esp),%eax
movl %eax,_biosdisk_sector
movl 0x34(%esp),%eax
movl %eax,_biosdisk_nsects
movl 0x38(%esp),%eax
movl %eax,_biosdisk_buffer
call switch_to_real
.code16
pushw %es // Save this just in case
movb $3,_biosdisk_retrycount // Set the retry count to 3
_biosdisk_read:
movl _biosdisk_buffer,%eax // Get buffer address in eax
shrl $4,%eax // Make linear address into segment
movw %ax,%es // Load ES with segment
movl _biosdisk_buffer,%ebx // and BX with offset
andl $0x0f,%ebx // so that data gets loaded to [ES:BX]
movb _biosdisk_sector,%cl // Get the sector in CL
movw _biosdisk_track,%ax // Cylinder in AX
movb %al,%ch // Now put it in CH
rorb $1,%ah // Low 8 bits of cylinder in CH, high 2 bits
rorb $1,%ah // in CL shifted to bits 6 & 7
andb $0xc0,%ah // Clear out low six bits
orb %ah,%cl // Or with sector number
movb _biosdisk_head,%dh // Get the head
movb _biosdisk_drive,%dl // Get the drive
movb $2,%ah // BIOS int 0x13, function 2 - Read Disk Sectors
movb _biosdisk_nsects,%al // Number of sectors to read
int $0x13 // Read a sector
// I have recently learned that not all bioses return
// the sector read count in the AL register (at least mine doesn't)
// even if the sectors were read correctly. So instead
// of checking the sector read count we will rely solely
// on the carry flag being set on error
//jmp _biosdisk_done
//cmpb _biosdisk_nsects,%al // See how many sectors we actually read
//jne _biosdisk_error // Jump if no error
movb $1,%al // Set the return value to be one (will be set to zero later if needed)
jc _biosdisk_error // Jump if error (CF = 1 on error)
jmp _biosdisk_done
_biosdisk_error:
movb %ah,_biosdisk_error_code// Save the error code
cmpb $0x11,%ah // Check and see if it was a corrected ECC error
je _biosdisk_done // If so then the data is still good, if not fail
movb _biosdisk_retrycount,%al// Get the current retry count
decb %al // Decrement it
movb %al,_biosdisk_retrycount// Save it
cmpb $0,%al // Is it zero?
jz _biosdisk_zero // Yes, return zero
movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System
movb _biosdisk_drive,%dl // Get the drive
int $0x13 // Reset the disk system
jmp _biosdisk_read // Try reading again
_biosdisk_zero:
movb $0,%al // We will return zero
_biosdisk_done:
movzbl %al,%eax // Put the number of sectors read into EAX
movl %eax,_biosdisk_retval // Save it as the return value
popw %es // Restore ES
call switch_to_prot
.code32
popal
movl _biosdisk_retval,%eax // Get return value
//movl $1,%eax
ret
/*
* BOOL BiosInt13ReadExtended(ULONG Drive, ULONG Sector, ULONG SectorCount, PVOID Buffer);
*/
_disk_address_packet:
_packet_size:
.byte 0x10
_packet_reserved:
.byte 0
_packet_sector_count:
.word 0
_packet_transfer_buffer_offset:
.word 0
_packet_transfer_buffer_segment:
.word 0
_packet_lba_sector_number:
.quad 0
_packet_64bit_flat_address:
.quad 0
_int13_extended_drive:
.long 0
_int13_extended_sector_count:
.long 0
_int13_extended_retval:
.long 0
_int13_extended_retrycount:
.byte 0
EXTERN(_BiosInt13ReadExtended)
.code32
pushal
/* Get parameters */
movl 0x24(%esp),%eax
movl %eax,_int13_extended_drive
movl 0x28(%esp),%eax
movl %eax,_packet_lba_sector_number
movl 0x2c(%esp),%eax
movw %ax,_packet_sector_count
movl %eax,_int13_extended_sector_count
movl 0x30(%esp),%eax // Get buffer address in eax
shrl $4,%eax // Make linear address into segment
movw %ax,_packet_transfer_buffer_segment // Save segment
movl 0x34(%esp),%eax // Get buffer address in eax
andl $0x0f,%eax // Make linear address into offset
movw %ax,_packet_transfer_buffer_offset // Save offset
call switch_to_real
.code16
pushw %es // Save this just in case
movb $3,_int13_extended_retrycount // Set the retry count to 3
_int13_extended_read:
movb _int13_extended_drive,%dl // Get the drive
movb $0x42,%ah // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ
movw $_disk_address_packet,%si // DS:SI -> disk address packet
int $0x13 // Read sectors
jc _int13_extended_error // Jump if error (CF = 1 on error)
movl _int13_extended_sector_count,%eax // Get the sector count in eax
cmpw _packet_sector_count,%ax // See how many sectors we actually read (returned in disk address packet sector count)
jne _int13_extended_error // Jump if not equal
jmp _int13_extended_done
_int13_extended_error:
movb %ah,_biosdisk_error_code // Save the error code
cmpb $0x11,%ah // Check and see if it was a corrected ECC error
je _int13_extended_done // If so then the data is still good, if not fail
movb _int13_extended_retrycount,%al // Get the current retry count
decb %al // Decrement it
movb %al,_int13_extended_retrycount // Save it
cmpb $0,%al // Is it zero?
jz _int13_extended_zero // Yes, return zero
movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System
movb _int13_extended_drive,%dl // Get the drive
int $0x13 // Reset the disk system
jmp _int13_extended_read // Try reading again
_int13_extended_zero:
movb $0,%al // We will return zero
_int13_extended_done:
movzbl %al,%eax // Put the number of sectors read into EAX
movl %eax,_int13_extended_retval // Save it as the return value
popw %es // Restore ES
call switch_to_prot
.code32
popal
movl _int13_extended_retval,%eax // Get return value
ret
/*
* BOOL BiosInt13ExtensionsSupported(ULONG Drive);
*/
_int13_extension_check_drive:
.long 0
_int13_extension_check_retval:
.long 0
EXTERN(_BiosInt13ExtensionsSupported)
.code32
pushal
/* Get parameters */
movl 0x24(%esp),%eax
movl %eax,_int13_extension_check_drive
call switch_to_real
.code16
// Now make sure this computer supports extended reads
movb $0x41,%ah // AH = 41h
movw $0x55aa,%bx // BX = 55AAh
movb _int13_extension_check_drive,%dl // DL = drive (80h-FFh)
int $0x13 // IBM/MS INT 13 Extensions - INSTALLATION CHECK
jc _int13_extension_check_error // CF set on error (extensions not supported)
cmpw $0xaa55,%bx // BX = AA55h if installed
jne _int13_extension_check_error
testb $1,%cl // CX = API subset support bitmap
jz _int13_extension_check_error // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
// If we get here then we passed all the int13 extension tests
movl $1,_int13_extension_check_retval // Set return value to TRUE
jmp _int13_extension_check_done
_int13_extension_check_error:
movl $0,_int13_extension_check_retval // The tests failed so return FALSE
_int13_extension_check_done:
call switch_to_prot
.code32
popal
movl _int13_extension_check_retval,%eax // Get return value
ret
/*
* ULONG BiosInt13GetLastErrorCode(VOID);
*/
EXTERN(_BiosInt13GetLastErrorCode)
.code32
movzbl _biosdisk_error_code,%eax // Get return value
ret
/*
* void StopFloppyMotor(void);
*
* Stops the floppy drive from spinning, so that other software is
* jumped to with a known state.
*/
EXTERN(_StopFloppyMotor)
.code32
pushal
call switch_to_real
.code16
movw $0x3F2, %dx
xorb %al, %al
outb %al, %dx
call switch_to_prot
.code32
popal
ret
/*
* int get_heads(int drive);
*/
EXTERN(_get_heads)
.code32
pushal
push %es
/* Get drive */
movl 0x28(%esp),%eax
movl %eax,_biosdisk_drive
call switch_to_real
.code16
movb $0x08,%ah
movb _biosdisk_drive,%dl
int $0x13
jc _get_heads_error
movzbl %dh,%edx
incl %edx
movl %edx,_biosdisk_retval
jmp _get_heads_done
_get_heads_error:
movl $0xff,_biosdisk_retval
_get_heads_done:
call switch_to_prot
.code32
pop %es
popal
movl _biosdisk_retval,%eax // Get return value
ret
/*
* int get_cylinders(int drive);
*/
EXTERN(_get_cylinders)
.code32
pushal
push %es
/* Get drive */
movl 0x28(%esp),%eax
movl %eax,_biosdisk_drive
call switch_to_real
.code16
movb $0x08,%ah
movb _biosdisk_drive,%dl
int $0x13
jc _get_cylinders_error
xorl %edx,%edx
andb $0xc0,%cl
shrb $0x06,%cl
movb %cl,%dh
movb %ch,%dl
incl %edx
movl %edx,_biosdisk_retval
jmp _get_cylinders_done
_get_cylinders_error:
movl $0xff,_biosdisk_retval
_get_cylinders_done:
call switch_to_prot
.code32
pop %es
popal
movl _biosdisk_retval,%eax // Get return value
ret
/*
* int get_sectors(int drive);
*/
EXTERN(_get_sectors)
.code32
pushal
push %es
/* Get drive */
movl 0x28(%esp),%eax
movl %eax,_biosdisk_drive
call switch_to_real
.code16
movb $0x08,%ah
movb _biosdisk_drive,%dl
int $0x13
jc _get_sectors_error
andb $0x3f,%cl
movzbl %cl,%ecx
movl %ecx,_biosdisk_retval
jmp _get_sectors_done
_get_sectors_error:
movl $0xff,_biosdisk_retval
_get_sectors_done:
call switch_to_prot
.code32
pop %es
popal
movl _biosdisk_retval,%eax // Get return value
ret
/*
* BOOL BiosInt13GetDriveParameters(ULONG Drive, PGEOMETRY Geometry);
*/
_bios_int13_cylinders:
.long 0
_bios_int13_heads:
.long 0
_bios_int13_sectors:
.long 0
_bios_int13_bytes_per_sector:
.long 0
_bios_int13_drive_parameters_struct_address:
.long 0
EXTERN(_BiosInt13GetDriveParameters)
.code32
pushal
push %es
/* Get drive */
movl 0x28(%esp),%eax
movl %eax,_biosdisk_drive
movl 0x2c(%esp),%eax
movl %eax,_bios_int13_drive_parameters_struct_address
call switch_to_real
.code16
movb $0x08,%ah
movb _biosdisk_drive,%dl
int $0x13
jc _BiosInt13GetDriveParameters_Error
// Get the heads
movzbl %dh,%eax
incl %eax
movl %eax,_bios_int13_heads
// Get the sectors
movw %cx,%dx
andb $0x3f,%dl
movzbl %dl,%edx
movl %edx,_bios_int13_sectors
// Get the cylinders
xorl %edx,%edx
andb $0xc0,%cl
shrb $0x06,%cl
movb %cl,%dh
movb %ch,%dl
incl %edx
movl %edx,_bios_int13_cylinders
// Get the bytes per sector
movl $512,_bios_int13_bytes_per_sector // Just assume 512 bytes per sector
movl $0x01,_biosdisk_retval
jmp _BiosInt13GetDriveParameters_Done
_BiosInt13GetDriveParameters_Error:
movl $0x00,_biosdisk_retval
_BiosInt13GetDriveParameters_Done:
call switch_to_prot
.code32
// Copy drive parameters to structure
movl $_bios_int13_cylinders,%esi
movl _bios_int13_drive_parameters_struct_address,%edi
movl $0x04,%ecx
cld
rep movsl
pop %es
popal
movl _biosdisk_retval,%eax // Get return value
ret

View File

@@ -1,226 +0,0 @@
; FATHELP.ASM
; FAT12/16 Boot Sector Helper Code
; Copyright (c) 1998, 2001, 2002 Brian Palmer
;org 8000h
segment .text
bits 16
BootSectorStackTop equ 0x7bf2
DataAreaStartHigh equ 0x2
DataAreaStartLow equ 0x4
BiosCHSDriveSize equ 0x6
BiosCHSDriveSizeHigh equ 0x6
BiosCHSDriveSizeLow equ 0x8
ReadSectorsOffset equ 0xa
ReadClusterOffset equ 0xc
PutCharsOffset equ 0xe
OEMName equ 3
BytesPerSector equ 11
SectsPerCluster equ 13
ReservedSectors equ 14
NumberOfFats equ 16
MaxRootEntries equ 17
TotalSectors equ 19
MediaDescriptor equ 21
SectorsPerFat equ 22
SectorsPerTrack equ 24
NumberOfHeads equ 26
HiddenSectors equ 28
TotalSectorsBig equ 32
BootDrive equ 36
Reserved equ 37
ExtendSig equ 38
SerialNumber equ 39
VolumeLabel equ 43
FileSystem equ 54
; This code will be stored in the first 512 bytes
; of freeldr.sys. The first 3 bytes will be a jmp
; instruction to skip past the FAT helper code
; that is stored in the rest of the 512 bytes.
;
; This code is loaded at 0000:8000 so we have to
; encode a jmp instruction to jump to 0000:8200
global start
start:
db 0xe9
db 0xfd
db 0x01
; Now starts the extra boot code that we will store
; in the first 512 bytes of freeldr.sys. This code
; allows the FAT12/16 bootsector to navigate the
; FAT table so that we can still load freeldr.sys
; even if it is fragmented.
FatHelperEntryPoint:
push ax ; First save AX - the start cluster of freeldr.sys
; Display "Loading FreeLoader..." message
mov esi,msgLoading ; Loading message
call [bp-PutCharsOffset] ; Display it
call ReadFatIntoMemory
pop ax ; Restore AX (start cluster)
; AX has start cluster of freeldr.sys
mov bx,800h
mov es,bx
LoadFile:
push ax
call IsFat12
pop ax
jnc LoadFile2
cmp ax,0ff8h ; Check to see if this is the last cluster in the chain
jmp LoadFile3
LoadFile2:
cmp ax,0fff8h
LoadFile3:
jae LoadFile_Done ; If so continue, if not then read then next one
push ax
xor bx,bx ; Load ROSLDR starting at 0000:8000h
push es
call [bp-ReadClusterOffset]
pop es
xor bx,bx
mov bl,BYTE [BYTE bp+SectsPerCluster]
shl bx,5 ; BX = BX * 512 / 16
mov ax,es ; Increment the load address by
add ax,bx ; The size of a cluster
mov es,ax
call IsFat12
pop ax
push es
jnc LoadFile4
call GetFatEntry12 ; Get the next entry
jmp LoadFile5
LoadFile4:
call GetFatEntry16
LoadFile5:
pop es
jmp LoadFile ; Load the next cluster (if any)
LoadFile_Done:
mov dl,BYTE [BYTE bp+BootDrive] ; Load the boot drive into DL
push WORD 0x0000
push WORD 0x8000 ; We will do a far return to 0000:8000h
retf ; Transfer control to ROSLDR
; Reads the entire FAT into memory at 7000:0000
ReadFatIntoMemory:
mov ax,WORD [BYTE bp+HiddenSectors]
mov dx,WORD [BYTE bp+HiddenSectors+2]
add ax,WORD [BYTE bp+ReservedSectors]
adc dx,byte 0
mov cx,WORD [BYTE bp+SectorsPerFat]
mov bx,7000h
mov es,bx
xor bx,bx
call [bp-ReadSectorsOffset]
ret
; Returns the FAT entry for a given cluster number for 16-bit FAT
; On entry AX has cluster number
; On return AX has FAT entry for that cluster
GetFatEntry16:
mov cx,2 ; AX = AX * 2 (since FAT16 entries are 2 bytes)
mul cx
shl dx,0fh
mov bx,7000h
add bx,dx
mov es,bx
mov bx,ax ; Restore FAT entry offset
mov ax,WORD [es:bx] ; Get FAT entry
ret
; Returns the FAT entry for a given cluster number for 12-bit FAT
; On entry AX has cluster number
; On return AX has FAT entry for that cluster
GetFatEntry12:
push ax
mov cx,ax
shr ax,1
add ax,cx ; AX = AX * 1.5 (AX = AX + (AX / 2)) (since FAT12 entries are 12 bits)
mov bx,7000h
mov es,bx
mov bx,ax ; Put FAT entry offset into BX
mov ax,WORD [es:bx] ; Get FAT entry
pop cx ; Get cluster number from stack
and cx,1
jz UseLow12Bits
and ax,0fff0h
shr ax,4
jmp GetFatEntry12_Done
UseLow12Bits:
and ax,0fffh
GetFatEntry12_Done:
ret
; Returns CF = 1 if this is a FAT12 file system
; Otherwise CF = 0 for FAT16
IsFat12:
mov bx,[BYTE bp-DataAreaStartLow]
mov cx,[BYTE bp-DataAreaStartHigh]
; CX:BX now has the number of the starting sector of the data area
xor dx,dx
mov ax,WORD [BYTE bp+TotalSectors]
cmp ax,byte 0
jnz IsFat12_2
mov ax,WORD [BYTE bp+TotalSectorsBig]
mov dx,WORD [BYTE bp+TotalSectorsBig+2]
; DX:AX now contains the number of sectors on the volume
IsFat12_2:
sub ax,bx ; Subtract data area start sector
sub dx,cx ; from total sectors of volume
; DX:AX now contains the number of data sectors on the volume
movzx bx,BYTE [BYTE bp+SectsPerCluster]
div bx
; AX now has the number of clusters on the volume
stc
cmp ax,4085
jb IsFat12_Done
clc
IsFat12_Done:
ret
msgLoading db 'Loading FreeLoader...',0dh,0ah,0
times 510-($-$$) db 0 ; Pad to 510 bytes
dw 0aa55h ; BootSector signature

View File

@@ -1,224 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
.p2align 2 /* force 4-byte alignment */
EXTERN(i386idt)
/* Exception 0 - Divide By Zero */
.word i386DivideByZero /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Flags, Zero Byte */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 1 - Debug Exception */
.word i386DebugException /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 2 - NMI */
.word i386NMIException /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 3 - Breakpoint (INT 3) */
.word i386Breakpoint /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 4 - Overflow (INTO with EFLAGS[OF] set) */
.word i386Overflow /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 5 - Bound Exception */
.word i386BoundException /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 6 - Invalid Opcode */
.word i386InvalidOpcode /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 7 - FPU Not Available */
.word i386FPUNotAvailable /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 8 - Double Fault */
.word i386DoubleFault /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 9 - Coprocessor Segment Overrun */
.word i386CoprocessorSegment /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 10 (0x0A) - Invalid TSS */
.word i386InvalidTSS /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 11 (0x0B) - Segment Not Present */
.word i386SegmentNotPresent /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 12 (0x0C) - Stack Exception */
.word i386StackException /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 13 (0x0D) - General Protection Fault */
.word i386GeneralProtectionFault /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 14 (0x0E) - Page Fault */
.word i386PageFault /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 15 (0x0F) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 16 (0x10) - Coprocessor Error */
.word i386CoprocessorError /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 17 (0x11) - Alignment Check */
.word i386AlignmentCheck /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 18 (0x12) - Machine Check */
.word i386MachineCheck /* Offset 0 - 15 */
.word 0x0008 /* Selector */
.word 0x8e00 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 19 (0x13) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 20 (0x14) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 21 (0x15) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 22 (0x16) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 23 (0x17) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 24 (0x18) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 25 (0x19) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 26 (0x1A) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 27 (0x1B) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 28 (0x1C) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 29 (0x1D) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 30 (0x1E) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* Exception 31 (0x1F) - Reserved */
.word 0x0000 /* Offset 0 - 15 */
.word 0x0000 /* Selector */
.word 0x0000 /* Zero byte, flags */
.word 0x0000 /* Offset 16 - 31 */
/* IDT table pointer */
EXTERN(i386idtptr)
.word (i386idtptr-i386idt) /* Limit */
.long i386idt /* Base Address */

View File

@@ -1,761 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
.macro SAVE_CPU_REGS
movl %eax,i386_EAX
movl %ebx,i386_EBX
movl %ecx,i386_ECX
movl %edx,i386_EDX
movl %esp,i386_ESP
movl %ebp,i386_EBP
movl %esi,i386_ESI
movl %edi,i386_EDI
movw %ds,%ax
movw %ax,i386_DS
movw %es,%ax
movw %ax,i386_ES
movw %fs,%ax
movw %ax,i386_FS
movw %gs,%ax
movw %ax,i386_GS
movw %ss,%ax
movw %ax,i386_SS
popl %eax
movl %eax,i386_EIP
popl %eax
movw %ax,i386_CS
popl %eax
movl %eax,i386_EFLAGS
movl %cr0,%eax
movl %eax,i386_CR0
//movl %cr1,%eax
//movl %eax,i386_CR1
movl %cr2,%eax
movl %eax,i386_CR2
movl %cr3,%eax
movl %eax,i386_CR3
movl %dr0,%eax
movl %eax,i386_DR0
movl %dr1,%eax
movl %eax,i386_DR1
movl %dr2,%eax
movl %eax,i386_DR2
movl %dr3,%eax
movl %eax,i386_DR3
sgdt i386_GDTR
sidt i386_IDTR
sldt i386_LDTR
str i386_TR
.endm
.macro SAVE_CPU_REGS_ERROR_CODE
movl %eax,i386_EAX
movl %ebx,i386_EBX
movl %ecx,i386_ECX
movl %edx,i386_EDX
movl %esp,i386_ESP
movl %ebp,i386_EBP
movl %esi,i386_ESI
movl %edi,i386_EDI
movw %ds,%ax
movw %ax,i386_DS
movw %es,%ax
movw %ax,i386_ES
movw %fs,%ax
movw %ax,i386_FS
movw %gs,%ax
movw %ax,i386_GS
movw %ss,%ax
movw %ax,i386_SS
popl %eax
movl %eax,i386_ERROR_CODE
popl %eax
movl %eax,i386_EIP
popl %eax
movw %ax,i386_CS
popl %eax
movl %eax,i386_EFLAGS
movl %cr0,%eax
movl %eax,i386_CR0
//movl %cr1,%eax
//movl %eax,i386_CR1
movl %cr2,%eax
movl %eax,i386_CR2
movl %cr3,%eax
movl %eax,i386_CR3
movl %dr0,%eax
movl %eax,i386_DR0
movl %dr1,%eax
movl %eax,i386_DR1
movl %dr2,%eax
movl %eax,i386_DR2
movl %dr3,%eax
movl %eax,i386_DR3
sgdt i386_GDTR
sidt i386_IDTR
sldt i386_LDTR
str i386_TR
.endm
i386ExceptionHandlerText:
.ascii "FreeLoader i386 Exception Handler\n"
.asciz "Report bugs to Brian Palmer <brianp@reactos.org>\n\n"
i386DivideByZeroText:
.asciz "Exception 00: DIVIDE BY ZERO\n\n"
i386DebugExceptionText:
.asciz "Exception 01: DEBUG EXCEPTION\n\n"
i386NMIExceptionText:
.asciz "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION\n\n"
i386BreakpointText:
.asciz "Exception 03: BREAKPOINT (INT 3)\n\n"
i386OverflowText:
.asciz "Exception 04: OVERFLOW\n\n"
i386BoundExceptionText:
.asciz "Exception 05: BOUND EXCEPTION\n\n"
i386InvalidOpcodeText:
.asciz "Exception 06: INVALID OPCODE\n\n"
i386FPUNotAvailableText:
.asciz "Exception 07: FPU NOT AVAILABLE\n\n"
i386DoubleFaultText:
.asciz "Exception 08: DOUBLE FAULT\n\n"
i386CoprocessorSegmentText:
.asciz "Exception 09: COPROCESSOR SEGMENT OVERRUN\n\n"
i386InvalidTSSText:
.asciz "Exception 0A: INVALID TSS\n\n"
i386SegmentNotPresentText:
.asciz "Exception 0B: SEGMENT NOT PRESENT\n\n"
i386StackExceptionText:
.asciz "Exception 0C: STACK EXCEPTION\n\n"
i386GeneralProtectionFaultText:
.asciz "Exception 0D: GENERAL PROTECTION FAULT\n\n"
i386PageFaultText:
.asciz "Exception 0E: PAGE FAULT\n\n"
i386CoprocessorErrorText:
.asciz "Exception 10: COPROCESSOR ERROR\n\n"
i386AlignmentCheckText:
.asciz "Exception 11: ALIGNMENT CHECK\n\n"
i386MachineCheckText:
.asciz "Exception 12: MACHINE CHECK\n\n"
i386_EAX_Text:
.asciz "EAX: "
i386_EBX_Text:
.asciz "EBX: "
i386_ECX_Text:
.asciz "ECX: "
i386_EDX_Text:
.asciz "EDX: "
i386_ESP_Text:
.asciz " ESP: "
i386_EBP_Text:
.asciz " EBP: "
i386_ESI_Text:
.asciz " ESI: "
i386_EDI_Text:
.asciz " EDI: "
i386_CS_Text:
.asciz "CS: "
i386_DS_Text:
.asciz "DS: "
i386_ES_Text:
.asciz "ES: "
i386_FS_Text:
.asciz "FS: "
i386_GS_Text:
.asciz "GS: "
i386_SS_Text:
.asciz "SS: "
i386_EFLAGS_Text:
.asciz " EFLAGS: "
i386_EIP_Text:
.asciz " EIP: "
i386_ERROR_CODE_Text:
.asciz " ERROR CODE: "
i386_CR0_Text:
.asciz " CR0: "
i386_CR1_Text:
.asciz " CR1: "
i386_CR2_Text:
.asciz " CR2: "
i386_CR3_Text:
.asciz " CR3: "
i386_DR0_Text:
.asciz " DR0: "
i386_DR1_Text:
.asciz " DR1: "
i386_DR2_Text:
.asciz " DR2: "
i386_DR3_Text:
.asciz " DR3: "
i386_GDTR_Text:
.asciz " GDTR Base: "
i386_IDTR_Text:
.asciz " IDTR Base: "
i386_Limit_Text:
.asciz " Limit: "
i386_LDTR_Text:
.asciz " LDTR: "
i386_TR_Text:
.asciz " TR: "
/* Set by each exception handler to the address of the description text */
i386ExceptionDescriptionText:
.long 0
/* Used to store the contents of all the registers when an exception occurs */
i386_EAX:
.long 0
i386_EBX:
.long 0
i386_ECX:
.long 0
i386_EDX:
.long 0
i386_ESP:
.long 0
i386_EBP:
.long 0
i386_ESI:
.long 0
i386_EDI:
.long 0
i386_CS:
.word 0
i386_DS:
.word 0
i386_ES:
.word 0
i386_FS:
.word 0
i386_GS:
.word 0
i386_SS:
.word 0
i386_EFLAGS:
.long 0
i386_EIP:
.long 0
i386_ERROR_CODE:
.long 0
i386_CR0:
.long 0
i386_CR1:
.long 0
i386_CR2:
.long 0
i386_CR3:
.long 0
i386_DR0:
.long 0
i386_DR1:
.long 0
i386_DR2:
.long 0
i386_DR3:
.long 0
i386_GDTR:
.word 0
.long 0
i386_IDTR:
.word 0
.long 0
i386_LDTR:
.word 0
i386_TR:
.word 0
/* Used to store the current X and Y position on the screen */
i386_ScreenPosX:
.long 0
i386_ScreenPosY:
.long 0
/************************************************************************/
i386CommonExceptionHandler:
.code32
call i386ClearScreenToBlue
movl $i386ExceptionHandlerText,%esi
call i386PrintText
movl i386ExceptionDescriptionText,%esi
call i386PrintText
movl $i386_EAX_Text,%esi
call i386PrintText
movl i386_EAX,%eax
call i386PrintHexDword // Display EAX
movl $i386_ESP_Text,%esi
call i386PrintText
movl i386_ESP,%eax
call i386PrintHexDword // Display ESP
movl $i386_CR0_Text,%esi
call i386PrintText
movl i386_CR0,%eax
call i386PrintHexDword // Display CR0
movl $i386_DR0_Text,%esi
call i386PrintText
movl i386_DR0,%eax
call i386PrintHexDword // Display DR0
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_EBX_Text,%esi
call i386PrintText
movl i386_EBX,%eax
call i386PrintHexDword // Display EBX
movl $i386_EBP_Text,%esi
call i386PrintText
movl i386_EBP,%eax
call i386PrintHexDword // Display EBP
movl $i386_CR1_Text,%esi
call i386PrintText
movl i386_CR1,%eax
call i386PrintHexDword // Display CR1
movl $i386_DR1_Text,%esi
call i386PrintText
movl i386_DR1,%eax
call i386PrintHexDword // Display DR1
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_ECX_Text,%esi
call i386PrintText
movl i386_ECX,%eax
call i386PrintHexDword // Display ECX
movl $i386_ESI_Text,%esi
call i386PrintText
movl i386_ESI,%eax
call i386PrintHexDword // Display ESI
movl $i386_CR2_Text,%esi
call i386PrintText
movl i386_CR2,%eax
call i386PrintHexDword // Display CR2
movl $i386_DR2_Text,%esi
call i386PrintText
movl i386_DR2,%eax
call i386PrintHexDword // Display DR2
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_EDX_Text,%esi
call i386PrintText
movl i386_EDX,%eax
call i386PrintHexDword // Display EDX
movl $i386_EDI_Text,%esi
call i386PrintText
movl i386_EDI,%eax
call i386PrintHexDword // Display EDI
movl $i386_CR3_Text,%esi
call i386PrintText
movl i386_CR3,%eax
call i386PrintHexDword // Display CR3
movl $i386_DR3_Text,%esi
call i386PrintText
movl i386_DR3,%eax
call i386PrintHexDword // Display DR3
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
incl i386_ScreenPosY
movl $i386_CS_Text,%esi
call i386PrintText
movw i386_CS,%ax
call i386PrintHexWord // Display CS
movl $i386_EIP_Text,%esi
call i386PrintText
movl i386_EIP,%eax
call i386PrintHexDword // Display EIP
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_DS_Text,%esi
call i386PrintText
movw i386_DS,%ax
call i386PrintHexWord // Display DS
movl $i386_ERROR_CODE_Text,%esi
call i386PrintText
movl i386_ERROR_CODE,%eax
call i386PrintHexDword // Display ERROR CODE
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_ES_Text,%esi
call i386PrintText
movw i386_ES,%ax
call i386PrintHexWord // Display ES
movl $i386_EFLAGS_Text,%esi
call i386PrintText
movl i386_EFLAGS,%eax
call i386PrintHexDword // Display EFLAGS
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_FS_Text,%esi
call i386PrintText
movw i386_FS,%ax
call i386PrintHexWord // Display FS
movl $i386_GDTR_Text,%esi
call i386PrintText
movl i386_GDTR+2,%eax
call i386PrintHexDword // Display GDTR Base
movl $i386_Limit_Text,%esi
call i386PrintText
movw i386_GDTR,%ax
call i386PrintHexWord // Display GDTR Limit
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_GS_Text,%esi
call i386PrintText
movw i386_GS,%ax
call i386PrintHexWord // Display GS
movl $i386_IDTR_Text,%esi
call i386PrintText
movl i386_IDTR+2,%eax
call i386PrintHexDword // Display IDTR Base
movl $i386_Limit_Text,%esi
call i386PrintText
movw i386_IDTR,%ax
call i386PrintHexWord // Display IDTR Limit
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
movl $i386_SS_Text,%esi
call i386PrintText
movw i386_SS,%ax
call i386PrintHexWord // Display SS
movl $i386_LDTR_Text,%esi
call i386PrintText
movw i386_LDTR,%ax
call i386PrintHexWord // Display LDTR
movl $i386_TR_Text,%esi
call i386PrintText
movw i386_TR,%ax
call i386PrintHexWord // Display TR
movl $0,i386_ScreenPosX
incl i386_ScreenPosY
incl i386_ScreenPosY
i386ExceptionHandlerHang:
jmp i386ExceptionHandlerHang
iret
/************************************************************************/
i386ClearScreenToBlue:
.code32
cld
movw $0x1F20,%ax
movl $0xB0000,%edi
movl $0x8000,%ecx
rep stosw
ret
/************************************************************************/
/* ESI = Address of text to display */
/************************************************************************/
i386PrintText:
.code32
i386PrintTextLoop:
lodsb
// Check for end of string char
cmp $0,%al
je i386PrintTextDone
// Check for newline char
cmp $0x0a,%al
jne i386PrintTextLoop2
incl i386_ScreenPosY
movl $0,i386_ScreenPosX
jmp i386PrintTextLoop
i386PrintTextLoop2:
call i386PrintTextCalcAddressOfNextChar
stosb
incl i386_ScreenPosX
jmp i386PrintTextLoop
i386PrintTextDone:
ret
/************************************************************************/
/* On return EDI = Address of next char in screen memory */
/************************************************************************/
i386PrintTextCalcAddressOfNextChar:
.code32
push %eax
movl $0xB8000,%edi
addl i386_ScreenPosX,%edi
addl i386_ScreenPosX,%edi
movl i386_ScreenPosY,%eax
movl $160,%ecx // 80 columns, 2 bytes per column
mull %ecx
addl %eax,%edi
pop %eax
ret
/************************************************************************/
/* Prints the value in EAX on the screen in hex */
/************************************************************************/
i386PrintHexDword:
.code32
call i386PrintHex1
i386PrintHex1:
call i386PrintHex2
i386PrintHex2:
call i386PrintHex3
i386PrintHex3:
movb $4,%cl
rol %cl,%eax
push %eax
andb $0x0f,%al
movl $i386PrintHexTable,%ebx
xlat /*$i386PrintHexTable*/
call i386PrintTextCalcAddressOfNextChar
stosb
incl i386_ScreenPosX
pop %eax
ret
i386PrintHexTable:
.ascii "0123456789ABCDEF"
/************************************************************************/
/* Prints the value in AX on the screen in hex */
/************************************************************************/
i386PrintHexWord:
.code32
call i386PrintHexWord1
i386PrintHexWord1:
call i386PrintHexWord2
i386PrintHexWord2:
movb $4,%cl
rol %cl,%ax
push %eax
andb $0x0f,%al
movl $i386PrintHexTable,%ebx
xlat /*$i386PrintHexTable*/
call i386PrintTextCalcAddressOfNextChar
stosb
incl i386_ScreenPosX
pop %eax
ret
/************************************************************************/
/* Prints the value in AL on the screen in hex */
/************************************************************************/
i386PrintHexByte:
.code32
call i386PrintHexByte1
i386PrintHexByte1:
movb $4,%cl
rol %cl,%al
push %eax
andb $0x0f,%al
movl $i386PrintHexTable,%ebx
xlat /*$i386PrintHexTable*/
call i386PrintTextCalcAddressOfNextChar
stosb
incl i386_ScreenPosX
pop %eax
ret
/************************************************************************/
EXTERN(i386DivideByZero)
.code32
SAVE_CPU_REGS
movl $i386DivideByZeroText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386DebugException)
.code32
SAVE_CPU_REGS
movl $i386DebugExceptionText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386NMIException)
.code32
SAVE_CPU_REGS
movl $i386NMIExceptionText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386Breakpoint)
.code32
SAVE_CPU_REGS
movl $i386BreakpointText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386Overflow)
.code32
SAVE_CPU_REGS
movl $i386OverflowText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386BoundException)
.code32
SAVE_CPU_REGS
movl $i386BoundExceptionText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386InvalidOpcode)
.code32
SAVE_CPU_REGS
movl $i386InvalidOpcodeText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386FPUNotAvailable)
.code32
SAVE_CPU_REGS
movl $i386FPUNotAvailableText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386DoubleFault)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386DoubleFaultText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386CoprocessorSegment)
.code32
SAVE_CPU_REGS
movl $i386CoprocessorSegmentText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386InvalidTSS)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386InvalidTSSText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386SegmentNotPresent)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386SegmentNotPresentText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386StackException)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386StackExceptionText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386GeneralProtectionFault)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386GeneralProtectionFaultText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386PageFault)
.code32
SAVE_CPU_REGS_ERROR_CODE
movl $i386PageFaultText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386CoprocessorError)
.code32
SAVE_CPU_REGS
movl $i386CoprocessorErrorText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386AlignmentCheck)
.code32
SAVE_CPU_REGS
movl $i386AlignmentCheckText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler
/************************************************************************/
EXTERN(i386MachineCheck)
.code32
SAVE_CPU_REGS
movl $i386MachineCheckText,i386ExceptionDescriptionText
jmp i386CommonExceptionHandler

View File

@@ -1,81 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
.code32
EXTERN(_BootNewLinuxKernel)
call switch_to_real
.code16
/* Set the boot drive */
movb (_BootDrive),%dl
/* Load segment registers */
cli
movw $0x9000,%bx
movw %bx,%ds
movw %bx,%es
movw %bx,%fs
movw %bx,%gs
movw %bx,%ss
movw $0x9000,%sp
ljmpl $0x9020,$0x0000
.code32
/*
* VOID BootOldLinuxKernel(ULONG KernelSize);
*/
EXTERN(_BootOldLinuxKernel)
/* First we have to copy the kernel down from 0x100000 to 0x10000 */
/* The reason we can overwrite low memory is because this code */
/* executes between 0000:8000 and 0000:FFFF. That leaves space for */
/* 32k of code before we start interfering with Linux kernel address space. */
/* Get KernelSize in ECX and move the kernel down */
movl 0x04(%esp),%ecx
movl $0x100000,%esi
movl $0x10000,%edi
rep movsb
call switch_to_real
.code16
/* Set the boot drive */
movb (_BootDrive),%dl
/* Load segment registers */
cli
movw $0x9000,%bx
movw %bx,%ds
movw %bx,%es
movw %bx,%fs
movw %bx,%gs
movw %bx,%ss
movw $0x9000,%sp
ljmpl $0x9020,$0x0000

View File

@@ -1,262 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
#include <multiboot.h>
/*
* Here we assume the kernel is loaded at 1mb
* This boots the kernel
*/
.code32
EXTERN(_boot_reactos)
call switch_to_real
.code16
/* Save cursor position */
movw $3,%ax //! Reset video mode
int $0x10
movb $10,%bl
movb $12,%ah
int $0x10
movw $0x1112,%ax // Use 8x8 font
xorb %bl,%bl
int $0x10
movw $0x1200,%ax // Use alternate print screen
movb $0x20,%bl
int $0x10
movb $1,%ah // Define cursor (scan lines 6 to 7)
movw $0x0607,%cx
int $0x10
movb $1,%ah
movw $0x600,%cx
int $0x10
movb $6,%ah // Scroll active page up
movb $0x32,%al // Clear 25 lines
movw $0,%cx // Upper left of scroll
movw $0x314F,%dx // Lower right of scroll
movb $(1*0x10+1),%bh // Use normal attribute on blanked line
int $0x10 // Video-IO
movw $0,%dx
movb $0,%dh
movb $2,%ah
movb $0,%bh
int $0x10
movw $0,%dx
movb $0,%dh
movb $2,%ah
movb $0,%bh
int $0x10
call _multi_boot
// Should never get here
cli
hlt
/*
* After you have setup the _mb_header and _mb_info structures
* then call this routine to transfer control to the kernel.
* This routine must be entered in 16-bit mode.
*/
.code16
EXTERN(_multi_boot)
cli
/*
* Setup various variables
*/
movw %ds,%bx
movzwl %bx,%eax
shll $4,%eax
addl %eax,kernel_gdtbase
/*
* Load the absolute address of the multiboot information structure
*/
movl $_mb_info,%ebx
/*
* load gdt
*/
lgdt kernel_gdtptr
/*
* Enter pmode and clear prefetch queue
*/
movl %cr0,%eax
orl $0x10001,%eax
movl %eax,%cr0
jmp next
next:
/*
* NOTE: This must be position independant (no references to
* non absolute variables)
*/
/*
* Initalize segment registers
*/
movw $KERNEL_DS,%ax
movw %ax,%ds
movw %ax,%ss
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
/*
* Initalize eflags
*/
pushl $0
popfl
/*
* Load the multiboot magic value into eax
*/
movl $0x2badb002,%eax
/*
* Jump to start of 32 bit code at 0xc0000000 + 0x1000
*/
pushl $KERNEL_CS
pushl _mb_entry_addr
lretl
//ljmpl $KERNEL_CS,$(0x0200000+0x1000)
//ljmpl $KERNEL_CS,(_mb_entry_addr)
//ljmpl $KERNEL_CS,$(KERNEL_BASE+0x1000)
.p2align 2 /* force 4-byte alignment */
kernel_gdt:
.word 0 // Zero descriptor
.word 0
.word 0
.word 0
.word 0xffff // Kernel code descriptor
.word 0x0000 //
.word 0x9a00 // base 0h limit 4gb
.word 0x00cf
.word 0xffff // Kernel data descriptor
.word 0x0000 //
.word 0x9200 // base 0h limit 4gb
.word 0x00cf
kernel_gdtptr:
.word (3*8)-1 /* Limit */
kernel_gdtbase:
.long kernel_gdt /* Base Address */
EXTERN(_mb_header)
_mb_magic:
.long 0 // unsigned long magic;
_mb_flags:
.long 0 // unsigned long flags;
_mb_checksum:
.long 0 // unsigned long checksum;
_mb_header_addr:
.long 0 // unsigned long header_addr;
_mb_load_addr:
.long 0 // unsigned long load_addr;
_mb_load_end_addr:
.long 0 // unsigned long load_end_addr;
_mb_bss_end_addr:
.long 0 // unsigned long bss_end_addr;
_mb_entry_addr:
.long 0 // unsigned long entry_addr;
//
// Boot information structure
//
EXTERN(_mb_info)
_multiboot_flags:
.long 0
_multiboot_mem_lower:
.long 0
_multiboot_mem_upper:
.long 0
_multiboot_boot_device:
.long 0
_multiboot_cmdline:
.long 0
_multiboot_mods_count:
.long 0
_multiboot_mods_addr:
.long 0
_multiboot_syms:
.rept 12
.byte 0
.endr
_multiboot_mmap_length:
.long 0
_multiboot_mmap_addr:
.long 0
_multiboot_drives_count:
.long 0
_multiboot_drives_addr:
.long 0
_multiboot_config_table:
.long 0
_multiboot_boot_loader_name:
.long 0
_multiboot_apm_table:
.long 0
EXTERN(_multiboot_modules)
.rept (64 * /*multiboot_module_size*/ 16)
.byte 0
.endr
EXTERN(_multiboot_module_strings)
.rept (64*256)
.byte 0
.endr
EXTERN(_multiboot_memory_map_descriptor_size)
.long 0
EXTERN(_multiboot_memory_map)
.rept (64 * /*sizeof(memory_map_t)*/24)
.byte 0
.endr
EXTERN(_multiboot_kernel_cmdline)
.rept 255
.byte 0
.endr

View File

@@ -1,213 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
#include <multiboot.h>
/*
* ULONG GetExtendedMemorySize(VOID);
*/
ExtendedMemorySize:
.long 0
EXTERN(_GetExtendedMemorySize)
.code32
pushal
movl $0,ExtendedMemorySize
call switch_to_real
.code16
movw $0xE801,%ax
int $0x15
jc GetExtendedMemorySizeTryInt15Func88
cmpw $0,%ax
je GetExtendedMemorySizeUseCXDX
movzwl %bx,%ebx
shll $6,%ebx
movzwl %ax,%eax
addl %ebx,%eax
movl %eax,ExtendedMemorySize
jmp GetExtendedMemorySizeDone
GetExtendedMemorySizeUseCXDX:
cmpw $0,%cx
je GetExtendedMemorySizeTryInt15Func88
movzwl %dx,%edx
shll $6,%edx
movzwl %cx,%ecx
addl %ecx,%edx
movl %edx,ExtendedMemorySize
jmp GetExtendedMemorySizeDone
GetExtendedMemorySizeTryInt15Func88:
movb $0x88,%ah
int $0x15
jc GetExtendedMemorySizeTryCMOS
cmpw $0,%ax
je GetExtendedMemorySizeTryCMOS
movzwl %ax,%eax
movl %eax,ExtendedMemorySize
jmp GetExtendedMemorySizeDone
GetExtendedMemorySizeTryCMOS:
xorl %eax,%eax
movb $0x31,%al
outb %al,$0x70
inb $0x71,%al
andl $0xffff,%eax
shll $8,%eax
movl %eax,ExtendedMemorySize
GetExtendedMemorySizeDone:
call switch_to_prot
.code32
popal
/* Restore return value */
movl ExtendedMemorySize,%eax
ret
/*
* ULONG GetConventionalMemorySize(VOID);
*/
ConventionalMemorySize:
.long 0
EXTERN(_GetConventionalMemorySize)
.code32
pushal
movl $0,ConventionalMemorySize
call switch_to_real
.code16
xorl %eax,%eax
int $0x12
/* Save return value */
movzwl %ax,%eax
movl %eax,ConventionalMemorySize
call switch_to_prot
.code32
popal
/* Restore return value */
movl ConventionalMemorySize,%eax
ret
/*
* ULONG GetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap);
*/
_gbmm_mem_map_length:
.long 0
_gbmm_memory_map_addr:
.long 0
_gbmm_memory_map:
.rept 32
.quad 0
.quad 0
.long 0
.long 0
.endr
EXTERN(_GetBiosMemoryMap)
.code32
pushal
movl $0,_gbmm_mem_map_length
/* Get memory map structure array address off stack */
movl 0x24(%esp),%eax
movl %eax,_gbmm_memory_map_addr
call switch_to_real
.code16
xorl %ebx,%ebx
movl $_gbmm_memory_map,%edi
GetBiosMemoryMapNext:
movl $0x534D4150,%edx // 'SMAP'
movl $24,%ecx
movl $0xE820,%eax
int $0x15
jc GetBiosMemoryMapDone
// If the BIOS didn't return 'SMAP' in EAX then
// it doesn't support this call
cmpl $0x534D4150,%eax // 'SMAP'
jne GetBiosMemoryMapDone
// Increment our count of items and the offset in the array
addl $24,%edi
incl _gbmm_mem_map_length
// If we have copied 32 items then we can't hold any
// more in our array so we're done
cmpl $32,_gbmm_mem_map_length
jae GetBiosMemoryMapDone
// If the continuation value is zero then this was
// the last entry so we're done
cmpl $0,%ebx
jne GetBiosMemoryMapNext
GetBiosMemoryMapDone:
call switch_to_prot
.code32
// Copy the memory map data into the supplied buffer
movl $_gbmm_memory_map,%esi
movl _gbmm_memory_map_addr,%edi
movl $(24 * 32),%ecx
rep movsb
popal
/* Get return value */
movl _gbmm_mem_map_length,%eax
ret

View File

@@ -1,470 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
.text
.code16
#define ASM
#include <arch.h>
/*
* void putchar(int ch);
*/
EXTERN(_putchar)
.code32
pushal
/* Get character to display */
movb 0x24(%esp),%bl
/* If we are displaying a CR '\n' then do a LF also */
cmpb $0x0a,%bl
jnz putchar_1
/* Display the LF */
pushl $0x0d
call _putchar
popl %eax
putchar_1:
/* If we are displaying a TAB '\t' then display 8 spaces ' ' */
cmpb $0x09,%bl
jnz putchar_2
/* Display the 8 spaces ' ' */
pushl $0x20
call _putchar
call _putchar
call _putchar
call _putchar
call _putchar
call _putchar
call _putchar
call _putchar
popl %eax
popal
ret
putchar_2:
call switch_to_real
.code16
/* Display the character via BIOS int 0x10 function 0x0e */
movb $0x0e,%ah
movb %bl,%al
movw $1,%bx
int $0x10
call switch_to_prot
.code32
popal
ret
/*
* int kbhit(void);
*/
_kbhit_retval:
.long 0
EXTERN(_kbhit)
.code32
pushal
movl $0x00,_kbhit_retval
call switch_to_real
.code16
/* Int 0x16, AH = 0x01 - Get Keyboard Status */
movb $0x01,%ah
int $0x16
jz kbhit_1 // ZF=0 if no key is available
/* Return value is non-zero if a key is available */
movl $1,_kbhit_retval
jmp kbhit_done
kbhit_1:
/* Return value is zero if no key is available */
movl $0,_kbhit_retval
kbhit_done:
call switch_to_prot
.code32
popal
/* Get return value */
movl _kbhit_retval,%eax
ret
/*
* int getch(void);
*/
extended_scancode:
.byte 0
EXTERN(_getch)
.code32
push %ebp
push %ebx
call switch_to_real
.code16
/* Check and see if we have an extended scancode to return */
movb extended_scancode,%al
movb $0,extended_scancode
movzbl %al,%ebx
cmpb $0,%al
jnz getch_done
/* Int 0x16, AH = 0x00 - Wait for keypress */
movb $0,%ah
int $0x16
/* If al is zero then it is an extended key */
cmp $0,%al
jnz getch_1
/* Save the scan code to be returned on the next call to getch() */
movb %ah,extended_scancode
getch_1:
/* Store character in ebx */
movzbl %al,%ebx
getch_done:
call switch_to_prot
.code32
/* Get return value from ebx */
movl %ebx,%eax
pop %ebx
pop %ebp
ret
/*
* int getyear(void);
*/
EXTERN(_getyear)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the date */
movb $4,%ah
int $0x1a
/* Convert from BCD to normal */
movb %ch,%al
andb $0x0f,%al
movb %al,%dl
movb %ch,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
movb %dl,%dh
movb %cl,%al
andb $0x0f,%al
movb %al,%dl
movb %cl,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
movb %dl,%cl
movzbl %dh,%eax
movl $100,%ebx
mull %ebx
movl %eax,%edx
addb %cl,%dl
/* Save return value */
movl %edx,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int getday(void);
*/
EXTERN(_getday)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the date */
movb $4,%ah
int $0x1a
/* Convert from BCD to normal */
movb %dl,%al
andb $0x0f,%al
movb %al,%cl
movb %dl,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%cl
/* Save return value */
movzbl %cl,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int getmonth(void);
*/
EXTERN(_getmonth)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the date */
movb $4,%ah
int $0x1a
/* Convert from BCD to normal */
movb %dh,%al
andb $0x0f,%al
movb %al,%dl
movb %dh,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
/* Save return value */
movzbl %dl,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int gethour(void);
*/
EXTERN(_gethour)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the time */
movb $2,%ah
int $0x1a
/* Convert from BCD to normal */
movb %ch,%al
andb $0x0f,%al
movb %al,%dl
movb %ch,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
/* Save return value */
movzbl %dl,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int getminute(void);
*/
EXTERN(_getminute)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the time */
movb $2,%ah
int $0x1a
/* Convert from BCD to normal */
movb %cl,%al
andb $0x0f,%al
movb %al,%dl
movb %cl,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
/* Save return value */
movzbl %dl,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int getsecond(void);
*/
EXTERN(_getsecond)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the time */
movb $2,%ah
int $0x1a
/* Convert from BCD to normal */
movb %dh,%al
andb $0x0f,%al
movb %al,%dl
movb %dh,%al
shrb $0x04,%al
andb $0x0f,%al
movb $0x0a,%bl
mulb %bl
addb %al,%dl
/* Save return value */
movzbl %dl,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret

View File

@@ -1,263 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include "cm.h"
#include <mm.h>
#include <disk.h>
#include <rtl.h>
#include <debug.h>
#include <arch.h>
// Returns a pointer to a CACHE_BLOCK structure
// Adds the block to the cache manager block list
// in cache memory if it isn't already there
PCACHE_BLOCK CacheInternalGetBlockPointer(PCACHE_DRIVE CacheDrive, ULONG BlockNumber)
{
PCACHE_BLOCK CacheBlock = NULL;
DbgPrint((DPRINT_CACHE, "CacheInternalGetBlockPointer() BlockNumber = %d\n", BlockNumber));
CacheBlock = CacheInternalFindBlock(CacheDrive, BlockNumber);
if (CacheBlock != NULL)
{
DbgPrint((DPRINT_CACHE, "Cache hit! BlockNumber: %d CacheBlock->BlockNumber: %d\n", BlockNumber, CacheBlock->BlockNumber));
return CacheBlock;
}
DbgPrint((DPRINT_CACHE, "Cache miss! BlockNumber: %d\n", BlockNumber));
CacheBlock = CacheInternalAddBlockToCache(CacheDrive, BlockNumber);
// Optimize the block list so it has a LRU structure
CacheInternalOptimizeBlockList(CacheDrive, CacheBlock);
return CacheBlock;
}
PCACHE_BLOCK CacheInternalFindBlock(PCACHE_DRIVE CacheDrive, ULONG BlockNumber)
{
PCACHE_BLOCK CacheBlock = NULL;
DbgPrint((DPRINT_CACHE, "CacheInternalFindBlock() BlockNumber = %d\n", BlockNumber));
//
// Make sure the block list has entries before I start searching it.
//
if (!RtlListIsEmpty((PLIST_ITEM)CacheDrive->CacheBlockHead))
{
//
// Search the list and find the BIOS drive number
//
CacheBlock = CacheDrive->CacheBlockHead;
while (CacheBlock != NULL)
{
//
// We found the block, so return it
//
if (CacheBlock->BlockNumber == BlockNumber)
{
//
// Increment the blocks access count
//
CacheBlock->AccessCount++;
return CacheBlock;
}
CacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlock);
}
}
return NULL;
}
PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNumber)
{
PCACHE_BLOCK CacheBlock = NULL;
DbgPrint((DPRINT_CACHE, "CacheInternalAddBlockToCache() BlockNumber = %d\n", BlockNumber));
// Check the size of the cache so we don't exceed our limits
CacheInternalCheckCacheSizeLimits(CacheDrive);
// We will need to add the block to the
// drive's list of cached blocks. So allocate
// the block memory.
CacheBlock = MmAllocateMemory(sizeof(CACHE_BLOCK));
if (CacheBlock == NULL)
{
return NULL;
}
// Now initialize the structure and
// allocate room for the block data
RtlZeroMemory(CacheBlock, sizeof(CACHE_BLOCK));
CacheBlock->BlockNumber = BlockNumber;
CacheBlock->BlockData = MmAllocateMemory(CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
if (CacheBlock->BlockData ==NULL)
{
MmFreeMemory(CacheBlock);
return NULL;
}
// Now try to read in the block
if (!DiskReadLogicalSectors(CacheDrive->DriveNumber, (BlockNumber * CacheDrive->BlockSize), CacheDrive->BlockSize, (PVOID)DISKREADBUFFER))
{
MmFreeMemory(CacheBlock->BlockData);
MmFreeMemory(CacheBlock);
return NULL;
}
RtlCopyMemory(CacheBlock->BlockData, (PVOID)DISKREADBUFFER, CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
// Add it to our list of blocks managed by the cache
if (CacheDrive->CacheBlockHead == NULL)
{
CacheDrive->CacheBlockHead = CacheBlock;
}
else
{
RtlListInsertTail((PLIST_ITEM)CacheDrive->CacheBlockHead, (PLIST_ITEM)CacheBlock);
}
// Update the cache data
CacheBlockCount++;
CacheSizeCurrent = CacheBlockCount * (CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
CacheInternalDumpBlockList(CacheDrive);
return CacheBlock;
}
BOOL CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive)
{
PCACHE_BLOCK CacheBlockToFree;
DbgPrint((DPRINT_CACHE, "CacheInternalFreeBlock()\n"));
// Get a pointer to the last item in the block list
// that isn't forced to be in the cache and remove
// it from the list
CacheBlockToFree = (PCACHE_BLOCK)RtlListGetTail((PLIST_ITEM)CacheDrive->CacheBlockHead);
while (CacheBlockToFree != NULL && CacheBlockToFree->LockedInCache == TRUE)
{
CacheBlockToFree = (PCACHE_BLOCK)RtlListGetPrevious((PLIST_ITEM)CacheBlockToFree);
}
// No blocks left in cache that can be freed
// so just return
if (CacheBlockToFree == NULL)
{
return FALSE;
}
//
// If we are freeing the head of the list then update it's pointer
//
if (CacheBlockToFree == CacheDrive->CacheBlockHead)
{
CacheDrive->CacheBlockHead = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlockToFree);
}
RtlListRemoveEntry((PLIST_ITEM)CacheBlockToFree);
// Free the block memory and the block structure
MmFreeMemory(CacheBlockToFree->BlockData);
MmFreeMemory(CacheBlockToFree);
// Update the cache data
CacheBlockCount--;
CacheSizeCurrent = CacheBlockCount * (CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
return TRUE;
}
VOID CacheInternalCheckCacheSizeLimits(PCACHE_DRIVE CacheDrive)
{
ULONG NewCacheSize;
DbgPrint((DPRINT_CACHE, "CacheInternalCheckCacheSizeLimits()\n"));
// Calculate the size of the cache if we added a block
NewCacheSize = (CacheBlockCount + 1) * (CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
// Check the new size against the cache size limit
if (NewCacheSize > CacheSizeLimit)
{
CacheInternalFreeBlock(CacheDrive);
CacheInternalDumpBlockList(CacheDrive);
}
}
VOID CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive)
{
PCACHE_BLOCK CacheBlock;
DbgPrint((DPRINT_CACHE, "Dumping block list for BIOS drive 0x%x.\n", CacheDrive->DriveNumber));
DbgPrint((DPRINT_CACHE, "LbaSupported = %s.\n", CacheDrive->LbaSupported ? "TRUE" : "FALSE"));
DbgPrint((DPRINT_CACHE, "Cylinders: %d.\n", CacheDrive->DriveGeometry.Cylinders));
DbgPrint((DPRINT_CACHE, "Heads: %d.\n", CacheDrive->DriveGeometry.Heads));
DbgPrint((DPRINT_CACHE, "Sectors: %d.\n", CacheDrive->DriveGeometry.Sectors));
DbgPrint((DPRINT_CACHE, "BytesPerSector: %d.\n", CacheDrive->DriveGeometry.BytesPerSector));
DbgPrint((DPRINT_CACHE, "BlockSize: %d.\n", CacheDrive->BlockSize));
DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit));
DbgPrint((DPRINT_CACHE, "CacheSizeCurrent: %d.\n", CacheSizeCurrent));
DbgPrint((DPRINT_CACHE, "CacheBlockCount: %d.\n", CacheBlockCount));
DbgPrint((DPRINT_CACHE, "Dumping %d cache blocks.\n", RtlListCountEntries((PLIST_ITEM)CacheDrive->CacheBlockHead)));
CacheBlock = CacheDrive->CacheBlockHead;
while (CacheBlock != NULL)
{
DbgPrint((DPRINT_CACHE, "Cache Block: CacheBlock: 0x%x\n", CacheBlock));
DbgPrint((DPRINT_CACHE, "Cache Block: Block Number: %d\n", CacheBlock->BlockNumber));
DbgPrint((DPRINT_CACHE, "Cache Block: Access Count: %d\n", CacheBlock->AccessCount));
DbgPrint((DPRINT_CACHE, "Cache Block: Block Data: 0x%x\n", CacheBlock->BlockData));
DbgPrint((DPRINT_CACHE, "Cache Block: Locked In Cache: %d\n", CacheBlock->LockedInCache));
if (CacheBlock->BlockData == NULL)
{
BugCheck((DPRINT_CACHE, "What the heck?!?\n"));
}
CacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlock);
}
}
VOID CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive, PCACHE_BLOCK CacheBlock)
{
DbgPrint((DPRINT_CACHE, "CacheInternalOptimizeBlockList()\n"));
// Don't do this if this block is already at the head of the list
if (CacheBlock != CacheDrive->CacheBlockHead)
{
// Remove this item from the block list
RtlListRemoveEntry((PLIST_ITEM)CacheBlock);
// Re-insert it at the head of the list
RtlListInsertHead((PLIST_ITEM)CacheDrive->CacheBlockHead, (PLIST_ITEM)CacheBlock);
// Update the head pointer
CacheDrive->CacheBlockHead = CacheBlock;
}
}

View File

@@ -1,329 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include "cm.h"
#include <mm.h>
#include <disk.h>
#include <rtl.h>
#include <debug.h>
///////////////////////////////////////////////////////////////////////////////////////
//
// Internal data
//
///////////////////////////////////////////////////////////////////////////////////////
CACHE_DRIVE CacheManagerDrive;
BOOL CacheManagerInitialized = FALSE;
ULONG CacheBlockCount = 0;
ULONG CacheSizeLimit = 0;
ULONG CacheSizeCurrent = 0;
BOOL CacheInitializeDrive(ULONG DriveNumber)
{
PCACHE_BLOCK NextCacheBlock;
// If we already have a cache for this drive then
// by all means lets keep it, unless it is a removable
// drive, in which case we'll invalidate the cache
if ((CacheManagerInitialized == TRUE) &&
(DriveNumber == CacheManagerDrive.DriveNumber) &&
(DriveNumber >= 0x80))
{
return TRUE;
}
//
// If we have already been initialized then free
// the old data
//
if (CacheManagerInitialized)
{
CacheManagerInitialized = FALSE;
DbgPrint((DPRINT_CACHE, "CacheBlockCount: %d\n", CacheBlockCount));
DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d\n", CacheSizeLimit));
DbgPrint((DPRINT_CACHE, "CacheSizeCurrent: %d\n", CacheSizeCurrent));
//
// Loop through and free the cache blocks
//
while (CacheManagerDrive.CacheBlockHead != NULL)
{
NextCacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheManagerDrive.CacheBlockHead);
MmFreeMemory(CacheManagerDrive.CacheBlockHead->BlockData);
MmFreeMemory(CacheManagerDrive.CacheBlockHead);
CacheManagerDrive.CacheBlockHead = NextCacheBlock;
}
}
// Initialize the structure
RtlZeroMemory(&CacheManagerDrive, sizeof(CACHE_DRIVE));
CacheManagerDrive.DriveNumber = DriveNumber;
CacheManagerDrive.LbaSupported = BiosInt13ExtensionsSupported(DriveNumber);
if (!DiskGetDriveGeometry(DriveNumber, &CacheManagerDrive.DriveGeometry))
{
return FALSE;
}
// If LBA is supported then the block size will be 128 sectors (64k)
// If not then the block size is the size of one track
if (CacheManagerDrive.LbaSupported)
{
// FIXME: Temporarily reduced this to
// 64 sectors since not all BIOS calls
// support reading as many as 128 sectors
CacheManagerDrive.BlockSize = 64;//128;
}
else
{
CacheManagerDrive.BlockSize = CacheManagerDrive.DriveGeometry.Sectors;
}
CacheBlockCount = 0;
CacheSizeLimit = GetSystemMemorySize() / 8;
CacheSizeCurrent = 0;
if (CacheSizeLimit < (64 * 1024))
{
CacheSizeLimit = (64 * 1024);
}
CacheManagerInitialized = TRUE;
DbgPrint((DPRINT_CACHE, "Initializing BIOS drive 0x%x.\n", DriveNumber));
DbgPrint((DPRINT_CACHE, "LbaSupported = %s.\n", CacheManagerDrive.LbaSupported ? "TRUE" : "FALSE"));
DbgPrint((DPRINT_CACHE, "Cylinders: %d.\n", CacheManagerDrive.DriveGeometry.Cylinders));
DbgPrint((DPRINT_CACHE, "Heads: %d.\n", CacheManagerDrive.DriveGeometry.Heads));
DbgPrint((DPRINT_CACHE, "Sectors: %d.\n", CacheManagerDrive.DriveGeometry.Sectors));
DbgPrint((DPRINT_CACHE, "BytesPerSector: %d.\n", CacheManagerDrive.DriveGeometry.BytesPerSector));
DbgPrint((DPRINT_CACHE, "BlockSize: %d.\n", CacheManagerDrive.BlockSize));
DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit));
return TRUE;
}
BOOL CacheReadDiskSectors(ULONG DiskNumber, ULONG StartSector, ULONG SectorCount, PVOID Buffer)
{
PCACHE_BLOCK CacheBlock;
ULONG StartBlock;
ULONG SectorOffsetInStartBlock;
ULONG CopyLengthInStartBlock;
ULONG EndBlock;
ULONG SectorOffsetInEndBlock;
ULONG BlockCount;
ULONG Idx;
DbgPrint((DPRINT_CACHE, "CacheReadDiskSectors() DiskNumber: 0x%x StartSector: %d SectorCount: %d Buffer: 0x%x\n", DiskNumber, StartSector, SectorCount, Buffer));
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
{
return FALSE;
}
//
// Caculate which blocks we must cache
//
StartBlock = StartSector / CacheManagerDrive.BlockSize;
SectorOffsetInStartBlock = StartSector % CacheManagerDrive.BlockSize;
CopyLengthInStartBlock = (SectorCount > (CacheManagerDrive.BlockSize - SectorOffsetInStartBlock)) ? (CacheManagerDrive.BlockSize - SectorOffsetInStartBlock) : SectorCount;
EndBlock = (StartSector + (SectorCount - 1)) / CacheManagerDrive.BlockSize;
SectorOffsetInEndBlock = (StartSector + SectorCount) % CacheManagerDrive.BlockSize;
BlockCount = (EndBlock - StartBlock) + 1;
DbgPrint((DPRINT_CACHE, "StartBlock: %d SectorOffsetInStartBlock: %d CopyLengthInStartBlock: %d EndBlock: %d SectorOffsetInEndBlock: %d BlockCount: %d\n", StartBlock, SectorOffsetInStartBlock, CopyLengthInStartBlock, EndBlock, SectorOffsetInEndBlock, BlockCount));
//
// Read the first block into the buffer
//
if (BlockCount > 0)
{
//
// Get cache block pointer (this forces the disk sectors into the cache memory)
//
CacheBlock = CacheInternalGetBlockPointer(&CacheManagerDrive, StartBlock);
if (CacheBlock == NULL)
{
return FALSE;
}
//
// Copy the portion requested into the buffer
//
RtlCopyMemory(Buffer,
(CacheBlock->BlockData + (SectorOffsetInStartBlock * CacheManagerDrive.DriveGeometry.BytesPerSector)),
(CopyLengthInStartBlock * CacheManagerDrive.DriveGeometry.BytesPerSector));
DbgPrint((DPRINT_CACHE, "1 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, (CacheBlock->BlockData + (SectorOffsetInStartBlock * CacheManagerDrive.DriveGeometry.BytesPerSector)), (CopyLengthInStartBlock * CacheManagerDrive.DriveGeometry.BytesPerSector)));
//
// Update the buffer address
//
Buffer += (CopyLengthInStartBlock * CacheManagerDrive.DriveGeometry.BytesPerSector);
//
// Update the block count
//
BlockCount--;
}
//
// Loop through the middle blocks and read them into the buffer
//
for (Idx=StartBlock+1; BlockCount>1; Idx++)
{
//
// Get cache block pointer (this forces the disk sectors into the cache memory)
//
CacheBlock = CacheInternalGetBlockPointer(&CacheManagerDrive, Idx);
if (CacheBlock == NULL)
{
return FALSE;
}
//
// Copy the portion requested into the buffer
//
RtlCopyMemory(Buffer,
CacheBlock->BlockData,
CacheManagerDrive.BlockSize * CacheManagerDrive.DriveGeometry.BytesPerSector);
DbgPrint((DPRINT_CACHE, "2 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, CacheManagerDrive.BlockSize * CacheManagerDrive.DriveGeometry.BytesPerSector));
//
// Update the buffer address
//
Buffer += CacheManagerDrive.BlockSize * CacheManagerDrive.DriveGeometry.BytesPerSector;
//
// Update the block count
//
BlockCount--;
}
//
// Read the last block into the buffer
//
if (BlockCount > 0)
{
//
// Get cache block pointer (this forces the disk sectors into the cache memory)
//
CacheBlock = CacheInternalGetBlockPointer(&CacheManagerDrive, EndBlock);
if (CacheBlock == NULL)
{
return FALSE;
}
//
// Copy the portion requested into the buffer
//
RtlCopyMemory(Buffer,
CacheBlock->BlockData,
SectorOffsetInEndBlock * CacheManagerDrive.DriveGeometry.BytesPerSector);
DbgPrint((DPRINT_CACHE, "3 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, SectorOffsetInEndBlock * CacheManagerDrive.DriveGeometry.BytesPerSector));
//
// Update the buffer address
//
Buffer += SectorOffsetInEndBlock * CacheManagerDrive.DriveGeometry.BytesPerSector;
//
// Update the block count
//
BlockCount--;
}
return TRUE;
}
BOOL CacheForceDiskSectorsIntoCache(ULONG DiskNumber, ULONG StartSector, ULONG SectorCount)
{
PCACHE_BLOCK CacheBlock;
ULONG StartBlock;
ULONG EndBlock;
ULONG BlockCount;
ULONG Idx;
DbgPrint((DPRINT_CACHE, "CacheForceDiskSectorsIntoCache() DiskNumber: 0x%x StartSector: %d SectorCount: %d\n", DiskNumber, StartSector, SectorCount));
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
{
return FALSE;
}
//
// Caculate which blocks we must cache
//
StartBlock = StartSector / CacheManagerDrive.BlockSize;
EndBlock = (StartSector + SectorCount) / CacheManagerDrive.BlockSize;
BlockCount = (EndBlock - StartBlock) + 1;
//
// Loop through and cache them
//
for (Idx=StartBlock; Idx<(StartBlock+BlockCount); Idx++)
{
//
// Get cache block pointer (this forces the disk sectors into the cache memory)
//
CacheBlock = CacheInternalGetBlockPointer(&CacheManagerDrive, Idx);
if (CacheBlock == NULL)
{
return FALSE;
}
//
// Lock the sectors into the cache
//
CacheBlock->LockedInCache = TRUE;
}
return TRUE;
}
BOOL CacheReleaseMemory(ULONG MinimumAmountToRelease)
{
ULONG AmountReleased;
DbgPrint((DPRINT_CACHE, "CacheReleaseMemory() MinimumAmountToRelease = %d\n", MinimumAmountToRelease));
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
{
return FALSE;
}
// Loop through and try to free the requested amount of memory
for (AmountReleased=0; AmountReleased<MinimumAmountToRelease; )
{
// Try to free a block
// If this fails then break out of the loop
if (!CacheInternalFreeBlock(&CacheManagerDrive))
{
break;
}
// It succeeded so increment the amount of memory we have freed
AmountReleased += CacheManagerDrive.BlockSize * CacheManagerDrive.DriveGeometry.BytesPerSector;
}
// Return status
return (AmountReleased >= MinimumAmountToRelease);
}

View File

@@ -1,93 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <disk.h>
#ifndef __CM_H
#define __CM_H
///////////////////////////////////////////////////////////////////////////////////////
//
// This structure describes a cached block element. The disk is divided up into
// cache blocks. For disks which LBA is not supported each block is the size of
// one track. This will force the cache manager to make track sized reads, and
// therefore maximizes throughput. For disks which support LBA the block size
// is 64k because they have no cylinder, head, or sector boundaries.
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct
{
LIST_ITEM ListEntry; // Doubly linked list synchronization member
ULONG BlockNumber; // Track index for CHS, 64k block index for LBA
BOOL LockedInCache; // Indicates that this block is locked in cache memory
ULONG AccessCount; // Access count for this block
PVOID BlockData; // Pointer to block data
} CACHE_BLOCK, *PCACHE_BLOCK;
///////////////////////////////////////////////////////////////////////////////////////
//
// This structure describes a cached drive. It contains the BIOS drive number
// and indicates whether or not LBA is supported. If LBA is not supported then
// the drive's geometry is described here.
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct
{
ULONG DriveNumber;
BOOL LbaSupported;
GEOMETRY DriveGeometry;
ULONG BlockSize; // Block size (in sectors)
PCACHE_BLOCK CacheBlockHead;
} CACHE_DRIVE, *PCACHE_DRIVE;
///////////////////////////////////////////////////////////////////////////////////////
//
// Internal data
//
///////////////////////////////////////////////////////////////////////////////////////
extern CACHE_DRIVE CacheManagerDrive;
extern BOOL CacheManagerInitialized;
extern ULONG CacheBlockCount;
extern ULONG CacheSizeLimit;
extern ULONG CacheSizeCurrent;
///////////////////////////////////////////////////////////////////////////////////////
//
// Internal functions
//
///////////////////////////////////////////////////////////////////////////////////////
PCACHE_BLOCK CacheInternalGetBlockPointer(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Returns a pointer to a CACHE_BLOCK structure given a block number
PCACHE_BLOCK CacheInternalFindBlock(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Searches the block list for a particular block
PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Adds a block to the cache's block list
BOOL CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive); // Removes a block from the cache's block list & frees the memory
VOID CacheInternalCheckCacheSizeLimits(PCACHE_DRIVE CacheDrive); // Checks the cache size limits to see if we can add a new block, if not calls CacheInternalFreeBlock()
VOID CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive); // Dumps the list of cached blocks to the debug output port
VOID CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive, PCACHE_BLOCK CacheBlock); // Moves the specified block to the head of the list
#endif // defined __CM_H

View File

@@ -1,183 +0,0 @@
/* $Id: portio.c,v 1.2 2002/06/06 05:58:35 bpalmer Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/hal/x86/portio.c
* PURPOSE: Port I/O functions
* PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de)
* UPDATE HISTORY:
* Created 18/10/99
*/
//#include <ddk/ntddk.h>
#include <freeldr.h>
/* FUNCTIONS ****************************************************************/
/*
* This file contains the definitions for the x86 IO instructions
* inb/inw/inl/outb/outw/outl and the "string versions" of the same
* (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
* versions of the single-IO instructions (inb_p/inw_p/..).
*
* This file is not meant to be obfuscating: it's just complicated
* to (a) handle it all in a way that makes gcc able to optimize it
* as well as possible and (b) trying to avoid writing the same thing
* over and over again with slight variations and possibly making a
* mistake somewhere.
*/
/*
* Thanks to James van Artsdalen for a better timing-fix than
* the two short jumps: using outb's to a nonexistent port seems
* to guarantee better timings even on fast machines.
*
* On the other hand, I'd like to be sure of a non-existent port:
* I feel a bit unsafe about using 0x80 (should be safe, though)
*
* Linus
*/
#ifdef SLOW_IO_BY_JUMPING
#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
#else
#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
#endif
#ifdef REALLY_SLOW_IO
#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
#else
#define SLOW_DOWN_IO __SLOW_DOWN_IO
#endif
VOID /*STDCALL*/
READ_PORT_BUFFER_UCHAR (PUCHAR Port,
PUCHAR Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; insb\n\t"
: "=D" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
VOID /*STDCALL*/
READ_PORT_BUFFER_USHORT (PUSHORT Port,
PUSHORT Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; insw"
: "=D" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
VOID /*STDCALL*/
READ_PORT_BUFFER_ULONG (PULONG Port,
PULONG Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; insl"
: "=D" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
UCHAR /*STDCALL*/
READ_PORT_UCHAR (PUCHAR Port)
{
UCHAR Value;
__asm__("inb %w1, %0\n\t"
: "=a" (Value)
: "d" (Port));
SLOW_DOWN_IO;
return(Value);
}
USHORT /*STDCALL*/
READ_PORT_USHORT (PUSHORT Port)
{
USHORT Value;
__asm__("inw %w1, %0\n\t"
: "=a" (Value)
: "d" (Port));
SLOW_DOWN_IO;
return(Value);
}
ULONG /*STDCALL*/
READ_PORT_ULONG (PULONG Port)
{
ULONG Value;
__asm__("inl %w1, %0\n\t"
: "=a" (Value)
: "d" (Port));
SLOW_DOWN_IO;
return(Value);
}
VOID /*STDCALL*/
WRITE_PORT_BUFFER_UCHAR (PUCHAR Port,
PUCHAR Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; outsb"
: "=S" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
VOID /*STDCALL*/
WRITE_PORT_BUFFER_USHORT (PUSHORT Port,
PUSHORT Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; outsw"
: "=S" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
VOID /*STDCALL*/
WRITE_PORT_BUFFER_ULONG (PULONG Port,
PULONG Buffer,
ULONG Count)
{
__asm__ __volatile__ ("cld ; rep ; outsl"
: "=S" (Buffer), "=c" (Count)
: "d" (Port),"0" (Buffer),"1" (Count));
}
VOID /*STDCALL*/
WRITE_PORT_UCHAR (PUCHAR Port,
UCHAR Value)
{
__asm__("outb %0, %w1\n\t"
:
: "a" (Value),
"d" (Port));
SLOW_DOWN_IO;
}
VOID /*STDCALL*/
WRITE_PORT_USHORT (PUSHORT Port,
USHORT Value)
{
__asm__("outw %0, %w1\n\t"
:
: "a" (Value),
"d" (Port));
SLOW_DOWN_IO;
}
VOID /*STDCALL*/
WRITE_PORT_ULONG (PULONG Port,
ULONG Value)
{
__asm__("outl %0, %w1\n\t"
:
: "a" (Value),
"d" (Port));
SLOW_DOWN_IO;
}
/* EOF */

View File

@@ -1,276 +0,0 @@
/*
* FreeLoader
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
* Copyright (C) 2001 Eric Kohl
* Copyright (C) 2001 Emanuele Aliberti
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <comm.h>
/* MACROS *******************************************************************/
#define DEFAULT_BAUD_RATE 19200
#define SER_RBR(x) ((x)+0)
#define SER_THR(x) ((x)+0)
#define SER_DLL(x) ((x)+0)
#define SER_IER(x) ((x)+1)
#define SER_DLM(x) ((x)+1)
#define SER_IIR(x) ((x)+2)
#define SER_LCR(x) ((x)+3)
#define SR_LCR_CS5 0x00
#define SR_LCR_CS6 0x01
#define SR_LCR_CS7 0x02
#define SR_LCR_CS8 0x03
#define SR_LCR_ST1 0x00
#define SR_LCR_ST2 0x04
#define SR_LCR_PNO 0x00
#define SR_LCR_POD 0x08
#define SR_LCR_PEV 0x18
#define SR_LCR_PMK 0x28
#define SR_LCR_PSP 0x38
#define SR_LCR_BRK 0x40
#define SR_LCR_DLAB 0x80
#define SER_MCR(x) ((x)+4)
#define SR_MCR_DTR 0x01
#define SR_MCR_RTS 0x02
#define SER_LSR(x) ((x)+5)
#define SR_LSR_DR 0x01
#define SR_LSR_TBE 0x20
#define SER_MSR(x) ((x)+6)
#define SR_MSR_CTS 0x10
#define SR_MSR_DSR 0x20
#define SER_SCR(x) ((x)+7)
/* STATIC VARIABLES *********************************************************/
static ULONG Rs232ComPort = 0;
static ULONG Rs232BaudRate = 0;
static PUCHAR Rs232PortBase = (PUCHAR)0;
/* The com port must only be initialized once! */
static BOOLEAN PortInitialized = FALSE;
/* STATIC FUNCTIONS *********************************************************/
static BOOL Rs232DoesComPortExist(PUCHAR BaseAddress)
{
BOOLEAN found;
BYTE mcr;
BYTE msr;
found = FALSE;
/* save Modem Control Register (MCR) */
mcr = READ_PORT_UCHAR (SER_MCR(BaseAddress));
/* enable loop mode (set Bit 4 of the MCR) */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10);
/* clear all modem output bits */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10);
/* read the Modem Status Register */
msr = READ_PORT_UCHAR (SER_MSR(BaseAddress));
/*
* the upper nibble of the MSR (modem output bits) must be
* equal to the lower nibble of the MCR (modem input bits)
*/
if ((msr & 0xF0) == 0x00)
{
/* set all modem output bits */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x1F);
/* read the Modem Status Register */
msr = READ_PORT_UCHAR (SER_MSR(BaseAddress));
/*
* the upper nibble of the MSR (modem output bits) must be
* equal to the lower nibble of the MCR (modem input bits)
*/
if ((msr & 0xF0) == 0xF0)
found = TRUE;
}
/* restore MCR */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), mcr);
return (found);
}
/* FUNCTIONS *********************************************************/
BOOL Rs232PortInitialize(ULONG ComPort, ULONG BaudRate)
{
ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
//char buffer[80];
ULONG divisor;
BYTE lcr;
if (PortInitialized == FALSE)
{
if (BaudRate != 0)
{
Rs232BaudRate = BaudRate;
}
else
{
Rs232BaudRate = DEFAULT_BAUD_RATE;
}
if (ComPort == 0)
{
if (Rs232DoesComPortExist ((PUCHAR)BaseArray[2]))
{
Rs232PortBase = (PUCHAR)BaseArray[2];
Rs232ComPort = 2;
/*#ifndef NDEBUG
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif*/ /* NDEBUG */
}
else if (Rs232DoesComPortExist ((PUCHAR)BaseArray[1]))
{
Rs232PortBase = (PUCHAR)BaseArray[1];
Rs232ComPort = 1;
/*#ifndef NDEBUG
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif*/ /* NDEBUG */
}
else
{
/*sprintf (buffer,
"\nKernel Debugger: No COM port found!!!\n\n");
HalDisplayString (buffer);*/
return FALSE;
}
}
else
{
if (Rs232DoesComPortExist ((PUCHAR)BaseArray[ComPort]))
{
Rs232PortBase = (PUCHAR)BaseArray[ComPort];
Rs232ComPort = ComPort;
/*#ifndef NDEBUG
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif*/ /* NDEBUG */
}
else
{
/*sprintf (buffer,
"\nKernel Debugger: No serial port found!!!\n\n");
HalDisplayString (buffer);*/
return FALSE;
}
}
PortInitialized = TRUE;
}
/*
* set baud rate and data format (8N1)
*/
/* turn on DTR and RTS */
WRITE_PORT_UCHAR (SER_MCR(Rs232PortBase), SR_MCR_DTR | SR_MCR_RTS);
/* set DLAB */
lcr = READ_PORT_UCHAR (SER_LCR(Rs232PortBase)) | SR_LCR_DLAB;
WRITE_PORT_UCHAR (SER_LCR(Rs232PortBase), lcr);
/* set baud rate */
divisor = 115200 / BaudRate;
WRITE_PORT_UCHAR (SER_DLL(Rs232PortBase), divisor & 0xff);
WRITE_PORT_UCHAR (SER_DLM(Rs232PortBase), (divisor >> 8) & 0xff);
/* reset DLAB and set 8N1 format */
WRITE_PORT_UCHAR (SER_LCR(Rs232PortBase),
SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO);
/* read junk out of the RBR */
lcr = READ_PORT_UCHAR (SER_RBR(Rs232PortBase));
/*
* set global info
*/
//KdComPortInUse = (ULONG)PortBase;
/*
* print message to blue screen
*/
/*sprintf (buffer,
"\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n",
ComPort,
(ULONG)PortBase,
BaudRate);
HalDisplayString (buffer);*/
return TRUE;
}
BOOL Rs232PortGetByte(PUCHAR ByteRecieved)
{
if (PortInitialized == FALSE)
return FALSE;
if ((READ_PORT_UCHAR (SER_LSR(Rs232PortBase)) & SR_LSR_DR))
{
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(Rs232PortBase));
return TRUE;
}
return FALSE;
}
BOOL Rs232PortPollByte(PUCHAR ByteRecieved)
{
if (PortInitialized == FALSE)
return FALSE;
while ((READ_PORT_UCHAR (SER_LSR(Rs232PortBase)) & SR_LSR_DR) == 0)
;
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(Rs232PortBase));
return TRUE;
}
VOID Rs232PortPutByte(UCHAR ByteToSend)
{
if (PortInitialized == FALSE)
return;
while ((READ_PORT_UCHAR (SER_LSR(Rs232PortBase)) & SR_LSR_TBE) == 0)
;
WRITE_PORT_UCHAR (SER_THR(Rs232PortBase), ByteToSend);
}

View File

@@ -1,369 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <debug.h>
#include <rtl.h>
#include <comm.h>
#ifdef DEBUG
//#define DEBUG_ULTRA
//#define DEBUG_INIFILE
//#define DEBUG_REACTOS
//#define DEBUG_CUSTOM
#define DEBUG_NONE
#ifdef DEBUG_ULTRA
ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM |
DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS |
DPRINT_LINUX;
#endif
#ifdef DEBUG_INIFILE
ULONG DebugPrintMask = DPRINT_INIFILE;
#endif
#ifdef DEBUG_REACTOS
ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY;
#endif
#ifdef DEBUG_CUSTOM
ULONG DebugPrintMask = 0;
#endif
#ifdef DEBUG_NONE
ULONG DebugPrintMask = 0;
#endif
#define SCREEN 0
#define RS232 1
#define BOCHS 2
#define COM1 1
#define COM2 2
#define COM3 3
#define COM4 4
#define BOCHS_OUTPUT_PORT 0xe9
//ULONG DebugPort = RS232;
//ULONG DebugPort = SCREEN;
ULONG DebugPort = BOCHS;
ULONG ComPort = COM1;
//ULONG BaudRate = 19200;
ULONG BaudRate = 115200;
BOOL DebugStartOfLine = TRUE;
VOID DebugInit(VOID)
{
if (DebugPort == RS232)
{
Rs232PortInitialize(ComPort, BaudRate);
}
}
VOID DebugPrintChar(UCHAR Character)
{
if (Character == '\n')
{
DebugStartOfLine = TRUE;
}
if (DebugPort == RS232)
{
if (Character == '\n')
{
Rs232PortPutByte('\r');
}
Rs232PortPutByte(Character);
}
else if (DebugPort == BOCHS)
{
WRITE_PORT_UCHAR((PUCHAR)BOCHS_OUTPUT_PORT, Character);
}
else
{
putchar(Character);
}
}
VOID DebugPrintHeader(ULONG Mask)
{
/* No header */
if (Mask == 0)
return;
switch (Mask)
{
case DPRINT_WARNING:
DebugPrintChar('W');
DebugPrintChar('A');
DebugPrintChar('R');
DebugPrintChar('N');
DebugPrintChar('I');
DebugPrintChar('N');
DebugPrintChar('G');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_MEMORY:
DebugPrintChar('M');
DebugPrintChar('E');
DebugPrintChar('M');
DebugPrintChar('O');
DebugPrintChar('R');
DebugPrintChar('Y');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_FILESYSTEM:
DebugPrintChar('F');
DebugPrintChar('I');
DebugPrintChar('L');
DebugPrintChar('E');
DebugPrintChar('S');
DebugPrintChar('Y');
DebugPrintChar('S');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_INIFILE:
DebugPrintChar('I');
DebugPrintChar('N');
DebugPrintChar('I');
DebugPrintChar('F');
DebugPrintChar('I');
DebugPrintChar('L');
DebugPrintChar('E');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_UI:
DebugPrintChar('U');
DebugPrintChar('I');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_DISK:
DebugPrintChar('D');
DebugPrintChar('I');
DebugPrintChar('S');
DebugPrintChar('K');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_CACHE:
DebugPrintChar('C');
DebugPrintChar('A');
DebugPrintChar('C');
DebugPrintChar('H');
DebugPrintChar('E');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_REGISTRY:
DebugPrintChar('R');
DebugPrintChar('E');
DebugPrintChar('G');
DebugPrintChar('I');
DebugPrintChar('S');
DebugPrintChar('T');
DebugPrintChar('R');
DebugPrintChar('Y');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_REACTOS:
DebugPrintChar('R');
DebugPrintChar('E');
DebugPrintChar('A');
DebugPrintChar('C');
DebugPrintChar('T');
DebugPrintChar('O');
DebugPrintChar('S');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
case DPRINT_LINUX:
DebugPrintChar('L');
DebugPrintChar('I');
DebugPrintChar('N');
DebugPrintChar('U');
DebugPrintChar('X');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
default:
DebugPrintChar('U');
DebugPrintChar('N');
DebugPrintChar('K');
DebugPrintChar('N');
DebugPrintChar('O');
DebugPrintChar('W');
DebugPrintChar('N');
DebugPrintChar(':');
DebugPrintChar(' ');
break;
}
}
VOID DebugPrint(ULONG Mask, char *format, ...)
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
// Mask out unwanted debug messages
if (!(Mask & DebugPrintMask))
{
return;
}
// Print the header if we have started a new line
if (DebugStartOfLine)
{
DebugPrintHeader(Mask);
DebugStartOfLine = FALSE;
}
dataptr++;
while ((c = *(format++)))
{
if (c != '%')
{
DebugPrintChar(c);
}
else
{
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
ptr = str;
while (*ptr)
{
DebugPrintChar(*(ptr++));
}
break;
case 'c':
DebugPrintChar((*(dataptr++))&0xff);
break;
case 's':
ptr = (char *)(*(dataptr++));
while ((c = *(ptr++)))
{
DebugPrintChar(c);
}
break;
}
}
}
if (DebugPort == SCREEN)
{
//getch();
}
}
VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
{
PUCHAR BufPtr = (PUCHAR)Buffer;
ULONG Idx;
ULONG Idx2;
// Mask out unwanted debug messages
if (!(Mask & DebugPrintMask))
{
return;
}
DebugStartOfLine = FALSE; // We don't want line headers
DebugPrint(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer, Length);
for (Idx=0; Idx<Length; )
{
DebugStartOfLine = FALSE; // We don't want line headers
if (Idx < 0x0010)
{
DebugPrint(Mask, "000%x:\t", Idx);
}
else if (Idx < 0x0100)
{
DebugPrint(Mask, "00%x:\t", Idx);
}
else if (Idx < 0x1000)
{
DebugPrint(Mask, "0%x:\t", Idx);
}
else
{
DebugPrint(Mask, "%x:\t", Idx);
}
for (Idx2=0; Idx2<16; Idx2++,Idx++)
{
if (BufPtr[Idx] < 0x10)
{
DebugPrint(Mask, "0");
}
DebugPrint(Mask, "%x", BufPtr[Idx]);
if (Idx2 == 7)
{
DebugPrint(Mask, "-");
}
else
{
DebugPrint(Mask, " ");
}
}
Idx -= 16;
DebugPrint(Mask, " ");
for (Idx2=0; Idx2<16; Idx2++,Idx++)
{
if ((BufPtr[Idx] > 20) && (BufPtr[Idx] < 0x80))
{
DebugPrint(Mask, "%c", BufPtr[Idx]);
}
else
{
DebugPrint(Mask, ".");
}
}
DebugPrint(Mask, "\n");
}
}
#endif // defined DEBUG

View File

@@ -1,144 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <disk.h>
#include <fs.h>
#include <rtl.h>
#include <ui.h>
#include <arch.h>
#include <debug.h>
/////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////
VOID DiskError(PUCHAR ErrorString)
{
UCHAR ErrorCodeString[80];
sprintf(ErrorCodeString, "%s\nError Code: 0x%lx", ErrorString, BiosInt13GetLastErrorCode());
DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString));
UiMessageBox(ErrorCodeString);
}
BOOL DiskReadLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{
ULONG PhysicalSector;
ULONG PhysicalHead;
ULONG PhysicalTrack;
GEOMETRY DriveGeometry;
ULONG NumberOfSectorsToRead;
DbgPrint((DPRINT_DISK, "ReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer));
//
// Check to see if it is a fixed disk drive
// If so then check to see if Int13 extensions work
// If they do then use them, otherwise default back to BIOS calls
//
if ((DriveNumber >= 0x80) && (BiosInt13ExtensionsSupported(DriveNumber)))
{
DbgPrint((DPRINT_DISK, "Using Int 13 Extensions for read. BiosInt13ExtensionsSupported(%d) = %s\n", DriveNumber, BiosInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE"));
//
// LBA is easy, nothing to calculate
// Just do the read
//
if (!BiosInt13ReadExtended(DriveNumber, SectorNumber, SectorCount, Buffer))
{
DiskError("Disk read error.");
return FALSE;
}
}
else
{
//
// Get the drive geometry
//
if (!DiskGetDriveGeometry(DriveNumber, &DriveGeometry))
{
return FALSE;
}
while (SectorCount)
{
//
// Calculate the physical disk offsets
//
PhysicalSector = 1 + (SectorNumber % DriveGeometry.Sectors);
PhysicalHead = (SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads;
PhysicalTrack = (SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads;
//
// Calculate how many sectors we are supposed to read
//
if (PhysicalSector > 1)
{
if (SectorCount >= (DriveGeometry.Sectors - (PhysicalSector - 1)))
NumberOfSectorsToRead = (DriveGeometry.Sectors - (PhysicalSector - 1));
else
NumberOfSectorsToRead = SectorCount;
}
else
{
if (SectorCount >= DriveGeometry.Sectors)
NumberOfSectorsToRead = DriveGeometry.Sectors;
else
NumberOfSectorsToRead = SectorCount;
}
DbgPrint((DPRINT_DISK, "Calling BiosInt13Read() with PhysicalHead: %d\n", PhysicalHead));
DbgPrint((DPRINT_DISK, "Calling BiosInt13Read() with PhysicalTrack: %d\n", PhysicalTrack));
DbgPrint((DPRINT_DISK, "Calling BiosInt13Read() with PhysicalSector: %d\n", PhysicalSector));
DbgPrint((DPRINT_DISK, "Calling BiosInt13Read() with NumberOfSectorsToRead: %d\n", NumberOfSectorsToRead));
//
// Make sure the read is within the geometry boundaries
//
if ((PhysicalHead >= DriveGeometry.Heads) ||
(PhysicalTrack >= DriveGeometry.Cylinders) ||
((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.Sectors + 1)) ||
(PhysicalSector > DriveGeometry.Sectors))
{
DiskError("Disk read exceeds drive geometry limits.");
return FALSE;
}
//
// Perform the read
//
if (!BiosInt13Read(DriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, NumberOfSectorsToRead, Buffer))
{
DiskError("Disk read error.");
return FALSE;
}
Buffer += (NumberOfSectorsToRead * DriveGeometry.BytesPerSector);
SectorCount -= NumberOfSectorsToRead;
SectorNumber += NumberOfSectorsToRead;
}
}
return TRUE;
}

View File

@@ -1,37 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <disk.h>
#include <rtl.h>
#include <mm.h>
BOOL DiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry)
{
// For now just return the geometry as the BIOS reports it
// BytesPerSector is always set to 512 by BiosInt13GetDriveParameters()
if (!BiosInt13GetDriveParameters(DriveNumber, DriveGeometry))
{
DiskError("Drive geometry unknown.");
return FALSE;
}
return TRUE;
}

View File

@@ -1,271 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <disk.h>
#include <rtl.h>
#include <mm.h>
#include <debug.h>
#include <arch.h>
BOOL DiskIsDriveRemovable(ULONG DriveNumber)
{
// Hard disks use drive numbers >= 0x80
// So if the drive number indicates a hard disk
// then return FALSE
if (DriveNumber >= 0x80)
{
return FALSE;
}
// Drive is a floppy diskette so return TRUE
return TRUE;
}
BOOL DiskIsDriveCdRom(ULONG DriveNumber)
{
PUCHAR Sector = (PUCHAR)DISKREADBUFFER;
BOOL Result;
// Hard disks use drive numbers >= 0x80
// So if the drive number indicates a hard disk
// then return FALSE
if ((DriveNumber >= 0x80) && (BiosInt13ExtensionsSupported(DriveNumber)))
{
if (!BiosInt13ReadExtended(DriveNumber, 16, 1, Sector))
{
DiskError("Disk read error.");
MmFreeMemory(Sector);
return FALSE;
}
Result = (Sector[0] == 1 &&
Sector[1] == 'C' &&
Sector[2] == 'D' &&
Sector[3] == '0' &&
Sector[4] == '0' &&
Sector[5] == '1');
return Result;
}
// Drive is not CdRom so return FALSE
return FALSE;
}
BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
ULONG BootablePartitionCount = 0;
MASTER_BOOT_RECORD MasterBootRecord;
// Read master boot record
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
{
return FALSE;
}
// Count the bootable partitions
if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80)
{
BootablePartitionCount++;
BootPartition = 0;
}
if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80)
{
BootablePartitionCount++;
BootPartition = 1;
}
if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80)
{
BootablePartitionCount++;
BootPartition = 2;
}
if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80)
{
BootablePartitionCount++;
BootPartition = 3;
}
// Make sure there was only one bootable partition
if (BootablePartitionCount != 1)
{
DiskError("Too many bootable partitions or none found.");
return FALSE;
}
// Copy the partition table entry
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[BootPartition], sizeof(PARTITION_TABLE_ENTRY));
return TRUE;
}
BOOL DiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
MASTER_BOOT_RECORD MasterBootRecord;
PARTITION_TABLE_ENTRY ExtendedPartitionTableEntry;
ULONG ExtendedPartitionNumber;
ULONG Index;
// Read master boot record
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
{
return FALSE;
}
// If they are asking for a primary
// partition then things are easy
if (PartitionNumber < 5)
{
// PartitionNumber is one-based and we need it zero-based
PartitionNumber--;
// Copy the partition table entry
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[PartitionNumber], sizeof(PARTITION_TABLE_ENTRY));
return TRUE;
}
else
{
// They want an extended partition entry so we will need
// to loop through all the extended partitions on the disk
// and return the one they want.
ExtendedPartitionNumber = PartitionNumber - 5;
for (Index=0; Index<=ExtendedPartitionNumber; Index++)
{
// Get the extended partition table entry
if (!DiskGetFirstExtendedPartitionEntry(&MasterBootRecord, &ExtendedPartitionTableEntry))
{
return FALSE;
}
// Read the partition boot record
if (!DiskReadBootRecord(DriveNumber, ExtendedPartitionTableEntry.SectorCountBeforePartition, &MasterBootRecord))
{
return FALSE;
}
// Get the first real partition table entry
if (!DiskGetFirstPartitionEntry(&MasterBootRecord, PartitionTableEntry))
{
return FALSE;
}
}
// When we get here we should have the correct entry
// already stored in PartitionTableEntry
// so just return TRUE
return TRUE;
}
}
BOOL DiskGetFirstPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
ULONG Index;
for (Index=0; Index<4; Index++)
{
// Check the system indicator
// If it's not an extended or unused partition
// then we're done
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_ENTRY_UNUSED) &&
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_EXTENDED) &&
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_XINT13_EXTENDED))
{
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
return TRUE;
}
}
return FALSE;
}
BOOL DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
ULONG Index;
for (Index=0; Index<4; Index++)
{
// Check the system indicator
// If it an extended partition then we're done
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_EXTENDED) ||
(MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_XINT13_EXTENDED))
{
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
return TRUE;
}
}
return FALSE;
}
BOOL DiskReadBootRecord(ULONG DriveNumber, ULONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord)
{
#ifdef DEBUG
ULONG Index;
#endif
// Read master boot record
if (!DiskReadLogicalSectors(DriveNumber, LogicalSectorNumber, 1, (PVOID)DISKREADBUFFER))
{
return FALSE;
}
RtlCopyMemory(BootRecord, (PVOID)DISKREADBUFFER, sizeof(MASTER_BOOT_RECORD));
#ifdef DEBUG
DbgPrint((DPRINT_DISK, "Dumping partition table for drive 0x%x:\n", DriveNumber));
DbgPrint((DPRINT_DISK, "Boot record logical start sector = %d\n", LogicalSectorNumber));
DbgPrint((DPRINT_DISK, "sizeof(MASTER_BOOT_RECORD) = 0x%x.\n", sizeof(MASTER_BOOT_RECORD)));
for (Index=0; Index<4; Index++)
{
DbgPrint((DPRINT_DISK, "-------------------------------------------\n"));
DbgPrint((DPRINT_DISK, "Partition %d\n", (Index + 1)));
DbgPrint((DPRINT_DISK, "BootIndicator: 0x%x\n", BootRecord->PartitionTable[Index].BootIndicator));
DbgPrint((DPRINT_DISK, "StartHead: 0x%x\n", BootRecord->PartitionTable[Index].StartHead));
DbgPrint((DPRINT_DISK, "StartSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].StartSector));
DbgPrint((DPRINT_DISK, "StartCylinder: 0x%x\n", BootRecord->PartitionTable[Index].StartCylinder));
DbgPrint((DPRINT_DISK, "SystemIndicator: 0x%x\n", BootRecord->PartitionTable[Index].SystemIndicator));
DbgPrint((DPRINT_DISK, "EndHead: 0x%x\n", BootRecord->PartitionTable[Index].EndHead));
DbgPrint((DPRINT_DISK, "EndSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].EndSector));
DbgPrint((DPRINT_DISK, "EndCylinder: 0x%x\n", BootRecord->PartitionTable[Index].EndCylinder));
DbgPrint((DPRINT_DISK, "SectorCountBeforePartition: 0x%x\n", BootRecord->PartitionTable[Index].SectorCountBeforePartition));
DbgPrint((DPRINT_DISK, "PartitionSectorCount: 0x%x\n", BootRecord->PartitionTable[Index].PartitionSectorCount));
}
#endif // defined DEBUG
// Check the partition table magic value
if (BootRecord->MasterBootRecordMagic != 0xaa55)
{
DiskError("Invalid partition table magic (0xaa55)");
return FALSE;
}
return TRUE;
}

View File

@@ -1,214 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <fs.h>
#include <reactos.h>
#include <ui.h>
#include <arch.h>
#include <miscboot.h>
#include <linux.h>
#include <mm.h>
#include <inifile.h>
#include <debug.h>
#include <oslist.h>
#include <video.h>
// Variable BootDrive moved to asmcode.S
//ULONG BootDrive = 0; // BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc.
ULONG BootPartition = 0; // Boot Partition, 1-4
ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount);
LONG GetTimeOut(VOID);
VOID BootMain(VOID)
{
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
ULONG OperatingSystemCount;
PUCHAR *OperatingSystemSectionNames;
PUCHAR *OperatingSystemDisplayNames;
ULONG DefaultOperatingSystem;
LONG TimeOut;
ULONG SelectedOperatingSystem;
EnableA20();
#ifdef DEBUG
DebugInit();
#endif
if (!MmInitializeMemoryManager())
{
printf("Press any key to reboot.\n");
getch();
return;
}
if (!IniFileInitialize())
{
printf("Press any key to reboot.\n");
getch();
return;
}
if (!IniOpenSection("FreeLoader", &SectionId))
{
printf("Section [FreeLoader] not found in freeldr.ini.\n");
getch();
return;
}
if (!UiInitialize())
{
printf("Press any key to reboot.\n");
getch();
return;
}
if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount))
{
UiMessageBox("Press ENTER to reboot.\n");
goto reboot;
}
if (OperatingSystemCount == 0)
{
UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
goto reboot;
}
DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemSectionNames, OperatingSystemCount);
TimeOut = GetTimeOut();
//
// Find all the message box settings and run them
//
UiShowMessageBoxesInSection("FreeLoader");
for (;;)
{
// Redraw the backdrop
UiDrawBackdrop();
// Show the operating system list menu
if (!UiDisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem))
{
UiMessageBox("Press ENTER to reboot.\n");
goto reboot;
}
TimeOut = -1;
DefaultOperatingSystem = SelectedOperatingSystem;
// Try to open the operating system section in the .ini file
if (!IniOpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
UiMessageBox(SettingName);
continue;
}
// Try to read the boot type
if (!IniReadSettingByName(SectionId, "BootType", SettingValue, 80))
{
sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
UiMessageBox(SettingName);
continue;
}
if (stricmp(SettingValue, "ReactOS") == 0)
{
LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "Linux") == 0)
{
LoadAndBootLinux(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "BootSector") == 0)
{
LoadAndBootBootSector(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "Partition") == 0)
{
LoadAndBootPartition(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "Drive") == 0)
{
LoadAndBootDrive(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
}
reboot:
VideoClearScreen();
VideoShowTextCursor();
return;
}
ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount)
{
UCHAR DefaultOSText[80];
ULONG SectionId;
ULONG DefaultOS = 0;
ULONG Idx;
if (!IniOpenSection("FreeLoader", &SectionId))
{
return 0;
}
if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, 80))
{
for (Idx=0; Idx<OperatingSystemCount; Idx++)
{
if (stricmp(DefaultOSText, OperatingSystemList[Idx]) == 0)
{
DefaultOS = Idx;
break;
}
}
}
return DefaultOS;
}
LONG GetTimeOut(VOID)
{
UCHAR TimeOutText[20];
ULONG TimeOut;
ULONG SectionId;
if (!IniOpenSection("FreeLoader", &SectionId))
{
return -1;
}
if (IniReadSettingByName(SectionId, "TimeOut", TimeOutText, 20))
{
TimeOut = atoi(TimeOutText);
}
else
{
TimeOut = -1;
}
return TimeOut;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,164 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FAT_H
#define __FAT_H
typedef struct _FAT_BOOTSECTOR
{
BYTE JumpBoot[3]; // Jump instruction to boot code
UCHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
WORD BytesPerSector; // Bytes per sector
BYTE SectorsPerCluster; // Number of sectors in a cluster
WORD ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
BYTE NumberOfFats; // Number of FAT tables
WORD RootDirEntries; // Number of root directory entries (fat12/16)
WORD TotalSectors; // Number of total sectors on the drive, 16-bit
BYTE MediaDescriptor; // Media descriptor byte
WORD SectorsPerFat; // Sectors per FAT table (fat12/16)
WORD SectorsPerTrack; // Number of sectors in a track
WORD NumberOfHeads; // Number of heads on the disk
DWORD HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
DWORD TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
BYTE DriveNumber; // Int 0x13 drive number (e.g. 0x80)
BYTE Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
BYTE BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
DWORD VolumeSerialNumber; // Volume serial number
UCHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
UCHAR FileSystemType[8]; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
BYTE BootCodeAndData[448]; // The remainder of the boot sector
WORD BootSectorMagic; // 0xAA55
} PACKED FAT_BOOTSECTOR, *PFAT_BOOTSECTOR;
typedef struct _FAT32_BOOTSECTOR
{
BYTE JumpBoot[3]; // Jump instruction to boot code
UCHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
WORD BytesPerSector; // Bytes per sector
BYTE SectorsPerCluster; // Number of sectors in a cluster
WORD ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
BYTE NumberOfFats; // Number of FAT tables
WORD RootDirEntries; // Number of root directory entries (fat12/16)
WORD TotalSectors; // Number of total sectors on the drive, 16-bit
BYTE MediaDescriptor; // Media descriptor byte
WORD SectorsPerFat; // Sectors per FAT table (fat12/16)
WORD SectorsPerTrack; // Number of sectors in a track
WORD NumberOfHeads; // Number of heads on the disk
DWORD HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
DWORD TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
DWORD SectorsPerFatBig; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
WORD ExtendedFlags; // Extended flags (fat32)
WORD FileSystemVersion; // File system version (fat32)
DWORD RootDirStartCluster; // Starting cluster of the root directory (fat32)
WORD FsInfo; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
WORD BackupBootSector; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
BYTE Reserved[12]; // Reserved for future expansion
BYTE DriveNumber; // Int 0x13 drive number (e.g. 0x80)
BYTE Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
BYTE BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
DWORD VolumeSerialNumber; // Volume serial number
UCHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
UCHAR FileSystemType[8]; // Always set to the string "FAT32 "
BYTE BootCodeAndData[420]; // The remainder of the boot sector
WORD BootSectorMagic; // 0xAA55
} PACKED FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
/*
* Structure of MSDOS directory entry
*/
typedef struct //_DIRENTRY
{
UCHAR FileName[11]; /* Filename + extension */
UINT8 Attr; /* File attributes */
UINT8 ReservedNT; /* Reserved for use by Windows NT */
UINT8 TimeInTenths; /* Millisecond stamp at file creation */
UINT16 CreateTime; /* Time file was created */
UINT16 CreateDate; /* Date file was created */
UINT16 LastAccessDate; /* Date file was last accessed */
UINT16 ClusterHigh; /* High word of this entry's start cluster */
UINT16 Time; /* Time last modified */
UINT16 Date; /* Date last modified */
UINT16 ClusterLow; /* First cluster number low word */
UINT32 Size; /* File size */
} PACKED DIRENTRY, * PDIRENTRY;
typedef struct
{
UINT8 SequenceNumber; /* Sequence number for slot */
WCHAR Name0_4[5]; /* First 5 characters in name */
UINT8 EntryAttributes; /* Attribute byte */
UINT8 Reserved; /* Always 0 */
UINT8 AliasChecksum; /* Checksum for 8.3 alias */
WCHAR Name5_10[6]; /* 6 more characters in name */
UINT16 StartCluster; /* Starting cluster number */
WCHAR Name11_12[2]; /* Last 2 characters in name */
} PACKED LFN_DIRENTRY, * PLFN_DIRENTRY;
typedef struct
{
ULONG FileSize; // File size
ULONG FilePointer; // File pointer
PUINT32 FileFatChain; // File fat chain array
ULONG DriveNumber;
} FAT_FILE_INFO, * PFAT_FILE_INFO;
BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartSector);
ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector);
PVOID FatBufferDirectory(UINT32 DirectoryStartCluster, PUINT32 EntryCountPointer, BOOL RootDirectory);
BOOL FatSearchDirectoryBufferForFile(PVOID DirectoryBuffer, UINT32 EntryCount, PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer);
BOOL FatLookupFile(PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer);
ULONG FatGetNumPathParts(PUCHAR Path);
VOID FatGetFirstNameFromPath(PUCHAR Buffer, PUCHAR Path);
void FatParseShortFileName(PUCHAR Buffer, PDIRENTRY DirEntry);
BOOL FatGetFatEntry(UINT32 Cluster, PUINT32 ClusterPointer);
FILE* FatOpenFile(PUCHAR FileName);
UINT32 FatCountClustersInChain(UINT32 StartCluster);
PUINT32 FatGetClusterChainArray(UINT32 StartCluster);
BOOL FatReadCluster(ULONG ClusterNumber, PVOID Buffer);
BOOL FatReadClusterChain(ULONG StartClusterNumber, ULONG NumberOfClusters, PVOID Buffer);
BOOL FatReadPartialCluster(ULONG ClusterNumber, ULONG StartingOffset, ULONG Length, PVOID Buffer);
BOOL FatReadFile(FILE *FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer);
ULONG FatGetFileSize(FILE *FileHandle);
VOID FatSetFilePointer(FILE *FileHandle, ULONG NewFilePointer);
ULONG FatGetFilePointer(FILE *FileHandle);
BOOL FatReadVolumeSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer);
#define ATTR_NORMAL 0x00
#define ATTR_READONLY 0x01
#define ATTR_HIDDEN 0x02
#define ATTR_SYSTEM 0x04
#define ATTR_VOLUMENAME 0x08
#define ATTR_DIRECTORY 0x10
#define ATTR_ARCHIVE 0x20
#define ATTR_LONG_NAME (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUMENAME)
#define FAT12 1
#define FAT16 2
#define FAT32 3
#endif // #defined __FAT_H

View File

@@ -1,289 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <fs.h>
#include "fat.h"
#include "iso.h"
#include <disk.h>
#include <rtl.h>
#include <ui.h>
#include <arch.h>
#include <debug.h>
/////////////////////////////////////////////////////////////////////////////////////////////
// DATA
/////////////////////////////////////////////////////////////////////////////////////////////
ULONG FileSystemType = 0; // Type of filesystem on boot device, set by OpenDiskDrive()
/////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////
VOID FileSystemError(PUCHAR ErrorString)
{
DbgPrint((DPRINT_FILESYSTEM, "%s\n", ErrorString));
UiMessageBox(ErrorString);
}
/*
*
* BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber);
*
* This function is called to open a disk drive for file access.
* It must be called before any of the file functions will work.
* It takes two parameters:
*
* Drive: The BIOS drive number of the disk to open
* Partition: This is zero for floppy drives.
* If the disk is a hard disk then this specifies
* The partition number to open (1 - 4)
* If it is zero then it opens the active (bootable) partition
*
*/
BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber)
{
PARTITION_TABLE_ENTRY PartitionTableEntry;
DbgPrint((DPRINT_FILESYSTEM, "OpenDiskDrive() DriveNumber: 0x%x PartitionNumber: 0x%x\n", DriveNumber, PartitionNumber));
// Check and see if it is a floppy drive
// If so then just assume FAT12 file system type
if (DiskIsDriveRemovable(DriveNumber))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
FileSystemType = FS_FAT;
return FatOpenVolume(DriveNumber, 0);
}
// Check and see if it is a cdrom drive
// If so then just assume ISO9660 file system type
if (DiskIsDriveCdRom(DriveNumber))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
FileSystemType = FS_ISO9660;
return IsoOpenVolume(DriveNumber);
}
// Set the boot partition
BootPartition = PartitionNumber;
// Get the requested partition entry
if (PartitionNumber == 0)
{
// Partition requested was zero which means the boot partition
if (DiskGetActivePartitionEntry(DriveNumber, &PartitionTableEntry) == FALSE)
{
FileSystemError("No active partition.");
return FALSE;
}
}
else
{
// Get requested partition
if (DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry) == FALSE)
{
FileSystemError("Partition not found.");
return FALSE;
}
}
// Check for valid partition
if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
{
FileSystemError("Invalid partition.");
return FALSE;
}
switch (PartitionTableEntry.SystemIndicator)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:
case PARTITION_HUGE:
case PARTITION_XINT13:
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13:
FileSystemType = FS_FAT;
return FatOpenVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition);
default:
FileSystemType = 0;
FileSystemError("Unsupported file system.");
return FALSE;
}
return TRUE;
}
PFILE OpenFile(PUCHAR FileName)
{
PFILE FileHandle = NULL;
//
// Print status message
//
DbgPrint((DPRINT_FILESYSTEM, "Opening file '%s'...\n", FileName));
//
// Check file system type and pass off to appropriate handler
//
if (FileSystemType == FS_FAT)
{
FileHandle = FatOpenFile(FileName);
}
else if (FileSystemType == FS_ISO9660)
{
FileHandle = IsoOpenFile(FileName);
}
else
{
FileSystemError("Error: Unknown filesystem.");
}
#ifdef DEBUG
//
// Check return value
//
if (FileHandle != NULL)
{
DbgPrint((DPRINT_FILESYSTEM, "OpenFile() succeeded. FileHandle: 0x%x\n", FileHandle));
}
else
{
DbgPrint((DPRINT_FILESYSTEM, "OpenFile() failed.\n"));
}
#endif // defined DEBUG
return FileHandle;
}
VOID CloseFile(PFILE FileHandle)
{
}
/*
* ReadFile()
* returns number of bytes read or EOF
*/
BOOL ReadFile(PFILE FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer)
{
//
// Set the number of bytes read equal to zero
//
if (BytesRead !=NULL)
{
*BytesRead = 0;
}
switch (FileSystemType)
{
case FS_FAT:
return FatReadFile(FileHandle, BytesToRead, BytesRead, Buffer);
case FS_ISO9660:
return IsoReadFile(FileHandle, BytesToRead, BytesRead, Buffer);
default:
FileSystemError("Unknown file system.");
return FALSE;
}
return FALSE;
}
ULONG GetFileSize(PFILE FileHandle)
{
switch (FileSystemType)
{
case FS_FAT:
return FatGetFileSize(FileHandle);
case FS_ISO9660:
return IsoGetFileSize(FileHandle);
default:
FileSystemError("Unknown file system.");
break;
}
return 0;
}
VOID SetFilePointer(PFILE FileHandle, ULONG NewFilePointer)
{
switch (FileSystemType)
{
case FS_FAT:
FatSetFilePointer(FileHandle, NewFilePointer);
break;
case FS_ISO9660:
IsoSetFilePointer(FileHandle, NewFilePointer);
break;
default:
FileSystemError("Unknown file system.");
break;
}
}
ULONG GetFilePointer(PFILE FileHandle)
{
switch (FileSystemType)
{
case FS_FAT:
return FatGetFilePointer(FileHandle);
break;
case FS_ISO9660:
return IsoGetFilePointer(FileHandle);
break;
default:
FileSystemError("Unknown file system.");
break;
}
return 0;
}
BOOL IsEndOfFile(PFILE FileHandle)
{
if (GetFilePointer(FileHandle) >= GetFileSize(FileHandle))
{
return TRUE;
}
else
{
return FALSE;
}
}

View File

@@ -1,559 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <fs.h>
#include "iso.h"
#include <disk.h>
#include <rtl.h>
#include <ui.h>
#include <arch.h>
#include <mm.h>
#include <debug.h>
#include <cache.h>
#define SECTORSIZE 2048
static ULONG IsoRootSector; // Starting sector of the root directory
static ULONG IsoRootLength; // Length of the root directory
ULONG IsoDriveNumber = 0;
BOOL IsoOpenVolume(ULONG DriveNumber)
{
PPVD Pvd;
DbgPrint((DPRINT_FILESYSTEM, "IsoOpenVolume() DriveNumber = 0x%x VolumeStartSector = 16\n", DriveNumber));
// Store the drive number
IsoDriveNumber = DriveNumber;
IsoRootSector = 0;
IsoRootLength = 0;
Pvd = MmAllocateMemory(SECTORSIZE);
if (!DiskReadLogicalSectors(DriveNumber, 16, 1, Pvd))
{
FileSystemError("Failed to read the PVD.");
MmFreeMemory(Pvd);
return FALSE;
}
IsoRootSector = Pvd->RootDirRecord.ExtentLocationL;
IsoRootLength = Pvd->RootDirRecord.DataLengthL;
MmFreeMemory(Pvd);
DbgPrint((DPRINT_FILESYSTEM, "IsoRootSector = %u IsoRootLegth = %u\n", IsoRootSector, IsoRootLength));
return TRUE;
}
static BOOL IsoSearchDirectoryBufferForFile(PVOID DirectoryBuffer, UINT32 DirectoryLength, PUCHAR FileName, PISO_FILE_INFO IsoFileInfoPointer)
{
PDIR_RECORD Record;
ULONG Offset;
ULONG i;
UCHAR Name[32];
DbgPrint((DPRINT_FILESYSTEM, "IsoSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x DirectoryLength = %d FileName = %s\n", DirectoryBuffer, DirectoryLength, FileName));
memset(Name, 0, 32 * sizeof(UCHAR));
Offset = 0;
Record = (PDIR_RECORD)DirectoryBuffer;
while (TRUE)
{
Offset = Offset + Record->RecordLength;
Record = (PDIR_RECORD)(DirectoryBuffer + Offset);
if (Record->RecordLength == 0)
{
Offset = ROUND_UP(Offset, SECTORSIZE);
Record = (PDIR_RECORD)(DirectoryBuffer + Offset);
}
if (Record->FileIdLength == 1 && Record->FileId[0] == 0)
{
DbgPrint((DPRINT_FILESYSTEM, "Name '.'\n"));
}
else if (Record->FileIdLength == 1 && Record->FileId[0] == 1)
{
DbgPrint((DPRINT_FILESYSTEM, "Name '..'\n"));
}
else
{
for (i = 0; i < Record->FileIdLength && Record->FileId[i] != ';'; i++)
Name[i] = Record->FileId[i];
Name[i] = 0;
DbgPrint((DPRINT_FILESYSTEM, "Name '%s'\n", Name));
if (strlen(FileName) == strlen(Name) && stricmp(FileName, Name) == 0)
{
IsoFileInfoPointer->FileStart = Record->ExtentLocationL;
IsoFileInfoPointer->FileSize = Record->DataLengthL;
IsoFileInfoPointer->FilePointer = 0;
IsoFileInfoPointer->Directory = (Record->FileFlags & 0x02)?TRUE:FALSE;
return TRUE;
}
}
if (Offset >= DirectoryLength)
return FALSE;
memset(Name, 0, 32 * sizeof(UCHAR));
}
return FALSE;
}
static PVOID IsoBufferDirectory(UINT32 DirectoryStartSector, UINT32 DirectoryLength)
{
PVOID DirectoryBuffer;
UINT32 SectorCount;
DbgPrint((DPRINT_FILESYSTEM, "IsoBufferDirectory() DirectoryStartSector = %d DirectoryLength = %d\n", DirectoryStartSector, DirectoryLength));
//
// Attempt to allocate memory for directory buffer
//
DbgPrint((DPRINT_FILESYSTEM, "Trying to allocate (DirectoryLength) %d bytes.\n", DirectoryLength));
DirectoryBuffer = MmAllocateMemory(DirectoryLength);
if (DirectoryBuffer == NULL)
{
return NULL;
}
SectorCount = ROUND_UP(DirectoryLength, SECTORSIZE) / SECTORSIZE;
DbgPrint((DPRINT_FILESYSTEM, "Trying to read (DirectoryCount) %d sectors.\n", SectorCount));
//
// Now read directory contents into DirectoryBuffer
//
if (!DiskReadLogicalSectors(IsoDriveNumber, DirectoryStartSector, SectorCount, DirectoryBuffer))
{
MmFreeMemory(DirectoryBuffer);
return NULL;
}
return DirectoryBuffer;
}
/*
* IsoGetNumPathParts()
* This function parses a path in the form of dir1\dir2\file1.ext
* and returns the number of parts it has (i.e. 3 - dir1,dir2,file1.ext)
*/
static ULONG IsoGetNumPathParts(PUCHAR Path)
{
ULONG i;
ULONG num;
for (i=0,num=0; i<(int)strlen(Path); i++)
{
if ((Path[i] == '\\') || (Path[i] == '/'))
{
num++;
}
}
num++;
DbgPrint((DPRINT_FILESYSTEM, "IsoGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num));
return num;
}
/*
* IsoGetFirstNameFromPath()
* This function parses a path in the form of dir1\dir2\file1.ext
* and puts the first name of the path (e.g. "dir1") in buffer
* compatible with the MSDOS directory structure
*/
static VOID IsoGetFirstNameFromPath(PUCHAR Buffer, PUCHAR Path)
{
ULONG i;
// Copy all the characters up to the end of the
// string or until we hit a '\' character
// and put them in Buffer
for (i=0; i<(int)strlen(Path); i++)
{
if ((Path[i] == '\\') || (Path[i] == '/'))
{
break;
}
else
{
Buffer[i] = Path[i];
}
}
Buffer[i] = 0;
DbgPrint((DPRINT_FILESYSTEM, "IsoGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer));
}
/*
* IsoLookupFile()
* This function searches the file system for the
* specified filename and fills in an ISO_FILE_INFO structure
* with info describing the file, etc. returns true
* if the file exists or false otherwise
*/
static BOOL IsoLookupFile(PUCHAR FileName, PISO_FILE_INFO IsoFileInfoPointer)
{
int i;
ULONG NumberOfPathParts;
UCHAR PathPart[261];
PVOID DirectoryBuffer;
UINT32 DirectorySector;
UINT32 DirectoryLength;
ISO_FILE_INFO IsoFileInfo;
DbgPrint((DPRINT_FILESYSTEM, "IsoLookupFile() FileName = %s\n", FileName));
memset(IsoFileInfoPointer, 0, sizeof(ISO_FILE_INFO));
//
// Check and see if the first character is '\' and remove it if so
//
while ((*FileName == '\\') || (*FileName == '/'))
{
FileName++;
}
//
// Figure out how many sub-directories we are nested in
//
NumberOfPathParts = IsoGetNumPathParts(FileName);
DirectorySector = IsoRootSector;
DirectoryLength = IsoRootLength;
//
// Loop once for each part
//
for (i=0; i<NumberOfPathParts; i++)
{
//
// Get first path part
//
IsoGetFirstNameFromPath(PathPart, FileName);
//
// Advance to the next part of the path
//
for (; (*FileName != '\\') && (*FileName != '/') && (*FileName != '\0'); FileName++)
{
}
FileName++;
//
// Buffer the directory contents
//
DirectoryBuffer = IsoBufferDirectory(DirectorySector, DirectoryLength);
if (DirectoryBuffer == NULL)
{
return FALSE;
}
//
// Search for file name in directory
//
if (!IsoSearchDirectoryBufferForFile(DirectoryBuffer, DirectoryLength, PathPart, &IsoFileInfo))
{
MmFreeMemory(DirectoryBuffer);
return FALSE;
}
MmFreeMemory(DirectoryBuffer);
//
// If we have another sub-directory to go then
// grab the start sector and file size
//
if ((i+1) < NumberOfPathParts)
{
DirectorySector = IsoFileInfo.FileStart;
DirectoryLength = IsoFileInfo.FileSize;
}
}
memcpy(IsoFileInfoPointer, &IsoFileInfo, sizeof(ISO_FILE_INFO));
return TRUE;
}
/*
* IsoOpenFile()
* Tries to open the file 'name' and returns true or false
* for success and failure respectively
*/
FILE* IsoOpenFile(PUCHAR FileName)
{
ISO_FILE_INFO TempFileInfo;
PISO_FILE_INFO FileHandle;
DbgPrint((DPRINT_FILESYSTEM, "IsoOpenFile() FileName = %s\n", FileName));
if (!IsoLookupFile(FileName, &TempFileInfo))
{
return NULL;
}
FileHandle = MmAllocateMemory(sizeof(ISO_FILE_INFO));
if (FileHandle == NULL)
{
return NULL;
}
memcpy(FileHandle, &TempFileInfo, sizeof(ISO_FILE_INFO));
return (FILE*)FileHandle;
}
/*
* IsoReadPartialSector()
* Reads part of a cluster into memory
*/
static BOOL IsoReadPartialSector(ULONG SectorNumber, ULONG StartingOffset, ULONG Length, PVOID Buffer)
{
PUCHAR SectorBuffer;
DbgPrint((DPRINT_FILESYSTEM, "IsoReadPartialSector() SectorNumber = %d StartingOffset = %d Length = %d Buffer = 0x%x\n", SectorNumber, StartingOffset, Length, Buffer));
SectorBuffer = MmAllocateMemory(SECTORSIZE);
if (SectorBuffer == NULL)
{
return FALSE;
}
if (!DiskReadLogicalSectors(IsoDriveNumber, SectorNumber, 1, SectorBuffer))
{
MmFreeMemory(SectorBuffer);
return FALSE;
}
memcpy(Buffer, ((PVOID)SectorBuffer + StartingOffset), Length);
MmFreeMemory(SectorBuffer);
return TRUE;
}
/*
* IsoReadFile()
* Reads BytesToRead from open file and
* returns the number of bytes read in BytesRead
*/
BOOL IsoReadFile(FILE *FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer)
{
PISO_FILE_INFO IsoFileInfo = (PISO_FILE_INFO)FileHandle;
UINT32 SectorNumber;
UINT32 OffsetInSector;
UINT32 LengthInSector;
UINT32 NumberOfSectors;
DbgPrint((DPRINT_FILESYSTEM, "IsoReadFile() BytesToRead = %d Buffer = 0x%x\n", BytesToRead, Buffer));
if (BytesRead != NULL)
{
*BytesRead = 0;
}
//
// If they are trying to read past the
// end of the file then return success
// with BytesRead == 0
//
if (IsoFileInfo->FilePointer >= IsoFileInfo->FileSize)
{
return TRUE;
}
//
// If they are trying to read more than there is to read
// then adjust the amount to read
//
if ((IsoFileInfo->FilePointer + BytesToRead) > IsoFileInfo->FileSize)
{
BytesToRead = (IsoFileInfo->FileSize - IsoFileInfo->FilePointer);
}
//
// Ok, now we have to perform at most 3 calculations
// I'll draw you a picture (using nifty ASCII art):
//
// CurrentFilePointer -+
// |
// +----------------+
// |
// +-----------+-----------+-----------+-----------+
// | Sector 1 | Sector 2 | Sector 3 | Sector 4 |
// +-----------+-----------+-----------+-----------+
// | |
// +---------------+--------------------+
// |
// BytesToRead -------+
//
// 1 - The first calculation (and read) will align
// the file pointer with the next sector
// boundary (if we are supposed to read that much)
// 2 - The next calculation (and read) will read
// in all the full sectors that the requested
// amount of data would cover (in this case
// sectors 2 & 3).
// 3 - The last calculation (and read) would read
// in the remainder of the data requested out of
// the last sector.
//
//
// Only do the first read if we
// aren't aligned on a cluster boundary
//
if (IsoFileInfo->FilePointer % SECTORSIZE)
{
//
// Do the math for our first read
//
SectorNumber = IsoFileInfo->FileStart + (IsoFileInfo->FilePointer / SECTORSIZE);
OffsetInSector = IsoFileInfo->FilePointer % SECTORSIZE;
LengthInSector = (BytesToRead > (SECTORSIZE - OffsetInSector)) ? (SECTORSIZE - OffsetInSector) : BytesToRead;
//
// Now do the read and update BytesRead, BytesToRead, FilePointer, & Buffer
//
if (!IsoReadPartialSector(SectorNumber, OffsetInSector, LengthInSector, Buffer))
{
return FALSE;
}
if (BytesRead != NULL)
{
*BytesRead += LengthInSector;
}
BytesToRead -= LengthInSector;
IsoFileInfo->FilePointer += LengthInSector;
Buffer += LengthInSector;
}
//
// Do the math for our second read (if any data left)
//
if (BytesToRead > 0)
{
//
// Determine how many full clusters we need to read
//
NumberOfSectors = (BytesToRead / SECTORSIZE);
if (NumberOfSectors > 0)
{
SectorNumber = IsoFileInfo->FileStart + (IsoFileInfo->FilePointer / SECTORSIZE);
//
// Now do the read and update BytesRead, BytesToRead, FilePointer, & Buffer
//
if (!DiskReadLogicalSectors(IsoDriveNumber, SectorNumber, NumberOfSectors, Buffer))
{
return FALSE;
}
if (BytesRead != NULL)
{
*BytesRead += (NumberOfSectors * SECTORSIZE);
}
BytesToRead -= (NumberOfSectors * SECTORSIZE);
IsoFileInfo->FilePointer += (NumberOfSectors * SECTORSIZE);
Buffer += (NumberOfSectors * SECTORSIZE);
}
}
//
// Do the math for our third read (if any data left)
//
if (BytesToRead > 0)
{
SectorNumber = IsoFileInfo->FileStart + (IsoFileInfo->FilePointer / SECTORSIZE);
//
// Now do the read and update BytesRead, BytesToRead, FilePointer, & Buffer
//
if (!IsoReadPartialSector(SectorNumber, 0, BytesToRead, Buffer))
{
return FALSE;
}
if (BytesRead != NULL)
{
*BytesRead += BytesToRead;
}
IsoFileInfo->FilePointer += BytesToRead;
BytesToRead -= BytesToRead;
Buffer += BytesToRead;
}
printf("IsoReadFile() done\n");
return TRUE;
}
ULONG IsoGetFileSize(FILE *FileHandle)
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
DbgPrint((DPRINT_FILESYSTEM, "IsoGetFileSize() FileSize = %d\n", IsoFileHandle->FileSize));
return IsoFileHandle->FileSize;
}
VOID IsoSetFilePointer(FILE *FileHandle, ULONG NewFilePointer)
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
DbgPrint((DPRINT_FILESYSTEM, "IsoSetFilePointer() NewFilePointer = %d\n", NewFilePointer));
IsoFileHandle->FilePointer = NewFilePointer;
}
ULONG IsoGetFilePointer(FILE *FileHandle)
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
DbgPrint((DPRINT_FILESYSTEM, "IsoGetFilePointer() FilePointer = %d\n", IsoFileHandle->FilePointer));
return IsoFileHandle->FilePointer;
}

View File

@@ -1,115 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ISO_H
#define __ISO_H
struct _DIR_RECORD
{
UCHAR RecordLength; // 1
UCHAR ExtAttrRecordLength; // 2
ULONG ExtentLocationL; // 3-6
ULONG ExtentLocationM; // 7-10
ULONG DataLengthL; // 11-14
ULONG DataLengthM; // 15-18
UCHAR Year; // 19
UCHAR Month; // 20
UCHAR Day; // 21
UCHAR Hour; // 22
UCHAR Minute; // 23
UCHAR Second; // 24
UCHAR TimeZone; // 25
UCHAR FileFlags; // 26
UCHAR FileUnitSize; // 27
UCHAR InterleaveGapSize; // 28
ULONG VolumeSequenceNumber; // 29-32
UCHAR FileIdLength; // 33
UCHAR FileId[1]; // 34
} __attribute__((packed));
typedef struct _DIR_RECORD DIR_RECORD, *PDIR_RECORD;
/* Volume Descriptor header*/
struct _VD_HEADER
{
UCHAR VdType; // 1
UCHAR StandardId[5]; // 2-6
UCHAR VdVersion; // 7
} __attribute__((packed));
typedef struct _VD_HEADER VD_HEADER, *PVD_HEADER;
/* Primary Volume Descriptor */
struct _PVD
{
UCHAR VdType; // 1
UCHAR StandardId[5]; // 2-6
UCHAR VdVersion; // 7
UCHAR unused0; // 8
UCHAR SystemId[32]; // 9-40
UCHAR VolumeId[32]; // 41-72
UCHAR unused1[8]; // 73-80
ULONG VolumeSpaceSizeL; // 81-84
ULONG VolumeSpaceSizeM; // 85-88
UCHAR unused2[32]; // 89-120
ULONG VolumeSetSize; // 121-124
ULONG VolumeSequenceNumber; // 125-128
ULONG LogicalBlockSize; // 129-132
ULONG PathTableSizeL; // 133-136
ULONG PathTableSizeM; // 137-140
ULONG LPathTablePos; // 141-144
ULONG LOptPathTablePos; // 145-148
ULONG MPathTablePos; // 149-152
ULONG MOptPathTablePos; // 153-156
DIR_RECORD RootDirRecord; // 157-190
UCHAR VolumeSetIdentifier[128]; // 191-318
UCHAR PublisherIdentifier[128]; // 319-446
/* more data ... */
} __attribute__((packed));
typedef struct _PVD PVD, *PPVD;
typedef struct
{
ULONG FileStart; // File start sector
ULONG FileSize; // File size
ULONG FilePointer; // File pointer
BOOL Directory;
ULONG DriveNumber;
} ISO_FILE_INFO, * PISO_FILE_INFO;
BOOL IsoOpenVolume(ULONG DriveNumber);
FILE* IsoOpenFile(PUCHAR FileName);
BOOL IsoReadFile(FILE *FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer);
ULONG IsoGetFileSize(FILE *FileHandle);
VOID IsoSetFilePointer(FILE *FileHandle, ULONG NewFilePointer);
ULONG IsoGetFilePointer(FILE *FileHandle);
#endif // #defined __FAT_H

View File

@@ -1,60 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Defines needed for switching between real and protected mode */
#define NULL_DESC 0x00 /* NULL descriptor */
#define PMODE_CS 0x08 /* PMode code selector, base 0 limit 4g */
#define PMODE_DS 0x10 /* PMode data selector, base 0 limit 4g */
#define RMODE_CS 0x18 /* RMode code selector, base 0 limit 64k */
#define RMODE_DS 0x20 /* RMode data selector, base 0 limit 64k */
#define KERNEL_BASE 0xC0000000
//#define USER_CS 0x08
//#define USER_DS 0x10
//#define KERNEL_CS 0x20
//#define KERNEL_DS 0x28
#define KERNEL_CS 0x08
#define KERNEL_DS 0x10
#define CR0_PE_SET 0x00000001 /* OR this value with CR0 to enable pmode */
#define CR0_PE_CLR 0xFFFFFFFE /* AND this value with CR0 to disable pmode */
#define NR_TASKS 128 /* Space reserved in the GDT for TSS descriptors */
#define STACK16ADDR 0x7000 /* The 16-bit stack top will be at 0000:7000 */
#define STACK32ADDR 0x80000 /* The 32-bit stack top will be at 7000:FFFF, or 0x7FFFF */
#define MAXLOWMEMADDR 0x78000 /* The highest usuable low memory address for our memory allocator */
#define FILESYSBUFFER 0x80000 /* Buffer to store file system data (e.g. cluster buffer for FAT) */
#define DISKREADBUFFER 0x90000 /* Buffer to store data read in from the disk via the BIOS */
/* Makes "x" a global variable or label */
#define EXTERN(x) .global x; x:
#ifndef ASM
void EnableA20(void);
void StopFloppyMotor(void);
#endif /* ! ASM */

View File

@@ -1,29 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CACHE_H
#define __CACHE_H
BOOL CacheInitializeDrive(ULONG DriveNumber);
BOOL CacheReadDiskSectors(ULONG DiskNumber, ULONG StartSector, ULONG SectorCount, PVOID Buffer);
BOOL CacheForceDiskSectorsIntoCache(ULONG DiskNumber, ULONG StartSector, ULONG SectorCount);
BOOL CacheReleaseMemory(ULONG MinimumAmountToRelease);
#endif // defined __CACHE_H

View File

@@ -1,85 +0,0 @@
/*
* FreeLoader
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
* Copyright (C) 2001 Eric Kohl
* Copyright (C) 2001 Emanuele Aliberti
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __RS232_H
#define __RS232_H
BOOL Rs232PortInitialize(ULONG ComPort, ULONG BaudRate);
BOOL Rs232PortGetByte(PUCHAR ByteRecieved);
BOOL Rs232PortPollByte(PUCHAR ByteRecieved);
VOID Rs232PortPutByte(UCHAR ByteToSend);
/*
* Port I/O functions
*/
VOID
/*STDCALL*/
READ_PORT_BUFFER_UCHAR (PUCHAR Port, PUCHAR Value, ULONG Count);
VOID
/*STDCALL*/
READ_PORT_BUFFER_ULONG (PULONG Port, PULONG Value, ULONG Count);
VOID
/*STDCALL*/
READ_PORT_BUFFER_USHORT (PUSHORT Port, PUSHORT Value, ULONG Count);
UCHAR
/*STDCALL*/
READ_PORT_UCHAR (PUCHAR Port);
ULONG
/*STDCALL*/
READ_PORT_ULONG (PULONG Port);
USHORT
/*STDCALL*/
READ_PORT_USHORT (PUSHORT Port);
VOID
/*STDCALL*/
WRITE_PORT_BUFFER_UCHAR (PUCHAR Port, PUCHAR Value, ULONG Count);
VOID
/*STDCALL*/
WRITE_PORT_BUFFER_ULONG (PULONG Port, PULONG Value, ULONG Count);
VOID
/*STDCALL*/
WRITE_PORT_BUFFER_USHORT (PUSHORT Port, PUSHORT Value, ULONG Count);
VOID
/*STDCALL*/
WRITE_PORT_UCHAR (PUCHAR Port, UCHAR Value);
VOID
/*STDCALL*/
WRITE_PORT_ULONG (PULONG Port, ULONG Value);
VOID
/*STDCALL*/
WRITE_PORT_USHORT (PUSHORT Port, USHORT Value);
#endif // defined __RS232_H

View File

@@ -1,56 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __DEBUG_H
#define __DEBUG_H
#ifdef DEBUG
#define DPRINT_NONE 0x00000000 // Simple debug print
#define DPRINT_WARNING 0x00000001 // OR this with DebugPrintMask to enable debugger messages and other misc stuff
#define DPRINT_MEMORY 0x00000002 // OR this with DebugPrintMask to enable memory management messages
#define DPRINT_FILESYSTEM 0x00000004 // OR this with DebugPrintMask to enable file system messages
#define DPRINT_INIFILE 0x00000008 // OR this with DebugPrintMask to enable .ini file messages
#define DPRINT_UI 0x00000010 // OR this with DebugPrintMask to enable user interface messages
#define DPRINT_DISK 0x00000020 // OR this with DebugPrintMask to enable disk messages
#define DPRINT_CACHE 0x00000040 // OR this with DebugPrintMask to enable cache messages
#define DPRINT_REGISTRY 0x00000080 // OR this with DebugPrintMask to enable registry messages
#define DPRINT_REACTOS 0x00000100 // OR this with DebugPrintMask to enable ReactOS messages
#define DPRINT_LINUX 0x00000200 // OR this with DebugPrintMask to enable Linux messages
VOID DebugInit(VOID);
VOID DebugPrint(ULONG Mask, char *format, ...);
VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length);
#define DbgPrint(_x_) { DebugPrint(DPRINT_NONE, "%s:%d(%s)\n", __FILE__, __LINE__, __FUNCTION__); DebugPrint _x_ ; }
#define BugCheck(_x_) { DebugPrint(DPRINT_WARNING, "Fatal Error: %s:%d(%s)\n", __FILE__, __LINE__, __FUNCTION__); DebugPrint _x_ ; for (;;); }
#define DbgDumpBuffer(_x_, _y_, _z_) DebugDumpBuffer(_x_, _y_, _z_)
#else
#define DbgPrint(_x_)
#define BugCheck(_x_)
#define DbgDumpBuffer(_x_, _y_, _z_)
#endif // defined DEBUG
#define UNIMPLEMENTED BugCheck((DPRINT_WARNING, "Unimplemented\n"));
#endif // defined __DEBUG_H

View File

@@ -1,122 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __DISK_H
#define __DISK_H
typedef struct _GEOMETRY
{
ULONG Cylinders;
ULONG Heads;
ULONG Sectors;
ULONG BytesPerSector;
} GEOMETRY, *PGEOMETRY;
//
// Define the structure of a partition table entry
//
typedef struct _PARTITION_TABLE_ENTRY
{
BYTE BootIndicator; // 0x00 - non-bootable partition, 0x80 - bootable partition (one partition only)
BYTE StartHead; // Beginning head number
BYTE StartSector; // Beginning sector (2 high bits of cylinder #)
BYTE StartCylinder; // Beginning cylinder# (low order bits of cylinder #)
BYTE SystemIndicator; // System indicator
BYTE EndHead; // Ending head number
BYTE EndSector; // Ending sector (2 high bits of cylinder #)
BYTE EndCylinder; // Ending cylinder# (low order bits of cylinder #)
DWORD SectorCountBeforePartition; // Number of sectors preceding the partition
DWORD PartitionSectorCount; // Number of sectors in the partition
} PACKED PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
//
// Define the structure of the master boot record
//
typedef struct _MASTER_BOOT_RECORD
{
BYTE MasterBootRecordCodeAndData[0x1be];
PARTITION_TABLE_ENTRY PartitionTable[4];
WORD MasterBootRecordMagic;
} PACKED MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
//
// Partition type defines
//
#define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
#define PARTITION_FAT_12 0x01 // 12-bit FAT entries
#define PARTITION_XENIX_1 0x02 // Xenix
#define PARTITION_XENIX_2 0x03 // Xenix
#define PARTITION_FAT_16 0x04 // 16-bit FAT entries
#define PARTITION_EXTENDED 0x05 // Extended partition entry
#define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
#define PARTITION_IFS 0x07 // IFS Partition
#define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
#define PARTITION_FAT32 0x0B // FAT32
#define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
#define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
#define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
#define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
#define PARTITION_LDM 0x42 // Logical Disk Manager partition
#define PARTITION_UNIX 0x63 // Unix
///////////////////////////////////////////////////////////////////////////////////////
//
// BIOS Disk Functions
//
///////////////////////////////////////////////////////////////////////////////////////
int biosdisk(int cmd, int drive, int head, int track, int sector, int nsects, void *buffer); // Implemented in asmcode.S
BOOL BiosInt13Read(ULONG Drive, ULONG Head, ULONG Track, ULONG Sector, ULONG SectorCount, PVOID Buffer); // Implemented in asmcode.S
BOOL BiosInt13ReadExtended(ULONG Drive, ULONG Sector, ULONG SectorCount, PVOID Buffer); // Implemented in asmcode.S
BOOL BiosInt13ExtensionsSupported(ULONG Drive);
ULONG BiosInt13GetLastErrorCode(VOID);
void StopFloppyMotor(void); // Implemented in asmcode.S
int get_heads(int drive); // Implemented in asmcode.S
int get_cylinders(int drive); // Implemented in asmcode.S
int get_sectors(int drive); // Implemented in asmcode.S
BOOL BiosInt13GetDriveParameters(ULONG Drive, PGEOMETRY Geometry); // Implemented in disk.S
///////////////////////////////////////////////////////////////////////////////////////
//
// FreeLoader Disk Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID DiskError(PUCHAR ErrorString);
BOOL DiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry);
BOOL DiskReadLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer);
///////////////////////////////////////////////////////////////////////////////////////
//
// Fixed Disk Partition Management Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL DiskIsDriveRemovable(ULONG DriveNumber);
BOOL DiskIsDriveCdRom(ULONG DriveNumber);
BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOL DiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOL DiskGetFirstPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOL DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOL DiskReadBootRecord(ULONG DriveNumber, ULONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord);
#endif // defined __DISK_H

View File

@@ -1,69 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FREELDR_H
#define __FREELDR_H
#define size_t unsigned int
#define BOOL int
#define BOOLEAN int
#define NULL 0
#define TRUE 1
#define FALSE 0
#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned long
#define CHAR char
#define PCHAR char *
#define UCHAR unsigned char
#define PUCHAR unsigned char *
#define WCHAR unsigned short
#define PWCHAR unsigned short *
#define SHORT short
#define USHORT unsigned short
#define PUSHORT unsigned short *
#define LONG long
#define ULONG unsigned long
#define PULONG unsigned long *
#define PDWORD DWORD *
#define PWORD WORD *
#define VOID void
#define PVOID VOID*
#define INT8 char
#define UINT8 unsigned char
#define INT16 short
#define UINT16 unsigned short
#define INT32 long
#define UINT32 unsigned long
#define PUINT32 UINT32 *
#define INT64 long long
#define UINT64 unsigned long long
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#define PACKED __attribute__((packed))
extern ULONG BootDrive; // BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc.
extern ULONG BootPartition; // Boot Partition, 1-4
extern BOOL UserInterfaceUp; // Tells us if the user interface is displayed
void BootMain(void);
#endif // defined __FREELDR_H

View File

@@ -1,45 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FS_H
#define __FS_H
#define EOF -1
#define FS_FAT 1
#define FS_NTFS 2
#define FS_EXT2 3
#define FS_REISER 4
#define FS_ISO9660 5
#define FILE VOID
#define PFILE FILE *
VOID FileSystemError(PUCHAR ErrorString);
BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber);
PFILE OpenFile(PUCHAR FileName);
VOID CloseFile(PFILE FileHandle);
BOOL ReadFile(PFILE FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer);
ULONG GetFileSize(PFILE FileHandle);
VOID SetFilePointer(PFILE FileHandle, ULONG NewFilePointer);
ULONG GetFilePointer(PFILE FileHandle);
BOOL IsEndOfFile(PFILE FileHandle);
#endif // #defined __FS_H

View File

@@ -1,31 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PARSEINI_H
#define __PARSEINI_H
BOOL IniFileInitialize(VOID);
BOOL IniOpenSection(PUCHAR SectionName, PULONG SectionId);
ULONG IniGetNumSectionItems(ULONG SectionId);
BOOL IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize);
BOOL IniReadSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize);
#endif // defined __PARSEINI_H

View File

@@ -1,132 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __LINUX_H
#define __LINUX_H
#define LINUX_LOADER_TYPE_LILO 0x01
#define LINUX_LOADER_TYPE_LOADLIN 0x11
#define LINUX_LOADER_TYPE_BOOTSECT 0x21
#define LINUX_LOADER_TYPE_SYSLINUX 0x31
#define LINUX_LOADER_TYPE_ETHERBOOT 0x41
#define LINUX_LOADER_TYPE_FREELOADER 0x81
#define LINUX_COMMAND_LINE_MAGIC 0xA33F
#define LINUX_SETUP_HEADER_ID 0x53726448 // 'HdrS'
#define LINUX_BOOT_SECTOR_MAGIC 0xAA55
#define LINUX_KERNEL_LOAD_ADDRESS 0x100000
#define LINUX_FLAG_LOAD_HIGH 0x01
#define LINUX_FLAG_CAN_USE_HEAP 0x80
typedef struct
{
BYTE BootCode1[0x20];
WORD CommandLineMagic;
WORD CommandLineOffset;
BYTE BootCode2[0x1CD];
BYTE SetupSectors;
WORD RootFlags;
WORD SystemSize;
WORD SwapDevice;
WORD RamSize;
WORD VideoMode;
WORD RootDevice;
WORD BootFlag; // 0xAA55
} PACKED LINUX_BOOTSECTOR, *PLINUX_BOOTSECTOR;
typedef struct
{
BYTE JumpInstruction[2];
DWORD SetupHeaderSignature; // Signature for SETUP-header
WORD Version; // Version number of header format
WORD RealModeSwitch; // Default switch
WORD SetupSeg; // SETUPSEG
WORD StartSystemSeg;
WORD KernelVersion; // Offset to kernel version string
BYTE TypeOfLoader; // Loader ID
// =0, old one (LILO, Loadlin,
// Bootlin, SYSLX, bootsect...)
// else it is set by the loader:
// 0xTV: T=0 for LILO
// T=1 for Loadlin
// T=2 for bootsect-loader
// T=3 for SYSLX
// T=4 for ETHERBOOT
// V = version
BYTE LoadFlags; // flags, unused bits must be zero (RFU)
// LOADED_HIGH = 1
// bit within loadflags,
// if set, then the kernel is loaded high
// CAN_USE_HEAP = 0x80
// if set, the loader also has set heap_end_ptr
// to tell how much space behind setup.S
// can be used for heap purposes.
// Only the loader knows what is free!
WORD SetupMoveSize; // size to move, when we (setup) are not
// loaded at 0x90000. We will move ourselves
// to 0x90000 then just before jumping into
// the kernel. However, only the loader
// know how much of data behind us also needs
// to be loaded.
DWORD Code32Start; // here loaders can put a different
// start address for 32-bit code.
//
// 0x1000 = default for zImage
//
// 0x100000 = default for big kernel
DWORD RamdiskAddress; // address of loaded ramdisk image
// Here the loader (or kernel generator) puts
// the 32-bit address were it loaded the image.
DWORD RamdiskSize; // its size in bytes
WORD BootSectKludgeOffset;
WORD BootSectKludgeSegment;
WORD HeapEnd; // space from here (exclusive) down to
// end of setup code can be used by setup
// for local heap purposes.
} PACKED LINUX_SETUPSECTOR, *PLINUX_SETUPSECTOR;
VOID BootNewLinuxKernel(VOID); // Implemented in linux.S
VOID BootOldLinuxKernel(ULONG KernelSize); // Implemented in linux.S
VOID LoadAndBootLinux(PUCHAR OperatingSystemName);
BOOL LinuxParseIniSection(PUCHAR OperatingSystemName);
BOOL LinuxReadBootSector(PFILE LinuxKernelFile);
BOOL LinuxReadSetupSector(PFILE LinuxKernelFile);
BOOL LinuxReadKernel(PFILE LinuxKernelFile);
BOOL LinuxCheckKernelVersion(VOID);
BOOL LinuxReadInitrd(VOID);
#endif // defined __LINUX_H

View File

@@ -1,29 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __BOOT_H
#define __BOOT_H
VOID ChainLoadBiosBootSectorCode(VOID); // Implemented in boot.S
VOID LoadAndBootBootSector(PUCHAR OperatingSystemName);
VOID LoadAndBootPartition(PUCHAR OperatingSystemName);
VOID LoadAndBootDrive(PUCHAR OperatingSystemName);
#endif // defined __BOOT_H

View File

@@ -1,59 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MEMORY_H
#define __MEMORY_H
#define MEMTYPE_USABLE 0x01
#define MEMTYPE_RESERVED 0x02
#define MEMTYPE_ACPI_RECLAIM 0x03
#define MEMTYPE_ACPI_NVS 0x04
typedef struct
{
ULONG BaseAddressLow;
ULONG BaseAddressHigh;
ULONG LengthLow;
ULONG LengthHigh;
ULONG Type;
ULONG Reserved;
} PACKED BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP;
ULONG GetSystemMemorySize(VOID); // Returns the amount of total memory in the system
// These functions are implemented in mem.S
ULONG GetExtendedMemorySize(VOID); // Returns extended memory size in KB
ULONG GetConventionalMemorySize(VOID); // Returns conventional memory size in KB
ULONG GetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap); // Fills mem_map structure with BIOS memory map and returns length of memory map
//BOOL MmInitializeMemoryManager(ULONG LowMemoryStart, ULONG LowMemoryLength);
BOOL MmInitializeMemoryManager(VOID);
PVOID MmAllocateMemory(ULONG MemorySize);
VOID MmFreeMemory(PVOID MemoryPointer);
//PVOID MmAllocateLowMemory(ULONG MemorySize);
//VOID MmFreeLowMemory(PVOID MemoryPointer);
PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress);
#endif // defined __MEMORY_H

View File

@@ -1,159 +0,0 @@
/* multiboot.h - the header for Multiboot */
/* Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __MULTIBOOT_H
#define __MULTIBOOT_H
/* Macros. */
/* The magic number for the Multiboot header. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* The flags for the Multiboot header. */
#define MULTIBOOT_HEADER_FLAGS 0x00010003
/* The magic number passed by a Multiboot-compliant boot loader. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* The size of our stack (16KB). */
#define STACK_SIZE 0x4000
/* C symbol format. HAVE_ASM_USCORE is defined by configure. */
#ifdef HAVE_ASM_USCORE
# define EXT_C(sym) _ ## sym
#else
# define EXT_C(sym) sym
#endif
#define MB_INFO_FLAG_MEM_SIZE 0x00000001
#define MB_INFO_FLAG_BOOT_DEVICE 0x00000002
#define MB_INFO_FLAG_COMMAND_LINE 0x00000004
#define MB_INFO_FLAG_MODULES 0x00000008
#define MB_INFO_FLAG_AOUT_SYMS 0x00000010
#define MB_INFO_FLAG_ELF_SYMS 0x00000020
#define MB_INFO_FLAG_MEMORY_MAP 0x00000040
#define MB_INFO_FLAG_DRIVES 0x00000080
#define MB_INFO_FLAG_CONFIG_TABLE 0x00000100
#define MB_INFO_FLAG_BOOT_LOADER_NAME 0x00000200
#define MB_INFO_FLAG_APM_TABLE 0x00000400
#define MB_INFO_FLAG_GRAPHICS_TABLE 0x00000800
#ifndef ASM
/* Do not include here in boot.S. */
/* Types. */
/* The Multiboot header. */
typedef struct multiboot_header
{
unsigned long magic;
unsigned long flags;
unsigned long checksum;
unsigned long header_addr;
unsigned long load_addr;
unsigned long load_end_addr;
unsigned long bss_end_addr;
unsigned long entry_addr;
} multiboot_header_t;
/* The symbol table for a.out. */
typedef struct aout_symbol_table
{
unsigned long tabsize;
unsigned long strsize;
unsigned long addr;
unsigned long reserved;
} aout_symbol_table_t;
/* The section header table for ELF. */
typedef struct elf_section_header_table
{
unsigned long num;
unsigned long size;
unsigned long addr;
unsigned long shndx;
} elf_section_header_table_t;
/* The Multiboot information. */
typedef struct multiboot_info
{
unsigned long flags;
unsigned long mem_lower;
unsigned long mem_upper;
unsigned long boot_device;
unsigned long cmdline;
unsigned long mods_count;
unsigned long mods_addr;
union
{
aout_symbol_table_t aout_sym;
elf_section_header_table_t elf_sec;
} u;
unsigned long mmap_length;
unsigned long mmap_addr;
} multiboot_info_t;
/* The module structure. */
typedef struct module
{
unsigned long mod_start;
unsigned long mod_end;
unsigned long string;
unsigned long reserved;
} module_t;
/* The memory map. Be careful that the offset 0 is base_addr_low
but no size. */
typedef struct memory_map
{
//unsigned long size;
unsigned long base_addr_low;
unsigned long base_addr_high;
unsigned long length_low;
unsigned long length_high;
unsigned long type;
unsigned long reserved;
} memory_map_t;
multiboot_header_t mb_header; // Multiboot header structure defined in kernel image file
multiboot_info_t mb_info; // Multiboot info structure passed to kernel
char multiboot_kernel_cmdline[255]; // Command line passed to kernel
module_t multiboot_modules[64]; // Array to hold boot module info loaded for the kernel
char multiboot_module_strings[64][256]; // Array to hold module names
unsigned long multiboot_memory_map_descriptor_size;
memory_map_t multiboot_memory_map; // Memory map
void boot_reactos(void);
#include "fs.h" // Included FILE structure definition
BOOL MultiBootLoadKernel(FILE *KernelImage);
//BOOL MultiBootLoadModule(FILE *ModuleImage, char *ModuleName);
PVOID MultiBootLoadModule(FILE *ModuleImage, char *ModuleName, PULONG ModuleSize);
int GetBootPartition(char *OperatingSystemName);
PVOID MultiBootCreateModule(char *ModuleName);
BOOL MultiBootCloseModule(PVOID ModuleBase, DWORD dwModuleSize);
#endif /* ! ASM */
#endif // defined __MULTIBOOT_H

View File

@@ -1,31 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __OPTIONS_H
#define __OPTIONS_H
void DoOptionsMenu(void);
void DoDiskOptionsMenu(void);
void DoBootOptionsMenu(int BootDriveNum, char *BootDriveText);
void DoBootPartitionOptionsMenu(int BootDriveNum);
int RunOptionsMenu(char OptionsMenuItems[][80], int OptionsMenuItemCount, int nOptionSelected, char *OptionsMenuTitle);
void InitOptionsMenu(int *nOptionsMenuBoxLeft, int *nOptionsMenuBoxTop, int *nOptionsMenuBoxRight, int *nOptionsMenuBoxBottom, int OptionsMenuItemCount);
void DrawOptionsMenu(char OptionsMenuItems[][80], int OptionsMenuItemCount, int nOptionSelected, char *OptionsMenuTitle, int nOptionsMenuBoxLeft, int nOptionsMenuBoxTop, int nOptionsMenuBoxRight, int nOptionsMenuBoxBottom);
#endif // #defined __OPTIONS_H

View File

@@ -1,28 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __OSLIST_H
#define __OSLIST_H
BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNamesPointer, PULONG OperatingSystemCountPointer);
ULONG CountOperatingSystems(ULONG SectionId);
BOOL AllocateListMemory(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNamesPointer, ULONG OperatingSystemCount);
BOOL RemoveQuotes(PUCHAR QuotedString);
#endif // #defined __OSLIST_H

View File

@@ -1,42 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __REACTOS_H
#define __REACTOS_H
///////////////////////////////////////////////////////////////////////////////////////
//
// ReactOS Loading Functions
//
///////////////////////////////////////////////////////////////////////////////////////
void LoadAndBootReactOS(PUCHAR OperatingSystemName);
///////////////////////////////////////////////////////////////////////////////////////
//
// ARC Path Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL DissectArcPath(char *ArcPath, char *BootPath, PULONG BootDrive, PULONG BootPartition);
//BOOL ConvertBiosDriveToArcName(PUCHAR ArcName, ULONG BiosDriveNumber);
//ULONG ConvertArcNameToBiosDrive(PUCHAR ArcName);
#endif // defined __REACTOS_H

View File

@@ -1,128 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __STDLIB_H
#define __STDLIB_H
#include <freeldr.h>
///////////////////////////////////////////////////////////////////////////////////////
//
// String Functions
//
///////////////////////////////////////////////////////////////////////////////////////
int strlen(char *str);
char * strcpy(char *dest, char *src);
char * strncpy(char *dest, char *src, size_t count);
char * strcat(char *dest, char *src);
char * strchr(const char *s, int c);
char * strrchr(const char *s, int c);
int strcmp(const char *string1, const char *string2);
int stricmp(const char *string1, const char *string2);
int strncmp(const char *string1, const char *string2, size_t length);
int _strnicmp(const char *string1, const char *string2, size_t length);
///////////////////////////////////////////////////////////////////////////////////////
//
// Memory Functions
//
///////////////////////////////////////////////////////////////////////////////////////
int RtlCompareMemory(const PVOID Source1, const PVOID Source2, ULONG Length);
VOID RtlCopyMemory(PVOID Destination, const PVOID Source, ULONG Length);
VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill);
VOID RtlZeroMemory(PVOID Destination, ULONG Length);
#define memcmp(buf1, buf2, count) RtlCompareMemory(buf1, buf2, count)
#define memcpy(dest, src, count) RtlCopyMemory(dest, src,count)
#define memset(dest, c, count) RtlFillMemory(dest,count, c)
///////////////////////////////////////////////////////////////////////////////////////
//
// Standard Library Functions
//
///////////////////////////////////////////////////////////////////////////////////////
int atoi(char *string);
char * itoa(int value, char *string, int radix);
int toupper(int c);
int tolower(int c);
int isspace(int c);
int isdigit(int c);
int isxdigit(int c);
char * convert_to_ascii(char *buf, int c, ...);
void putchar(int ch); // Implemented in asmcode.S
int kbhit(void); // Implemented in asmcode.S
int getch(void); // Implemented in asmcode.S
int getyear(void); // Implemented in asmcode.S
int getday(void); // Implemented in asmcode.S
int getmonth(void); // Implemented in asmcode.S
int gethour(void); // Implemented in asmcode.S
int getminute(void); // Implemented in asmcode.S
int getsecond(void); // Implemented in asmcode.S
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
///////////////////////////////////////////////////////////////////////////////////////
//
// Screen Output Functions
//
///////////////////////////////////////////////////////////////////////////////////////
void print(char *str);
void printf(char *fmt, ...);
void sprintf(char *buffer, char *format, ...);
///////////////////////////////////////////////////////////////////////////////////////
//
// List Functions
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct _LIST_ITEM
{
struct _LIST_ITEM* ListPrev;
struct _LIST_ITEM* ListNext;
} LIST_ITEM, *PLIST_ITEM;
VOID RtlListInitializeHead(PLIST_ITEM ListHead); // Initializes a doubly linked list
VOID RtlListInsertHead(PLIST_ITEM ListHead, PLIST_ITEM Entry); // Inserts an entry at the head of the list
VOID RtlListInsertTail(PLIST_ITEM ListHead, PLIST_ITEM Entry); // Inserts an entry at the tail of the list
PLIST_ITEM RtlListRemoveHead(PLIST_ITEM ListHead); // Removes the entry at the head of the list
PLIST_ITEM RtlListRemoveTail(PLIST_ITEM ListHead); // Removes the entry at the tail of the list
PLIST_ITEM RtlListGetHead(PLIST_ITEM ListHead); // Returns the entry at the head of the list
PLIST_ITEM RtlListGetTail(PLIST_ITEM ListHead); // Returns the entry at the tail of the list
BOOL RtlListIsEmpty(PLIST_ITEM ListHead); // Indicates whether a doubly linked list is empty
ULONG RtlListCountEntries(PLIST_ITEM ListHead); // Counts the entries in a doubly linked list
PLIST_ITEM RtlListGetPrevious(PLIST_ITEM ListEntry); // Returns the previous item in the list
PLIST_ITEM RtlListGetNext(PLIST_ITEM ListEntry); // Returns the next item in the list
PLIST_ITEM RtlListRemoveEntry(PLIST_ITEM ListEntry); // Removes the entry from the list
VOID RtlListInsertEntry(PLIST_ITEM InsertAfter, PLIST_ITEM ListEntry); // Inserts a new list entry right after the specified one
VOID RtlListMoveEntryPrevious(PLIST_ITEM ListEntry); // Moves the list entry to before the previous entry
VOID RtlListMoveEntryNext(PLIST_ITEM ListEntry); // Moves the list entry to after the next entry
#endif // defined __STDLIB_H

View File

@@ -1,84 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __UI_H
#define __UI_H
extern ULONG UiScreenWidth; // Screen Width
extern ULONG UiScreenHeight; // Screen Height
extern UCHAR UiStatusBarFgColor; // Status bar foreground color
extern UCHAR UiStatusBarBgColor; // Status bar background color
extern UCHAR UiBackdropFgColor; // Backdrop foreground color
extern UCHAR UiBackdropBgColor; // Backdrop background color
extern UCHAR UiBackdropFillStyle; // Backdrop fill style
extern UCHAR UiTitleBoxFgColor; // Title box foreground color
extern UCHAR UiTitleBoxBgColor; // Title box background color
extern UCHAR UiMessageBoxFgColor; // Message box foreground color
extern UCHAR UiMessageBoxBgColor; // Message box background color
extern UCHAR UiMenuFgColor; // Menu foreground color
extern UCHAR UiMenuBgColor; // Menu background color
extern UCHAR UiTextColor; // Normal text color
extern UCHAR UiSelectedTextColor; // Selected text color
extern UCHAR UiSelectedTextBgColor; // Selected text background color
extern UCHAR UiTitleBoxTitleText[260]; // Title box's title text
extern PUCHAR UiMessageBoxLineText;
extern BOOL UserInterfaceUp; // Tells us if the user interface is displayed
extern UCHAR UiMonthNames[12][15];
///////////////////////////////////////////////////////////////////////////////////////
//
// User Interface Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL UiInitialize(VOID); // Initialize User-Interface
VOID UiDrawBackdrop(VOID); // Fills the entire screen with a backdrop
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr); // Draws a box around the area specified
VOID UiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr); // Draws text at coordinates specified
VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PUCHAR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges
VOID UiDrawStatusText(PUCHAR StatusText); // Draws text at the very bottom line on the screen
VOID UiUpdateDateTime(VOID); // Updates the date and time
VOID UiMessageBox(PUCHAR MessageText); // Displays a message box on the screen with an ok button
VOID UiMessageBoxCritical(PUCHAR MessageText); // Displays a message box on the screen with an ok button using no system resources
VOID UiMessageLine(PUCHAR MessageText); // Adds a line of text to the message box buffer
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range); // Draws the progress bar showing nPos percent filled
VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range); // Draws the progress bar showing nPos percent filled
VOID UiShowMessageBoxesInSection(PUCHAR SectionName); // Displays all the message boxes in a given section
UCHAR UiTextToColor(PUCHAR ColorText); // Converts the text color into it's equivalent color value
UCHAR UiTextToFillStyle(PUCHAR FillStyleText); // Converts the text fill into it's equivalent fill value
VOID UiTruncateStringEllipsis(PUCHAR StringText, ULONG MaxChars); // Truncates a string to MaxChars by adding an ellipsis on the end '...'
///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL UiDisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem);
#endif // #defined __UI_H

View File

@@ -1,45 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __VERSION_H
#define __VERSION_H
/* just some stuff */
#define VERSION "FreeLoader v1.3.1"
#define COPYRIGHT "Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>"
#define AUTHOR_EMAIL "<brianp@sginet.com>"
#define BY_AUTHOR "by Brian Palmer"
// FreeLoader version defines
//
// NOTE:
// If you fix bugs then you increment the patch version
// If you add features then you increment the minor version and zero the patch version
// If you add major functionality then you increment the major version and zero the minor & patch versions
//
#define FREELOADER_MAJOR_VERSION 1
#define FREELOADER_MINOR_VERSION 3
#define FREELOADER_PATCH_VERSION 1
PUCHAR GetFreeLoaderVersionString(VOID);
#endif // defined __VERSION_H

View File

@@ -1,79 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __VIDEO_H
#define __VIDEO_H
#define VIDEOCARD_CGA_OR_OTHER 0
#define VIDEOCARD_EGA 1
#define VIDEOCARD_VGA 2
#define VIDEOMODE_NORMAL_TEXT 0
#define VIDEOMODE_EXTENDED_TEXT 1
#define VIDEOMODE_80X28 0x501C
#define VIDEOMODE_80X30 0x501E
#define VIDEOMODE_80X34 0x5022
#define VIDEOMODE_80X43 0x502B
#define VIDEOMODE_80X60 0x503C
#define VIDEOPORT_PALETTE_READ 0x03C7
#define VIDEOPORT_PALETTE_WRITE 0x03C8
#define VIDEOPORT_PALETTE_DATA 0x03C9
#define VIDEOPORT_VERTICAL_RETRACE 0x03DA
VOID BiosSetVideoMode(ULONG VideoMode); // Implemented in biosvid.S
VOID BiosSetVideoFont8x8(VOID); // Implemented in biosvid.S
VOID BiosSetVideoFont8x14(VOID); // Implemented in biosvid.S
VOID BiosSetVideoFont8x16(VOID); // Implemented in biosvid.S
VOID BiosSelectAlternatePrintScreen(VOID); // Implemented in biosvid.S
VOID BiosDisableCursorEmulation(VOID); // Implemented in biosvid.S
VOID BiosDefineCursor(ULONG StartScanLine, ULONG EndScanLine); // Implemented in biosvid.S
ULONG BiosDetectVideoCard(VOID); // Implemented in biosvid.S
VOID BiosSet200ScanLines(VOID); // Implemented in biosvid.S, must be called right before BiosSetVideoMode()
VOID BiosSet350ScanLines(VOID); // Implemented in biosvid.S, must be called right before BiosSetVideoMode()
VOID BiosSet400ScanLines(VOID); // Implemented in biosvid.S, must be called right before BiosSetVideoMode()
VOID BiosSet480ScanLines(VOID); // Implemented in biosvid.S, must be called right after BiosSetVideoMode()
VOID BiosSetVideoDisplayEnd(VOID); // Implemented in biosvid.S
VOID VideoSetTextCursorPosition(ULONG X, ULONG Y); // Implemented in biosvid.S
VOID VideoHideTextCursor(VOID); // Implemented in biosvid.S
VOID VideoShowTextCursor(VOID); // Implemented in biosvid.S
ULONG VideoGetTextCursorPositionX(VOID); // Implemented in biosvid.S
ULONG VideoGetTextCursorPositionY(VOID); // Implemented in biosvid.S
BOOL VideoSetMode(ULONG VideoMode);
BOOL VideoSetMode80x25(VOID); // Sets 80x25
BOOL VideoSetMode80x50_80x43(VOID); // Sets 80x50 (VGA) or 80x43 (EGA) 8-pixel mode
BOOL VideoSetMode80x28(VOID); // Sets 80x28. Works on all VGA's. Standard 80x25 with 14-point font
BOOL VideoSetMode80x43(VOID); // Sets 80x43. Works on all VGA's. It's a 350-scanline mode with 8-pixel font.
BOOL VideoSetMode80x30(VOID); // Sets 80x30. Works on all VGA's. 480 scanlines, 16-pixel font.
BOOL VideoSetMode80x34(VOID); // Sets 80x34. Works on all VGA's. 480 scanlines, 14-pixel font.
BOOL VideoSetMode80x60(VOID); // Sets 80x60. Works on all VGA's. 480 scanlines, 8-pixel font.
ULONG VideoGetCurrentModeResolutionX(VOID);
ULONG VideoGetCurrentModeResolutionY(VOID);
ULONG VideoGetCurrentMode(VOID);
VOID VideoClearScreen(VOID);
VOID VideoWaitForVerticalRetrace(VOID);
VOID VideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue);
VOID VideoGetPaletteColor(UCHAR Color, PUCHAR Red, PUCHAR Green, PUCHAR Blue);
#endif // defined __VIDEO_H

View File

@@ -1,72 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __INI_H
#define __INI_H
#include <rtl.h>
#define INI_FILE_COMMENT_CHAR ';'
// This structure describes a single .ini file item
// The item format in the .ini file is:
// Name=Value
typedef struct
{
LIST_ITEM ListEntry;
PUCHAR ItemName;
PUCHAR ItemValue;
} INI_SECTION_ITEM, *PINI_SECTION_ITEM;
// This structure describes a .ini file section
// The section format in the .ini file is:
// [Section Name]
// This structure has a list of section items with
// one INI_SECTION_ITEM for each line in the section
typedef struct
{
LIST_ITEM ListEntry;
PUCHAR SectionName;
ULONG SectionItemCount;
PINI_SECTION_ITEM SectionItemList;
} INI_SECTION, *PINI_SECTION;
extern PINI_SECTION IniFileSectionListHead;
extern ULONG IniFileSectionListCount;
BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize);
ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset);
ULONG IniGetNextLine(PUCHAR IniFileData, ULONG IniFileSize, PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset);
BOOL IniIsLineEmpty(PUCHAR LineOfText, ULONG TextLength);
BOOL IniIsCommentLine(PUCHAR LineOfText, ULONG TextLength);
BOOL IniIsSectionName(PUCHAR LineOfText, ULONG TextLength);
ULONG IniGetSectionNameSize(PUCHAR SectionNameLine, ULONG LineLength);
VOID IniExtractSectionName(PUCHAR SectionName, PUCHAR SectionNameLine, ULONG LineLength);
BOOL IniIsSetting(PUCHAR LineOfText, ULONG TextLength);
ULONG IniGetSettingNameSize(PUCHAR SettingNameLine, ULONG LineLength);
ULONG IniGetSettingValueSize(PUCHAR SettingValueLine, ULONG LineLength);
VOID IniExtractSettingName(PUCHAR SettingName, PUCHAR SettingNameLine, ULONG LineLength);
VOID IniExtractSettingValue(PUCHAR SettingValue, PUCHAR SettingValueLine, ULONG LineLength);
#endif // defined __INI_H

View File

@@ -1,78 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include "ini.h"
#include <fs.h>
#include <rtl.h>
#include <mm.h>
#include <debug.h>
BOOL IniFileInitialize(VOID)
{
PFILE Freeldr_Ini; // File handle for freeldr.ini
PUCHAR FreeLoaderIniFileData;
ULONG FreeLoaderIniFileSize;
BOOL Success;
// Open the boot drive for file access
if (!OpenDiskDrive(BootDrive, 0))
{
printf("Error opening boot drive for file access.\n");
return FALSE;
}
// Try to open freeldr.ini or fail
Freeldr_Ini = OpenFile("freeldr.ini");
if (Freeldr_Ini == NULL)
{
printf("FREELDR.INI not found.\nYou need to re-install FreeLoader.\n");
return FALSE;
}
// Get the file size & allocate enough memory for it
FreeLoaderIniFileSize = GetFileSize(Freeldr_Ini);
FreeLoaderIniFileData = MmAllocateMemory(FreeLoaderIniFileSize);
// If we are out of memory then return FALSE
if (FreeLoaderIniFileData == NULL)
{
printf("Out of memory while loading FREELDR.INI.\n");
CloseFile(Freeldr_Ini);
return FALSE;
}
// Read freeldr.ini off the disk
if (!ReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData))
{
CloseFile(Freeldr_Ini);
MmFreeMemory(FreeLoaderIniFileData);
return FALSE;
}
CloseFile(Freeldr_Ini);
// Parse the .ini file data
Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
MmFreeMemory(FreeLoaderIniFileData);
return Success;
}

View File

@@ -1,132 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include "ini.h"
#include <ui.h>
#include <rtl.h>
#include <debug.h>
BOOL IniOpenSection(PUCHAR SectionName, PULONG SectionId)
{
PINI_SECTION Section;
DbgPrint((DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName));
// Loop through each section and find the one they want
Section = (PINI_SECTION)RtlListGetHead((PLIST_ITEM)IniFileSectionListHead);
while (Section != NULL)
{
// Compare against the section name
if (stricmp(SectionName, Section->SectionName) == 0)
{
// We found it
*SectionId = (ULONG)Section;
DbgPrint((DPRINT_INIFILE, "IniOpenSection() Found it! SectionId = 0x%x\n", SectionId));
return TRUE;
}
// Get the next section in the list
Section = (PINI_SECTION)RtlListGetNext((PLIST_ITEM)Section);
}
DbgPrint((DPRINT_INIFILE, "IniOpenSection() Section not found.\n"));
return FALSE;
}
ULONG IniGetNumSectionItems(ULONG SectionId)
{
PINI_SECTION Section = (PINI_SECTION)SectionId;
DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() SectionId = 0x%x\n", SectionId));
DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount));
return Section->SectionItemCount;
}
BOOL IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize)
{
PINI_SECTION Section = (PINI_SECTION)SectionId;
PINI_SECTION_ITEM SectionItem;
#ifdef DEBUG
ULONG RealSettingNumber = SettingNumber;
#endif
DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId));
// Loop through each section item and find the one they want
SectionItem = (PINI_SECTION_ITEM)RtlListGetHead((PLIST_ITEM)Section->SectionItemList);
while (SectionItem != NULL)
{
// Check to see if this is the setting they want
if (SettingNumber == 0)
{
DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", RealSettingNumber));
DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName));
DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue));
strncpy(SettingName, SectionItem->ItemName, NameSize);
strncpy(SettingValue, SectionItem->ItemValue, ValueSize);
return TRUE;
}
// Nope, keep going
SettingNumber--;
// Get the next section item in the list
SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem);
}
DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", RealSettingNumber));
return FALSE;
}
BOOL IniReadSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize)
{
PINI_SECTION Section = (PINI_SECTION)SectionId;
PINI_SECTION_ITEM SectionItem;
DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() SectionId = 0x%x\n", SectionId));
// Loop through each section item and find the one they want
SectionItem = (PINI_SECTION_ITEM)RtlListGetHead((PLIST_ITEM)Section->SectionItemList);
while (SectionItem != NULL)
{
// Check to see if this is the setting they want
if (stricmp(SettingName, SectionItem->ItemName) == 0)
{
DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' found.\n", SettingName));
DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue));
strncpy(Buffer, SectionItem->ItemValue, BufferSize);
return TRUE;
}
// Get the next section item in the list
SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem);
}
DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' not found.\n", SettingName));
return FALSE;
}

View File

@@ -1,602 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include "ini.h"
#include <rtl.h>
#include <mm.h>
#include <debug.h>
PINI_SECTION IniFileSectionListHead = NULL;
ULONG IniFileSectionCount = 0;
ULONG IniFileSettingCount = 0;
BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize)
{
ULONG CurrentOffset;
ULONG CurrentLineNumber;
PUCHAR IniFileLine;
ULONG IniFileLineSize;
ULONG LineLength;
PINI_SECTION CurrentSection = NULL;
PINI_SECTION_ITEM CurrentItem = NULL;
DbgPrint((DPRINT_INIFILE, "IniParseFile() IniFileSize: %d\n", IniFileSize));
// Start with an 80-byte buffer
IniFileLineSize = 80;
IniFileLine = MmAllocateMemory(IniFileLineSize);
if (!IniFileLine)
{
return FALSE;
}
// Loop through each line and parse it
CurrentLineNumber = 0;
CurrentOffset = 0;
while (CurrentOffset < IniFileSize)
{
// First check the line size and increase our buffer if necessary
if (IniFileLineSize < IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset))
{
IniFileLineSize = IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset);
MmFreeMemory(IniFileLine);
IniFileLine = MmAllocateMemory(IniFileLineSize);
if (!IniFileLine)
{
return FALSE;
}
}
// Get the line of data
CurrentOffset = IniGetNextLine(IniFileData, IniFileSize, IniFileLine, IniFileLineSize, CurrentOffset);
LineLength = strlen(IniFileLine);
// If it is a blank line or a comment then skip it
if (IniIsLineEmpty(IniFileLine, LineLength) || IniIsCommentLine(IniFileLine, LineLength))
{
CurrentLineNumber++;
continue;
}
// Check if it is a new section
if (IniIsSectionName(IniFileLine, LineLength))
{
// Allocate a new section structure
CurrentSection = MmAllocateMemory(sizeof(INI_SECTION));
if (!CurrentSection)
{
MmFreeMemory(IniFileLine);
return FALSE;
}
RtlZeroMemory(CurrentSection, sizeof(INI_SECTION));
// Allocate the section name buffer
CurrentSection->SectionName = MmAllocateMemory(IniGetSectionNameSize(IniFileLine, LineLength));
if (!CurrentSection->SectionName)
{
MmFreeMemory(CurrentSection);
MmFreeMemory(IniFileLine);
return FALSE;
}
// Get the section name
IniExtractSectionName(CurrentSection->SectionName, IniFileLine, LineLength);
// Add it to the section list head
IniFileSectionCount++;
if (IniFileSectionListHead == NULL)
{
IniFileSectionListHead = CurrentSection;
}
else
{
RtlListInsertTail((PLIST_ITEM)IniFileSectionListHead, (PLIST_ITEM)CurrentSection);
}
CurrentLineNumber++;
continue;
}
// Check if it is a setting
if (IniIsSetting(IniFileLine, LineLength))
{
// First check to make sure we're inside a [section]
if (CurrentSection == NULL)
{
printf("Error: freeldr.ini:%ld: Setting '%s' found outside of a [section].\n", CurrentLineNumber, IniFileLine);
CurrentLineNumber++;
continue;
}
// Allocate a new item structure
CurrentItem = MmAllocateMemory(sizeof(INI_SECTION_ITEM));
if (!CurrentItem)
{
MmFreeMemory(IniFileLine);
return FALSE;
}
RtlZeroMemory(CurrentItem, sizeof(INI_SECTION_ITEM));
// Allocate the setting name buffer
CurrentItem->ItemName = MmAllocateMemory(IniGetSettingNameSize(IniFileLine, LineLength));
if (!CurrentItem->ItemName)
{
MmFreeMemory(CurrentItem);
MmFreeMemory(IniFileLine);
return FALSE;
}
// Allocate the setting value buffer
CurrentItem->ItemValue = MmAllocateMemory(IniGetSettingValueSize(IniFileLine, LineLength));
if (!CurrentItem->ItemValue)
{
MmFreeMemory(CurrentItem);
MmFreeMemory(IniFileLine);
return FALSE;
}
// Get the section name
IniExtractSettingName(CurrentItem->ItemName, IniFileLine, LineLength);
IniExtractSettingValue(CurrentItem->ItemValue, IniFileLine, LineLength);
// Add it to the current section
IniFileSettingCount++;
CurrentSection->SectionItemCount++;
if (CurrentSection->SectionItemList == NULL)
{
CurrentSection->SectionItemList = CurrentItem;
}
else
{
RtlListInsertTail((PLIST_ITEM)CurrentSection->SectionItemList, (PLIST_ITEM)CurrentItem);
}
CurrentLineNumber++;
continue;
}
CurrentLineNumber++;
}
DbgPrint((DPRINT_INIFILE, "Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount));
DbgPrint((DPRINT_INIFILE, "IniParseFile() done.\n"));
return TRUE;
}
ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset)
{
ULONG Idx;
ULONG LineCharCount = 0;
// Loop through counting chars until we hit the end of the
// file or we encounter a new line char
for (Idx=0; (CurrentOffset < IniFileSize); CurrentOffset++)
{
// Increment the line character count
LineCharCount++;
// Check for new line char
if (IniFileData[CurrentOffset] == '\n')
{
CurrentOffset++;
break;
}
}
// Add one for the NULL-terminator
LineCharCount++;
// Send back line character count
return LineCharCount;
}
ULONG IniGetNextLine(PUCHAR IniFileData, ULONG IniFileSize, PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
{
ULONG Idx;
// Loop through grabbing chars until we hit the end of the
// file or we encounter a new line char
for (Idx=0; (CurrentOffset < IniFileSize); CurrentOffset++)
{
// If we haven't exceeded our buffer size yet
// then store another char
if (Idx < (BufferSize - 1))
{
Buffer[Idx++] = IniFileData[CurrentOffset];
}
// Check for new line char
if (IniFileData[CurrentOffset] == '\n')
{
CurrentOffset++;
break;
}
}
// Terminate the string
Buffer[Idx] = '\0';
// Get rid of newline & linefeed characters (if any)
if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r'))
Buffer[strlen(Buffer)-1] = '\0';
if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r'))
Buffer[strlen(Buffer)-1] = '\0';
// Send back new offset
return CurrentOffset;
}
BOOL IniIsLineEmpty(PUCHAR LineOfText, ULONG TextLength)
{
ULONG Idx;
// Check for text (skipping whitespace)
for (Idx=0; Idx<TextLength; Idx++)
{
if ((LineOfText[Idx] == ' ') ||
(LineOfText[Idx] == '\t') ||
(LineOfText[Idx] == '\n') ||
(LineOfText[Idx] == '\r'))
{
continue;
}
else
{
return FALSE;
}
}
return TRUE;
}
BOOL IniIsCommentLine(PUCHAR LineOfText, ULONG TextLength)
{
ULONG Idx;
// Check the first character (skipping whitespace)
// and make sure that it is an opening bracket
for (Idx=0; Idx<TextLength; Idx++)
{
if ((LineOfText[Idx] == ' ') ||
(LineOfText[Idx] == '\t'))
{
continue;
}
else if (LineOfText[Idx] == INI_FILE_COMMENT_CHAR)
{
return TRUE;
}
else
{
break;
}
}
return FALSE;
}
BOOL IniIsSectionName(PUCHAR LineOfText, ULONG TextLength)
{
ULONG Idx;
// Check the first character (skipping whitespace)
// and make sure that it is an opening bracket
for (Idx=0; Idx<TextLength; Idx++)
{
if ((LineOfText[Idx] == ' ') ||
(LineOfText[Idx] == '\t'))
{
continue;
}
else if (LineOfText[Idx] == '[')
{
return TRUE;
}
else
{
break;
}
}
return FALSE;
}
ULONG IniGetSectionNameSize(PUCHAR SectionNameLine, ULONG LineLength)
{
ULONG Idx;
ULONG NameSize;
// Find the opening bracket (skipping whitespace)
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SectionNameLine[Idx] == ' ') ||
(SectionNameLine[Idx] == '\t'))
{
continue;
}
else //if (SectionNameLine[Idx] == '[')
{
break;
}
}
// Skip past the opening bracket
Idx++;
// Count the characters up until the closing bracket or EOL
for (NameSize=0; Idx<LineLength; Idx++)
{
if ((SectionNameLine[Idx] == ']') ||
(SectionNameLine[Idx] == '\0'))
{
break;
}
// Increment the count
NameSize++;
}
// Add one for the NULL-terminator
NameSize++;
return NameSize;
}
VOID IniExtractSectionName(PUCHAR SectionName, PUCHAR SectionNameLine, ULONG LineLength)
{
ULONG Idx;
ULONG DestIdx;
// Find the opening bracket (skipping whitespace)
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SectionNameLine[Idx] == ' ') ||
(SectionNameLine[Idx] == '\t'))
{
continue;
}
else //if (SectionNameLine[Idx] == '[')
{
break;
}
}
// Skip past the opening bracket
Idx++;
// Count the characters up until the closing bracket or EOL
for (DestIdx=0; Idx<LineLength; Idx++)
{
if ((SectionNameLine[Idx] == ']') ||
(SectionNameLine[Idx] == '\0'))
{
break;
}
// Grab a character and increment DestIdx
SectionName[DestIdx] = SectionNameLine[Idx];
DestIdx++;
}
// Terminate the string
SectionName[DestIdx] = '\0';
}
BOOL IniIsSetting(PUCHAR LineOfText, ULONG TextLength)
{
ULONG Idx;
// Basically just check for an '=' equals sign
for (Idx=0; Idx<TextLength; Idx++)
{
if (LineOfText[Idx] == '=')
{
return TRUE;
}
}
return FALSE;
}
ULONG IniGetSettingNameSize(PUCHAR SettingNameLine, ULONG LineLength)
{
ULONG Idx;
ULONG NameSize;
// Skip whitespace
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SettingNameLine[Idx] == ' ') ||
(SettingNameLine[Idx] == '\t'))
{
continue;
}
else
{
break;
}
}
// Count the characters up until the '=' equals sign or EOL
for (NameSize=0; Idx<LineLength; Idx++)
{
if ((SettingNameLine[Idx] == '=') ||
(SettingNameLine[Idx] == '\0'))
{
break;
}
// Increment the count
NameSize++;
}
// Add one for the NULL-terminator
NameSize++;
return NameSize;
}
ULONG IniGetSettingValueSize(PUCHAR SettingValueLine, ULONG LineLength)
{
ULONG Idx;
ULONG ValueSize;
// Skip whitespace
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SettingValueLine[Idx] == ' ') ||
(SettingValueLine[Idx] == '\t'))
{
continue;
}
else
{
break;
}
}
// Skip the characters up until the '=' equals sign or EOL
for (; Idx<LineLength; Idx++)
{
if (SettingValueLine[Idx] == '=')
{
Idx++;
break;
}
// If we hit EOL then obviously the value size is zero
if (SettingValueLine[Idx] == '\0')
{
return 0;
}
}
// Count the characters up until the EOL
for (ValueSize=0; Idx<LineLength; Idx++)
{
if (SettingValueLine[Idx] == '\0')
{
break;
}
// Increment the count
ValueSize++;
}
// Add one for the NULL-terminator
ValueSize++;
return ValueSize;
}
VOID IniExtractSettingName(PUCHAR SettingName, PUCHAR SettingNameLine, ULONG LineLength)
{
ULONG Idx;
ULONG DestIdx;
// Skip whitespace
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SettingNameLine[Idx] == ' ') ||
(SettingNameLine[Idx] == '\t'))
{
continue;
}
else
{
break;
}
}
// Get the characters up until the '=' equals sign or EOL
for (DestIdx=0; Idx<LineLength; Idx++)
{
if ((SettingNameLine[Idx] == '=') ||
(SettingNameLine[Idx] == '\0'))
{
break;
}
// Grab a character and increment DestIdx
SettingName[DestIdx] = SettingNameLine[Idx];
DestIdx++;
}
// Terminate the string
SettingName[DestIdx] = '\0';
}
VOID IniExtractSettingValue(PUCHAR SettingValue, PUCHAR SettingValueLine, ULONG LineLength)
{
ULONG Idx;
ULONG DestIdx;
// Skip whitespace
for (Idx=0; Idx<LineLength; Idx++)
{
if ((SettingValueLine[Idx] == ' ') ||
(SettingValueLine[Idx] == '\t'))
{
continue;
}
else
{
break;
}
}
// Skip the characters up until the '=' equals sign or EOL
for (; Idx<LineLength; Idx++)
{
if (SettingValueLine[Idx] == '=')
{
Idx++;
break;
}
// If we hit EOL then obviously the value size is zero
if (SettingValueLine[Idx] == '\0')
{
SettingValue[0] = '\0';
return;
}
}
// Get the characters up until the EOL
for (DestIdx=0; Idx<LineLength; Idx++)
{
if (SettingValueLine[Idx] == '\0')
{
break;
}
// Grab a character and increment DestIdx
SettingValue[DestIdx] = SettingValueLine[Idx];
DestIdx++;
}
// Terminate the string
SettingValue[DestIdx] = '\0';
}

View File

@@ -1,460 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <arch.h>
#include <miscboot.h>
#include <rtl.h>
#include <fs.h>
#include <ui.h>
#include <linux.h>
#include <debug.h>
#include <mm.h>
#include <inifile.h>
#include <oslist.h> // For RemoveQuotes()
#include <video.h>
PLINUX_BOOTSECTOR LinuxBootSector = NULL;
PLINUX_SETUPSECTOR LinuxSetupSector = NULL;
ULONG SetupSectorSize = 0;
BOOL NewStyleLinuxKernel = FALSE;
ULONG LinuxKernelSize = 0;
UCHAR LinuxKernelName[260];
UCHAR LinuxInitrdName[260];
BOOL LinuxHasInitrd = FALSE;
UCHAR LinuxCommandLine[260] = "";
ULONG LinuxCommandLineSize = 0;
PVOID LinuxKernelLoadAddress = NULL;
PVOID LinuxInitrdLoadAddress = NULL;
VOID LoadAndBootLinux(PUCHAR OperatingSystemName)
{
PFILE LinuxKernel = NULL;
UCHAR TempString[260];
UiDrawBackdrop();
// Parse the .ini file section
if (!LinuxParseIniSection(OperatingSystemName))
{
goto LinuxBootFailed;
}
// Open the boot volume
if (!OpenDiskDrive(BootDrive, BootPartition))
{
UiMessageBox("Failed to open boot drive.");
goto LinuxBootFailed;
}
// Open the kernel
LinuxKernel = OpenFile(LinuxKernelName);
if (LinuxKernel == NULL)
{
sprintf(TempString, "Linux kernel \'%s\' not found.", LinuxKernelName);
UiMessageBox(TempString);
goto LinuxBootFailed;
}
// Read the boot sector
if (!LinuxReadBootSector(LinuxKernel))
{
goto LinuxBootFailed;
}
// Read the setup sector
if (!LinuxReadSetupSector(LinuxKernel))
{
goto LinuxBootFailed;
}
// Read the kernel
if (!LinuxReadKernel(LinuxKernel))
{
goto LinuxBootFailed;
}
// Read the initrd (if necessary)
if (LinuxHasInitrd)
{
if (!LinuxReadInitrd())
{
goto LinuxBootFailed;
}
}
// If the default root device is set to FLOPPY (0000h), change to /dev/fd0 (0200h)
if (LinuxBootSector->RootDevice == 0x0000)
{
LinuxBootSector->RootDevice = 0x0200;
}
LinuxBootSector->CommandLineMagic = LINUX_COMMAND_LINE_MAGIC;
LinuxBootSector->CommandLineOffset = 0x9000;
if (NewStyleLinuxKernel)
{
LinuxSetupSector->TypeOfLoader = LINUX_LOADER_TYPE_FREELOADER;
}
else
{
LinuxSetupSector->LoadFlags = 0;
}
RtlCopyMemory((PVOID)0x90000, LinuxBootSector, 512);
RtlCopyMemory((PVOID)0x90200, LinuxSetupSector, SetupSectorSize);
RtlCopyMemory((PVOID)0x99000, LinuxCommandLine, LinuxCommandLineSize);
VideoShowTextCursor();
VideoClearScreen();
StopFloppyMotor();
if (LinuxSetupSector->LoadFlags & LINUX_FLAG_LOAD_HIGH)
{
BootNewLinuxKernel();
}
else
{
BootOldLinuxKernel(LinuxKernelSize);
}
LinuxBootFailed:
if (LinuxKernel != NULL)
{
CloseFile(LinuxKernel);
}
if (LinuxBootSector != NULL)
{
MmFreeMemory(LinuxBootSector);
}
if (LinuxSetupSector != NULL)
{
MmFreeMemory(LinuxSetupSector);
}
if (LinuxKernelLoadAddress != NULL)
{
MmFreeMemory(LinuxKernelLoadAddress);
}
if (LinuxInitrdLoadAddress != NULL)
{
MmFreeMemory(LinuxInitrdLoadAddress);
}
LinuxBootSector = NULL;
LinuxSetupSector = NULL;
LinuxKernelLoadAddress = NULL;
LinuxInitrdLoadAddress = NULL;
SetupSectorSize = 0;
NewStyleLinuxKernel = FALSE;
LinuxKernelSize = 0;
LinuxHasInitrd = FALSE;
strcpy(LinuxCommandLine, "");
LinuxCommandLineSize = 0;
}
BOOL LinuxParseIniSection(PUCHAR OperatingSystemName)
{
UCHAR SettingName[260];
UCHAR SettingValue[260];
ULONG SectionId;
// Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!IniOpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
UiMessageBox(SettingName);
return FALSE;
}
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 260))
{
UiMessageBox("Boot drive not specified for selected OS!");
return FALSE;
}
BootDrive = atoi(SettingValue);
BootPartition = 0;
if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 260))
{
BootPartition = atoi(SettingValue);
}
// Get the kernel name
if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, 260))
{
UiMessageBox("Linux kernel filename not specified for selected OS!");
return FALSE;
}
// Get the initrd name
if (IniReadSettingByName(SectionId, "Initrd", LinuxInitrdName, 260))
{
LinuxHasInitrd = TRUE;
}
// Get the command line
if (IniReadSettingByName(SectionId, "CommandLine", LinuxCommandLine, 260))
{
RemoveQuotes(LinuxCommandLine);
LinuxCommandLineSize = strlen(LinuxCommandLine) + 1;
}
return TRUE;
}
BOOL LinuxReadBootSector(PFILE LinuxKernelFile)
{
// Allocate memory for boot sector
LinuxBootSector = (PLINUX_BOOTSECTOR)MmAllocateMemory(512);
if (LinuxBootSector == NULL)
{
return FALSE;
}
// Read linux boot sector
SetFilePointer(LinuxKernelFile, 0);
if (!ReadFile(LinuxKernelFile, 512, NULL, LinuxBootSector))
{
return FALSE;
}
// Check for validity
if (LinuxBootSector->BootFlag != LINUX_BOOT_SECTOR_MAGIC)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
return FALSE;
}
DbgDumpBuffer(DPRINT_LINUX, LinuxBootSector, 512);
DbgPrint((DPRINT_LINUX, "SetupSectors: %d\n", LinuxBootSector->SetupSectors));
DbgPrint((DPRINT_LINUX, "RootFlags: 0x%x\n", LinuxBootSector->RootFlags));
DbgPrint((DPRINT_LINUX, "SystemSize: 0x%x\n", LinuxBootSector->SystemSize));
DbgPrint((DPRINT_LINUX, "SwapDevice: 0x%x\n", LinuxBootSector->SwapDevice));
DbgPrint((DPRINT_LINUX, "RamSize: 0x%x\n", LinuxBootSector->RamSize));
DbgPrint((DPRINT_LINUX, "VideoMode: 0x%x\n", LinuxBootSector->VideoMode));
DbgPrint((DPRINT_LINUX, "RootDevice: 0x%x\n", LinuxBootSector->RootDevice));
DbgPrint((DPRINT_LINUX, "BootFlag: 0x%x\n", LinuxBootSector->BootFlag));
return TRUE;
}
BOOL LinuxReadSetupSector(PFILE LinuxKernelFile)
{
BYTE TempLinuxSetupSector[512];
LinuxSetupSector = (PLINUX_SETUPSECTOR)TempLinuxSetupSector;
// Read first linux setup sector
SetFilePointer(LinuxKernelFile, 512);
if (!ReadFile(LinuxKernelFile, 512, NULL, TempLinuxSetupSector))
{
return FALSE;
}
// Check the kernel version
if (!LinuxCheckKernelVersion())
{
return FALSE;
}
if (NewStyleLinuxKernel)
{
SetupSectorSize = 512 * LinuxBootSector->SetupSectors;
}
else
{
SetupSectorSize = 4 * 512; // Always 4 setup sectors
}
// Allocate memory for setup sectors
LinuxSetupSector = (PLINUX_SETUPSECTOR)MmAllocateMemory(SetupSectorSize);
if (LinuxSetupSector == NULL)
{
return FALSE;
}
// Copy over first setup sector
RtlCopyMemory(LinuxSetupSector, TempLinuxSetupSector, 512);
// Read in the rest of the linux setup sectors
SetFilePointer(LinuxKernelFile, 1024);
if (!ReadFile(LinuxKernelFile, SetupSectorSize - 512, NULL, ((PVOID)LinuxSetupSector) + 512))
{
return FALSE;
}
DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize);
DbgPrint((DPRINT_LINUX, "SetupHeaderSignature: 0x%x (HdrS)\n", LinuxSetupSector->SetupHeaderSignature));
DbgPrint((DPRINT_LINUX, "Version: 0x%x\n", LinuxSetupSector->Version));
DbgPrint((DPRINT_LINUX, "RealModeSwitch: 0x%x\n", LinuxSetupSector->RealModeSwitch));
DbgPrint((DPRINT_LINUX, "SetupSeg: 0x%x\n", LinuxSetupSector->SetupSeg));
DbgPrint((DPRINT_LINUX, "StartSystemSeg: 0x%x\n", LinuxSetupSector->StartSystemSeg));
DbgPrint((DPRINT_LINUX, "KernelVersion: 0x%x\n", LinuxSetupSector->KernelVersion));
DbgPrint((DPRINT_LINUX, "TypeOfLoader: 0x%x\n", LinuxSetupSector->TypeOfLoader));
DbgPrint((DPRINT_LINUX, "LoadFlags: 0x%x\n", LinuxSetupSector->LoadFlags));
DbgPrint((DPRINT_LINUX, "SetupMoveSize: 0x%x\n", LinuxSetupSector->SetupMoveSize));
DbgPrint((DPRINT_LINUX, "Code32Start: 0x%x\n", LinuxSetupSector->Code32Start));
DbgPrint((DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress));
DbgPrint((DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize));
DbgPrint((DPRINT_LINUX, "BootSectKludgeOffset: 0x%x\n", LinuxSetupSector->BootSectKludgeOffset));
DbgPrint((DPRINT_LINUX, "BootSectKludgeSegment: 0x%x\n", LinuxSetupSector->BootSectKludgeSegment));
DbgPrint((DPRINT_LINUX, "HeapEnd: 0x%x\n", LinuxSetupSector->HeapEnd));
return TRUE;
}
BOOL LinuxReadKernel(PFILE LinuxKernelFile)
{
ULONG BytesLoaded;
UCHAR StatusText[260];
PVOID LoadAddress;
sprintf(StatusText, "Loading %s", LinuxKernelName);
UiDrawStatusText(StatusText);
UiDrawProgressBarCenter(0, 100);
// Calc kernel size
LinuxKernelSize = GetFileSize(LinuxKernelFile) - (512 + SetupSectorSize);
// Allocate memory for Linux kernel
LinuxKernelLoadAddress = MmAllocateMemoryAtAddress(LinuxKernelSize, (PVOID)LINUX_KERNEL_LOAD_ADDRESS);
if (LinuxKernelLoadAddress != (PVOID)LINUX_KERNEL_LOAD_ADDRESS)
{
return FALSE;
}
LoadAddress = LinuxKernelLoadAddress;
// Read linux kernel to 0x100000 (1mb)
SetFilePointer(LinuxKernelFile, 512 + SetupSectorSize);
for (BytesLoaded=0; BytesLoaded<LinuxKernelSize; )
{
if (!ReadFile(LinuxKernelFile, 0x4000, NULL, LoadAddress))
{
return FALSE;
}
BytesLoaded += 0x4000;
LoadAddress += 0x4000;
UiDrawProgressBarCenter(BytesLoaded, LinuxKernelSize);
}
return TRUE;
}
BOOL LinuxCheckKernelVersion(VOID)
{
// Just assume old kernel until we find otherwise
NewStyleLinuxKernel = FALSE;
// Check for new style setup header
if (LinuxSetupSector->SetupHeaderSignature != LINUX_SETUP_HEADER_ID)
{
NewStyleLinuxKernel = FALSE;
}
// Check for version below 2.0
else if (LinuxSetupSector->Version < 0x0200)
{
NewStyleLinuxKernel = FALSE;
}
// Check for version 2.0
else if (LinuxSetupSector->Version == 0x0200)
{
NewStyleLinuxKernel = TRUE;
}
// Check for version 2.01+
else if (LinuxSetupSector->Version >= 0x0201)
{
NewStyleLinuxKernel = TRUE;
LinuxSetupSector->HeapEnd = 0x9000;
LinuxSetupSector->LoadFlags |= LINUX_FLAG_CAN_USE_HEAP;
}
if ((NewStyleLinuxKernel == FALSE) && (LinuxHasInitrd == TRUE))
{
UiMessageBox("Error: Cannot load a ramdisk (initrd) with an old kernel image.");
return FALSE;
}
return TRUE;
}
BOOL LinuxReadInitrd(VOID)
{
PFILE LinuxInitrdFile;
UCHAR TempString[260];
ULONG LinuxInitrdSize;
ULONG BytesLoaded;
UCHAR StatusText[260];
sprintf(StatusText, "Loading %s", LinuxInitrdName);
UiDrawStatusText(StatusText);
UiDrawProgressBarCenter(0, 100);
// Open the initrd file image
LinuxInitrdFile = OpenFile(LinuxInitrdName);
if (LinuxInitrdFile == NULL)
{
sprintf(TempString, "Linux initrd image \'%s\' not found.", LinuxInitrdName);
UiMessageBox(TempString);
return FALSE;
}
// Get the file size
LinuxInitrdSize = GetFileSize(LinuxInitrdFile);
// Allocate memory for the ramdisk
LinuxInitrdLoadAddress = MmAllocateMemory(LinuxInitrdSize);
if (LinuxInitrdLoadAddress == NULL)
{
return FALSE;
}
// Set the information in the setup struct
LinuxSetupSector->RamdiskAddress = (ULONG)LinuxInitrdLoadAddress;
LinuxSetupSector->RamdiskSize = LinuxInitrdSize;
// Read in the ramdisk
for (BytesLoaded=0; BytesLoaded<LinuxInitrdSize; )
{
if (!ReadFile(LinuxInitrdFile, 0x4000, NULL, (PVOID)LinuxInitrdLoadAddress))
{
return FALSE;
}
BytesLoaded += 0x4000;
LinuxInitrdLoadAddress += 0x4000;
UiDrawProgressBarCenter(BytesLoaded, LinuxInitrdSize);
}
return TRUE;
}

View File

@@ -1,230 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <arch.h>
#include <miscboot.h>
#include <rtl.h>
#include <fs.h>
#include <ui.h>
#include <inifile.h>
#include <disk.h>
#include <video.h>
VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
{
PFILE FilePointer;
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
UCHAR FileName[260];
ULONG BytesRead;
// Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!IniOpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
UiMessageBox(SettingName);
return;
}
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
UiMessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(SettingValue);
BootPartition = 0;
if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
{
BootPartition = atoi(SettingValue);
}
if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, 260))
{
UiMessageBox("Boot sector file not specified for selected OS!");
return;
}
if (!OpenDiskDrive(BootDrive, BootPartition))
{
UiMessageBox("Failed to open boot drive.");
return;
}
FilePointer = OpenFile(FileName);
if (FilePointer == NULL)
{
strcat(FileName, " not found.");
UiMessageBox(FileName);
return;
}
// Read boot sector
if (!ReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
{
return;
}
// Check for validity
if (*((PWORD)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
return;
}
VideoClearScreen();
VideoShowTextCursor();
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
//StopFloppyMotor();
ChainLoadBiosBootSectorCode();
}
VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
{
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
PARTITION_TABLE_ENTRY PartitionTableEntry;
// Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!IniOpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
UiMessageBox(SettingName);
return;
}
// Read the boot drive
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
UiMessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(SettingValue);
// Read the boot partition
if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
{
UiMessageBox("Boot partition not specified for selected OS!");
return;
}
BootPartition = atoi(SettingValue);
// Get the partition table entry
if (!DiskGetPartitionEntry(BootDrive, BootPartition, &PartitionTableEntry))
{
return;
}
// Now try to read the partition boot sector
// If this fails then abort
if (!DiskReadLogicalSectors(BootDrive, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00))
{
return;
}
// Check for validity
if (*((PWORD)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
return;
}
VideoClearScreen();
VideoShowTextCursor();
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
//StopFloppyMotor();
ChainLoadBiosBootSectorCode();
}
VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
{
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
// Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!IniOpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
UiMessageBox(SettingName);
return;
}
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
UiMessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(SettingValue);
// Now try to read the boot sector (or mbr)
// If this fails then abort
if (!DiskReadLogicalSectors(BootDrive, 0, 1, (PVOID)0x7C00))
{
return;
}
// Check for validity
if (*((PWORD)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
return;
}
VideoClearScreen();
VideoShowTextCursor();
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
//StopFloppyMotor();
ChainLoadBiosBootSectorCode();
}

View File

@@ -1,65 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MEM_H
#define __MEM_H
#define MM_PAGE_SIZE 4096
typedef struct
{
UINT32 PageAllocated; // Zero = free, non-zero = allocated
UINT32 PageAllocationLength; // Number of pages allocated (or zero if this isn't the first page in the chain)
} PAGE_LOOKUP_TABLE_ITEM, *PPAGE_LOOKUP_TABLE_ITEM;
//
// Define this to 1 if you want the entire contents
// of the memory allocation bitmap displayed
// when a chunk is allocated or freed
//
#define DUMP_MEM_MAP_ON_VERIFY 0
extern PVOID PageLookupTableAddress;
extern ULONG TotalPagesInLookupTable;
extern ULONG FreePagesInLookupTable;
extern ULONG LastFreePageHint;
#ifdef DEBUG
PUCHAR MmGetSystemMemoryMapTypeString(ULONG Type);
#endif
ULONG MmGetPageNumberFromAddress(PVOID Address); // Returns the page number that contains a linear address
PVOID MmGetEndAddressOfAnyMemory(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount); // Returns the last address of memory from the memory map
ULONG MmGetAddressablePageCountIncludingHoles(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount); // Returns the count of addressable pages from address zero including any memory holes and reserved memory regions
PVOID MmFindLocationForPageLookupTable(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount); // Returns the address for a memory chunk big enough to hold the page lookup table (starts search from end of memory)
VOID MmSortBiosMemoryMap(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount); // Sorts the BIOS_MEMORY_MAP array so the first element corresponds to the first address in memory
VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount, BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount); // Inits the page lookup table according to the memory types in the memory map
VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, ULONG PageAllocated); // Marks the specified pages as allocated or free in the lookup table
VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount); // Allocates the specified pages in the lookup table
ULONG MmCountFreePagesInLookupTable(PVOID PageLookupTable, ULONG TotalPageCount); // Returns the number of free pages in the lookup table
ULONG MmFindAvailablePagesFromEnd(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded); // Returns the page number of the first available page range from the end of memory
VOID MmFixupSystemMemoryMap(BIOS_MEMORY_MAP BiosMemoryMap[32], PULONG MapCount); // Removes entries in the memory map that describe memory above 4G
VOID MmUpdateLastFreePageHint(PVOID PageLookupTable, ULONG TotalPageCount); // Sets the LastFreePageHint to the last usable page of memory
BOOL MmAreMemoryPagesAvailable(PVOID PageLookupTable, ULONG TotalPageCount, PVOID PageAddress, ULONG PageCount); // Returns TRUE if the specified pages of memory are available, otherwise FALSE
#endif // defined __MEM_H

View File

@@ -1,430 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <arch.h>
#include <mm.h>
#include "mem.h"
#include <rtl.h>
#include <debug.h>
#include <ui.h>
#ifdef DEBUG
typedef struct
{
ULONG Type;
UCHAR TypeString[20];
} MEMORY_TYPE, *PMEMORY_TYPE;
ULONG MemoryTypeCount = 5;
MEMORY_TYPE MemoryTypeArray[] =
{
{ 0, "Unknown Memory" },
{ MEMTYPE_USABLE, "Usable Memory" },
{ MEMTYPE_RESERVED, "Reserved Memory" },
{ MEMTYPE_ACPI_RECLAIM, "ACPI Reclaim Memory" },
{ MEMTYPE_ACPI_NVS, "ACPI NVS Memory" },
};
#endif
PVOID PageLookupTableAddress = NULL;
ULONG TotalPagesInLookupTable = 0;
ULONG FreePagesInLookupTable = 0;
ULONG LastFreePageHint = 0;
BOOL MmInitializeMemoryManager(VOID)
{
BIOS_MEMORY_MAP BiosMemoryMap[32];
ULONG BiosMemoryMapEntryCount;
ULONG ExtendedMemorySize;
ULONG ConventionalMemorySize;
ULONG Index;
DbgPrint((DPRINT_MEMORY, "Initializing Memory Manager.\n"));
RtlZeroMemory(BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
BiosMemoryMapEntryCount = GetBiosMemoryMap((PBIOS_MEMORY_MAP)&BiosMemoryMap);
ExtendedMemorySize = GetExtendedMemorySize();
ConventionalMemorySize = GetConventionalMemorySize();
// If we got the system memory map then fixup invalid entries
if (BiosMemoryMapEntryCount != 0)
{
MmFixupSystemMemoryMap(BiosMemoryMap, &BiosMemoryMapEntryCount);
}
#ifdef DEBUG
// Dump the system memory map
if (BiosMemoryMapEntryCount != 0)
{
DbgPrint((DPRINT_MEMORY, "System Memory Map (Base Address, Length, Type):\n"));
for (Index=0; Index<BiosMemoryMapEntryCount; Index++)
{
DbgPrint((DPRINT_MEMORY, "%x%x\t %x%x\t %s\n", BiosMemoryMap[Index].BaseAddressHigh, BiosMemoryMap[Index].BaseAddressLow, BiosMemoryMap[Index].LengthHigh, BiosMemoryMap[Index].LengthLow, MmGetSystemMemoryMapTypeString(BiosMemoryMap[Index].Type)));
}
}
else
{
DbgPrint((DPRINT_MEMORY, "GetBiosMemoryMap() not supported.\n"));
}
#endif
DbgPrint((DPRINT_MEMORY, "Extended memory size: %d KB\n", ExtendedMemorySize));
DbgPrint((DPRINT_MEMORY, "Conventional memory size: %d KB\n", ConventionalMemorySize));
// Since I don't feel like writing two sets of routines
// one to handle the BiosMemoryMap structure and another
// to handle just a flat extended memory size I'm going
// to create a 'fake' memory map entry out of the
// extended memory size if GetBiosMemoryMap() fails.
if (BiosMemoryMapEntryCount == 0)
{
BiosMemoryMap[0].BaseAddressLow = 0x100000; // Start at 1MB
BiosMemoryMap[0].BaseAddressHigh = 0;
BiosMemoryMap[0].LengthLow = ExtendedMemorySize * 1024;
BiosMemoryMap[0].LengthHigh = 0;
BiosMemoryMap[0].Type = MEMTYPE_USABLE;
BiosMemoryMapEntryCount = 1;
}
TotalPagesInLookupTable = MmGetAddressablePageCountIncludingHoles(BiosMemoryMap, BiosMemoryMapEntryCount);
PageLookupTableAddress = MmFindLocationForPageLookupTable(BiosMemoryMap, BiosMemoryMapEntryCount);
LastFreePageHint = TotalPagesInLookupTable;
if (PageLookupTableAddress == 0)
{
// If we get here then we probably couldn't
// find a contigous chunk of memory big
// enough to hold the page lookup table
printf("Error initializing memory manager!\n");
return FALSE;
}
MmInitPageLookupTable(PageLookupTableAddress, TotalPagesInLookupTable, BiosMemoryMap, BiosMemoryMapEntryCount);
MmUpdateLastFreePageHint(PageLookupTableAddress, TotalPagesInLookupTable);
FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress, TotalPagesInLookupTable);
DbgPrint((DPRINT_MEMORY, "Memory Manager initialized. %d pages available.\n", FreePagesInLookupTable));
return TRUE;
}
#ifdef DEBUG
PUCHAR MmGetSystemMemoryMapTypeString(ULONG Type)
{
ULONG Index;
for (Index=1; Index<MemoryTypeCount; Index++)
{
if (MemoryTypeArray[Index].Type == Type)
{
return MemoryTypeArray[Index].TypeString;
}
}
return MemoryTypeArray[0].TypeString;
}
#endif
ULONG MmGetPageNumberFromAddress(PVOID Address)
{
return ((ULONG)Address) / MM_PAGE_SIZE;
}
PVOID MmGetEndAddressOfAnyMemory(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount)
{
ULONG MaxStartAddressSoFar;
UINT64 EndAddressOfMemory;
ULONG Index;
MaxStartAddressSoFar = 0;
EndAddressOfMemory = 0;
for (Index=0; Index<MapCount; Index++)
{
if (MaxStartAddressSoFar < BiosMemoryMap[Index].BaseAddressLow)
{
MaxStartAddressSoFar = BiosMemoryMap[Index].BaseAddressLow;
EndAddressOfMemory = ((UINT64)MaxStartAddressSoFar + (UINT64)BiosMemoryMap[Index].LengthLow);
if (EndAddressOfMemory > 0xFFFFFFFF)
{
EndAddressOfMemory = 0xFFFFFFFF;
}
}
}
DbgPrint((DPRINT_MEMORY, "MmGetEndAddressOfAnyMemory() returning 0x%x\n", (UINT32)EndAddressOfMemory));
return (PVOID)(UINT32)EndAddressOfMemory;
}
ULONG MmGetAddressablePageCountIncludingHoles(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount)
{
ULONG PageCount;
PageCount = MmGetPageNumberFromAddress(MmGetEndAddressOfAnyMemory(BiosMemoryMap, MapCount));
DbgPrint((DPRINT_MEMORY, "MmGetAddressablePageCountIncludingHoles() returning %d\n", PageCount));
return PageCount;
}
PVOID MmFindLocationForPageLookupTable(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount)
{
ULONG TotalPageCount;
ULONG PageLookupTableSize;
PVOID PageLookupTableAddress;
int Index;
BIOS_MEMORY_MAP TempBiosMemoryMap[32];
TotalPageCount = MmGetAddressablePageCountIncludingHoles(BiosMemoryMap, MapCount);
PageLookupTableSize = TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM);
PageLookupTableAddress = 0;
RtlCopyMemory(TempBiosMemoryMap, BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
MmSortBiosMemoryMap(TempBiosMemoryMap, MapCount);
for (Index=(MapCount-1); Index>=0; Index--)
{
// If this is usable memory with a big enough length
// then we'll put our page lookup table here
if (TempBiosMemoryMap[Index].Type == MEMTYPE_USABLE && TempBiosMemoryMap[Index].LengthLow >= PageLookupTableSize)
{
PageLookupTableAddress = (PVOID)(TempBiosMemoryMap[Index].BaseAddressLow + (TempBiosMemoryMap[Index].LengthLow - PageLookupTableSize));
break;
}
}
DbgPrint((DPRINT_MEMORY, "MmFindLocationForPageLookupTable() returning 0x%x\n", PageLookupTableAddress));
return PageLookupTableAddress;
}
VOID MmSortBiosMemoryMap(BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount)
{
ULONG Index;
ULONG LoopCount;
BIOS_MEMORY_MAP TempMapItem;
// Loop once for each entry in the memory map minus one
// On each loop iteration go through and sort the memory map
for (LoopCount=0; LoopCount<(MapCount-1); LoopCount++)
{
for (Index=0; Index<(MapCount-1); Index++)
{
if (BiosMemoryMap[Index].BaseAddressLow > BiosMemoryMap[Index+1].BaseAddressLow)
{
TempMapItem = BiosMemoryMap[Index];
BiosMemoryMap[Index] = BiosMemoryMap[Index+1];
BiosMemoryMap[Index+1] = TempMapItem;
}
}
}
}
VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount, BIOS_MEMORY_MAP BiosMemoryMap[32], ULONG MapCount)
{
ULONG MemoryMapStartPage;
ULONG MemoryMapEndPage;
ULONG MemoryMapPageCount;
ULONG MemoryMapPageAllocated;
ULONG PageLookupTableStartPage;
ULONG PageLookupTablePageCount;
ULONG Index;
DbgPrint((DPRINT_MEMORY, "MmInitPageLookupTable()\n"));
// Mark every page as allocated initially
// We will go through and mark pages again according to the memory map
// But this will mark any holes not described in the map as allocated
MmMarkPagesInLookupTable(PageLookupTable, 0, TotalPageCount, 1);
for (Index=0; Index<MapCount; Index++)
{
MemoryMapStartPage = MmGetPageNumberFromAddress((PVOID)BiosMemoryMap[Index].BaseAddressLow);
MemoryMapEndPage = MmGetPageNumberFromAddress((PVOID)(BiosMemoryMap[Index].BaseAddressLow + BiosMemoryMap[Index].LengthLow - 1));
MemoryMapPageCount = (MemoryMapEndPage - MemoryMapStartPage) + 1;
MemoryMapPageAllocated = (BiosMemoryMap[Index].Type == MEMTYPE_USABLE) ? 0 : BiosMemoryMap[Index].Type;
DbgPrint((DPRINT_MEMORY, "Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryMapStartPage, MemoryMapPageCount));
MmMarkPagesInLookupTable(PageLookupTable, MemoryMapStartPage, MemoryMapPageCount, MemoryMapPageAllocated);
}
// Mark the low memory region below 1MB as reserved (256 pages in region)
DbgPrint((DPRINT_MEMORY, "Marking the low 1MB region as reserved.\n"));
MmMarkPagesInLookupTable(PageLookupTable, 0, 256, MEMTYPE_RESERVED);
// Mark the pages that the lookup tabel occupies as reserved
PageLookupTableStartPage = MmGetPageNumberFromAddress(PageLookupTable);
PageLookupTablePageCount = MmGetPageNumberFromAddress(PageLookupTable + ROUND_UP(TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM), MM_PAGE_SIZE)) - PageLookupTableStartPage;
DbgPrint((DPRINT_MEMORY, "Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount));
MmMarkPagesInLookupTable(PageLookupTable, PageLookupTableStartPage, PageLookupTablePageCount, MEMTYPE_RESERVED);
}
VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, ULONG PageAllocated)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
for (Index=StartPage; Index<(StartPage+PageCount); Index++)
{
RealPageLookupTable[Index].PageAllocated = PageAllocated;
RealPageLookupTable[Index].PageAllocationLength = PageAllocated ? 1 : 0;
}
}
VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
for (Index=StartPage; Index<(StartPage+PageCount); Index++)
{
RealPageLookupTable[Index].PageAllocated = 1;
RealPageLookupTable[Index].PageAllocationLength = (Index == StartPage) ? PageCount : 0;
}
}
ULONG MmCountFreePagesInLookupTable(PVOID PageLookupTable, ULONG TotalPageCount)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
ULONG FreePageCount;
FreePageCount = 0;
for (Index=0; Index<TotalPageCount; Index++)
{
if (RealPageLookupTable[Index].PageAllocated == 0)
{
FreePageCount++;
}
}
return FreePageCount;
}
ULONG MmFindAvailablePagesFromEnd(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG AvailablePageStart;
ULONG AvailablePagesSoFar;
ULONG Index;
if (LastFreePageHint > TotalPageCount)
{
LastFreePageHint = TotalPageCount;
}
AvailablePageStart = 0;
AvailablePagesSoFar = 0;
for (Index=LastFreePageHint-1; Index>=0; Index--)
{
if (RealPageLookupTable[Index].PageAllocated != 0)
{
AvailablePagesSoFar = 0;
continue;
}
else
{
AvailablePagesSoFar++;
}
if (AvailablePagesSoFar >= PagesNeeded)
{
return Index;
}
}
return 0;
}
VOID MmFixupSystemMemoryMap(BIOS_MEMORY_MAP BiosMemoryMap[32], PULONG MapCount)
{
int Index;
int Index2;
UINT64 RealLength;
// Loop through each entry in the array
for (Index=0; Index<*MapCount; Index++)
{
// If the base address for this entry starts at
// or above 4G then remove this entry
if (BiosMemoryMap[Index].BaseAddressHigh != 0)
{
// Slide every entry after this down one
for (Index2=Index; Index2<(*MapCount - 1); Index2++)
{
BiosMemoryMap[Index2] = BiosMemoryMap[Index2 + 1];
}
(*MapCount)--;
Index--;
}
// If the base address plus the length for this entry
// extends beyond 4G then truncate this entry
RealLength = BiosMemoryMap[Index].BaseAddressLow + BiosMemoryMap[Index].LengthLow;
if ((BiosMemoryMap[Index].LengthHigh != 0) || (RealLength > 0xFFFFFFFF))
{
BiosMemoryMap[Index].LengthLow = 0xFFFFFFFF - BiosMemoryMap[Index].BaseAddressLow;
}
}
}
VOID MmUpdateLastFreePageHint(PVOID PageLookupTable, ULONG TotalPageCount)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
for (Index=TotalPageCount-1; Index>=0; Index--)
{
if (RealPageLookupTable[Index].PageAllocated == 0)
{
LastFreePageHint = Index + 1;
break;
}
}
}
BOOL MmAreMemoryPagesAvailable(PVOID PageLookupTable, ULONG TotalPageCount, PVOID PageAddress, ULONG PageCount)
{
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG StartPage;
ULONG Index;
StartPage = MmGetPageNumberFromAddress(PageAddress);
// Make sure they aren't trying to go past the
// end of availabe memory
if ((StartPage + PageCount) > TotalPageCount)
{
return FALSE;
}
for (Index=StartPage; Index<(StartPage + PageCount); Index++)
{
// If this page is allocated then there obviously isn't
// memory availabe so return FALSE
if (RealPageLookupTable[Index].PageAllocated != 0)
{
return FALSE;
}
}
return TRUE;
}

View File

@@ -1,348 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <mm.h>
#include "mem.h"
#include <rtl.h>
#include <debug.h>
#include <ui.h>
#ifdef DEBUG
ULONG AllocationCount = 0;
VOID VerifyHeap(VOID);
VOID DumpMemoryAllocMap(VOID);
VOID IncrementAllocationCount(VOID);
VOID DecrementAllocationCount(VOID);
VOID MemAllocTest(VOID);
#endif // DEBUG
PVOID MmAllocateMemory(ULONG MemorySize)
{
ULONG PagesNeeded;
ULONG FirstFreePageFromEnd;
PVOID MemPointer;
if (MemorySize == 0)
{
DbgPrint((DPRINT_MEMORY, "MmAllocateMemory() called for 0 bytes. Returning NULL.\n"));
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemory() called for 0 bytes.");
return NULL;
}
// Find out how many blocks it will take to
// satisfy this allocation
PagesNeeded = ROUND_UP(MemorySize, MM_PAGE_SIZE) / MM_PAGE_SIZE;
// If we don't have enough available mem
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed. Not enough free memory to allocate %d bytes. AllocationCount: %d\n", MemorySize, AllocationCount));
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
FirstFreePageFromEnd = MmFindAvailablePagesFromEnd(PageLookupTableAddress, TotalPagesInLookupTable, PagesNeeded);
if (FirstFreePageFromEnd == 0)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed. Not enough free memory to allocate %d bytes. AllocationCount: %d\n", MemorySize, AllocationCount));
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MmAllocatePagesInLookupTable(PageLookupTableAddress, FirstFreePageFromEnd, PagesNeeded);
FreePagesInLookupTable -= PagesNeeded;
MemPointer = (PVOID)(FirstFreePageFromEnd * MM_PAGE_SIZE);
#ifdef DEBUG
IncrementAllocationCount();
DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d. AllocCount: %d\n", MemorySize, PagesNeeded, FirstFreePageFromEnd, AllocationCount));
DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
//VerifyHeap();
#endif // DEBUG
// Now return the pointer
return MemPointer;
}
PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress)
{
ULONG PagesNeeded;
ULONG StartPageNumber;
PVOID MemPointer;
if (MemorySize == 0)
{
DbgPrint((DPRINT_MEMORY, "MmAllocateMemoryAtAddress() called for 0 bytes. Returning NULL.\n"));
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemoryAtAddress() called for 0 bytes.");
return NULL;
}
// Find out how many blocks it will take to
// satisfy this allocation
PagesNeeded = ROUND_UP(MemorySize, MM_PAGE_SIZE) / MM_PAGE_SIZE;
// Get the starting page number
StartPageNumber = MmGetPageNumberFromAddress(DesiredAddress);
// If we don't have enough available mem
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed. Not enough free memory to allocate %d bytes. AllocationCount: %d\n", MemorySize, AllocationCount));
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (MmAreMemoryPagesAvailable(PageLookupTableAddress, TotalPagesInLookupTable, DesiredAddress, PagesNeeded) == FALSE)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed. Not enough free memory to allocate %d bytes. AllocationCount: %d\n", MemorySize, AllocationCount));
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MmAllocatePagesInLookupTable(PageLookupTableAddress, StartPageNumber, PagesNeeded);
FreePagesInLookupTable -= PagesNeeded;
MemPointer = (PVOID)(StartPageNumber * MM_PAGE_SIZE);
#ifdef DEBUG
IncrementAllocationCount();
DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d. AllocCount: %d\n", MemorySize, PagesNeeded, StartPageNumber, AllocationCount));
DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
//VerifyHeap();
#endif // DEBUG
// Now return the pointer
return MemPointer;
}
VOID MmFreeMemory(PVOID MemoryPointer)
{
ULONG PageNumber;
ULONG PageCount;
ULONG Idx;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
#ifdef DEBUG
// Make sure we didn't get a bogus pointer
if (MemoryPointer >= (PVOID)(TotalPagesInLookupTable * MM_PAGE_SIZE))
{
BugCheck((DPRINT_MEMORY, "Bogus memory pointer (0x%x) passed to MmFreeMemory()\n", MemoryPointer));
}
#endif // DEBUG
// Find out the page number of the first
// page of memory they allocated
PageNumber = MmGetPageNumberFromAddress(MemoryPointer);
PageCount = RealPageLookupTable[PageNumber].PageAllocationLength;
#ifdef DEBUG
// Make sure we didn't get a bogus pointer
if ((PageCount < 1) || (PageCount > (TotalPagesInLookupTable - PageNumber)))
{
BugCheck((DPRINT_MEMORY, "Invalid page count in lookup table. PageLookupTable[%d].PageAllocationLength = %d\n", PageNumber, RealPageLookupTable[PageNumber].PageAllocationLength));
}
// Loop through our array check all the pages
// to make sure they are allocated with a length of 0
for (Idx=PageNumber+1; Idx<(PageNumber + PageCount); Idx++)
{
if ((RealPageLookupTable[Idx].PageAllocated != 1) ||
(RealPageLookupTable[Idx].PageAllocationLength != 0))
{
BugCheck((DPRINT_MEMORY, "Invalid page entry in lookup table, PageAllocated should = 1 and PageAllocationLength should = 0 because this is not the first block in the run. PageLookupTable[%d].PageAllocated = %d PageLookupTable[%d].PageAllocationLength = %d\n", PageNumber, RealPageLookupTable[PageNumber].PageAllocated, PageNumber, RealPageLookupTable[PageNumber].PageAllocationLength));
}
}
#endif
// Loop through our array and mark all the
// blocks as free
for (Idx=PageNumber; Idx<(PageNumber + PageCount); Idx++)
{
RealPageLookupTable[Idx].PageAllocated = 0;
RealPageLookupTable[Idx].PageAllocationLength = 0;
}
#ifdef DEBUG
DecrementAllocationCount();
DbgPrint((DPRINT_MEMORY, "Freed %d pages of memory starting at page %d. AllocationCount: %d\n", PageCount, PageNumber, AllocationCount));
//VerifyHeap();
#endif // DEBUG
}
#ifdef DEBUG
VOID VerifyHeap(VOID)
{
ULONG Idx;
ULONG Idx2;
ULONG Count;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
if (DUMP_MEM_MAP_ON_VERIFY)
{
DumpMemoryAllocMap();
}
// Loop through the array and verify that
// everything is kosher
for (Idx=0; Idx<TotalPagesInLookupTable; Idx++)
{
// Check if this block is allocated
if (RealPageLookupTable[Idx].PageAllocated != 0)
{
// This is the first block in the run so it
// had better have a length that is within range
if ((RealPageLookupTable[Idx].PageAllocationLength < 1) || (RealPageLookupTable[Idx].PageAllocationLength > (TotalPagesInLookupTable - Idx)))
{
BugCheck((DPRINT_MEMORY, "Allocation length out of range in heap table. PageLookupTable[Idx].PageAllocationLength = %d\n", RealPageLookupTable[Idx].PageAllocationLength));
}
// Now go through and verify that the rest of
// this run has the blocks marked allocated
// with a length of zero but don't check the
// first one because we already did
Count = RealPageLookupTable[Idx].PageAllocationLength;
for (Idx2=1; Idx2<Count; Idx2++)
{
// Make sure it's allocated
if (RealPageLookupTable[Idx + Idx2].PageAllocated == 0)
{
BugCheck((DPRINT_MEMORY, "Lookup table indicates hole in memory allocation. RealPageLookupTable[Idx + Idx2].PageAllocated == 0\n"));
}
// Make sure the length is zero
if (RealPageLookupTable[Idx + Idx2].PageAllocationLength != 0)
{
BugCheck((DPRINT_MEMORY, "Allocation chain has non-zero value in non-first block in lookup table. RealPageLookupTable[Idx + Idx2].PageAllocationLength != 0\n"));
}
}
// Move on to the next run
Idx += (Count - 1);
}
else
{
// Nope, not allocated so make sure the length is zero
if (RealPageLookupTable[Idx].PageAllocationLength != 0)
{
BugCheck((DPRINT_MEMORY, "Free block is start of memory allocation. RealPageLookupTable[Idx].PageAllocationLength != 0\n"));
}
}
}
}
VOID DumpMemoryAllocMap(VOID)
{
ULONG Idx;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
DbgPrint((DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n"));
for (Idx=0; Idx<TotalPagesInLookupTable; Idx++)
{
if ((Idx % 32) == 0)
{
DbgPrint((DPRINT_MEMORY, "\n"));
DbgPrint((DPRINT_MEMORY, "%x:\t", (Idx * MM_PAGE_SIZE)));
}
else if ((Idx % 4) == 0)
{
DbgPrint((DPRINT_MEMORY, " "));
}
switch (RealPageLookupTable[Idx].PageAllocated)
{
case 0:
DbgPrint((DPRINT_MEMORY, "*"));
break;
case 1:
DbgPrint((DPRINT_MEMORY, "A"));
break;
case MEMTYPE_RESERVED:
DbgPrint((DPRINT_MEMORY, "R"));
break;
case MEMTYPE_ACPI_RECLAIM:
DbgPrint((DPRINT_MEMORY, "M"));
break;
case MEMTYPE_ACPI_NVS:
DbgPrint((DPRINT_MEMORY, "N"));
break;
default:
DbgPrint((DPRINT_MEMORY, "X"));
break;
}
}
DbgPrint((DPRINT_MEMORY, "\n"));
}
VOID IncrementAllocationCount(VOID)
{
AllocationCount++;
}
VOID DecrementAllocationCount(VOID)
{
AllocationCount--;
}
VOID MemAllocTest(VOID)
{
PVOID MemPtr1;
PVOID MemPtr2;
PVOID MemPtr3;
PVOID MemPtr4;
PVOID MemPtr5;
MemPtr1 = MmAllocateMemory(4096);
printf("MemPtr1: 0x%x\n", (int)MemPtr1);
getch();
MemPtr2 = MmAllocateMemory(4096);
printf("MemPtr2: 0x%x\n", (int)MemPtr2);
getch();
MemPtr3 = MmAllocateMemory(4096);
printf("MemPtr3: 0x%x\n", (int)MemPtr3);
DumpMemoryAllocMap();
VerifyHeap();
getch();
MmFreeMemory(MemPtr2);
getch();
MemPtr4 = MmAllocateMemory(2048);
printf("MemPtr4: 0x%x\n", (int)MemPtr4);
getch();
MemPtr5 = MmAllocateMemory(4096);
printf("MemPtr5: 0x%x\n", (int)MemPtr5);
getch();
}
#endif // DEBUG
ULONG GetSystemMemorySize(VOID)
{
return (TotalPagesInLookupTable * MM_PAGE_SIZE);
}

View File

@@ -1,270 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <arch.h>
#include <rtl.h>
#include <fs.h>
#include <multiboot.h>
#include <ui.h>
#include <inifile.h>
#include <mm.h>
unsigned long next_module_load_base = 0;
module_t* pOpenModule = NULL;
BOOL MultiBootLoadKernel(FILE *KernelImage)
{
PDWORD ImageHeaders;
int Idx;
DWORD dwHeaderChecksum;
DWORD dwFileLoadOffset;
DWORD dwDataSize;
DWORD dwBssSize;
// Allocate 8192 bytes for multiboot header
ImageHeaders = (PDWORD)MmAllocateMemory(8192);
if (ImageHeaders == NULL)
{
return FALSE;
}
/*
* Load the first 8192 bytes of the kernel image
* so we can search for the multiboot header
*/
if (!ReadFile(KernelImage, 8192, NULL, ImageHeaders))
{
MmFreeMemory(ImageHeaders);
return FALSE;
}
/*
* Now find the multiboot header and copy it
*/
for (Idx=0; Idx<2048; Idx++)
{
// Did we find it?
if (ImageHeaders[Idx] == MULTIBOOT_HEADER_MAGIC)
{
// Yes, copy it and break out of this loop
memcpy(&mb_header, &ImageHeaders[Idx], sizeof(multiboot_header_t));
break;
}
}
MmFreeMemory(ImageHeaders);
/*
* If we reached the end of the 8192 bytes without
* finding the multiboot header then return error
*/
if (Idx == 2048)
{
UiMessageBox("No multiboot header found!");
return FALSE;
}
/*printf("multiboot header:\n");
printf("0x%x\n", mb_header.magic);
printf("0x%x\n", mb_header.flags);
printf("0x%x\n", mb_header.checksum);
printf("0x%x\n", mb_header.header_addr);
printf("0x%x\n", mb_header.load_addr);
printf("0x%x\n", mb_header.load_end_addr);
printf("0x%x\n", mb_header.bss_end_addr);
printf("0x%x\n", mb_header.entry_addr);
getch();*/
/*
* Calculate the checksum and make sure it matches
*/
dwHeaderChecksum = mb_header.magic;
dwHeaderChecksum += mb_header.flags;
dwHeaderChecksum += mb_header.checksum;
if (dwHeaderChecksum != 0)
{
UiMessageBox("Multiboot header checksum invalid!");
return FALSE;
}
/*
* Get the file offset, this should be 0, and move the file pointer
*/
dwFileLoadOffset = (Idx * sizeof(DWORD)) - (mb_header.header_addr - mb_header.load_addr);
SetFilePointer(KernelImage, dwFileLoadOffset);
/*
* Load the file image
*/
dwDataSize = (mb_header.load_end_addr - mb_header.load_addr);
ReadFile(KernelImage, dwDataSize, NULL, (void*)mb_header.load_addr);
/*
* Initialize bss area
*/
dwBssSize = (mb_header.bss_end_addr - mb_header.load_end_addr);
memset((void*)mb_header.load_end_addr, 0, dwBssSize);
next_module_load_base = ROUND_UP(mb_header.bss_end_addr, /*PAGE_SIZE*/4096);
return TRUE;
}
#if 0
BOOL MultiBootLoadModule(FILE *ModuleImage, char *ModuleName)
{
DWORD dwModuleSize;
module_t* pModule;
char* ModuleNameString;
char * TempName;
/*
* Get current module data structure and module name string array
*/
pModule = &multiboot_modules[mb_info.mods_count];
do {
TempName = strchr( ModuleName, '\\' );
if( TempName )
ModuleName = TempName + 1;
} while( TempName );
ModuleNameString = multiboot_module_strings[mb_info.mods_count];
dwModuleSize = GetFileSize(ModuleImage);
pModule->mod_start = next_module_load_base;
pModule->mod_end = next_module_load_base + dwModuleSize;
strcpy(ModuleNameString, ModuleName);
pModule->string = (unsigned long)ModuleNameString;
/*
* Load the file image
*/
ReadFile(ModuleImage, dwModuleSize, NULL, (void*)next_module_load_base);
next_module_load_base = ROUND_UP(pModule->mod_end, /*PAGE_SIZE*/4096);
mb_info.mods_count++;
return TRUE;
}
#endif
PVOID MultiBootLoadModule(FILE *ModuleImage, char *ModuleName, PULONG ModuleSize)
{
DWORD dwModuleSize;
module_t* pModule;
char* ModuleNameString;
char * TempName;
/*
* Get current module data structure and module name string array
*/
pModule = &multiboot_modules[mb_info.mods_count];
do {
TempName = strchr( ModuleName, '\\' );
if( TempName )
ModuleName = TempName + 1;
} while( TempName );
ModuleNameString = multiboot_module_strings[mb_info.mods_count];
dwModuleSize = GetFileSize(ModuleImage);
pModule->mod_start = next_module_load_base;
pModule->mod_end = next_module_load_base + dwModuleSize;
strcpy(ModuleNameString, ModuleName);
pModule->string = (unsigned long)ModuleNameString;
/*
* Load the file image
*/
ReadFile(ModuleImage, dwModuleSize, NULL, (void*)next_module_load_base);
next_module_load_base = ROUND_UP(pModule->mod_end, /*PAGE_SIZE*/4096);
mb_info.mods_count++;
if (ModuleSize != NULL)
*ModuleSize = dwModuleSize;
return((PVOID)pModule->mod_start);
}
int GetBootPartition(char *OperatingSystemName)
{
int BootPartitionNumber = -1;
char value[1024];
ULONG SectionId;
if (IniOpenSection(OperatingSystemName, &SectionId))
{
if (IniReadSettingByName(SectionId, "BootPartition", value, 1024))
{
BootPartitionNumber = atoi(value);
}
}
return BootPartitionNumber;
}
PVOID MultiBootCreateModule(char *ModuleName)
{
module_t* pModule;
char* ModuleNameString;
/*
* Get current module data structure and module name string array
*/
pModule = &multiboot_modules[mb_info.mods_count];
ModuleNameString = multiboot_module_strings[mb_info.mods_count];
pModule->mod_start = next_module_load_base;
pModule->mod_end = -1;
strcpy(ModuleNameString, ModuleName);
pModule->string = (unsigned long)ModuleNameString;
pOpenModule = pModule;
return((PVOID)pModule->mod_start);
}
BOOL MultiBootCloseModule(PVOID ModuleBase, DWORD dwModuleSize)
{
module_t* pModule;
if ((pOpenModule != NULL) &&
((module_t*)ModuleBase == (module_t*)pOpenModule->mod_start) &&
(pOpenModule->mod_end == -1))
{
pModule = pOpenModule;
pModule->mod_end = pModule->mod_start + dwModuleSize;
next_module_load_base = ROUND_UP(pModule->mod_end, /*PAGE_SIZE*/4096);
mb_info.mods_count++;
pOpenModule = NULL;
return(TRUE);
}
return(FALSE);
}

View File

@@ -1,396 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <ui.h>
#include <options.h>
#include <miscboot.h>
#if 0
void DoOptionsMenu(void)
{
int OptionsMenuItemCount = 1; // Count is 1 because we don't show the "Set ReactOS Boot Flags" menu item yet
char OptionsMenuItems[2][80] = { "Boot Wizard", "Set ReactOS Boot Flags" /* i.e. Safe Mode, Last Known Good Configuration */ };
int OptionsMenuItemSelected = 0;
while (OptionsMenuItemSelected != -1)
{
OptionsMenuItemSelected = RunOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, OptionsMenuItemSelected, "[Advanced Options]");
switch (OptionsMenuItemSelected)
{
case 0:
DoDiskOptionsMenu();
break;
}
}
}
void DoDiskOptionsMenu(void)
{
char DiskMenuItems[25][80];
int DiskMenuItemCount = 0;
int FloppyDiskMenuItemCount = 0;
int HardDiskMenuItemCount = 0;
int DiskMenuItemSelected = 0;
char temp[255];
int i;
FloppyDiskMenuItemCount = (int)*((char *)((0x40 * 16) + 0x10)); // Get number of floppy disks from bios data area 40:10
if (FloppyDiskMenuItemCount & 1)
FloppyDiskMenuItemCount = (FloppyDiskMenuItemCount >> 6) + 1;
else
FloppyDiskMenuItemCount = 0;
HardDiskMenuItemCount = (int)*((char *)((0x40 * 16) + 0x75)); // Get number of hard disks from bios data area 40:75
DiskMenuItemCount = FloppyDiskMenuItemCount + HardDiskMenuItemCount;
for (i=0; i<FloppyDiskMenuItemCount; i++)
{
strcpy(DiskMenuItems[i], "Floppy Disk ");
itoa(i + 1, temp, 10);
strcat(DiskMenuItems[i], temp);
}
for (i=0; i<HardDiskMenuItemCount; i++)
{
strcpy(DiskMenuItems[i + FloppyDiskMenuItemCount], "Hard Disk ");
itoa(i + 1, temp, 10);
strcat(DiskMenuItems[i + FloppyDiskMenuItemCount], temp);
strcat(DiskMenuItems[i + FloppyDiskMenuItemCount], " (");
itoa((get_heads(i+0x80) * get_cylinders(i+0x80) * get_sectors(i+0x80)) / 2048, temp, 10);
strcat(DiskMenuItems[i + FloppyDiskMenuItemCount], temp);
strcat(DiskMenuItems[i + FloppyDiskMenuItemCount], " MB)");
}
DiskMenuItemSelected = 0;
while (DiskMenuItemSelected != -1)
{
DiskMenuItemSelected = RunOptionsMenu(DiskMenuItems, DiskMenuItemCount, DiskMenuItemSelected, "[Boot Wizard]");
if (DiskMenuItemSelected != -1)
{
if (DiskMenuItemSelected < FloppyDiskMenuItemCount)
DoBootOptionsMenu(DiskMenuItemSelected, DiskMenuItems[DiskMenuItemSelected]);
else
DoBootOptionsMenu((DiskMenuItemSelected - FloppyDiskMenuItemCount) + 0x80, DiskMenuItems[DiskMenuItemSelected]);
}
}
}
void DoBootOptionsMenu(int BootDriveNum, char *BootDriveText)
{
int BootOptionsMenuItemCount = 2;
char BootOptionsMenuItems[2][80] = { "Boot To ", "Pick A Boot Partition" };
int BootOptionsMenuItemSelected = 0;
/*strcat(BootOptionsMenuItems[0], BootDriveText);
while (BootOptionsMenuItemSelected != -1)
{
BootOptionsMenuItemSelected = RunOptionsMenu(BootOptionsMenuItems, BootOptionsMenuItemCount, BootOptionsMenuItemSelected, "[Boot Options]");
switch (BootOptionsMenuItemSelected)
{
case 0:
BootDrive = BootDriveNum;
if (!biosdisk(_DISK_READ, BootDrive, 0, 0, 1, 1, (void*)0x7c00))
{
MessageBox("Disk Read Error");
return;
}
// Check for validity
if (*((WORD*)(0x7c00 + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid boot sector magic (0xaa55)");
return;
}
RestoreScreen(ScreenBuffer);
VideoShowTextCursor();
gotoxy(CursorXPos, CursorYPos);
StopFloppyMotor();
JumpToBootCode();
break;
case 1:
if (BootDriveNum < 0x80)
{
MessageBox("This option is not available for a floppy disk.");
continue;
}
else
DoBootPartitionOptionsMenu(BootDriveNum);
break;
}
}*/
}
void DoBootPartitionOptionsMenu(int BootDriveNum)
{
struct
{
int partition_num;
int partition_type;
int head, sector, cylinder;
} BootPartitions[8];
int BootOptionsMenuItemCount = 0;
char BootOptionsMenuItems[8][80];
int BootOptionsMenuItemSelected = 0;
int head, sector, cylinder;
int offset;
int i;
char temp[25];
/*BootDrive = BootDriveNum;
if (!biosdisk(_DISK_READ, BootDrive, 0, 0, 1, 1, SectorBuffer))
{
MessageBox("Disk Read Error");
return;
}
// Check for validity
if (*((WORD*)(SectorBuffer + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid partition table magic (0xaa55)");
return;
}
offset = 0x1BE;
for (i=0; i<4; i++)
{
// Check for valid partition
if (SectorBuffer[offset + 4] != 0)
{
BootPartitions[BootOptionsMenuItemCount].partition_num = i;
BootPartitions[BootOptionsMenuItemCount].partition_type = SectorBuffer[offset + 4];
BootPartitions[BootOptionsMenuItemCount].head = SectorBuffer[offset + 1];
BootPartitions[BootOptionsMenuItemCount].sector = (SectorBuffer[offset + 2] & 0x3F);
BootPartitions[BootOptionsMenuItemCount].cylinder = SectorBuffer[offset + 3];
if (SectorBuffer[offset + 2] & 0x80)
BootPartitions[BootOptionsMenuItemCount].cylinder += 0x200;
if (SectorBuffer[offset + 2] & 0x40)
BootPartitions[BootOptionsMenuItemCount].cylinder += 0x100;
strcpy(BootOptionsMenuItems[BootOptionsMenuItemCount], "Boot To Partition ");
itoa(i+1, temp, 10);
strcat(BootOptionsMenuItems[BootOptionsMenuItemCount], temp);
strcat(BootOptionsMenuItems[BootOptionsMenuItemCount], " (Type: 0x");
itoa(BootPartitions[BootOptionsMenuItemCount].partition_type, temp, 16);
if (strlen(temp) < 2)
strcat(BootOptionsMenuItems[BootOptionsMenuItemCount], "0");
strcat(BootOptionsMenuItems[BootOptionsMenuItemCount], temp);
strcat(BootOptionsMenuItems[BootOptionsMenuItemCount], ")");
BootOptionsMenuItemCount++;
}
offset += 0x10;
}
while (BootOptionsMenuItemSelected != -1)
{
BootOptionsMenuItemSelected = RunOptionsMenu(BootOptionsMenuItems, BootOptionsMenuItemCount, BootOptionsMenuItemSelected, "[Boot Partition Options]");
if (BootOptionsMenuItemSelected != -1)
{
head = BootPartitions[BootOptionsMenuItemCount].head;
sector = BootPartitions[BootOptionsMenuItemCount].sector;
cylinder = BootPartitions[BootOptionsMenuItemCount].cylinder;
// Read partition boot sector
if (!biosdisk(_DISK_READ, BootDrive, head, cylinder, sector, 1, (void*)0x7c00))
{
MessageBox("Disk Read Error");
return;
}
// Check for validity
if (*((WORD*)(0x7c00 + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid boot sector magic (0xaa55)");
return;
}
RestoreScreen(ScreenBuffer);
VideoShowTextCursor();
gotoxy(CursorXPos, CursorYPos);
StopFloppyMotor();
JumpToBootCode();
}
}*/
}
int RunOptionsMenu(char OptionsMenuItems[][80], int OptionsMenuItemCount, int nOptionSelected, char *OptionsMenuTitle)
{
int key;
int second;
BOOL bDone = FALSE;
int nOptionsMenuBoxLeft;
int nOptionsMenuBoxRight;
int nOptionsMenuBoxTop;
int nOptionsMenuBoxBottom;
// Initialise the menu
InitOptionsMenu(&nOptionsMenuBoxLeft, &nOptionsMenuBoxTop, &nOptionsMenuBoxRight, &nOptionsMenuBoxBottom, OptionsMenuItemCount);
DrawBackdrop();
// Update the menu
DrawOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, nOptionSelected, OptionsMenuTitle, nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom);
second = getsecond();
// Loop
do
{
// Check for a keypress
if (kbhit())
{
// Cancel the timeout
if (nTimeOut != -1)
{
nTimeOut = -1;
DrawOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, nOptionSelected, OptionsMenuTitle, nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom);
}
// Get the key
key = getch();
// Is it extended?
if (key == 0)
key = getch(); // Yes - so get the extended key
// Process the key
switch (key)
{
case KEY_UP:
if (nOptionSelected)
{
nOptionSelected--;
// Update the menu
DrawOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, nOptionSelected, OptionsMenuTitle, nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom);
}
break;
case KEY_DOWN:
if (nOptionSelected < (OptionsMenuItemCount - 1))
{
nOptionSelected++;
// Update the menu
DrawOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, nOptionSelected, OptionsMenuTitle, nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom);
}
break;
case KEY_ENTER:
//MessageBox("The Advanced Options are still being implemented.");
bDone = TRUE;
break;
case KEY_ESC:
nOptionSelected = -1;
bDone = TRUE;
break;
}
}
// Update the date & time
UpdateDateTime();
if (nTimeOut > 0)
{
if (getsecond() != second)
{
second = getsecond();
nTimeOut--;
// Update the menu
DrawOptionsMenu(OptionsMenuItems, OptionsMenuItemCount, nOptionSelected, OptionsMenuTitle, nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom);
}
}
if (nTimeOut == 0)
bDone = TRUE;
}
while (!bDone);
return nOptionSelected;
}
void InitOptionsMenu(int *nOptionsMenuBoxLeft, int *nOptionsMenuBoxTop, int *nOptionsMenuBoxRight, int *nOptionsMenuBoxBottom, int OptionsMenuItemCount)
{
/*int height = OptionsMenuItemCount;
int width = 20;
height += 1; // Allow room for top & bottom borders
width += 18; // Allow room for left & right borders, plus 8 spaces on each side
// Calculate the OS list box area
*nOptionsMenuBoxLeft = (nScreenWidth - width) / 2;
*nOptionsMenuBoxRight = *nOptionsMenuBoxLeft + width;
*nOptionsMenuBoxTop = (nScreenHeight - height) / 2 + 1;
*nOptionsMenuBoxBottom = *nOptionsMenuBoxTop + height;*/
}
void DrawOptionsMenu(char OptionsMenuItems[][80], int OptionsMenuItemCount, int nOptionSelected, char *OptionsMenuTitle, int nOptionsMenuBoxLeft, int nOptionsMenuBoxTop, int nOptionsMenuBoxRight, int nOptionsMenuBoxBottom)
{
int i, j;
char text[260];
int space, space_left, space_right;
// Update the status bar
/*DrawStatusText("Use \x18\x19 to select, then press ENTER. Press ESC to go back.");
DrawBox(nOptionsMenuBoxLeft, nOptionsMenuBoxTop, nOptionsMenuBoxRight, nOptionsMenuBoxBottom, D_VERT, D_HORZ, TRUE, TRUE, ATTR(cMenuFgColor, cMenuBgColor));
DrawText(nOptionsMenuBoxLeft + (((nOptionsMenuBoxRight - nOptionsMenuBoxLeft) - strlen(OptionsMenuTitle)) / 2) + 1, nOptionsMenuBoxTop, OptionsMenuTitle, ATTR(cMenuFgColor, cMenuBgColor));
for(i=0; i<OptionsMenuItemCount; i++)
{
space = (nOptionsMenuBoxRight - nOptionsMenuBoxLeft - 2) - strlen(OptionsMenuItems[i]);
space_left = (space / 2) + 1;
space_right = (space - space_left) + 1;
text[0] = '\0';
for(j=0; j<space_left; j++)
strcat(text, " ");
strcat(text, OptionsMenuItems[i]);
for(j=0; j<space_right; j++)
strcat(text, " ");
if(i == nOptionSelected)
{
DrawText(nOptionsMenuBoxLeft+1, nOptionsMenuBoxTop+1+i, text, ATTR(cSelectedTextColor, cSelectedTextBgColor));
}
else
{
DrawText(nOptionsMenuBoxLeft+1, nOptionsMenuBoxTop+1+i, text, ATTR(cTextColor, cMenuBgColor));
}
}*/
}
#endif

View File

@@ -1,254 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <inifile.h>
#include <oslist.h>
#include <rtl.h>
#include <mm.h>
#include <ui.h>
BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNamesPointer, PULONG OperatingSystemCountPointer)
{
ULONG Idx;
ULONG CurrentOperatingSystemIndex;
UCHAR SettingName[260];
UCHAR SettingValue[260];
ULONG OperatingSystemCount;
ULONG SectionId;
ULONG OperatingSystemSectionId;
ULONG SectionSettingCount;
PUCHAR *OperatingSystemSectionNames;
PUCHAR *OperatingSystemDisplayNames;
//
// Open the [FreeLoader] section
//
if (!IniOpenSection("FreeLoader", &SectionId))
{
UiMessageBox("Section [FreeLoader] not found in freeldr.ini.");
return FALSE;
}
SectionSettingCount = IniGetNumSectionItems(SectionId);
OperatingSystemCount = CountOperatingSystems(SectionId);
//
// Allocate memory to hold operating system lists
//
if (!AllocateListMemory(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, OperatingSystemCount))
{
return FALSE;
}
//
// Now loop through and read the operating system section names
//
CurrentOperatingSystemIndex = 0;
for (Idx=0; Idx<SectionSettingCount; Idx++)
{
IniReadSettingByNumber(SectionId, Idx, SettingName, 260, SettingValue, 260);
if (stricmp(SettingName, "OS") == 0 && IniOpenSection(SettingValue, &OperatingSystemSectionId))
{
strcpy(OperatingSystemSectionNames[CurrentOperatingSystemIndex], SettingValue);
CurrentOperatingSystemIndex++;
}
}
//
// Now loop through and read the operating system display names
//
for (Idx=0; Idx<OperatingSystemCount; Idx++)
{
if (IniOpenSection(OperatingSystemSectionNames[Idx], &OperatingSystemSectionId))
{
if (IniReadSettingByName(OperatingSystemSectionId, "Name", SettingValue, 260))
{
//
// Remove any quotes around the string
//
RemoveQuotes(SettingValue);
strcpy(OperatingSystemDisplayNames[Idx], SettingValue);
}
else
{
sprintf(SettingName, "Operating System '%s' has no\nName= line in it's [section].", OperatingSystemSectionNames[Idx]);
UiMessageBox(SettingName);
strcpy(OperatingSystemDisplayNames[Idx], "");
}
}
}
*OperatingSystemCountPointer = OperatingSystemCount;
*SectionNamesPointer = OperatingSystemSectionNames;
*DisplayNamesPointer = OperatingSystemDisplayNames;
return TRUE;
}
ULONG CountOperatingSystems(ULONG SectionId)
{
ULONG Idx;
UCHAR SettingName[260];
UCHAR SettingValue[260];
ULONG OperatingSystemCount = 0;
ULONG SectionSettingCount;
//
// Loop through and count the operating systems
//
SectionSettingCount = IniGetNumSectionItems(SectionId);
for (Idx=0; Idx<SectionSettingCount; Idx++)
{
IniReadSettingByNumber(SectionId, Idx, SettingName, 260, SettingValue, 260);
if (stricmp(SettingName, "OS") == 0)
{
if (IniOpenSection(SettingValue, NULL))
{
OperatingSystemCount++;
}
else
{
sprintf(SettingName, "Operating System '%s' is listed in\nfreeldr.ini but doesn't have a [section].", SettingValue);
UiMessageBox(SettingName);
}
}
}
return OperatingSystemCount;
}
BOOL AllocateListMemory(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNamesPointer, ULONG OperatingSystemCount)
{
ULONG Idx;
PUCHAR *OperatingSystemSectionNames = NULL;
PUCHAR *OperatingSystemDisplayNames = NULL;
//
// Allocate memory to hold operating system list arrays
//
OperatingSystemSectionNames = (PUCHAR*) MmAllocateMemory( sizeof(PUCHAR) * OperatingSystemCount);
OperatingSystemDisplayNames = (PUCHAR*) MmAllocateMemory( sizeof(PUCHAR) * OperatingSystemCount);
//
// If either allocation failed then return FALSE
//
if ( (OperatingSystemSectionNames == NULL) || (OperatingSystemDisplayNames == NULL) )
{
if (OperatingSystemSectionNames != NULL)
{
MmFreeMemory(OperatingSystemSectionNames);
}
if (OperatingSystemDisplayNames != NULL)
{
MmFreeMemory(OperatingSystemDisplayNames);
}
return FALSE;
}
//
// Clear our newly allocated memory
//
memset(OperatingSystemSectionNames, 0, sizeof(PUCHAR) * OperatingSystemCount);
memset(OperatingSystemDisplayNames, 0, sizeof(PUCHAR) * OperatingSystemCount);
//
// Loop through each array element and allocate it's string memory
//
for (Idx=0; Idx<OperatingSystemCount; Idx++)
{
OperatingSystemSectionNames[Idx] = (PUCHAR) MmAllocateMemory(80);
OperatingSystemDisplayNames[Idx] = (PUCHAR) MmAllocateMemory(80);
//
// If it failed then jump to the cleanup code
//
if ( (OperatingSystemSectionNames[Idx] == NULL) || (OperatingSystemDisplayNames[Idx] == NULL))
{
goto AllocateListMemoryFailed;
}
}
*SectionNamesPointer = OperatingSystemSectionNames;
*DisplayNamesPointer = OperatingSystemDisplayNames;
return TRUE;
AllocateListMemoryFailed:
//
// Loop through each array element and free it's string memory
//
for (Idx=0; Idx<OperatingSystemCount; Idx++)
{
if (OperatingSystemSectionNames[Idx] != NULL)
{
MmFreeMemory(OperatingSystemSectionNames[Idx]);
}
if (OperatingSystemDisplayNames[Idx] != NULL)
{
MmFreeMemory(OperatingSystemDisplayNames[Idx]);
}
}
//
// Free operating system list arrays
//
MmFreeMemory(OperatingSystemSectionNames);
MmFreeMemory(OperatingSystemDisplayNames);
return FALSE;
}
BOOL RemoveQuotes(PUCHAR QuotedString)
{
UCHAR TempString[200];
//
// If this string is not quoted then return FALSE
//
if ((QuotedString[0] != '\"') && (QuotedString[strlen(QuotedString)-1] != '\"'))
{
return FALSE;
}
if (QuotedString[0] == '\"')
{
strcpy(TempString, (QuotedString + 1));
}
else
{
strcpy(TempString, QuotedString);
}
if (TempString[strlen(TempString)-1] == '\"')
{
TempString[strlen(TempString)-1] = '\0';
}
strcpy(QuotedString, TempString);
return TRUE;
}

View File

@@ -1,74 +0,0 @@
/*
* FreeLoader - arcname.c
*
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
* Copyright (C) 2001 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
BOOL DissectArcPath(char *ArcPath, char *BootPath, PULONG BootDrive, PULONG BootPartition)
{
char *p;
if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
return FALSE;
p = ArcPath + 15;
if (_strnicmp(p, "fdisk(", 6) == 0)
{
/*
* floppy disk path:
* multi(0)disk(0)fdisk(x)\path
*/
p = p + 6;
*BootDrive = atoi(p);
p = strchr(p, ')');
if (p == NULL)
return FALSE;
p++;
*BootPartition = 0;
}
else if (_strnicmp(p, "rdisk(", 6) == 0)
{
/*
* hard disk path:
* multi(0)disk(0)rdisk(x)partition(y)\path
*/
p = p + 6;
*BootDrive = atoi(p) + 0x80;
p = strchr(p, ')');
if ((p == NULL) || (_strnicmp(p, ")partition(", 11) != 0))
return FALSE;
p = p + 11;
*BootPartition = atoi(p);
p = strchr(p, ')');
if ((p == NULL) || (*BootPartition == 0))
return FALSE;
p++;
}
else
{
return FALSE;
}
strcpy(BootPath, p);
return TRUE;
}

View File

@@ -1,28 +0,0 @@
/*
* FreeLoader
*
* Copyright (C) 2001 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <debug.h>
VOID
DetectHardware(VOID)
{
}

View File

@@ -1,26 +0,0 @@
/*
* FreeLoader
*
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __HWDETECT_H
#define __HWDETECT_H
VOID DetectHardware(VOID);
#endif /* __HWDETECT_H */

View File

@@ -1,640 +0,0 @@
/*
* FreeLoader
*
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <debug.h>
#include <arch.h>
#include <reactos.h>
#include <rtl.h>
#include <fs.h>
#include <ui.h>
#include <multiboot.h>
#include <mm.h>
#include <inifile.h>
#include "registry.h"
#include "hwdetect.h"
#define NDEBUG
static BOOL
LoadKernel(PCHAR szFileName, int nPos)
{
PFILE FilePointer;
PCHAR szShortName;
char szBuffer[256];
szShortName = strrchr(szFileName, '\\');
if (szShortName == NULL)
szShortName = szFileName;
else
szShortName = szShortName + 1;
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL)
{
strcpy(szBuffer, szShortName);
strcat(szBuffer, " not found.");
UiMessageBox(szBuffer);
return(FALSE);
}
/*
* Update the status bar with the current file
*/
strcpy(szBuffer, "Reading ");
strcat(szBuffer, szShortName);
UiDrawStatusText(szBuffer);
/*
* Load the kernel
*/
MultiBootLoadKernel(FilePointer);
UiDrawProgressBarCenter(nPos, 100);
return(TRUE);
}
static BOOL
LoadDriver(PCHAR szFileName, int nPos)
{
PFILE FilePointer;
char value[256];
char *p;
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL)
{
strcpy(value, szFileName);
strcat(value, " not found.");
UiMessageBox(value);
return(FALSE);
}
/*
* Update the status bar with the current file
*/
strcpy(value, "Reading ");
p = strrchr(szFileName, '\\');
if (p == NULL)
strcat(value, szFileName);
else
strcat(value, p + 1);
UiDrawStatusText(value);
/*
* Load the driver
*/
MultiBootLoadModule(FilePointer, szFileName, NULL);
UiDrawProgressBarCenter(nPos, 100);
return(TRUE);
}
#if 0
static BOOL
LoadNlsFile(PCHAR szFileName, PCHAR szModuleName)
{
PFILE FilePointer;
char value[256];
char *p;
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL)
{
strcpy(value, szFileName);
strcat(value, " not found.");
UiMessageBox(value);
return(FALSE);
}
/*
* Update the status bar with the current file
*/
strcpy(value, "Reading ");
p = strrchr(szFileName, '\\');
if (p == NULL)
strcat(value, szFileName);
else
strcat(value, p + 1);
UiDrawStatusText(value);
/*
* Load the driver
*/
MultiBootLoadModule(FilePointer, szModuleName, NULL);
return(TRUE);
}
#endif
static VOID
LoadBootDrivers(PCHAR szSystemRoot, int nPos)
{
LONG rc = 0;
HKEY hGroupKey, hServiceKey, hDriverKey;
char ValueBuffer[512];
char ServiceName[256];
ULONG BufferSize;
ULONG Index;
char *GroupName;
ULONG ValueSize;
ULONG ValueType;
ULONG StartValue;
UCHAR DriverGroup[256];
ULONG DriverGroupSize;
UCHAR ImagePath[256];
/* get 'service group order' key */
rc = RegOpenKey(NULL,
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
&hGroupKey);
DbgPrint((DPRINT_REACTOS, "RegOpenKey(): rc %d\n", (int)rc));
if (rc != ERROR_SUCCESS)
return;
/* enumerate drivers */
rc = RegOpenKey(NULL,
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
&hServiceKey);
DbgPrint((DPRINT_REACTOS, "RegOpenKey(): rc %d\n", (int)rc));
if (rc != ERROR_SUCCESS)
return;
DbgPrint((DPRINT_REACTOS, "hServiceKey: %x\n", (int)hServiceKey));
BufferSize = sizeof(ValueBuffer);
rc = RegQueryValue(hGroupKey, "List", NULL, (PUCHAR)&ValueBuffer, &BufferSize);
DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
if (rc != ERROR_SUCCESS)
return;
DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
DbgPrint((DPRINT_REACTOS, "ValueBuffer: '%s' \n", ValueBuffer));
GroupName = ValueBuffer;
while (*GroupName)
{
DbgPrint((DPRINT_REACTOS, "Driver group: '%s'\n", GroupName));
/* enumerate all drivers */
Index = 0;
while (TRUE)
{
ValueSize = sizeof(ValueBuffer);
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
if (rc == ERROR_NO_MORE_ITEMS)
break;
if (rc != ERROR_SUCCESS)
return;
DbgPrint((DPRINT_REACTOS, "Service %d: '%s'\n", (int)Index, ServiceName));
/* open driver Key */
rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, "Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
DriverGroupSize = 256;
rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
DbgPrint((DPRINT_REACTOS, " Group: '%s' \n", DriverGroup));
if ((StartValue == 0) && (stricmp(DriverGroup, GroupName) == 0))
{
ValueSize = 256;
rc = RegQueryValue(hDriverKey,
"ImagePathName",
NULL,
(PUCHAR)ImagePath,
&ValueSize);
if (rc != ERROR_SUCCESS)
{
DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
strcpy(ImagePath, szSystemRoot);
strcat(ImagePath, "system32\\drivers\\");
strcat(ImagePath, ServiceName);
strcat(ImagePath, ".sys");
}
else
{
DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
}
DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
if (nPos < 100)
nPos += 5;
LoadDriver(ImagePath, nPos);
}
else
{
DbgPrint((DPRINT_REACTOS, " Skipping driver '%s' with Start %d and Group '%s' (Current group '%s')\n",
ImagePath, StartValue, DriverGroup, GroupName));
}
Index++;
}
GroupName = GroupName + strlen(GroupName) + 1;
}
}
#if 0
static BOOL
LoadNlsFiles(PCHAR szSystemRoot)
{
LONG rc = ERROR_SUCCESS;
HKEY hKey;
char szIdBuffer[80];
char szNameBuffer[80];
char szFileName[256];
ULONG BufferSize;
/* open the codepage key */
rc = RegOpenKey(NULL,
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
&hKey);
if (rc != ERROR_SUCCESS)
return(FALSE);
/* get ANSI codepage */
BufferSize = 80;
rc = RegQueryValue(hKey, "ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
BufferSize = 80;
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
/* load ANSI codepage table */
strcpy(szFileName, szSystemRoot);
strcat(szFileName, "system32\\");
strcat(szFileName, szNameBuffer);
if (!LoadNlsFile(szFileName, "ANSI.NLS"))
return(FALSE);
/* get OEM codepage */
BufferSize = 80;
rc = RegQueryValue(hKey, "OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
BufferSize = 80;
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
/* load OEM codepage table */
strcpy(szFileName, szSystemRoot);
strcat(szFileName, "system32\\");
strcat(szFileName, szNameBuffer);
if (!LoadNlsFile(szFileName, "OEM.NLS"))
return(FALSE);
/* open the language key */
rc = RegOpenKey(NULL,
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
&hKey);
if (rc != ERROR_SUCCESS)
return(FALSE);
/* get the Unicode case table */
BufferSize = 80;
rc = RegQueryValue(hKey, "Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
BufferSize = 80;
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
if (rc != ERROR_SUCCESS)
return(FALSE);
/* load Unicode case table */
strcpy(szFileName, szSystemRoot);
strcat(szFileName, "system32\\");
strcat(szFileName, szNameBuffer);
if (!LoadNlsFile(szFileName, "UNICASE.NLS"))
return(FALSE);
return(TRUE);
}
#endif
void
LoadAndBootReactOS(PUCHAR OperatingSystemName)
{
PFILE FilePointer;
char name[1024];
char value[1024];
char szFileName[1024];
char szBootPath[256];
// int i;
// int nNumDriverFiles=0;
// int nNumFilesLoaded=0;
char MsgBuffer[256];
ULONG SectionId;
char* Base;
ULONG Size;
//
// Open the operating system section
// specified in the .ini file
//
if (!IniOpenSection(OperatingSystemName, &SectionId))
{
sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
UiMessageBox(MsgBuffer);
return;
}
/*
* Setup multiboot information structure
*/
mb_info.flags = MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_BOOT_DEVICE | MB_INFO_FLAG_COMMAND_LINE | MB_INFO_FLAG_MODULES;
mb_info.mem_lower = GetConventionalMemorySize();
mb_info.mem_upper = GetExtendedMemorySize();
mb_info.boot_device = 0xffffffff;
mb_info.cmdline = (unsigned long)multiboot_kernel_cmdline;
mb_info.mods_count = 0;
mb_info.mods_addr = (unsigned long)multiboot_modules;
mb_info.mmap_length = (unsigned long)GetBiosMemoryMap((PBIOS_MEMORY_MAP)&multiboot_memory_map);
if (mb_info.mmap_length)
{
mb_info.mmap_addr = (unsigned long)&multiboot_memory_map;
mb_info.flags |= MB_INFO_FLAG_MEMORY_MAP;
//printf("memory map length: %d\n", mb_info.mmap_length);
//printf("dumping memory map:\n");
//for (i=0; i<(mb_info.mmap_length / 4); i++)
//{
// printf("0x%x\n", ((unsigned long *)&multiboot_memory_map)[i]);
//}
//getch();
}
//printf("low_mem = %d\n", mb_info.mem_lower);
//printf("high_mem = %d\n", mb_info.mem_upper);
//getch();
/*
* Make sure the system path is set in the .ini file
*/
if (!IniReadSettingByName(SectionId, "SystemPath", value, 1024))
{
UiMessageBox("System path not specified for selected operating system.");
return;
}
/*
* Verify system path
*/
if (!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition))
{
sprintf(MsgBuffer,"Invalid system path: '%s'", value);
UiMessageBox(MsgBuffer);
return;
}
/* set boot drive and partition */
((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
/* copy ARC path into kernel command line */
strcpy(multiboot_kernel_cmdline, value);
/*
* Read the optional kernel parameters (if any)
*/
if (IniReadSettingByName(SectionId, "Options", value, 1024))
{
strcat(multiboot_kernel_cmdline, " ");
strcat(multiboot_kernel_cmdline, value);
}
/* append a backslash */
if ((strlen(szBootPath)==0) ||
szBootPath[strlen(szBootPath)] != '\\')
strcat(szBootPath, "\\");
DebugPrint(DPRINT_REACTOS,"SystemRoot: '%s'", szBootPath);
UiDrawBackdrop();
UiDrawStatusText("Loading...");
UiDrawProgressBarCenter(0, 100);
/*
* Try to open boot drive
*/
if (!OpenDiskDrive(BootDrive, BootPartition))
{
UiMessageBox("Failed to open boot drive.");
return;
}
/*
* Find the kernel image name
* and try to load the kernel off the disk
*/
if(IniReadSettingByName(SectionId, "Kernel", value, 1024))
{
/*
* Set the name and
*/
if (value[0] == '\\')
{
strcpy(szFileName, value);
}
else
{
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\");
strcat(szFileName, value);
}
}
else
{
strcpy(value, "NTOSKRNL.EXE");
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\");
strcat(szFileName, value);
}
if (!LoadKernel(szFileName, 5))
return;
/*
* Find the HAL image name
* and try to load the kernel off the disk
*/
if(IniReadSettingByName(SectionId, "Hal", value, 1024))
{
/*
* Set the name and
*/
if (value[0] == '\\')
{
strcpy(szFileName, value);
}
else
{
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\");
strcat(szFileName, value);
}
}
else
{
strcpy(value, "HAL.DLL");
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\");
strcat(szFileName, value);
}
if (!LoadDriver(szFileName, 10))
return;
/*
* Find the System hive image name
* and try to load it off the disk
*/
if(IniReadSettingByName(SectionId, "SystemHive", value, 1024))
{
/*
* Set the name and
*/
if (value[0] == '\\')
{
strcpy(szFileName, value);
}
else
{
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\CONFIG\\");
strcat(szFileName, value);
}
}
else
{
strcpy(value, "SYSTEM.HIV");
strcpy(szFileName, szBootPath);
strcat(szFileName, "SYSTEM32\\CONFIG\\");
strcat(szFileName, value);
}
DebugPrint(DPRINT_REACTOS, "SystemHive: '%s'", szFileName);
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL)
{
strcat(value, " not found.");
UiMessageBox(value);
return;
}
/*
* Update the status bar with the current file
*/
strcpy(name, "Reading ");
strcat(name, value);
while (strlen(name) < 80)
strcat(name, " ");
UiDrawStatusText(name);
/*
* Load the system hive
*/
Base = MultiBootLoadModule(FilePointer, szFileName, &Size);
RegInitializeRegistry();
RegImportHive(Base, Size);
UiDrawProgressBarCenter(15, 100);
DebugPrint(DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size);
/*
* Retrieve hardware information and create the hardware hive
*/
DetectHardware();
#if 0
Base = MultiBootCreateModule(HARDWARE.HIV);
RegExportHive("\\Registry\\Machine\\HARDWARE", Base, &Size);
MultiBootCloseModule(Base, Size);
#endif
UiDrawProgressBarCenter(20, 100);
/*
* Load NLS files
*/
#if 0
if (!LoadNlsFiles(szBootPath))
{
MessageBox("Failed to load NLS files\n");
return;
}
#endif
UiDrawProgressBarCenter(25, 100);
/*
* Load boot drivers
*/
LoadBootDrivers(szBootPath, 25);
/*
* Clear the screen and redraw the backdrop and status bar
*/
UiDrawBackdrop();
UiDrawStatusText("Press any key to boot");
/*
* Wait for user
*/
strcpy(name, "Kernel and Drivers loaded.\nPress any key to boot ");
strcat(name, OperatingSystemName);
strcat(name, ".");
//MessageBox(name);
/*
* Now boot the kernel
*/
StopFloppyMotor();
boot_reactos();
}

View File

@@ -1,589 +0,0 @@
/*
* FreeLoader
*
* Copyright (C) 2001 Rex Jolliff
* Copyright (C) 2001 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <mm.h>
#include <debug.h>
#include "registry.h"
#define REGISTRY_FILE_MAGIC "REGEDIT4"
static PCHAR
checkAndSkipMagic (PCHAR regChunk)
{
if (strncmp (regChunk,
REGISTRY_FILE_MAGIC,
strlen (REGISTRY_FILE_MAGIC)) != 0)
{
DbgPrint((DPRINT_REGISTRY, "Incorrect magic number in registry chunk. Expected: '%s' Got: '%.*s'\n",
REGISTRY_FILE_MAGIC, strlen(REGISTRY_FILE_MAGIC), regChunk));
return 0;
}
regChunk += strlen (REGISTRY_FILE_MAGIC);
DbgPrint((DPRINT_REGISTRY, "Found registry chunk magic value\n"));
return regChunk;
}
static PCHAR
skipWhitespaceInChunk (PCHAR regChunk)
{
while (*regChunk && isspace (*regChunk))
regChunk++;
return *regChunk ? regChunk : 0;
}
static int
computeKeyNameSize (PCHAR regChunk)
{
int copyCount = 0;
while (*regChunk != 0 && *regChunk != ']')
{
copyCount++;
regChunk++;
}
return copyCount;
}
static BOOL
allocateKeyName(PCHAR *newKeyName, int newKeySize)
{
if (*newKeyName != NULL)
MmFreeMemory(*newKeyName);
*newKeyName = MmAllocateMemory(newKeySize + 1);
if (*newKeyName == NULL)
return(FALSE);
memset(*newKeyName, 0, newKeySize + 1);
return(TRUE);
}
static PCHAR
skipToNextKeyInChunk (PCHAR regChunk)
{
while (*regChunk != 0 && *regChunk != '[')
{
while (*regChunk != 0 && *regChunk != '\n')
{
regChunk++;
}
regChunk++;
}
return *regChunk ? regChunk : 0;
}
static PCHAR
getKeyNameFromChunk (PCHAR regChunk, PCHAR newKeyName)
{
int index = 0;
while (*regChunk != 0 && *regChunk != ']')
{
newKeyName[index++] = *regChunk++;
}
newKeyName[index] = '\0';
return *regChunk ? regChunk : 0;
}
static HKEY
createNewKey (PCHAR newKeyName)
{
HKEY handleToReturn = NULL;
DbgPrint((DPRINT_REGISTRY, "Adding new key '%s'\n", newKeyName));
RegCreateKey(NULL,
newKeyName,
&handleToReturn);
DbgPrint((DPRINT_REGISTRY, "Returned handle: 0x%x\n", handleToReturn));
return handleToReturn;
}
static PCHAR
skipToNextKeyValueInChunk (PCHAR regChunk)
{
while (*regChunk != 0 && *regChunk != '\n')
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
return regChunk;
}
static int
computeKeyValueNameSize (PCHAR regChunk)
{
int size = 0;
if (*regChunk != '\"')
return 0;
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
size++;
regChunk++;
}
return regChunk ? size : 0;
}
static PCHAR
getKeyValueNameFromChunk (PCHAR regChunk, PCHAR newKeyName)
{
int index = 0;
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
newKeyName[index++] = *regChunk++;
}
newKeyName[index] = '\0';
regChunk++;
return *regChunk ? regChunk : 0;
}
static PCHAR
getKeyValueTypeFromChunk (PCHAR regChunk, PCHAR dataFormat, int *keyValueType)
{
if (*regChunk == '\"')
{
strcpy (dataFormat, "string");
*keyValueType = REG_SZ;
}
else if (strncmp (regChunk, "hex", 3) == 0)
{
strcpy (dataFormat, "hex");
regChunk += 3;
if (*regChunk == '(')
{
regChunk++;
*keyValueType = atoi (regChunk);
while (*regChunk != 0 && *regChunk != ')')
regChunk++;
regChunk++;
}
else
*keyValueType = REG_BINARY;
if (*regChunk == ':')
regChunk++;
}
else if (strncmp (regChunk, "dword", 5) == 0)
{
strcpy (dataFormat, "dword");
*keyValueType = REG_DWORD;
regChunk += 5;
if (*regChunk == ':')
regChunk++;
}
else if (strncmp (regChunk, "multi", 5) == 0)
{
strcpy (dataFormat, "multi");
*keyValueType = REG_MULTI_SZ;
regChunk += 5;
if (*regChunk == ':')
regChunk++;
}
else if (strncmp (regChunk, "expand", 6) == 0)
{
strcpy (dataFormat, "expand");
*keyValueType = REG_EXPAND_SZ;
regChunk += 6;
if (*regChunk == ':')
regChunk++;
}
else
{
UNIMPLEMENTED;
}
return *regChunk ? regChunk : 0;
}
static int
computeKeyValueDataSize (PCHAR regChunk, PCHAR dataFormat)
{
int dataSize = 0;
if (strcmp (dataFormat, "string") == 0)
{
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
dataSize++;
regChunk++;
}
dataSize++;
}
else if (strcmp (dataFormat, "hex") == 0)
{
while (*regChunk != 0 && isxdigit(*regChunk))
{
regChunk++;
regChunk++;
dataSize++;
if (*regChunk == ',')
{
regChunk++;
if (*regChunk == '\\')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
}
}
}
}
else if (strcmp (dataFormat, "dword") == 0)
{
dataSize = sizeof(DWORD);
while (*regChunk != 0 && isxdigit(*regChunk))
{
regChunk++;
}
}
else if (strcmp (dataFormat, "multi") == 0)
{
while (*regChunk == '\"')
{
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
dataSize++;
regChunk++;
}
regChunk++;
dataSize++;
if (*regChunk == ',')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
if (*regChunk == '\\')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
}
}
else
break;
}
dataSize++;
}
else if (strcmp (dataFormat, "expand") == 0)
{
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
dataSize++;
regChunk++;
}
dataSize++;
}
else
{
UNIMPLEMENTED;
}
return dataSize;
}
static BOOL
allocateDataBuffer (PVOID * data, int * dataBufferSize, int dataSize)
{
if (*dataBufferSize < dataSize)
{
if (*dataBufferSize > 0)
MmFreeMemory(*data);
*data = MmAllocateMemory(dataSize);
*dataBufferSize = dataSize;
}
return TRUE;
}
static PCHAR
getKeyValueDataFromChunk (PCHAR regChunk, PCHAR dataFormat, PCHAR data)
{
char dataValue;
ULONG ulValue;
PCHAR ptr;
if (strcmp (dataFormat, "string") == 0)
{
/* convert quoted string to zero-terminated Unicode string */
ptr = (PCHAR)data;
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
*ptr++ = (CHAR)*regChunk++;
}
*ptr = 0;
regChunk++;
}
else if (strcmp (dataFormat, "hex") == 0)
{
while (*regChunk != 0 && isxdigit (*regChunk))
{
dataValue = (isdigit (*regChunk) ? *regChunk - '0' :
tolower(*regChunk) - 'a') << 4;
regChunk++;
dataValue += (isdigit (*regChunk) ? *regChunk - '0' :
tolower(*regChunk) - 'a');
regChunk++;
*data++ = dataValue;
if (*regChunk == ',')
{
regChunk++;
if (*regChunk == '\\')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
}
}
}
}
else if (strcmp (dataFormat, "dword") == 0)
{
ulValue = 0;
while (*regChunk != 0 && isxdigit(*regChunk))
{
dataValue = (isdigit (*regChunk) ? *regChunk - '0' :
tolower(*regChunk) - 'a');
ulValue = (ulValue << 4) + dataValue;
regChunk++;
}
memcpy(data, &ulValue, sizeof(ULONG));
}
else if (strcmp (dataFormat, "multi") == 0)
{
ptr = (PCHAR)data;
while (*regChunk == '\"')
{
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
*ptr++ = (CHAR)*regChunk++;
}
regChunk++;
*ptr++ = 0;
if (*regChunk == ',')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
if (*regChunk == '\\')
{
regChunk++;
regChunk = skipWhitespaceInChunk (regChunk);
}
}
else
break;
}
*ptr = 0;
}
else if (strcmp (dataFormat, "expand") == 0)
{
/* convert quoted string to zero-terminated Unicode string */
ptr = (PCHAR)data;
regChunk++;
while (*regChunk != 0 && *regChunk != '\"')
{
*ptr++ = (CHAR)*regChunk++;
}
*ptr = 0;
regChunk++;
}
else
{
UNIMPLEMENTED;
}
return *regChunk ? regChunk : 0;
}
static BOOL
setKeyValue (HKEY currentKey,
PCHAR newValueName,
ULONG keyValueType,
PVOID data,
ULONG dataSize)
{
LONG status;
DbgPrint((DPRINT_REGISTRY, "Adding value (%s) to current key, with data type %d and size %d\n",
newValueName, (int)keyValueType, (int)dataSize));
status = RegSetValue(currentKey,
newValueName,
keyValueType,
data,
dataSize);
if (status != ERROR_SUCCESS)
{
DbgPrint((DPRINT_REGISTRY, "Could not set key value. status: %d\n", status));
return FALSE;
}
return TRUE;
}
VOID
RegImportHive(PCHAR ChunkBase,
ULONG ChunkSize)
{
HKEY currentKey = INVALID_HANDLE_VALUE;
char *newKeyName = NULL;
int newKeySize;
char dataFormat [10];
int keyValueType;
int dataSize = 0;
int dataBufferSize = 0;
PVOID data = 0;
PCHAR regChunk;
DbgPrint((DPRINT_REGISTRY, "ChunkBase %p ChunkSize %lx\n", ChunkBase, ChunkSize));
regChunk = checkAndSkipMagic (ChunkBase);
if (regChunk == 0)
return;
while (regChunk != 0 && *regChunk != 0 && (((ULONG)regChunk-(ULONG)ChunkBase) < ChunkSize))
{
regChunk = skipWhitespaceInChunk (regChunk);
if (regChunk == 0)
continue;
if (*regChunk == '[')
{
if (currentKey != INVALID_HANDLE_VALUE)
{
DbgPrint((DPRINT_REGISTRY, "Closing current key: 0x%lx\n", currentKey));
currentKey = INVALID_HANDLE_VALUE;
}
regChunk++;
newKeySize = computeKeyNameSize (regChunk);
if (!allocateKeyName (&newKeyName, newKeySize))
{
regChunk = 0;
continue;
}
regChunk = getKeyNameFromChunk (regChunk, newKeyName);
if (regChunk == 0)
continue;
currentKey = createNewKey (newKeyName);
if (currentKey == INVALID_HANDLE_VALUE)
{
regChunk = skipToNextKeyInChunk (regChunk);
continue;
}
regChunk++;
}
else
{
if (currentKey == INVALID_HANDLE_VALUE)
{
regChunk = skipToNextKeyInChunk (regChunk);
continue;
}
newKeySize = computeKeyValueNameSize (regChunk);
if (!allocateKeyName (&newKeyName, newKeySize))
{
regChunk = 0;
continue;
}
regChunk = getKeyValueNameFromChunk (regChunk, newKeyName);
if (regChunk == 0)
continue;
if (*regChunk != '=')
{
regChunk = skipToNextKeyValueInChunk (regChunk);
continue;
}
regChunk++;
regChunk = getKeyValueTypeFromChunk (regChunk, dataFormat, &keyValueType);
if (regChunk == 0)
continue;
dataSize = computeKeyValueDataSize (regChunk, dataFormat);
if (!allocateDataBuffer (&data, &dataBufferSize, dataSize))
{
regChunk = 0;
continue;
}
regChunk = getKeyValueDataFromChunk (regChunk, dataFormat, data);
if (regChunk == 0)
continue;
if (!setKeyValue (currentKey, newKeyName, keyValueType, data, dataSize))
{
regChunk = 0;
continue;
}
}
}
if (currentKey != INVALID_HANDLE_VALUE)
{
DbgPrint((DPRINT_REGISTRY, "Closing current key: 0x%lx\n", currentKey));
}
if (newKeyName != NULL)
{
MmFreeMemory(newKeyName);
}
if (data != NULL)
{
MmFreeMemory(data);
}
return;
}
BOOL
RegExportHive(PCHAR ChunkBase, PULONG ChunkSize)
{
return(TRUE);
}
/* EOF */

View File

@@ -1,579 +0,0 @@
/*
* FreeLoader
*
* Copyright (C) 2001 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* TODO:
* - Implement RegDeleteKey().
* - Implement RegQueryMultipleValue().
* - Fix RegEnumValue().
*/
#include <freeldr.h>
#include <mm.h>
#include <rtl.h>
#include <debug.h>
#include "registry.h"
static HKEY RootKey;
VOID
RegInitializeRegistry(VOID)
{
RootKey = (HKEY)MmAllocateMemory(sizeof(KEY));
InitializeListHead(&RootKey->SubKeyList);
InitializeListHead(&RootKey->ValueList);
InitializeListHead(&RootKey->KeyList);
RootKey->NameSize = 2;
RootKey->Name = (PUCHAR)MmAllocateMemory(2);
strcpy(RootKey->Name, "\\");
RootKey->Type = 0;
RootKey->DataSize = 0;
RootKey->Data = NULL;
}
LONG
RegCreateKey(HKEY ParentKey,
PCHAR KeyName,
PHKEY Key)
{
PLIST_ENTRY Ptr;
HKEY SearchKey = INVALID_HANDLE_VALUE;
HKEY CurrentKey;
HKEY NewKey;
PCHAR p;
PCHAR name;
int subkeyLength;
int stringLength;
DbgPrint((DPRINT_REGISTRY, "KeyName '%s'\n", KeyName));
if (*KeyName == '\\')
{
KeyName++;
CurrentKey = RootKey;
}
else if (ParentKey == NULL)
{
CurrentKey = RootKey;
}
else
{
CurrentKey = ParentKey;
}
while (*KeyName != 0)
{
DbgPrint((DPRINT_REGISTRY, "KeyName '%s'\n", KeyName));
if (*KeyName == '\\')
KeyName++;
p = strchr(KeyName, '\\');
if ((p != NULL) && (p != KeyName))
{
subkeyLength = p - KeyName;
stringLength = subkeyLength + 1;
name = KeyName;
}
else
{
subkeyLength = strlen(KeyName);
stringLength = subkeyLength;
name = KeyName;
}
Ptr = CurrentKey->SubKeyList.Flink;
while (Ptr != &CurrentKey->SubKeyList)
{
DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr));
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey));
DbgPrint((DPRINT_REGISTRY, "Searching '%s'\n", SearchKey->Name));
if (strncmp(SearchKey->Name, name, subkeyLength) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &CurrentKey->SubKeyList)
{
/* no key found -> create new subkey */
NewKey = (HKEY)MmAllocateMemory(sizeof(KEY));
if (NewKey == NULL)
return(ERROR_OUTOFMEMORY);
InitializeListHead(&NewKey->SubKeyList);
InitializeListHead(&NewKey->ValueList);
NewKey->Type = 0;
NewKey->DataSize = 0;
NewKey->Data = NULL;
InsertTailList(&CurrentKey->SubKeyList, &NewKey->KeyList);
NewKey->NameSize = subkeyLength + 1;
NewKey->Name = (PCHAR)MmAllocateMemory(NewKey->NameSize);
if (NewKey->Name == NULL)
return(ERROR_OUTOFMEMORY);
memcpy(NewKey->Name, name, subkeyLength);
NewKey->Name[subkeyLength] = 0;
DbgPrint((DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey));
DbgPrint((DPRINT_REGISTRY, "NewKey '%s' Length %d\n", NewKey->Name, NewKey->NameSize));
CurrentKey = NewKey;
}
else
{
CurrentKey = SearchKey;
}
KeyName = KeyName + stringLength;
}
if (Key != NULL)
*Key = CurrentKey;
return(ERROR_SUCCESS);
}
LONG
RegDeleteKey(HKEY Key,
PCHAR Name)
{
if (strchr(Name, '\\') != NULL)
return(ERROR_INVALID_PARAMETER);
return(ERROR_SUCCESS);
}
LONG
RegEnumKey(HKEY Key,
ULONG Index,
PCHAR Name,
PULONG NameSize)
{
PLIST_ENTRY Ptr;
HKEY SearchKey;
ULONG Count = 0;
ULONG Size;
Ptr = Key->SubKeyList.Flink;
while (Ptr != &Key->SubKeyList)
{
if (Index == Count)
break;
Count++;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->SubKeyList)
return(ERROR_NO_MORE_ITEMS);
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
DbgPrint((DPRINT_REGISTRY, "Name '%s' Length %d\n", SearchKey->Name, SearchKey->NameSize));
Size = min(SearchKey->NameSize, *NameSize);
*NameSize = Size;
memcpy(Name, SearchKey->Name, Size);
return(ERROR_SUCCESS);
}
LONG
RegOpenKey(HKEY ParentKey,
PCHAR KeyName,
PHKEY Key)
{
PLIST_ENTRY Ptr;
HKEY SearchKey = INVALID_HANDLE_VALUE;
HKEY CurrentKey;
PCHAR p;
PCHAR name;
int subkeyLength;
int stringLength;
DbgPrint((DPRINT_REGISTRY, "KeyName '%s'\n", KeyName));
*Key = NULL;
if (*KeyName == '\\')
{
KeyName++;
CurrentKey = RootKey;
}
else if (ParentKey == NULL)
{
CurrentKey = RootKey;
}
else
{
CurrentKey = ParentKey;
}
while (*KeyName != 0)
{
DbgPrint((DPRINT_REGISTRY, "KeyName '%s'\n", KeyName));
if (*KeyName == '\\')
KeyName++;
p = strchr(KeyName, '\\');
if ((p != NULL) && (p != KeyName))
{
subkeyLength = p - KeyName;
stringLength = subkeyLength + 1;
name = KeyName;
}
else
{
subkeyLength = strlen(KeyName);
stringLength = subkeyLength;
name = KeyName;
}
Ptr = CurrentKey->SubKeyList.Flink;
while (Ptr != &CurrentKey->SubKeyList)
{
DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr));
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey));
DbgPrint((DPRINT_REGISTRY, "Searching '%s'\n", SearchKey->Name));
if (strncmp(SearchKey->Name, name, subkeyLength) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &CurrentKey->SubKeyList)
{
return(ERROR_PATH_NOT_FOUND);
}
else
{
CurrentKey = SearchKey;
}
KeyName = KeyName + stringLength;
}
if (Key != NULL)
*Key = CurrentKey;
return(ERROR_SUCCESS);
}
LONG
RegSetValue(HKEY Key,
PCHAR ValueName,
ULONG Type,
PUCHAR Data,
ULONG DataSize)
{
PLIST_ENTRY Ptr;
PVALUE Value = NULL;
DbgPrint((DPRINT_REGISTRY, "Key 0x%x, ValueName '%s', Type %d, Data 0x%x, DataSize %d\n",
(int)Key, ValueName, (int)Type, (int)Data, (int)DataSize));
if ((ValueName == NULL) || (*ValueName == 0))
{
/* set default value */
if (Key->Data != NULL)
MmFreeMemory(Key->Data);
Key->Data = (PUCHAR)MmAllocateMemory(DataSize);
Key->DataSize = DataSize;
Key->Type = Type;
memcpy(Key->Data, Data, DataSize);
}
else
{
/* set non-default value */
Ptr = Key->ValueList.Flink;
while (Ptr != &Key->ValueList)
{
Value = CONTAINING_RECORD(Ptr,
VALUE,
ValueList);
DbgPrint((DPRINT_REGISTRY, "Value->Name '%s'\n", Value->Name));
if (stricmp(Value->Name, ValueName) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->ValueList)
{
/* add new value */
DbgPrint((DPRINT_REGISTRY, "No value found - adding new value\n"));
Value = (PVALUE)MmAllocateMemory(sizeof(VALUE));
if (Value == NULL)
return(ERROR_OUTOFMEMORY);
InsertTailList(&Key->ValueList, &Value->ValueList);
Value->NameSize = strlen(ValueName)+1;
Value->Name = (PCHAR)MmAllocateMemory(Value->NameSize);
if (Value->Name == NULL)
return(ERROR_OUTOFMEMORY);
strcpy(Value->Name, ValueName);
Value->Data = NULL;
}
/* set new value */
if (DataSize <= sizeof(PUCHAR))
{
Value->DataSize = DataSize;
Value->Type = Type;
memcpy(&Value->Data, Data, DataSize);
}
else
{
if(Value->Data != NULL)
MmFreeMemory(Value->Data);
Value->Data = (PUCHAR)MmAllocateMemory(DataSize);
if (Value->Data == NULL)
return(ERROR_OUTOFMEMORY);
Value->DataSize = DataSize;
Value->Type = Type;
memcpy(Value->Data, Data, DataSize);
}
}
return(ERROR_SUCCESS);
}
LONG
RegQueryValue(HKEY Key,
PCHAR ValueName,
PULONG Type,
PUCHAR Data,
PULONG DataSize)
{
ULONG Size;
PLIST_ENTRY Ptr;
PVALUE Value = NULL;
if ((ValueName == NULL) || (*ValueName == 0))
{
/* query default value */
if (Key->Data == NULL)
return(ERROR_INVALID_PARAMETER);
if (Type != NULL)
*Type = Key->Type;
if ((Data != NULL) && (DataSize != NULL))
{
Size = min(Key->DataSize, *DataSize);
memcpy(Data, Key->Data, Size);
*DataSize = Size;
}
}
else
{
/* query non-default value */
Ptr = Key->ValueList.Flink;
while (Ptr != &Key->ValueList)
{
Value = CONTAINING_RECORD(Ptr,
VALUE,
ValueList);
DbgPrint((DPRINT_REGISTRY, "Searching for '%s'. Value name '%s'\n", ValueName, Value->Name));
if (stricmp(Value->Name, ValueName) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->ValueList)
return(ERROR_INVALID_PARAMETER);
if (Type != NULL)
*Type = Value->Type;
if ((Data != NULL) && (DataSize != NULL))
{
if (Value->DataSize <= sizeof(PUCHAR))
{
Size = min(Value->DataSize, *DataSize);
memcpy(Data, &Value->Data, Size);
*DataSize = Size;
}
else
{
Size = min(Value->DataSize, *DataSize);
memcpy(Data, Value->Data, Size);
*DataSize = Size;
}
}
}
return(ERROR_SUCCESS);
}
LONG
RegDeleteValue(HKEY Key,
PCHAR ValueName)
{
PLIST_ENTRY Ptr;
PVALUE Value = NULL;
if ((ValueName == NULL) || (*ValueName == 0))
{
/* delete default value */
if (Key->Data != NULL)
MmFreeMemory(Key->Data);
Key->Data = NULL;
Key->DataSize = 0;
Key->Type = 0;
}
else
{
/* delete non-default value */
Ptr = Key->ValueList.Flink;
while (Ptr != &Key->ValueList)
{
Value = CONTAINING_RECORD(Ptr,
VALUE,
ValueList);
if (strcmp(Value->Name, ValueName) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->ValueList)
return(ERROR_INVALID_PARAMETER);
/* delete value */
if (Value->Name != NULL)
MmFreeMemory(Value->Name);
Value->Name = NULL;
Value->NameSize = 0;
if (Value->DataSize > sizeof(PUCHAR))
{
if (Value->Data != NULL)
MmFreeMemory(Value->Data);
}
Value->Data = NULL;
Value->DataSize = 0;
Value->Type = 0;
RemoveEntryList(&Value->ValueList);
MmFreeMemory(Value);
}
return(ERROR_SUCCESS);
}
LONG
RegEnumValue(HKEY Key,
ULONG Index,
PCHAR ValueName,
PULONG NameSize,
PULONG Type,
PUCHAR Data,
PULONG DataSize)
{
PLIST_ENTRY Ptr;
PVALUE Value;
ULONG Count = 0;
if (Key->Data != NULL)
{
if (Index > 0)
{
Index--;
}
else
{
/* enumerate default value */
if (ValueName != NULL)
*ValueName = 0;
if (Type != NULL)
*Type = Key->Type;
if (DataSize != NULL)
*DataSize = Key->DataSize;
/* FIXME: return more values */
}
}
Ptr = Key->ValueList.Flink;
while (Ptr != &Key->ValueList)
{
if (Index == Count)
break;
Count++;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->ValueList)
return(ERROR_NO_MORE_ITEMS);
Value = CONTAINING_RECORD(Ptr,
VALUE,
ValueList);
/* FIXME: return values */
return(ERROR_SUCCESS);
}
#if 0
LONG
RegQueryMultipleValue(HKEY Key,
...)
{
return(ERROR_SUCCESS);
}
#endif
/* EOF */

View File

@@ -1,289 +0,0 @@
/*
* FreeLoader - registry.h
*
* Copyright (C) 2001 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __REGISTRY_H
#define __REGISTRY_H
#define INVALID_HANDLE_VALUE NULL
typedef struct _LIST_ENTRY
{
struct _LIST_ENTRY *Flink;
struct _LIST_ENTRY *Blink;
} LIST_ENTRY, *PLIST_ENTRY;
typedef struct _REG_KEY
{
LIST_ENTRY KeyList;
LIST_ENTRY SubKeyList;
LIST_ENTRY ValueList;
ULONG NameSize;
PUCHAR Name;
/* default data */
ULONG Type;
ULONG DataSize;
PUCHAR Data;
} KEY, *HKEY, **PHKEY;
typedef struct _REG_VALUE
{
LIST_ENTRY ValueList;
/* value name */
ULONG NameSize;
PUCHAR Name;
/* value data */
ULONG Type;
ULONG DataSize;
PUCHAR Data;
} VALUE, *PVALUE;
#define ERROR_SUCCESS 0L
#define ERROR_PATH_NOT_FOUND 2L
#define ERROR_OUTOFMEMORY 14L
#define ERROR_INVALID_PARAMETER 87L
#define ERROR_MORE_DATA 234L
#define ERROR_NO_MORE_ITEMS 259L
#define assert(x)
/*
* VOID
* InitializeListHead (
* PLIST_ENTRY ListHead
* );
*
* FUNCTION: Initializes a double linked list
* ARGUMENTS:
* ListHead = Caller supplied storage for the head of the list
*/
#define InitializeListHead(ListHead) \
{ \
(ListHead)->Flink = (ListHead); \
(ListHead)->Blink = (ListHead); \
}
/*
* VOID
* InsertHeadList (
* PLIST_ENTRY ListHead,
* PLIST_ENTRY Entry
* );
*
* FUNCTION: Inserts an entry in a double linked list
* ARGUMENTS:
* ListHead = Head of the list
* Entry = Entry to insert
*/
#define InsertHeadList(ListHead, ListEntry) \
{ \
PLIST_ENTRY OldFlink; \
OldFlink = (ListHead)->Flink; \
(ListEntry)->Flink = OldFlink; \
(ListEntry)->Blink = (ListHead); \
OldFlink->Blink = (ListEntry); \
(ListHead)->Flink = (ListEntry); \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink!=NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
}
/*
* VOID
* InsertTailList (
* PLIST_ENTRY ListHead,
* PLIST_ENTRY Entry
* );
*
* FUNCTION:
* Inserts an entry in a double linked list
*
* ARGUMENTS:
* ListHead = Head of the list
* Entry = Entry to insert
*/
#define InsertTailList(ListHead, ListEntry) \
{ \
PLIST_ENTRY OldBlink; \
OldBlink = (ListHead)->Blink; \
(ListEntry)->Flink = (ListHead); \
(ListEntry)->Blink = OldBlink; \
OldBlink->Flink = (ListEntry); \
(ListHead)->Blink = (ListEntry); \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink != NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
}
/*
* BOOLEAN
* IsListEmpty (
* PLIST_ENTRY ListHead
* );
*
* FUNCTION:
* Checks if a double linked list is empty
*
* ARGUMENTS:
* ListHead = Head of the list
*/
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
/*
*VOID
*RemoveEntryList (
* PLIST_ENTRY Entry
* );
*
* FUNCTION:
* Removes an entry from a double linked list
*
* ARGUMENTS:
* ListEntry = Entry to remove
*/
#define RemoveEntryList(ListEntry) \
{ \
PLIST_ENTRY OldFlink; \
PLIST_ENTRY OldBlink; \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink!=NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
OldFlink = (ListEntry)->Flink; \
OldBlink = (ListEntry)->Blink; \
OldFlink->Blink = OldBlink; \
OldBlink->Flink = OldFlink; \
(ListEntry)->Flink = NULL; \
(ListEntry)->Blink = NULL; \
}
/*
* PURPOSE: Returns the byte offset of a field within a structure
*/
#define FIELD_OFFSET(Type,Field) (LONG)(&(((Type *)(0))->Field))
/*
* PURPOSE: Returns the base address structure if the caller knows the
* address of a field within the structure
* ARGUMENTS:
* Address = address of the field
* Type = Type of the whole structure
* Field = Name of the field whose address is none
*/
#define CONTAINING_RECORD(Address,Type,Field) \
(Type *)(((LONG)Address) - FIELD_OFFSET(Type,Field))
//typedef struct _REG_KEY *HKEY, **PHKEY;
#define REG_NONE 0
#define REG_SZ 1
#define REG_EXPAND_SZ 2
#define REG_BINARY 3
#define REG_DWORD 4
#define REG_DWORD_BIG_ENDIAN 5
#define REG_DWORD_LITTLE_ENDIAN 4
#define REG_LINK 6
#define REG_MULTI_SZ 7
#define REG_RESOURCE_LIST 8
#define REG_FULL_RESOURCE_DESCRIPTOR 9
#define REG_RESOURCE_REQUIREMENTS_LIST 10
VOID
RegInitializeRegistry(VOID);
LONG
RegCreateKey(HKEY ParentKey,
PCHAR KeyName,
PHKEY Key);
LONG
RegDeleteKey(HKEY Key,
PCHAR Name);
LONG
RegEnumKey(HKEY Key,
ULONG Index,
PCHAR Name,
PULONG NameSize);
LONG
RegOpenKey(HKEY ParentKey,
PCHAR KeyName,
PHKEY Key);
LONG
RegSetValue(HKEY Key,
PCHAR ValueName,
ULONG Type,
PUCHAR Data,
ULONG DataSize);
LONG
RegQueryValue(HKEY Key,
PCHAR ValueName,
PULONG Type,
PUCHAR Data,
PULONG DataSize);
LONG
RegDeleteValue(HKEY Key,
PCHAR ValueName);
LONG
RegEnumValue(HKEY Key,
ULONG Index,
PCHAR ValueName,
PULONG NameSize,
PULONG Type,
PUCHAR Data,
PULONG DataSize);
VOID
RegImportHive(PCHAR ChunkBase,
ULONG ChunkSize);
#endif /* __REGISTRY_H */
/* EOF */

View File

@@ -1,175 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <rtl.h>
VOID RtlListInitializeHead(PLIST_ITEM ListHead)
{
ListHead->ListPrev = NULL;
ListHead->ListNext = NULL;
}
VOID RtlListInsertHead(PLIST_ITEM ListHead, PLIST_ITEM Entry)
{
ListHead = RtlListGetHead(ListHead);
ListHead->ListPrev = Entry;
Entry->ListNext = ListHead;
Entry->ListPrev = NULL;
}
VOID RtlListInsertTail(PLIST_ITEM ListHead, PLIST_ITEM Entry)
{
ListHead = RtlListGetTail(ListHead);
ListHead->ListNext = Entry;
Entry->ListNext = NULL;
Entry->ListPrev = ListHead;
}
PLIST_ITEM RtlListRemoveHead(PLIST_ITEM ListHead)
{
PLIST_ITEM OldListHead = RtlListGetHead(ListHead);
ListHead = ListHead->ListNext;
ListHead->ListPrev = NULL;
return OldListHead;
}
PLIST_ITEM RtlListRemoveTail(PLIST_ITEM ListHead)
{
PLIST_ITEM ListTail;
ListTail = RtlListGetTail(ListHead);
ListHead = ListTail->ListPrev;
ListHead->ListNext = NULL;
return ListTail;
}
PLIST_ITEM RtlListGetHead(PLIST_ITEM ListHead)
{
while (ListHead->ListPrev != NULL)
{
ListHead = ListHead->ListPrev;
}
return ListHead;
}
PLIST_ITEM RtlListGetTail(PLIST_ITEM ListHead)
{
while (ListHead->ListNext != NULL)
{
ListHead = ListHead->ListNext;
}
return ListHead;
}
BOOL RtlListIsEmpty(PLIST_ITEM ListHead)
{
if (ListHead == NULL)
{
return TRUE;
}
return (ListHead->ListNext == NULL);
}
ULONG RtlListCountEntries(PLIST_ITEM ListHead)
{
ULONG Count = 0;
while (ListHead != NULL)
{
Count++;
ListHead = ListHead->ListNext;
}
return Count;
}
PLIST_ITEM RtlListGetPrevious(PLIST_ITEM ListEntry)
{
return ListEntry->ListPrev;
}
PLIST_ITEM RtlListGetNext(PLIST_ITEM ListEntry)
{
return ListEntry->ListNext;
}
PLIST_ITEM RtlListRemoveEntry(PLIST_ITEM ListEntry)
{
PLIST_ITEM ListNext = RtlListGetNext(ListEntry);
PLIST_ITEM ListPrev = RtlListGetPrevious(ListEntry);
if (ListPrev != NULL)
{
ListPrev->ListNext = ListNext;
}
if (ListNext != NULL)
{
ListNext->ListPrev = ListPrev;
}
return ListNext;
}
VOID RtlListInsertEntry(PLIST_ITEM InsertAfter, PLIST_ITEM ListEntry)
{
PLIST_ITEM ListNext = RtlListGetNext(InsertAfter);
InsertAfter->ListNext = ListEntry;
ListEntry->ListPrev = InsertAfter;
ListEntry->ListNext = ListNext;
}
VOID RtlListMoveEntryPrevious(PLIST_ITEM ListEntry)
{
PLIST_ITEM ListPrev = RtlListGetPrevious(ListEntry);
if (ListPrev == NULL)
{
return;
}
//
// Move the previous entry after this one
//
RtlListRemoveEntry(ListPrev);
RtlListInsertEntry(ListEntry, ListPrev);
}
VOID RtlListMoveEntryNext(PLIST_ITEM ListEntry)
{
PLIST_ITEM ListNext = RtlListGetNext(ListEntry);
if (ListNext == NULL)
{
return;
}
//
// Move this entry after the next entry
//
RtlListRemoveEntry(ListEntry);
RtlListInsertEntry(ListNext, ListEntry);
}

View File

@@ -1,67 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
int RtlCompareMemory(const PVOID Source1, const PVOID Source2, ULONG Length)
{
ULONG i;
const PCHAR buffer1 = Source1;
const PCHAR buffer2 = Source2;
for (i=0; i<Length; i++)
{
if(buffer1[i] == buffer2[i])
continue;
else
return (buffer1[i] - buffer2[i]);
}
return 0;
}
VOID RtlCopyMemory(PVOID Destination, const PVOID Source, ULONG Length)
{
ULONG i;
PCHAR buf1 = Destination;
const PCHAR buf2 = Source;
for (i=0; i<Length; i++)
{
buf1[i] = buf2[i];
}
}
VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill)
{
ULONG i;
PUCHAR buf1 = Destination;
for (i=0; i<Length; i++)
{
buf1[i] = Fill;
}
}
VOID RtlZeroMemory(PVOID Destination, ULONG Length)
{
RtlFillMemory(Destination, Length, 0);
}

View File

@@ -1,121 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <rtl.h>
/*
* print() - prints unformatted text to stdout
*/
void print(char *str)
{
int i;
for(i=0; i<strlen(str); i++)
putchar(str[i]);
}
/*
* printf() - prints formatted text to stdout
* from:
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
*/
void printf(char *format, ... )
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
dataptr++;
while ((c = *(format++)))
{
if (c != '%')
putchar(c);
else
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
ptr = str;
while (*ptr)
putchar(*(ptr++));
break;
case 'c': putchar((*(dataptr++))&0xff); break;
case 's':
ptr = (char *)(*(dataptr++));
while ((c = *(ptr++)))
putchar(c);
break;
}
}
}
void sprintf(char *buffer, char *format, ... )
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
char *p = buffer;
dataptr++;
while ((c = *(format++)))
{
if (c != '%')
{
*p = c;
p++;
}
else
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
ptr = str;
while (*ptr)
{
*p = *(ptr++);
p++;
}
break;
case 'c':
*p = (*(dataptr++))&0xff;
p++;
break;
case 's':
ptr = (char *)(*(dataptr++));
while ((c = *(ptr++)))
{
*p = c;
p++;
}
break;
}
}
*p=0;
}

View File

@@ -1,152 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* convert_to_ascii() - converts a number to it's ascii equivalent
* from:
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
*/
char *convert_to_ascii(char *buf, int c, ...)
{
unsigned long num = *((&c) + 1), mult = 10;
char *ptr = buf;
if (c == 'x')
mult = 16;
if ((num & 0x80000000uL) && c == 'd')
{
num = (~num)+1;
*(ptr++) = '-';
buf++;
}
do
{
int dig = num % mult;
*(ptr++) = ( (dig > 9) ? dig + 'a' - 10 : '0' + dig );
}
while (num /= mult);
/* reorder to correct direction!! */
{
char *ptr1 = ptr-1;
char *ptr2 = buf;
while (ptr1 > ptr2)
{
int c = *ptr1;
*ptr1 = *ptr2;
*ptr2 = c;
ptr1--;
ptr2++;
}
}
return ptr;
}
char *itoa(int value, char *string, int radix)
{
if(radix == 16)
*convert_to_ascii(string, 'x', value) = 0;
else
*convert_to_ascii(string, 'd', value) = 0;
return string;
}
int toupper(int c)
{
if((c >= 'a') && (c <= 'z'))
c -= 32;
return c;
}
int tolower(int c)
{
if((c >= 'A') && (c <= 'Z'))
c += 32;
return c;
}
int atoi(char *string)
{
int base;
int result = 0;
char *str;
if((string[0] == '0') && (string[1] == 'x'))
{
base = 16;
str = string + 2;
}
else
{
base = 10;
str = string;
}
while(1)
{
if(base == 16)
{
if(((*str < '0') || (*str > '9')) && ((*str < 'a') || (*str > 'f')) && ((*str < 'A') || (*str > 'F')))
break;
result *= base;
if((*str >= '0') && (*str <= '9'))
result += (*str - '0');
if((*str >= 'a') && (*str <= 'f'))
result += (*str - 'a') + 10;
if((*str >= 'A') && (*str <= 'F'))
result += (*str - 'A') + 10;
str++;
}
else //if(base == 10)
{
if((*str < '0') || (*str > '9'))
break;
result *= base;
result += (*str - '0');
str++;
}
}
return result;
}
int isspace(int c)
{
return(c == ' ' || (c >= 0x09 && c <= 0x0D));
}
int isdigit(int c)
{
return(c >= '0' && c <= '9');
}
int isxdigit(int c)
{
return((c >= '0' && c <= '9')||(c >= 'a' && c <= 'f')||(c >= 'A' && c <= 'F'));
}

View File

@@ -1,152 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <rtl.h>
int strlen(char *str)
{
int len;
for(len=0; str[len] != '\0'; len++);
return len;
}
char *strcpy(char *dest, char *src)
{
char *ret = dest;
while(*src)
*dest++ = *src++;
*dest = 0;
return ret;
}
char *strncpy(char *dest, char *src, size_t count)
{
char *ret = dest;
while((*src) && (count--))
*dest++ = *src++;
*dest = 0;
return ret;
}
char *strcat(char *dest, char *src)
{
char *ret = dest;
while(*dest)
dest++;
while(*src)
*dest++ = *src++;
*dest = 0;
return ret;
}
char *strchr(const char *s, int c)
{
char cc = c;
while (*s)
{
if (*s == cc)
return (char *)s;
s++;
}
if (cc == 0)
return (char *)s;
return 0;
}
char *strrchr(const char *s, int c)
{
char cc = c;
const char *sp=(char *)0;
while (*s)
{
if (*s == cc)
sp = s;
s++;
}
if (cc == 0)
sp = s;
return (char *)sp;
}
int strcmp(const char *string1, const char *string2)
{
while(*string1 == *string2)
{
if(*string1 == 0)
return 0;
string1++;
string2++;
}
return *(unsigned const char *)string1 - *(unsigned const char *)(string2);
}
int stricmp(const char *string1, const char *string2)
{
while(tolower(*string1) == tolower(*string2))
{
if(*string1 == 0)
return 0;
string1++;
string2++;
}
return (int)tolower(*string1) - (int)tolower(*string2);
}
int _strnicmp(const char *string1, const char *string2, size_t length)
{
if (length == 0)
return 0;
do
{
if (toupper(*string1) != toupper(*string2++))
return toupper(*(unsigned const char *)string1) - toupper(*(unsigned const char *)--string2);
if (*string1++ == 0)
break;
}
while (--length != 0);
return 0;
}
int strncmp(const char *string1, const char *string2, size_t length)
{
if (length == 0)
return 0;
do
{
if (*string1 != *string2++)
return *(unsigned const char *)string1 - *(unsigned const char *)--string2;
if (*string1++ == 0)
break;
}
while (--length != 0);
return 0;
}

View File

@@ -1,85 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <ui.h>
#include "gui.h"
#include <rtl.h>
#include <mm.h>
#include <debug.h>
#include <inifile.h>
#include <version.h>
VOID GuiDrawBackdrop(VOID)
{
}
VOID GuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */)
{
}
VOID GuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
{
}
VOID GuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr)
{
}
VOID GuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr)
{
}
VOID GuiDrawStatusText(PUCHAR StatusText)
{
}
VOID GuiUpdateDateTime(VOID)
{
}
VOID GuiSaveScreen(PUCHAR Buffer)
{
}
VOID GuiRestoreScreen(PUCHAR Buffer)
{
}
VOID GuiMessageBox(PUCHAR MessageText)
{
}
VOID GuiMessageBoxCritical(PUCHAR MessageText)
{
}
VOID GuiDrawProgressBar(ULONG Position, ULONG Range)
{
}
UCHAR GuiTextToColor(PUCHAR ColorText)
{
return 0;
}
UCHAR GuiTextToFillStyle(PUCHAR FillStyleText)
{
return 0;
}

View File

@@ -1,56 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GUI_H
#define __GUI_H
#define TUI_SCREEN_MEM 0xB8000
#define TITLE_BOX_CHAR_HEIGHT 5
///////////////////////////////////////////////////////////////////////////////////////
//
// Graphical User Interface Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID GuiDrawBackdrop(VOID); // Fills the entire screen with a backdrop
VOID GuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
VOID GuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
VOID GuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr); // Draws a box around the area specified
VOID GuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr); // Draws text at coordinates specified
VOID GuiDrawStatusText(PUCHAR StatusText); // Draws text at the very bottom line on the screen
VOID GuiUpdateDateTime(VOID); // Updates the date and time
VOID GuiSaveScreen(PUCHAR Buffer); // Saves the screen so that it can be restored later
VOID GuiRestoreScreen(PUCHAR Buffer); // Restores the screen from a previous save
VOID GuiMessageBox(PUCHAR MessageText); // Displays a message box on the screen with an ok button
VOID GuiMessageBoxCritical(PUCHAR MessageText); // Displays a message box on the screen with an ok button using no system resources
VOID GuiDrawProgressBar(ULONG Position, ULONG Range); // Draws the progress bar showing nPos percent filled
UCHAR GuiTextToColor(PUCHAR ColorText); // Converts the text color into it's equivalent color value
UCHAR GuiTextToFillStyle(PUCHAR FillStyleText); // Converts the text fill into it's equivalent fill value
///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL GuiDisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem);
#endif // #defined __GUI_H

View File

@@ -1,45 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __KEYCODES_H
#define __KEYCODES_H
// Key codes
#define KEY_EXTENDED 0x00
#define KEY_ENTER 0x0D
#define KEY_SPACE 0x20
#define KEY_UP 0x48
#define KEY_DOWN 0x50
#define KEY_LEFT 0x4B
#define KEY_RIGHT 0x4D
#define KEY_ESC 0x1B
#define KEY_F1 0x3B
#define KEY_F2 0x3C
#define KEY_F3 0x3D
#define KEY_F4 0x3E
#define KEY_F5 0x3F
#define KEY_F6 0x40
#define KEY_F7 0x41
#define KEY_F8 0x42
#define KEY_F9 0x43
#define KEY_F10 0x44
#endif // #defined __KEYCODES_H

View File

@@ -1,608 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <ui.h>
#include "tui.h"
#include "keycodes.h"
#include <rtl.h>
#include <mm.h>
#include <debug.h>
#include <inifile.h>
#include <version.h>
VOID TuiDrawBackdrop(VOID)
{
//
// Fill in the background (excluding title box & status bar)
//
TuiFillArea(0,
TUI_TITLE_BOX_CHAR_HEIGHT,
UiScreenWidth - 1,
UiScreenHeight - 2,
UiBackdropFillStyle,
ATTR(UiBackdropFgColor, UiBackdropBgColor));
//
// Draw the title box
//
TuiDrawBox(0,
0,
UiScreenWidth - 1,
TUI_TITLE_BOX_CHAR_HEIGHT - 1,
D_VERT,
D_HORZ,
TRUE,
FALSE,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
//
// Draw version text
//
TuiDrawText(2,
1,
GetFreeLoaderVersionString(),
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
//
// Draw copyright
//
TuiDrawText(2,
2,
BY_AUTHOR,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
TuiDrawText(2,
3,
AUTHOR_EMAIL,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
//
// Draw help text
//
//TuiDrawText(UiScreenWidth - 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
//
// Draw title text
//
TuiDrawText( (UiScreenWidth / 2) - (strlen(UiTitleBoxTitleText) / 2),
2,
UiTitleBoxTitleText,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
//
// Draw status bar
//
TuiDrawStatusText("");
//
// Update the date & time
//
TuiUpdateDateTime();
}
/*
* FillArea()
* This function assumes coordinates are zero-based
*/
VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */)
{
PUCHAR ScreenMemory = (PUCHAR)TUI_SCREEN_MEM;
ULONG i, j;
// Clip the area to the screen
// FIXME: This code seems to have problems... Uncomment and view ;-)
/*if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight))
{
return;
}
if ((Left + Right) >= UiScreenWidth)
{
Right = UiScreenWidth - Left;
}
if ((Top + Bottom) >= UiScreenHeight)
{
Bottom = UiScreenHeight - Top;
}*/
// Loop through each line and fill it in
for (i=Top; i<=Bottom; i++)
{
// Loop through each character (column) in the line and fill it in
for (j=Left; j<=Right; j++)
{
ScreenMemory[((i*2)*UiScreenWidth)+(j*2)] = FillChar;
ScreenMemory[((i*2)*UiScreenWidth)+(j*2)+1] = Attr;
}
}
}
/*
* DrawShadow()
* This function assumes coordinates are zero-based
*/
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
{
PUCHAR ScreenMemory = (PUCHAR)TUI_SCREEN_MEM;
ULONG Idx;
// Shade the bottom of the area
if (Bottom < (UiScreenHeight - 1))
{
if (UiScreenHeight < 34)
{
Idx=Left + 2;
}
else
{
Idx=Left + 1;
}
for (; Idx<=Right; Idx++)
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+(Idx*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
// Shade the right of the area
if (Right < (UiScreenWidth - 1))
{
for (Idx=Top+1; Idx<=Bottom; Idx++)
{
ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
if (UiScreenHeight < 34)
{
if ((Right + 1) < (UiScreenWidth - 1))
{
for (Idx=Top+1; Idx<=Bottom; Idx++)
{
ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
}
// Shade the bottom right corner
if ((Right < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
if (UiScreenHeight < 34)
{
if (((Right + 1) < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
}
/*
* DrawBox()
* This function assumes coordinates are zero-based
*/
VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr)
{
UCHAR ULCorner, URCorner, LLCorner, LRCorner;
// Calculate the corner values
if (HorzStyle == HORZ)
{
if (VertStyle == VERT)
{
ULCorner = UL;
URCorner = UR;
LLCorner = LL;
LRCorner = LR;
}
else // VertStyle == D_VERT
{
ULCorner = VD_UL;
URCorner = VD_UR;
LLCorner = VD_LL;
LRCorner = VD_LR;
}
}
else // HorzStyle == D_HORZ
{
if (VertStyle == VERT)
{
ULCorner = HD_UL;
URCorner = HD_UR;
LLCorner = HD_LL;
LRCorner = HD_LR;
}
else // VertStyle == D_VERT
{
ULCorner = D_UL;
URCorner = D_UR;
LLCorner = D_LL;
LRCorner = D_LR;
}
}
// Fill in box background
if (Fill)
{
TuiFillArea(Left, Top, Right, Bottom, ' ', Attr);
}
// Fill in corners
TuiFillArea(Left, Top, Left, Top, ULCorner, Attr);
TuiFillArea(Right, Top, Right, Top, URCorner, Attr);
TuiFillArea(Left, Bottom, Left, Bottom, LLCorner, Attr);
TuiFillArea(Right, Bottom, Right, Bottom, LRCorner, Attr);
// Fill in left line
TuiFillArea(Left, Top+1, Left, Bottom-1, VertStyle, Attr);
// Fill in top line
TuiFillArea(Left+1, Top, Right-1, Top, HorzStyle, Attr);
// Fill in right line
TuiFillArea(Right, Top+1, Right, Bottom-1, VertStyle, Attr);
// Fill in bottom line
TuiFillArea(Left+1, Bottom, Right-1, Bottom, HorzStyle, Attr);
// Draw the shadow
if (Shadow)
{
TuiDrawShadow(Left, Top, Right, Bottom);
}
}
/*
* DrawText()
* This function assumes coordinates are zero-based
*/
VOID TuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr)
{
PUCHAR ScreenMemory = (PUCHAR)TUI_SCREEN_MEM;
ULONG i, j;
// Draw the text
for (i=X, j=0; Text[j] && i<UiScreenWidth; i++,j++)
{
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = Text[j];
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr;
}
}
VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PUCHAR TextString, UCHAR Attr)
{
}
VOID TuiDrawStatusText(PUCHAR StatusText)
{
ULONG i;
TuiDrawText(0, UiScreenHeight-1, " ", ATTR(UiStatusBarFgColor, UiStatusBarBgColor));
TuiDrawText(1, UiScreenHeight-1, StatusText, ATTR(UiStatusBarFgColor, UiStatusBarBgColor));
for (i=strlen(StatusText)+1; i<UiScreenWidth; i++)
{
TuiDrawText(i, UiScreenHeight-1, " ", ATTR(UiStatusBarFgColor, UiStatusBarBgColor));
}
}
VOID TuiUpdateDateTime(VOID)
{
UCHAR DateString[40];
UCHAR TimeString[40];
UCHAR TempString[20];
ULONG Hour, Minute, Second;
BOOL PMHour = FALSE;
// Get the month name
strcpy(DateString, UiMonthNames[getmonth()-1]);
// Get the day
itoa(getday(), TempString, 10);
// Get the day postfix
if ((getday() == 1) || (getday() == 21) || (getday() == 31))
{
strcat(TempString, "st");
}
else if ((getday() == 2) || (getday() == 22))
{
strcat(TempString, "nd");
}
else if ((getday() == 3) || (getday() == 23))
{
strcat(TempString, "rd");
}
else
{
strcat(TempString, "th");
}
// Add the day to the date
strcat(DateString, TempString);
strcat(DateString, " ");
// Get the year and add it to the date
itoa(getyear(), TempString, 10);
strcat(DateString, TempString);
// Draw the date
TuiDrawText(UiScreenWidth-strlen(DateString)-2, 1, DateString, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// Get the hour and change from 24-hour mode to 12-hour
Hour = gethour();
if (Hour > 12)
{
Hour -= 12;
PMHour = TRUE;
}
if (Hour == 0)
{
Hour = 12;
}
Minute = getminute();
Second = getsecond();
itoa(Hour, TempString, 10);
strcpy(TimeString, " ");
strcat(TimeString, TempString);
strcat(TimeString, ":");
itoa(Minute, TempString, 10);
if (Minute < 10)
{
strcat(TimeString, "0");
}
strcat(TimeString, TempString);
strcat(TimeString, ":");
itoa(Second, TempString, 10);
if (Second < 10)
{
strcat(TimeString, "0");
}
strcat(TimeString, TempString);
if (PMHour)
{
strcat(TimeString, " PM");
}
else
{
strcat(TimeString, " AM");
}
// Draw the time
TuiDrawText(UiScreenWidth-strlen(TimeString)-2, 2, TimeString, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
}
VOID TuiSaveScreen(PUCHAR Buffer)
{
PUCHAR ScreenMemory = (PUCHAR)TUI_SCREEN_MEM;
ULONG i;
for (i=0; i < (UiScreenWidth * UiScreenHeight * 2); i++)
{
Buffer[i] = ScreenMemory[i];
}
}
VOID TuiRestoreScreen(PUCHAR Buffer)
{
PUCHAR ScreenMemory = (PUCHAR)TUI_SCREEN_MEM;
ULONG i;
for (i=0; i < (UiScreenWidth * UiScreenHeight * 2); i++)
{
ScreenMemory[i] = Buffer[i];
}
}
VOID TuiMessageBox(PUCHAR MessageText)
{
PVOID ScreenBuffer;
// Save the screen contents
ScreenBuffer = MmAllocateMemory(UiScreenWidth * UiScreenHeight * 2);
TuiSaveScreen(ScreenBuffer);
// Display the message box
TuiMessageBoxCritical(MessageText);
// Restore the screen contents
TuiRestoreScreen(ScreenBuffer);
MmFreeMemory(ScreenBuffer);
}
VOID TuiMessageBoxCritical(PUCHAR MessageText)
{
int width = 8;
int height = 1;
int curline = 0;
int i , j, k;
int x1, x2, y1, y2;
char temp[260];
char key;
// Find the height
for (i=0; i<strlen(MessageText); i++)
{
if (MessageText[i] == '\n')
height++;
}
// Find the width
for (i=0,j=0,k=0; i<height; i++)
{
while ((MessageText[j] != '\n') && (MessageText[j] != 0))
{
j++;
k++;
}
if (k > width)
width = k;
k = 0;
j++;
}
// Calculate box area
x1 = (UiScreenWidth - (width+2))/2;
x2 = x1 + width + 3;
y1 = ((UiScreenHeight - height - 2)/2) + 1;
y2 = y1 + height + 4;
// Draw the box
TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
// Draw the text
for (i=0,j=0; i<strlen(MessageText)+1; i++)
{
if ((MessageText[i] == '\n') || (MessageText[i] == 0))
{
temp[j] = 0;
j = 0;
UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
curline++;
}
else
temp[j++] = MessageText[i];
}
// Draw OK button
strcpy(temp, " OK ");
UiDrawText(x1+((x2-x1)/2)-3, y2-2, temp, ATTR(COLOR_BLACK, COLOR_GRAY));
// Draw status text
UiDrawStatusText("Press ENTER to continue");
for (;;)
{
if (kbhit())
{
key = getch();
if(key == KEY_EXTENDED)
key = getch();
if(key == KEY_ENTER)
break;
else if(key == KEY_SPACE)
break;
else if(key == KEY_ESC)
break;
}
TuiUpdateDateTime();
}
}
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range)
{
ULONG Left, Top, Right, Bottom;
ULONG Width = 50; // Allow for 50 "bars"
ULONG Height = 2;
Left = (UiScreenWidth - Width - 4) / 2;
Right = Left + Width + 3;
Top = (UiScreenHeight - Height - 2) / 2;
Top += 2;
Bottom = Top + Height + 1;
TuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range);
}
VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range)
{
ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3;
if (Position > Range)
{
Position = Range;
}
// Draw the box
TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor));
// Draw the "Loading..." text
TuiDrawText(70/2, Top+1, "Loading...", ATTR(UiTextColor, UiMenuBgColor));
// Draw the percent complete
for (i=0; i<(Position*ProgressBarWidth)/Range; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
}
// Draw the rest
for (; i<ProgressBarWidth; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
}
TuiUpdateDateTime();
}
UCHAR TuiTextToColor(PUCHAR ColorText)
{
if (stricmp(ColorText, "Black") == 0)
return COLOR_BLACK;
else if (stricmp(ColorText, "Blue") == 0)
return COLOR_BLUE;
else if (stricmp(ColorText, "Green") == 0)
return COLOR_GREEN;
else if (stricmp(ColorText, "Cyan") == 0)
return COLOR_CYAN;
else if (stricmp(ColorText, "Red") == 0)
return COLOR_RED;
else if (stricmp(ColorText, "Magenta") == 0)
return COLOR_MAGENTA;
else if (stricmp(ColorText, "Brown") == 0)
return COLOR_BROWN;
else if (stricmp(ColorText, "Gray") == 0)
return COLOR_GRAY;
else if (stricmp(ColorText, "DarkGray") == 0)
return COLOR_DARKGRAY;
else if (stricmp(ColorText, "LightBlue") == 0)
return COLOR_LIGHTBLUE;
else if (stricmp(ColorText, "LightGreen") == 0)
return COLOR_LIGHTGREEN;
else if (stricmp(ColorText, "LightCyan") == 0)
return COLOR_LIGHTCYAN;
else if (stricmp(ColorText, "LightRed") == 0)
return COLOR_LIGHTRED;
else if (stricmp(ColorText, "LightMagenta") == 0)
return COLOR_LIGHTMAGENTA;
else if (stricmp(ColorText, "Yellow") == 0)
return COLOR_YELLOW;
else if (stricmp(ColorText, "White") == 0)
return COLOR_WHITE;
return COLOR_BLACK;
}
UCHAR TuiTextToFillStyle(PUCHAR FillStyleText)
{
if (stricmp(FillStyleText, "Light") == 0)
{
return LIGHT_FILL;
}
else if (stricmp(FillStyleText, "Medium") == 0)
{
return MEDIUM_FILL;
}
else if (stricmp(FillStyleText, "Dark") == 0)
{
return DARK_FILL;
}
return LIGHT_FILL;
}

View File

@@ -1,143 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __TUI_H
#define __TUI_H
#define TUI_SCREEN_MEM 0xB8000
#define TUI_TITLE_BOX_CHAR_HEIGHT 5
///////////////////////////////////////////////////////////////////////////////////////
//
// Textual User Interface Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID TuiDrawBackdrop(VOID); // Fills the entire screen with a backdrop
VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr); // Draws a box around the area specified
VOID TuiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr); // Draws text at coordinates specified
VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PUCHAR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges
VOID TuiDrawStatusText(PUCHAR StatusText); // Draws text at the very bottom line on the screen
VOID TuiUpdateDateTime(VOID); // Updates the date and time
VOID TuiSaveScreen(PUCHAR Buffer); // Saves the screen so that it can be restored later
VOID TuiRestoreScreen(PUCHAR Buffer); // Restores the screen from a previous save
VOID TuiMessageBox(PUCHAR MessageText); // Displays a message box on the screen with an ok button
VOID TuiMessageBoxCritical(PUCHAR MessageText); // Displays a message box on the screen with an ok button using no system resources
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range); // Draws the progress bar showing nPos percent filled
VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range); // Draws the progress bar showing nPos percent filled
UCHAR TuiTextToColor(PUCHAR ColorText); // Converts the text color into it's equivalent color value
UCHAR TuiTextToFillStyle(PUCHAR FillStyleText); // Converts the text fill into it's equivalent fill value
///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct
{
PUCHAR *MenuItemList;
ULONG MenuItemCount;
LONG MenuTimeRemaining;
ULONG SelectedMenuItem;
ULONG Left;
ULONG Top;
ULONG Right;
ULONG Bottom;
} TUI_MENU_INFO, *PTUI_MENU_INFO;
VOID TuiCalcMenuBoxSize(PTUI_MENU_INFO MenuInfo);
VOID TuiDrawMenu(PTUI_MENU_INFO MenuInfo);
VOID TuiDrawMenuBox(PTUI_MENU_INFO MenuInfo);
VOID TuiDrawMenuItem(PTUI_MENU_INFO MenuInfo, ULONG MenuItemNumber);
ULONG TuiProcessMenuKeyboardEvent(PTUI_MENU_INFO MenuInfo);
BOOL TuiDisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem);
/*
* Combines the foreground and background colors into a single attribute byte
*/
#define ATTR(cFore, cBack) ((cBack << 4)|cFore)
/*
* Fill styles for DrawBackdrop()
*/
#define LIGHT_FILL 0xB0
#define MEDIUM_FILL 0xB1
#define DARK_FILL 0xB2
/*
* Screen colors
*/
#define COLOR_BLACK 0
#define COLOR_BLUE 1
#define COLOR_GREEN 2
#define COLOR_CYAN 3
#define COLOR_RED 4
#define COLOR_MAGENTA 5
#define COLOR_BROWN 6
#define COLOR_GRAY 7
#define COLOR_DARKGRAY 8
#define COLOR_LIGHTBLUE 9
#define COLOR_LIGHTGREEN 10
#define COLOR_LIGHTCYAN 11
#define COLOR_LIGHTRED 12
#define COLOR_LIGHTMAGENTA 13
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
/* Add COLOR_BLINK to a background to cause blinking */
#define COLOR_BLINK 8
/*
* Defines for IBM box drawing characters
*/
#define HORZ (0xc4) /* Single horizontal line */
#define D_HORZ (0xcd) /* Double horizontal line.*/
#define VERT (0xb3) /* Single vertical line */
#define D_VERT (0xba) /* Double vertical line. */
/* Definitions for corners, depending on HORIZ and VERT */
#define UL (0xda)
#define UR (0xbf) /* HORZ and VERT */
#define LL (0xc0)
#define LR (0xd9)
#define D_UL (0xc9)
#define D_UR (0xbb) /* D_HORZ and D_VERT */
#define D_LL (0xc8)
#define D_LR (0xbc)
#define HD_UL (0xd5)
#define HD_UR (0xb8) /* D_HORZ and VERT */
#define HD_LL (0xd4)
#define HD_LR (0xbe)
#define VD_UL (0xd6)
#define VD_UR (0xb7) /* HORZ and D_VERT */
#define VD_LL (0xd3)
#define VD_LR (0xbd)
#endif // #defined __TUI_H

View File

@@ -1,353 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <rtl.h>
#include <ui.h>
#include "tui.h"
#include "keycodes.h"
#include <options.h>
#include <mm.h>
BOOL TuiDisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem)
{
TUI_MENU_INFO MenuInformation;
ULONG CurrentClockSecond;
//
// The first thing we need to check is the timeout
// If it's zero then don't bother with anything,
// just return the default item
//
if (MenuTimeOut == 0)
{
if (SelectedMenuItem != NULL)
{
*SelectedMenuItem = DefaultMenuItem;
}
return TRUE;
}
//
// Setup the MENU_INFO structure
//
MenuInformation.MenuItemList = MenuItemList;
MenuInformation.MenuItemCount = MenuItemCount;
MenuInformation.MenuTimeRemaining = MenuTimeOut;
MenuInformation.SelectedMenuItem = DefaultMenuItem;
//
// Calculate the size of the menu box
//
TuiCalcMenuBoxSize(&MenuInformation);
//
// Draw the menu
//
TuiDrawMenu(&MenuInformation);
//
// Get the current second of time
//
CurrentClockSecond = getsecond();
//
// Process keys
//
while (1)
{
//
// Process key presses
//
if (TuiProcessMenuKeyboardEvent(&MenuInformation) == KEY_ENTER)
{
//
// If they pressed enter then exit this loop
//
break;
}
//
// Update the date & time
//
UiUpdateDateTime();
if (MenuInformation.MenuTimeRemaining > 0)
{
if (getsecond() != CurrentClockSecond)
{
//
// Update the time information
//
CurrentClockSecond = getsecond();
MenuInformation.MenuTimeRemaining--;
//
// Update the menu
//
TuiDrawMenuBox(&MenuInformation);
}
}
else if (MenuInformation.MenuTimeRemaining == 0)
{
//
// A time out occurred, exit this loop and return default OS
//
break;
}
}
//
// Update the selected menu item information
//
if (SelectedMenuItem != NULL)
{
*SelectedMenuItem = MenuInformation.SelectedMenuItem;
}
return TRUE;
}
VOID TuiCalcMenuBoxSize(PTUI_MENU_INFO MenuInfo)
{
ULONG Idx;
ULONG Width;
ULONG Height;
ULONG Length;
//
// Height is the menu item count plus 2 (top border & bottom border)
//
Height = MenuInfo->MenuItemCount + 2;
Height -= 1; // Height is zero-based
//
// Find the length of the longest string in the menu
//
Width = 0;
for(Idx=0; Idx<MenuInfo->MenuItemCount; Idx++)
{
Length = strlen(MenuInfo->MenuItemList[Idx]);
if (Length > Width)
{
Width = Length;
}
}
//
// Allow room for left & right borders, plus 8 spaces on each side
//
Width += 18;
//
// Calculate the menu box area
//
MenuInfo->Left = (UiScreenWidth - Width) / 2;
MenuInfo->Right = (MenuInfo->Left) + Width;
MenuInfo->Top = (( (UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT) - Height) / 2 + 1) + (TUI_TITLE_BOX_CHAR_HEIGHT / 2);
MenuInfo->Bottom = (MenuInfo->Top) + Height;
}
VOID TuiDrawMenu(PTUI_MENU_INFO MenuInfo)
{
ULONG Idx;
//
// Draw the menu box
//
TuiDrawMenuBox(MenuInfo);
//
// Draw each line of the menu
//
for (Idx=0; Idx<MenuInfo->MenuItemCount; Idx++)
{
TuiDrawMenuItem(MenuInfo, Idx);
}
}
VOID TuiDrawMenuBox(PTUI_MENU_INFO MenuInfo)
{
UCHAR MenuLineText[80];
UCHAR TempString[80];
//
// Update the status bar
//
UiDrawStatusText("Use \x18\x19 to select, ENTER to boot.");
//
// Draw the menu box
//
UiDrawBox(MenuInfo->Left,
MenuInfo->Top,
MenuInfo->Right,
MenuInfo->Bottom,
D_VERT,
D_HORZ,
FALSE, // Filled
TRUE, // Shadow
ATTR(UiMenuFgColor, UiMenuBgColor));
//
// If there is a timeout draw the time remaining
//
if (MenuInfo->MenuTimeRemaining >= 0)
{
strcpy(MenuLineText, "[ Time Remaining: ");
itoa(MenuInfo->MenuTimeRemaining, TempString, 10);
strcat(MenuLineText, TempString);
strcat(MenuLineText, " ]");
UiDrawText(MenuInfo->Right - strlen(MenuLineText) - 1,
MenuInfo->Bottom,
MenuLineText,
ATTR(UiMenuFgColor, UiMenuBgColor));
}
}
VOID TuiDrawMenuItem(PTUI_MENU_INFO MenuInfo, ULONG MenuItemNumber)
{
ULONG Idx;
UCHAR MenuLineText[80];
ULONG SpaceTotal;
ULONG SpaceLeft;
ULONG SpaceRight;
//
// We will want the string centered so calculate
// how many spaces will be to the left and right
//
SpaceTotal = (MenuInfo->Right - MenuInfo->Left - 2) - strlen(MenuInfo->MenuItemList[MenuItemNumber]);
SpaceLeft = (SpaceTotal / 2) + 1;
SpaceRight = (SpaceTotal - SpaceLeft) + 1;
//
// Insert the spaces on the left
//
for (Idx=0; Idx<SpaceLeft; Idx++)
{
MenuLineText[Idx] = ' ';
}
MenuLineText[Idx] = '\0';
//
// Now append the text string
//
strcat(MenuLineText, MenuInfo->MenuItemList[MenuItemNumber]);
//
// Now append the spaces on the right
//
for (Idx=0; Idx<SpaceRight; Idx++)
{
strcat(MenuLineText, " ");
}
//
// If this is the selected menu item then draw it as selected
// otherwise just draw it using the normal colors
//
if (MenuItemNumber == MenuInfo->SelectedMenuItem)
{
UiDrawText(MenuInfo->Left + 1,
MenuInfo->Top + 1 + MenuItemNumber,
MenuLineText,
ATTR(UiSelectedTextColor, UiSelectedTextBgColor));
}
else
{
UiDrawText(MenuInfo->Left + 1,
MenuInfo->Top + 1 + MenuItemNumber,
MenuLineText,
ATTR(UiTextColor, UiMenuBgColor));
}
}
ULONG TuiProcessMenuKeyboardEvent(PTUI_MENU_INFO MenuInfo)
{
ULONG KeyEvent = 0;
//
// Check for a keypress
//
if (kbhit())
{
//
// Cancel the timeout
//
if (MenuInfo->MenuTimeRemaining != -1)
{
MenuInfo->MenuTimeRemaining = -1;
TuiDrawMenuBox(MenuInfo);
}
//
// Get the key
//
KeyEvent = getch();
//
// Is it extended?
//
if (KeyEvent == 0)
KeyEvent = getch(); // Yes - so get the extended key
//
// Process the key
//
switch (KeyEvent)
{
case KEY_UP:
if (MenuInfo->SelectedMenuItem > 0)
{
MenuInfo->SelectedMenuItem--;
//
// Update the menu
//
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem + 1); // Deselect previous item
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); // Select new item
}
break;
case KEY_DOWN:
if (MenuInfo->SelectedMenuItem < (MenuInfo->MenuItemCount - 1))
{
MenuInfo->SelectedMenuItem++;
//
// Update the menu
//
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem - 1); // Deselect previous item
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); // Select new item
}
break;
}
}
return KeyEvent;
}

View File

@@ -1,475 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <ui.h>
#include "tui.h"
#include <rtl.h>
#include <mm.h>
#include <debug.h>
#include <inifile.h>
#include <version.h>
#include <video.h>
#define DISPLAYMODE_TEXT 0
#define DISPLAYMODE_GRAPHICS 1
ULONG UiScreenWidth = 80; // Screen Width
ULONG UiScreenHeight = 25; // Screen Height
UCHAR UiStatusBarFgColor = COLOR_BLACK; // Status bar foreground color
UCHAR UiStatusBarBgColor = COLOR_CYAN; // Status bar background color
UCHAR UiBackdropFgColor = COLOR_WHITE; // Backdrop foreground color
UCHAR UiBackdropBgColor = COLOR_BLUE; // Backdrop background color
UCHAR UiBackdropFillStyle = MEDIUM_FILL; // Backdrop fill style
UCHAR UiTitleBoxFgColor = COLOR_WHITE; // Title box foreground color
UCHAR UiTitleBoxBgColor = COLOR_RED; // Title box background color
UCHAR UiMessageBoxFgColor = COLOR_WHITE; // Message box foreground color
UCHAR UiMessageBoxBgColor = COLOR_BLUE; // Message box background color
UCHAR UiMenuFgColor = COLOR_WHITE; // Menu foreground color
UCHAR UiMenuBgColor = COLOR_BLUE; // Menu background color
UCHAR UiTextColor = COLOR_YELLOW; // Normal text color
UCHAR UiSelectedTextColor = COLOR_BLACK; // Selected text color
UCHAR UiSelectedTextBgColor = COLOR_GRAY; // Selected text background color
UCHAR UiTitleBoxTitleText[260] = "Boot Menu"; // Title box's title text
PUCHAR UiMessageBoxLineText = NULL;
#define UIMESSAGEBOXLINETEXTSIZE 4096
BOOL UserInterfaceUp = FALSE; // Tells us if the user interface is displayed
BOOL UiDisplayMode = DISPLAYMODE_TEXT; // Tells us if we are in text or graphics mode
UCHAR UiMonthNames[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
BOOL UiInitialize(VOID)
{
ULONG SectionId;
UCHAR SettingText[260];
ULONG VideoMode = VIDEOMODE_NORMAL_TEXT;
DbgPrint((DPRINT_UI, "Initializing User Interface.\n"));
UiMessageBoxLineText = MmAllocateMemory(UIMESSAGEBOXLINETEXTSIZE);
if (UiMessageBoxLineText == NULL)
{
return FALSE;
}
RtlZeroMemory(UiMessageBoxLineText, UIMESSAGEBOXLINETEXTSIZE);
DbgPrint((DPRINT_UI, "Reading in UI settings from [Display] section.\n"));
if (IniOpenSection("Display", &SectionId))
{
if (IniReadSettingByName(SectionId, "DisplayMode", SettingText, 260))
{
if (BiosDetectVideoCard() == VIDEOCARD_CGA_OR_OTHER)
{
DbgPrint((DPRINT_UI, "CGA or other display adapter detected.\n"));
}
else if (BiosDetectVideoCard() == VIDEOCARD_EGA)
{
DbgPrint((DPRINT_UI, "EGA display adapter detected.\n"));
}
else if (BiosDetectVideoCard() == VIDEOCARD_VGA)
{
DbgPrint((DPRINT_UI, "VGA display adapter detected.\n"));
}
if (stricmp(SettingText, "NORMAL_VGA") == 0)
{
VideoMode = VIDEOMODE_NORMAL_TEXT;
}
else if (stricmp(SettingText, "EXTENDED_VGA") == 0)
{
VideoMode = VIDEOMODE_EXTENDED_TEXT;
}
else
{
VideoMode = atoi(SettingText);
}
if (!VideoSetMode(VideoMode))
{
printf("Error: unable to set video display mode 0x%lx\n", VideoMode);
printf("Press any key to continue.\n");
getch();
}
UiScreenWidth = VideoGetCurrentModeResolutionX();
UiScreenHeight = VideoGetCurrentModeResolutionY();
}
if (IniReadSettingByName(SectionId, "TitleText", SettingText, 260))
{
strcpy(UiTitleBoxTitleText, SettingText);
}
if (IniReadSettingByName(SectionId, "StatusBarColor", SettingText, 260))
{
UiStatusBarBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "StatusBarTextColor", SettingText, 260))
{
UiStatusBarFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropTextColor", SettingText, 260))
{
UiBackdropFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropColor", SettingText, 260))
{
UiBackdropBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropFillStyle", SettingText, 260))
{
UiBackdropFillStyle = UiTextToFillStyle(SettingText);
}
if (IniReadSettingByName(SectionId, "TitleBoxTextColor", SettingText, 260))
{
UiTitleBoxFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "TitleBoxColor", SettingText, 260))
{
UiTitleBoxBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MessageBoxTextColor", SettingText, 260))
{
UiMessageBoxFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MessageBoxColor", SettingText, 260))
{
UiMessageBoxBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MenuTextColor", SettingText, 260))
{
UiMenuFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MenuColor", SettingText, 260))
{
UiMenuBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "TextColor", SettingText, 260))
{
UiTextColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "SelectedTextColor", SettingText, 260))
{
UiSelectedTextColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "SelectedColor", SettingText, 260))
{
UiSelectedTextBgColor = UiTextToColor(SettingText);
}
}
VideoClearScreen();
VideoHideTextCursor();
// Draw the backdrop and title box
UiDrawBackdrop();
UserInterfaceUp = TRUE;
DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
return TRUE;
}
VOID UiDrawBackdrop(VOID)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawBackdrop();
}
else
{
UNIMPLEMENTED
//GuiDrawBackdrop();
}
}
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR FillChar, UCHAR Attr /* Color Attributes */)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
}
else
{
UNIMPLEMENTED
//GuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
}
}
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawShadow(Left, Top, Right, Bottom);
}
else
{
UNIMPLEMENTED
//GuiDrawShadow(Left, Top, Right, Bottom);
}
}
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
}
else
{
UNIMPLEMENTED
//GuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
}
}
VOID UiDrawText(ULONG X, ULONG Y, PUCHAR Text, UCHAR Attr)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawText(X, Y, Text, Attr);
}
else
{
UNIMPLEMENTED
//GuiDrawText(X, Y, Text, Attr);
}
}
VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PUCHAR TextString, UCHAR Attr)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
}
else
{
UNIMPLEMENTED
//GuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
}
}
VOID UiDrawStatusText(PUCHAR StatusText)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawStatusText(StatusText);
}
else
{
UNIMPLEMENTED
//GuiDrawStatusText(StatusText);
}
}
VOID UiUpdateDateTime(VOID)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiUpdateDateTime();
}
else
{
UNIMPLEMENTED
//TuiUpdateDateTime();
}
}
VOID UiMessageBox(PUCHAR MessageText)
{
strcat(UiMessageBoxLineText, MessageText);
// We have not yet displayed the user interface
// We are probably still reading the .ini file
// and have encountered an error. Just use printf()
// and return.
if (!UserInterfaceUp)
{
printf("%s\n", UiMessageBoxLineText);
printf("Press any key\n");
getch();
return;
}
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiMessageBox(UiMessageBoxLineText);
}
else
{
UNIMPLEMENTED
//GuiMessageBox(UiMessageBoxLineText);
}
RtlZeroMemory(UiMessageBoxLineText, UIMESSAGEBOXLINETEXTSIZE);
}
VOID UiMessageBoxCritical(PUCHAR MessageText)
{
// We have not yet displayed the user interface
// We are probably still reading the .ini file
// and have encountered an error. Just use printf()
// and return.
if (!UserInterfaceUp)
{
printf("%s\n", MessageText);
printf("Press any key\n");
getch();
return;
}
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiMessageBoxCritical(MessageText);
}
else
{
UNIMPLEMENTED
//GuiMessageBoxCritical(MessageText);
}
}
VOID UiMessageLine(PUCHAR MessageText)
{
strcat(UiMessageBoxLineText, MessageText);
strcat(UiMessageBoxLineText, "\n");
}
UCHAR UiTextToColor(PUCHAR ColorText)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
return TuiTextToColor(ColorText);
}
else
{
UNIMPLEMENTED
return 0;
//return GuiTextToColor(ColorText);
}
}
UCHAR UiTextToFillStyle(PUCHAR FillStyleText)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
return TuiTextToFillStyle(FillStyleText);
}
else
{
UNIMPLEMENTED
return 0;
//return GuiTextToFillStyle(FillStyleText);
}
}
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawProgressBarCenter(Position, Range);
}
else
{
UNIMPLEMENTED
//GuiDrawProgressBarCenter(Position, Range);
}
}
VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
TuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range);
}
else
{
UNIMPLEMENTED
//GuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range);
}
}
VOID UiShowMessageBoxesInSection(PUCHAR SectionName)
{
ULONG Idx;
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
//
// Zero out message line text
//
strcpy(UiMessageBoxLineText, "");
if (!IniOpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section %s not found in freeldr.ini.\n", SectionName);
UiMessageBox(SettingName);
return;
}
//
// Find all the message box settings and run them
//
for (Idx=0; Idx<IniGetNumSectionItems(SectionId); Idx++)
{
IniReadSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
if (stricmp(SettingName, "MessageBox") == 0)
{
UiMessageBox(SettingValue);
}
else if (stricmp(SettingName, "MessageLine") == 0)
{
UiMessageLine(SettingValue);
}
}
//
// Zero out message line text
//
strcpy(UiMessageBoxLineText, "");
}
VOID UiTruncateStringEllipsis(PUCHAR StringText, ULONG MaxChars)
{
UNIMPLEMENTED
}
BOOL UiDisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem)
{
if (UiDisplayMode == DISPLAYMODE_TEXT)
{
return TuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem);
}
else
{
UNIMPLEMENTED
return FALSE;
//return GuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem);
}
}

View File

@@ -1,38 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <version.h>
#include <rtl.h>
UCHAR FreeLoaderVersionString[80];
PUCHAR GetFreeLoaderVersionString(VOID)
{
if (FREELOADER_PATCH_VERSION == 0)
{
sprintf(FreeLoaderVersionString, "FreeLoader v%d.%d", FREELOADER_MAJOR_VERSION, FREELOADER_MINOR_VERSION);
}
else
{
sprintf(FreeLoaderVersionString, "FreeLoader v%d.%d.%d", FREELOADER_MAJOR_VERSION, FREELOADER_MINOR_VERSION, FREELOADER_PATCH_VERSION);
}
return FreeLoaderVersionString;
}

View File

@@ -1,57 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <video.h>
#include <comm.h>
VOID VideoClearScreen(VOID)
{
VideoSetMode(VideoGetCurrentMode());
}
VOID VideoWaitForVerticalRetrace(VOID)
{
while ((READ_PORT_UCHAR((PUCHAR)VIDEOPORT_VERTICAL_RETRACE) & 0x08))
{
// Keep reading the port until bit 4 is clear
}
while (!(READ_PORT_UCHAR((PUCHAR)VIDEOPORT_VERTICAL_RETRACE) & 0x08))
{
// Keep reading the port until bit 4 is set
}
}
VOID VideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
{
WRITE_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_WRITE, Color);
WRITE_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA, Red);
WRITE_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA, Green);
WRITE_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA, Blue);
}
VOID VideoGetPaletteColor(UCHAR Color, PUCHAR Red, PUCHAR Green, PUCHAR Blue)
{
WRITE_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_READ, Color);
*Red = READ_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA);
*Green = READ_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA);
*Blue = READ_PORT_UCHAR((PUCHAR)VIDEOPORT_PALETTE_DATA);
}

View File

@@ -1,179 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <video.h>
ULONG CurrentVideoMode = VIDEOMODE_NORMAL_TEXT;
ULONG VideoResolutionX = 80;
ULONG VideoResolutionY = 25;
BOOL VideoSetMode(ULONG VideoMode)
{
switch (VideoMode)
{
case VIDEOMODE_NORMAL_TEXT:
CurrentVideoMode = VideoMode;
return VideoSetMode80x25();
case VIDEOMODE_EXTENDED_TEXT:
CurrentVideoMode = VideoMode;
return VideoSetMode80x50_80x43();
case VIDEOMODE_80X28:
CurrentVideoMode = VideoMode;
return VideoSetMode80x28();
case VIDEOMODE_80X30:
CurrentVideoMode = VideoMode;
return VideoSetMode80x30();
case VIDEOMODE_80X34:
CurrentVideoMode = VideoMode;
return VideoSetMode80x34();
case VIDEOMODE_80X43:
CurrentVideoMode = VideoMode;
return VideoSetMode80x43();
case VIDEOMODE_80X60:
CurrentVideoMode = VideoMode;
return VideoSetMode80x60();
default:
return FALSE;
}
return TRUE;
}
BOOL VideoSetMode80x25(VOID)
{
BiosSetVideoMode(0x03);
VideoResolutionX = 80;
VideoResolutionY = 25;
return TRUE;
}
BOOL VideoSetMode80x50_80x43(VOID)
{
if (BiosDetectVideoCard() == VIDEOCARD_VGA)
{
BiosSetVideoMode(0x03);
BiosSetVideoFont8x8();
BiosSelectAlternatePrintScreen();
BiosDisableCursorEmulation();
BiosDefineCursor(6, 7);
VideoResolutionX = 80;
VideoResolutionY = 50;
}
else if (BiosDetectVideoCard() == VIDEOCARD_EGA)
{
BiosSetVideoMode(0x03);
BiosSetVideoFont8x8();
BiosSelectAlternatePrintScreen();
BiosDisableCursorEmulation();
BiosDefineCursor(6, 7);
VideoResolutionX = 80;
VideoResolutionY = 43;
}
else // VIDEOCARD_CGA_OR_OTHER
{
return FALSE;
}
return TRUE;
}
BOOL VideoSetMode80x28(VOID)
{
// FIXME: Is this VGA-only?
VideoSetMode80x25();
BiosSetVideoFont8x14();
BiosDefineCursor(11, 12);
VideoResolutionX = 80;
VideoResolutionY = 28;
return TRUE;
}
BOOL VideoSetMode80x43(VOID)
{
// FIXME: Is this VGA-only?
BiosSet350ScanLines();
VideoSetMode80x25();
BiosSetVideoFont8x8();
BiosSelectAlternatePrintScreen();
BiosDisableCursorEmulation();
BiosDefineCursor(6, 7);
VideoResolutionX = 80;
VideoResolutionY = 43;
return TRUE;
}
BOOL VideoSetMode80x30(VOID)
{
// FIXME: Is this VGA-only?
VideoSetMode80x25();
BiosSet480ScanLines();
VideoResolutionX = 80;
VideoResolutionY = 30;
return TRUE;
}
BOOL VideoSetMode80x34(VOID)
{
// FIXME: Is this VGA-only?
VideoSetMode80x25();
BiosSet480ScanLines();
BiosSetVideoFont8x14();
BiosDefineCursor(11, 12);
BiosSetVideoDisplayEnd();
VideoResolutionX = 80;
VideoResolutionY = 34;
return TRUE;
}
BOOL VideoSetMode80x60(VOID)
{
// FIXME: Is this VGA-only?
VideoSetMode80x25();
BiosSet480ScanLines();
BiosSetVideoFont8x8();
BiosSelectAlternatePrintScreen();
BiosDisableCursorEmulation();
BiosDefineCursor(6, 7);
BiosSetVideoDisplayEnd();
VideoResolutionX = 80;
VideoResolutionY = 60;
return TRUE;
}
ULONG VideoGetCurrentModeResolutionX(VOID)
{
return VideoResolutionX;
}
ULONG VideoGetCurrentModeResolutionY(VOID)
{
return VideoResolutionY;
}
ULONG VideoGetCurrentMode(VOID)
{
return CurrentVideoMode;
}

View File

@@ -1,53 +0,0 @@
#
# FreeLoader
# Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
CC = gcc
LD = ld
RM = cmd /C del
FLAGS = -Wall
OBJS = install.o volume.o
LIBS = -lkernel32
.PHONY : clean
all: ../bootsect/fat.h ../bootsect/fat32.h install.exe
../bootsect/fat.h ../bootsect/fat32.h :
@$(MAKE) --no-print-directory -C ../bootsect
install.exe: $(OBJS)
@echo ===================================================== LINKING install
$(CC) $(FLAGS) -o install.exe $(OBJS)
install.o: install.c install.h volume.h
@echo ===================================================== Compiling $*
$(CC) $(FLAGS) -o install.o -c install.c
volume.o: volume.c volume.h install.h
@echo ===================================================== Compiling $*
$(CC) $(FLAGS) -o volume.o -c volume.c
clean:
@-$(RM) *.o
@-$(RM) *.exe
@echo Clean ALL done.

View File

@@ -1,189 +0,0 @@
/*
* FreeLoader - install.c
*
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "install.h"
#include "volume.h"
#include "../bootsect/fat.h"
#include "../bootsect/fat32.h"
BOOL BackupBootSector(LPCTSTR lpszVolumeName);
BOOL InstallBootSector(LPCTSTR lpszVolumeType);
int main(int argc, char *argv[])
{
if (argc < 3)
{
_tprintf(_T("syntax: install x: [fs_type]\nwhere fs_type is fat or fat32\n"));
return -1;
}
if (!OpenVolume(argv[1]))
{
return -1;
}
BackupBootSector(argv[1]);
InstallBootSector(argv[2]);
_tprintf(_T("You must now copy freeldr.sys & freeldr.ini to %s.\n"), argv[1]);
CloseVolume();
return 0;
}
BOOL BackupBootSector(LPCTSTR lpszVolumeName)
{
HANDLE hBackupFile;
TCHAR szFileName[MAX_PATH];
ULONG Count;
BYTE BootSectorBuffer[512];
DWORD dwNumberOfBytesWritten;
BOOL bRetVal;
//
// Find the next unused filename and open it
//
for (Count=0; ; Count++)
{
//
// Generate the next filename
//
_stprintf(szFileName, _T("%s\\bootsect.%03d"), lpszVolumeName, Count);
//
// Try to create a new file, fail if exists
//
hBackupFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, /*FILE_ATTRIBUTE_SYSTEM*/0, NULL);
//
// Check to see if it worked
//
if (hBackupFile != INVALID_HANDLE_VALUE)
{
break;
}
//
// Nope, didn't work
// Check to see if it already existed
//
if (!(GetLastError() != ERROR_ALREADY_EXISTS))
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("Boot sector backup failed. Error code %d.\n"), GetLastError());
return FALSE;
}
}
//
// Try to read the boot sector
//
if (!ReadVolumeSector(0, BootSectorBuffer))
{
CloseHandle(hBackupFile);
return FALSE;
}
//
// Try to write the boot sector data to the file
//
bRetVal = WriteFile(hBackupFile, BootSectorBuffer, 512, &dwNumberOfBytesWritten, NULL);
if (!bRetVal || (dwNumberOfBytesWritten != 512))
{
CloseHandle(hBackupFile);
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("WriteFile() failed. Error code %d.\n"), GetLastError());
return FALSE;
}
_tprintf(_T("Boot sector backed up to file: %s\n"), szFileName);
CloseHandle(hBackupFile);
return TRUE;
}
BOOL InstallBootSector(LPCTSTR lpszVolumeType)
{
BYTE BootSectorBuffer[512];
//
// Read in the old boot sector
//
if (!ReadVolumeSector(0, BootSectorBuffer))
{
return FALSE;
}
if (_tcsicmp(lpszVolumeType, _T("fat")) == 0)
{
//
// Update the BPB in the new boot sector
//
memcpy((fat_data+3), (BootSectorBuffer+3), 59 /*fat BPB length*/);
//
// Write out new boot sector
//
if (!WriteVolumeSector(0, fat_data))
{
return FALSE;
}
}
else if (_tcsicmp(lpszVolumeType, _T("fat32")) == 0)
{
//
// Update the BPB in the new boot sector
//
memcpy((fat32_data+3), (BootSectorBuffer+3), 87 /*fat32 BPB length*/);
//
// Write out new boot sector
//
if (!WriteVolumeSector(0, fat32_data))
{
return FALSE;
}
//
// Write out new extra sector
//
if (!WriteVolumeSector(14, (fat_data+512) ))
{
return FALSE;
}
}
else
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("File system type %s unknown.\n"), lpszVolumeType);
return FALSE;
}
_tprintf(_T("%s boot sector installed.\n"), lpszVolumeType);
return TRUE;
}

View File

@@ -1,24 +0,0 @@
/*
* FreeLoader - install.h
*
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __INSTALL_H
#define __INSTALL_H
#endif // defined __INSTALL_H

View File

@@ -1,135 +0,0 @@
/*
* FreeLoader - volume.c
*
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "volume.h"
static HANDLE hDiskVolume = NULL;
BOOL OpenVolume(LPCTSTR lpszVolumeName)
{
TCHAR RealVolumeName[MAX_PATH];
//
// If they passed in a drive letter (e.g. "A:")
// then try to open the physical device volume,
// otherwise we will assume it is a disk image
// file they are writing to. (not fully supported yet)
//
if ((_tcslen(lpszVolumeName) == 2) && (lpszVolumeName[1] == _T(':')))
{
_tcscpy(RealVolumeName, _T("\\\\.\\"));
_tcscat(RealVolumeName, lpszVolumeName);
}
else
{
_tcscpy(RealVolumeName, lpszVolumeName);
}
_tprintf(_T("Opening volume \'%s\'\n"), lpszVolumeName);
hDiskVolume = CreateFile(RealVolumeName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hDiskVolume == INVALID_HANDLE_VALUE)
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("Failed. Error code %d.\n"), GetLastError());
return FALSE;
}
return TRUE;
}
void CloseVolume(void)
{
CloseHandle(hDiskVolume);
}
BOOL ReadVolumeSector(ULONG SectorNumber, PVOID SectorBuffer)
{
DWORD dwNumberOfBytesRead;
DWORD dwFilePosition;
BOOL bRetVal;
//
// FIXME: this doesn't seem to handle the situation
// properly when SectorNumber is bigger than the
// amount of sectors on the disk. Seems to me that
// the call to SetFilePointer() should just give an
// out of bounds error or something but it doesn't.
//
dwFilePosition = SetFilePointer(hDiskVolume, (SectorNumber * 512), NULL, FILE_BEGIN);
if (dwFilePosition != (SectorNumber * 512))
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("SetFilePointer() failed. Error code %d.\n"), GetLastError());
return FALSE;
}
bRetVal = ReadFile(hDiskVolume, SectorBuffer, 512, &dwNumberOfBytesRead, NULL);
if (!bRetVal || (dwNumberOfBytesRead != 512))
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("ReadFile() failed. Error code %d.\n"), GetLastError());
return FALSE;
}
return TRUE;
}
BOOL WriteVolumeSector(ULONG SectorNumber, PVOID SectorBuffer)
{
DWORD dwNumberOfBytesWritten;
DWORD dwFilePosition;
BOOL bRetVal;
//
// FIXME: this doesn't seem to handle the situation
// properly when SectorNumber is bigger than the
// amount of sectors on the disk. Seems to me that
// the call to SetFilePointer() should just give an
// out of bounds error or something but it doesn't.
//
dwFilePosition = SetFilePointer(hDiskVolume, (SectorNumber * 512), NULL, FILE_BEGIN);
if (dwFilePosition != (SectorNumber * 512))
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("SetFilePointer() failed. Error code %d.\n"), GetLastError());
return FALSE;
}
bRetVal = WriteFile(hDiskVolume, SectorBuffer, 512, &dwNumberOfBytesWritten, NULL);
if (!bRetVal || (dwNumberOfBytesWritten != 512))
{
_tprintf(_T("%s:%d: "), __FILE__, __LINE__);
_tprintf(_T("WriteFile() failed. Error code %d.\n"), GetLastError());
return FALSE;
}
return TRUE;
}

View File

@@ -1,29 +0,0 @@
/*
* FreeLoader - volume.h
*
* Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __VOLUME_H
#define __VOLUME_H
BOOL OpenVolume(LPCTSTR lpszVolumeName);
void CloseVolume(void);
BOOL ReadVolumeSector(ULONG SectorNumber, PVOID SectorBuffer);
BOOL WriteVolumeSector(ULONG SectorNumber, PVOID SectorBuffer);
#endif // defined __VOLUME_H

View File

@@ -1,50 +0,0 @@
FreeLoader notes
To build FreeLoader you will need DJGPP because Mingw32 doesn't support 16-bit code
ext2 filesystem support needs to be added.
The MessageBox() function needs to not allocate memory. Because it gets called when memory allocation fails.
Memory layout:
0000:0000 - 0000:0FFF: Interrupt vector table & BIOS data
0000:1000 - 0000:6FFF: Real mode stack area
0000:7000 - 0000:7FFF: Unused
0000:8000 - xxxx:xxxx: FreeLoader program & data area
xxxx:xxxx - 7000:7FFF: Random memory allocation heap
7000:8000 - 7000:FFFF: Protected mode stack area
8000:0000 - 8000:FFFF: File system read buffer
9000:0000 - 9000:FFFF: Disk read buffer for BIOS Int 13h
A000:0000 - FFFF:FFFF: reserved
FreeLoader Boot Process
FAT 12/16/32 Boot Sector
The BIOS loads the boot sector at 0000:7C00. The FAT32 boot sector
relocates itself higher in memory at 9000:0000 and loads it's extra sector
at 9000:0200 and then looks for freeldr.sys on the file system. Once found
it loads freeldr.sys to 0000:7E00 and then jumps to it's entry point at
0000:8000. The FAT12/16 boot sector does no relocation, it just searches for
the freeldr.sys and loads the first 512 bytes to 0000:7E00. This extra code
enables it to fully navigate the file allocation table. Then it loads
freeldr.sys to 0000:7E00 and jumps to it's entry point at 0000:8000. Before
FreeLoader gets control the boot sector saves the screen contents to a buffer
at 9000:8000 and the cursor x & y position to bytes at 9000:8FA0 & 9000:8FA1
respectively.
ISO-9660 (CD-ROM) Boot Sector
The BIOS loads the boot sector (2048 bytes) at 0000:7C00. First, the
boot sector relocates itself to 0000:7000 (up to 0000:7800). Then it looks
for the I386 directory and makes it the current directory. Next it looks for
FREELDR.SYS and loads it at 0000:8000. Finally it restores the boot drive
number in the DL register and jumps to FreeLoader's entry point at 0000:8000.
FreeLoader Initialization
When FreeLoader gets control it saves the boot drive, passed to it in
the DL register, and sets up the stack, enables protected mode, and calls
BootMain().

View File

@@ -1,85 +0,0 @@
/* Copyright (C) 2000 CW Sandmann (sandmann@clio.rice.edu) 1206 Braelinn, Sugar Land, TX 77479 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifdef GO32
#include <unistd.h>
#else
#include <io.h>
#endif
char view_only = 0;
const char *client_patch_code;
char buffer[20480];
unsigned long search_base = 0x4c800L;
int f;
char oldpatch[] = {0x3b, 0x05, 0xac, 0xe6 };
char newpatch[] = {0x3b, 0x05, 0x58, 0x5e };
void patch_image(char *filename)
{
int i,size;
view_only = 0;
f = open(filename, O_RDWR | O_BINARY);
if (f < 0) {
f = open(filename, O_RDONLY | O_BINARY);
if (f < 0) {
perror(filename);
return;
}
view_only = 1;
}
lseek(f, search_base, SEEK_SET);
size = read(f, buffer, sizeof(buffer));
client_patch_code = NULL;
for(i=0; i<size && !client_patch_code; i++)
if(!memcmp(buffer+i,oldpatch,sizeof(oldpatch)))
client_patch_code = (buffer+i);
if(!client_patch_code) {
printf("Old patch string not found in %s!\n",filename);
} else {
lseek(f, search_base+i-1, SEEK_SET); /* Ready to update */
if(!view_only) {
write(f, newpatch, sizeof(newpatch));
printf("%s patched\n",filename);
} else
printf("%s patchable (not changed, readonly)\n",filename);
}
close(f);
return;
}
int main(int argc, char **argv)
{
int i;
char filename[256];
char buf1[256];
char file2[256];
if (argc != 1) { /* If they specify names, patch them, exit */
for(i=1; i<argc; i++)
patch_image(argv[i]);
return 0;
}
fprintf(stderr, "This image patches Windows 2000 NTVDM to fix nesting DPMI bug.\n");
strcpy(filename,getenv("SYSTEMROOT"));
strcpy(file2,filename);
strcat(filename,"\\system32\\ntvdm.exe");
strcat(file2,"\\system32\\dllcache\\ntvdm.exe");
sprintf(buf1,"copy %s %s\\system32\\ntvdm.ori",filename,getenv("SYSTEMROOT"));
printf("%s\n",buf1);
system(buf1);
patch_image(file2);
patch_image(filename);
return 0;
}

Binary file not shown.

View File

@@ -1,18 +0,0 @@
Perform at your own risk.
Directions for patching NTVDM on Windows 2000
1) Start a Command Prompt Window
2) Start Task Manager. Sort by Name. If NTVDM.EXE is a task End Process.
3) Execute NTVDMPAT.EXE from this ZIP file.
Notes:
With no arguments the executable patches both the DLLCACHE (for system file
protection) and the version in SYSTEM32. The image is a Win32 executable
(launching a DJGPP image will require NTVDM, locking the DLL so it can't
be patched). It saves the old version into NTVDM.ORI if you want to go
back. If you specify arguments on the command line it will patch the
executables you specify instead of automating the process (if you want to
do the archives/patches/moves yourself). Good luck.
Source included if you want to hack your own version.

View File

@@ -1,57 +0,0 @@
#
# FreeLoader
# Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#############################################
# PROGRAMS
#
CC = gcc
RM = rdel
#############################################
TOOLS = deptool \
bin2c \
hosttype \
rdel \
rcopy \
rmkdir \
rrmdir
#############################################
all : $(TOOLS)
@echo Tools are up to date.
% :: all
#############################################
%: %.c
@echo ===================================================== Compiling $*
@$(CC) -Wall -O3 -o $@ $<
#############################################
.PHONY : clean
clean:
@-$(RM) $(TOOLS)
@-$(RM) *.exe
@echo Clean ALL done.

Some files were not shown because too many files have changed in this diff Show More