示例#1
0
        public static void Init()
        {
            int NetworkDeviceID = 0;

            Console.WriteLine("Searching for Ethernet Controllers...");

            foreach (PCIDevice device in PCI.Devices)
            {
                if ((device.ClassCode == 0x02) && (device.Subclass == 0x00) && // is Ethernet Controller
                    device == PCI.GetDevice(device.bus, device.slot, device.function))
                {
                    Console.WriteLine("Found " + PCIDevice.DeviceClass.GetDeviceString(device) + " on PCI " + device.bus + ":" + device.slot + ":" + device.function);

                    #region PCNETII

                    if (device.VendorID == (ushort)VendorID.AMD && device.DeviceID == (ushort)DeviceID.PCNETII)
                    {
                        Console.WriteLine("NIC IRQ: " + device.InterruptLine);

                        var AMDPCNetIIDevice = new AMDPCNetII(device);

                        AMDPCNetIIDevice.NameID = ("eth" + NetworkDeviceID);

                        Console.WriteLine("Registered at " + AMDPCNetIIDevice.NameID + " (" + AMDPCNetIIDevice.MACAddress.ToString() + ")");

                        AMDPCNetIIDevice.Enable();

                        NetworkDeviceID++;
                    }

                    #endregion
                    #region RTL8139

                    if (device.VendorID == 0x10EC && device.DeviceID == 0x8139)
                    {
                        var RTL8139Device = new RTL8139(device);

                        RTL8139Device.NameID = ("eth" + NetworkDeviceID);

                        RTL8139Device.Enable();

                        NetworkDeviceID++;
                    }

                    #endregion
                }
            }

            if (NetworkDevice.Devices.Count == 0)
            {
                Console.WriteLine("No supported network card found!!");
            }
            else
            {
                Console.WriteLine("Network initialization done!");
            }
        }
示例#2
0
        /// <summary>
        /// Get MAC Address String
        /// </summary>
        public static string PhysicalAddress()
        {
            PCIDevice device;

            device = PCI.GetDevice(VendorID.AMD, DeviceID.PCNETII);
            if (NetworkCardAvailable())
            {
                AMDPCNetII nic = new AMDPCNetII(device);
                return(nic.MACAddress.ToString());
            }
            else
            {
                return("");
            }
        }
示例#3
0
文件: Kernel.cs 项目: zer09/Cosmos
        //public class DictIntComparer : IEqualityComparer<int>
        //{
        //    public bool Equals(int x, int y)
        //    {
        //        return x == y;
        //    }

        //    public int GetHashCode(int obj)
        //    {
        //        return obj;
        //    }
        //}

        //private Dictionary<int, string> testDict;
        //private DictIntComparer testDictComparer;

        //public class IntMap<TValue> : Map<int, TValue>
        //{
        //    protected override bool keysEqual(int key1, int key2)
        //    {
        //        return (key1 == key2);
        //    }
        //}
        //public class StringMap<TValue> : Map<string, TValue>
        //{
        //    protected override bool keysEqual(string key1, string key2)
        //    {
        //        return (key1 == key2);
        //    }
        //}

        //public float Pow(float x, float y)
        //{
        //    if (y == 0)
        //    {
        //        return 1;
        //    }
        //    else if (y == 1)
        //    {
        //        return x;
        //    }
        //    else
        //    {
        //        float xResult = x;

        //        for (int i = 2; i <= y; i++)
        //        {
        //            xResult = xResult * x;
        //        }

        //        return xResult;
        //    }
        //}
        //private float Sqrt(float d)
        //{
        //    if ((d < 0) || (float.IsNaN(d) == true) || (float.IsNegativeInfinity(d) == true))
        //    {
        //        return float.NaN;
        //    }
        //    if (float.IsPositiveInfinity(d) == true)
        //    {
        //        return float.PositiveInfinity;
        //    }
        //    if (d == 0)
        //    {
        //        return 0;
        //    }
        //    if (d == 1)
        //    {
        //        return 1;
        //    }

        //    string strD = d.ToString();
        //    int D = strD.Length;
        //    int n = 0;
        //    float x;
        //    if ((D % 2) == 0)
        //    {
        //        n = (D - 2) / 2;
        //        x = 6.0f * Pow(10f, n);
        //    }
        //    else
        //    {
        //        n = (D - 1) / 2;
        //        x = 2.0f * Pow(10f, n);
        //    }
        //    int precision = (strD.Length > 6 ? strD.Length : 6);

        //    return x;
        //}

        //internal class BaseClass
        //{
        //    public int baseField;

        //    internal BaseClass()
        //    {
        //        initFields();
        //    }

        //    protected virtual void initFields()
        //    {
        //        baseField = 1;
        //    }
        //}
        //internal class SubClass : BaseClass
        //{
        //    public int subField;

        //    internal SubClass()
        //        : base()
        //    {
        //    }

        //    protected override void initFields()
        //    {
        //        base.initFields();
        //        subField = 2;
        //    }
        //}
        //internal class SubSubClass : SubClass
        //{
        //    public int subsubField;

        //    internal SubSubClass()
        //        :base()
        //    {
        //    }

        //    protected override void initFields()
        //    {
        //        base.initFields();
        //        subsubField = 3;
        //    }
        //}

        protected override void BeforeRun()
        {
            Console.WriteLine("SSchocke Test Playground");

            Console.WriteLine("Finding network devices...");
            AMDPCNetII.FindAll();

            NetworkDevice nic = NetworkDevice.Devices[0];

            IPv4.Address myIP      = new IPv4.Address(192, 168, 1, 51);
            IPv4.Address mySubnet  = new IPv4.Address(255, 255, 255, 0);
            IPv4.Address myGateway = new IPv4.Address(192, 168, 1, 1);
            IPv4.Config  myConfig  = new IPv4.Config(myIP, mySubnet, myGateway);

            NetworkStack.ConfigIP(nic, myConfig);
            nic.Enable();

            Console.WriteLine("Init Done... Starting main loop");
        }