Compare commits

...

1 Commits

Author SHA1 Message Date
The ReactOS Team
eeff2a1e2c This commit was manufactured by cvs2svn to create tag 'krnl0019'.
svn path=/tags/krnl0019/; revision=2645
2002-02-24 13:10:37 +00:00
791 changed files with 0 additions and 235338 deletions

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,158 +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) 2001 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=3<> Floppy (A:)
OS=Microsoft Windows (C:)
OS=Drive D:
DefaultOS=ReactOS (Floppy)
TimeOut=10
[Display]
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:)
# - does not work on large harddisks
[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="Linux"
# Linux boot type not implemented yet
#BootType=Partition
#BootDrive=0x80
#BootPartition=2
[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,44 +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.
#
export CC = gcc
export LD = ld
export AR = ar
export RM = cmd /C del
export CP = cmd /C copy
export NASM_CMD = nasm
export MAKE = make
.PHONY : bootsect freeldr install clean
all: bootsect freeldr install
bootsect:
$(MAKE) -C bootsect
freeldr: bootsect
$(MAKE) -C freeldr
install:
$(MAKE) -C install
clean:
$(RM) *.bin
$(MAKE) -C freeldr clean

View File

@@ -1,54 +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.
#
export CC = gcc
export LD = ld
export AR = ar
export RM = cmd /C del
export CP = cmd /C copy
export NASM_CMD = nasm
.PHONY : clean
all: fat.bin fat32.bin bin2c.exe split.exe stubit.exe
fat.bin: fat.asm bin2c.exe split.exe
$(NASM_CMD) -o fat_tmp.bin -f bin fat.asm
split fat_tmp.bin fat.bin fatstub.bin 512
$(RM) fat_tmp.bin
bin2c fat.bin fat.h fat_data
fat32.bin: fat32.asm bin2c.exe
$(NASM_CMD) -o fat32.bin -f bin fat32.asm
bin2c fat32.bin fat32.h fat32_data
bin2c.exe: bin2c.c
$(CC) -o bin2c.exe bin2c.c
split.exe: split.c
$(CC) -o split.exe split.c
stubit.exe: stubit.c
$(CC) -o stubit.exe stubit.c
clean:
$(RM) *.bin
$(RM) *.exe
$(RM) *.h

View File

@@ -1,48 +0,0 @@
#include <stdio.h>
FILE *in;
FILE *out;
int main(int argc, char *argv[])
{
unsigned char ch;
int cnt = 0;
if (argc < 4)
{
printf("usage: bin2c infile.bin outfile.h array_name\n");
return -1;
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
printf("Couldn't open data file.\n");
return -1;
}
if ((out = fopen(argv[2], "wb")) == NULL)
{
printf("Couldn't open output file.\n");
return -1;
}
fprintf(out, "unsigned char %s[] = {\n", argv[3]);
ch = fgetc(in);
while (!feof(in))
{
if (cnt != 0)
fprintf(out, ", ");
if (!(cnt % 16))
fprintf(out, "\n");
fprintf(out, "0x%02x", (int)ch);
cnt++;
ch = fgetc(in);
}
fprintf(out, "\n};");
fclose(in);
fclose(out);
return 0;
}

View File

@@ -1,499 +0,0 @@
; FAT.ASM
; FAT12/16 Boot Sector
; Copyright (c) 1998, 2001 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:7C00 so that the first
; DWORD pushed will be placed at 0000:7BFC
;
; When it locates freeldr.sys on the disk it will
; load the first sector of the file to 0000:7E00
; 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.
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:
cli
cld
xor ax,ax
mov ss,ax
mov bp,7c00h
mov sp,bp ; Setup a stack
mov ax,cs ; Setup segment registers
mov ds,ax ; Make DS correct
mov es,ax ; Make ES correct
sti ; Enable ints now
mov [BYTE bp+BootDrive],dl ; Save the boot drive
xor ax,ax ; Zero out AX
; Reset disk controller
int 13h
jnc Continue1
jmp BadBoot ; Reset failed...
Continue1:
; Now we must find our way to the first sector of the root directory
xor ax,ax
xor dx,dx
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,byte 0 ; Add carry bit
push ax ; Store it on the stack
push dx ; Save 32-bit logical start sector
push ax
push dx ; Save it for later use also
; 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 WORD [BYTE bp+MaxRootEntries] ; 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
xchg ax,cx ; Now CX has number of sectors
pop dx
pop ax ; Restore logical sector start
push cx ; Save number of root dir sectors for later use
mov bx,7c0h ; We will load the root directory
add bx,byte 20h ; Right after the boot sector in memory
mov es,bx
xor bx,bx ; We will load it to [0000:7e00h]
call ReadSectors ; Read the sectors
; Now we have to find our way through the root directory to
; The OSLOADER.SYS file
mov bx,[BYTE bp+MaxRootEntries]; Search entire root directory
mov ax,7e0h ; We loaded at 07e0: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 ErrBoot
FindFile:
mov ax,es ; We didn't find it in the previous dir entry
add ax,byte 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?
jmp ErrBoot
FoundFile:
; We found freeldr.sys on the disk
; so we need to load the first 512
; bytes of it to 0000:7E00
xor di,di ; ES:DI has dir entry
xor dx,dx
mov ax,WORD [es:di+1ah]; Get start cluster
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] ; Times sectors per cluster
mul cx
pop cx ; Get number of sectors for root dir
add ax,cx ; Add it to the start sector of freeldr.sys
adc dx,byte 0
pop cx ; Get logical start sector of
pop bx ; Root directory
add ax,bx ; Now we have DX:AX with the logical start
adc dx,cx ; Sector of OSLOADER.SYS
mov cx,1 ; We will load 1 sector
push WORD [es:di+1ah] ; Save start cluster
mov bx,7e0h
mov es,bx
xor bx,bx
call ReadSectors ; Load it
pop ax ; Restore start cluster
jmp LoadFile
; 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
ReadSectors:
push ax
push dx
push cx
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
pop cx
pop dx
pop ax
inc ax ;Increment Sector to Read
jnz NoCarry
inc dx
NoCarry:
push bx
mov bx,es
add bx,byte 20h
mov es,bx
pop bx
; Increment read buffer for next sector
loop ReadSectors ; Read next sector
ret
; 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 Reboot
; 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
msgDiskError db 'Disk error',0dh,0ah,0
msgFreeLdr db 'FREELDR.SYS not found',0dh,0ah,0
msgAnyKey db 'Press any key to restart',0dh,0ah,0
filename db 'FREELDR SYS'
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
; in the first 512 bytes of freeldr.sys
LoadFile:
push ax ; First save AX - the start cluster of freeldr.sys
; Display "Loading FreeLoader..." message
mov si,msgLoading ; Loading message
call PutChars ; Display it
pop ax ; Restore AX
; AX has start cluster of freeldr.sys
push ax
call ReadFatIntoMemory
pop ax
mov bx,7e0h
mov es,bx
LoadFile2:
push ax
call IsFat12
pop ax
jnc LoadFile3
cmp ax,0ff8h ; Check to see if this is the last cluster in the chain
jmp LoadFile4
LoadFile3:
cmp ax,0fff8h
LoadFile4:
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 ReadCluster
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 LoadFile5
call GetFatEntry12 ; Get the next entry
jmp LoadFile6
LoadFile5:
call GetFatEntry16
LoadFile6:
pop es
jmp LoadFile2 ; Load the next cluster (if any)
LoadFile_Done:
mov dl,BYTE [BYTE bp+BootDrive]
xor ax,ax
push ax
mov ax,8000h
push ax ; 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 ReadSectors
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:
xor dx,dx
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
; Reads cluster number in AX into [ES:0000]
ReadCluster:
; StartSector = ((Cluster - 2) * SectorsPerCluster) + + ReservedSectors + HiddenSectors;
dec ax
dec ax
xor dx,dx
movzx bx,BYTE [BYTE bp+SectsPerCluster]
mul bx
push ax
push dx
; Now calculate the size of the root directory
mov ax,0020h ; Size of dir entry
mul WORD [BYTE bp+MaxRootEntries] ; Times the number of entries
mov bx,WORD [BYTE bp+BytesPerSector]
add ax,bx
dec ax
div bx ; Divided by the size of a sector
mov cx,ax
; CX now has the number of root directory sectors
xor dx,dx
movzx ax,BYTE [BYTE bp+NumberOfFats]
mul WORD [BYTE bp+SectorsPerFat]
add ax,WORD [BYTE bp+ReservedSectors]
adc dx,byte 0
add ax,WORD [BYTE bp+HiddenSectors]
adc dx,WORD [BYTE bp+HiddenSectors+2]
add ax,cx
adc dx,byte 0
pop cx
pop bx
add ax,bx
adc dx,cx
xor bx,bx ; We will load it to [ES:0000], ES loaded before function call
movzx cx,BYTE [BYTE bp+SectsPerCluster]
call ReadSectors
ret
; Returns CF = 1 if this is a FAT12 file system
; Otherwise CF = 0 for FAT16
IsFat12:
; Now calculate the size of the root directory
mov ax,0020h ; Size of dir entry
mul WORD [BYTE bp+MaxRootEntries] ; Times the number of entries
mov bx,WORD [BYTE bp+BytesPerSector]
add ax,bx ; Plus (BytesPerSector - 1)
dec ax
div bx ; Divided by the size of a sector
; AX now has the number of root directory sectors
mov bx,ax
; Now we must find our way to the first sector of the root directory
xor ax,ax
xor dx,dx
mov al,BYTE [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,[BYTE bp+ReservedSectors] ; Add the number of reserved sectors
adc dx,byte 0 ; Add carry bit
add ax,bx
adc dx,byte 0 ; Add carry bit
; DX:AX now has the number of the starting sector of the data area
xor cx,cx
mov bx,WORD [BYTE bp+TotalSectors]
cmp bx,byte 0
jnz IsFat12_2
mov bx,WORD [BYTE bp+TotalSectorsBig]
mov cx,WORD [BYTE bp+TotalSectorsBig+2]
; CX:BX now contains the number of sectors on the volume
IsFat12_2:
sub bx,ax ; Subtract data area start sector
sub cx,dx ; from total sectors of volume
mov ax,bx
mov dx,cx
; 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
times 998-($-$$) db 0 ; Pad to 998 bytes
msgLoading db 'Loading FreeLoader...',0dh,0ah,0
dw 0aa55h ; BootSector signature

View File

@@ -1,487 +0,0 @@
; FAT32.ASM
; FAT32 Boot Sector
; Copyright (c) 1998, 2000, 2001 Brian Palmer
;org 7c00h
org 0
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:
cli
cld
; Lets copy ourselves from 0000:7c00 to 9000:0000
; and transfer control to the new code
xor ax,ax
mov ds,ax
mov si,7c00h
mov ax,9000h
mov es,ax
xor di,di
mov cx,512
rep movsb
jmp 0x9000:RealMain
; Now we are executing at 9000:xxxx
; We are now free to load freeldr.sys at 0000:7e00
RealMain:
xor ax,ax
mov bp,ax
mov sp,ax ; Setup a stack
mov ax,cs ; Setup segment registers
mov ds,ax ; Make DS correct
mov es,ax ; Make ES correct
mov ss,ax ; Make SS correct
sti ; Enable ints now
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 [9000:0200h]
mov eax,0eh
add eax,DWORD [BYTE bp+HiddenSectors] ; Add the number of hidden sectors
mov cx,1
mov bx,9000h
mov es,bx ; Read sector to [9000:0200h]
mov bx,0200h
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 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 eax ; Put 64-bit logical 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
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 PrintDiskError ; If the read failed then abort
add sp,0x10 ; Remove disk address packet from stack
popad ; Restore sector count & logical sector number
inc eax ; Increment sector to read
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]
; EAX has logical sector number to read
; CX has number of sectors to read
ReadSectorsCHS:
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 ReadSectorsCHS ; 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,7e0h
mov es,bx ; Read cluster to [0000:7e00h]
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,7e0h ; We loaded at 07e0: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
popad
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,7e0h
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:7e00h
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 ; We loaded at 0000:7e00 but the entry point is 0000:8000
push ax ; because the first 512 bytes is fat helper code
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
mov bx,7000h
mov es,bx
xor bx,bx ; We will load it to [7000:0000h]
mov cx,1
call ReadSectors
mov bx,7000h
mov es,bx
pop ecx
mov eax,DWORD [es:ecx] ; Get FAT entry
and eax,0fffffffh ; Mask off reserved bits
ret
; 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,55 +0,0 @@
#include <stdio.h>
FILE *in;
FILE *out;
FILE *new;
int main(int argc, char *argv[])
{
unsigned char ch;
int cnt;
int split_offset;
if (argc < 5)
{
printf("usage: split infile.bin outfile.bin newfile.bin split_offset\n");
return -1;
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
printf("Couldn't open data file.\n");
return -1;
}
if ((out = fopen(argv[2], "wb")) == NULL)
{
printf("Couldn't open output file.\n");
return -1;
}
if ((new = fopen(argv[3], "wb")) == NULL)
{
printf("Couldn't open new file.\n");
return -1;
}
split_offset = atoi(argv[4]);
for (cnt=0; cnt<split_offset; cnt++)
{
ch = fgetc(in);
fputc(ch, out);
}
ch = fgetc(in);
while (!feof(in))
{
fputc(ch, new);
ch = fgetc(in);
}
fclose(in);
fclose(out);
fclose(new);
return 0;
}

View File

@@ -1,52 +0,0 @@
#include <stdio.h>
FILE *in;
FILE *in2;
FILE *out;
int main(int argc, char *argv[])
{
unsigned char ch;
if (argc < 4)
{
printf("usage: stubit infile1.bin infile2.sys outfile.bin\n");
return -1;
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
printf("Couldn't open data file.\n");
return -1;
}
if ((in2 = fopen(argv[2], "rb")) == NULL)
{
printf("Couldn't open data file.\n");
return -1;
}
if ((out = fopen(argv[3], "wb")) == NULL)
{
printf("Couldn't open output file.\n");
return -1;
}
ch = fgetc(in);
while (!feof(in))
{
fputc(ch, out);
ch = fgetc(in);
}
ch = fgetc(in2);
while (!feof(in2))
{
fputc(ch, out);
ch = fgetc(in2);
}
fclose(in);
fclose(in2);
fclose(out);
return 0;
}

View File

@@ -1,464 +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.
;
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 0
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,7 +0,0 @@
cd bootsect
call make.bat
cd..
cd freeldr
make
copy freeldr.sys ..
cd ..

View File

@@ -1,117 +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 rules.mk
# asmcode.o has to be first in the link line because it contains the startup code
#OBJS = asmcode.a asmcode.o mb.o boot.o freeldr.o rtl.o fs.a fs.o fat.o \
# reactos.o tui.o menu.o miscboot.o options.o linux.o multiboot.o arcname.o \
# mem.o memory.o debug.o parseini.o registry.o import.o
#ASM_OBJS = asmcode.o mb.o boot.o mem.o
OBJS = freeldr.o miscboot.o options.o linux.o multiboot.o debug.o parseini.o oslist.o
LIBS = arch rtl fs ui reactos comm disk mm cache
LIB_FILES = arch/arch.a rtl/rtl.a fs/fs.a ui/ui.a reactos/reactos.a
LIB_FILES2 = comm/comm.a disk/disk.a mm/mm.a cache/cache.a
.PHONY : clean
all: freeldr.sys
freeldr.sys: c_code.a
$(LD) -N -Ttext=0x8000 --oformat=binary -s -o f.sys c_code.a
../bootsect/stubit ../bootsect/fatstub.bin f.sys freeldr.sys
freeldr.exe: asmcode.a c_code.a
$(LD) -o freeldr.exe asmcode.a c_code.a
c_code.a: $(LIBS) c_code1.a c_code2.a
$(LD) -r -o c_code.a $(LIB_FILES) c_code1.a c_code2.a
c_code1.a: $(LIBS)
$(LD) -r -o c_code1.a $(LIB_FILES2)
c_code2.a: $(OBJS)
$(LD) -r -o c_code2.a $(OBJS)
freeldr.o: freeldr.c freeldr.h rtl.h fs.h reactos.h ui.h arch.h miscboot.h
$(CC) $(FLAGS) -o freeldr.o -c freeldr.c
miscboot.o: miscboot.c freeldr.h arch.h rtl.h fs.h ui.h miscboot.h
$(CC) $(FLAGS) -o miscboot.o -c miscboot.c
options.o: options.c freeldr.h rtl.h ui.h options.h
$(CC) $(FLAGS) -o options.o -c options.c
linux.o: linux.c freeldr.h rtl.h ui.h linux.h
$(CC) $(FLAGS) -o linux.o -c linux.c
multiboot.o: multiboot.c freeldr.h rtl.h fs.h multiboot.h ui.h
$(CC) $(FLAGS) -o multiboot.o -c multiboot.c
debug.o: debug.c debug.h
$(CC) $(FLAGS) -o debug.o -c debug.c
parseini.o: parseini.c parseini.h
$(CC) $(FLAGS) -o parseini.o -c parseini.c
oslist.o: oslist.c oslist.h
$(CC) $(FLAGS) -o oslist.o -c oslist.c
arch:
$(MAKE) -C arch
rtl:
$(MAKE) -C rtl
fs:
$(MAKE) -C fs
ui:
$(MAKE) -C ui
reactos:
$(MAKE) -C reactos
comm:
$(MAKE) -C comm
disk:
$(MAKE) -C disk
mm:
$(MAKE) -C mm
cache:
$(MAKE) -C cache
.PHONY : $(LIBS)
clean:
- $(RM) *.o
- $(RM) *.a
- $(RM) *.sys
$(MAKE) -C arch clean
$(MAKE) -C reactos clean
$(MAKE) -C comm clean
$(MAKE) -C disk clean
$(MAKE) -C mm clean
$(MAKE) -C ui clean
$(MAKE) -C fs clean
$(MAKE) -C rtl clean
$(MAKE) -C cache clean

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.
*/
/* 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 0xA0000 /* The 32-bit stack top will be at 9000:FFFF, or 0x9FFFF */
#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 enable_a20(void);
void stop_floppy(void);
#endif /* ! ASM */

View File

@@ -1,33 +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 ../rules.mk
TARGET = i386
.PHONY : clean
all: arch.a
arch.a:
$(MAKE) -C $(TARGET)
clean:
- $(RM) *.a
$(MAKE) -C $(TARGET) clean

View File

@@ -1,50 +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 ../../rules.mk
OBJS = arch.o boot.o mb.o mem.o disk.o
.PHONY : clean
all: arch.a
arch.a: $(OBJS)
$(LD) -r -o arch.a $(OBJS)
- $(RM) ..\arch.a
$(CP) arch.a ..\arch.a
arch.o: arch.S
$(CC) $(FLAGS) -o arch.o -c arch.S
boot.o: boot.S
$(CC) $(FLAGS) -o boot.o -c boot.S
mb.o: mb.S
$(CC) $(FLAGS) -o mb.o -c mb.S
mem.o: mem.S
$(CC) $(FLAGS) -o mem.o -c mem.S
disk.o: disk.S
$(CC) $(FLAGS) -o disk.o -c disk.S
clean:
- $(RM) *.o
- $(RM) *.a

View File

@@ -1,898 +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(start)
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
/* 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)
sti /* These are ok now */
/* Now return in r-mode! */
ret
/*
* void putchar(int ch);
*/
EXTERN(_putchar)
.code32
push %eax
push %ebx
push %ebp
/* Get character to display */
movb 0x10(%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
pop %ebp
pop %ebx
pop %eax
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
pop %ebp
pop %ebx
pop %eax
ret
/*
* void clrscr(void);
*/
EXTERN(_clrscr)
.code32
push %eax
push %ebp
call switch_to_real
.code16
/* Int 0x10, AH = 0x0F - Get Current Video Mode */
movb $0x0f,%ah
int $0x10
/* Int 0x10, AH = 0x00 - Set Current Video Mode, also clears the screen */
movb $0x00,%ah
int $0x10
call switch_to_prot
.code32
pop %ebp
pop %eax
ret
/*
* int kbhit(void);
*/
EXTERN(_kbhit)
.code32
push %ebp
push %ebx
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,%ebx
jmp kbhit_done
kbhit_1:
/* Return value is zero if no key is available */
movl $0,%ebx
kbhit_done:
call switch_to_prot
.code32
/* Get return value from ebx */
movl %ebx,%eax
pop %ebx
pop %ebp
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
/*
* void gotoxy(int x, int y);
*/
EXTERN(_gotoxy)
.code32
push %ebp
push %eax
push %ebx
push %edx
/* Get cursor positions */
movb 0x14(%esp),%dl
movb 0x18(%esp),%dh
call switch_to_real
.code16
/* Update the cursor position */
movb $2,%ah
movb $0,%bh
int $0x10
call switch_to_prot
.code32
pop %edx
pop %ebx
pop %eax
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
/*
* void hidecursor(void);
*/
EXTERN(_hidecursor)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Hide the cursor */
movb $1,%ah
movw $0x2000,%cx
int $0x10
call switch_to_prot
.code32
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* void showcursor(void);
*/
EXTERN(_showcursor)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Show the cursor */
movb $1,%ah
movb $0x0d,%ch
movb $0x0e,%cl
int $0x10
call switch_to_prot
.code32
pop %edx
pop %ecx
pop %ebx
pop %ebp
ret
/*
* int wherex(void);
*/
EXTERN(_wherex)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the cursor position */
movb $3,%ah
movb $0,%bh
int $0x10
/* 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 wherey(void);
*/
EXTERN(_wherey)
.code32
push %ebp
push %ebx
push %ecx
push %edx
call switch_to_real
.code16
/* Get the cursor position */
movb $3,%ah
movb $0,%bh
int $0x10
/* Save return value */
movzbl %dh,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
pop %edx
pop %ecx
pop %ebx
pop %ebp
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)
*/
.code32
EXTERN(_enable_a20)
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
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 */
EXTERN(_BootDrive)
.long 0

View File

@@ -1,47 +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"
.code32
EXTERN(_JumpToBootCode)
call switch_to_real
.code16
/* Set the boot drive */
movb (_BootDrive),%dl
ljmpl $0x0000,$0x7C00
.code32
EXTERN(_JumpToLinuxBootCode)
call switch_to_real
.code16
/* Set the boot drive */
movb (_BootDrive),%dl
ljmpl $0x0200,$0x9000

View File

@@ -1,515 +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
push %ebp
push %esi
push %edi
push %ebx
push %ecx
push %edx
/* Get parameters */
movl 0x1c(%esp),%eax
movl %eax,_biosdisk_drive
movl 0x20(%esp),%eax
movl %eax,_biosdisk_head
movl 0x24(%esp),%eax
movl %eax,_biosdisk_track
movl 0x28(%esp),%eax
movl %eax,_biosdisk_sector
movl 0x2c(%esp),%eax
movl %eax,_biosdisk_nsects
movl 0x30(%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
movl _biosdisk_retval,%eax // Get return value
//movl $1,%eax
pop %edx
pop %ecx
pop %ebx
pop %edi
pop %esi
pop %ebp
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_segment:
.word 0
_packet_transfer_buffer_offset:
.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
push %ebp
push %esi
push %edi
push %ebx
push %ecx
push %edx
/* Get parameters */
movl 0x1c(%esp),%eax
movl %eax,_int13_extended_drive
movl 0x20(%esp),%eax
movl %eax,_packet_lba_sector_number
movl 0x24(%esp),%eax
movw %ax,_packet_sector_count
movl %eax,_int13_extended_sector_count
movl 0x28(%esp),%eax // Get buffer address in eax
shrl $4,%eax // Make linear address into segment
movw %ax,_packet_transfer_buffer_segment // Save segment
movl 0x28(%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 $42,%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
movb $1,%al // Set the return value to be one (will be set to zero later if needed)
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
movl _int13_extended_retval,%eax // Get return value
//movl $1,%eax
pop %edx
pop %ecx
pop %ebx
pop %edi
pop %esi
pop %ebp
ret
/*
* BOOL BiosInt13ExtensionsSupported(ULONG Drive);
*/
_int13_extension_check_drive:
.long 0
_int13_extension_check_retval:
.long 0
EXTERN(_BiosInt13ExtensionsSupported)
.code32
push %ebp
push %esi
push %edi
push %ebx
push %ecx
push %edx
/* Get parameters */
movl 0x1c(%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 $0x55aa,%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
movl _int13_extension_check_retval,%eax // Get return value
pop %edx
pop %ecx
pop %ebx
pop %edi
pop %esi
pop %ebp
ret
/*
* ULONG BiosInt13GetLastErrorCode(VOID);
*/
EXTERN(_BiosInt13GetLastErrorCode)
.code32
movzbl _biosdisk_error_code,%eax // Get return value
ret
/*
* void stop_floppy(void);
*
* Stops the floppy drive from spinning, so that other software is
* jumped to with a known state.
*/
EXTERN(_stop_floppy)
.code32
push %eax
push %edx
call switch_to_real
.code16
movw $0x3F2, %dx
xorb %al, %al
outb %al, %dx
call switch_to_prot
.code32
pop %edx
pop %eax
ret
/*
* int get_heads(int drive);
*/
EXTERN(_get_heads)
.code32
push %ebx
push %ecx
push %edx
push %edi
push %es
/* Get drive */
movl 0x18(%esp),%eax
movl %eax,_biosdisk_drive
call switch_to_real
.code16
movb $0x08,%ah
movb _biosdisk_drive,%dl
int $0x13
jc _get_heads_error
incb %dh
movzbl %dh,%edx
movl %edx,_biosdisk_retval
jmp _get_heads_done
_get_heads_error:
movl $0xff,_biosdisk_retval
_get_heads_done:
call switch_to_prot
.code32
movl _biosdisk_retval,%eax // Get return value
pop %es
pop %edi
pop %edx
pop %ecx
pop %ebx
ret
/*
* int get_cylinders(int drive);
*/
EXTERN(_get_cylinders)
.code32
push %ebx
push %ecx
push %edx
push %edi
push %es
/* Get drive */
movl 0x18(%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
movl _biosdisk_retval,%eax // Get return value
pop %es
pop %edi
pop %edx
pop %ecx
pop %ebx
ret
/*
* int get_sectors(int drive);
*/
EXTERN(_get_sectors)
.code32
push %ebx
push %ecx
push %edx
push %edi
push %es
/* Get drive */
movl 0x18(%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
movl _biosdisk_retval,%eax // Get return value
pop %es
pop %edi
pop %edx
pop %ecx
pop %ebx
ret

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,198 +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"
.code32
EXTERN(_GetExtendedMemorySize)
//
// get extended memory size in KB
//
pushl %edx
pushl %ecx
pushl %ebx
call switch_to_real
.code16
movw $0xe801,%ax
int $0x15
jc .oldstylemem
cmpw $0,%ax
je .cmem
movzwl %bx,%ebx
shll $6,%ebx
movzwl %ax,%eax
addl %ebx,%eax
jmp .done_mem
.cmem:
cmpw $0,%cx
je .oldstylemem
movzwl %dx,%edx
shll $6,%edx
movzwl %cx,%ecx
addl %ecx,%edx
movl %edx,%eax
jmp .done_mem
.oldstylemem:
// int 15h opt e801 don't work , try int 15h, option 88h
movb $0x88,%ah
int $0x15
cmp $0,%ax
je .cmosmem
movzwl %ax,%eax
jmp .done_mem
.cmosmem:
// int 15h opt 88h don't work , try read cmos
xorl %eax,%eax
movb $0x31,%al
outb %al,$0x70
inb $0x71,%al
andl $0xffff,%eax // clear carry
shll $8,%eax
.done_mem:
/* Save return value */
movl %eax,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
popl %ebx
popl %ecx
popl %edx
ret
.code32
EXTERN(_GetConventionalMemorySize)
//
// get conventional memory size in KB
//
pushl %edx
call switch_to_real
.code16
xorl %eax,%eax
int $0x12
/*xorl %eax,%eax
movb $0x30,%al
outb %al,$0x70
inb $0x71,%al
andl $0xffff,%eax*/ // clear carry
/* Save return value */
movl %eax,%edx
call switch_to_prot
.code32
/* Restore return value */
movl %edx,%eax
popl %edx
ret
.code32
_gbmm_mem_map_length:
.long 0
_gbmm_memory_map_addr:
.long 0
EXTERN(_GetBiosMemoryMap)
//
// Retrieve BIOS memory map if available
//
pushl %edx
pushl %ecx
pushl %ebx
pushl %edi
movl $0,_gbmm_mem_map_length
/* Get memory map address off stack */
movl 0x10(%esp),%eax
movl %eax,_gbmm_memory_map_addr
call switch_to_real
.code16
xorl %ebx,%ebx
movl _gbmm_memory_map_addr,%edi
.mmap_next:
movl $0x534D4150,%edx // 'SMAP'
movl $/*sizeof(memory_map_t)*/24,%ecx
movl 0xE820,%eax
int $0x15
jc .done_mmap
cmpl $0x534D4150,%eax // 'SMAP'
jne .done_mmap
addl $/*sizeof(memory_map_t)*/24,%edi
addl $/*sizeof(memory_map_t)*/24,_gbmm_mem_map_length
cmpl $0,%ebx
jne .mmap_next
.done_mmap:
call switch_to_prot
.code32
/* Get return value */
movl _gbmm_mem_map_length,%eax
popl %edi
popl %ebx
popl %ecx
popl %edx
ret

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,39 +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 ../rules.mk
OBJS = cache.o blocklist.o
.PHONY : clean
all: cache.a
cache.a: $(OBJS)
$(LD) -r -o cache.a $(OBJS)
cache.o: cache.c cm.h
$(CC) $(FLAGS) -o cache.o -c cache.c
blocklist.o: blocklist.c cm.h
$(CC) $(FLAGS) -o blocklist.o -c blocklist.c
clean:
- $(RM) *.o
- $(RM) *.a

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 = AllocateMemory(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 = AllocateMemory(CacheDrive->BlockSize * CacheDrive->DriveGeometry.BytesPerSector);
if (CacheBlock->BlockData ==NULL)
{
FreeMemory(CacheBlock);
return NULL;
}
// Now try to read in the block
if (!DiskReadMultipleLogicalSectors(CacheDrive->DriveNumber, (BlockNumber * CacheDrive->BlockSize), CacheDrive->BlockSize, (PVOID)DISKREADBUFFER))
{
FreeMemory(CacheBlock->BlockData);
FreeMemory(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
FreeMemory(CacheBlockToFree->BlockData);
FreeMemory(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);
FreeMemory(CacheManagerDrive.CacheBlockHead->BlockData);
FreeMemory(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,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,39 +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 ../rules.mk
OBJS = rs232.o portio.o
.PHONY : clean
all: comm.a
comm.a: $(OBJS)
$(LD) -r -o comm.a $(OBJS)
rs232.o: rs232.c ../comm.h
$(CC) $(FLAGS) -o rs232.o -c rs232.c
portio.o: portio.c ../comm.h
$(CC) $(FLAGS) -o portio.o -c portio.c
clean:
- $(RM) *.o
- $(RM) *.a

View File

@@ -1,183 +0,0 @@
/* $Id: portio.c,v 1.1 2001/11/28 10:26:52 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,235 +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
ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM |
DPRINT_UI | DPRINT_DISK | DPRINT_CACHE;
//ULONG DebugPrintMask = DPRINT_CACHE;
#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;
BOOL DebugStartOfLine = TRUE;
VOID DebugInit(VOID)
{
if (DebugPort == RS232)
{
Rs232PortInitialize(ComPort, BaudRate);
}
}
VOID DebugPrintChar(UCHAR Character)
{
if (Character == '\n')
{
DebugStartOfLine = TRUE;
}
if (DebugPort == RS232)
{
Rs232PortPutByte(Character);
if (Character == '\n')
{
Rs232PortPutByte('\r');
}
}
else if (DebugPort == BOCHS)
{
WRITE_PORT_UCHAR((PUCHAR)BOCHS_OUTPUT_PORT, Character);
}
else
{
putchar(Character);
}
}
VOID DebugPrintHeader(ULONG Mask)
{
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;
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();
}
}
#endif // defined DEBUG

View File

@@ -1,47 +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_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
VOID DebugInit(VOID);
VOID DebugPrint(ULONG Mask, char *format, ...);
#define DbgPrint(_x_) DebugPrint _x_
#define BugCheck(_x_) { DebugPrint(DPRINT_WARNING, "Fatal Error: %s:%d\n", __FILE__, __LINE__); DebugPrint _x_ ; for (;;); }
#else
#define DbgPrint(_x_)
#define BugCheck(_x_)
#endif // defined DEBUG
#endif // defined __DEBUG_H

View File

@@ -1,61 +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;
///////////////////////////////////////////////////////////////////////////////////////
//
// 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 stop_floppy(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
///////////////////////////////////////////////////////////////////////////////////////
//
// FreeLoader Disk Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID DiskError(PUCHAR ErrorString);
BOOL DiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry);
BOOL DiskSetDriveGeometry(ULONG DriveNumber, ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector);
BOOL DiskReadMultipleLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOL DiskReadLogicalSector(ULONG DriveNumber, ULONG SectorNumber, PVOID Buffer);
#endif // defined __DISK_H

View File

@@ -1,39 +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 ../rules.mk
OBJS = disk.o geometry.o
.PHONY : clean
all: disk.a
disk.a: $(OBJS)
$(LD) -r -o disk.a $(OBJS)
disk.o: disk.c ../disk.h
$(CC) $(FLAGS) -o disk.o -c disk.c
geometry.o: geometry.c ../disk.h
$(CC) $(FLAGS) -o geometry.o -c geometry.c
clean:
- $(RM) *.o
- $(RM) *.a

View File

@@ -1,226 +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%x", ErrorString, BiosInt13GetLastErrorCode());
DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString));
if (UserInterfaceUp)
{
MessageBox(ErrorCodeString);
}
else
{
printf("%s", ErrorCodeString);
printf("\nPress any key\n");
getch();
}
}
BOOL DiskReadMultipleLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{
ULONG PhysicalSector;
ULONG PhysicalHead;
ULONG PhysicalTrack;
GEOMETRY DriveGeometry;
ULONG NumberOfSectorsToRead;
DbgPrint((DPRINT_DISK, "ReadLogicalSector() DriveNumber: 0x%x SectorNumber: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, 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, 1, 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;
}
BOOL DiskReadLogicalSector(ULONG DriveNumber, ULONG SectorNumber, PVOID Buffer)
{
ULONG PhysicalSector;
ULONG PhysicalHead;
ULONG PhysicalTrack;
GEOMETRY DriveGeometry;
DbgPrint((DPRINT_DISK, "ReadLogicalSector() DriveNumber: 0x%x SectorNumber: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, 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, 1, Buffer))
{
DiskError("Disk read error.");
return FALSE;
}
}
else
{
//
// Get the drive geometry
//
if (!DiskGetDriveGeometry(DriveNumber, &DriveGeometry))
{
return FALSE;
}
//
// Calculate the physical disk offsets
//
PhysicalSector = 1 + (SectorNumber % DriveGeometry.Sectors);
PhysicalHead = (SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads;
PhysicalTrack = (SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads;
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));
//
// Make sure the read is within the geometry boundaries
//
if ((PhysicalHead >= DriveGeometry.Heads) ||
(PhysicalTrack >= DriveGeometry.Cylinders) ||
(PhysicalSector > DriveGeometry.Sectors))
{
DiskError("Disk read exceeds drive geometry limits.");
return FALSE;
}
//
// Perform the read
//
if (!BiosInt13Read(DriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, 1, Buffer))
{
DiskError("Disk read error.");
return FALSE;
}
}
return TRUE;
}

View File

@@ -1,126 +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>
typedef struct
{
LIST_ITEM ListEntry;
ULONG DriveNumber;
GEOMETRY DriveGeometry;
} DRIVE_GEOMETRY, *PDRIVE_GEOMETRY;
PDRIVE_GEOMETRY DriveGeometryListHead = NULL;
BOOL DiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry)
{
PDRIVE_GEOMETRY DriveGeometryListEntry;
//
// Search the drive geometry list for the requested drive
//
DriveGeometryListEntry = DriveGeometryListHead;
while (DriveGeometryListEntry != NULL)
{
//
// Check to see if this is the drive we want
//
if (DriveGeometryListEntry->DriveNumber == DriveNumber)
{
//
// Yep - return the information
//
RtlCopyMemory(DriveGeometry, &DriveGeometryListEntry->DriveGeometry, sizeof(GEOMETRY));
return TRUE;
}
//
// Nope, get next item
//
DriveGeometryListEntry = (PDRIVE_GEOMETRY)RtlListGetNext((PLIST_ITEM)DriveGeometryListEntry);
}
DiskError("Drive geometry unknown.");
return FALSE;
}
BOOL DiskSetDriveGeometry(ULONG DriveNumber, ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector)
{
PDRIVE_GEOMETRY DriveGeometryListEntry;
//
// Search the drive geometry list for the requested drive
//
DriveGeometryListEntry = DriveGeometryListHead;
while (DriveGeometryListEntry != NULL)
{
//
// Check to see if this is the drive
//
if (DriveGeometryListEntry->DriveNumber == DriveNumber)
{
//
// Yes, we already have this drive's geometry information
// so just return
//
return TRUE;
}
//
// Nope, get next item
//
DriveGeometryListEntry = (PDRIVE_GEOMETRY)RtlListGetNext((PLIST_ITEM)DriveGeometryListEntry);
}
//
// If we get here then this is a new drive and we have
// to add it's information to our list
//
DriveGeometryListEntry = (PDRIVE_GEOMETRY)AllocateMemory(sizeof(DRIVE_GEOMETRY));
if (DriveGeometryListEntry == NULL)
{
return FALSE;
}
RtlZeroMemory(DriveGeometryListEntry, sizeof(DRIVE_GEOMETRY));
DriveGeometryListEntry->DriveNumber = DriveNumber;
DriveGeometryListEntry->DriveGeometry.Cylinders = Cylinders;
DriveGeometryListEntry->DriveGeometry.Heads = Heads;
DriveGeometryListEntry->DriveGeometry.Sectors = Sectors;
DriveGeometryListEntry->DriveGeometry.BytesPerSector = BytesPerSector;
if (DriveGeometryListHead == NULL)
{
DriveGeometryListHead = DriveGeometryListEntry;
}
else
{
RtlListInsertTail((PLIST_ITEM)DriveGeometryListHead, (PLIST_ITEM)DriveGeometryListEntry);
}
return TRUE;
}

View File

@@ -1,205 +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 "parseini.h"
#include "debug.h"
#include "oslist.h"
#include "cache.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)
{
ULONG Idx;
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
ULONG OperatingSystemCount;
PUCHAR *OperatingSystemSectionNames;
PUCHAR *OperatingSystemDisplayNames;
ULONG DefaultOperatingSystem;
LONG TimeOut;
ULONG SelectedOperatingSystem;
enable_a20();
#ifdef DEBUG
DebugInit();
#endif
InitMemoryManager( (PVOID) 0x20000 /* BaseAddress */, 0x70000 /* Length */);
if (!ParseIniFile())
{
printf("Press any key to reboot.\n");
getch();
return;
}
if (!OpenSection("FreeLoader", &SectionId))
{
printf("Section [FreeLoader] not found in freeldr.ini.\n");
getch();
return;
}
if (!InitUserInterface())
{
printf("Press any key to reboot.\n");
getch();
return;
}
if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount))
{
MessageBox("Press ENTER to reboot.\n");
goto reboot;
}
if (OperatingSystemCount == 0)
{
MessageBox("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
//
ShowMessageBoxesInSection("FreeLoader");
for (;;)
{
// Show the operating system list menu
if (!DisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem))
{
MessageBox("Press ENTER to reboot.\n");
goto reboot;
}
// Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
MessageBox(SettingName);
continue;
}
// Try to read the boot type
if (!ReadSectionSettingByName(SectionId, "BootType", SettingValue, 80))
{
sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
MessageBox(SettingName);
continue;
}
if (stricmp(SettingValue, "ReactOS") == 0)
{
LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "Linux") == 0)
{
MessageBox("Cannot boot this OS type yet!");
}
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:
clrscr();
showcursor();
return;
}
ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount)
{
UCHAR DefaultOSText[80];
ULONG SectionId;
ULONG DefaultOS = 0;
ULONG Idx;
if (!OpenSection("FreeLoader", &SectionId))
{
return 0;
}
if (ReadSectionSettingByName(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 (!OpenSection("FreeLoader", &SectionId))
{
return -1;
}
if (ReadSectionSettingByName(SectionId, "TimeOut", TimeOutText, 20))
{
TimeOut = atoi(TimeOutText);
}
else
{
TimeOut = -1;
}
return TimeOut;
}

View File

@@ -1,77 +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
/* just some stuff */
#define VERSION "FreeLoader v0.9"
#define COPYRIGHT "Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>"
#define ROSLDR_MAJOR_VERSION 0
#define ROSLDR_MINOR_VERSION 8
#define ROSLDR_PATCH_VERSION 0
#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,98 +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 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;
//
// This macro will return the cylinder when you pass it a cylinder/sector
// pair where the high 2 bits of the cylinder are stored in the sector byte
//
#define MAKE_CYLINDER(cylinder, sector) ( cylinder + ((((WORD)sector) & 0xC0) << 2) )
//
// 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
#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);
#define EOF -1
#define FS_FAT 1
#define FS_NTFS 2
#define FS_EXT2 3
#endif // #defined __FS_H

View File

@@ -1,39 +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 ../rules.mk
OBJS = fs.o fat.o
.PHONY : clean
all: fs.a
fs.a: $(OBJS)
$(LD) -r -o fs.a $(OBJS)
fs.o: fs.c fat.h ../fs.h
$(CC) $(FLAGS) -o fs.o -c fs.c
fat.o: fat.c fat.h ../fs.h
$(CC) $(FLAGS) -o fat.o -c fat.c
clean:
- $(RM) *.o
- $(RM) *.a

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,30 +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 <fs.h>
#ifndef __FILESYS_H
#define __FILESYS_H
BOOL FsInternalIsDiskPartitioned(ULONG DriveNumber); // Returns TRUE if the disk contains partitions, FALSE if floppy disk
BOOL FsInternalGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); // Returns the active partition table entry
BOOL FsInternalGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); // Returns the active partition table entry
ULONG FsInternalGetPartitionCount(ULONG DriveNumber); // Returns the number of partitions on the disk
#endif // #defined __FILESYS_H

View File

@@ -1,384 +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 "filesys.h"
#include "fat.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));
if (UserInterfaceUp)
{
MessageBox(ErrorString);
}
else
{
printf("%s", ErrorString);
printf("\nPress any key\n");
getch();
}
}
/*
*
* 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)
{
MASTER_BOOT_RECORD DriveMasterBootRecord;
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 (FsInternalIsDiskPartitioned(DriveNumber) == FALSE)
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
FileSystemType = FS_FAT;
return FatOpenVolume(DriveNumber, 0);
}
//
// Read master boot record
//
if (!BiosInt13Read(DriveNumber, 0, 0, 1, 1, &DriveMasterBootRecord))
{
FileSystemError("Disk read error.");
return FALSE;
}
#ifdef DEBUG
DbgPrint((DPRINT_FILESYSTEM, "Drive is a hard disk, dumping partition table:\n"));
DbgPrint((DPRINT_FILESYSTEM, "sizeof(MASTER_BOOT_RECORD) = 0x%x.\n", sizeof(MASTER_BOOT_RECORD)));
for (BootPartition=0; BootPartition<4; BootPartition++)
{
DbgPrint((DPRINT_FILESYSTEM, "-------------------------------------------\n"));
DbgPrint((DPRINT_FILESYSTEM, "Partition %d\n", (BootPartition + 1)));
DbgPrint((DPRINT_FILESYSTEM, "BootIndicator: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].BootIndicator));
DbgPrint((DPRINT_FILESYSTEM, "StartHead: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].StartHead));
DbgPrint((DPRINT_FILESYSTEM, "StartSector (Plus 2 cylinder bits): 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].StartSector));
DbgPrint((DPRINT_FILESYSTEM, "StartCylinder: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].StartCylinder));
DbgPrint((DPRINT_FILESYSTEM, "SystemIndicator: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].SystemIndicator));
DbgPrint((DPRINT_FILESYSTEM, "EndHead: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].EndHead));
DbgPrint((DPRINT_FILESYSTEM, "EndSector (Plus 2 cylinder bits): 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].EndSector));
DbgPrint((DPRINT_FILESYSTEM, "EndCylinder: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].EndCylinder));
DbgPrint((DPRINT_FILESYSTEM, "SectorCountBeforePartition: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].SectorCountBeforePartition));
DbgPrint((DPRINT_FILESYSTEM, "PartitionSectorCount: 0x%x\n", DriveMasterBootRecord.PartitionTable[BootPartition].PartitionSectorCount));
}
#endif // defined DEBUG
// Check the partition table magic value
if (DriveMasterBootRecord.MasterBootRecordMagic != 0xaa55)
{
FileSystemError("Invalid partition table magic (0xaa55)");
return FALSE;
}
// Get the requested partition entry
if (PartitionNumber == 0)
{
// Partition requested was zero which means the boot partition
if (FsInternalGetActivePartitionEntry(DriveNumber, &PartitionTableEntry) == FALSE)
{
return FALSE;
}
}
else
{
// Get requested partition
if (FsInternalGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry) == FALSE)
{
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;
}
BOOL FsInternalIsDiskPartitioned(ULONG DriveNumber)
{
// Hard disks use drive numbers >= 0x80
// So if the drive number indicates a hard disk
// then return TRUE
if (DriveNumber >= 0x80)
{
return TRUE;
}
// Drive is a floppy diskette so return FALSE
return FALSE;
}
BOOL FsInternalGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
ULONG BootablePartitionCount = 0;
MASTER_BOOT_RECORD MasterBootRecord;
// Read master boot record
if (!BiosInt13Read(DriveNumber, 0, 0, 1, 1, &MasterBootRecord))
{
FileSystemError("Disk read error.");
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)
{
FileSystemError("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 FsInternalGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
MASTER_BOOT_RECORD MasterBootRecord;
// Read master boot record
if (!BiosInt13Read(DriveNumber, 0, 0, 1, 1, &MasterBootRecord))
{
FileSystemError("Disk read error.");
return FALSE;
}
// 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;
}
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
{
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);
default:
FileSystemError("Unknown file system.");
return FALSE;
}
return FALSE;
}
ULONG GetFileSize(PFILE FileHandle)
{
switch (FileSystemType)
{
case FS_FAT:
return FatGetFileSize(FileHandle);
default:
FileSystemError("Unknown file system.");
break;
}
return 0;
}
VOID SetFilePointer(PFILE FileHandle, ULONG NewFilePointer)
{
switch (FileSystemType)
{
case FS_FAT:
FatSetFilePointer(FileHandle, NewFilePointer);
break;
default:
FileSystemError("Unknown file system.");
break;
}
}
ULONG GetFilePointer(PFILE FileHandle)
{
switch (FileSystemType)
{
case FS_FAT:
return FatGetFilePointer(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,101 +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"
void LoadAndBootLinux(int DriveNum, int Partition, char *vmlinuz, char *cmd_line)
{
/*FILE file;
char temp[260];
char bootsector[512];
char setup[2048];
int len;
BootDrive = DriveNum;
BootPartition = Partition;
if (!OpenDiskDrive(BootDrive, BootPartition))
{
MessageBox("Failed to open boot drive.");
return;
}
if (!OpenFile(vmlinuz, &file))
{
strcpy(temp, vmlinuz);
strcat(temp, " not found.");
MessageBox(temp);
return;
}
// Read boot sector
if (ReadFile(&file, 512, bootsector) != 512)
{
MessageBox("Disk Read Error");
return;
}
MessageBox("bootsector loaded");
// Read setup code
if (ReadFile(&file, 2048, setup) != 2048)
{
MessageBox("Disk Read Error");
return;
}
MessageBox("setup loaded");
// Read kernel code
len = GetFileSize(&file) - (2048 + 512);
//len = 0x200;
if (ReadFile(&file, len, (void*)0x100000) != len)
{
MessageBox("Disk Read Error");
return;
}
MessageBox("kernel loaded");
// Check for validity
if (*((WORD*)(bootsector + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid boot sector magic (0xaa55)");
return;
}
if (*((DWORD*)(setup + 2)) != 0x53726448)
{
MessageBox("Invalid setup magic (\"HdrS\")");
return;
}
memcpy((void*)0x90000, bootsector, 512);
memcpy((void*)0x90200, setup, 2048);
RestoreScreen(ScreenBuffer);
showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy();
JumpToLinuxBootCode();*/
}

View File

@@ -1,27 +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
void JumpToLinuxBootCode(void); // Implemented in boot.S
void LoadAndBootLinux(int DriveNum, int Partition, char *vmlinuz, char *cmd_line);
#endif // defined __LINUX_H

View File

@@ -1,232 +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 "parseini.h"
#include "disk.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
ShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
MessageBox(SettingName);
return;
}
if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
MessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(SettingValue);
BootPartition = 0;
if (ReadSectionSettingByName(SectionId, "BootPartition", SettingValue, 80))
{
BootPartition = atoi(SettingValue);
}
if (!ReadSectionSettingByName(SectionId, "BootSectorFile", FileName, 260))
{
MessageBox("Boot sector file not specified for selected OS!");
return;
}
if (!OpenDiskDrive(BootDrive, BootPartition))
{
MessageBox("Failed to open boot drive.");
return;
}
FilePointer = OpenFile(FileName);
if (FilePointer == NULL)
{
strcat(FileName, " not found.");
MessageBox(FileName);
return;
}
// Read boot sector
if (!ReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
{
DiskError("Disk read error.");
return;
}
// Check for validity
if (*((WORD*)(0x7c00 + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid boot sector magic (0xaa55)");
return;
}
clrscr();
showcursor();
stop_floppy();
JumpToBootCode();
}
VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
{
char name[260];
char value[260];
int head, sector, cylinder;
int offset;
int i;
// Find all the message box settings and run them
/*for (i=1; i<=GetNumSectionItems(OSList[nOSToBoot].name); i++)
{
ReadSectionSettingByNumber(OSList[nOSToBoot].name, i, name, value);
if (stricmp(name, "MessageBox") == 0)
MessageBox(value);
if (stricmp(name, "MessageLine") == 0)
MessageLine(value);
}
if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootDrive", value))
{
MessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(value);
if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootPartition", value))
{
MessageBox("Boot partition not specified for selected OS!");
return;
}
BootPartition = atoi(value);
if (!BiosInt13Read(BootDrive, 0, 0, 1, 1, DISKREADBUFFER))
{
MessageBox("Disk Read Error");
return;
}
// Check for validity
if (*((WORD*)(DISKREADBUFFER + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid partition table magic (0xaa55)");
return;
}
offset = 0x1BE + ((BootPartition-1) * 0x10);
// Check for valid partition
if (SectorBuffer[offset + 4] == 0)
{
MessageBox("Invalid boot partition");
return;
}
head = SectorBuffer[offset + 1];
sector = (SectorBuffer[offset + 2] & 0x3F);
cylinder = SectorBuffer[offset + 3];
if (SectorBuffer[offset + 2] & 0x80)
cylinder += 0x200;
if (SectorBuffer[offset + 2] & 0x40)
cylinder += 0x100;
// 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);
showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy();
JumpToBootCode();*/
}
VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
{
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
// Find all the message box settings and run them
ShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
MessageBox(SettingName);
return;
}
if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
MessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = atoi(SettingValue);
if (!BiosInt13Read(BootDrive, 0, 0, 1, 1, (PVOID)0x7C00))
{
DiskError("Disk read error.");
return;
}
// Check for validity
if (*((WORD*)(0x7c00 + 0x1fe)) != 0xaa55)
{
MessageBox("Invalid boot sector magic (0xaa55)");
return;
}
clrscr();
showcursor();
stop_floppy();
JumpToBootCode();
}

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 JumpToBootCode(void); // Implemented in boot.S
VOID LoadAndBootBootSector(PUCHAR OperatingSystemName);
VOID LoadAndBootPartition(PUCHAR OperatingSystemName);
VOID LoadAndBootDrive(PUCHAR OperatingSystemName);
#endif // defined __BOOT_H

View File

@@ -1,55 +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
#include <multiboot.h>
VOID InitMemoryManager(PVOID BaseAddress, ULONG Length);
PVOID AllocateMemory(ULONG NumberOfBytes);
VOID FreeMemory(PVOID MemBlock);
ULONG GetSystemMemorySize(VOID); // Returns the amount of total usuable memory available to the memory manager
// These functions are implemented in mem.S
int GetExtendedMemorySize(void); // Returns extended memory size in KB
int GetConventionalMemorySize(void); // Returns conventional memory size in KB
int GetBiosMemoryMap(memory_map_t *mem_map); // Fills mem_map structure with BIOS memory map and returns length of memory map
//BOOL MmInitializeMemoryManager(ULONG LowMemoryStart, ULONG LowMemoryLength);
//PVOID MmAllocateMemory(ULONG MemorySize);
//VOID MmFreeMemory(PVOID MemoryPointer);
//PVOID MmAllocateLowMemory(ULONG MemorySize);
//VOID MmFreeLowMemory(PVOID MemoryPointer);
//PVOID MmAllocateMemoryFrom1Mb(ULONG MemorySize);
#endif // defined __MEMORY_H

View File

@@ -1,36 +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 ../rules.mk
OBJS = mm.o
.PHONY : clean
all: mm.a
mm.a: $(OBJS)
$(LD) -r -o mm.a $(OBJS)
mm.o: mm.c ../mm.h
$(CC) $(FLAGS) -o mm.o -c mm.c
clean:
- $(RM) *.o
- $(RM) *.a

View File

@@ -1,340 +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 <rtl.h>
#include <debug.h>
#include <ui.h>
//
// 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
#define MEM_BLOCK_SIZE 256
typedef struct
{
BOOL MemBlockAllocated; // Is this block allocated or free
ULONG BlocksAllocated; // Block length, in multiples of 256 bytes
} MEMBLOCK, *PMEMBLOCK;
PVOID HeapBaseAddress = NULL;
ULONG HeapLengthInBytes = 0;
ULONG HeapMemBlockCount = 0;
PMEMBLOCK HeapMemBlockArray = NULL;
#ifdef DEBUG
ULONG AllocationCount = 0;
VOID VerifyHeap(VOID);
VOID DumpMemoryAllocMap(VOID);
VOID IncrementAllocationCount(VOID);
VOID DecrementAllocationCount(VOID);
VOID MemAllocTest(VOID);
#endif // DEBUG
VOID InitMemoryManager(PVOID BaseAddress, ULONG Length)
{
ULONG MemBlocks;
// Calculate how many memory blocks we have
MemBlocks = (Length / MEM_BLOCK_SIZE);
// Adjust the heap length so we can reserve
// enough storage space for the MEMBLOCK array
Length -= (MemBlocks * sizeof(MEMBLOCK));
// Initialize our tracking variables
HeapBaseAddress = BaseAddress;
HeapLengthInBytes = Length;
HeapMemBlockCount = (HeapLengthInBytes / MEM_BLOCK_SIZE);
HeapMemBlockArray = (PMEMBLOCK)(HeapBaseAddress + HeapLengthInBytes);
// Clear the memory
RtlZeroMemory(HeapBaseAddress, HeapLengthInBytes);
RtlZeroMemory(HeapMemBlockArray, (HeapMemBlockCount * sizeof(MEMBLOCK)));
#ifdef DEBUG
DbgPrint((DPRINT_MEMORY, "Memory Manager initialized. BaseAddress = 0x%x Length = 0x%x. %d blocks in heap.\n", BaseAddress, Length, HeapMemBlockCount));
//MemAllocTest();
#endif
}
PVOID AllocateMemory(ULONG NumberOfBytes)
{
ULONG BlocksNeeded;
ULONG Idx;
ULONG NumFree;
PVOID MemPointer;
if (NumberOfBytes == 0)
{
DbgPrint((DPRINT_MEMORY, "AllocateMemory() called for 0 bytes. Returning NULL.\n"));
return NULL;
}
// Find out how many blocks it will take to
// satisfy this allocation
BlocksNeeded = ROUND_UP(NumberOfBytes, MEM_BLOCK_SIZE) / MEM_BLOCK_SIZE;
// Now loop through our array of blocks and
// see if we have enough space
for (Idx=0,NumFree=0; Idx<HeapMemBlockCount; Idx++)
{
// Check this block and see if it is already allocated
// If so reset our counter and continue the loop
if (HeapMemBlockArray[Idx].MemBlockAllocated)
{
NumFree = 0;
continue;
}
else
{
// It is free memory so lets increment our count
NumFree++;
}
// If we have found enough blocks to satisfy the request
// then we're done searching
if (NumFree >= BlocksNeeded)
{
break;
}
}
Idx++;
// If we don't have enough available mem
// then return NULL
if (NumFree < BlocksNeeded)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed. Not enough free memory to allocate %d bytes. AllocationCount: %d\n", NumberOfBytes, AllocationCount));
MessageBox("Memory allocation failed: out of memory.");
return NULL;
}
// Subtract the block count from Idx and we have
// the start block of the memory
Idx -= NumFree;
// Now we know which block to give them
MemPointer = HeapBaseAddress + (Idx * MEM_BLOCK_SIZE);
// Now loop through and mark all the blocks as allocated
for (NumFree=0; NumFree<BlocksNeeded; NumFree++)
{
HeapMemBlockArray[Idx + NumFree].MemBlockAllocated = TRUE;
HeapMemBlockArray[Idx + NumFree].BlocksAllocated = NumFree ? 0 : BlocksNeeded; // Mark only the first block with the count
}
#ifdef DEBUG
IncrementAllocationCount();
DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d blocks) of memory starting at block %d. AllocCount: %d\n", NumberOfBytes, BlocksNeeded, Idx, AllocationCount));
VerifyHeap();
#endif // DEBUG
// Now return the pointer
return MemPointer;
}
VOID FreeMemory(PVOID MemBlock)
{
ULONG BlockNumber;
ULONG BlockCount;
ULONG Idx;
#ifdef DEBUG
// Make sure we didn't get a bogus pointer
if ((MemBlock < HeapBaseAddress) || (MemBlock > (HeapBaseAddress + HeapLengthInBytes)))
{
BugCheck((DPRINT_MEMORY, "Bogus memory pointer (0x%x) passed to FreeMemory()\n", MemBlock));
}
#endif // DEBUG
// Find out the block number if the first
// block of memory they allocated
BlockNumber = (MemBlock - HeapBaseAddress) / MEM_BLOCK_SIZE;
BlockCount = HeapMemBlockArray[BlockNumber].BlocksAllocated;
#ifdef DEBUG
// Make sure we didn't get a bogus pointer
if ((BlockCount < 1) || (BlockCount > HeapMemBlockCount))
{
BugCheck((DPRINT_MEMORY, "Invalid block count in heap page header. HeapMemBlockArray[BlockNumber].BlocksAllocated = %d\n", HeapMemBlockArray[BlockNumber].BlocksAllocated));
}
#endif
// Loop through our array and mark all the
// blocks as free
for (Idx=BlockNumber; Idx<(BlockNumber + BlockCount); Idx++)
{
HeapMemBlockArray[Idx].MemBlockAllocated = FALSE;
HeapMemBlockArray[Idx].BlocksAllocated = 0;
}
#ifdef DEBUG
DecrementAllocationCount();
DbgPrint((DPRINT_MEMORY, "Freed %d blocks of memory starting at block %d. AllocationCount: %d\n", BlockCount, BlockNumber, AllocationCount));
VerifyHeap();
#endif // DEBUG
}
#ifdef DEBUG
VOID VerifyHeap(VOID)
{
ULONG Idx;
ULONG Idx2;
ULONG Count;
if (DUMP_MEM_MAP_ON_VERIFY)
{
DumpMemoryAllocMap();
}
// Loop through the array and verify that
// everything is kosher
for (Idx=0; Idx<HeapMemBlockCount; Idx++)
{
// Check if this block is allocation
if (HeapMemBlockArray[Idx].MemBlockAllocated)
{
// This is the first block in the run so it
// had better have a length that is within range
if ((HeapMemBlockArray[Idx].BlocksAllocated < 1) || (HeapMemBlockArray[Idx].BlocksAllocated > (HeapMemBlockCount - Idx)))
{
BugCheck((DPRINT_MEMORY, "Allocation length out of range in heap table. HeapMemBlockArray[Idx].BlocksAllocated = %d\n", HeapMemBlockArray[Idx].BlocksAllocated));
}
// 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 = HeapMemBlockArray[Idx].BlocksAllocated;
for (Idx2=1; Idx2<Count; Idx2++)
{
// Make sure it's allocated
if (HeapMemBlockArray[Idx + Idx2].MemBlockAllocated != TRUE)
{
BugCheck((DPRINT_MEMORY, "Heap table indicates hole in memory allocation. HeapMemBlockArray[Idx + Idx2].MemBlockAllocated != TRUE\n"));
}
// Make sure the length is zero
if (HeapMemBlockArray[Idx + Idx2].BlocksAllocated != 0)
{
BugCheck((DPRINT_MEMORY, "Allocation chain has non-zero value in non-first block in heap table. HeapMemBlockArray[Idx + Idx2].BlocksAllocated != 0\n"));
}
}
// Move on to the next run
Idx += (Count - 1);
}
else
{
// Nope, not allocated so make sure the length is zero
if (HeapMemBlockArray[Idx].BlocksAllocated != 0)
{
BugCheck((DPRINT_MEMORY, "Free block is start of memory allocation. HeapMemBlockArray[Idx].BlocksAllocated != 0\n"));
}
}
}
}
VOID DumpMemoryAllocMap(VOID)
{
ULONG Idx;
DbgPrint((DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n"));
for (Idx=0; Idx<HeapMemBlockCount; Idx++)
{
if ((Idx % 32) == 0)
{
DbgPrint((DPRINT_MEMORY, "\n"));
DbgPrint((DPRINT_MEMORY, "%x:\t", (Idx * 256)));
}
else if ((Idx % 4) == 0)
{
DbgPrint((DPRINT_MEMORY, " "));
}
if (HeapMemBlockArray[Idx].MemBlockAllocated)
{
DbgPrint((DPRINT_MEMORY, "X"));
}
else
{
DbgPrint((DPRINT_MEMORY, "*"));
}
}
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 = AllocateMemory(4096);
printf("MemPtr1: 0x%x\n", (int)MemPtr1);
getch();
MemPtr2 = AllocateMemory(4096);
printf("MemPtr2: 0x%x\n", (int)MemPtr2);
getch();
MemPtr3 = AllocateMemory(4096);
printf("MemPtr3: 0x%x\n", (int)MemPtr3);
DumpMemoryAllocMap();
VerifyHeap();
getch();
FreeMemory(MemPtr2);
getch();
MemPtr4 = AllocateMemory(2048);
printf("MemPtr4: 0x%x\n", (int)MemPtr4);
getch();
MemPtr5 = AllocateMemory(4096);
printf("MemPtr5: 0x%x\n", (int)MemPtr5);
getch();
}
#endif // DEBUG
// Returns the amount of total usuable memory available to the memory manager
ULONG GetSystemMemorySize(VOID)
{
return HeapLengthInBytes;
}

View File

@@ -1,257 +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 "parseini.h"
unsigned long next_module_load_base = 0;
module_t* pOpenModule = NULL;
BOOL MultiBootLoadKernel(FILE *KernelImage)
{
DWORD ImageHeaders[2048];
int Idx;
DWORD dwHeaderChecksum;
DWORD dwFileLoadOffset;
DWORD dwDataSize;
DWORD dwBssSize;
ULONG BytesRead;
/*
* Load the first 8192 bytes of the kernel image
* so we can search for the multiboot header
*/
ReadFile(KernelImage, 8192, NULL, ImageHeaders);
/*
* 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;
}
}
/*
* If we reached the end of the 8192 bytes without
* finding the multiboot header then return error
*/
if (Idx == 2048)
{
MessageBox("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)
{
MessageBox("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 (OpenSection(OperatingSystemName, &SectionId))
{
if (ReadSectionSettingByName(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 == 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,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,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);
showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy();
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);
showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy();
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,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,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 "parseini.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[80];
UCHAR SettingValue[80];
ULONG OperatingSystemCount;
ULONG SectionId;
ULONG OperatingSystemSectionId;
ULONG SectionSettingCount;
PUCHAR *OperatingSystemSectionNames;
PUCHAR *OperatingSystemDisplayNames;
//
// Open the [FreeLoader] section
//
if (!OpenSection("FreeLoader", &SectionId))
{
MessageBox("Section [FreeLoader] not found in freeldr.ini.");
return FALSE;
}
SectionSettingCount = GetNumSectionItems(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++)
{
ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
if (stricmp(SettingName, "OS") == 0)
{
strcpy(OperatingSystemSectionNames[CurrentOperatingSystemIndex], SettingValue);
CurrentOperatingSystemIndex++;
}
}
//
// Now loop through and read the operating system display names
//
for (Idx=0; Idx<OperatingSystemCount; Idx++)
{
if (OpenSection(OperatingSystemSectionNames[Idx], &OperatingSystemSectionId))
{
if (ReadSectionSettingByName(OperatingSystemSectionId, "Name", SettingValue, 80))
{
//
// Remove any quotes around the string
//
RemoveQuotes(SettingValue);
strcpy(OperatingSystemDisplayNames[Idx], SettingValue);
}
else
{
sprintf(SettingName, "Operating System '%s' has no Name= line in it's [section].", OperatingSystemSectionNames[Idx]);
MessageBox(SettingName);
strcpy(OperatingSystemDisplayNames[Idx], "");
}
}
}
*OperatingSystemCountPointer = OperatingSystemCount;
*SectionNamesPointer = OperatingSystemSectionNames;
*DisplayNamesPointer = OperatingSystemDisplayNames;
return TRUE;
}
ULONG CountOperatingSystems(ULONG SectionId)
{
ULONG Idx;
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG OperatingSystemCount = 0;
ULONG SectionSettingCount;
//
// Loop through and count the operating systems
//
SectionSettingCount = GetNumSectionItems(SectionId);
for (Idx=0; Idx<SectionSettingCount; Idx++)
{
ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
if (stricmp(SettingName, "OS") == 0)
{
if (OpenSection(SettingValue, NULL))
{
OperatingSystemCount++;
}
else
{
sprintf(SettingName, "Operating System '%s' is listed in freeldr.ini but doesn't have a [section].", SettingValue);
MessageBox(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*) AllocateMemory( sizeof(PUCHAR) * OperatingSystemCount);
OperatingSystemDisplayNames = (PUCHAR*) AllocateMemory( sizeof(PUCHAR) * OperatingSystemCount);
//
// If either allocation failed then return FALSE
//
if ( (OperatingSystemSectionNames == NULL) || (OperatingSystemDisplayNames == NULL) )
{
if (OperatingSystemSectionNames != NULL)
{
FreeMemory(OperatingSystemSectionNames);
}
if (OperatingSystemDisplayNames != NULL)
{
FreeMemory(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) AllocateMemory(80);
OperatingSystemDisplayNames[Idx] = (PUCHAR) AllocateMemory(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)
{
FreeMemory(OperatingSystemSectionNames[Idx]);
}
if (OperatingSystemDisplayNames[Idx] != NULL)
{
FreeMemory(OperatingSystemDisplayNames[Idx]);
}
}
//
// Free operating system list arrays
//
FreeMemory(OperatingSystemSectionNames);
FreeMemory(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,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,433 +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 "parseini.h"
#include "ui.h"
#include "fs.h"
#include "rtl.h"
#include "mm.h"
#include "debug.h"
PUCHAR FreeLoaderIniFileData = NULL;
ULONG FreeLoaderIniFileSize = 0;
BOOL ParseIniFile(VOID)
{
//int i;
//char name[1024];
//char value[1024];
PFILE Freeldr_Ini; // File handle for freeldr.ini
// 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 = AllocateMemory(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
ReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData);
CloseFile(Freeldr_Ini);
// Make sure the [FREELOADER] section exists
/*if (OpenSection("FREELOADER", NULL))
{
printf("Section [FREELOADER] not found in FREELDR.INI.\nYou need to re-install FreeLoader.\n");
return FALSE;
}
// Validate the settings in the [FREELOADER] section
for (i=1; i<=GetNumSectionItems("FREELOADER"); i++)
{
ReadSectionSettingByNumber("FREELOADER", i, name, value);
if (!IsValidSetting(name, value))
{
printf("Invalid setting in freeldr.ini.\nName: \"%s\", Value: \"%s\"\n", name, value);
printf("Press any key to continue.\n");
getch();
}
else
SetSetting(name, value);
}*/
return TRUE;
}
ULONG GetNextLineOfFileData(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 < FreeLoaderIniFileSize); CurrentOffset++)
{
// If we haven't exceeded our buffer size yet
// then store another char
if (Idx < (BufferSize - 1))
{
Buffer[Idx++] = FreeLoaderIniFileData[CurrentOffset];
}
// Check for new line char
if (FreeLoaderIniFileData[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 OpenSection(PUCHAR SectionName, PULONG SectionId)
{
UCHAR TempString[80];
UCHAR RealSectionName[80];
ULONG FileOffset;
BOOL SectionFound = FALSE;
//
// Get the real section name
//
strcpy(RealSectionName, "[");
strcat(RealSectionName, SectionName);
strcat(RealSectionName, "]");
//
// Get to the beginning of the file
//
FileOffset = 0;
//
// Find the section
//
while (FileOffset < FreeLoaderIniFileSize)
{
//
// Read a line
//
FileOffset = GetNextLineOfFileData(TempString, 80, FileOffset);
//
// If it isn't a section header then continue on
//
if (TempString[0] != '[')
continue;
//
// Check and see if we found it
//
if (stricmp(TempString, RealSectionName) == 0)
{
SectionFound = TRUE;
break;
}
}
if (SectionId)
{
*SectionId = FileOffset;
}
return SectionFound;
}
ULONG GetNumSectionItems(ULONG SectionId)
{
UCHAR TempString[80];
ULONG SectionItemCount = 0;
// Now count how many settings are in this section
while (SectionId < FreeLoaderIniFileSize)
{
// Read a line
SectionId = GetNextLineOfFileData(TempString, 80, SectionId);
// If we hit a new section then we're done
if (TempString[0] == '[')
break;
// Skip comments
if (TempString[0] == '#')
continue;
// Skip blank lines
if (!strlen(TempString))
continue;
SectionItemCount++;
}
return SectionItemCount;
}
BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize)
{
UCHAR TempString[1024];
ULONG SectionItemCount = 0;
ULONG Idx;
ULONG FileOffset;
//
// Get to the beginning of the section
//
FileOffset = SectionId;
//
// Now find the setting we are looking for
//
do
{
// Read a line
FileOffset = GetNextLineOfFileData(TempString, 1024, FileOffset);
// Skip comments
if (TempString[0] == '#')
continue;
// Skip blank lines
if (!strlen(TempString))
continue;
// If we hit a new section then we're done
if (TempString[0] == '[')
break;
// Check and see if we found the setting
if (SectionItemCount == SettingNumber)
{
for (Idx=0; Idx<strlen(TempString); Idx++)
{
// Check and see if this character is the separator
if (TempString[Idx] == '=')
{
SettingName[Idx] = '\0';
strncpy(SettingValue, TempString + Idx + 1, ValueSize);
return TRUE;
}
else if (Idx < NameSize)
{
SettingName[Idx] = TempString[Idx];
}
}
}
// Increment setting number
SectionItemCount++;
}
while (FileOffset < FreeLoaderIniFileSize);
return FALSE;
}
BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize)
{
UCHAR TempString[1024];
UCHAR TempBuffer[80];
ULONG Idx;
ULONG FileOffset;
//
// Get to the beginning of the section
//
FileOffset = SectionId;
//
// Now find the setting we are looking for
//
while (FileOffset < FreeLoaderIniFileSize)
{
// Read a line
FileOffset = GetNextLineOfFileData(TempString, 1024, FileOffset);
// Skip comments
if (TempString[0] == '#')
continue;
// Skip blank lines
if (!strlen(TempString))
continue;
// If we hit a new section then we're done
if (TempString[0] == '[')
break;
// Extract the setting name
for (Idx=0; Idx<strlen(TempString); Idx++)
{
if (TempString[Idx] != '=')
TempBuffer[Idx] = TempString[Idx];
else
{
TempBuffer[Idx] = '\0';
break;
}
}
// Check and see if we found the setting
if (stricmp(TempBuffer, SettingName) == 0)
{
for (Idx=0; Idx<strlen(TempString); Idx++)
{
// Check and see if this character is the separator
if (TempString[Idx] == '=')
{
strcpy(Buffer, TempString + Idx + 1);
return TRUE;
}
}
}
}
return FALSE;
}
BOOL IsValidSetting(char *setting, char *value)
{
if(stricmp(setting, "MessageBox") == 0)
return TRUE;
else if(stricmp(setting, "MessageLine") == 0)
return TRUE;
else if(stricmp(setting, "TitleText") == 0)
return TRUE;
else if(stricmp(setting, "StatusBarColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "StatusBarTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "BackdropTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "BackdropColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "BackdropFillStyle") == 0)
{
if(IsValidFillStyle(value))
return TRUE;
}
else if(stricmp(setting, "TitleBoxTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "TitleBoxColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "MessageBoxTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "MessageBoxColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "MenuTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "MenuColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "TextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "SelectedTextColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "SelectedColor") == 0)
{
if(IsValidColor(value))
return TRUE;
}
else if(stricmp(setting, "OS") == 0)
return TRUE;
else if(stricmp(setting, "TimeOut") == 0)
return TRUE;
/*else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;
else if(stricmp(setting, "") == 0)
return TRUE;*/
return FALSE;
}

View File

@@ -1,41 +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 ParseIniFile(void);
ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset); // Gets the next line of text (up to BufferSize) after CurrentOffset and returns the offset of the next line
ULONG GetOffsetOfFirstLineOfSection(PUCHAR SectionName); // Returns the offset of the first line in the section or zero if the section wasn't found
ULONG GetNumSectionItems(PUCHAR SectionName); // returns the number of items in a particular section (i.e. [FREELOADER])
BOOL ReadSectionSettingByNumber(PUCHAR SectionName, ULONG SettingNumber, PUCHAR SettingName, PUCHAR SettingValue); // Reads the num'th value from section
BOOL ReadSectionSettingByName(PUCHAR SectionName, PUCHAR SettingName, PUCHAR SettingValue); // Reads the value named name from section
BOOL IsValidSetting(char *setting, char *value);
void SetSetting(char *setting, char *value);*/
BOOL ParseIniFile(VOID);
ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset);
BOOL OpenSection(PUCHAR SectionName, PULONG SectionId);
ULONG GetNumSectionItems(ULONG SectionId);
BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize);
BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize);
BOOL IsValidSetting(char *setting, char *value);
#endif // defined __PARSEINI_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,48 +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 ../rules.mk
OBJS = reactos.o arcname.o hwdetect.o reghive.o registry.o
.PHONY : clean
all: reactos.a
reactos.a: $(OBJS)
$(LD) -r -o reactos.a $(OBJS)
reactos.o: reactos.c ../reactos.h
$(CC) $(FLAGS) -o reactos.o -c reactos.c
arcname.o: arcname.c ../reactos.h
$(CC) $(FLAGS) -o arcname.o -c arcname.c
hwdetect.o: hwdetect.c ../reactos.h
$(CC) $(FLAGS) -o hwdetect.o -c hwdetect.c
reghive.o: reghive.c ../reactos.h
$(CC) $(FLAGS) -o reghive.o -c reghive.c
registry.o: registry.c ../reactos.h
$(CC) $(FLAGS) -o registry.o -c registry.c
clean:
- $(RM) *.o
- $(RM) *.a

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,39 +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>
//#define NDEBUG
VOID
DetectHardware(VOID)
{
#ifndef NDEBUG
printf("DetectHardware() called\n");
#endif
#ifndef NDEBUG
printf("DetectHardware() done\n");
#endif
//for(;;);
}

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,655 +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 <reactos.h>
#include <rtl.h>
#include <fs.h>
#include <ui.h>
#include <multiboot.h>
#include <mm.h>
#include <parseini.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.");
MessageBox(szBuffer);
return(FALSE);
}
/*
* Update the status bar with the current file
*/
strcpy(szBuffer, " Reading ");
strcat(szBuffer, szShortName);
DrawStatusText(szBuffer);
/*
* Load the kernel
*/
MultiBootLoadKernel(FilePointer);
DrawProgressBar(nPos);
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.");
MessageBox(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);
DrawStatusText(value);
/*
* Load the driver
*/
MultiBootLoadModule(FilePointer, szFileName, NULL);
DrawProgressBar(nPos);
return(TRUE);
}
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.");
MessageBox(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);
DrawStatusText(value);
/*
* Load the driver
*/
MultiBootLoadModule(FilePointer, szModuleName, NULL);
return(TRUE);
}
static VOID
LoadBootDrivers(PCHAR szSystemRoot, int nPos)
{
LONG rc = 0;
HKEY hGroupKey, hServiceKey, hDriverKey;
char ValueBuffer[256];
char ServiceName[256];
ULONG BufferSize;
ULONG Index;
char *s, *p;
char GroupName[256];
ULONG len;
BOOL done;
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);
// printf("RegOpenKey(): rc %d\n", (int)rc);
if (rc != ERROR_SUCCESS)
return;
/* enumerate drivers */
rc = RegOpenKey(NULL,
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
&hServiceKey);
// printf("RegOpenKey(): rc %d\n", (int)rc);
if (rc != ERROR_SUCCESS)
return;
// printf("hKey: %x\n", (int)hKey);
BufferSize = 256;
rc = RegQueryValue(hGroupKey, "List", NULL, (PUCHAR)ValueBuffer, &BufferSize);
// printf("RegQueryValue(): rc %d\n", (int)rc);
if (rc != ERROR_SUCCESS)
return;
// printf("BufferSize: %d \n", (int)BufferSize);
// printf("ValueBuffer: '%s' \n", ValueBuffer);
done = FALSE;
s = ValueBuffer;
do
{
p = strchr(s, ';');
if (p != NULL)
{
len = p - s;
memcpy(GroupName, s, len);
GroupName[len] = 0;
s = p + 1;
}
else
{
strcpy(GroupName, s);
done = TRUE;
}
// printf("Driver group: '%s'\n", GroupName);
/* enumerate all drivers */
Index = 0;
while (TRUE)
{
ValueSize = 256;
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
// printf("RegEnumKey(): rc %d\n", (int)rc);
if (rc == ERROR_NO_MORE_ITEMS)
break;
if (rc != ERROR_SUCCESS)
return;
// printf("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);
// printf(" Start: %x \n", (int)StartValue);
DriverGroupSize = 256;
rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
// printf(" 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)
{
// printf(" ImagePath: not found\n");
strcpy(ImagePath, szSystemRoot);
strcat(ImagePath, "system32\\drivers\\");
strcat(ImagePath, ServiceName);
strcat(ImagePath, ".sys");
}
else
{
// printf(" ImagePath: '%s'\n", ImagePath);
}
// printf(" Loading driver: '%s'\n", ImagePath);
if (nPos < 100)
nPos += 5;
LoadDriver(ImagePath, nPos);
}
Index++;
}
}
while(done == FALSE);
}
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);
}
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 (!OpenSection(OperatingSystemName, &SectionId))
{
sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
MessageBox(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 = GetBiosMemoryMap(&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 (!ReadSectionSettingByName(SectionId, "SystemPath", value, 1024))
{
MessageBox("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);
MessageBox(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 (ReadSectionSettingByName(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, "\\");
#ifndef NDEBUG
sprintf(MsgBuffer,"SystemRoot: '%s'", szBootPath);
MessageBox(MsgBuffer);
#endif
DrawBackdrop();
DrawStatusText(" Loading...");
DrawProgressBar(0);
/*
* Try to open boot drive
*/
if (!OpenDiskDrive(BootDrive, BootPartition))
{
MessageBox("Failed to open boot drive.");
return;
}
/*
* Find the kernel image name
* and try to load the kernel off the disk
*/
if(ReadSectionSettingByName(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(ReadSectionSettingByName(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(ReadSectionSettingByName(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);
}
#ifndef NDEBUG
sprintf(MsgBuffer,"SystemHive: '%s'", szFileName);
MessageBox(MsgBuffer);
#endif
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL)
{
strcat(value, " not found.");
MessageBox(value);
return;
}
/*
* Update the status bar with the current file
*/
strcpy(name, " Reading ");
strcat(name, value);
while (strlen(name) < 80)
strcat(name, " ");
DrawStatusText(name);
/*
* Load the system hive
*/
Base = MultiBootLoadModule(FilePointer, szFileName, &Size);
RegInitializeRegistry();
RegImportHive(Base, Size);
DrawProgressBar(15);
#ifndef NDEBUG
sprintf(MsgBuffer,"SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size);
MessageBox(MsgBuffer);
#endif
/*
* Retrieve hardware information and create the hardware hive
*/
DetectHardware();
// Base = MultiBootCreateModule(HARDWARE.HIV);
// RegExportHive("\\Registry\\Machine\\HARDWARE", Base, &Size);
// MultiBootCloseModule(Base, Size);
DrawProgressBar(20);
/*
* Load NLS files
*/
#if 0
if (!LoadNlsFiles(szBootPath))
{
MessageBox("Failed to load NLS files\n");
return;
}
#endif
DrawProgressBar(25);
/*
* Load boot drivers
*/
LoadBootDrivers(szBootPath, 25);
/*
* Clear the screen and redraw the backdrop and status bar
*/
DrawBackdrop();
DrawStatusText(" 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
*/
stop_floppy();
boot_reactos();
}

View File

@@ -1,571 +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 "registry.h"
#define NDEBUG
#define REGISTRY_FILE_MAGIC "REGEDIT4"
#define INVALID_HANDLE_VALUE NULL
static PCHAR
checkAndSkipMagic (PCHAR regChunk)
{
if (strncmp (regChunk,
REGISTRY_FILE_MAGIC,
strlen (REGISTRY_FILE_MAGIC)) != 0)
{
#ifndef NDEBUG
printf("incorrect magic number in registry chunk. expected: %s got:%.*s\n",
REGISTRY_FILE_MAGIC,
strlen (REGISTRY_FILE_MAGIC),
regChunk);
#endif
return 0;
}
regChunk += strlen (REGISTRY_FILE_MAGIC);
#ifndef NDEBUG
printf("Found registry chunk magic value\n");
#endif
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)
FreeMemory(*newKeyName);
*newKeyName = AllocateMemory(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;
#ifndef NDEBUG
printf("Adding new key '%s'\n", newKeyName);
#endif
RegCreateKey(NULL,
newKeyName,
&handleToReturn);
#ifndef NDEBUG
printf(" returned handle: 0x%x\n", handleToReturn);
#endif
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
{
// 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
{
// UNIMPLEMENTED;
}
return dataSize;
}
static BOOL
allocateDataBuffer (PVOID * data, int * dataBufferSize, int dataSize)
{
if (*dataBufferSize < dataSize)
{
if (*dataBufferSize > 0)
FreeMemory(*data);
*data = AllocateMemory(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
{
// UNIMPLEMENTED;
}
return *regChunk ? regChunk : 0;
}
static BOOL
setKeyValue (HKEY currentKey,
PCHAR newValueName,
ULONG keyValueType,
PVOID data,
ULONG dataSize)
{
LONG status;
#ifndef NDEBUG
printf("Adding value (%s) to current key, with data type %d size %d\n",
newValueName,
(int)keyValueType,
(int)dataSize);
#endif
status = RegSetValue(currentKey,
newValueName,
keyValueType,
data,
dataSize);
if (status != ERROR_SUCCESS)
{
#ifndef NDEBUG
printf("could not set key value, rc:%d\n", status);
#endif
return FALSE;
}
return TRUE;
}
VOID
RegImportHive(PCHAR ChunkBase,
ULONG ChunkSize)
{
HKEY currentKey = NULL;
int newKeySize = 0;
char *newKeyName = NULL;
char dataFormat [10];
int keyValueType;
int dataSize = 0;
int dataBufferSize = 0;
PVOID data = 0;
PCHAR regChunk;
#ifndef NDEBUG
printf("ChunkBase 0x%x ChunkSize %x\n", ChunkBase, ChunkSize);
#endif
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 == '[')
{
#ifndef NDEBUG
printf("Line: %s\n", regChunk);
#endif
if (currentKey != NULL)
{
#ifndef NDEBUG
printf("Closing current key: 0x%lx\n", currentKey);
#endif
currentKey = NULL;
}
regChunk++;
newKeySize = computeKeyNameSize (regChunk);
if (!allocateKeyName (&newKeyName, newKeySize))
{
regChunk = 0;
continue;
}
regChunk = getKeyNameFromChunk (regChunk, newKeyName);
if (regChunk == 0)
continue;
currentKey = createNewKey (newKeyName);
if (currentKey == NULL)
{
regChunk = skipToNextKeyInChunk (regChunk);
continue;
}
regChunk++;
}
else
{
if (currentKey == NULL)
{
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 (newKeyName != NULL)
{
FreeMemory(newKeyName);
}
if (data != NULL)
{
FreeMemory(data);
}
return;
}
static PCHAR
bprintf(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;
}
}
return(p);
}
BOOL
RegExportHive(PCHAR ChunkBase, PULONG ChunkSize)
{
return(TRUE);
}
/* EOF */

View File

@@ -1,596 +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 "registry.h"
#define NDEBUG
static HKEY RootKey;
VOID
RegInitializeRegistry(VOID)
{
RootKey = (HKEY)AllocateMemory(sizeof(KEY));
InitializeListHead(&RootKey->SubKeyList);
InitializeListHead(&RootKey->ValueList);
InitializeListHead(&RootKey->KeyList);
RootKey->NameSize = 2;
RootKey->Name = (PUCHAR)AllocateMemory(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;
HKEY CurrentKey;
HKEY NewKey;
PCHAR p;
PCHAR name;
int subkeyLength;
int stringLength;
#ifndef NDEBUG
printf("RegCreateKey(%s) called\n", KeyName);
#endif
if (*KeyName == '\\')
{
KeyName++;
CurrentKey = RootKey;
}
else if (ParentKey == NULL)
{
CurrentKey = RootKey;
}
else
{
CurrentKey = ParentKey;
}
while (*KeyName != 0)
{
#ifndef NDEBUG
printf("RegCreateKey(): KeyName '%s'\n", KeyName);
#endif
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)
{
#ifndef NDEBUG
printf("RegCreateKey(): Ptr 0x%x\n", Ptr);
#endif
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
#ifndef NDEBUG
printf("RegCreateKey(): SearchKey 0x%x\n", SearchKey);
printf("RegCreateKey(): searching '%s'\n", SearchKey->Name);
#endif
if (strncmp(SearchKey->Name, name, subkeyLength) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &CurrentKey->SubKeyList)
{
/* no key found -> create new subkey */
NewKey = (HKEY)AllocateMemory(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)AllocateMemory(NewKey->NameSize);
if (NewKey->Name == NULL)
return(ERROR_OUTOFMEMORY);
memcpy(NewKey->Name, name, subkeyLength);
NewKey->Name[subkeyLength] = 0;
#ifndef NDEBUG
printf("RegCreateKey(): new key 0x%x\n", NewKey);
printf("RegCreateKey(): new key '%s' length %d\n", NewKey->Name, NewKey->NameSize);
#endif
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);
#ifndef NDEBUG
printf("RegEnumKey(): name '%s' length %d\n", SearchKey->Name, SearchKey->NameSize);
#endif
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;
HKEY CurrentKey;
PCHAR p;
PCHAR name;
int subkeyLength;
int stringLength;
#ifndef NDEBUG
printf("RegOpenKey(%s) called\n", KeyName);
#endif
*Key = NULL;
if (*KeyName == '\\')
{
KeyName++;
CurrentKey = RootKey;
}
else if (ParentKey == NULL)
{
CurrentKey = RootKey;
}
else
{
CurrentKey = ParentKey;
}
while (*KeyName != 0)
{
#ifndef NDEBUG
printf("RegOpenKey(): KeyName '%s'\n", KeyName);
#endif
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)
{
#ifndef NDEBUG
printf("RegCreateKey(): Ptr 0x%x\n", Ptr);
#endif
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
#ifndef NDEBUG
printf("RegOpenKey(): SearchKey 0x%x\n", SearchKey);
printf("RegOpenKey(): searching '%s'\n", SearchKey->Name);
#endif
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;
#ifndef NDEBUG
printf("RegSetValue(%x, '%s', %d, %x, %d)\n", (int)Key, ValueName, (int)Type, (int)Data, (int)DataSize);
#endif
if ((ValueName == NULL) || (*ValueName == 0))
{
/* set default value */
if (Key->Data != NULL)
FreeMemory(Key->Data);
Key->Data = (PUCHAR)AllocateMemory(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);
#ifndef NDEBUG
printf("Value->Name: '%s'\n", Value->Name);
#endif
if (stricmp(Value->Name, ValueName) == 0)
break;
Ptr = Ptr->Flink;
}
if (Ptr == &Key->ValueList)
{
/* add new value */
#ifndef NDEBUG
printf("No value found - adding new value\n");
#endif
Value = (PVALUE)AllocateMemory(sizeof(VALUE));
if (Value == NULL)
return(ERROR_OUTOFMEMORY);
InsertTailList(&Key->ValueList, &Value->ValueList);
Value->NameSize = strlen(ValueName)+1;
Value->Name = (PCHAR)AllocateMemory(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)
FreeMemory(Value->Data);
Value->Data = (PUCHAR)AllocateMemory(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;
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);
#ifndef NDEBUG
printf("Name: %s\n", Value->Name);
#endif
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;
if ((ValueName == NULL) || (*ValueName == 0))
{
/* delete default value */
if (Key->Data != NULL)
FreeMemory(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)
FreeMemory(Value->Name);
Value->Name = NULL;
Value->NameSize = 0;
if (Value->DataSize > sizeof(PUCHAR))
{
if (Value->Data != NULL)
FreeMemory(Value->Data);
}
Value->Data = NULL;
Value->DataSize = 0;
Value->Type = 0;
RemoveEntryList(&Value->ValueList);
FreeMemory(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,287 +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
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,134 +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
void clrscr(void); // Implemented in asmcode.S
int kbhit(void); // Implemented in asmcode.S
int getch(void); // Implemented in asmcode.S
void gotoxy(int x, int y); // 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
void hidecursor(void); // Implemented in asmcode.S
void showcursor(void); // Implemented in asmcode.S
int wherex(void); // Implemented in asmcode.S
int wherey(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,48 +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 ../rules.mk
OBJS = memory.o print.o stdlib.o string.o list.o
.PHONY : clean
all: rtl.a
rtl.a: $(OBJS)
$(LD) -r -o rtl.a $(OBJS)
memory.o: memory.c ../rtl.h
$(CC) $(FLAGS) -o memory.o -c memory.c
print.o: print.c ../rtl.h
$(CC) $(FLAGS) -o print.o -c print.c
stdlib.o: stdlib.c ../rtl.h
$(CC) $(FLAGS) -o stdlib.o -c stdlib.c
string.o: string.c ../rtl.h
$(CC) $(FLAGS) -o string.o -c string.c
list.o: list.c ../rtl.h
$(CC) $(FLAGS) -o list.o -c list.c
clean:
- $(RM) *.o
- $(RM) *.a

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,135 +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((*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,32 +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.
#
CC = gcc
LD = ld
AR = ar
RM = cmd /C del
CP = cmd /C copy
MAKE = make
# For a release build uncomment this line
FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -I../../ -O3
# For a debug build uncomment this line
#FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -I../../ -DDEBUG -O3

View File

@@ -1,157 +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 SCREEN_MEM 0xB8000
#define TITLE_BOX_HEIGHT 5
// Initialize Textual-User-Interface
BOOL InitUserInterface(VOID);
// Fills the entire screen with a backdrop
void DrawBackdrop(void);
// Fills the area specified with cFillChar and cAttr
void FillArea(int nLeft, int nTop, int nRight, int nBottom, char cFillChar, char cAttr /* Color Attributes */);
// Draws a shadow on the bottom and right sides of the area specified
void DrawShadow(int nLeft, int nTop, int nRight, int nBottom);
// Draws a box around the area specified
void DrawBox(int nLeft, int nTop, int nRight, int nBottom, int nVertStyle, int nHorzStyle, int bFill, int bShadow, char cAttr);
// Draws text at coordinates specified
void DrawText(int nX, int nY, char *text, char cAttr);
// Draws text at the very bottom line on the screen
void DrawStatusText(char *text);
// Updates the date and time
void UpdateDateTime(void);
// Saves the screen so that it can be restored later
void SaveScreen(char *buffer);
// Restores the screen from a previous save
void RestoreScreen(char *buffer);
// Displays a message box on the screen with an ok button
void MessageBox(char *text);
// Adds a line of text to the message box buffer
void MessageLine(char *text);
// Returns true if color is valid
BOOL IsValidColor(char *color);
// Converts the text color into it's equivalent color value
char TextToColor(char *color);
// Returns true if fill is valid
BOOL IsValidFillStyle(char *fill);
// Converts the text fill into it's equivalent fill value
char TextToFillStyle(char *fill);
// Draws the progress bar showing nPos percent filled
void DrawProgressBar(int nPos);
// Displays all the message boxes in a given section
void ShowMessageBoxesInSection(PUCHAR SectionName);
/*
* 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)
// 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
///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL DisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem);
#endif // #defined __TUI_H

View File

@@ -1,39 +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 ../rules.mk
OBJS = tui.o menu.o
.PHONY : clean
all: ui.a
ui.a: $(OBJS)
$(LD) -r -o ui.a $(OBJS)
tui.o: tui.c ../ui.h
$(CC) $(FLAGS) -o tui.o -c tui.c
menu.o: menu.c ../ui.h
$(CC) $(FLAGS) -o menu.o -c menu.c
clean:
- $(RM) *.o
- $(RM) *.a

View File

@@ -1,404 +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 <mm.h>
typedef struct
{
PUCHAR *MenuItemList;
ULONG MenuItemCount;
LONG MenuTimeRemaining;
ULONG SelectedMenuItem;
ULONG Left;
ULONG Top;
ULONG Right;
ULONG Bottom;
} MENU_INFO, *PMENU_INFO;
VOID CalcMenuBoxSize(PMENU_INFO MenuInfo);
VOID DrawMenu(PMENU_INFO MenuInfo);
VOID DrawMenuBox(PMENU_INFO MenuInfo);
VOID DrawMenuItem(PMENU_INFO MenuInfo, ULONG MenuItemNumber);
ULONG ProcessMenuKeyboardEvent(PMENU_INFO MenuInfo);
extern ULONG nScreenWidth; // Screen Width
extern ULONG nScreenHeight; // Screen Height
extern CHAR cStatusBarFgColor; // Status bar foreground color
extern CHAR cStatusBarBgColor; // Status bar background color
extern CHAR cBackdropFgColor; // Backdrop foreground color
extern CHAR cBackdropBgColor; // Backdrop background color
extern CHAR cBackdropFillStyle; // Backdrop fill style
extern CHAR cTitleBoxFgColor; // Title box foreground color
extern CHAR cTitleBoxBgColor; // Title box background color
extern CHAR cMessageBoxFgColor; // Message box foreground color
extern CHAR cMessageBoxBgColor; // Message box background color
extern CHAR cMenuFgColor; // Menu foreground color
extern CHAR cMenuBgColor; // Menu background color
extern CHAR cTextColor; // Normal text color
extern CHAR cSelectedTextColor; // Selected text color
extern CHAR cSelectedTextBgColor; // Selected text background color
BOOL DisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem)
{
PUCHAR ScreenBuffer;
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;
}
//
// Allocate memory to hold screen contents before menu is drawn
//
ScreenBuffer = AllocateMemory(4000);
if (ScreenBuffer == NULL)
{
return FALSE;
}
//
// Save screen contents to our buffer
//
SaveScreen(ScreenBuffer);
//
// Setup the MENU_INFO structure
//
MenuInformation.MenuItemList = MenuItemList;
MenuInformation.MenuItemCount = MenuItemCount;
MenuInformation.MenuTimeRemaining = MenuTimeOut;
MenuInformation.SelectedMenuItem = DefaultMenuItem;
//
// Calculate the size of the menu box
//
CalcMenuBoxSize(&MenuInformation);
//
// Draw the menu
//
DrawMenu(&MenuInformation);
//
// Get the current second of time
//
CurrentClockSecond = getsecond();
//
// Process keys
//
while (1)
{
//
// Process key presses
//
if (ProcessMenuKeyboardEvent(&MenuInformation) == KEY_ENTER)
{
//
// If they pressed enter then exit this loop
//
break;
}
//
// Update the date & time
//
UpdateDateTime();
if (MenuInformation.MenuTimeRemaining > 0)
{
if (getsecond() != CurrentClockSecond)
{
//
// Update the time information
//
CurrentClockSecond = getsecond();
MenuInformation.MenuTimeRemaining--;
//
// Update the menu
//
DrawMenuBox(&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 CalcMenuBoxSize(PMENU_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 = (nScreenWidth - Width) / 2;
MenuInfo->Right = (MenuInfo->Left) + Width;
MenuInfo->Top = (( (nScreenHeight - TITLE_BOX_HEIGHT) - Height) / 2 + 1) + (TITLE_BOX_HEIGHT / 2);
MenuInfo->Bottom = (MenuInfo->Top) + Height;
}
VOID DrawMenu(PMENU_INFO MenuInfo)
{
ULONG Idx;
//
// Draw the menu box
//
DrawMenuBox(MenuInfo);
//
// Draw each line of the menu
//
for (Idx=0; Idx<MenuInfo->MenuItemCount; Idx++)
{
DrawMenuItem(MenuInfo, Idx);
}
}
VOID DrawMenuBox(PMENU_INFO MenuInfo)
{
UCHAR MenuLineText[80];
UCHAR TempString[80];
//
// Update the status bar
//
DrawStatusText(" Use \x18\x19 to select, ENTER to boot.");
//
// Draw the menu box
//
DrawBox(MenuInfo->Left,
MenuInfo->Top,
MenuInfo->Right,
MenuInfo->Bottom,
D_VERT,
D_HORZ,
FALSE, // Filled
TRUE, // Shadow
ATTR(cMenuFgColor, cMenuBgColor));
//
// 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, " ]");
DrawText(MenuInfo->Right - strlen(MenuLineText) - 1,
MenuInfo->Bottom,
MenuLineText,
ATTR(cMenuFgColor, cMenuBgColor));
}
}
VOID DrawMenuItem(PMENU_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)
{
DrawText(MenuInfo->Left + 1,
MenuInfo->Top + 1 + MenuItemNumber,
MenuLineText,
ATTR(cSelectedTextColor, cSelectedTextBgColor));
}
else
{
DrawText(MenuInfo->Left + 1,
MenuInfo->Top + 1 + MenuItemNumber,
MenuLineText,
ATTR(cTextColor, cMenuBgColor));
}
}
ULONG ProcessMenuKeyboardEvent(PMENU_INFO MenuInfo)
{
ULONG KeyEvent = 0;
//
// Check for a keypress
//
if (kbhit())
{
//
// Cancel the timeout
//
if (MenuInfo->MenuTimeRemaining != -1)
{
MenuInfo->MenuTimeRemaining = -1;
DrawMenuBox(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
//
DrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem + 1); // Deselect previous item
DrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); // Select new item
}
break;
case KEY_DOWN:
if (MenuInfo->SelectedMenuItem < (MenuInfo->MenuItemCount - 1))
{
MenuInfo->SelectedMenuItem++;
//
// Update the menu
//
DrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem - 1); // Deselect previous item
DrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); // Select new item
}
break;
}
}
return KeyEvent;
}

View File

@@ -1,755 +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 <mm.h>
#include <debug.h>
#include <parseini.h>
ULONG nScreenWidth = 80; // Screen Width
ULONG nScreenHeight = 25; // Screen Height
CHAR cStatusBarFgColor = COLOR_BLACK; // Status bar foreground color
CHAR cStatusBarBgColor = COLOR_CYAN; // Status bar background color
CHAR cBackdropFgColor = COLOR_WHITE; // Backdrop foreground color
CHAR cBackdropBgColor = COLOR_BLUE; // Backdrop background color
CHAR cBackdropFillStyle = MEDIUM_FILL; // Backdrop fill style
CHAR cTitleBoxFgColor = COLOR_WHITE; // Title box foreground color
CHAR cTitleBoxBgColor = COLOR_RED; // Title box background color
CHAR cMessageBoxFgColor = COLOR_WHITE; // Message box foreground color
CHAR cMessageBoxBgColor = COLOR_BLUE; // Message box background color
CHAR cMenuFgColor = COLOR_WHITE; // Menu foreground color
CHAR cMenuBgColor = COLOR_BLUE; // Menu background color
CHAR cTextColor = COLOR_YELLOW; // Normal text color
CHAR cSelectedTextColor = COLOR_BLACK; // Selected text color
CHAR cSelectedTextBgColor = COLOR_GRAY; // Selected text background color
CHAR szTitleBoxTitleText[260] = "Boot Menu"; // Title box's title text
PUCHAR szMessageBoxLineText = NULL;
BOOL UserInterfaceUp = FALSE; // Tells us if the user interface is displayed
BOOL InitUserInterface(VOID)
{
ULONG SectionId;
UCHAR SettingText[260];
DbgPrint((DPRINT_UI, "Initializing User Interface.\n"));
szMessageBoxLineText = AllocateMemory(4096);
if (szMessageBoxLineText == NULL)
{
return FALSE;
}
DbgPrint((DPRINT_UI, "Reading in UI settings from [Display] section.\n"));
if (OpenSection("Display", &SectionId))
{
if (ReadSectionSettingByName(SectionId, "TitleText", SettingText, 260))
{
strcpy(szTitleBoxTitleText, SettingText);
}
if (ReadSectionSettingByName(SectionId, "StatusBarColor", SettingText, 260))
{
cStatusBarBgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "StatusBarTextColor", SettingText, 260))
{
cStatusBarFgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "BackdropTextColor", SettingText, 260))
{
cBackdropFgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "BackdropColor", SettingText, 260))
{
cBackdropBgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "BackdropFillStyle", SettingText, 260))
{
cBackdropFillStyle = TextToFillStyle(SettingText);
}
if (ReadSectionSettingByName(SectionId, "TitleBoxTextColor", SettingText, 260))
{
cTitleBoxFgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "TitleBoxColor", SettingText, 260))
{
cTitleBoxBgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "MessageBoxTextColor", SettingText, 260))
{
cMessageBoxFgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "MessageBoxColor", SettingText, 260))
{
cMessageBoxBgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "MenuTextColor", SettingText, 260))
{
cMenuFgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "MenuColor", SettingText, 260))
{
cMenuBgColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "TextColor", SettingText, 260))
{
cTextColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "SelectedTextColor", SettingText, 260))
{
cSelectedTextColor = TextToColor(SettingText);
}
if (ReadSectionSettingByName(SectionId, "SelectedColor", SettingText, 260))
{
cSelectedTextBgColor = TextToColor(SettingText);
}
}
clrscr();
hidecursor();
// Draw the backdrop and title box
DrawBackdrop();
UserInterfaceUp = TRUE;
DbgPrint((DPRINT_UI, "InitUserInterface() returning TRUE.\n"));
return TRUE;
}
void DrawBackdrop(void)
{
//
// Fill in the background (excluding title box & status bar)
//
FillArea(0,
TITLE_BOX_HEIGHT,
nScreenWidth - 1,
nScreenHeight - 1,
cBackdropFillStyle,
ATTR(cBackdropFgColor, cBackdropBgColor));
//
// Draw the title box
//
DrawBox(1,
1,
nScreenWidth,
5,
D_VERT,
D_HORZ,
TRUE,
FALSE,
ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
//
// Draw version text
//
DrawText(3,
2,
VERSION,
ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
//
// Draw copyright
//
DrawText(3,
3,
"by Brian Palmer",
ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
DrawText(3,
4,
"<brianp@sginet.com>",
ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
//
// Draw help text
//
//DrawText(nScreenWidth-15, 4, /*"F1 for Help"*/"F8 for Options", ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
//
// Draw title text
//
DrawText( (nScreenWidth / 2) - (strlen(szTitleBoxTitleText)/2),
3,
szTitleBoxTitleText,
ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
//
// Draw status bar
//
DrawStatusText("");
//
// Update the date & time
//
UpdateDateTime();
}
/*
* FillArea()
* This function assumes coordinates are zero-based
*/
void FillArea(int nLeft, int nTop, int nRight, int nBottom, char cFillChar, char cAttr /* Color Attributes */)
{
char *screen = (char *)SCREEN_MEM;
int i, j;
for(i=nTop; i<=nBottom; i++)
{
for(j=nLeft; j<=nRight; j++)
{
screen[((i*2)*nScreenWidth)+(j*2)] = cFillChar;
screen[((i*2)*nScreenWidth)+(j*2)+1] = cAttr;
}
}
}
/*
* DrawShadow()
* This function assumes coordinates are zero-based
*/
void DrawShadow(int nLeft, int nTop, int nRight, int nBottom)
{
char *screen = (char *)SCREEN_MEM;
int i;
// Shade the bottom of the area
if(nBottom < (nScreenHeight-1))
{
for(i=nLeft+2; i<=nRight; i++)
screen[(((nBottom+1)*2)*nScreenWidth)+(i*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
// Shade the right of the area
if(nRight < (nScreenWidth-1))
{
for(i=nTop+1; i<=nBottom; i++)
screen[((i*2)*nScreenWidth)+((nRight+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
if(nRight+1 < (nScreenWidth-1))
{
for(i=nTop+1; i<=nBottom; i++)
screen[((i*2)*nScreenWidth)+((nRight+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
// Shade the bottom right corner
if((nRight < (nScreenWidth-1)) && (nBottom < (nScreenHeight-1)))
screen[(((nBottom+1)*2)*nScreenWidth)+((nRight+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
if((nRight+1 < (nScreenWidth-1)) && (nBottom < (nScreenHeight-1)))
screen[(((nBottom+1)*2)*nScreenWidth)+((nRight+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
/*
* DrawBox()
* This function assumes coordinates are one-based
*/
void DrawBox(int nLeft, int nTop, int nRight, int nBottom, int nVertStyle, int nHorzStyle, int bFill, int bShadow, char cAttr)
{
char cULCorner, cURCorner, cLLCorner, cLRCorner;
char cHorz, cVert;
nLeft--;
nTop--;
nRight--;
nBottom--;
cHorz = nHorzStyle;
cVert = nVertStyle;
if(nHorzStyle == HORZ)
{
if(nVertStyle == VERT)
{
cULCorner = UL;
cURCorner = UR;
cLLCorner = LL;
cLRCorner = LR;
}
else // nVertStyle == D_VERT
{
cULCorner = VD_UL;
cURCorner = VD_UR;
cLLCorner = VD_LL;
cLRCorner = VD_LR;
}
}
else // nHorzStyle == D_HORZ
{
if(nVertStyle == VERT)
{
cULCorner = HD_UL;
cURCorner = HD_UR;
cLLCorner = HD_LL;
cLRCorner = HD_LR;
}
else // nVertStyle == D_VERT
{
cULCorner = D_UL;
cURCorner = D_UR;
cLLCorner = D_LL;
cLRCorner = D_LR;
}
}
// Fill in box background
if(bFill)
FillArea(nLeft, nTop, nRight, nBottom, ' ', cAttr);
// Fill in corners
FillArea(nLeft, nTop, nLeft, nTop, cULCorner, cAttr);
FillArea(nRight, nTop, nRight, nTop, cURCorner, cAttr);
FillArea(nLeft, nBottom, nLeft, nBottom, cLLCorner, cAttr);
FillArea(nRight, nBottom, nRight, nBottom, cLRCorner, cAttr);
// Fill in left line
FillArea(nLeft, nTop+1, nLeft, nBottom-1, cVert, cAttr);
// Fill in top line
FillArea(nLeft+1, nTop, nRight-1, nTop, cHorz, cAttr);
// Fill in right line
FillArea(nRight, nTop+1, nRight, nBottom-1, cVert, cAttr);
// Fill in bottom line
FillArea(nLeft+1, nBottom, nRight-1, nBottom, cHorz, cAttr);
if(bShadow)
DrawShadow(nLeft, nTop, nRight, nBottom);
}
/*
* DrawText()
* This function assumes coordinates are one-based
*/
void DrawText(int nX, int nY, char *text, char cAttr)
{
char *screen = (char *)SCREEN_MEM;
int i, j;
nX--;
nY--;
// Draw the text
for(i=nX, j=0; text[j]; i++,j++)
{
screen[((nY*2)*nScreenWidth)+(i*2)] = text[j];
screen[((nY*2)*nScreenWidth)+(i*2)+1] = cAttr;
}
}
void DrawStatusText(char *text)
{
int i;
DrawText(1, nScreenHeight, text, ATTR(cStatusBarFgColor, cStatusBarBgColor));
for(i=strlen(text)+1; i<=nScreenWidth; i++)
DrawText(i, nScreenHeight, " ", ATTR(cStatusBarFgColor, cStatusBarBgColor));
}
void UpdateDateTime(void)
{
char date[40];
char time[40];
char temp[20];
int hour, minute, second, bPM=FALSE;
switch(getmonth())
{
case 1:
strcpy(date, "January ");
break;
case 2:
strcpy(date, "February ");
break;
case 3:
strcpy(date, "March ");
break;
case 4:
strcpy(date, "April ");
break;
case 5:
strcpy(date, "May ");
break;
case 6:
strcpy(date, "June ");
break;
case 7:
strcpy(date, "July ");
break;
case 8:
strcpy(date, "August ");
break;
case 9:
strcpy(date, "September ");
break;
case 10:
strcpy(date, "October ");
break;
case 11:
strcpy(date, "November ");
break;
case 12:
strcpy(date, "December ");
break;
}
itoa(getday(), temp, 10);
if((getday() == 1) || (getday() == 21) || (getday() == 31))
strcat(temp, "st");
else if((getday() == 2) || (getday() == 22))
strcat(temp, "nd");
else if((getday() == 3) || (getday() == 23))
strcat(temp, "rd");
else
strcat(temp, "th");
strcat(date, temp);
strcat(date, " ");
itoa(getyear(), temp, 10);
strcat(date, temp);
// Draw the date
DrawText(nScreenWidth-strlen(date)-1, 2, date, ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
hour = gethour();
if(hour > 12)
{
hour -= 12;
bPM = TRUE;
}
if (hour == 0)
hour = 12;
minute = getminute();
second = getsecond();
itoa(hour, temp, 10);
strcpy(time, " ");
strcat(time, temp);
strcat(time, ":");
itoa(minute, temp, 10);
if(minute < 10)
strcat(time, "0");
strcat(time, temp);
strcat(time, ":");
itoa(second, temp, 10);
if(second < 10)
strcat(time, "0");
strcat(time, temp);
if(bPM)
strcat(time, " PM");
else
strcat(time, " AM");
// Draw the time
DrawText(nScreenWidth-strlen(time)-1, 3, time, ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
}
void SaveScreen(char *buffer)
{
char *screen = (char *)SCREEN_MEM;
int i;
for(i=0; i < (nScreenWidth * nScreenHeight * 2); i++)
buffer[i] = screen[i];
}
void RestoreScreen(char *buffer)
{
char *screen = (char *)SCREEN_MEM;
int i;
for(i=0; i < (nScreenWidth * nScreenHeight * 2); i++)
screen[i] = buffer[i];
}
void MessageBox(char *text)
{
int width = 8;
int height = 1;
int curline = 0;
int i , j, k;
int x1, x2, y1, y2;
PVOID savebuffer;
char temp[260];
char key;
if (!UserInterfaceUp)
{
printf("%s%s", szMessageBoxLineText, text);
printf("Press any key.\n");
getch();
return;
}
savebuffer = AllocateMemory(8000);
SaveScreen(savebuffer);
strcat(szMessageBoxLineText, text);
// Find the height
for(i=0; i<strlen(szMessageBoxLineText); i++)
{
if(szMessageBoxLineText[i] == '\n')
height++;
}
// Find the width
for(i=0,j=0,k=0; i<height; i++)
{
while((szMessageBoxLineText[j] != '\n') && (szMessageBoxLineText[j] != 0))
{
j++;
k++;
}
if(k > width)
width = k;
k = 0;
j++;
}
// Calculate box area
x1 = (nScreenWidth - (width+2))/2;
x2 = x1 + width + 3;
y1 = ((nScreenHeight - height - 2)/2) + 1;
y2 = y1 + height + 4;
// Draw the box
DrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(cMessageBoxFgColor, cMessageBoxBgColor));
// Draw the text
for(i=0,j=0; i<strlen(szMessageBoxLineText)+1; i++)
{
if((szMessageBoxLineText[i] == '\n') || (szMessageBoxLineText[i] == 0))
{
temp[j] = 0;
j = 0;
DrawText(x1+2, y1+1+curline, temp, ATTR(cMessageBoxFgColor, cMessageBoxBgColor));
curline++;
}
else
temp[j++] = szMessageBoxLineText[i];
}
// Draw OK button
strcpy(temp, " OK ");
DrawText(x1+((x2-x1)/2)-3, y2-2, temp, ATTR(COLOR_BLACK, COLOR_GRAY));
for(;;)
{
if(kbhit())
{
key = getch();
if(key == KEY_EXTENDED)
key = getch();
if(key == KEY_ENTER)
break;
else if(key == KEY_SPACE)
break;
}
UpdateDateTime();
}
RestoreScreen(savebuffer);
FreeMemory(savebuffer);
UpdateDateTime();
strcpy(szMessageBoxLineText, "");
}
void MessageLine(char *text)
{
strcat(szMessageBoxLineText, text);
strcat(szMessageBoxLineText, "\n");
}
BOOL IsValidColor(char *color)
{
if(stricmp(color, "Black") == 0)
return TRUE;
else if(stricmp(color, "Blue") == 0)
return TRUE;
else if(stricmp(color, "Green") == 0)
return TRUE;
else if(stricmp(color, "Cyan") == 0)
return TRUE;
else if(stricmp(color, "Red") == 0)
return TRUE;
else if(stricmp(color, "Magenta") == 0)
return TRUE;
else if(stricmp(color, "Brown") == 0)
return TRUE;
else if(stricmp(color, "Gray") == 0)
return TRUE;
else if(stricmp(color, "DarkGray") == 0)
return TRUE;
else if(stricmp(color, "LightBlue") == 0)
return TRUE;
else if(stricmp(color, "LightGreen") == 0)
return TRUE;
else if(stricmp(color, "LightCyan") == 0)
return TRUE;
else if(stricmp(color, "LightRed") == 0)
return TRUE;
else if(stricmp(color, "LightMagenta") == 0)
return TRUE;
else if(stricmp(color, "Yellow") == 0)
return TRUE;
else if(stricmp(color, "White") == 0)
return TRUE;
return FALSE;
}
char TextToColor(char *color)
{
if(stricmp(color, "Black") == 0)
return COLOR_BLACK;
else if(stricmp(color, "Blue") == 0)
return COLOR_BLUE;
else if(stricmp(color, "Green") == 0)
return COLOR_GREEN;
else if(stricmp(color, "Cyan") == 0)
return COLOR_CYAN;
else if(stricmp(color, "Red") == 0)
return COLOR_RED;
else if(stricmp(color, "Magenta") == 0)
return COLOR_MAGENTA;
else if(stricmp(color, "Brown") == 0)
return COLOR_BROWN;
else if(stricmp(color, "Gray") == 0)
return COLOR_GRAY;
else if(stricmp(color, "DarkGray") == 0)
return COLOR_DARKGRAY;
else if(stricmp(color, "LightBlue") == 0)
return COLOR_LIGHTBLUE;
else if(stricmp(color, "LightGreen") == 0)
return COLOR_LIGHTGREEN;
else if(stricmp(color, "LightCyan") == 0)
return COLOR_LIGHTCYAN;
else if(stricmp(color, "LightRed") == 0)
return COLOR_LIGHTRED;
else if(stricmp(color, "LightMagenta") == 0)
return COLOR_LIGHTMAGENTA;
else if(stricmp(color, "Yellow") == 0)
return COLOR_YELLOW;
else if(stricmp(color, "White") == 0)
return COLOR_WHITE;
return COLOR_BLACK;
}
BOOL IsValidFillStyle(char *fill)
{
if(stricmp(fill, "Light") == 0)
return TRUE;
else if(stricmp(fill, "Medium") == 0)
return TRUE;
else if(stricmp(fill, "Dark") == 0)
return TRUE;
return FALSE;
}
char TextToFillStyle(char *fill)
{
if(stricmp(fill, "Light") == 0)
return LIGHT_FILL;
else if(stricmp(fill, "Medium") == 0)
return MEDIUM_FILL;
else if(stricmp(fill, "Dark") == 0)
return DARK_FILL;
return LIGHT_FILL;
}
void DrawProgressBar(int nPos)
{
int left, top, right, bottom;
int width = 50; // Allow for 50 "bars"
int height = 2;
int i;
if(nPos > 100)
nPos = 100;
left = (nScreenWidth - width - 4) / 2;
right = left + width + 3;
top = (nScreenHeight - height - 2) / 2;
top += 4;
bottom = top + height + 1;
// Draw the box
DrawBox(left, top, right, bottom, VERT, HORZ, TRUE, TRUE, ATTR(cMenuFgColor, cMenuBgColor));
// Draw the "Loading..." text
DrawText(70/2, top+1, "Loading...", ATTR(cTextColor, cMenuBgColor));
// Draw the percent complete
for(i=0; i<(nPos/2); i++)
DrawText(left+2+i, top+2, "\xDB", ATTR(cTextColor, cMenuBgColor));
// Draw the rest
for(; i<50; i++)
DrawText(left+2+i, top+2, "\xB2", ATTR(cTextColor, cMenuBgColor));
UpdateDateTime();
}
void ShowMessageBoxesInSection(PUCHAR SectionName)
{
ULONG Idx;
UCHAR SettingName[80];
UCHAR SettingValue[80];
ULONG SectionId;
if (!OpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section %s not found in freeldr.ini.\n", SectionName);
MessageBox(SettingName);
return;
}
//
// Find all the message box settings and run them
//
for (Idx=0; Idx<GetNumSectionItems(SectionId); Idx++)
{
ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
if (stricmp(SettingName, "MessageBox") == 0)
{
MessageBox(SettingValue);
}
else if (stricmp(SettingName, "MessageLine") == 0)
{
MessageLine(SettingValue);
}
}
//
// Zero out message line text
//
strcpy(szMessageBoxLineText, "");
}

View File

@@ -1,5 +0,0 @@
cd bootsect
call install.bat
cd..
copy freeldr.sys a:\FREELDR.SYS
copy freeldr.ini a:\FREELDR.INI

View File

@@ -1,49 +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.
#
export CC = gcc
export LD = ld
export AR = ar
export RM = cmd /C del
export CP = cmd /C copy
export NASM = nasm
export MAKE = make
FLAGS = -Wall
OBJS = install.o volume.o
LIBS = -lkernel32
.PHONY : clean
all: install.exe
install.exe: $(OBJS)
$(CC) $(FLAGS) -o install.exe $(OBJS)
install.o: install.c install.h volume.h
$(CC) $(FLAGS) -o install.o -c install.c
volume.o: volume.c volume.h install.h
$(CC) $(FLAGS) -o volume.o -c volume.c
clean:

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,43 +0,0 @@
FreeLoader notes
To build FreeLoader you will need DJGPP because Mingw32 doesn't support 16-bit code
FreeLoader does not currently work with extended partitions.
Linux booting support needs to be added.
ext2 filesystem support needs to be added.
The MessageBox() function needs to not allocate memory. Because it gets called when memory allocation fails.
Old memory layout:
0000:0000 - 0000:0FFF: Interrupt vector table & BIOS data
0000:1000 - 0000:6FFF: Real mode stack area
0000:7000 - xxxx:xxxx: FreeLoader program & data area
xxxx:xxxx - 6000:0000: Protected mode stack area & heap
6000:0000 - 6000:C000: Filesystem data buffer
6000:C000 - 7000:0000: FREELDR.INI loaded here
7000:0000 - 7000:FFFF: scratch area for any function's use (ie sector buffer for biosdisk()) - can be overwritten by any function
8000:0000 - 9000:FFFF: fat table entry buffer
A000:0000 - FFFF:FFFF: reserved
New 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 - 8000:FFFF: Random memory allocation heap
9000:0000 - 9000:7FFF: Disk read buffer for BIOS Int 13h
9000:8000 - 9000:8FFF: Screen save buffer passed in from boot sector
9000:9000 - 9000:FFFF: Protected mode stack area
A000:0000 - FFFF:FFFF: reserved
FreeLoader Boot Process
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.
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,115 +0,0 @@
/*
* fcntl.h
*
* Access constants for _open. Note that the permissions constants are
* in sys/stat.h (ick).
*
* This code is part of the Mingw32 package.
*
* Contributors:
* Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.4 $
* $Author: ariadne $
* $Date: 1999/03/22 20:48:08 $
*
*/
/* Appropriated for Reactos Crtdll by Ariadne */
/* added _O_RANDOM_O_SEQUENTIAL _O_SHORT_LIVED*/
/* changed fmode_dll */
#ifndef _FCNTL_H_
#define _FCNTL_H_
/*
* It appears that fcntl.h should include io.h for compatibility...
*/
#include <io.h>
/*
* This variable determines the default file mode.
* TODO: Which flags work?
*/
#if __MSVCRT__
extern unsigned int* __imp__fmode;
#define _fmode (*__imp__fmode)
#else
/* CRTDLL */
extern unsigned int* _fmode_dll;
#define _fmode (*_fmode_dll)
#endif
/* Specifiy one of these flags to define the access mode. */
#define _O_RDONLY 0
#define _O_WRONLY 1
#define _O_RDWR 2
/* Mask for access mode bits in the _open flags. */
#define _O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#define _O_APPEND 0x0008 /* Writes will add to the end of the file. */
#define _O_CREAT 0x0100 /* Create the file if it does not exist. */
#define _O_TRUNC 0x0200 /* Truncate the file if it does exist. */
#define _O_EXCL 0x0400 /* Open only if the file does not exist. */
/* NOTE: Text is the default even if the given _O_TEXT bit is not on. */
#define _O_TEXT 0x4000 /* CR-LF in file becomes LF in memory. */
#define _O_BINARY 0x8000 /* Input and output is not translated. */
#define _O_RAW _O_BINARY
#define _O_TEMPORARY 0x0040 /* Make the file dissappear after closing.
* WARNING: Even if not created by _open! */
#define _O_RANDOM 0x0010
#define _O_SEQUENTIAL _O_RANDOM
#define _O_SHORT_LIVED 0x1000
#ifndef __STRICT_ANSI__
#ifndef _NO_OLDNAMES
/* POSIX/Non-ANSI names for increased portability */
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_RDWR _O_RDWR
#define O_ACCMODE _O_ACCMODE
#define O_APPEND _O_APPEND
#define O_CREAT _O_CREAT
#define O_TRUNC _O_TRUNC
#define O_EXCL _O_EXCL
#define O_TEXT _O_TEXT
#define O_BINARY _O_BINARY
#define O_TEMPORARY _O_TEMPORARY
#define O_RANDOM _O_RANDOM
#define O_SEQUENTIAL _O_RANDOM
#define O_SHORT_LIVED _O_SHORT_LIVED
#endif /* Not _NO_OLDNAMES */
#ifdef __cplusplus
extern "C" {
#endif
int _setmode (int nHandle, int nAccessMode);
#ifndef _NO_OLDNAMES
int setmode (int nHandle, int nAccessMode);
#endif /* Not _NO_OLDNAMES */
#ifdef __cplusplus
}
#endif
#endif /* Not __STRICT_ANSI__ */
#endif /* Not _FCNTL_H_ */

View File

@@ -1,151 +0,0 @@
#ifndef __INCLUDE_INTERNAL_PORT_H
#define __INCLUDE_INTERNAL_PORT_H
#include <napi/lpc.h>
typedef
struct _EPORT
{
KSPIN_LOCK Lock;
KEVENT Event;
ULONG State;
struct _EPORT * OtherPort;
ULONG QueueLength;
LIST_ENTRY QueueListHead;
ULONG ConnectQueueLength;
LIST_ENTRY ConnectQueueListHead;
ULONG MaxDataLength;
ULONG MaxConnectInfoLength;
} EPORT, * PEPORT;
typedef struct _EPORT_TERMINATION_REQUEST
{
LIST_ENTRY ThreadListEntry;
PEPORT Port;
} EPORT_TERMINATION_REQUEST, *PEPORT_TERMINATION_REQUEST;
NTSTATUS
STDCALL
LpcRequestPort (
PEPORT Port,
PLPC_MESSAGE LpcMessage
);
NTSTATUS
STDCALL
LpcSendTerminationPort (
PEPORT Port,
TIME CreationTime
);
/* Port Object Access */
#define PORT_ALL_ACCESS (0x1)
/* EPORT.State */
#define EPORT_INACTIVE (0)
#define EPORT_WAIT_FOR_CONNECT (1)
#define EPORT_WAIT_FOR_ACCEPT (2)
#define EPORT_WAIT_FOR_COMPLETE_SRV (3)
#define EPORT_WAIT_FOR_COMPLETE_CLT (4)
#define EPORT_CONNECTED_CLIENT (5)
#define EPORT_CONNECTED_SERVER (6)
#define EPORT_DISCONNECTED (7)
typedef
struct _QUEUEDMESSAGE
{
PEPORT Sender;
LIST_ENTRY QueueListEntry;
LPC_MESSAGE Message;
UCHAR MessageData [MAX_MESSAGE_DATA];
} QUEUEDMESSAGE, *PQUEUEDMESSAGE;
/* Code in ntoskrnl/lpc/close.c */
VOID
NiClosePort (
PVOID ObjectBody,
ULONG HandleCount
);
VOID
NiDeletePort (
IN PVOID ObjectBody
);
/* Code in ntoskrnl/lpc/queue.c */
VOID
STDCALL
EiEnqueueConnectMessagePort (
IN OUT PEPORT Port,
IN PQUEUEDMESSAGE Message
);
VOID
STDCALL
EiEnqueueMessagePort (
IN OUT PEPORT Port,
IN PQUEUEDMESSAGE Message
);
PQUEUEDMESSAGE
STDCALL
EiDequeueConnectMessagePort (
IN OUT PEPORT Port
);
PQUEUEDMESSAGE
STDCALL
EiDequeueMessagePort (
IN OUT PEPORT Port
);
/* Code in ntoskrnl/lpc/create.c */
NTSTATUS
NiCreatePort (
PVOID ObjectBody,
PVOID Parent,
PWSTR RemainingPath,
POBJECT_ATTRIBUTES ObjectAttributes
);
/* Code in ntoskrnl/lpc/port.c */
NTSTATUS
STDCALL
NiInitializePort (
IN OUT PEPORT Port
);
NTSTATUS
NiInitPort (
VOID
);
extern POBJECT_TYPE ExPortType;
extern ULONG EiNextLpcMessageId;
/* Code in ntoskrnl/lpc/reply.c */
NTSTATUS
STDCALL
EiReplyOrRequestPort (
IN PEPORT Port,
IN PLPC_MESSAGE LpcReply,
IN ULONG MessageType,
IN PEPORT Sender
);
#endif /* __INCLUDE_INTERNAL_PORT_H */

View File

@@ -1,193 +0,0 @@
/*
* stdlib.h
*
* Definitions for common types, variables, and functions.
*
* This file is part of the Mingw32 package.
*
* Contributors:
* Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.5 $
* $Author: ariadne $
* $Date: 1999/03/22 20:48:08 $
*
*/
/* Appropriated for Reactos Crtdll by Ariadne */
/* added splitpath */
/* changed definition of environ and argc */
#ifndef _STDLIB_H_
#define _STDLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* This seems like a convenient place to declare these variables, which
* give programs using WinMain (or main for that matter) access to main-ish
* argc and argv. environ is a pointer to a table of environment variables.
* NOTE: Strings in _argv and environ are ANSI strings.
*/
extern int* __argc_dll;
extern char*** __argv_dll;
extern char*** _environ_dll;
#define __argc (*__argc_dll)
#define __argv (*__argv_dll)
#define _environ (*_environ_dll)
#define __need_size_t
#define __need_wchar_t
#define __need_NULL
#include <stddef.h>
#ifdef __GNUC__
#define _ATTRIB_NORETURN __attribute__ ((noreturn))
#else /* Not __GNUC__ */
#define _ATTRIB_NORETURN
#endif /* __GNUC__ */
double atof (const char* szNumber);
int atoi (const char* szNumber);
long atol (const char* szNumber);
double strtod (const char* szNumber, char** pszAfterNumber);
double wcstod (const wchar_t* wsNumber, wchar_t** pwsAfterNumber);
long strtol (const char* szNumber, char** pszAfterNumber, int nBase);
long wcstol (const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
unsigned long strtoul (const char* szNumber, char** pszAfterNumber,
int nBase);
unsigned long wcstoul (const wchar_t* wsNumber, wchar_t** pwsAfterNumber,
int nBase);
size_t wcstombs (char* mbsDest, const wchar_t* wsConvert, size_t size);
int wctomb (char* mbDest, wchar_t wc);
int mblen (const char* mbs, size_t sizeString);
size_t mbstowcs (wchar_t* wcaDest, const char* mbsConvert,
size_t size);
int mbtowc (wchar_t* wcDest, const char* mbConvert, size_t size);
/*
* RAND_MAX is the maximum value that may be returned by rand.
* The minimum is zero.
*/
#define RAND_MAX 0x7FFF
int rand (void);
void srand (unsigned int nSeed);
void* calloc (size_t sizeObjCnt, size_t sizeObject);
void* malloc (size_t sizeObject);
void* realloc (void* pObject, size_t sizeNew);
void free (void* pObject);
/* These values may be used as exit status codes. */
#define EXIT_SUCCESS 0
#define EXIT_FAILURE -1
void abort (void) _ATTRIB_NORETURN;
void exit (int nStatus) _ATTRIB_NORETURN;
int atexit (void (*pfuncExitProcessing)(void));
int system (const char* szCommand); // impl in process
char* getenv (const char* szVarName); // impl in stdio
typedef int (*_pfunccmp_t)(const void*, const void*);
void* bsearch (const void* pKey, const void* pBase, size_t cntObjects,
size_t sizeObject, _pfunccmp_t pfuncCmp);
void qsort (const void* pBase, size_t cntObjects, size_t sizeObject,
_pfunccmp_t pfuncCmp);
int abs (int n);
long labs (long n);
/*
* div_t and ldiv_t are structures used to return the results of div and
* ldiv.
*
* NOTE: div and ldiv appear not to work correctly unless
* -fno-pcc-struct-return is specified. This is included in the
* mingw32 specs file.
*/
typedef struct { int quot, rem; } div_t;
typedef struct { long quot, rem; } ldiv_t;
typedef struct { long long quot, rem; } lldiv_t;
div_t div (int nNumerator, int nDenominator);
ldiv_t ldiv (long lNumerator, long lDenominator);
lldiv_t lldiv (long long lNumerator, long long lDenominator);
#ifndef __STRICT_ANSI__
/*
* NOTE: Officially the three following functions are obsolete. The Win32 API
* functions SetErrorMode, Beep and Sleep are their replacements.
*/
void _beep (unsigned int, unsigned int);
void _seterrormode (int nMode);
void _sleep (unsigned long ulTime);
void _exit (int nStatus) _ATTRIB_NORETURN;
int _putenv (const char* szNameEqValue);
void _searchenv (const char* szFileName, const char* szVar,
char* szFullPathBuf);
void _splitpath( const char *path, char *drive, char *dir,
char *fname, char *ext );
char* _itoa (int nValue, char* sz, int nRadix);
char* _ltoa (long lnValue, char* sz, int nRadix);
char* _ecvt (double dValue, int nDig, int* pnDec, int* pnSign);
char* _fcvt (double dValue, int nDig, int* pnDec, int* pnSign);
char* _gcvt (double dValue, int nDec, char* caBuf);
char* _fullpath (char* caBuf, const char* szPath, size_t sizeMax);
#ifndef _NO_OLDNAMES
#define beep _beep
#define seterrormode _seterrormode
#define sleep _sleep
#define putenv _putenv
#define searchenv _searchenv
#define splitpath _splitpath
#define itoa _itoa
#define ltoa _ltoa
#define ecvt _ecvt
#define fcvt _fcvt
#define gcvt _gcvt
#endif /* Not _NO_OLDNAMES */
#endif /* Not __STRICT_ANSI__ */
/*
* Undefine the no return attribute used in some function definitions
*/
#undef _ATTRIB_NORETURN
#ifdef __cplusplus
}
#endif
#endif /* _STDLIB_H_ */

View File

@@ -1,142 +0,0 @@
#
# Global makefile
#
#
# Select your host
#
#HOST = mingw32-linux
#HOST = djgpp-msdos
HOST = mingw32-windows
include rules.mak
#
# Required to run the system
#
COMPONENTS = iface_native ntoskrnl
#DLLS = ntdll kernel32 crtdll user32 fmifs gdi32
DLLS = ntdll kernel32 crtdll fmifs gdi32
#DLLS = crtdll mingw32
SUBSYS = win32k
#
# Select the server(s) you want to build
#
SERVERS = win32
# SERVERS = posix linux os2
#
# Select the loader(s) you want to build
#
LOADERS = dos
# LOADERS = boot
#
# Select the device drivers and filesystems you want
#
DEVICE_DRIVERS = blue ide keyboard mouse null parallel serial vidport
# DEVICE_DRIVERS = beep event floppy ide_test sound test test1
FS_DRIVERS = vfat
# FS_DRIVERS = minix ext2 template
KERNEL_SERVICES = $(DEVICE_DRIVERS) $(FS_DRIVERS)
APPS = args hello shell test cat bench
# APPS = cmd
all: $(COMPONENTS) $(DLLS) $(SUBSYS) $(LOADERS) $(KERNEL_SERVICES) $(APPS)
.PHONY: all
clean: $(COMPONENTS:%=%_clean) $(DLLS:%=%_clean) $(LOADERS:%=%_clean) \
$(KERNEL_SERVICES:%=%_clean) $(APPS:%=%_clean)
.PHONY: clean
#
# Applications
#
$(APPS): %:
make -C apps/$*
$(APPS:%=%_clean): %_clean:
make -C apps/$* clean
.PHONY: $(APPS) $(APPS:%=%_clean)
#
# Interfaces
#
iface_native:
make -C iface/native
iface_native_clean:
make -C iface/native clean
.PHONY: iface_native iface_native_clean
#
# Device driver rules
#
$(DEVICE_DRIVERS): %:
make -C services/dd/$*
$(DEVICE_DRIVERS:%=%_clean): %_clean:
make -C services/dd/$* clean
.PHONY: $(DEVICE_DRIVERS) $(DEVICE_DRIVERS:%=%_clean)
$(FS_DRIVERS): %:
make -C services/fs/$*
$(FS_DRIVERS:%=%_clean): %_clean:
make -C services/fs/$* clean
.PHONY: $(FS_DRIVERS) $(FS_DRIVERS:%=%_clean)
#
# Kernel loaders
#
$(LOADERS): %:
make -C loaders/$*
$(LOADERS:%=%_clean): %_clean:
make -C loaders/$* clean
.PHONY: $(LOADERS) $(LOADERS:%=%_clean)
#
# Required system components
#
ntoskrnl:
make -C ntoskrnl
ntoskrnl_clean:
make -C ntoskrnl clean
.PHONY: ntoskrnl ntoskrnl_clean
#
# Required DLLs
#
$(DLLS): %:
make -C lib/$*
$(DLLS:%=%_clean): %_clean:
make -C lib/$* clean
.PHONY: $(DLLS) $(DLLS:%=%_clean)
#
# Kernel Subsystems
#
$(SUBSYS): %:
make -C subsys/$*
$(SUBSYS:%=%_clean): %_clean:
make -C lib/$* clean
.PHONY: $(SUBSYS) $(SUBSYS:%=%_clean)

View File

@@ -1,45 +0,0 @@
/*
*
*/
#ifndef __INTERNAL_HAL_HAL_H
#define __INTERNAL_HAL_HAL_H
#include <ddk/service.h>
#include <internal/ntoskrnl.h>
/*
* FUNCTION: Probes for a BIOS32 extension
*/
VOID Hal_bios32_probe(VOID);
/*
* FUNCTION: Determines if a a bios32 service is present
*/
BOOLEAN Hal_bios32_is_service_present(ULONG service);
VOID HalInitializeDisplay (PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID HalResetDisplay (VOID);
VOID HalpInitBusHandlers (VOID);
/* irql.c */
VOID HalpInitPICs(VOID);
/* udelay.c */
VOID HalpCalibrateStallExecution(VOID);
/* pci.c */
VOID HalpInitPciBus (VOID);
struct _ADAPTER_OBJECT {
int Channel;
PVOID PagePort;
PVOID CountPort;
PVOID OffsetPort;
KSPIN_LOCK SpinLock;
PVOID Buffer;
BOOLEAN Inuse;
};
#endif /* __INTERNAL_HAL_HAL_H */

View File

@@ -1,88 +0,0 @@
#
# Global makefile for the ROSAPPS package
#
#
# Select your host
#
#HOST = djgpp-msdos
HOST = mingw32-windows
include rules.mak
#
# Available applications
#
APPS = cmd cmdutils dflat32 mc notevil sysutils \
net\finger net\ncftp net\ping net\telnet net\whois
all: $(APPS)
.PHONY: all
clean: $(APPS:%=%_clean)
.PHONY: clean
floppy: make_floppy_dirs $(APPS:%=%_floppy)
dist: clean_dist_dir make_dist_dirs $(APPS:%=%_dist)
.PHONY: dist
#
# Applications
#
$(APPS): %:
make -C $*
$(APPS:%=%_clean): %_clean:
make -C $* clean
$(APPS:%=%_floppy): %_floppy:
make -C $* floppy
$(APPS:%=%_dist): %_dist:
make -C $* dist
.PHONY: $(APPS) $(APPS:%=%_clean) $(APPS:%=%_floppy) $(APPS:%=%_dist)
#
# Make an install floppy
#
install: all
./install.sh /mnt/hda1
make_floppy_dirs:
ifeq ($(DOSCLI),yes)
mkdir $(FLOPPY_DIR)\apps
else
mkdir $(FLOPPY_DIR)/apps
endif
.PHONY: make_floppy_dirs
#
# Make a distribution saveset
#
clean_dist_dir:
ifeq ($(DOSCLI),yes)
# $(RM) $(DIST_DIR)\apps\*.*
# $(RMDIR) $(DIST_DIR)\apps
# $(RMDIR) $(DIST_DIR)
else
$(RM) -r $(DIST_DIR)
endif
make_dist_dirs:
ifeq ($(DOSCLI),yes)
mkdir $(DIST_DIR)
mkdir $(DIST_DIR)\apps
else
mkdir $(DIST_DIR)
mkdir $(DIST_DIR)/apps
endif
.PHONY: clean_dist_dir make_dist_dirs
# EOF

View File

@@ -1 +0,0 @@
cmd.coff

View File

@@ -1,356 +0,0 @@
/*
* ALIAS.C - alias administration module.
*
*
* History:
*
* 02/02/1996 (Oliver Mueller)
* started.
*
* 02/03/1996 (Oliver Mueller)
* Added sorting algorithm and case sensitive substitution by using
* partstrupr().
*
* 27 Jul 1998 John P. Price
* added config.h include
* added ifdef's to disable aliases
*
* 09-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Fixed crash when removing an alias in DeleteAlias().
* Added help text ("/?").
*
* 14-Jan-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Clean up and Unicode safe!
*
* 24-Jan-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Redirection safe!
*/
#include "config.h"
#ifdef FEATURE_ALIASES
#include <windows.h>
#include <tchar.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cmd.h"
typedef struct tagALIAS
{
struct tagALIAS *next;
LPTSTR lpName;
LPTSTR lpSubst;
DWORD dwUsed;
} ALIAS, *LPALIAS;
static LPALIAS lpFirst = NULL;
static LPALIAS lpLast = NULL;
static DWORD dwUsed = 0;
/* module internal functions */
/* strlwr only for first word in string */
static VOID
partstrlwr (LPTSTR str)
{
LPTSTR c = str;
while (*c && !_istspace (*c) && *c != _T('='))
{
*c = _totlower (*c);
c++;
}
}
static VOID
PrintAlias (VOID)
{
LPALIAS ptr = lpFirst;
while (ptr)
{
ConOutPrintf (_T("%s=%s\n"), ptr->lpName, ptr->lpSubst);
ptr = ptr->next;
}
}
static VOID
DeleteAlias (LPTSTR pszName)
{
LPALIAS ptr = lpFirst;
LPALIAS prev = NULL;
while (ptr)
{
if (!_tcsicmp (ptr->lpName, pszName))
{
if (prev)
prev->next = ptr->next;
else
lpFirst = ptr->next;
free (ptr->lpName);
free (ptr->lpSubst);
free (ptr);
return;
}
prev = ptr;
ptr = ptr->next;
}
}
static VOID
AddAlias (LPTSTR name, LPTSTR subst)
{
LPALIAS ptr = lpFirst;
LPALIAS prev, entry;
LPTSTR s;
while (ptr)
{
if (!_tcsicmp (ptr->lpName, name))
{
s = (LPTSTR)malloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
if (!s)
{
error_out_of_memory ();
return;
}
free (ptr->lpSubst);
ptr->lpSubst = s;
_tcscpy (ptr->lpSubst, subst);
return;
}
ptr = ptr->next;
}
ptr = (LPALIAS)malloc (sizeof (ALIAS));
if (!ptr)
return;
ptr->next = 0;
ptr->lpName = (LPTSTR)malloc ((_tcslen (name) + 1)*sizeof(TCHAR));
if (!ptr->lpName)
{
error_out_of_memory ();
free (ptr);
return;
}
_tcscpy (ptr->lpName, name);
ptr->lpSubst = (LPTSTR)malloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
if (!ptr->lpSubst)
{
error_out_of_memory ();
free (ptr->lpName);
free (ptr);
return;
}
_tcscpy (ptr->lpSubst, subst);
/* it's necessary for recursive substitution */
partstrlwr (ptr->lpSubst);
ptr->dwUsed = 0;
/* Alias table must be sorted!
* Here a little example:
* command line = "ls -c"
* If the entries are
* ls=dir
* ls -c=ls /w
* command line will be expanded to "dir -c" which is not correct.
* If the entries are sortet as
* ls -c=ls /w
* ls=dir
* it will be expanded to "dir /w" which is a valid DOS command.
*/
entry = lpFirst;
prev = 0;
while (entry)
{
if (_tcsicmp (ptr->lpName, entry->lpName) > 0)
{
if (prev)
{
prev->next = ptr;
ptr->next = entry;
}
else
{
ptr->next = entry;
lpFirst = ptr;
}
return;
}
prev = entry;
entry = entry->next;
}
/* The new entry is the smallest (or the first) and must be
* added to the end of the list.
*/
if (!lpFirst)
lpFirst = ptr;
else
lpLast->next = ptr;
lpLast = ptr;
return;
}
VOID InitializeAlias (VOID)
{
lpFirst = NULL;
lpLast = NULL;
dwUsed = 0;
}
VOID DestroyAlias (VOID)
{
if (lpFirst == NULL)
return;
while (lpFirst->next != NULL)
{
lpLast = lpFirst;
lpFirst = lpLast->next;
free (lpLast->lpName);
free (lpLast->lpSubst);
free (lpLast);
}
free (lpFirst->lpName);
free (lpFirst->lpSubst);
free (lpFirst);
lpFirst = NULL;
lpLast = NULL;
dwUsed = 0;
}
/* specified routines */
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
{
unsigned n = 0,
m,
i,
len;
short d = 1;
LPALIAS ptr = lpFirst;
dwUsed++;
if (dwUsed == 0)
{
while (ptr)
ptr->dwUsed = 0;
ptr = lpFirst;
dwUsed = 1;
}
/* skipping white spaces */
while (_istspace (cmd[n]))
n++;
partstrlwr (&cmd[n]);
if (!_tcsncmp (&cmd[n], _T("NOALIAS"), 7) &&
(_istspace (cmd[n + 7]) || cmd[n + 7] == _T('\0')))
{
memmove (cmd, &cmd[n + 7], (_tcslen (&cmd[n + 7]) + 1) * sizeof (TCHAR));
return;
}
/* substitution loop */
while (d)
{
d = 0;
while (ptr)
{
len = _tcslen (ptr->lpName);
if (!_tcsncmp (&cmd[n], ptr->lpName, len) &&
(_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) &&
ptr->dwUsed != dwUsed)
{
m = _tcslen (ptr->lpSubst);
if ((int)(_tcslen (cmd) - len + m - n) > maxlen)
{
ConErrPrintf (_T("Command line too long after alias expansion!\n"));
/* the parser won't cause any problems with an empty line */
cmd[0] = _T('\0');
}
else
{
memmove (&cmd[m], &cmd[n + len], (_tcslen(&cmd[n + len]) + 1) * sizeof (TCHAR));
for (i = 0; i < m; i++)
cmd[i] = ptr->lpSubst[i];
ptr->dwUsed = dwUsed;
/* whitespaces are removed! */
n = 0;
d = 1;
}
}
ptr = ptr->next;
}
}
}
INT CommandAlias (LPTSTR cmd, LPTSTR param)
{
LPTSTR ptr;
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Sets, removes or shows aliases.\n"
"\n"
"ALIAS [alias=[command]]\n"
"\n"
" alias Name for an alias.\n"
" command Text to be substituted for an alias.\n"
"\n"
// "For example:\n"
"To list all aliases:\n"
" ALIAS\n\n"
"To set a new or replace an existing alias:\n"
" ALIAS da=dir a:\n\n"
"To remove an alias from the alias list:\n"
" ALIAS da="
// "Type ALIAS without a parameter to display the alias list.\n"
));
return 0;
}
if (param[0] == _T('\0'))
{
PrintAlias ();
return 0;
}
/* error if no '=' found */
if ((ptr = _tcschr (param, _T('='))) == 0)
return 1;
/* Split rest into name and substitute */
*ptr++ = _T('\0');
partstrlwr (param);
if (ptr[0] == _T('\0'))
DeleteAlias (param);
else
AddAlias (param, ptr);
return 0;
}
#endif

View File

@@ -1,356 +0,0 @@
/*
* ATTRIB.C - attrib internal command.
*
*
* History:
*
* 04-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* started
*
* 09-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* implementation works, except recursion ("attrib /s").
*
* 05-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* major rewrite.
* fixed recursion ("attrib /s").
* started directory support ("attrib /s /d").
* updated help text.
*
* 14-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Unicode ready!
*
* 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Redirection ready!
*
* 21-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Added check for invalid filenames.
*
* 23-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Added handling of multiple filenames.
*/
#include "config.h"
#ifdef INCLUDE_CMD_ATTRIB
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <ctype.h>
#include "cmd.h"
static VOID
PrintAttribute (LPTSTR pszPath, LPTSTR pszFile, BOOL bRecurse)
{
WIN32_FIND_DATA findData;
HANDLE hFind;
TCHAR szFullName[MAX_PATH];
LPTSTR pszFileName;
/* prepare full file name buffer */
_tcscpy (szFullName, pszPath);
pszFileName = szFullName + _tcslen (szFullName);
/* display all subdirectories */
if (bRecurse)
{
/* append file name */
_tcscpy (pszFileName, pszFile);
hFind = FindFirstFile (szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
ErrorMessage (GetLastError (), pszFile);
return;
}
do
{
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
continue;
if (!_tcscmp (findData.cFileName, _T(".")) ||
!_tcscmp (findData.cFileName, _T("..")))
continue;
_tcscpy (pszFileName, findData.cFileName);
_tcscat (pszFileName, _T("\\"));
PrintAttribute (szFullName, pszFile, bRecurse);
}
while (FindNextFile (hFind, &findData));
FindClose (hFind);
}
/* append file name */
_tcscpy (pszFileName, pszFile);
/* display current directory */
hFind = FindFirstFile (szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
ErrorMessage (GetLastError (), pszFile);
return;
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
_tcscpy (pszFileName, findData.cFileName);
ConOutPrintf (_T("%c %c%c%c %s\n"),
(findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '),
(findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '),
(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '),
(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '),
szFullName);
}
while (FindNextFile (hFind, &findData));
FindClose (hFind);
}
static VOID
ChangeAttribute (LPTSTR pszPath, LPTSTR pszFile, DWORD dwMask,
DWORD dwAttrib, BOOL bRecurse, BOOL bDirectories)
{
WIN32_FIND_DATA findData;
HANDLE hFind;
DWORD dwAttribute;
TCHAR szFullName[MAX_PATH];
LPTSTR pszFileName;
/* prepare full file name buffer */
_tcscpy (szFullName, pszPath);
pszFileName = szFullName + _tcslen (szFullName);
/* change all subdirectories */
if (bRecurse)
{
/* append file name */
_tcscpy (pszFileName, _T("*.*"));
hFind = FindFirstFile (szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
ErrorMessage (GetLastError (), pszFile);
return;
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!_tcscmp (findData.cFileName, _T(".")) ||
!_tcscmp (findData.cFileName, _T("..")))
continue;
_tcscpy (pszFileName, findData.cFileName);
_tcscat (pszFileName, _T("\\"));
ChangeAttribute (szFullName, pszFile, dwMask,
dwAttrib, bRecurse, bDirectories);
}
}
while (FindNextFile (hFind, &findData));
FindClose (hFind);
}
/* append file name */
_tcscpy (pszFileName, pszFile);
hFind = FindFirstFile (szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
ErrorMessage (GetLastError (), pszFile);
return;
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
_tcscpy (pszFileName, findData.cFileName);
dwAttribute = GetFileAttributes (szFullName);
if (dwAttribute != 0xFFFFFFFF)
{
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
SetFileAttributes (szFullName, dwAttribute);
}
}
while (FindNextFile (hFind, &findData));
FindClose (hFind);
}
INT CommandAttrib (LPTSTR cmd, LPTSTR param)
{
LPTSTR *arg;
INT argc, i;
TCHAR szPath[MAX_PATH];
TCHAR szFileName [MAX_PATH];
BOOL bRecurse = FALSE;
BOOL bDirectories = FALSE;
DWORD dwAttrib = 0;
DWORD dwMask = 0;
/* initialize strings */
szPath[0] = _T('\0');
szFileName[0] = _T('\0');
/* print help */
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays or changes file attributes.\n\n"
"ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n"
" [/S [/D]]\n\n"
" + Sets an attribute\n"
" - Clears an attribute\n"
" R Read-only file attribute\n"
" A Archive file attribute\n"
" S System file attribute\n"
" H Hidden file attribute\n"
" /S Processes matching files in the current directory\n"
" and all subdirectories\n"
" /D Processes direcories as well\n\n"
"Type ATTRIB without a parameter to display the attributes of all files."));
return 0;
}
/* build parameter array */
arg = split (param, &argc);
/* check for options */
for (i = 0; i < argc; i++)
{
if (_tcsicmp (arg[i], _T("/s")) == 0)
bRecurse = TRUE;
else if (_tcsicmp (arg[i], _T("/d")) == 0)
bDirectories = TRUE;
}
/* create attributes and mask */
for (i = 0; i < argc; i++)
{
if (*arg[i] == _T('+'))
{
if (_tcslen (arg[i]) != 2)
{
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
switch ((TCHAR)_totupper (arg[i][1]))
{
case _T('A'):
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
dwAttrib |= FILE_ATTRIBUTE_ARCHIVE;
break;
case _T('H'):
dwMask |= FILE_ATTRIBUTE_HIDDEN;
dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
break;
case _T('R'):
dwMask |= FILE_ATTRIBUTE_READONLY;
dwAttrib |= FILE_ATTRIBUTE_READONLY;
break;
case _T('S'):
dwMask |= FILE_ATTRIBUTE_SYSTEM;
dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
break;
default:
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
}
else if (*arg[i] == _T('-'))
{
if (_tcslen (arg[i]) != 2)
{
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
switch ((TCHAR)_totupper (arg[i][1]))
{
case _T('A'):
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE;
break;
case _T('H'):
dwMask |= FILE_ATTRIBUTE_HIDDEN;
dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
break;
case _T('R'):
dwMask |= FILE_ATTRIBUTE_READONLY;
dwAttrib &= ~FILE_ATTRIBUTE_READONLY;
break;
case _T('S'):
dwMask |= FILE_ATTRIBUTE_SYSTEM;
dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM;
break;
default:
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
}
}
if (argc == 0)
{
DWORD len;
len = GetCurrentDirectory (MAX_PATH, szPath);
if (szPath[len-1] != _T('\\'))
{
szPath[len] = _T('\\');
szPath[len + 1] = 0;
}
_tcscpy (szFileName, _T("*.*"));
PrintAttribute (szPath, szFileName, bRecurse);
freep (arg);
return 0;
}
/* get full file name */
for (i = 0; i < argc; i++)
{
if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/')))
{
LPTSTR p;
GetFullPathName (arg[i], MAX_PATH, szPath, NULL);
p = _tcsrchr (szPath, _T('\\')) + 1;
_tcscpy (szFileName, p);
*p = _T('\0');
if (dwMask == 0)
PrintAttribute (szPath, szFileName, bRecurse);
else
ChangeAttribute (szPath, szFileName, dwMask,
dwAttrib, bRecurse, bDirectories);
}
}
freep (arg);
return 0;
}
#endif /* INCLUDE_CMD_ATTRIB */

View File

@@ -1,450 +0,0 @@
/* $Id: batch.c,v 1.4 2001/02/28 22:33:23 ekohl Exp $
*
* BATCH.C - batch file processor for CMD.EXE.
*
*
* History:
*
* ??/??/?? (Evan Jeffrey)
* started.
*
* 15 Jul 1995 (Tim Norman)
* modes and bugfixes.
*
* 08 Aug 1995 (Matt Rains)
* i have cleaned up the source code. changes now bring this
* source into guidelines for recommended programming practice.
*
* i have added some constants to help making changes easier.
*
* 29 Jan 1996 (Steffan Kaiser)
* made a few cosmetic changes
*
* 05 Feb 1996 (Tim Norman)
* changed to comply with new first/rest calling scheme
*
* 14 Jun 1997 (Steffen Kaiser)
* bug fixes. added error level expansion %?. ctrl-break handling
*
* 16 Jul 1998 (Hans B Pufal)
* Totally reorganised in conjunction with COMMAND.C (cf) to
* implement proper BATCH file nesting and other improvements.
*
* 16 Jul 1998 (John P Price <linux-guru@gcfl.net>)
* Seperated commands into individual files.
*
* 19 Jul 1998 (Hans B Pufal) [HBP_001]
* Preserve state of echo flag across batch calls.
*
* 19 Jul 1998 (Hans B Pufal) [HBP_002]
* Implementation of FOR command
*
* 20-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* added error checking after malloc calls
*
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* added config.h include
*
* 02-Aug-1998 (Hans B Pufal) [HBP_003]
* Fixed bug in ECHO flag restoration at exit from batch file
*
* 26-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Replaced CRT io functions by Win32 io functions.
* Unicode safe!
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.es>)
* Fixes made to get "for" working.
*/
#include "config.h"
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "cmd.h"
#include "batch.h"
/* The stack of current batch contexts.
* NULL when no batch is active
*/
LPBATCH_CONTEXT bc = NULL;
BOOL bEcho = TRUE; /* The echo flag */
/* Buffer for reading Batch file lines */
TCHAR textline[BATCH_BUFFSIZE];
/*
* Returns a pointer to the n'th parameter of the current batch file.
* If no such parameter exists returns pointer to empty string.
* If no batch file is current, returns NULL
*
*/
LPTSTR FindArg (INT n)
{
LPTSTR pp;
#ifdef _DEBUG
DebugPrintf ("FindArg: (%d)\n", n);
#endif
if (bc == NULL)
return NULL;
n += bc->shiftlevel;
pp = bc->params;
/* Step up the strings till we reach the end */
/* or the one we want */
while (*pp && n--)
pp += _tcslen (pp) + 1;
return pp;
}
/*
* Batch_params builds a parameter list in newlay allocated memory.
* The parameters consist of null terminated strings with a final
* NULL character signalling the end of the parameters.
*
*/
LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
{
LPTSTR dp = (LPTSTR)malloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
/* JPP 20-Jul-1998 added error checking */
if (dp == NULL)
{
error_out_of_memory();
return NULL;
}
if (s1 && *s1)
{
s1 = stpcpy (dp, s1);
*s1++ = _T('\0');
}
else
s1 = dp;
while (*s2)
{
if (_istspace (*s2) || _tcschr (_T(",;"), *s2))
{
*s1++ = _T('\0');
s2++;
while (*s2 && _tcschr (_T(" ,;"), *s2))
s2++;
continue;
}
if ((*s2 == _T('"')) || (*s2 == _T('\'')))
{
TCHAR st = *s2;
do
*s1++ = *s2++;
while (*s2 && (*s2 != st));
}
*s1++ = *s2++;
}
*s1++ = _T('\0');
*s1 = _T('\0');
return dp;
}
/*
* If a batch file is current, exits it, freeing the context block and
* chaining back to the previous one.
*
* If no new batch context is found, sets ECHO back ON.
*
* If the parameter is non-null or not empty, it is printed as an exit
* message
*/
VOID ExitBatch (LPTSTR msg)
{
#ifdef _DEBUG
DebugPrintf ("ExitBatch: (\'%s\')\n", msg);
#endif
if (bc != NULL)
{
LPBATCH_CONTEXT t = bc;
if (bc->hBatchFile)
{
CloseHandle (bc->hBatchFile);
bc->hBatchFile = INVALID_HANDLE_VALUE;
}
if (bc->params)
free(bc->params);
if (bc->forproto)
free(bc->forproto);
if (bc->ffind)
free(bc->ffind);
/* Preserve echo state across batch calls */
bEcho = bc->bEcho;
bc = bc->prev;
free(t);
}
if (msg && *msg)
ConOutPrintf ("%s\n", msg);
}
/*
* Start batch file execution
*
* The firstword parameter is the full filename of the batch file.
*
*/
BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
{
HANDLE hFile;
hFile = CreateFile (fullname, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
#ifdef _DEBUG
DebugPrintf ("Batch: (\'%s\', \'%s\', \'%s\') hFile = %x\n",
fullname, firstword, param, hFile);
#endif
if (hFile == INVALID_HANDLE_VALUE)
{
ConErrPrintf (_T("Error opening batch file\n"));
return FALSE;
}
/* Kill any and all FOR contexts */
while (bc && bc->forvar)
ExitBatch (NULL);
if (bc == NULL)
{
/* No curent batch file, create a new context */
LPBATCH_CONTEXT n = (LPBATCH_CONTEXT)malloc (sizeof(BATCH_CONTEXT));
if (n == NULL)
{
error_out_of_memory ();
return FALSE;
}
n->prev = bc;
bc = n;
}
else if (bc->hBatchFile != INVALID_HANDLE_VALUE)
{
/* Then we are transferring to another batch */
CloseHandle (bc->hBatchFile);
bc->hBatchFile = INVALID_HANDLE_VALUE;
free (bc->params);
}
bc->hBatchFile = hFile;
bc->bEcho = bEcho; /* Preserve echo across batch calls */
bc->shiftlevel = 0;
bc->ffind = NULL;
bc->forvar = _T('\0');
bc->forproto = NULL;
bc->params = BatchParams (firstword, param);
#ifdef _DEBUG
DebugPrintf ("Batch: returns TRUE\n");
#endif
return TRUE;
}
/*
* Read and return the next executable line form the current batch file
*
* If no batch file is current or no further executable lines are found
* return NULL.
*
* Here we also look out for FOR bcontext structures which trigger the
* FOR expansion code.
*
* Set eflag to 0 if line is not to be echoed else 1
*/
LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
{
LPTSTR first;
LPTSTR ip;
/* No batch */
if (bc == NULL)
return NULL;
#ifdef _DEBUG
DebugPrintf ("ReadBatchLine ()\n");
#endif
while (1)
{
/* User halt */
if (CheckCtrlBreak (BREAK_BATCHFILE))
{
while (bc)
ExitBatch (NULL);
return NULL;
}
/* No batch */
if (bc == NULL)
return NULL;
/* If its a FOR context... */
if (bc->forvar)
{
LPTSTR sp = bc->forproto; /* pointer to prototype command */
LPTSTR dp = textline; /* Place to expand protoype */
LPTSTR fv = FindArg (0); /* Next list element */
/* End of list so... */
if ((fv == NULL) || (*fv == _T('\0')))
{
/* just exit this context */
ExitBatch (NULL);
continue;
}
if (_tcscspn (fv, _T("?*")) == _tcslen (fv))
{
/* element is wild file */
bc->shiftlevel++; /* No use it and shift list */
}
else
{
/* Wild file spec, find first (or next) file name */
if (bc->ffind)
{
/* First already done so do next */
fv = FindNextFile (bc->hFind, bc->ffind) ? bc->ffind->cFileName : NULL;
}
else
{
/* For first find, allocate a find first block */
if ((bc->ffind = (LPWIN32_FIND_DATA)malloc (sizeof (WIN32_FIND_DATA))) == NULL)
{
error_out_of_memory();
return NULL;
}
bc->hFind = FindFirstFile (fv, bc->ffind);
fv = !(bc->hFind==INVALID_HANDLE_VALUE) ? bc->ffind->cFileName : NULL;
}
if (fv == NULL)
{
/* Null indicates no more files.. */
free (bc->ffind); /* free the buffer */
bc->ffind = NULL;
bc->shiftlevel++; /* On to next list element */
continue;
}
}
/* At this point, fv points to parameter string */
while (*sp)
{
if ((*sp == _T('%')) && (*(sp + 1) == bc->forvar))
{
/* replace % var */
dp = stpcpy (dp, fv);
sp += 2;
}
else
{
/* Else just copy */
*dp++ = *sp++;
}
}
*dp = _T('\0');
*bLocalEcho = bEcho;
return textline;
}
if (!FileGetString (bc->hBatchFile, textline, sizeof (textline)))
{
#ifdef _DEBUG
DebugPrintf (_T("ReadBatchLine(): Reached EOF!\n"));
#endif
/* End of file.... */
ExitBatch (NULL);
if (bc == NULL)
return NULL;
continue;
}
#ifdef _DEBUG
DebugPrintf (_T("ReadBatchLine(): textline: \'%s\'\n"), textline);
#endif
/* Strip leading spaces and trailing space/control chars */
for (first = textline; _istspace (*first); first++)
;
for (ip = first + _tcslen (first) - 1; _istspace (*ip) || _istcntrl (*ip); ip--)
;
*++ip = _T('\0');
/* ignore labels and empty lines */
if (*first == _T(':') || *first == 0)
continue;
if (*first == _T('@'))
{
/* don't echo this line */
do
first++;
while (_istspace (*first));
*bLocalEcho = 0;
}
else
*bLocalEcho = bEcho;
break;
}
return first;
}
/* EOF */

View File

@@ -1,43 +0,0 @@
/*
* BATCH.H - A structure to preserve the context of a batch file
*
*
*/
#ifndef _BATCH_H_INCLUDED_
#define _BATCH_H_INCLUDED_
typedef struct tagBATCHCONTEXT
{
struct tagBATCHCONTEXT *prev;
LPWIN32_FIND_DATA ffind;
HANDLE hBatchFile;
LPTSTR forproto;
LPTSTR params;
INT shiftlevel;
BOOL bEcho; /* Preserve echo flag across batch calls */
HANDLE hFind; /* Preserve find handle when doing a for */
TCHAR forvar;
} BATCH_CONTEXT, *LPBATCH_CONTEXT;
/* The stack of current batch contexts.
* NULL when no batch is active
*/
extern LPBATCH_CONTEXT bc;
extern BOOL bEcho; /* The echo flag */
#define BATCH_BUFFSIZE 2048
extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
LPTSTR FindArg (INT);
LPTSTR BatchParams (LPTSTR, LPTSTR);
VOID ExitBatch (LPTSTR);
BOOL Batch (LPTSTR, LPTSTR, LPTSTR);
LPTSTR ReadBatchLine (LPBOOL);
#endif /* _BATCH_H_INCLUDED_ */

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