⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernelhardwareenumeration.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 2 页
字号:
////  Visopsys//  Copyright (C) 1998-2005 J. Andrew McLaughlin// //  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.,//  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.////  kernelHardwareEnumeration.c//// These routines enumerate all of the hardware devices in the system based// on the hardware data structure passed to the kernel by the os loader.#include "kernelHardwareEnumeration.h"#include "kernelParameters.h"#include "kernelDriverManagement.h"#include "kernelPageManager.h"#include "kernelProcessorX86.h"#include "kernelText.h"#include "kernelMiscFunctions.h"#include "kernelLog.h"#include "kernelError.h"#include "kernelBusPCI.h"#include "kernelMemoryManager.h"#include <stdio.h>#include <string.h>loaderInfoStruct *systemInfo = NULL;static kernelPic picDevice;static kernelSysTimer systemTimerDevice;static kernelRtc rtcDevice;static kernelDma dmaDevice;static kernelKeyboard keyboardDevice;static kernelMouse mouseDevice;static kernelPhysicalDisk floppyDevices[MAXFLOPPIES];  static int numberFloppies = 0;static kernelPhysicalDisk hardDiskDevices[MAXHARDDISKS];  static int numberHardDisks = 0;static kernelPhysicalDisk cdRomDevices[MAXHARDDISKS];  static int numberCdRoms = 0;static kernelGraphicAdapter graphicAdapterDevice;static void *biosData = NULL;static int enumeratePicDevice(void){  // This routine enumerates the system's Programmable Interrupt Controller  // device.  It doesn't really need enumeration; this really just registers   // the device and initializes the functions in the abstracted driver.  int status = 0;  kernelInstallPicDriver(&picDevice);  status = kernelPicRegisterDevice(&picDevice);  if (status < 0)    return (status);  status = kernelPicInitialize();  if (status < 0)    return (status);  return (status = 0);}static int enumerateSysTimerDevice(void){  // This routine enumerates the system timer device.  It doesn't really  // need enumeration; this really just registers the device and initializes  // the functions in the abstracted driver.  int status = 0;  kernelInstallSysTimerDriver(&systemTimerDevice);  status = kernelSysTimerRegisterDevice(&systemTimerDevice);  if (status < 0)    return (status);  // Initialize the system timer functions  status = kernelSysTimerInitialize();  if (status < 0)    return (status);  return (status = 0);}static int enumerateRtcDevice(void){  // This routine enumerates the system's Real-Time clock device.    // It doesn't really need enumeration; this really just registers the   // device and initializes the functions in the abstracted driver.  int status = 0;  kernelInstallRtcDriver(&rtcDevice);  status = kernelRtcRegisterDevice(&rtcDevice);  if (status < 0)    return (status);  // Initialize the real-time clock functions  status = kernelRtcInitialize();  if (status < 0)    return (status);  return (status = 0);}static int enumerateDmaDevice(void){  // This routine enumerates the system's DMA controller device(s).    // They doesn't really need enumeration; this really just registers the   // device and initializes the functions in the abstracted driver.  int status = 0;  kernelInstallDmaDriver(&dmaDevice);  status = kernelDmaRegisterDevice(&dmaDevice);  if (status < 0)    return (status);  // Initialize the DMA controller functions  status = kernelDmaInitialize();  if (status < 0)    return (status);  return (status = 0);}static int enumerateKeyboardDevice(void){  // This routine enumerates the system's keyboard device.    // They doesn't really need enumeration; this really just registers the   // device and initializes the functions in the abstracted driver.  int status = 0;  kernelInstallKeyboardDriver(&keyboardDevice);  status = kernelKeyboardRegisterDevice(&keyboardDevice);  if (status < 0)    return (status);  // Get the flags from the BIOS data area  keyboardDevice.flags = (unsigned) *((unsigned char *)(biosData + 0x417));  // Initialize the keyboard functions  status = kernelKeyboardInitialize();  if (status < 0)    return (status);  // Set the default keyboard data stream to be the console input  status =    kernelKeyboardSetStream((stream *) &(kernelTextGetConsoleInput()->s));  if (status < 0)    return (status);  return (status = 0);}static int enumerateFloppyDevices(void){  // This routine enumerates floppy drives, and their types, and creates  // kernelPhysicalDisks to store the information.  If successful, it   // returns the number of floppy devices it discovered.  It has a   // complementary routine which will return a pointer to the data  // structure it has created.  int status = 0;  int count;  // Reset the number of floppy devices   numberFloppies = systemInfo->floppyDisks;  // We know the types.  We can fill out some data values in the  // physical disk structure(s)  for (count = 0; count < numberFloppies; count ++)    {      kernelInstallFloppyDriver(&floppyDevices[count]);      // The device name and filesystem type      sprintf((char *) floppyDevices[count].name, "fd%d", count);      // The head, track and sector values we got from the loader      floppyDevices[count].heads = systemInfo->fddInfo[count].heads;      floppyDevices[count].cylinders = systemInfo->fddInfo[count].tracks;      floppyDevices[count].sectorsPerCylinder =	systemInfo->fddInfo[count].sectors;      floppyDevices[count].numSectors = 	(floppyDevices[count].heads * floppyDevices[count].cylinders *	 floppyDevices[count].sectorsPerCylinder);      floppyDevices[count].biosType = systemInfo->fddInfo[count].type;      // Some additional universal default values      floppyDevices[count].flags =	(DISKFLAG_PHYSICAL | DISKFLAG_REMOVABLE | DISKFLAG_FLOPPY);      floppyDevices[count].deviceNumber = count;      floppyDevices[count].sectorSize = 512;      floppyDevices[count].dmaChannel = 2;      // Assume motor off for now      // Register the floppy disk device      status = kernelDiskRegisterDevice(&floppyDevices[count]);      if (status < 0)	return (status);    }  return (numberFloppies);}static int enumerateHardDiskDevices(void){  // This routine enumerates hard disks, and creates kernelPhysicalDisks  // to store the information.  If successful, it returns the number of   // devices it enumerated.  int status = 0;  int deviceNumber = 0;  kernelPhysicalDisk physicalDisk;  // Reset the number of physical hard disk devices we've actually  // examined, and reset the number of logical disks we've created  numberHardDisks = 0;  // Make a message  kernelLog("Examining hard disks...");  for (deviceNumber = 0; (deviceNumber < MAXHARDDISKS); deviceNumber ++)    {      // Clear our disk structure      kernelMemClear((void *) &physicalDisk, sizeof(kernelPhysicalDisk));      // Install the ATA/ATAPI/IDE driver      kernelInstallIdeDriver(&physicalDisk);      // Call the detect routine      if (physicalDisk.driver	  ->driverDetect(deviceNumber, (void *) &physicalDisk) == 1)	{	  if (physicalDisk.flags & DISKFLAG_IDEDISK)	    {	      // In some cases, we are detecting hard disks that don't seem	      // to actually exist.  Check whether the number of cylinders	      // passed by the loader is non-NULL.	      if (!systemInfo->hddInfo[numberHardDisks].cylinders)		continue;	      kernelLog("Disk %d is an IDE disk", deviceNumber);	      	      // Hard disk.  Put it into our hard disks array	      kernelMemCopy((void *) &physicalDisk,			    (void *) &(hardDiskDevices[numberHardDisks]),			    sizeof(kernelPhysicalDisk));	      	      // The device name	      sprintf((char *) hardDiskDevices[numberHardDisks].name,		      (char *) "hd%d", numberHardDisks);	      	      // We get more hard disk info from the physical disk info we were	      // passed.	      hardDiskDevices[numberHardDisks].heads = 		systemInfo->hddInfo[numberHardDisks].heads;	      hardDiskDevices[numberHardDisks].cylinders = 		systemInfo->hddInfo[numberHardDisks].cylinders;	      hardDiskDevices[numberHardDisks].sectorsPerCylinder = 		systemInfo->hddInfo[numberHardDisks].sectorsPerCylinder;	      hardDiskDevices[numberHardDisks].numSectors = (unsigned)		systemInfo->hddInfo[numberHardDisks].totalSectors;	      hardDiskDevices[numberHardDisks].sectorSize = 		systemInfo->hddInfo[numberHardDisks].bytesPerSector;	      // Sometimes 0?  We can't have that as we are about to use it to	      // perform a division operation.	      if (hardDiskDevices[numberHardDisks].sectorSize == 0)		{		  kernelError(kernel_warn, "Physical disk %d sector size 0; "			      "assuming 512", deviceNumber);		  hardDiskDevices[numberHardDisks].sectorSize = 512;		}	      hardDiskDevices[numberHardDisks].motorState = 1;	      	      // Register the hard disk device	      status =		kernelDiskRegisterDevice(&hardDiskDevices[numberHardDisks]);	      if (status < 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -