/// <summary> /// Read method for filesystem /// </summary> /// <param name="node">The node</param> /// <param name="offset">The offset</param> /// <param name="size">The size</param> /// <param name="buffer">The buffer</param> /// <returns>The amount of bytes read</returns> private static unsafe uint readImpl(Node node, uint offset, uint size, byte[] buffer) { // Only support sizes in magnitudes of 512 if (size % 512 != 0) { return(0); } uint sz = size / 512; AHCICookie cookie = (AHCICookie)node.Cookie; byte *bufferPtr = (byte *)Util.ObjectToVoidPtr(buffer); if (cookie.AHCI.AtaTransfer(cookie.PortInfo, (int)offset, (int)sz, (byte *)Util.ObjectToVoidPtr(buffer), false) == 0) { return(0); } return((uint)size); }
/// <summary> /// Initalize port /// </summary> /// <param name="portInfo">Port info</param> private void initPort(AHCIPortInfo portInfo) { AHCI_Port_registers *portReg = mPorts + portInfo.PortNumber; portInfo.CommandHeader = (AHCI_Command_header *)Heap.AlignedAlloc(4048, sizeof(AHCI_Command_header) * NUM_CMD_HEADERS); Memory.Memset(portInfo.CommandHeader, 0xFF, sizeof(AHCI_Command_header) * NUM_CMD_HEADERS); portInfo.Type = GetPortType(portReg); // Port found? if (portInfo.Type == AHCI_PORT_TYPE.NO) { return; } // NOTE: We support only SATA for now.. if (portInfo.Type != AHCI_PORT_TYPE.SATA) { switch (portInfo.Type) { case AHCI_PORT_TYPE.PM: Console.Write("[AHCI] Unsupported type PM found on port "); Console.WriteNum(portInfo.PortNumber); Console.WriteLine(""); break; case AHCI_PORT_TYPE.SATAPI: Console.Write("[AHCI] Unsupported type SATAPI found on port "); Console.WriteNum(portInfo.PortNumber); Console.WriteLine(""); break; case AHCI_PORT_TYPE.SEMB: Console.Write("[AHCI] Unsupported type SEMB found on port "); Console.WriteNum(portInfo.PortNumber); Console.WriteLine(""); break; } return; } stopPort(portReg); AHCI_Received_FIS *Fises = (AHCI_Received_FIS *)Heap.AlignedAlloc(256, sizeof(AHCI_Received_FIS)); Memory.Memclear(Fises, sizeof(AHCI_Received_FIS)); portReg->CLB = (uint)Paging.GetPhysicalFromVirtual(portInfo.CommandHeader); portReg->CLBU = 0x00; portReg->FB = (uint)Paging.GetPhysicalFromVirtual(Fises); portReg->FBU = 0x00; AHCI_Command_table_entry *cmdTable = (AHCI_Command_table_entry *)Heap.AlignedAlloc(128, sizeof(AHCI_Command_table_entry)); Memory.Memclear(cmdTable, sizeof(AHCI_Command_table_entry)); for (int i = 0; i < NUM_CMD_HEADERS; i++) { portInfo.CommandHeader[i].Prdtl = 0; portInfo.CommandHeader[i].CTBA = (uint)cmdTable; portInfo.CommandHeader[i].CTBAU = 0x00; } startPort(portReg); portInfo.PortRegisters = portReg; char *name = (char *)Heap.Alloc(5); name[0] = 'H'; name[1] = 'D'; name[2] = 'A'; name[3] = (char)('0' + portInfo.PortNumber); name[4] = '\0'; string nameStr = Util.CharPtrToString(name); Node node = new Node(); node.Read = readImpl; //node.Write = writeImpl; AHCICookie cookie = new AHCICookie(); cookie.AHCI = this; cookie.PortInfo = portInfo; node.Cookie = cookie; Disk.InitalizeNode(node, nameStr); RootPoint dev = new RootPoint(nameStr, node); VFS.MountPointDevFS.AddEntry(dev); }