diff --git a/freeldr/freeldr/Makefile b/freeldr/freeldr/Makefile index 9db62776a42..ea246ad62dc 100644 --- a/freeldr/freeldr/Makefile +++ b/freeldr/freeldr/Makefile @@ -25,17 +25,17 @@ export RM = cmd /C del export CP = cmd /C copy #FLAGS = -Wall -nostdinc -fno-builtin -FLAGS = -Wall -fno-builtin -DDEBUG -O3 +FLAGS = -Wall -fno-builtin -I./ -DDEBUG -O3 #FLAGS = -Wall -fno-builtin # 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 stdlib.o fs.a fs.o fat.o \ +#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 -C_OBJS = freeldr.o stdlib.o fs.a tui.o menu.o miscboot.o options.o linux.o multiboot.o \ - reactos/reactos.o reactos/registry.o reactos/reghive.o reactos/hwdetect.o -C_OBJS2 = arcname.o memory.o debug.o parseini.o rs232.o portio.o oslist.o +C_OBJS = freeldr.o rtl/rtl.a fs/fs.a ui/ui.a miscboot.o options.o linux.o multiboot.o \ + reactos/reactos.a comm/comm.a disk/disk.a mm/mm.a +C_OBJS2 = debug.o parseini.o oslist.o .PHONY : clean @@ -63,56 +63,50 @@ c_code2.a: $(C_OBJS2) asmcode.o: asmcode.S asmcode.h Makefile $(CC) $(FLAGS) -o asmcode.o -c asmcode.S -freeldr.o: freeldr.c freeldr.h stdlib.h fs.h reactos/reactos.h tui.h asmcode.h menu.h miscboot.h Makefile - $(CC) $(FLAGS) -o freeldr.o -c freeldr.c - -stdlib.o: stdlib.c freeldr.h stdlib.h Makefile - $(CC) $(FLAGS) -o stdlib.o -c stdlib.c - -fs.a: fs.o fat.o Makefile - $(LD) -r -o fs.a fs.o fat.o - -fs.o: fs.c freeldr.h fs.h stdlib.h tui.h asmcode.h Makefile - $(CC) $(FLAGS) -o fs.o -c fs.c - -fat.o: fat.c fat.h freeldr.h fs.h stdlib.h tui.h Makefile - $(CC) $(FLAGS) -o fat.o -c fat.c - -reactos/reactos.o: reactos/reactos.c freeldr.h reactos/reactos.h reactos/registry.h reactos/hwdetect.h stdlib.h fs.h tui.h multiboot.h Makefile - $(CC) $(FLAGS) -o reactos/reactos.o -c reactos/reactos.c - -multiboot.o: multiboot.c freeldr.h stdlib.h fs.h multiboot.h tui.h Makefile - $(CC) $(FLAGS) -o multiboot.o -c multiboot.c - mb.o: mb.S asmcode.h multiboot.h Makefile $(CC) $(FLAGS) -o mb.o -c mb.S -tui.o: tui.c freeldr.h stdlib.h tui.h Makefile - $(CC) $(FLAGS) -o tui.o -c tui.c - -menu.o: menu.c freeldr.h stdlib.h tui.h menu.h Makefile - $(CC) $(FLAGS) -o menu.o -c menu.c - boot.o: boot.S asmcode.h Makefile $(CC) $(FLAGS) -o boot.o -c boot.S -miscboot.o: miscboot.c freeldr.h asmcode.h stdlib.h fs.h tui.h miscboot.h Makefile - $(CC) $(FLAGS) -o miscboot.o -c miscboot.c - -options.o: options.c freeldr.h stdlib.h tui.h options.h Makefile - $(CC) $(FLAGS) -o options.o -c options.c - -linux.o: linux.c freeldr.h stdlib.h tui.h linux.h Makefile - $(CC) $(FLAGS) -o linux.o -c linux.c - -arcname.o: arcname.c freeldr.h arcname.h stdlib.h Makefile - $(CC) $(FLAGS) -o arcname.o -c arcname.c - mem.o: mem.S asmcode.h Makefile $(CC) $(FLAGS) -o mem.o -c mem.S -memory.o: memory.c memory.h Makefile - $(CC) $(FLAGS) -o memory.o -c memory.c +freeldr.o: freeldr.c freeldr.h rtl.h fs.h reactos.h ui.h asmcode.h miscboot.h Makefile + $(CC) $(FLAGS) -o freeldr.o -c freeldr.c + +rtl/rtl.a: rtl/print.o rtl/stdlib.o rtl/string.o rtl/memory.o Makefile + $(MAKE) -C rtl + +fs/fs.a: fs/fs.o fs/fat.o Makefile + $(MAKE) -C fs + +ui/ui.a: ui/tui.o ui/menu.o Makefile + $(MAKE) -C ui + +miscboot.o: miscboot.c freeldr.h asmcode.h rtl.h fs.h ui.h miscboot.h Makefile + $(CC) $(FLAGS) -o miscboot.o -c miscboot.c + +options.o: options.c freeldr.h rtl.h ui.h options.h Makefile + $(CC) $(FLAGS) -o options.o -c options.c + +linux.o: linux.c freeldr.h rtl.h ui.h linux.h Makefile + $(CC) $(FLAGS) -o linux.o -c linux.c + +multiboot.o: multiboot.c freeldr.h rtl.h fs.h multiboot.h ui.h Makefile + $(CC) $(FLAGS) -o multiboot.o -c multiboot.c + +reactos/reactos.a: reactos/arcname.o reactos/reactos.o reactos/reghive.o reactos/registry.o reactos/hwdetect.o Makefile + $(MAKE) -C reactos + +comm/comm.a: comm/rs232.o comm/portio.o Makefile + $(MAKE) -C comm + +disk/disk.a: disk/disk.o Makefile + $(MAKE) -C disk + +mm/mm.a: mm/mm.o Makefile + $(MAKE) -C mm debug.o: debug.c debug.h Makefile $(CC) $(FLAGS) -o debug.o -c debug.c @@ -120,25 +114,17 @@ debug.o: debug.c debug.h Makefile parseini.o: parseini.c parseini.h Makefile $(CC) $(FLAGS) -o parseini.o -c parseini.c -rs232.o: rs232.c rs232.h Makefile - $(CC) $(FLAGS) -o rs232.o -c rs232.c - -portio.o: portio.c portio.h Makefile - $(CC) $(FLAGS) -o portio.o -c portio.c - oslist.o: oslist.c oslist.h Makefile $(CC) $(FLAGS) -o oslist.o -c oslist.c -reactos/registry.o: reactos/registry.c freeldr.h memory.h reactos/registry.h stdlib.h Makefile - $(CC) $(FLAGS) -o reactos/registry.o -c reactos/registry.c - -reactos/reghive.o: reactos/reghive.c freeldr.h reactos/registry.h stdlib.h memory.h Makefile - $(CC) $(FLAGS) -o reactos/reghive.o -c reactos/reghive.c - -reactos/hwdetect.o: reactos/hwdetect.c freeldr.h reactos/hwdetect.h Makefile - $(CC) $(FLAGS) -o reactos/hwdetect.o -c reactos/hwdetect.c - clean: $(RM) *.o $(RM) *.a $(RM) *.sys + $(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 diff --git a/freeldr/freeldr/cache/Makefile b/freeldr/freeldr/cache/Makefile new file mode 100644 index 00000000000..9db62776a42 --- /dev/null +++ b/freeldr/freeldr/cache/Makefile @@ -0,0 +1,144 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +#FLAGS = -Wall -nostdinc -fno-builtin +FLAGS = -Wall -fno-builtin -DDEBUG -O3 +#FLAGS = -Wall -fno-builtin + +# 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 stdlib.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 +C_OBJS = freeldr.o stdlib.o fs.a tui.o menu.o miscboot.o options.o linux.o multiboot.o \ + reactos/reactos.o reactos/registry.o reactos/reghive.o reactos/hwdetect.o +C_OBJS2 = arcname.o memory.o debug.o parseini.o rs232.o portio.o oslist.o + +.PHONY : clean + +all: freeldr.sys + +freeldr.sys: asmcode.a c_code.a + $(LD) -N -Ttext=0x8000 --oformat=binary -s -o f.sys asmcode.a 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 + +asmcode.a: $(ASM_OBJS) + $(LD) -r -o asmcode.a $(ASM_OBJS) + +c_code.a: c_code1.a c_code2.a + $(LD) -r -o c_code.a c_code1.a c_code2.a + +c_code1.a: $(C_OBJS) + $(LD) -r -o c_code1.a $(C_OBJS) + +c_code2.a: $(C_OBJS2) + $(LD) -r -o c_code2.a $(C_OBJS2) + +asmcode.o: asmcode.S asmcode.h Makefile + $(CC) $(FLAGS) -o asmcode.o -c asmcode.S + +freeldr.o: freeldr.c freeldr.h stdlib.h fs.h reactos/reactos.h tui.h asmcode.h menu.h miscboot.h Makefile + $(CC) $(FLAGS) -o freeldr.o -c freeldr.c + +stdlib.o: stdlib.c freeldr.h stdlib.h Makefile + $(CC) $(FLAGS) -o stdlib.o -c stdlib.c + +fs.a: fs.o fat.o Makefile + $(LD) -r -o fs.a fs.o fat.o + +fs.o: fs.c freeldr.h fs.h stdlib.h tui.h asmcode.h Makefile + $(CC) $(FLAGS) -o fs.o -c fs.c + +fat.o: fat.c fat.h freeldr.h fs.h stdlib.h tui.h Makefile + $(CC) $(FLAGS) -o fat.o -c fat.c + +reactos/reactos.o: reactos/reactos.c freeldr.h reactos/reactos.h reactos/registry.h reactos/hwdetect.h stdlib.h fs.h tui.h multiboot.h Makefile + $(CC) $(FLAGS) -o reactos/reactos.o -c reactos/reactos.c + +multiboot.o: multiboot.c freeldr.h stdlib.h fs.h multiboot.h tui.h Makefile + $(CC) $(FLAGS) -o multiboot.o -c multiboot.c + +mb.o: mb.S asmcode.h multiboot.h Makefile + $(CC) $(FLAGS) -o mb.o -c mb.S + +tui.o: tui.c freeldr.h stdlib.h tui.h Makefile + $(CC) $(FLAGS) -o tui.o -c tui.c + +menu.o: menu.c freeldr.h stdlib.h tui.h menu.h Makefile + $(CC) $(FLAGS) -o menu.o -c menu.c + +boot.o: boot.S asmcode.h Makefile + $(CC) $(FLAGS) -o boot.o -c boot.S + +miscboot.o: miscboot.c freeldr.h asmcode.h stdlib.h fs.h tui.h miscboot.h Makefile + $(CC) $(FLAGS) -o miscboot.o -c miscboot.c + +options.o: options.c freeldr.h stdlib.h tui.h options.h Makefile + $(CC) $(FLAGS) -o options.o -c options.c + +linux.o: linux.c freeldr.h stdlib.h tui.h linux.h Makefile + $(CC) $(FLAGS) -o linux.o -c linux.c + +arcname.o: arcname.c freeldr.h arcname.h stdlib.h Makefile + $(CC) $(FLAGS) -o arcname.o -c arcname.c + +mem.o: mem.S asmcode.h Makefile + $(CC) $(FLAGS) -o mem.o -c mem.S + +memory.o: memory.c memory.h Makefile + $(CC) $(FLAGS) -o memory.o -c memory.c + +debug.o: debug.c debug.h Makefile + $(CC) $(FLAGS) -o debug.o -c debug.c + +parseini.o: parseini.c parseini.h Makefile + $(CC) $(FLAGS) -o parseini.o -c parseini.c + +rs232.o: rs232.c rs232.h Makefile + $(CC) $(FLAGS) -o rs232.o -c rs232.c + +portio.o: portio.c portio.h Makefile + $(CC) $(FLAGS) -o portio.o -c portio.c + +oslist.o: oslist.c oslist.h Makefile + $(CC) $(FLAGS) -o oslist.o -c oslist.c + +reactos/registry.o: reactos/registry.c freeldr.h memory.h reactos/registry.h stdlib.h Makefile + $(CC) $(FLAGS) -o reactos/registry.o -c reactos/registry.c + +reactos/reghive.o: reactos/reghive.c freeldr.h reactos/registry.h stdlib.h memory.h Makefile + $(CC) $(FLAGS) -o reactos/reghive.o -c reactos/reghive.c + +reactos/hwdetect.o: reactos/hwdetect.c freeldr.h reactos/hwdetect.h Makefile + $(CC) $(FLAGS) -o reactos/hwdetect.o -c reactos/hwdetect.c + +clean: + $(RM) *.o + $(RM) *.a + $(RM) *.sys diff --git a/freeldr/freeldr/portio.h b/freeldr/freeldr/comm.h similarity index 83% rename from freeldr/freeldr/portio.h rename to freeldr/freeldr/comm.h index feee621b4cd..1849870593c 100644 --- a/freeldr/freeldr/portio.h +++ b/freeldr/freeldr/comm.h @@ -1,6 +1,8 @@ /* * FreeLoader * Copyright (C) 2001 Brian Palmer + * 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 @@ -17,8 +19,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef __PORTIO_H -#define __PORTIO_H +#ifndef __RS232_H +#define __RS232_H + +BOOL Rs232PortInitialize(ULONG ComPort, ULONG BaudRate); +BOOL Rs232PortGetByte(PUCHAR ByteRecieved); +BOOL Rs232PortPollByte(PUCHAR ByteRecieved); +VOID Rs232PortPutByte(UCHAR ByteToSend); + /* @@ -74,4 +82,4 @@ VOID WRITE_PORT_USHORT (PUSHORT Port, USHORT Value); -#endif // defined __PORTIO_H +#endif // defined __RS232_H diff --git a/freeldr/freeldr/comm/Makefile b/freeldr/freeldr/comm/Makefile new file mode 100644 index 00000000000..97ac6f73793 --- /dev/null +++ b/freeldr/freeldr/comm/Makefile @@ -0,0 +1,46 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +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 Makefile + $(CC) $(FLAGS) -o rs232.o -c rs232.c + +portio.o: portio.c ../comm.h Makefile + $(CC) $(FLAGS) -o portio.o -c portio.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/portio.c b/freeldr/freeldr/comm/portio.c similarity index 98% rename from freeldr/freeldr/portio.c rename to freeldr/freeldr/comm/portio.c index 1e6865ff215..c8b4f113cbd 100644 --- a/freeldr/freeldr/portio.c +++ b/freeldr/freeldr/comm/portio.c @@ -1,4 +1,4 @@ -/* $Id: portio.c,v 1.1 2001/08/07 06:19:43 bpalmer Exp $ +/* $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 diff --git a/freeldr/freeldr/rs232.c b/freeldr/freeldr/comm/rs232.c similarity index 99% rename from freeldr/freeldr/rs232.c rename to freeldr/freeldr/comm/rs232.c index 2c21d7eec73..b6fc8cd951f 100644 --- a/freeldr/freeldr/rs232.c +++ b/freeldr/freeldr/comm/rs232.c @@ -19,8 +19,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "portio.h" +#include +#include /* MACROS *******************************************************************/ @@ -120,7 +120,7 @@ static BOOL Rs232DoesComPortExist(PUCHAR BaseAddress) BOOL Rs232PortInitialize(ULONG ComPort, ULONG BaudRate) { ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8}; - char buffer[80]; + //char buffer[80]; ULONG divisor; BYTE lcr; diff --git a/freeldr/freeldr/debug.c b/freeldr/freeldr/debug.c index b8178c83636..e781870d7b3 100644 --- a/freeldr/freeldr/debug.c +++ b/freeldr/freeldr/debug.c @@ -17,16 +17,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "debug.h" -#include "stdlib.h" -#include "rs232.h" -#include "parseini.h" -#include "portio.h" +#include +#include +#include +#include #ifdef DEBUG -ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | DPRINT_UI; +ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | DPRINT_UI | DPRINT_DISK; #define SCREEN 0 #define RS232 1 diff --git a/freeldr/freeldr/debug.h b/freeldr/freeldr/debug.h index 57514cf1ab3..04c345cb3c7 100644 --- a/freeldr/freeldr/debug.h +++ b/freeldr/freeldr/debug.h @@ -28,6 +28,7 @@ #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 VOID DebugInit(VOID); VOID DebugPrint(ULONG Mask, char *format, ...); diff --git a/freeldr/freeldr/disk.h b/freeldr/freeldr/disk.h new file mode 100644 index 00000000000..7132229808f --- /dev/null +++ b/freeldr/freeldr/disk.h @@ -0,0 +1,59 @@ +/* + * FreeLoader + * Copyright (C) 1999, 2000, 2001 Brian Palmer + * + * 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); + +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 DiskSetDriveGeometry(ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector); +VOID DiskSetVolumeProperties(ULONG HiddenSectors); +BOOL DiskReadMultipleLogicalSectors(ULONG SectorNumber, ULONG SectorCount, PVOID Buffer); +BOOL DiskReadLogicalSector(ULONG SectorNumber, PVOID Buffer); + +#endif // defined __DISK_H \ No newline at end of file diff --git a/freeldr/freeldr/disk/Makefile b/freeldr/freeldr/disk/Makefile new file mode 100644 index 00000000000..41225ab2077 --- /dev/null +++ b/freeldr/freeldr/disk/Makefile @@ -0,0 +1,43 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +OBJS = disk.o + +.PHONY : clean + +all: disk.a + +disk.a: $(OBJS) + $(LD) -r -o disk.a $(OBJS) + +disk.o: disk.c ../disk.h Makefile + $(CC) $(FLAGS) -o disk.o -c disk.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/disk/disk.c b/freeldr/freeldr/disk/disk.c new file mode 100644 index 00000000000..7f521630ccb --- /dev/null +++ b/freeldr/freeldr/disk/disk.c @@ -0,0 +1,188 @@ +/* + * FreeLoader + * Copyright (C) 1999, 2000, 2001 Brian Palmer + * + * 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 +#include +#include +#include +#include +#include +#include + + +///////////////////////////////////////////////////////////////////////////////////////////// +// DATA +///////////////////////////////////////////////////////////////////////////////////////////// + +GEOMETRY DriveGeometry; +ULONG VolumeHiddenSectors; +ULONG CurrentlyOpenDriveNumber; + +///////////////////////////////////////////////////////////////////////////////////////////// +// FUNCTIONS +///////////////////////////////////////////////////////////////////////////////////////////// + +VOID DiskError(PUCHAR ErrorString) +{ + DbgPrint((DPRINT_DISK, "%s\n", ErrorString)); + + if (UserInterfaceUp) + { + MessageBox(ErrorString); + } + else + { + printf("%s", ErrorString); + printf("\nPress any key\n"); + getch(); + } +} + +VOID DiskSetDriveGeometry(ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector) +{ + DriveGeometry.Cylinders = Cylinders; + DriveGeometry.Heads = Heads; + DriveGeometry.Sectors = Sectors; + DriveGeometry.BytesPerSector = BytesPerSector; + + DbgPrint((DPRINT_DISK, "DriveGeometry.Cylinders: %d\n", DriveGeometry.Cylinders)); + DbgPrint((DPRINT_DISK, "DriveGeometry.Heads: %d\n", DriveGeometry.Heads)); + DbgPrint((DPRINT_DISK, "DriveGeometry.Sectors: %d\n", DriveGeometry.Sectors)); + DbgPrint((DPRINT_DISK, "DriveGeometry.BytesPerSector: %d\n", DriveGeometry.BytesPerSector)); +} + +VOID DiskSetVolumeProperties(ULONG HiddenSectors) +{ + VolumeHiddenSectors = HiddenSectors; +} + +BOOL DiskReadMultipleLogicalSectors(ULONG SectorNumber, ULONG SectorCount, PVOID Buffer) +{ + /*BOOL bRetVal; + int PhysicalSector; + int PhysicalHead; + int PhysicalTrack; + int nNum; + + nSect += nHiddenSectors; + + while (nNumberOfSectors) + { + PhysicalSector = 1 + (nSect % nSectorsPerTrack); + PhysicalHead = (nSect / nSectorsPerTrack) % nNumberOfHeads; + PhysicalTrack = nSect / (nSectorsPerTrack * nNumberOfHeads); + + if (PhysicalSector > 1) + { + if (nNumberOfSectors >= (nSectorsPerTrack - (PhysicalSector - 1))) + nNum = (nSectorsPerTrack - (PhysicalSector - 1)); + else + nNum = nNumberOfSectors; + } + else + { + if (nNumberOfSectors >= nSectorsPerTrack) + nNum = nSectorsPerTrack; + else + nNum = nNumberOfSectors; + } + + bRetVal = biosdisk(CurrentlyOpenDriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, nNum, pBuffer); + + if (!bRetVal) + { + FS_DO_ERROR("Disk Error"); + return FALSE; + } + + pBuffer += (nNum * 512); + nNumberOfSectors -= nNum; + nSect += nNum; + }*/ + + ULONG CurrentSector; + PVOID RealBuffer = Buffer; + + for (CurrentSector=SectorNumber; CurrentSector<(SectorNumber + SectorCount); CurrentSector++) + { + if (!DiskReadLogicalSector(CurrentSector, RealBuffer) ) + { + return FALSE; + } + + RealBuffer += DriveGeometry.BytesPerSector; + } + + return TRUE; +} + +BOOL DiskReadLogicalSector(ULONG SectorNumber, PVOID Buffer) +{ + ULONG PhysicalSector; + ULONG PhysicalHead; + ULONG PhysicalTrack; + + DbgPrint((DPRINT_DISK, "ReadLogicalSector() SectorNumber: %d Buffer: 0x%x\n", SectorNumber, Buffer)); + + SectorNumber += VolumeHiddenSectors; + PhysicalSector = 1 + (SectorNumber % DriveGeometry.Sectors); + PhysicalHead = (SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads; + PhysicalTrack = (SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads; + + //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalHead: %d\n", PhysicalHead)); + //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalTrack: %d\n", PhysicalTrack)); + //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalSector: %d\n", PhysicalSector)); + if (PhysicalHead >= DriveGeometry.Heads) + { + BugCheck((DPRINT_DISK, "PhysicalHead >= DriveGeometry.Heads\nPhysicalHead = %d\nDriveGeometry.Heads = %d\n", PhysicalHead, DriveGeometry.Heads)); + } + if (PhysicalTrack >= DriveGeometry.Cylinders) + { + BugCheck((DPRINT_DISK, "PhysicalTrack >= DriveGeometry.Cylinders\nPhysicalTrack = %d\nDriveGeometry.Cylinders = %d\n", PhysicalTrack, DriveGeometry.Cylinders)); + } + if (PhysicalSector > DriveGeometry.Sectors) + { + BugCheck((DPRINT_DISK, "PhysicalSector > DriveGeometry.Sectors\nPhysicalSector = %d\nDriveGeometry.Sectors = %d\n", PhysicalSector, DriveGeometry.Sectors)); + } + + // + // 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 ((CurrentlyOpenDriveNumber >= 0x80) && (BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber)) && (SectorNumber > (DriveGeometry.Cylinders * DriveGeometry.Heads * DriveGeometry.Sectors))) + { + DbgPrint((DPRINT_DISK, "Using Int 13 Extensions for read. BiosInt13ExtensionsSupported(%d) = %s\n", CurrentlyOpenDriveNumber, BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber) ? "TRUE" : "FALSE")); + if ( !BiosInt13ReadExtended(CurrentlyOpenDriveNumber, SectorNumber, 1, Buffer) ) + { + DiskError("Disk read error."); + return FALSE; + } + } + else + { + if ( !BiosInt13Read(CurrentlyOpenDriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, 1, Buffer) ) + { + DiskError("Disk read error."); + return FALSE; + } + } + + return TRUE; +} diff --git a/freeldr/freeldr/freeldr.c b/freeldr/freeldr/freeldr.c index 115b8a97491..55ea31a46ab 100644 --- a/freeldr/freeldr/freeldr.c +++ b/freeldr/freeldr/freeldr.c @@ -18,15 +18,14 @@ */ #include "freeldr.h" -#include "stdlib.h" +#include "rtl.h" #include "fs.h" -#include "reactos/reactos.h" -#include "tui.h" +#include "reactos.h" +#include "ui.h" #include "asmcode.h" -#include "menu.h" #include "miscboot.h" #include "linux.h" -#include "memory.h" +#include "mm.h" #include "parseini.h" #include "debug.h" #include "oslist.h" diff --git a/freeldr/freeldr/fs.h b/freeldr/freeldr/fs.h index b8c133eb11b..4cbfe5170fb 100644 --- a/freeldr/freeldr/fs.h +++ b/freeldr/freeldr/fs.h @@ -75,24 +75,11 @@ typedef struct _MASTER_BOOT_RECORD #define PARTITION_LDM 0x42 // Logical Disk Manager partition #define PARTITION_UNIX 0x63 // Unix -typedef struct _GEOMETRY -{ - ULONG Cylinders; - ULONG Heads; - ULONG Sectors; - ULONG BytesPerSector; - -} GEOMETRY, *PGEOMETRY; - #define FILE VOID #define PFILE FILE * VOID FileSystemError(PUCHAR ErrorString); BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber); -VOID SetDriveGeometry(ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector); -VOID SetVolumeProperties(ULONG HiddenSectors); -BOOL ReadMultipleLogicalSectors(ULONG SectorNumber, ULONG SectorCount, PVOID Buffer); -BOOL ReadLogicalSector(ULONG SectorNumber, PVOID Buffer); PFILE OpenFile(PUCHAR FileName); VOID CloseFile(PFILE FileHandle); BOOL ReadFile(PFILE FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Buffer); diff --git a/freeldr/freeldr/fs/Makefile b/freeldr/freeldr/fs/Makefile new file mode 100644 index 00000000000..cd2f5992bcb --- /dev/null +++ b/freeldr/freeldr/fs/Makefile @@ -0,0 +1,46 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +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 Makefile + $(CC) $(FLAGS) -o fs.o -c fs.c + +fat.o: fat.c fat.h ../fs.h Makefile + $(CC) $(FLAGS) -o fat.o -c fat.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/fat.c b/freeldr/freeldr/fs/fat.c similarity index 96% rename from freeldr/freeldr/fat.c rename to freeldr/freeldr/fs/fat.c index 0d73df061b9..0468a0eede6 100644 --- a/freeldr/freeldr/fat.c +++ b/freeldr/freeldr/fs/fat.c @@ -17,14 +17,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "fs.h" +#include +#include #include "fat.h" -#include "stdlib.h" -#include "tui.h" -#include "asmcode.h" -#include "memory.h" -#include "debug.h" +#include +#include +#include +#include +#include +#include PFAT_BOOTSECTOR FatVolumeBootSector = NULL; @@ -152,8 +153,8 @@ BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartHead, ULONG VolumeStartTr return FALSE; } - SetDriveGeometry(get_cylinders(DriveNumber), get_heads(DriveNumber), get_sectors(DriveNumber), FatVolumeBootSector->BytesPerSector); - SetVolumeProperties(FatVolumeBootSector->HiddenSectors); + DiskSetDriveGeometry(get_cylinders(DriveNumber), get_heads(DriveNumber), get_sectors(DriveNumber), FatVolumeBootSector->BytesPerSector); + DiskSetVolumeProperties(FatVolumeBootSector->HiddenSectors); // // Check the FAT cluster size @@ -267,7 +268,7 @@ PVOID FatBufferDirectory(UINT32 DirectoryStartCluster, PUINT32 EntryCountPointer RootDirectoryStartSector = FatVolumeBootSector->ReservedSectors + (FatVolumeBootSector->NumberOfFats * FatVolumeBootSector->SectorsPerFat); RootDirectorySectorCount = FatVolumeBootSector->RootDirEntries / 32; - if (!ReadMultipleLogicalSectors(RootDirectoryStartSector, RootDirectorySectorCount, DirectoryBuffer)) + if (!DiskReadMultipleLogicalSectors(RootDirectoryStartSector, RootDirectorySectorCount, DirectoryBuffer)) { FreeMemory(DirectoryBuffer); return NULL; @@ -698,14 +699,14 @@ DWORD FatGetFatEntry(DWORD nCluster) if (ThisFatEntOffset == (FatVolumeBootSector->BytesPerSector - 1)) { - if (!ReadMultipleLogicalSectors(ThisFatSecNum, 2, (PVOID)DISKREADBUFFER)) + if (!DiskReadMultipleLogicalSectors(ThisFatSecNum, 2, (PVOID)DISKREADBUFFER)) { return NULL; } } else { - if (!ReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) + if (!DiskReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) { return NULL; } @@ -725,7 +726,7 @@ DWORD FatGetFatEntry(DWORD nCluster) ThisFatSecNum = FatVolumeBootSector->ReservedSectors + (FatOffset / FatVolumeBootSector->BytesPerSector); ThisFatEntOffset = (FatOffset % FatVolumeBootSector->BytesPerSector); - if (!ReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) + if (!DiskReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) { return NULL; } @@ -740,7 +741,7 @@ DWORD FatGetFatEntry(DWORD nCluster) ThisFatSecNum = FatVolumeBootSector->ReservedSectors + (FatOffset / FatVolumeBootSector->BytesPerSector); ThisFatEntOffset = (FatOffset % FatVolumeBootSector->BytesPerSector); - if (!ReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) + if (!DiskReadLogicalSector(ThisFatSecNum, (PVOID)DISKREADBUFFER)) { return NULL; } @@ -885,7 +886,7 @@ BOOL FatReadCluster(ULONG ClusterNumber, PVOID Buffer) DbgPrint((DPRINT_FILESYSTEM, "FatReadCluster() ClusterNumber = %d Buffer = 0x%x ClusterStartSector = %d\n", ClusterNumber, Buffer, ClusterStartSector)); - if (!ReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) + if (!DiskReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) { return FALSE; } @@ -917,7 +918,7 @@ BOOL FatReadClusterChain(ULONG StartClusterNumber, ULONG NumberOfClusters, PVOID // // Read cluster into memory // - if (!ReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) + if (!DiskReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) { return FALSE; } @@ -965,7 +966,7 @@ BOOL FatReadPartialCluster(ULONG ClusterNumber, ULONG StartingOffset, ULONG Leng ClusterStartSector = ((ClusterNumber - 2) * FatVolumeBootSector->SectorsPerCluster) + DataSectorStart; - if (!ReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) + if (!DiskReadMultipleLogicalSectors(ClusterStartSector, FatVolumeBootSector->SectorsPerCluster, (PVOID)DISKREADBUFFER)) { return FALSE; } diff --git a/freeldr/freeldr/fat.h b/freeldr/freeldr/fs/fat.h similarity index 100% rename from freeldr/freeldr/fat.h rename to freeldr/freeldr/fs/fat.h diff --git a/freeldr/freeldr/fs.c b/freeldr/freeldr/fs/fs.c similarity index 69% rename from freeldr/freeldr/fs.c rename to freeldr/freeldr/fs/fs.c index 825030693d5..fdcc0f28b60 100644 --- a/freeldr/freeldr/fs.c +++ b/freeldr/freeldr/fs/fs.c @@ -17,13 +17,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "fs.h" +#include +#include #include "fat.h" -#include "stdlib.h" -#include "tui.h" -#include "asmcode.h" -#include "debug.h" +#include +#include +#include +#include +#include ///////////////////////////////////////////////////////////////////////////////////////////// @@ -230,136 +231,6 @@ BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber) return TRUE; } -VOID SetDriveGeometry(ULONG Cylinders, ULONG Heads, ULONG Sectors, ULONG BytesPerSector) -{ - DriveGeometry.Cylinders = Cylinders; - DriveGeometry.Heads = Heads; - DriveGeometry.Sectors = Sectors; - DriveGeometry.BytesPerSector = BytesPerSector; - - DbgPrint((DPRINT_FILESYSTEM, "DriveGeometry.Cylinders: %d\n", DriveGeometry.Cylinders)); - DbgPrint((DPRINT_FILESYSTEM, "DriveGeometry.Heads: %d\n", DriveGeometry.Heads)); - DbgPrint((DPRINT_FILESYSTEM, "DriveGeometry.Sectors: %d\n", DriveGeometry.Sectors)); - DbgPrint((DPRINT_FILESYSTEM, "DriveGeometry.BytesPerSector: %d\n", DriveGeometry.BytesPerSector)); -} - -VOID SetVolumeProperties(ULONG HiddenSectors) -{ - VolumeHiddenSectors = HiddenSectors; -} - -BOOL ReadMultipleLogicalSectors(ULONG SectorNumber, ULONG SectorCount, PVOID Buffer) -{ - /*BOOL bRetVal; - int PhysicalSector; - int PhysicalHead; - int PhysicalTrack; - int nNum; - - nSect += nHiddenSectors; - - while (nNumberOfSectors) - { - PhysicalSector = 1 + (nSect % nSectorsPerTrack); - PhysicalHead = (nSect / nSectorsPerTrack) % nNumberOfHeads; - PhysicalTrack = nSect / (nSectorsPerTrack * nNumberOfHeads); - - if (PhysicalSector > 1) - { - if (nNumberOfSectors >= (nSectorsPerTrack - (PhysicalSector - 1))) - nNum = (nSectorsPerTrack - (PhysicalSector - 1)); - else - nNum = nNumberOfSectors; - } - else - { - if (nNumberOfSectors >= nSectorsPerTrack) - nNum = nSectorsPerTrack; - else - nNum = nNumberOfSectors; - } - - bRetVal = biosdisk(CurrentlyOpenDriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, nNum, pBuffer); - - if (!bRetVal) - { - FS_DO_ERROR("Disk Error"); - return FALSE; - } - - pBuffer += (nNum * 512); - nNumberOfSectors -= nNum; - nSect += nNum; - }*/ - - ULONG CurrentSector; - PVOID RealBuffer = Buffer; - - for (CurrentSector=SectorNumber; CurrentSector<(SectorNumber + SectorCount); CurrentSector++) - { - if (!ReadLogicalSector(CurrentSector, RealBuffer) ) - { - return FALSE; - } - - RealBuffer += DriveGeometry.BytesPerSector; - } - - return TRUE; -} - -BOOL ReadLogicalSector(ULONG SectorNumber, PVOID Buffer) -{ - ULONG PhysicalSector; - ULONG PhysicalHead; - ULONG PhysicalTrack; - - DbgPrint((DPRINT_FILESYSTEM, "ReadLogicalSector() SectorNumber: %d Buffer: 0x%x\n", SectorNumber, Buffer)); - - SectorNumber += VolumeHiddenSectors; - PhysicalSector = 1 + (SectorNumber % DriveGeometry.Sectors); - PhysicalHead = (SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads; - PhysicalTrack = (SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads; - - //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalHead: %d\n", PhysicalHead)); - //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalTrack: %d\n", PhysicalTrack)); - //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalSector: %d\n", PhysicalSector)); - if (PhysicalHead >= DriveGeometry.Heads) - { - BugCheck((DPRINT_FILESYSTEM, "PhysicalHead >= DriveGeometry.Heads\nPhysicalHead = %d\nDriveGeometry.Heads = %d\n", PhysicalHead, DriveGeometry.Heads)); - } - if (PhysicalTrack >= DriveGeometry.Cylinders) - { - BugCheck((DPRINT_FILESYSTEM, "PhysicalTrack >= DriveGeometry.Cylinders\nPhysicalTrack = %d\nDriveGeometry.Cylinders = %d\n", PhysicalTrack, DriveGeometry.Cylinders)); - } - if (PhysicalSector > DriveGeometry.Sectors) - { - BugCheck((DPRINT_FILESYSTEM, "PhysicalSector > DriveGeometry.Sectors\nPhysicalSector = %d\nDriveGeometry.Sectors = %d\n", PhysicalSector, DriveGeometry.Sectors)); - } - - if ((CurrentlyOpenDriveNumber >= 0x80) && - (BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber)) && - (SectorNumber > (DriveGeometry.Cylinders * DriveGeometry.Heads * DriveGeometry.Sectors))) - { - DbgPrint((DPRINT_FILESYSTEM, "Using Int 13 Extensions for read. BiosInt13ExtensionsSupported(%d) = %s\n", CurrentlyOpenDriveNumber, BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber) ? "TRUE" : "FALSE")); - if ( !BiosInt13ReadExtended(CurrentlyOpenDriveNumber, SectorNumber, 1, Buffer) ) - { - FileSystemError("Disk read error."); - return FALSE; - } - } - else - { - if ( !BiosInt13Read(CurrentlyOpenDriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, 1, Buffer) ) - { - FileSystemError("Disk read error."); - return FALSE; - } - } - - return TRUE; -} - PFILE OpenFile(PUCHAR FileName) { PFILE FileHandle = NULL; diff --git a/freeldr/freeldr/linux.c b/freeldr/freeldr/linux.c index 6eedb47b9ed..7d86177dd42 100644 --- a/freeldr/freeldr/linux.c +++ b/freeldr/freeldr/linux.c @@ -21,9 +21,9 @@ #include "freeldr.h" #include "asmcode.h" #include "miscboot.h" -#include "stdlib.h" +#include "rtl.h" #include "fs.h" -#include "tui.h" +#include "ui.h" #include "linux.h" void LoadAndBootLinux(int DriveNum, int Partition, char *vmlinuz, char *cmd_line) diff --git a/freeldr/freeldr/miscboot.c b/freeldr/freeldr/miscboot.c index c084cc77ae8..6bd1a8d952d 100644 --- a/freeldr/freeldr/miscboot.c +++ b/freeldr/freeldr/miscboot.c @@ -21,9 +21,9 @@ #include "freeldr.h" #include "asmcode.h" #include "miscboot.h" -#include "stdlib.h" +#include "rtl.h" #include "fs.h" -#include "tui.h" +#include "ui.h" #include "parseini.h" void LoadAndBootBootSector(int nOSToBoot) diff --git a/freeldr/freeldr/memory.h b/freeldr/freeldr/mm.h similarity index 98% rename from freeldr/freeldr/memory.h rename to freeldr/freeldr/mm.h index b1113dff8d2..2bbdf21147e 100644 --- a/freeldr/freeldr/memory.h +++ b/freeldr/freeldr/mm.h @@ -21,7 +21,7 @@ #ifndef __MEMORY_H #define __MEMORY_H -#include "multiboot.h" +#include VOID InitMemoryManager(PVOID BaseAddress, ULONG Length); diff --git a/freeldr/freeldr/mm/Makefile b/freeldr/freeldr/mm/Makefile new file mode 100644 index 00000000000..742d1a2efdb --- /dev/null +++ b/freeldr/freeldr/mm/Makefile @@ -0,0 +1,43 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +OBJS = mm.o + +.PHONY : clean + +all: mm.a + +mm.a: $(OBJS) + $(LD) -r -o mm.a $(OBJS) + +mm.o: mm.c ../mm.h Makefile + $(CC) $(FLAGS) -o mm.o -c mm.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/memory.c b/freeldr/freeldr/mm/mm.c similarity index 97% rename from freeldr/freeldr/memory.c rename to freeldr/freeldr/mm/mm.c index 9f40d1dcfa2..24babccc351 100644 --- a/freeldr/freeldr/memory.c +++ b/freeldr/freeldr/mm/mm.c @@ -17,11 +17,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "memory.h" -#include "stdlib.h" -#include "debug.h" -#include "tui.h" +#include +#include +#include +#include +#include // @@ -72,8 +72,8 @@ VOID InitMemoryManager(PVOID BaseAddress, ULONG Length) HeapMemBlockArray = (PMEMBLOCK)(HeapBaseAddress + HeapLengthInBytes); // Clear the memory - ZeroMemory(HeapBaseAddress, HeapLengthInBytes); - ZeroMemory(HeapMemBlockArray, (HeapMemBlockCount * sizeof(MEMBLOCK))); + 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)); diff --git a/freeldr/freeldr/multiboot.c b/freeldr/freeldr/multiboot.c index 0e4fd7628a9..9b41a810b9c 100644 --- a/freeldr/freeldr/multiboot.c +++ b/freeldr/freeldr/multiboot.c @@ -20,10 +20,10 @@ #include "freeldr.h" #include "asmcode.h" -#include "stdlib.h" +#include "rtl.h" #include "fs.h" #include "multiboot.h" -#include "tui.h" +#include "ui.h" #include "parseini.h" unsigned long next_module_load_base = 0; diff --git a/freeldr/freeldr/options.c b/freeldr/freeldr/options.c index e779d0f6da7..c889f823322 100644 --- a/freeldr/freeldr/options.c +++ b/freeldr/freeldr/options.c @@ -18,8 +18,8 @@ */ #include "freeldr.h" -#include "stdlib.h" -#include "tui.h" +#include "rtl.h" +#include "ui.h" #include "options.h" #include "miscboot.h" diff --git a/freeldr/freeldr/oslist.c b/freeldr/freeldr/oslist.c index 9b58cf9273c..06d5f856146 100644 --- a/freeldr/freeldr/oslist.c +++ b/freeldr/freeldr/oslist.c @@ -20,9 +20,9 @@ #include "freeldr.h" #include "parseini.h" #include "oslist.h" -#include "stdlib.h" -#include "memory.h" -#include "tui.h" +#include "rtl.h" +#include "mm.h" +#include "ui.h" BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNamesPointer, PULONG OperatingSystemCountPointer) { diff --git a/freeldr/freeldr/parseini.c b/freeldr/freeldr/parseini.c index 681c1eba98c..cc2fa82d192 100644 --- a/freeldr/freeldr/parseini.c +++ b/freeldr/freeldr/parseini.c @@ -19,10 +19,10 @@ #include "freeldr.h" #include "parseini.h" -#include "tui.h" +#include "ui.h" #include "fs.h" -#include "stdlib.h" -#include "memory.h" +#include "rtl.h" +#include "mm.h" #include "debug.h" PUCHAR FreeLoaderIniFileData = NULL; diff --git a/freeldr/freeldr/arcname.h b/freeldr/freeldr/reactos.h similarity index 60% rename from freeldr/freeldr/arcname.h rename to freeldr/freeldr/reactos.h index 09dc3da1ac8..3a5e69ff2b7 100644 --- a/freeldr/freeldr/arcname.h +++ b/freeldr/freeldr/reactos.h @@ -1,8 +1,7 @@ /* - * FreeLoader - arcname.h + * FreeLoader * - * Copyright (C) 2001 Brian Palmer - * Copyright (C) 2001 Eric Kohl + * Copyright (C) 1999, 2000, 2001 Brian Palmer * * 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 @@ -19,11 +18,26 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef __ARCNAME_H -#define __ARCNAME_H +#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 __ARCNAME_H \ No newline at end of file + +#endif // defined __REACTOS_H \ No newline at end of file diff --git a/freeldr/freeldr/reactos/Makefile b/freeldr/freeldr/reactos/Makefile new file mode 100644 index 00000000000..824d5b026e6 --- /dev/null +++ b/freeldr/freeldr/reactos/Makefile @@ -0,0 +1,55 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +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 Makefile + $(CC) $(FLAGS) -o reactos.o -c reactos.c + +arcname.o: arcname.c ../reactos.h Makefile + $(CC) $(FLAGS) -o arcname.o -c arcname.c + +hwdetect.o: hwdetect.c ../reactos.h Makefile + $(CC) $(FLAGS) -o hwdetect.o -c hwdetect.c + +reghive.o: reghive.c ../reactos.h Makefile + $(CC) $(FLAGS) -o reghive.o -c reghive.c + +registry.o: registry.c ../reactos.h Makefile + $(CC) $(FLAGS) -o registry.o -c registry.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/arcname.c b/freeldr/freeldr/reactos/arcname.c similarity index 96% rename from freeldr/freeldr/arcname.c rename to freeldr/freeldr/reactos/arcname.c index 8860601c4d4..b099f28aa54 100644 --- a/freeldr/freeldr/arcname.c +++ b/freeldr/freeldr/reactos/arcname.c @@ -19,9 +19,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "arcname.h" -#include "stdlib.h" +#include +#include BOOL DissectArcPath(char *ArcPath, char *BootPath, PULONG BootDrive, PULONG BootPartition) diff --git a/freeldr/freeldr/reactos/hwdetect.c b/freeldr/freeldr/reactos/hwdetect.c index add0406a130..8782a5edead 100644 --- a/freeldr/freeldr/reactos/hwdetect.c +++ b/freeldr/freeldr/reactos/hwdetect.c @@ -18,8 +18,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "../freeldr.h" -#include "../stdlib.h" +#include +#include //#define NDEBUG diff --git a/freeldr/freeldr/reactos/reactos.c b/freeldr/freeldr/reactos/reactos.c index 14f12f3a3ba..abf1de4705a 100644 --- a/freeldr/freeldr/reactos/reactos.c +++ b/freeldr/freeldr/reactos/reactos.c @@ -18,16 +18,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "../freeldr.h" -#include "../asmcode.h" -#include "reactos.h" -#include "../stdlib.h" -#include "../fs.h" -#include "../tui.h" -#include "../multiboot.h" -#include "../arcname.h" -#include "../memory.h" -#include "../parseini.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "registry.h" #include "hwdetect.h" diff --git a/freeldr/freeldr/reactos/reactos.h b/freeldr/freeldr/reactos/reactos.h deleted file mode 100644 index fb907a3c8a7..00000000000 --- a/freeldr/freeldr/reactos/reactos.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * FreeLoader - * - * Copyright (C) 1999, 2000 Brian Palmer - * - * 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 - - -void LoadAndBootReactOS(PUCHAR OperatingSystemName); - - -#endif // defined __REACTOS_H \ No newline at end of file diff --git a/freeldr/freeldr/reactos/reghive.c b/freeldr/freeldr/reactos/reghive.c index f23f243f6e6..1eb9349ff36 100644 --- a/freeldr/freeldr/reactos/reghive.c +++ b/freeldr/freeldr/reactos/reghive.c @@ -19,9 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "../freeldr.h" -#include "../stdlib.h" -#include "../memory.h" +#include +#include +#include #include "registry.h" diff --git a/freeldr/freeldr/reactos/registry.c b/freeldr/freeldr/reactos/registry.c index f027b953aca..9434ba77006 100644 --- a/freeldr/freeldr/reactos/registry.c +++ b/freeldr/freeldr/reactos/registry.c @@ -25,9 +25,9 @@ * - Fix RegEnumValue(). */ -#include "../freeldr.h" -#include "../memory.h" -#include "../stdlib.h" +#include +#include +#include #include "registry.h" #define NDEBUG diff --git a/freeldr/freeldr/rs232.h b/freeldr/freeldr/rs232.h deleted file mode 100644 index 2f716e990fe..00000000000 --- a/freeldr/freeldr/rs232.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 2001 Brian Palmer - * 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); - - -#endif // defined __RS232_H \ No newline at end of file diff --git a/freeldr/freeldr/rtl.h b/freeldr/freeldr/rtl.h new file mode 100644 index 00000000000..3996325136e --- /dev/null +++ b/freeldr/freeldr/rtl.h @@ -0,0 +1,106 @@ +/* + * FreeLoader + * Copyright (C) 1999, 2000, 2001 Brian Palmer + * + * 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 + +/////////////////////////////////////////////////////////////////////////////////////// +// +// 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 + +/////////////////////////////////////////////////////////////////////////////////////// +// +// Screen Output Functions +// +/////////////////////////////////////////////////////////////////////////////////////// +void print(char *str); +void printf(char *fmt, ...); +void sprintf(char *buffer, char *format, ...); + + +#ifndef max +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef min +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#endif + + +#endif // defined __STDLIB_H \ No newline at end of file diff --git a/freeldr/freeldr/rtl/Makefile b/freeldr/freeldr/rtl/Makefile new file mode 100644 index 00000000000..d1450bcd703 --- /dev/null +++ b/freeldr/freeldr/rtl/Makefile @@ -0,0 +1,52 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +OBJS = memory.o print.o stdlib.o string.o + +.PHONY : clean + +all: rtl.a + +rtl.a: $(OBJS) + $(LD) -r -o rtl.a $(OBJS) + +memory.o: memory.c ../rtl.h Makefile + $(CC) $(FLAGS) -o memory.o -c memory.c + +print.o: print.c ../rtl.h Makefile + $(CC) $(FLAGS) -o print.o -c print.c + +stdlib.o: stdlib.c ../rtl.h Makefile + $(CC) $(FLAGS) -o stdlib.o -c stdlib.c + +string.o: string.c ../rtl.h Makefile + $(CC) $(FLAGS) -o string.o -c string.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/menu.h b/freeldr/freeldr/rtl/memory.c similarity index 51% rename from freeldr/freeldr/menu.h rename to freeldr/freeldr/rtl/memory.c index b30d0b6f26d..9c0d66226fe 100644 --- a/freeldr/freeldr/menu.h +++ b/freeldr/freeldr/rtl/memory.c @@ -17,9 +17,51 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef __MENU_H -#define __MENU_H +#include -BOOL DisplayMenu(PUCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, PULONG SelectedMenuItem); +int RtlCompareMemory(const PVOID Source1, const PVOID Source2, ULONG Length) +{ + ULONG i; + const PCHAR buffer1 = Source1; + const PCHAR buffer2 = Source2; -#endif // #defined __MENU_H \ No newline at end of file + for (i=0; i + * + * 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 + +/* + * print() - prints unformatted text to stdout + */ +void print(char *str) +{ + int i; + + for(i=0; i + */ +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; +} diff --git a/freeldr/freeldr/rtl/stdlib.c b/freeldr/freeldr/rtl/stdlib.c new file mode 100644 index 00000000000..e5401ffc200 --- /dev/null +++ b/freeldr/freeldr/rtl/stdlib.c @@ -0,0 +1,135 @@ +/* + * FreeLoader + * Copyright (C) 1999, 2000, 2001 Brian Palmer + * + * 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 + */ +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')); +} diff --git a/freeldr/freeldr/rtl/string.c b/freeldr/freeldr/rtl/string.c new file mode 100644 index 00000000000..f948643989b --- /dev/null +++ b/freeldr/freeldr/rtl/string.c @@ -0,0 +1,152 @@ +/* + * FreeLoader + * Copyright (C) 1999, 2000, 2001 Brian Palmer + * + * 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 + +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; +} diff --git a/freeldr/freeldr/stdlib.c b/freeldr/freeldr/stdlib.c deleted file mode 100644 index 18253e2ec10..00000000000 --- a/freeldr/freeldr/stdlib.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer - * - * 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 "stdlib.h" - -/* - * print() - prints unformatted text to stdout - */ -void print(char *str) -{ - int i; - - for(i=0; i - */ -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; -} - -/* - * printf() - prints formatted text to stdout - * from: - * GRUB -- GRand Unified Bootloader - * Copyright (C) 1996 Erich Boleyn - */ -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; -} - - -int strlen(char *str) -{ - int len; - - for(len=0; str[len] != '\0'; len++); - - return len; -} - -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 memcmp(const void *buf1, const void *buf2, size_t count) -{ - size_t i; - const char *buffer1 = buf1; - const char *buffer2 = buf2; - - for(i=0; i '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')); -} diff --git a/freeldr/freeldr/stdlib.h b/freeldr/freeldr/stdlib.h deleted file mode 100644 index f31334de998..00000000000 --- a/freeldr/freeldr/stdlib.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer - * - * 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 "fs.h" - -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 - -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); -char *itoa(int value, char *string, int radix); -int toupper(int c); -int tolower(int c); -int memcmp(const void *buf1, const void *buf2, size_t count); -void *memcpy(void *dest, const void *src, size_t count); -void *memset(void *dest, int c, size_t count); -char *fgets(char *string, int n, PFILE stream); -int atoi(char *string); - -#define ZeroMemory(Destination, Length) memset(Destination, 0, Length) - -int isspace(int c); -int isdigit(int c); -int isxdigit(int c); - - -void print(char *str); -void printf(char *fmt, ...); -void sprintf(char *buffer, char *format, ...); - -char *convert_to_ascii(char *buf, int c, ...); - -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); - -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 - -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - - -#endif // defined __STDLIB_H \ No newline at end of file diff --git a/freeldr/freeldr/tui.h b/freeldr/freeldr/ui.h similarity index 93% rename from freeldr/freeldr/tui.h rename to freeldr/freeldr/ui.h index 072ac5c7942..47178c1f744 100644 --- a/freeldr/freeldr/tui.h +++ b/freeldr/freeldr/ui.h @@ -143,4 +143,13 @@ void DrawProgressBar(int nPos); #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 \ No newline at end of file diff --git a/freeldr/freeldr/ui/Makefile b/freeldr/freeldr/ui/Makefile new file mode 100644 index 00000000000..6ad9eb13893 --- /dev/null +++ b/freeldr/freeldr/ui/Makefile @@ -0,0 +1,46 @@ +# +# FreeLoader +# Copyright (C) 1999, 2000, 2001 Brian Palmer +# +# 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 + +FLAGS = -Wall -fno-builtin -I../ -DDEBUG -O3 + +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 Makefile + $(CC) $(FLAGS) -o tui.o -c tui.c + +menu.o: menu.c ../ui.h Makefile + $(CC) $(FLAGS) -o menu.o -c menu.c + +clean: + $(RM) *.o + $(RM) *.a diff --git a/freeldr/freeldr/menu.c b/freeldr/freeldr/ui/menu.c similarity index 98% rename from freeldr/freeldr/menu.c rename to freeldr/freeldr/ui/menu.c index cb97c57fe0a..23f37e23102 100644 --- a/freeldr/freeldr/menu.c +++ b/freeldr/freeldr/ui/menu.c @@ -17,12 +17,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "stdlib.h" -#include "tui.h" -#include "menu.h" -#include "options.h" -#include "memory.h" +#include +#include +#include +#include +#include typedef struct diff --git a/freeldr/freeldr/tui.c b/freeldr/freeldr/ui/tui.c similarity index 99% rename from freeldr/freeldr/tui.c rename to freeldr/freeldr/ui/tui.c index f3cf79c2566..778cc2422ef 100644 --- a/freeldr/freeldr/tui.c +++ b/freeldr/freeldr/ui/tui.c @@ -17,12 +17,12 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "stdlib.h" -#include "tui.h" -#include "memory.h" -#include "debug.h" -#include "parseini.h" +#include +#include +#include +#include +#include +#include ULONG nScreenWidth = 80; // Screen Width ULONG nScreenHeight = 25; // Screen Height