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

📄 kernelhardwareenumeration.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 2 页
字号:
		return (status);	      	      // Increase the number of logical hard disk devices	      numberHardDisks++;	    }	  	  else if (physicalDisk.flags & DISKFLAG_IDECDROM)	    {	      kernelLog("Disk %d is an IDE CD-ROM", deviceNumber);	      	      // Hard disk.  Put it into our hard disks array	      kernelMemCopy((void *) &physicalDisk,			    (void *) &(cdRomDevices[numberCdRoms]),			    sizeof(kernelPhysicalDisk));	      	      // The device name	      sprintf((char *) cdRomDevices[numberCdRoms].name,		      (char *) "cd%d", numberCdRoms);	      	      // Register the CDROM device	      status = kernelDiskRegisterDevice(&cdRomDevices[numberCdRoms]);	      if (status < 0)		return (status);	      	      // Increase the number of logical hard disk devices	      numberCdRoms++;	    }	}            else	kernelLog("Disk %d type is unknown", deviceNumber);    }    return (numberHardDisks + numberCdRoms);}static int enumerateGraphicDevice(void){  // This routine enumerates the system's graphic adapter device.    // They doesn't really need enumeration; this really just registers the   // device and initializes the functions in the abstracted driver.  int status = 0;  // Set up the device parameters  graphicAdapterDevice.videoMemory = systemInfo->graphicsInfo.videoMemory;  graphicAdapterDevice.framebuffer = systemInfo->graphicsInfo.framebuffer;  graphicAdapterDevice.mode = systemInfo->graphicsInfo.mode;  graphicAdapterDevice.xRes = systemInfo->graphicsInfo.xRes;  graphicAdapterDevice.yRes = systemInfo->graphicsInfo.yRes;  graphicAdapterDevice.bitsPerPixel = systemInfo->graphicsInfo.bitsPerPixel;  if (graphicAdapterDevice.bitsPerPixel == 15)    graphicAdapterDevice.bytesPerPixel = 2;  else    graphicAdapterDevice.bytesPerPixel =      (graphicAdapterDevice.bitsPerPixel / 8);  graphicAdapterDevice.numberModes = systemInfo->graphicsInfo.numberModes;  kernelMemCopy(&(systemInfo->graphicsInfo.supportedModes),		&(graphicAdapterDevice.supportedModes),		(sizeof(videoMode) * MAXVIDEOMODES));        kernelInstallGraphicDriver(&graphicAdapterDevice);  // If we are in a graphics mode, initialize the graphics functions  if (graphicAdapterDevice.mode != 0)    {      // Map the supplied physical linear framebuffer address into kernel      // memory      status = kernelPageMapToFree(KERNELPROCID,				   graphicAdapterDevice.framebuffer, 				   &(graphicAdapterDevice.framebuffer),				   (graphicAdapterDevice.xRes *				    graphicAdapterDevice.yRes *				    graphicAdapterDevice.bytesPerPixel));      if (status < 0)	{	  kernelError(kernel_error, "Unable to map linear framebuffer");	  return (status);	}      status = kernelGraphicRegisterDevice(&graphicAdapterDevice);      if (status < 0)	return (status);      status = kernelGraphicInitialize();      if (status < 0)	return (status);    }  return (status = 0);}static int enumerateMouseDevice(void){  // This routine enumerates the system's mouse device.  For the time  // being it assumes that the mouse is a PS2 type  int status = 0;  kernelInstallMouseDriver(&mouseDevice);  status = kernelMouseRegisterDevice(&mouseDevice);  if (status < 0)    return (status);  // Initialize the mouse functions  status = kernelMouseInitialize();  if (status < 0)    return (status);  return (status = 0);}static int enumeratePCIDevices(void){	//Enumerates all devices on the PCI bus.	//I only use PCI configuration mechanism #1, because mechnism #2 is deprecated since 1997 	//and uncomfortable, buggy, etc.		int status = 0;		int bus, device, function;		kernelBusPCIDevice * pciDevice;		unsigned int i;		char * classname;		char * subclassname;		//Check for a PCI controller first	if(kernelBusPCIFindController() < 0)	{	   kernelLog("No PCI controller found on port 0xcf8! Perhaps configuration mechanism #2 must be used!\n");	   	   return (status = -1);	}		kernelLog("PCI controller found\n");		pciDevice = kernelMemoryGet(sizeof(kernelBusPCIDevice), "PCI-device");		//for every possible PCI device	   	for(bus = 0; bus < BUS_PCI_MAX_BUSES; bus++) 	{		for(device = 0; device < BUS_PCI_MAX_DEVICES; device++)		{			for(function = 0; function < BUS_PCI_MAX_FUNCTIONS; function++) 			{				      				for(i = 0; i < sizeof(kernelBusPCIDevice) / sizeof(DWORD); i++)   				{      					kernelBusPCIReadConfig32(bus, device, function, i * sizeof(DWORD),					(DWORD *) &(pciDevice->header[i]));   				}								//See if this is really a device, or if this device header is unoccupied.				if((*pciDevice).device.vendorID == 0xffff || (*pciDevice).device.deviceID == 0xffff)				{					//No device here, so try next one					continue;				}								//I didn't find a vendor with ID 0x0000 at http://www.pcidatabase.com				if((*pciDevice).device.vendorID == 0x0000)				{					//Not a valid device, try next one					continue;				} 								kernelBusPCIGetClassName((*pciDevice).device.class_code, (*pciDevice).device.subclass_code, &classname, &subclassname);											//if here, we found a PCI device				//TODO: substitute this message by a driver installation routine				kernelLog("%u:%u:%u -> device: %x, vendor: %x, class: %x, subclass: %u\n", bus, device, function, (*pciDevice).device.deviceID, (*pciDevice).device.vendorID, (*pciDevice).device.class_code, (*pciDevice).device.subclass_code); 				kernelLog(classname);				kernelLog(subclassname);				kernelLog("---------------------------------------"); 							}		}	}		kernelMemoryRelease((void *) pciDevice);		return status;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Below here, the functions are exported for external use////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int kernelHardwareEnumerate(loaderInfoStruct *info){  // Just calls all of the above hardware enumeration routines.  Used during  // kernel initialization.  Returns 0 unless any of the other routines  // return an error (negative), in which case it relays the error code.  int status = 0;  // Make sure the info structure isn't NULL  if (info == NULL)    return (status = ERR_NULLPARAMETER);  // Save the pointer to the data structure that describes the hardware  systemInfo = info;  // Initialize the memory for the various structures we're managing  kernelMemClear(&picDevice, sizeof(kernelPic));  kernelMemClear(&systemTimerDevice, sizeof(kernelSysTimer));  kernelMemClear(&rtcDevice, sizeof(kernelRtc));  kernelMemClear(&dmaDevice, sizeof(kernelDma));  kernelMemClear(&keyboardDevice, sizeof(kernelKeyboard));  kernelMemClear(&mouseDevice, sizeof(kernelMouse));  kernelMemClear((void *) floppyDevices, 			(sizeof(kernelPhysicalDisk) * MAXFLOPPIES));  kernelMemClear((void *) hardDiskDevices, 			(sizeof(kernelPhysicalDisk) * MAXHARDDISKS));  kernelMemClear(&graphicAdapterDevice, sizeof(kernelGraphicAdapter));  // Map the BIOS data area into our memory so we can get hardware information  // from it.  status = kernelPageMapToFree(KERNELPROCID, (void *) 0, &biosData, 0x1000);  if (status < 0)    {      kernelError(kernel_error, "Error mapping BIOS data area");      return (status);    }  // Start enumerating devices  // The PIC device needs to go first  status = enumeratePicDevice();  if (status < 0)    return (status);  // The system timer device  status = enumerateSysTimerDevice();  if (status < 0)    return (status);  // The Real-Time clock device  status = enumerateRtcDevice();  if (status < 0)    return (status);  // The DMA controller device  status = enumerateDmaDevice();  if (status < 0)    return (status);  // The keyboard device  status = enumerateKeyboardDevice();  if (status < 0)    return (status);  // Enable interrupts now.  kernelProcessorEnableInts();  // Enumerate the floppy disk devices  status = enumerateFloppyDevices();  if (status < 0)    return (status);  // Enumerate the hard disk devices  status = enumerateHardDiskDevices();  if (status < 0)    return (status);  // Enumerate the graphic adapter  status = enumerateGraphicDevice();  if (status < 0)    return (status);  // Do the mouse device after the graphic device so we can get screen  // parameters, etc.  Also needs to be after the keyboard driver since  // PS2 mouses use the keyboard controller.  status = enumerateMouseDevice();  if (status < 0)    return (status);      status = enumeratePCIDevices();  if(status < 0)    return (status);  // Unmap BIOS data  kernelPageUnmap(KERNELPROCID, biosData, 0x1000);  // Return success  return (status = 0);}

⌨️ 快捷键说明

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