Removed broken dma code

Some work on memory managment
Initialize FPU
Reset CR0.TS after task switch but floating point state is *not* saved
Work on floppy driver
Add versions of ide and vfatfs drivers compiled with debugging information

svn path=/trunk/; revision=1268
This commit is contained in:
David Welch 2000-07-19 14:18:20 +00:00
parent 6041051d6a
commit c3d5ea4e9b
21 changed files with 765 additions and 536 deletions

View file

@ -34,7 +34,7 @@ LOADERS = dos
#
# Select the device drivers and filesystems you want
#
DEVICE_DRIVERS = blue ide keyboard null parallel serial vidport
DEVICE_DRIVERS = blue ide keyboard null parallel serial vidport floppy
# DEVICE_DRIVERS = beep event floppy ide_test mouse sound test test1
FS_DRIVERS = vfat minix
# FS_DRIVERS = minix ext2 template
@ -54,7 +54,7 @@ clean: buildno_clean $(COMPONENTS:%=%_clean) $(DLLS:%=%_clean) $(LOADERS:%=%_cle
.PHONY: clean
floppy: make_floppy_dirs autoexec_floppy $(COMPONENTS:%=%_floppy) \
install_floppy: make_floppy_dirs autoexec_floppy $(COMPONENTS:%=%_floppy) \
$(DLLS:%=%_floppy) $(LOADERS:%=%_floppy) \
$(KERNEL_SERVICES:%=%_floppy) $(SUBSYS:%=%_floppy) \
$(APPS:%=%_floppy)

View file

@ -1,31 +1,52 @@
//
// FLOPPY.C - NEC-765/8272A floppy device driver
// written by Rex Jolliff
// with help from various other sources, including but not limited to:
// Art Baker's NT Device Driver Book, Linux Source, and the internet.
//
// Modification History:
// 08/19/98 RJJ Created.
//
// To do:
// FIXME: get it working
// FIXME: add support for DMA hardware
// FIXME: should add support for floppy tape/zip devices
/*
* FLOPPY.C - NEC-765/8272A floppy device driver
* written by Rex Jolliff
* with help from various other sources, including but not limited to:
* Art Baker's NT Device Driver Book, Linux Source, and the internet.
*
* Modification History:
* 08/19/98 RJJ Created.
*
* To do:
* FIXME: get it working
* FIXME: add support for DMA hardware
* FIXME: should add support for floppy tape/zip devices
*/
#include <ddk/ntddk.h>
#include "../../../ntoskrnl/include/internal/i386/io.h"
#include "floppy.h"
#include <debug.h>
#define VERSION "V0.0.1"
// --------------------------------------------------- File Statics
/* --------------------------------------------------- File Statics */
typedef struct _FLOPPY_CONTROLLER_PARAMETERS
/* from linux drivers/block/floppy.c */
#define FLOPPY_MAX_REPLIES (16)
typedef struct _FLOPPY_DEVICE_EXTENSION
{
int PortBase;
int Vector;
int IrqL;
int SynchronizeIrqL;
} FLOPPY_DEVICE_EXTENSION, *PFLOPPY_DEVICE_EXTENSION;
typedef struct _FLOPPY_CONTROLLER_EXTENSION
{
PKINTERRUPT Interrupt;
KSPIN_LOCK SpinLock;
FLOPPY_CONTROLLER_TYPE FDCType;
ULONG Number;
ULONG PortBase;
ULONG Vector;
} FLOPPY_CONTROLLER_EXTENSION, *PFLOPPY_CONTROLLER_EXTENSION;
typedef struct _FLOPPY_CONTROLLER_PARAMETERS
{
ULONG PortBase;
ULONG Vector;
ULONG IrqL;
ULONG SynchronizeIrqL;
KINTERRUPT_MODE InterruptMode;
KAFFINITY Affinity;
} FLOPPY_CONTROLLER_PARAMETERS, *PFLOPPY_CONTROLLER_PARAMETERS;
@ -57,255 +78,57 @@ FLOPPY_DEVICE_PARAMETERS DeviceTypes[] =
static BOOLEAN FloppyInitialized = FALSE;
// ------------------------------------------------------ Functions
/* Bits of main status register */
#define STATUS_BUSYMASK (0x0f)
#define STATUS_BUSY (0x10)
#define STATUS_DMA (0x20)
#define STATUS_DIR (0x40)
#define STATUS_READY (0x80)
// ModuleEntry
//
// DESCRIPTION:
// This function initializes the driver, locates and claims
// hardware resources, and creates various NT objects needed
// to process I/O requests.
//
// RUN LEVEL:
// PASSIVE_LEVEL
//
// ARGUMENTS:
// IN PDRIVER_OBJECT DriverObject System allocated Driver Object
// for this driver
// IN PUNICODE_STRING RegistryPath Name of registry driver service
// key
//
// RETURNS:
// NTSTATUS
#define FLOPPY_STATUS (4)
#define FLOPPY_DATA (5)
NTSTATUS
DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
#define FLOPPY_CMD_UNLK_FIFO 0x14
#define FLOPPY_CMD_LOCK_FIFO 0x94
/* ------------------------------------------------------ Functions */
static int
FloppyReadSTAT(ULONG PortBase)
{
NTSTATUS RC;
PFLOPPY_DEVICE_EXTENSION DeviceExtension;
// Export other driver entry points...
DriverObject->DriverStartIo = FloppyStartIo;
DriverObject->MajorFunction[IRP_MJ_CREATE] = FloppyDispatchOpenClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = FloppyDispatchOpenClose;
DriverObject->MajorFunction[IRP_MJ_READ] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FloppyDispatchDeviceControl;
// Try to detect controller and abort if it fails
if (!FloppyCreateController(DriverObject,
&ControllerParameters[0],
0))
{
DPRINT("Could not find floppy controller");
return STATUS_NO_SUCH_DEVICE;
}
return STATUS_SUCCESS;
return(inb_p(PortBase + FLOPPY_STATUS));
}
static BOOLEAN
FloppyCreateController(PDRIVER_OBJECT DriverObject,
PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters,
int Index)
/* waits until the fdc becomes ready */
static int
FloppyWaitUntilReady(WORD PortBase)
{
PFLOPPY_CONTROLLER_TYPE ControllerType;
PCONTROLLER_OBJECT ControllerObject;
PFLOPPY_CONTROLLER_EXTENSION ControllerExtension;
int Retries;
int Status;
/* Detect controller and determine type */
if (!FloppyGetControllerVersion(ControllerParameters, &ControllerType))
for (Retries = 0; Retries < FLOPPY_MAX_STAT_RETRIES; Retries++)
{
return FALSE;
Status = FloppyReadSTAT(PortBase);
if (Status & STATUS_READY)
{
return Status;
}
}
// FIXME: Register port ranges and interrupts with HAL
/* Create controller object for FDC */
ControllerObject = IoCreateController(sizeof(FLOPPY_CONTROLLER_EXTENSION));
if (ControllerObject == NULL)
if (FloppyInitialized)
{
DPRINT("Could not create controller object for controller %d\n",
Index);
return FALSE;
DPRINT("Getstatus times out (%x) on fdc %d\n",
Status,
PortBase);
}
// FIXME: fill out controller data
ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)
ControllerObject->ControllerExtension;
ControllerExtension->Number = Index;
ControllerExtension->PortBase = ControllerParameters->PortBase;
ControllerExtension->Vector = ControllerParameters->Vector;
ControllerExtension->FDCType = ControllerType;
/* Initialize the spin lock in the controller extension */
KeInitializeSpinLock(&ControllerExtension->SpinLock);
/* Register an interrupt handler for this controller */
RC = IoConnectInterrupt(&ControllerExtension->Interrupt,
FloppyIsr,
ControllerExtension,
&ControllerExtension->SpinLock,
ControllerExtension->Vector,
ControllerParameters->IrqL,
ControllerParameters->SynchronizeIrqL,
ControllerParameters->InterruptMode,
FALSE,
ControllerParameters->Affinity,
FALSE);
if (!NT_SUCCESS(RC))
{
DPRINT("Could not Connect Interrupt %d\n", ControllerExtension->Vector);
IoDeleteController(ControllerObject);
return FALSE;
}
// FIXME: setup DMA stuff for controller
// Check for each possible drive and create devices for them
for (DriveIdx = 0; DriveIdx < FLOPPY_MAX_DRIVES; DriveIdx++)
{
// FIXME: try to identify the drive
// FIXME: create a device if it's there
}
return STATUS_SUCCESS;
return -1;
}
// FloppyGetControllerVersion
//
// DESCRIPTION
// Get the type/version of the floppy controller
//
// RUN LEVEL:
// PASSIVE_LEVEL
//
// ARGUMENTS:
// IN OUT PFLOPPY_DEVICE_EXTENSION DeviceExtension
//
// RETURNS:
// BOOL success or failure
//
// COMMENTS:
// This routine (get_fdc_version) was originally written by David C. Niemi
//
static BOOLEAN
FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters,
OUT PFLOPPY_CONTROLLER_TYPE ControllerType)
static VOID
FloppyWriteData(WORD PortBase, BYTE Byte)
{
BYTE ResultReturned
BYTE Result[FLOPPY_MAX_REPLIES];
int ResultLength;
/* 82072 and better know DUMPREGS */
if (!FloppyWriteCommandByte(ControllerParameters->PortBase,
FLOPPY_CMD_DUMP_FDC))
{
return FALSE;
}
ResultLength = FloppyReadResultCode(PortBase, &Result));
if (ResultLength < 0)
{
return FALSE;
}
/* 8272a/765 don't know DUMPREGS */
if ((ResultLength == 1) && (Result[0] == 0x80))
{
DPRINT("FDC %d is an 8272A\n", PortBase);
*ControllerType = FDC_8272A;
return TRUE;
}
if (r != 10)
{
DPRINT("FDC %d init: DUMP_FDC: unexpected return of %d bytes.\n",
PortBase,
ResultLength);
return FALSE;
}
if (!FloppyConfigure(PortBase, FALSE, 0x0a))
{
DPRINT("FDC %d is an 82072\n", PortBase);
*ControllerType = FDC_82072;
return TRUE;
}
FloppyWriteCommandByte(PortBase, FLOPPY_CMD_PPND_RW);
if (FloppyNeedsMoreOutput(PortBase, Result) == FLOPPY_NEEDS_OUTPUT)
{
FloppyWriteCommandByte(PortBase, 0);
}
else
{
DPRINT("FDC %d is an 82072A\n", PortBase);
*ControllerType = FDC_82072A;
return TRUE;
}
/* Pre-1991 82077, doesn't know LOCK/UNLOCK */
FloppyWriteCommandByte(PortBase, FLOPPY_CMD_UNLK_FIFO);
ResultLength = FloppyReadResultCode(PortBase, &Result));
if ((ResultLength == 1) && (Result[0] == 0x80))
{
DPRINT("FDC %d is a pre-1991 82077\n", PortBase);
*ControllerType = FDC_82077_ORIG;
return TRUE;
}
if ((ResultLength != 1) || (Result[0] != 0x00))
{
DPRINT("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
PortBase,
ResultLength);
return FALSE;
}
/* Revised 82077AA passes all the tests */
FloppyWriteCommandByte(PortBase, FLOPPY_CMD_PARTID);
ResultLength = FloppyReadResultCode(PortBase, &Result));
if (ResultLength != 1)
{
DPRINT("FDC %d init: PARTID: unexpected return of %d bytes.\n",
PortBase,
ResultLength);
return FALSE;
}
if (Result[0] == 0x80)
{
DPRINT("FDC %d is a post-1991 82077\n", PortBase);
*ControllerType = FDC_82077;
return TRUE;
}
switch (Result[0] >> 5)
{
case 0x0:
/* Either a 82078-1 or a 82078SL running at 5Volt */
DPRINT("FDC %d is an 82078.\n", PortBase);
*ControllerType = FDC_82078;
return TRUE;
case 0x1:
DPRINT("FDC %d is a 44pin 82078\n", PortBase);
*ControllerType = FDC_82078;
return TRUE;
case 0x2:
DPRINT("FDC %d is a S82078B\n", PortBase);
*ControllerType = FDC_S82078B;
return TRUE;
case 0x3:
DPRINT("FDC %d is a National Semiconductor PC87306\n", PortBase);
*ControllerType = FDC_87306;
return TRUE;
default:
DPRINT("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
PortBase,
Result[0] >> 5);
*ControllerType = FDC_82078_UNKN;
return TRUE;
}
outb_p(PortBase + FLOPPY_DATA, Byte);
}
/* sends a command byte to the fdc */
@ -314,7 +137,7 @@ FloppyWriteCommandByte(WORD PortBase, BYTE Byte)
{
int Status;
if ((Status = FloppyWaitUntilReady()) < 0)
if ((Status = FloppyWaitUntilReady(PortBase)) < 0)
{
return FALSE;
}
@ -338,7 +161,7 @@ FloppyWriteCommandByte(WORD PortBase, BYTE Byte)
/* gets the response from the fdc */
static int
FloppyReadResultCode(WORD PortBase, PBYTE Result)
FloppyReadResultCode(WORD PortBase, PUCHAR Result)
{
int Replies;
int Status;
@ -356,7 +179,7 @@ FloppyReadResultCode(WORD PortBase, PBYTE Result)
}
if (Status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
{
Result[Replies] = fd_inb(FD_DATA);
Result[Replies] = inb_p(FLOPPY_DATA);
}
else
{
@ -375,37 +198,10 @@ FloppyReadResultCode(WORD PortBase, PBYTE Result)
return -1;
}
/* waits until the fdc becomes ready */
static int
FloppyWaitUntilReady(WORD PortBase)
{
int Retries;
int Status;
for (Retries = 0; Retries < FLOPPY_MAX_STAT_RETRIES; Retries++)
{
status = FloppyReadSTAT(PortBase);
if (Status & STATUS_READY)
{
return Status;
}
}
if (FloppyInitialized)
{
DPRINT("Getstatus times out (%x) on fdc %d\n",
Status,
PortBase);
}
return -1;
}
#define MORE_OUTPUT -2
/* does the fdc need more output? */
static int
FloppyNeedsMoreOutput(WORD PortBase, PBYTE Result)
FloppyNeedsMoreOutput(WORD PortBase, PUCHAR Result)
{
int Status;
@ -425,8 +221,8 @@ FloppyConfigure(WORD PortBase, BOOLEAN DisableFIFO, BYTE FIFODepth)
BYTE Result[FLOPPY_MAX_REPLIES];
/* Turn on FIFO */
FloppyWriteCommandByte(FLOPPY_CMD_CFG_FIFO);
if (FloppyNeedsOutput(PortBase, Result) != FLOPPY_NEEDS_OUTPUT)
FloppyWriteCommandByte(PortBase, FLOPPY_CMD_CFG_FIFO);
if (FloppyNeedsMoreOutput(PortBase, Result) != FLOPPY_NEEDS_OUTPUT)
{
return FALSE;
}
@ -441,4 +237,315 @@ FloppyConfigure(WORD PortBase, BOOLEAN DisableFIFO, BYTE FIFODepth)
return TRUE;
}
/* FloppyGetControllerVersion
*
* DESCRIPTION
* Get the type/version of the floppy controller
*
* RUN LEVEL:
* PASSIVE_LEVEL
*
* ARGUMENTS:
* IN OUT PFLOPPY_DEVICE_EXTENSION DeviceExtension
*
* RETURNS:
* BOOL success or failure
*
* COMMENTS:
* This routine (get_fdc_version) was originally written by David C. Niemi
*/
static BOOLEAN
FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters,
OUT PFLOPPY_CONTROLLER_TYPE ControllerType)
{
ULONG ResultLength;
UCHAR Result[FLOPPY_MAX_REPLIES];
/* 82072 and better know DUMPREGS */
if (!FloppyWriteCommandByte(ControllerParameters->PortBase,
FLOPPY_CMD_DUMP_FDC))
{
DPRINT("Failed to write command byte\n");
return FALSE;
}
ResultLength = FloppyReadResultCode(ControllerParameters->PortBase,
Result);
if (ResultLength < 0)
{
return FALSE;
}
/* 8272a/765 don't know DUMPREGS */
if ((ResultLength == 1) && (Result[0] == 0x80))
{
DPRINT("FDC %d is an 8272A\n", ControllerParameters->PortBase);
*ControllerType = FDC_8272A;
return TRUE;
}
if (ResultLength != 10)
{
DPRINT("FDC %d init: DUMP_FDC: unexpected return of %d bytes.\n",
ControllerParameters->PortBase,
ResultLength);
return FALSE;
}
if (!FloppyConfigure(ControllerParameters->PortBase, FALSE, 0x0a))
{
DPRINT("FDC %d is an 82072\n", ControllerParameters->PortBase);
*ControllerType = FDC_82072;
return TRUE;
}
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PPND_RW);
if (FloppyNeedsMoreOutput(ControllerParameters->PortBase, Result) ==
FLOPPY_NEEDS_OUTPUT)
{
FloppyWriteCommandByte(ControllerParameters->PortBase, 0);
}
else
{
DPRINT("FDC %d is an 82072A\n", ControllerParameters->PortBase);
*ControllerType = FDC_82072A;
return TRUE;
}
/* Pre-1991 82077, doesn't know LOCK/UNLOCK */
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_UNLK_FIFO);
ResultLength = FloppyReadResultCode(ControllerParameters->PortBase,
Result);
if ((ResultLength == 1) && (Result[0] == 0x80))
{
DPRINT("FDC %d is a pre-1991 82077\n", ControllerParameters->PortBase);
*ControllerType = FDC_82077_ORIG;
return TRUE;
}
if ((ResultLength != 1) || (Result[0] != 0x00))
{
DPRINT("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
ControllerParameters->PortBase,
ResultLength);
return FALSE;
}
/* Revised 82077AA passes all the tests */
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PARTID);
ResultLength = FloppyReadResultCode(ControllerParameters->PortBase,
Result);
if (ResultLength != 1)
{
DPRINT("FDC %d init: PARTID: unexpected return of %d bytes.\n",
ControllerParameters->PortBase,
ResultLength);
return FALSE;
}
if (Result[0] == 0x80)
{
DPRINT("FDC %d is a post-1991 82077\n", ControllerParameters->PortBase);
*ControllerType = FDC_82077;
return TRUE;
}
switch (Result[0] >> 5)
{
case 0x0:
/* Either a 82078-1 or a 82078SL running at 5Volt */
DPRINT("FDC %d is an 82078.\n", ControllerParameters->PortBase);
*ControllerType = FDC_82078;
return TRUE;
case 0x1:
DPRINT("FDC %d is a 44pin 82078\n", ControllerParameters->PortBase);
*ControllerType = FDC_82078;
return TRUE;
case 0x2:
DPRINT("FDC %d is a S82078B\n", ControllerParameters->PortBase);
*ControllerType = FDC_S82078B;
return TRUE;
case 0x3:
DPRINT("FDC %d is a National Semiconductor PC87306\n",
ControllerParameters->PortBase);
*ControllerType = FDC_87306;
return TRUE;
default:
DPRINT("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
ControllerParameters->PortBase,
Result[0] >> 5);
*ControllerType = FDC_82078_UNKN;
return TRUE;
}
}
static BOOLEAN
FloppyIsr(PKINTERRUPT Interrupt, PVOID ServiceContext)
{
return(TRUE);
}
static BOOLEAN
FloppyCreateController(PDRIVER_OBJECT DriverObject,
PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters,
int Index)
{
FLOPPY_CONTROLLER_TYPE ControllerType;
PCONTROLLER_OBJECT ControllerObject;
PFLOPPY_CONTROLLER_EXTENSION ControllerExtension;
UNICODE_STRING DeviceName;
UNICODE_STRING SymlinkName;
NTSTATUS Status;
PDEVICE_OBJECT DeviceObject;
/* Detect controller and determine type */
if (!FloppyGetControllerVersion(ControllerParameters, &ControllerType))
{
DPRINT("Failed to get controller version\n");
return FALSE;
}
/* FIXME: Register port ranges and interrupts with HAL */
/* Create controller object for FDC */
ControllerObject = IoCreateController(sizeof(FLOPPY_CONTROLLER_EXTENSION));
if (ControllerObject == NULL)
{
DPRINT("Could not create controller object for controller %d\n",
Index);
return FALSE;
}
/* FIXME: fill out controller data */
ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)
ControllerObject->ControllerExtension;
ControllerExtension->Number = Index;
ControllerExtension->PortBase = ControllerParameters->PortBase;
ControllerExtension->Vector = ControllerParameters->Vector;
ControllerExtension->FDCType = ControllerType;
/* Initialize the spin lock in the controller extension */
KeInitializeSpinLock(&ControllerExtension->SpinLock);
/* Register an interrupt handler for this controller */
Status = IoConnectInterrupt(&ControllerExtension->Interrupt,
FloppyIsr,
ControllerExtension,
&ControllerExtension->SpinLock,
ControllerExtension->Vector,
ControllerParameters->IrqL,
ControllerParameters->SynchronizeIrqL,
ControllerParameters->InterruptMode,
FALSE,
ControllerParameters->Affinity,
FALSE);
if (!NT_SUCCESS(Status))
{
DPRINT("Could not Connect Interrupt %d\n",
ControllerExtension->Vector);
IoDeleteController(ControllerObject);
return FALSE;
}
/* FIXME: setup DMA stuff for controller */
#if 0
/* Check for each possible drive and create devices for them */
for (DriveIdx = 0; DriveIdx < FLOPPY_MAX_DRIVES; DriveIdx++)
{
/* FIXME: try to identify the drive */
/* FIXME: create a device if it's there */
}
#endif
/* FIXME: Let's assume one drive and one controller for the moment */
RtlInitUnicodeString(&DeviceName, L"\\Device\\Floppy0");
Status = IoCreateDevice(DriverObject,
sizeof(FLOPPY_DEVICE_EXTENSION),
&DeviceName,
FILE_DEVICE_DISK,
FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(Status))
{
IoDisconnectInterrupt(ControllerExtension->Interrupt);
IoDeleteController(ControllerObject);
}
/* Initialize the device */
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
DeviceObject->AlignmentRequirement = FILE_WORD_ALIGNMENT;
/* Create a symlink */
RtlInitUnicodeString(&SymlinkName, L"\\??\\A:");
IoCreateSymbolicLink(&SymlinkName, &DeviceName);
return STATUS_SUCCESS;
}
VOID FloppyStartIo(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
}
NTSTATUS FloppyDispatchOpenClose(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
return(STATUS_UNSUCCESSFUL);
}
NTSTATUS FloppyDispatchReadWrite(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
return(STATUS_UNSUCCESSFUL);
}
NTSTATUS FloppyDispatchDeviceControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
return(STATUS_UNSUCCESSFUL);
}
/* ModuleEntry
*
* DESCRIPTION:
* This function initializes the driver, locates and claims
* hardware resources, and creates various NT objects needed
* to process I/O requests.
*
* RUN LEVEL:
* PASSIVE_LEVEL
*
* ARGUMENTS:
* IN PDRIVER_OBJECT DriverObject System allocated Driver Object
* for this driver
* IN PUNICODE_STRING RegistryPath Name of registry driver service
* key
*
* RETURNS:
* NTSTATUS
*/
NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
DbgPrint("Floppy driver\n");
/* Export other driver entry points... */
DriverObject->DriverStartIo = FloppyStartIo;
DriverObject->MajorFunction[IRP_MJ_CREATE] = FloppyDispatchOpenClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = FloppyDispatchOpenClose;
DriverObject->MajorFunction[IRP_MJ_READ] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
FloppyDispatchDeviceControl;
/* Try to detect controller and abort if it fails */
if (!FloppyCreateController(DriverObject,
&ControllerParameters[0],
0))
{
DPRINT("Could not find floppy controller\n");
return STATUS_NO_SUCH_DEVICE;
}
return STATUS_SUCCESS;
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.11 2000/06/29 23:35:48 dwelch Exp $
# $Id: makefile,v 1.12 2000/07/19 14:18:20 dwelch Exp $
#
#
TARGET=ide
@ -7,7 +7,7 @@ OBJECTS = $(TARGET).o $(TARGET).coff ../../../ntoskrnl/ntoskrnl.a
BASE_CFLAGS = -I. -I../../../include
all: $(TARGET).sys
all: $(TARGET).nostrip.sys $(TARGET).sys
.phony: all
@ -40,6 +40,7 @@ else
endif
$(TARGET).sys: $(OBJECTS)
$(STRIP) --strip-debug $(OBJECTS)
$(CC) \
-specs=../../svc_specs \
-mdll \
@ -66,4 +67,33 @@ $(TARGET).sys: $(OBJECTS)
$(OBJECTS)
- $(RM) temp.exp
$(TARGET).nostrip.sys: $(OBJECTS)
$(CC) \
-specs=../../svc_specs \
-mdll \
-o junk.tmp \
-Wl,--defsym,_end=end \
-Wl,--defsym,_edata=__data_end__ \
-Wl,--defsym,_etext=etext \
-Wl,--base-file,base.tmp $(OBJECTS)
- $(RM) junk.tmp
$(DLLTOOL) \
--dllname $(TARGET).sys \
--base-file base.tmp \
--output-exp temp.exp \
--kill-at
- $(RM) base.tmp
$(CC) \
--verbose \
-Wl,--image-base,0x10000 \
-Wl,-e,_DriverEntry@8 \
-Wl,temp.exp \
-specs=../../svc_specs \
-mdll \
-o $(TARGET).nostrip.sys \
$(OBJECTS)
- $(RM) temp.exp
WITH_DEBUGGING=yes
include ../../../rules.mak

View file

@ -1,4 +1,4 @@
# $Id: makefile_rex,v 1.10 2000/05/14 13:10:00 dwelch Exp $
# $Id: makefile_rex,v 1.11 2000/07/19 14:18:20 dwelch Exp $
#
# Minix IFS Driver makefile
#
@ -27,7 +27,35 @@ clean:
minix.o: $(OBJECTS)
$(LD) -r $(OBJECTS) -o minix.o
minixfs.nostrip.sys: $(OBJECTS)
$(CC) \
-specs=../../svc_specs \
-mdll \
-o junk.tmp \
-Wl,--defsym,_end=end \
-Wl,--defsym,_edata=__data_end__ \
-Wl,--defsym,_etext=etext \
-Wl,--base-file,base.tmp \
$(OBJECTS)
- $(RM) junk.tmp
$(DLLTOOL) \
--dllname $(TARGETNAME).sys \
--base-file base.tmp \
--output-exp temp.exp
- $(RM) base.tmp
$(CC) \
--verbose \
-Wl,--image-base,0x10000 \
-Wl,-e,_DriverEntry@8 \
-specs=../../svc_specs \
-mdll \
-o $(TARGETNAME).nostrip.sys \
$(OBJECTS) \
-Wl,temp.exp
- $(RM) temp.exp
minixfs.sys: $(OBJECTS)
$(STRIP) --strip-debug $(OBJECTS)
$(CC) \
-specs=../../svc_specs \
-mdll \
@ -76,5 +104,6 @@ endif
WIN32_LEAN_AND_MEAN = yes
WARNINGS_ARE_ERRORS = yes
WITH_DEBUGGING = yes
include ../../../rules.mak
# EOF

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.17 2000/07/07 02:14:14 ekohl Exp $
# $Id: makefile,v 1.18 2000/07/19 14:18:20 dwelch Exp $
#
#
TARGET=vfatfs
@ -9,7 +9,7 @@ LIBS = ../../../ntoskrnl/ntoskrnl.a
BASE_CFLAGS = -I. -I../../../include
all: $(TARGET).sys
all: $(TARGET).nostrip.sys $(TARGET).sys
.phony: all
@ -45,7 +45,21 @@ else
$(CP) $(TARGET).sys ../../../$(DIST_DIR)/drivers/$(TARGET).sys
endif
$(TARGET).nostrip.sys: $(OBJECTS) $(LIBS)
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" $(OBJECTS) $(LIBS)
- $(RM) junk.tmp
$(DLLTOOL) \
--dllname $(TARGET).sys \
--base-file base.tmp \
--output-exp temp.exp \
--def vfatfs.def
- $(RM) base.tmp
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).nostrip.sys $(OBJECTS) $(LIBS)
- $(RM) temp.exp
$(TARGET).sys: $(OBJECTS) $(LIBS)
$(STRIP) --strip-debug $(OBJECTS)
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" $(OBJECTS) $(LIBS)
- $(RM) junk.tmp
$(DLLTOOL) \
@ -57,6 +71,6 @@ $(TARGET).sys: $(OBJECTS) $(LIBS)
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).sys $(OBJECTS) $(LIBS)
- $(RM) temp.exp
WITH_DEBUGGING=yes
WARNINGS_ARE_ERRORS = yes
include ../../../rules.mak

View file

@ -8,9 +8,11 @@ cp loaders/dos/loadros.com $1
cp ntoskrnl/ntoskrnl.exe $1
cp services/fs/vfat/vfatfs.sys $1
cp services/dd/ide/ide.sys $1
#cp services/dd/floppy/floppy.sys $1
cp ntoskrnl/ntoskrnl.exe $1/reactos/system32/
cp services/fs/vfat/vfatfs.sys $1/reactos/system32/drivers/
cp services/dd/ide/ide.sys $1/reactos/system32/drivers/
#cp services/dd/floppy/floppy.sys $1/reactos/system32/drivers/
cp services/dd/keyboard/keyboard.sys $1/reactos/system32/drivers
cp services/dd/blue/blue.sys $1/reactos/system32/drivers
#cp services/dd/vga/miniport/vgamp.sys $1/reactos/system32/drivers

View file

@ -4,6 +4,7 @@ mount -t vfat /bochs/1.44a /mnt/floppy -o loop,rw
./install-system.sh /mnt/floppy
umount /mnt/floppy
echo "Installing to disk."
mount -t vfat /bochs/10M.vga /mnt/floppy -o loop,offset=8704,rw
mount -t vfat /bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
#mount -t minix /bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
./install.sh /mnt/floppy
umount /mnt/floppy

View file

@ -27,3 +27,4 @@ cp apps/event/event.exe $1/reactos/bin
cp apps/file/file.exe $1/reactos/bin
cp apps/pteb/pteb.exe $1/reactos/bin
cp apps/consume/consume.exe $1/reactos/bin
cp apps/float/float.exe $1/reactos/bin

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.48 2000/05/14 13:10:00 dwelch Exp $
# $Id: makefile,v 1.49 2000/07/19 14:18:17 dwelch Exp $
#
# ReactOS Operating System
#
@ -121,5 +121,6 @@ else
$(CP) $(TARGET).dll ../../$(DIST_DIR)/dlls/$(TARGET).dll
endif
WITH_DEBUGGING=yes
#WARNINGS_ARE_ERRORS = yes
include ../../rules.mak

View file

@ -886,24 +886,37 @@ BOOL STDCALL RtlDestroyHeap(
* Pointer to allocated memory block
* NULL: Failure
*/
PVOID STDCALL RtlAllocateHeap(
HANDLE heap, /* [in] Handle of private heap block */
ULONG flags, /* [in] Heap allocation control flags */
ULONG size /* [in] Number of bytes to allocate */
) {
ARENA_FREE *pArena;
ARENA_INUSE *pInUse;
SUBHEAP *subheap;
HEAP *heapPtr = HEAP_GetPtr( heap );
/* Validate the parameters */
if (!heapPtr) return NULL;
flags &= HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY;
flags |= heapPtr->flags;
if (!(flags & HEAP_NO_SERIALIZE)) RtlLockHeap( heap );
size = (size + 3) & ~3;
if (size < HEAP_MIN_BLOCK_SIZE) size = HEAP_MIN_BLOCK_SIZE;
PVOID STDCALL
RtlAllocateHeap(HANDLE heap, /* [in] Handle of private heap block */
ULONG flags, /* [in] Heap allocation control flags */
ULONG size /* [in] Number of bytes to allocate */)
{
ARENA_FREE* pArena;
ARENA_INUSE* pInUse;
SUBHEAP* subheap;
HEAP* heapPtr = NULL;
DPRINT("RtlAllocateHeap(heap 0x%x, flags 0x%x, size %d)\n",
heap, flags, size);
/* Validate the parameters */
heapPtr = HEAP_GetPtr(heap);
if (!heapPtr)
{
return NULL;
}
flags &= HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY;
flags |= heapPtr->flags;
if (!(flags & HEAP_NO_SERIALIZE))
{
RtlLockHeap(heap);
}
size = (size + 3) & ~3;
if (size < HEAP_MIN_BLOCK_SIZE)
{
size = HEAP_MIN_BLOCK_SIZE;
}
/* Locate a suitable free block */
@ -911,9 +924,9 @@ PVOID STDCALL RtlAllocateHeap(
{
DPRINT("(%08x,%08lx,%08lx): returning NULL\n",
heap, flags, size );
if (!(flags & HEAP_NO_SERIALIZE)) RtlUnlockHeap( heap );
// SetLastError( ERROR_COMMITMENT_LIMIT );
return NULL;
if (!(flags & HEAP_NO_SERIALIZE)) RtlUnlockHeap( heap );
/* SetLastError( ERROR_COMMITMENT_LIMIT ); */
return NULL;
}
/* Remove the arena from the free list */
@ -927,7 +940,7 @@ PVOID STDCALL RtlAllocateHeap(
pInUse->size = (pInUse->size & ~ARENA_FLAG_FREE)
+ sizeof(ARENA_FREE) - sizeof(ARENA_INUSE);
pInUse->callerEIP = *((DWORD *)&heap - 1); /* hack hack */
// pInUse->threadId = GetCurrentTask();
/* pInUse->threadId = GetCurrentTask(); */
pInUse->magic = ARENA_INUSE_MAGIC;
/* Shrink the block */

View file

@ -34,7 +34,7 @@ org 100h
;
BITS 16
%define NDEBUG 1
;%define NDEBUG 1
%macro DPRINT 1+
%ifndef NDEBUG
@ -195,7 +195,7 @@ l16:
;
; Begin the pmode initalization
;
jmp _to_pmode
;jmp _to_pmode
exit:
mov ax,04c00h

View file

@ -1,4 +1,4 @@
/* $Id: adapter.c,v 1.1 2000/03/26 19:38:18 ea Exp $
/* $Id: adapter.c,v 1.2 2000/07/19 14:18:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -19,55 +19,43 @@
/* NOTE: IoAllocateAdapterChannel in NTOSKRNL.EXE */
BOOLEAN
STDCALL
IoFlushAdapterBuffers (
PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
ULONG Length,
BOOLEAN WriteToDevice
)
BOOLEAN STDCALL
IoFlushAdapterBuffers (PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
ULONG Length,
BOOLEAN WriteToDevice)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}
VOID
STDCALL
IoFreeAdapterChannel (
PADAPTER_OBJECT AdapterObject
)
VOID STDCALL
IoFreeAdapterChannel (PADAPTER_OBJECT AdapterObject)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}
VOID
STDCALL
IoFreeMapRegisters (
PADAPTER_OBJECT AdapterObject,
PVOID MapRegisterBase,
ULONG NumberOfMapRegisters
)
VOID STDCALL
IoFreeMapRegisters (PADAPTER_OBJECT AdapterObject,
PVOID MapRegisterBase,
ULONG NumberOfMapRegisters)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}
PHYSICAL_ADDRESS
STDCALL
IoMapTransfer (
PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
PULONG Length,
BOOLEAN WriteToDevice
)
PHYSICAL_ADDRESS STDCALL
IoMapTransfer (PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
PULONG Length,
BOOLEAN WriteToDevice)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}

View file

@ -1,4 +1,4 @@
/* $Id: dma.c,v 1.7 2000/07/01 18:23:06 ekohl Exp $
/* $Id: dma.c,v 1.8 2000/07/19 14:18:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -15,51 +15,13 @@
#include <internal/debug.h>
/* TYPES *********************************************************************/
#define MAP_REGISTER_SIZE (PAGESIZE)
#define NR_MAP_REGISTERS (32)
typedef struct
{
PVOID VirtualAddress;
PVOID PhysicalAddress;
} MAP_REGISTER, *PMAP_REGISTER;
/*
typedef struct _ADAPTER_OBJECT
{
DEVICE_DESCRIPTION desc;
KDEVICE_QUEUE wait_queue;
} ADAPTER_OBJECT, *PADAPTER_OBJECT
*/
/* GLOBALS *******************************************************************/
static PMAP_REGISTER map_registers[];
/* FUNCTIONS *****************************************************************/
VOID HalInitializeAdapterSupport(VOID)
{
/* ?? */
}
ULONG HalGetDmaAlignmentRequirement()
/*
* FUNCTION: Returns the size of the cache boundary
*/
{
return(1);
}
PVOID
STDCALL
HalAllocateCommonBuffer (
PADAPTER_OBJECT AdapterObject,
ULONG Length,
PPHYSICAL_ADDRESS LogicalAddress,
BOOLEAN CacheEnabled
)
PVOID STDCALL
HalAllocateCommonBuffer (PADAPTER_OBJECT AdapterObject,
ULONG Length,
PPHYSICAL_ADDRESS LogicalAddress,
BOOLEAN CacheEnabled)
/*
* FUNCTION: Allocates memory that is visible to both the processor(s) and
* a dma device
@ -74,61 +36,35 @@ HalAllocateCommonBuffer (
* NULL on failure
*/
{
/*
PVOID Buffer;
PHYSICAL_ADDRESS highest_address;
highest_address.HighPart = 0;
if (AdapterObject->Desc.Dma32BitAddresses )
{
highest_address.LowPart = 0xffffffff;
}
else
{
highest_address.LowPart = 0xfffff;
}
Buffer = MmAllocateContiguousMemory(Length,&highest_address);
LogicalAddress->HighPart = 0;
LogicalAddress->LowPart = MmGetPhysicalAddress(Buffer);
return(Buffer);*/
return NULL;
UNIMPLEMENTED;
}
BOOLEAN
STDCALL
HalFlushCommonBuffer (
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3,
ULONG Unknown4,
ULONG Unknown5,
ULONG Unknown6,
ULONG Unknown7,
ULONG Unknown8
)
BOOLEAN STDCALL
HalFlushCommonBuffer (ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3,
ULONG Unknown4,
ULONG Unknown5,
ULONG Unknown6,
ULONG Unknown7,
ULONG Unknown8)
{
return TRUE;
}
VOID
STDCALL
HalFreeCommonBuffer (
PADAPTER_OBJECT AdapterObject,
ULONG Length,
PHYSICAL_ADDRESS LogicalAddress,
PVOID VirtualAddress,
BOOLEAN CacheEnabled
)
VOID STDCALL
HalFreeCommonBuffer (PADAPTER_OBJECT AdapterObject,
ULONG Length,
PHYSICAL_ADDRESS LogicalAddress,
PVOID VirtualAddress,
BOOLEAN CacheEnabled)
{
MmFreeContiguousMemory (VirtualAddress);
UNIMPLEMENTED;
}
PADAPTER_OBJECT
STDCALL
HalGetAdapter (
PDEVICE_DESCRIPTION DeviceDescription,
PULONG NumberOfMapRegisters
)
PADAPTER_OBJECT STDCALL
HalGetAdapter (PDEVICE_DESCRIPTION DeviceDescription,
PULONG NumberOfMapRegisters)
/*
* FUNCTION: Returns a pointer to an adapter object for the DMA device
* defined the device description structure
@ -141,20 +77,12 @@ HalGetAdapter (
* NULL on failure
*/
{
/* PADAPTER_OBJECT adapter;
adapter = ExAllocatePool(NonPagedPool,sizeof(ADAPTER_OBJECT));
RtlCopyMemory(&adapter->desc,DeviceDescription,sizeof(DEVICE_DESCRIPTION));
*/
return NULL;
UNIMPLEMENTED;
}
ULONG
STDCALL
HalReadDmaCounter (
PADAPTER_OBJECT AdapterObject
)
ULONG STDCALL
HalReadDmaCounter (PADAPTER_OBJECT AdapterObject)
{
UNIMPLEMENTED;
}

View file

@ -1,4 +1,4 @@
/* $Id: adapter.c,v 1.3 2000/05/09 16:13:49 ekohl Exp $
/* $Id: adapter.c,v 1.4 2000/07/19 14:18:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -23,17 +23,14 @@ USHORT EXPORTED IoDeviceHandlerObjectSize = 0; /* FIXME */
/* FUNCTIONS *****************************************************************/
NTSTATUS
STDCALL
IoAllocateAdapterChannel (
PADAPTER_OBJECT AdapterObject,
PDEVICE_OBJECT DeviceObject,
ULONG NumberOfMapRegisters,
PDRIVER_CONTROL ExecutionRoutine,
PVOID Context
)
NTSTATUS STDCALL
IoAllocateAdapterChannel (PADAPTER_OBJECT AdapterObject,
PDEVICE_OBJECT DeviceObject,
ULONG NumberOfMapRegisters,
PDRIVER_CONTROL ExecutionRoutine,
PVOID Context)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}

View file

@ -72,6 +72,7 @@ VOID HalTaskSwitch(PKTHREAD thread)
: /* No outputs */
: "i" (TEB_SELECTOR)
: "ax");
__asm__("clts\n\t");
#if 0
Thread = PsGetCurrentThread();

View file

@ -16,10 +16,44 @@
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
static ULONG HardwareMathSupport;
static ULONG x;
/* FUNCTIONS *****************************************************************/
VOID KiCheckFPU(VOID)
{
unsigned short int status;
int cr0;
HardwareMathSupport = 0;
__asm__("clts\n\t");
__asm__("fninit\n\t");
__asm__("fstsw %0\n\t" : "=a" (status));
if (status != 0)
{
__asm__("movl %%cr0, %0\n\t" : "=g" (cr0));
cr0 = cr0 | 0x4;
__asm__("movl %0, %%cr0\n\t" :
: "g" (cr0));
DbgPrint("No FPU detected\n");
return;
}
/* FIXME: Do fsetpm */
DbgPrint("Detected FPU\n");
HardwareMathSupport = 1;
DbgPrint("Testing FPU\n");
x = x * 6.789456;
}
VOID KeInit1(VOID)
{
KiCheckFPU();
KeInitExceptions ();
KeInitInterrupts ();
}

View file

@ -1,4 +1,4 @@
/* $Id: loader.c,v 1.58 2000/07/04 08:52:41 dwelch Exp $
/* $Id: loader.c,v 1.59 2000/07/19 14:18:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -189,16 +189,25 @@ static VOID LdrLoadAutoConfigDriver (LPWSTR RelativeDriverName)
VOID LdrLoadAutoConfigDrivers (VOID)
{
/*
* Keyboard driver
*/
LdrLoadAutoConfigDriver( L"keyboard.sys" );
/*
* Raw console driver
*/
LdrLoadAutoConfigDriver( L"blue.sys" );
// LdrLoadAutoConfigDriver(L"minixfs.sys");
/*
* Keyboard driver
*/
LdrLoadAutoConfigDriver( L"keyboard.sys" );
/*
* Raw console driver
*/
LdrLoadAutoConfigDriver( L"blue.sys" );
/*
* Floppy disk driver
*/
// LdrLoadAutoConfigDriver(L"floppy.sys");
/*
* Minix filesystem driver
*/
LdrLoadAutoConfigDriver(L"minixfs.sys");
}

View file

@ -22,9 +22,11 @@
/* TYPES *******************************************************************/
#define PHYSICAL_PAGE_FREE (0x1)
#define PHYSICAL_PAGE_INUSE (0x2)
#define PHYSICAL_PAGE_BIOS (0x3)
#define MM_PHYSICAL_PAGE_FREE (0x1)
#define MM_PHYSICAL_PAGE_USED (0x2)
#define MM_PHYSICAL_PAGE_BIOS (0x3)
#define MM_PTYPE(x) ((x) & 0x3)
typedef struct _PHYSICAL_PAGE
{
@ -45,9 +47,6 @@ static KSPIN_LOCK PageListLock;
static LIST_ENTRY FreePageListHead;
static LIST_ENTRY BiosPageListHead;
ULONG MiNrFreePages;
ULONG MiNrUsedPages;
/* FUNCTIONS *************************************************************/
PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
@ -89,8 +88,12 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
LastPhysKernelAddress = (PVOID)PAGE_ROUND_UP(LastPhysKernelAddress);
LastPhysKernelAddress = LastPhysKernelAddress + (Reserved * PAGESIZE);
MiNrFreePages = 0;
MiNrUsedPages = 0;
MmStats.NrTotalPages = 0;
MmStats.NrSystemPages = 0;
MmStats.NrUserPages = 0;
MmStats.NrReservedPages = 0;
MmStats.NrFreePages = 0;
MmStats.NrLockedPages = 0;
for (i = 0; i < Reserved; i++)
{
@ -107,11 +110,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
i = 1;
if ((ULONG)FirstPhysKernelAddress < 0xa0000)
{
MiNrFreePages = MiNrFreePages +
((ULONG)FirstPhysKernelAddress/PAGESIZE);
MmStats.NrFreePages += ((ULONG)FirstPhysKernelAddress/PAGESIZE);
for (; i<((ULONG)FirstPhysKernelAddress/PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_FREE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_FREE;
MmPageArray[i].ReferenceCount = 0;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -119,11 +121,11 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&FreePageListHead,
&MmPageArray[i].ListEntry);
}
MiNrUsedPages = MiNrUsedPages +
MmStats.NrSystemPages +=
((((ULONG)LastPhysKernelAddress) / PAGESIZE) - i);
for (; i<((ULONG)LastPhysKernelAddress / PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_INUSE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_USED;
MmPageArray[i].ReferenceCount = 1;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -131,11 +133,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&UsedPageListHead,
&MmPageArray[i].ListEntry);
}
MiNrFreePages = MiNrFreePages +
((0xa0000/PAGESIZE) - i);
MmStats.NrFreePages += ((0xa0000/PAGESIZE) - i);
for (; i<(0xa0000/PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_FREE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_FREE;
MmPageArray[i].ReferenceCount = 0;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -143,9 +144,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&FreePageListHead,
&MmPageArray[i].ListEntry);
}
MmStats.NrReservedPages += ((0x100000/PAGESIZE) - i);
for (; i<(0x100000 / PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_BIOS;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_BIOS;
MmPageArray[i].ReferenceCount = 1;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -156,10 +158,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
}
else
{
MiNrFreePages = MiNrFreePages + (0xa0000 / PAGESIZE);
MmStats.NrFreePages += (0xa0000 / PAGESIZE);
for (; i<(0xa0000 / PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_FREE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_FREE;
MmPageArray[i].ReferenceCount = 0;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -167,9 +169,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&FreePageListHead,
&MmPageArray[i].ListEntry);
}
MmStats.NrReservedPages += (0x60000 / PAGESIZE);
for (; i<(0x100000 / PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_BIOS;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_BIOS;
MmPageArray[i].ReferenceCount = 1;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -177,11 +180,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&BiosPageListHead,
&MmPageArray[i].ListEntry);
}
MiNrFreePages = MiNrFreePages +
(((ULONG)FirstPhysKernelAddress/PAGESIZE) - i);
MmStats.NrFreePages += (((ULONG)FirstPhysKernelAddress/PAGESIZE) - i);
for (; i<((ULONG)FirstPhysKernelAddress/PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_FREE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_FREE;
MmPageArray[i].ReferenceCount = 0;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -189,11 +191,11 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
InsertTailList(&FreePageListHead,
&MmPageArray[i].ListEntry);
}
MiNrUsedPages = MiNrUsedPages +
MmStats.NrSystemPages +=
(((ULONG)LastPhysKernelAddress/PAGESIZE) - i);
for (; i<((ULONG)LastPhysKernelAddress/PAGESIZE); i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_INUSE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_USED;
MmPageArray[i].ReferenceCount = 1;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -203,10 +205,10 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
}
}
MiNrFreePages = MiNrFreePages + (MemorySizeInPages - i);
MmStats.NrFreePages += (MemorySizeInPages - i);
for (; i<MemorySizeInPages; i++)
{
MmPageArray[i].Flags = PHYSICAL_PAGE_FREE;
MmPageArray[i].Flags = MM_PHYSICAL_PAGE_FREE;
MmPageArray[i].ReferenceCount = 0;
KeInitializeEvent(&MmPageArray[i].Event,
NotificationEvent,
@ -279,6 +281,13 @@ VOID MmReferencePage(PVOID PhysicalAddress)
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Referencing non-used page\n");
KeBugCheck(0);
}
MmPageArray[Start].ReferenceCount++;
KeReleaseSpinLock(&PageListLock, oldIrql);
}
@ -295,33 +304,45 @@ VOID MmDereferencePage(PVOID PhysicalAddress)
KeBugCheck(0);
}
if (((ULONG)PhysicalAddress) > 0x400000)
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("MmFreePage() failed with %x\n", PhysicalAddress);
DbgPrint("Dereferencing free page\n");
KeBugCheck(0);
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
MiNrFreePages = MiNrFreePages + 1;
MiNrUsedPages = MiNrUsedPages - 1;
MmStats.NrFreePages++;
MmStats.NrSystemPages--;
MmPageArray[Start].ReferenceCount--;
if (MmPageArray[Start].ReferenceCount == 0)
{
RemoveEntryList(&MmPageArray[Start].ListEntry);
MmPageArray[Start].Flags = PHYSICAL_PAGE_FREE;
if (MmPageArray[Start].LockCount > 0)
{
DbgPrint("Freeing locked page\n");
KeBugCheck(0);
}
if (MmPageArray[Start].Flags != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Freeing page with flags %x\n",
MmPageArray[Start].Flags);
KeBugCheck(0);
}
MmPageArray[Start].Flags = MM_PHYSICAL_PAGE_FREE;
InsertTailList(&FreePageListHead, &MmPageArray[Start].ListEntry);
}
KeReleaseSpinLock(&PageListLock, oldIrql);
}
VOID MmLockPage(PVOID PhysicalAddress)
ULONG MmGetLockCountPage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
KIRQL oldIrql;
ULONG LockCount;
DPRINT("MmReferencePage(PhysicalAddress %x)\n", PhysicalAddress);
DPRINT("MmGetLockCountPage(PhysicalAddress %x)\n", PhysicalAddress);
if (((ULONG)PhysicalAddress) == 0)
{
@ -329,6 +350,39 @@ VOID MmLockPage(PVOID PhysicalAddress)
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Getting lock count for free page\n");
KeBugCheck(0);
}
LockCount = MmPageArray[Start].LockCount;
KeReleaseSpinLock(&PageListLock, oldIrql);
return(LockCount);
}
VOID MmLockPage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
KIRQL oldIrql;
DPRINT("MmLockPage(PhysicalAddress %x)\n", PhysicalAddress);
if (((ULONG)PhysicalAddress) == 0)
{
KeBugCheck(0);
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Locking free page\n");
KeBugCheck(0);
}
MmPageArray[Start].LockCount++;
KeReleaseSpinLock(&PageListLock, oldIrql);
}
@ -338,7 +392,7 @@ VOID MmUnlockPage(PVOID PhysicalAddress)
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
KIRQL oldIrql;
DPRINT("MmReferencePage(PhysicalAddress %x)\n", PhysicalAddress);
DPRINT("MmUnlockPage(PhysicalAddress %x)\n", PhysicalAddress);
if (((ULONG)PhysicalAddress) == 0)
{
@ -346,6 +400,13 @@ VOID MmUnlockPage(PVOID PhysicalAddress)
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Unlocking free page\n");
KeBugCheck(0);
}
MmPageArray[Start].LockCount--;
KeReleaseSpinLock(&PageListLock, oldIrql);
}
@ -369,8 +430,14 @@ PVOID MmAllocPage(SWAPENTRY SavedSwapEntry)
}
PageDescriptor = CONTAINING_RECORD(ListEntry, PHYSICAL_PAGE, ListEntry);
DPRINT("PageDescriptor %x\n",PageDescriptor);
PageDescriptor->Flags = PHYSICAL_PAGE_INUSE;
if (PageDescriptor->Flags != MM_PHYSICAL_PAGE_FREE)
{
DbgPrint("Got non-free page from freelist\n");
KeBugCheck(0);
}
PageDescriptor->Flags = MM_PHYSICAL_PAGE_USED;
PageDescriptor->ReferenceCount = 1;
PageDescriptor->LockCount = 0;
PageDescriptor->SavedSwapEntry = SavedSwapEntry;
ExInterlockedInsertTailList(&UsedPageListHead, ListEntry,
&PageListLock);
@ -381,14 +448,8 @@ PVOID MmAllocPage(SWAPENTRY SavedSwapEntry)
offset = offset / sizeof(PHYSICAL_PAGE) * PAGESIZE;
DPRINT("offset %x\n",offset);
MiNrUsedPages = MiNrUsedPages + 1;
MiNrFreePages = MiNrFreePages - 1;
if (offset > 0x400000)
{
DbgPrint("Failed in MmAllocPage() with offset %x\n", offset);
KeBugCheck(0);
}
MmStats.NrSystemPages++;
MmStats.NrFreePages--;
DPRINT("MmAllocPage() = %x\n",offset);
return((PVOID)offset);

View file

@ -1,4 +1,4 @@
/* $Id: page.c,v 1.12 2000/07/07 10:30:57 dwelch Exp $
/* $Id: page.c,v 1.13 2000/07/19 14:18:19 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -23,8 +23,6 @@
/* GLOBALS *****************************************************************/
extern ULONG MiNrFreePages;
#define PA_BIT_PRESENT (0)
#define PA_BIT_READWRITE (1)
#define PA_BIT_USER (2)
@ -218,9 +216,9 @@ VOID MmDeletePageEntry(PEPROCESS Process, PVOID Address, BOOL FreePage)
{
if (PAGE_MASK(*page_tlb) >= 0x400000)
{
DbgPrint("MmDeletePageEntry(Address %x) Physical %x Free %d, "
DbgPrint("MmDeletePageEntry(Address %x) Physical %x "
"Entry %x\n",
Address, PAGE_MASK(*page_tlb), MiNrFreePages,
Address, PAGE_MASK(*page_tlb),
*page_tlb);
KeBugCheck(0);
}
@ -384,12 +382,9 @@ PHYSICAL_ADDRESS STDCALL MmGetPhysicalAddress(PVOID vaddr)
{
PHYSICAL_ADDRESS p;
p.QuadPart = 0;
DPRINT("MmGetPhysicalAddress(vaddr %x)\n", vaddr);
p.u.LowPart = PAGE_MASK(*MmGetPageEntry(vaddr));
p.u.HighPart = 0;
p.QuadPart = PAGE_MASK(*MmGetPageEntry(vaddr));
return p;
}

View file

@ -1,4 +1,4 @@
/* $Id: mminit.c,v 1.3 2000/07/07 10:30:56 dwelch Exp $
/* $Id: mminit.c,v 1.4 2000/07/19 14:18:19 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -163,6 +163,23 @@ VOID MmInit1(PLOADER_PARAMETER_BLOCK bp, ULONG LastKernelAddress)
MmUserProbeAddress = (PVOID)0x7fff0000;
MmHighestUserAddress = (PVOID)0x7ffeffff;
/*
* Initialize memory managment statistics
*/
MmStats.NrTotalPages = 0;
MmStats.NrSystemPages = 0;
MmStats.NrUserPages = 0;
MmStats.NrReservedPages = 0;
MmStats.NrUserPages = 0;
MmStats.NrFreePages = 0;
MmStats.NrLockedPages = 0;
MmStats.PagingRequestsInLastMinute = 0;
MmStats.PagingRequestsInLastFiveMinutes = 0;
MmStats.PagingRequestsInLastFifteenMinutes = 0;
/*
* Initialize the kernel address space
*/
MmInitializeKernelAddressSpace();
/*

View file

@ -1,4 +1,4 @@
/* $Id: pager.c,v 1.3 2000/07/06 14:34:51 dwelch Exp $
/* $Id: pager.c,v 1.4 2000/07/19 14:18:19 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -99,6 +99,7 @@ static NTSTATUS MmPagerThreadMain(PVOID Ignored)
LastProcess = PsGetNextProcess(LastProcess);
}
}
DbgPrint("Out of memory\n");
KeSetEvent(&FreedMemEvent, IO_NO_INCREMENT, FALSE);
}
}