diff --git a/Asuro.iso b/Asuro.iso index 364c3710..64044608 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/bin/kernel.bin b/bin/kernel.bin index 5f00dbab..671b6c7c 100755 Binary files a/bin/kernel.bin and b/bin/kernel.bin differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index 5f00dbab..671b6c7c 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/E1000.ppu b/lib/E1000.ppu index 8aee150d..e8fe5506 100644 Binary files a/lib/E1000.ppu and b/lib/E1000.ppu differ diff --git a/lib/PCI.ppu b/lib/PCI.ppu index f4daea46..bd150d6a 100644 Binary files a/lib/PCI.ppu and b/lib/PCI.ppu differ diff --git a/lib/USB.ppu b/lib/USB.ppu index 6a1180d7..bcb4ee0f 100644 Binary files a/lib/USB.ppu and b/lib/USB.ppu differ diff --git a/lib/bios_data_area.ppu b/lib/bios_data_area.ppu index d8e223d3..3c206fe8 100644 Binary files a/lib/bios_data_area.ppu and b/lib/bios_data_area.ppu differ diff --git a/lib/console.o b/lib/console.o index ce299f54..a05a7f87 100644 Binary files a/lib/console.o and b/lib/console.o differ diff --git a/lib/console.ppu b/lib/console.ppu index f7eee766..723096e5 100644 Binary files a/lib/console.ppu and b/lib/console.ppu differ diff --git a/lib/drivermanagement.ppu b/lib/drivermanagement.ppu index 27e3ee55..fc9a5c48 100644 Binary files a/lib/drivermanagement.ppu and b/lib/drivermanagement.ppu differ diff --git a/lib/gdt.ppu b/lib/gdt.ppu index d7a92e00..d3679911 100644 Binary files a/lib/gdt.ppu and b/lib/gdt.ppu differ diff --git a/lib/idt.ppu b/lib/idt.ppu index b2a0852c..4871b8fb 100644 Binary files a/lib/idt.ppu and b/lib/idt.ppu differ diff --git a/lib/irq.ppu b/lib/irq.ppu index 99d52d07..c1cf59c7 100644 Binary files a/lib/irq.ppu and b/lib/irq.ppu differ diff --git a/lib/isr.ppu b/lib/isr.ppu index f25da85c..69646688 100644 Binary files a/lib/isr.ppu and b/lib/isr.ppu differ diff --git a/lib/isr0.ppu b/lib/isr0.ppu index fb8d7d74..6f8c8923 100644 Binary files a/lib/isr0.ppu and b/lib/isr0.ppu differ diff --git a/lib/isr1.ppu b/lib/isr1.ppu index 43e11d45..296da208 100644 Binary files a/lib/isr1.ppu and b/lib/isr1.ppu differ diff --git a/lib/isr10.ppu b/lib/isr10.ppu index e0fb031c..af0d5d38 100644 Binary files a/lib/isr10.ppu and b/lib/isr10.ppu differ diff --git a/lib/isr11.ppu b/lib/isr11.ppu index d1bf9c0b..9d077a65 100644 Binary files a/lib/isr11.ppu and b/lib/isr11.ppu differ diff --git a/lib/isr12.ppu b/lib/isr12.ppu index 0815ab65..f4096a0b 100644 Binary files a/lib/isr12.ppu and b/lib/isr12.ppu differ diff --git a/lib/isr13.ppu b/lib/isr13.ppu index a9519d77..62b7e1fc 100644 Binary files a/lib/isr13.ppu and b/lib/isr13.ppu differ diff --git a/lib/isr14.ppu b/lib/isr14.ppu index 4130981b..8f2baa03 100644 Binary files a/lib/isr14.ppu and b/lib/isr14.ppu differ diff --git a/lib/isr15.ppu b/lib/isr15.ppu index 15f3667f..ee35c567 100644 Binary files a/lib/isr15.ppu and b/lib/isr15.ppu differ diff --git a/lib/isr16.ppu b/lib/isr16.ppu index b7c59b81..01424b3c 100644 Binary files a/lib/isr16.ppu and b/lib/isr16.ppu differ diff --git a/lib/isr17.ppu b/lib/isr17.ppu index 43c39915..ab4d924f 100644 Binary files a/lib/isr17.ppu and b/lib/isr17.ppu differ diff --git a/lib/isr18.ppu b/lib/isr18.ppu index 0418511e..e701cc45 100644 Binary files a/lib/isr18.ppu and b/lib/isr18.ppu differ diff --git a/lib/isr2.ppu b/lib/isr2.ppu index 51452406..996fcef7 100644 Binary files a/lib/isr2.ppu and b/lib/isr2.ppu differ diff --git a/lib/isr3.ppu b/lib/isr3.ppu index 9469a089..57029eac 100644 Binary files a/lib/isr3.ppu and b/lib/isr3.ppu differ diff --git a/lib/isr32.ppu b/lib/isr32.ppu index 0548b9ec..8371b814 100644 Binary files a/lib/isr32.ppu and b/lib/isr32.ppu differ diff --git a/lib/isr33.ppu b/lib/isr33.ppu index d94f583d..ce7abed4 100644 Binary files a/lib/isr33.ppu and b/lib/isr33.ppu differ diff --git a/lib/isr4.ppu b/lib/isr4.ppu index fcbfde61..d3069b2d 100644 Binary files a/lib/isr4.ppu and b/lib/isr4.ppu differ diff --git a/lib/isr40.ppu b/lib/isr40.ppu index 014fb948..69fd52dc 100644 Binary files a/lib/isr40.ppu and b/lib/isr40.ppu differ diff --git a/lib/isr44.ppu b/lib/isr44.ppu index be07b9e7..f9f0aba0 100644 Binary files a/lib/isr44.ppu and b/lib/isr44.ppu differ diff --git a/lib/isr5.ppu b/lib/isr5.ppu index 8356cab7..70d626b4 100644 Binary files a/lib/isr5.ppu and b/lib/isr5.ppu differ diff --git a/lib/isr6.ppu b/lib/isr6.ppu index 39f206db..56fda7f2 100644 Binary files a/lib/isr6.ppu and b/lib/isr6.ppu differ diff --git a/lib/isr7.ppu b/lib/isr7.ppu index ab9f32c2..7cf55096 100644 Binary files a/lib/isr7.ppu and b/lib/isr7.ppu differ diff --git a/lib/isr8.ppu b/lib/isr8.ppu index b5a0933a..5aeeb88f 100644 Binary files a/lib/isr8.ppu and b/lib/isr8.ppu differ diff --git a/lib/isr9.ppu b/lib/isr9.ppu index 1f98c7d2..212ff00c 100644 Binary files a/lib/isr9.ppu and b/lib/isr9.ppu differ diff --git a/lib/kernel.ppu b/lib/kernel.ppu index 5e367d1a..d2450340 100644 Binary files a/lib/kernel.ppu and b/lib/kernel.ppu differ diff --git a/lib/keyboard.ppu b/lib/keyboard.ppu index 04446110..f8c27a9a 100644 Binary files a/lib/keyboard.ppu and b/lib/keyboard.ppu differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index 01e83ae0..7742b7ae 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 5ca66c38..84be8355 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 5ca41f52..a4e9fe1e 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/lib/lmemorymanager.ppu b/lib/lmemorymanager.ppu index 9c649401..1347cc55 100644 Binary files a/lib/lmemorymanager.ppu and b/lib/lmemorymanager.ppu differ diff --git a/lib/mouse.ppu b/lib/mouse.ppu index ee7b60c2..54f8726b 100644 Binary files a/lib/mouse.ppu and b/lib/mouse.ppu differ diff --git a/lib/pmemorymanager.ppu b/lib/pmemorymanager.ppu index 2ea1e620..590b2810 100644 Binary files a/lib/pmemorymanager.ppu and b/lib/pmemorymanager.ppu differ diff --git a/lib/scheduler.ppu b/lib/scheduler.ppu index b3a6507d..6465bf31 100644 Binary files a/lib/scheduler.ppu and b/lib/scheduler.ppu differ diff --git a/lib/terminal.ppu b/lib/terminal.ppu index a981f485..35b63f2d 100644 Binary files a/lib/terminal.ppu and b/lib/terminal.ppu differ diff --git a/lib/testdriver.ppu b/lib/testdriver.ppu index ac614f55..f633bfe3 100644 Binary files a/lib/testdriver.ppu and b/lib/testdriver.ppu differ diff --git a/lib/tss.ppu b/lib/tss.ppu index 024b647a..9916f0d0 100644 Binary files a/lib/tss.ppu and b/lib/tss.ppu differ diff --git a/lib/util.ppu b/lib/util.ppu index 9c242c3d..5e46d28e 100644 Binary files a/lib/util.ppu and b/lib/util.ppu differ diff --git a/lib/vmemorymanager.ppu b/lib/vmemorymanager.ppu index 300b3a01..f725536b 100644 Binary files a/lib/vmemorymanager.ppu and b/lib/vmemorymanager.ppu differ diff --git a/src/bios_data_area.pas b/src/bios_data_area.pas index 89d26339..1311adee 100644 --- a/src/bios_data_area.pas +++ b/src/bios_data_area.pas @@ -71,7 +71,7 @@ end; procedure init(); begin - console.writestringln('BDA: Loaded.'); + console.outputln('BDA','Loaded.'); //TO-DO search for important structures like the MCFG or the EBDA. end; diff --git a/src/console.pas b/src/console.pas index 95777ce4..02235a08 100644 --- a/src/console.pas +++ b/src/console.pas @@ -42,6 +42,9 @@ procedure writecharln(character : char); procedure writecharex(character : char; attributes : char); procedure writecharlnex(character : char; attributes : char); +procedure Output(identifier : PChar; str : PChar); +procedure Outputln(identifier : PChar; str : PChar); + procedure writestring(str: PChar); procedure writestringln(str: PChar); procedure writestringex(str: PChar; attributes : char); @@ -57,6 +60,7 @@ procedure writewordln(i: DWORD); procedure writewordex(i: DWORD; attributes : char); procedure writewordlnex(i: DWORD; attributes : char); +procedure writehexpair(b : uint8); procedure writehex(i: DWORD); procedure writehexln(i: DWORD); procedure writehexex(i : DWORD; attributes : char); @@ -278,6 +282,36 @@ begin console._safeincrement_x(); end; +procedure writehexpair(b : uint8); +var + bn : Array[0..1] of uint8; + i : uint8; + +begin + bn[0]:= b SHR 4; + bn[1]:= b AND $0F; + for i:=0 to 1 do begin + case bn[i] of + 0:writestring('0'); + 1:writestring('1'); + 2:writestring('2'); + 3:writestring('3'); + 4:writestring('4'); + 5:writestring('5'); + 6:writestring('6'); + 7:writestring('7'); + 8:writestring('8'); + 9:writestring('9'); + 10:writestring('A'); + 11:writestring('B'); + 12:writestring('C'); + 13:writestring('D'); + 14:writestring('E'); + 15:writestring('F'); + end; + end; +end; + procedure writehexex(i : dword; attributes: char); [public, alias: 'console_writehexex']; var Hex : Array[0..7] of Byte; @@ -340,6 +374,20 @@ begin writehexlnex(i, Console_Properties.Default_Attribute); end; +procedure Output(identifier : PChar; str : PChar); +begin + writestring('['); + writestring(identifier); + writestring('] '); + writestring(str); +end; + +procedure Outputln(identifier : PChar; str : PChar); +begin + Output(identifier, str); + writestringln(' '); +end; + procedure writestringex(str: PChar; attributes: char); [public, alias: 'console_writestringex']; var i : integer; diff --git a/src/driver/HID/keyboard.pas b/src/driver/HID/keyboard.pas index c527f65e..fd384016 100644 --- a/src/driver/HID/keyboard.pas +++ b/src/driver/HID/keyboard.pas @@ -62,7 +62,7 @@ end; function load(ptr : void) : boolean; begin isr33.hook(uint32(@callback)); - console.writestringln('PS/2 KEYBOARD: LOADED.'); + console.outputln('PS/2 KEYBOARD', 'LOADED.'); load:= true; end; @@ -71,7 +71,7 @@ var devid : TDeviceIdentifier; begin - console.writestringln('PS/2 KEYBOARD: INIT BEGIN.'); + console.outputln('PS/2 KEYBOARD', 'INIT BEGIN.'); if keyboard_layout[1].key_code = 0 then lang_USA(); devid.bus:= biUnknown; devid.id0:= 0; @@ -81,7 +81,7 @@ begin devid.id4:= 0; devid.ex:= nil; drivermanagement.register_driver_ex('PS/2 Keyboard', @devid, @load, true); - console.writestringln('PS/2 KEYBOARD: INIT END.'); + console.outputln('PS/2 KEYBOARD', 'INIT END.'); end; //2A AA diff --git a/src/driver/HID/mouse.pas b/src/driver/HID/mouse.pas index 9529c151..92ecb341 100644 --- a/src/driver/HID/mouse.pas +++ b/src/driver/HID/mouse.pas @@ -107,7 +107,7 @@ end; function load(ptr : void) : boolean; begin isr44.hook(uint32(@callback)); - console.writestringln('PS/2 MOUSE: LOADED.'); + console.outputln('PS/2 MOUSE', 'LOADED.'); load:= true; end; @@ -116,7 +116,7 @@ var devid : TDeviceIdentifier; begin - console.writestringln('PS/2 MOUSE: INIT BEGIN.'); + console.outputln('PS/2 MOUSE', 'INIT BEGIN.'); devid.bus:= biUnknown; devid.id0:= 0; devid.id1:= 0; @@ -125,7 +125,7 @@ begin devid.id4:= 0; devid.ex:= nil; drivermanagement.register_driver_ex('PS/2 Mouse', @devid, @load, true); - console.writestringln('PS/2 MOUSE: INIT END.'); + console.outputln('PS/2 MOUSE', 'INIT END.'); end; end. \ No newline at end of file diff --git a/src/driver/PCI.pas b/src/driver/PCI.pas index 391b754f..ed2bb101 100644 --- a/src/driver/PCI.pas +++ b/src/driver/PCI.pas @@ -79,14 +79,14 @@ var current_bus : uint8; begin - console.writestringln('PCI: Scanning Bus: 0'); + console.outputln('PCI', 'Scanning Bus: 0'); scanBus(0); //while unscanned busses scan busses current_bus := 1; while true do begin if current_bus < bus_count then begin - console.writestringln('PCI: Scanning Bus: '); - console.writeint(bus_count); + console.output('PCI', 'Scanning Bus: '); + console.writeintln(bus_count); scanBus(current_bus); current_bus := current_bus + 1; end else break; @@ -99,7 +99,7 @@ var DevID : TDeviceIdentifier; begin - console.writestringln('PCI: INIT BEGIN.'); + console.outputln('PCI','INIT BEGIN.'); DevID.Bus:= biUnknown; DevID.id0:= 0; DevID.id1:= 0; @@ -107,7 +107,7 @@ begin DevID.id3:= 0; DevID.ex:= nil; drivermanagement.register_driver_ex('PCI Driver', @DevID, @load, true); - console.writestringln('PCI: INIT END.'); + console.outputln('PCI', 'INIT END.'); end; procedure scanBus(bus : uint8); @@ -315,7 +315,7 @@ begin DevID^.id4:= device.vendor_id; DevID^.ex:= nil; - console.writestring('PCI: Found Device: '); + console.output('PCI', 'Found Device: '); console.writehex(device.header_type); console.writestring(' '); console.writehex(device.device_id); diff --git a/src/driver/bus/USB.pas b/src/driver/bus/USB.pas index 66bf4700..e85d0f17 100644 --- a/src/driver/bus/USB.pas +++ b/src/driver/bus/USB.pas @@ -50,12 +50,12 @@ var begin devices:= PCI.getDeviceInfo($0C, $03, $10, count); - console.writestring('USB-OHCI: Found '); + console.output('USB-OHCI Driver', 'Found '); console.writeint(count); console.writestringln(' USB Controller(s).'); if count > 0 then begin for i:=0 to count-1 do begin - console.writestring('USB: Controller['); + console.output('USB-OHCI Driver', 'Controller['); console.writeint(i); console.writestring(']: '); console.writehex(devices[i].device_id); @@ -80,12 +80,12 @@ var begin devices:= PCI.getDeviceInfo($0C, $03, $00, count); - console.writestring('USB-UHCI: Found '); + console.output('USB-UHCI Driver','Found '); console.writeint(count); console.writestringln(' USB Controller(s).'); if count > 0 then begin for i:=0 to count-1 do begin - console.writestring('USB: Controller['); + console.output('USB-UHCI Driver','Controller['); console.writeint(i); console.writestring(']: '); console.writehex(devices[i].device_id); @@ -103,7 +103,7 @@ var UHCI_ID, OHCI_ID : TDeviceIdentifier; begin - console.writestringln('USB: INIT BEGIN.'); + console.outputln('USB Driver', 'INIT BEGIN.'); UHCI_ID.Bus:= biPCI; UHCI_ID.id0:= idANY; @@ -124,7 +124,7 @@ begin drivermanagement.register_driver('USB-UHCI Driver', @UHCI_ID, @loadUHCI); drivermanagement.register_driver('USB-OHCI Driver', @OHCI_ID, @loadOHCI); - console.writestringln('USB: INIT END.'); + console.outputln('USB Driver', 'INIT END.'); end; end. \ No newline at end of file diff --git a/src/driver/network/E1000.pas b/src/driver/network/E1000.pas index 85f72d26..10fb6eeb 100644 --- a/src/driver/network/E1000.pas +++ b/src/driver/network/E1000.pas @@ -7,7 +7,9 @@ uses strings, vmemorymanager, lmemorymanager, - drivermanagement; + drivermanagement, + drivertypes, + util; const INTEL_VEND = $8086; @@ -95,6 +97,9 @@ const TSTA_LC = (1 SHL 2); // Late Collision LSTA_TU = (1 SHL 3); // Transmit Underrun + E1000_NUM_RX_DESC = 32; + E1000_NUM_TX_DESC = 8; + type PE1000_rx_desc = ^TE1000_rx_desc; TE1000_rx_desc = bitpacked record @@ -117,62 +122,203 @@ type special : uint16; end; + TCardType = (ctUnknown, ctE1000, ctI217, ct82577LM); + procedure init(); procedure fire(); -function getMACAddress : uint8; +function getMACAddress : puint8; function sendPacket(p_data : void; p_len : uint16) : sint32; implementation var + loaded : boolean; + card_type : TCardType; bar_type : uint8; io_base : uint16; mem_base : uint64; eeprom_exists : boolean; mac : array[0..5] of uint8; - rx_descs : array[0..65535] of TE1000_rx_desc; - tx_descs : array[0..65535] of TE1000_tx_desc; + rx_descs : array[0..E1000_NUM_RX_DESC-1] of PE1000_rx_desc; + tx_descs : array[0..E1000_NUM_TX_DESC-1] of PE1000_tx_desc; rx_curr : uint16; tx_curr : uint16; procedure writeCommand(p_address : uint16; p_value : uint32); +var + mem : puint32; + begin - + if (bar_type = 0) then begin + mem:= puint32(mem_base + p_address); + mem^:= p_value; + end else begin + outl(io_base + 0, p_address); + outl(io_base + 4, p_address) + end; end; function readCommand(p_address : uint16) : uint32; +var + mem : puint32; + begin - + if (bar_type = 0) then begin + mem:= puint32(mem_base + p_address); + readCommand:= mem^; + end else begin + outl(io_base, p_address); + readCommand:= inl(io_base + 4); + end; end; function detectEEPROM() : boolean; -begin +var + val, i : uint32; +begin + val:= 0; + writeCommand(REG_EEPROM, $1); + for i:=0 to 1000 do begin + if eeprom_exists then break; + val:= readCommand(REG_EEPROM); + if (val and $10) > 0 then eeprom_exists:= true else eeprom_exists:= false; + end; + detectEEPROM:= eeprom_exists; end; function EEPROMRead( address : uint8 ) : uint32; -begin +var + data : uint16; + tmp : uint32; +begin + tmp:= 0; + if (eeprom_exists) then begin + writeCommand( REG_EEPROM, 1 OR (uint32(address) SHL 8) ); + while (tmp AND (1 SHL 4)) = 0 do begin + tmp:= readCommand(REG_EEPROM); //Might be wrong? + end; + end else begin + writeCommand( REG_EEPROM, 1 OR (uint32(address) SHL 2) ); + while (tmp AND (1 SHL 1)) = 0 do begin + tmp:= readCommand(REG_EEPROM); //Might be wrong? + end; + end; + data:= uint16( (tmp SHR 16) AND ($FFFF) ); + EEPROMRead:= data; end; function readMACAddress() : boolean; -begin +var + temp : uint32; + mem_base_mac_8 : puint8; + mem_base_mac_32 : puint32; + res : boolean; + i : uint32; +begin + res:= true; + if (eeprom_exists) then begin + temp:= EEPROMRead(0); + mac[0]:= temp AND $FF; + mac[1]:= temp SHR 8; + temp:= EEPROMRead(1); + mac[2]:= temp AND $FF; + mac[3]:= temp SHR 8; + temp:= EEPROMRead(2); + mac[4]:= temp AND $FF; + mac[5]:= temp SHR 8; + end else begin + mem_base_mac_8:= puint8(mem_base + $5400); + mem_base_mac_32:= puint32(mem_base + $5400); + if (mem_base_mac_32[0] <> 0) then begin + for i:=0 to 6 do begin + mac[i]:= mem_base_mac_8[i]; + end; + end else begin + res:= false; + end; + end; + readMACAddress:= res; end; procedure startLink(); -begin +var + val : uint32; +begin + val:= readCommand(REG_CTRL); + writeCommand(REG_CTRL, val OR ECTRL_SLU); end; procedure rxinit(); -begin +var + ptr : puint8; + outptr : puint8; + descs : PE1000_rx_desc; + i : uint32; +begin + ptr:= puint8(kalloc(sizeof(TE1000_rx_desc) * E1000_NUM_RX_DESC + 16)); + descs:= PE1000_rx_desc(ptr); + for i:=0 to E1000_NUM_RX_DESC do begin + rx_descs[i]:= PE1000_rx_desc(uint32(descs + i*16)); + rx_descs[i]^.address:= uint64(kalloc(8192 + 16)); + rx_descs[i]^.status:= 0; + end; + + outptr:= puint8(uint32(ptr) - KERNEL_VIRTUAL_BASE); + + writeCommand(REG_TXDESCLO, uint32(uint64(outptr) SHR 32)); + writeCommand(REG_TXDESCHI, uint32(uint64(outptr) AND $FFFFFFFF)); + + writeCommand(REG_RXDESCLO, uint32(outptr)); + writeCommand(REG_RXDESCHI, 0); + + writeCommand(REG_RXDESCLEN, E1000_NUM_RX_DESC * 16); + + writeCommand(REG_RXDESCHEAD, 0); + writeCommand(REG_RXDESCTAIL, E1000_NUM_RX_DESC-1); + rx_curr:= 0; + + writeCommand(REG_RCTRL, RCTL_EN OR RCTL_SBP OR RCTL_UPE OR RCTL_MPE OR RCTL_LBM_NONE OR RTCL_RDMTS_HALF OR RCTL_BAM OR RCTL_SECRC OR RCTL_BSIZE_2048); end; procedure txinit(); -begin +var + ptr : puint8; + outptr : puint8; + descs : PE1000_tx_desc; + i : uint32; +begin + ptr:= puint8(kalloc(sizeof(TE1000_tx_desc) * E1000_NUM_TX_DESC + 16)); + descs:= PE1000_tx_desc(ptr); + for i:=0 to E1000_NUM_TX_DESC do begin + tx_descs[i]:= PE1000_tx_desc(uint32(descs + i*16)); + tx_descs[i]^.address:= 0; + tx_descs[i]^.cmd:= 0; + tx_descs[i]^.status:= TSTA_DD; + end; + + outptr:= puint8(uint32(ptr) - KERNEL_VIRTUAL_BASE); + + writeCommand(REG_TXDESCHI, uint32(uint64(outptr) SHR 32)); + writeCommand(REG_TXDESCLO, uint32(uint64(outptr) AND $FFFFFFFF)); + + writeCommand(REG_TXDESCLEN, E1000_NUM_TX_DESC * 16); + + writeCommand( REG_TXDESCHEAD, 0 ); + writeCommand( REG_TXDESCTAIL, 0 ); + tx_curr:= 0; + writeCommand(REG_TCTRL, TCTL_EN OR TCTL_PSP OR (15 SHL TCTL_CT_SHIFT) OR (64 SHL TCTL_COLD_SHIFT) OR TCTL_RTLC); + + //The following is needed for I217 & 82577LM + if (card_type = ct82577LM) OR (card_type = ctI217) then begin + writeCommand(REG_TCTRL, $3003F0FA); + writeCommand(REG_TIPG, $0060200A); + end; end; procedure enableInturrupt(); @@ -185,9 +331,88 @@ begin end; -function load(ptr : void) : boolean; +procedure writeCardType(); begin - load:= true; + console.output('E1000 Driver', 'Card Type: '); + case card_type of + ctUnknown:writestringln('Unknown'); + ct82577LM:writestringln('82577LM'); + ctE1000:writestringln('Generic E1000'); + ctI217:writestringln('I217'); + end; +end; + +procedure writeMACAddress(); +var + i : integer; + +begin + console.writehexpair(mac[0]); + for i:=1 to 5 do begin + console.writestring(':'); + console.writehexpair(mac[i]); + end; + console.writestringln(' '); +end; + +function load(ptr : void) : boolean; +var + PCI_Info : PPCI_Device; +begin + console.outputln('E1000 Driver', 'Load Start.'); + + writeCardType(); + + PCI_Info:= PPCI_Device(ptr); + bar_type:= PCI_Info^.address0 AND $00000001; + io_base:= PCI_Info^.address0 AND $FFFFFFF0; + mem_base:= PCI_INFO^.address0 AND $FFFFFFFC; + + { !!!!! Dirty way to alloc the pages, needs fixing !!!!! } + kpalloc(io_base); + kpalloc(mem_base); + + eeprom_exists:= false; + detectEEPROM(); + if eeprom_exists then console.outputln('E1000 Driver', 'EEPROM Exists: YES.') else console.outputln('E1000 Driver', 'EEPROM Exists: NO.'); + if not readMACAddress() then begin + console.outputln('E1000 Driver', 'MAC Read Failed.'); + load:= false; + exit; + end; + console.output('E1000 Driver', 'MAC Address: '); + writeMACAddress(); + + startLink(); + load:= true; + console.outputln('E1000 Driver', 'Load Finish.'); +end; + +function loadE1000(ptr : void) : boolean; +begin + loadE1000:= false; + if not Loaded then begin + card_type:= ctE1000; + loadE1000:= load(ptr); + end; +end; + +function load82577LM(ptr : void) : boolean; +begin + load82577LM:= false; + if not Loaded then begin + card_type:= ct82577LM; + load82577LM:= load(ptr); + end; +end; + +function loadI217(ptr : void) : boolean; +begin + loadI217:= false; + if not Loaded then begin + card_type:= ctI217; + loadI217:= load(ptr); + end; end; procedure init(); @@ -195,6 +420,7 @@ var dev : TDeviceIdentifier; begin + card_type:= ctUnknown; dev.Bus:= biPCI; dev.id0:= INTEL_VEND; dev.id1:= idANY; @@ -202,11 +428,11 @@ begin dev.id3:= idANY; dev.id4:= E1000_DEV; dev.ex:= nil; - drivermanagement.register_driver('E1000 Ethernet Driver', @dev, @load); + drivermanagement.register_driver('E1000 Ethernet Driver', @dev, @loadE1000); dev.id4:= I217_DEV; - drivermanagement.register_driver('I217 Ethernet Driver', @dev, @load); + drivermanagement.register_driver('I217 Ethernet Driver', @dev, @loadI217); dev.id4:= LM82577_DEV; - drivermanagement.register_driver('82577LM Ethernet Driver', @dev, @load); + drivermanagement.register_driver('82577LM Ethernet Driver', @dev, @load82577LM); end; procedure fire(); @@ -214,9 +440,9 @@ begin end; -function getMACAddress : uint8; +function getMACAddress : puint8; begin - + getMACAddress:= puint8(@mac[0]); end; function sendPacket(p_data : void; p_len : uint16) : sint32; diff --git a/src/driver/testdriver.pas b/src/driver/testdriver.pas index fda02bc6..a5f7ca12 100644 --- a/src/driver/testdriver.pas +++ b/src/driver/testdriver.pas @@ -11,7 +11,7 @@ implementation function load(ptr : void) : boolean; begin - console.writestringln('DUMMY DRIVER LOADED.') + console.outputln('DUMMY DRIVER', 'LOADED.') end; procedure init; diff --git a/src/drivermanagement.pas b/src/drivermanagement.pas index de731863..41d63022 100644 --- a/src/drivermanagement.pas +++ b/src/drivermanagement.pas @@ -307,7 +307,12 @@ begin end; RegList^.Next:= NewReg; end; + console.output('Driver Management', 'New Driver Registered: '); + console.writestringln(NewReg^.Driver_Name); if force_load then begin + console.output('Driver Management', 'Driver ('); + console.writestring(NewReg^.Driver_Name); + console.writestringln(') forced to load.'); NewReg^.Loaded:= True; NewReg^.Driver_Load(nil); end; @@ -336,9 +341,18 @@ begin end; dev_list^.Next:= new_dev; end; + console.output('Driver Management', 'New Device Registered: '); + console.writestringln(new_dev^.Device_Name); while drv <> nil do begin if identifiers_match(drv^.Identifier, DeviceID) then begin + console.output('Driver Management', 'Device/Driver Match: '); + console.writestring(new_dev^.Device_Name); + console.writestring('->'); + console.writestringln(drv^.Driver_Name); if drv^.Driver_Load(ptr) then begin + console.output('Driver Management', 'Driver ('); + console.writestring(drv^.Driver_Name); + console.writestringln(') successfully loaded.'); drv^.Loaded:= true; new_dev^.Driver_Loaded:= true; new_dev^.Driver:= drv; diff --git a/src/gdt.pas b/src/gdt.pas index 6c38ba5f..11a1a567 100644 --- a/src/gdt.pas +++ b/src/gdt.pas @@ -58,7 +58,7 @@ end; procedure flush; begin - console.writestringln('GDT: FLUSH.'); + console.outputln('GDT','FLUSH.'); flush_gdt(uint32(@gdt_pointer)); end; @@ -70,7 +70,7 @@ end; procedure reload; begin - console.writestringln('GDT: RELOAD.'); + console.outputln('GDT','RELOAD.'); reload_gdt(uint32(@gdt_pointer)); end; @@ -90,14 +90,14 @@ begin gdt_entries[Gate_Number].limit_low := (Limit AND $FFFF); gdt_entries[Gate_Number].granularity := ((Limit SHR 16) AND $0F) OR (Granularity AND $F0); gdt_entries[Gate_Number].access := Access; - console.writestring('GDT: GATE '); + console.output('GDT','GATE '); console.writeint(Gate_Number); console.writestringln(' SET.'); end; procedure init(); begin - console.writestringln('GDT: INIT START.'); + console.outputln('GDT','INIT START.'); gdt_pointer.limit:= 0; gdt_pointer.base := uint32(@gdt_entries); set_gate($00, $00, $00, $00, $00); //OFFSET: 0 @@ -106,7 +106,7 @@ begin set_gate($03, $00, $FFFFFFFF, $FA, $CF); //OFFSET: 24 set_gate($04, $00, $FFFFFFFF, $F2, $CF); //OFFSET: 32 flush; - console.writestringln('GDT: INIT END.'); + console.outputln('GDT','INIT END.'); end; end. \ No newline at end of file diff --git a/src/idt.pas b/src/idt.pas index 3c3f609e..f90bba7f 100644 --- a/src/idt.pas +++ b/src/idt.pas @@ -52,7 +52,7 @@ begin IDT_Entries[Number].selector:= Selector; IDT_Entries[Number].flags:= Flags; IDT_Entries[Number].always_0:= $00; - console.writestring('IDT: GATE '); + console.output('IDT','GATE '); console.writeint(Number); console.writestringln(' SET.'); end; @@ -65,14 +65,14 @@ end; procedure init(); begin - console.writestringln('IDT: INIT START.'); + console.outputln('IDT','INIT START.'); IDT_Pointer.limit:= (sizeof(TIDT_Entry) * 256) - 1; IDT_Pointer.base:= uint32(@IDT_Entries); - console.writestringln('IDT: CLEAR.'); + console.outputln('IDT','CLEAR.'); util.memset(uint32(@IDT_Entries[0]), 0, sizeof(TIDT_Entry) * 256); - console.writestringln('IDT: LOAD.'); + console.outputln('IDT','LOAD.'); load(uint32(@IDT_Pointer)); - console.writestringln('IDT: INIT END.'); + console.outputln('IDT','INIT END.'); end; end. \ No newline at end of file diff --git a/src/irq.pas b/src/irq.pas index b815853d..bdee02f7 100644 --- a/src/irq.pas +++ b/src/irq.pas @@ -19,7 +19,7 @@ implementation procedure init(); begin - console.writestringln('IRQ: INIT START.'); + console.outputln('IRQ','INIT START.'); outb($20, $11); outb($A0, $11); outb($21, $20); @@ -30,7 +30,7 @@ begin outb($A1, $01); outb($21, $00); outb($A1, $00); - console.writestringln('IRQ: INIT END.'); + console.outputln('IRQ','INIT END.'); end; end. \ No newline at end of file diff --git a/src/isr.pas b/src/isr.pas index 9b8c1650..66a05462 100644 --- a/src/isr.pas +++ b/src/isr.pas @@ -24,7 +24,7 @@ implementation procedure init(); begin - console.writestringln('ISR: INIT START.'); + console.outputln('ISR','INIT START.'); ISR0.register(); // Divide-By-Zero ISR1.register(); // Debug ISR2.register(); // Non-Maskable Inturrupt @@ -49,7 +49,7 @@ begin ISR33.register(); // Keyboard ISR40.register(); // 1024/s Timer ISR44.register(); // Mouse - console.writestringln('ISR: INIT END.'); + console.outputln('ISR','INIT END.'); end; end. \ No newline at end of file diff --git a/src/kernel.pas b/src/kernel.pas index bc9f4e82..f8749144 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -89,8 +89,8 @@ begin if (multibootmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin console.setdefaultattribute(console.combinecolors(Red, Black)); - console.writestringln('Multiboot Compliant Boot-Loader Needed!'); - console.writestringln('HALTING'); + console.outputln('KERNEL', 'Multiboot Compliant Boot-Loader Needed!'); + console.outputln('KERNEL', 'HALTING.'); util.halt_and_catch_fire; end; @@ -99,9 +99,10 @@ begin MOV dds, CS end; if dds = $08 then begin - console.writestringlnex('GDT: LOAD SUCCESS.', console.combinecolors(Green, Black)); + console.outputln('KERNEL', 'GDT: LOAD SUCCESS.'); end else begin - console.writestringlnex('GDT: LOAD FAIL.', console.combinecolors(Red, Black)); + console.outputln('KERNEL', 'GDT: LOAD FAIL.'); + console.outputln('KERNEL', 'HALTING.'); halt_and_catch_fire; end; @@ -121,7 +122,7 @@ begin isr32.hook(uint32(@bios_data_area.tick_update)); //drivers - console.writestringln('DRIVERS: INIT BEGIN.'); + console.outputln('KERNEL', 'DRIVERS: INIT BEGIN.'); keyboard.init(keyboard_layout); mouse.init(); testdriver.init(); @@ -130,7 +131,7 @@ begin //Nothing beyond here USB.init(); pci.init(); - console.writestringln('DRIVERS: INIT END.'); + console.outputln('KERNEL', 'DRIVERS: INIT END.'); console.writestringln(''); console.setdefaultattribute(console.combinecolors(Green, Black)); diff --git a/src/lmemorymanager.pas b/src/lmemorymanager.pas index ab1e397f..04ddef54 100644 --- a/src/lmemorymanager.pas +++ b/src/lmemorymanager.pas @@ -86,7 +86,7 @@ var i : uint32; begin - console.writestringln('LMM: INIT BEGIN.'); + console.outputln('LMM','INIT BEGIN.'); Root_Page:= PHeapPage(new_lmm_page); Search_Page:= Root_Page; Root_Page^.Next_Page:= 0; @@ -96,7 +96,7 @@ begin Root_Page^.Entries[i].Root:= False; Root_Page^.Entries[i].Last:= False; end; - console.writestringln('LMM: INIT END.'); + console.outputln('LMM','INIT END.'); end; function kpalloc(address : uint32) : void; diff --git a/src/pmemorymanager.pas b/src/pmemorymanager.pas index 83805634..6ee9e6c8 100644 --- a/src/pmemorymanager.pas +++ b/src/pmemorymanager.pas @@ -109,15 +109,15 @@ end; procedure init; begin - console.writestringln('PMM: INIT BEGIN.'); + console.outputln('PMM','INIT BEGIN.'); walk_memory_map; force_alloc_block(0, 0); force_alloc_block(1, 0); force_alloc_block(2, 0); //First 12MiB reserved for Kernel/BIOS. - console.writestring('PMM: '); + console.output('PMM',' '); console.writeword(nPresent); console.writestringln('/1024 Block Available for Allocation.'); - console.writestringln('PMM: INIT END.'); + console.outputln('PMM','INIT END.'); end; function alloc_block(block : uint16; caller : uint32) : boolean; diff --git a/src/scheduler.pas b/src/scheduler.pas index 2f8c5aeb..2da94438 100644 --- a/src/scheduler.pas +++ b/src/scheduler.pas @@ -105,7 +105,7 @@ end; procedure init; begin - console.writestringln('SCHEDULER: INIT BEGIN.'); + console.outputln('SCHEDULER','INIT BEGIN.'); Root_Task:= PScheduler_Entry(kalloc(sizeof(TScheduler_Entry))); Root_Task^.ThreadID:= 0; Root_Task^.Priority:= 1; @@ -116,7 +116,7 @@ begin Active:= False; isr32.hook(uint32(@delta)); terminal.registerCommand('TASKS', @terminal_command_tasks, 'List Active Processes.'); - console.writestringln('SCHEDULER: INIT END.'); + console.outputln('SCHEDULER','INIT END.'); end; end. \ No newline at end of file diff --git a/src/tss.pas b/src/tss.pas index 35d7e818..d3e253e8 100644 --- a/src/tss.pas +++ b/src/tss.pas @@ -79,7 +79,7 @@ var cCR3 : uint32; begin - console.writestringln('TSS: INIT BEGIN.'); + console.outputln('TSS','INIT BEGIN.'); ptrTaskStateSegment^.ss0:= $08; ptrTaskStateSegment^.iomap:= sizeof(TTaskStateSegment)-1; asm @@ -95,7 +95,7 @@ begin mov AX, 40 ltr AX end; - console.writestringln('TSS: INIT END.'); + console.outputln('TSS','INIT END.'); end; end. \ No newline at end of file diff --git a/src/vmemorymanager.pas b/src/vmemorymanager.pas index 26aee3de..8a72eade 100644 --- a/src/vmemorymanager.pas +++ b/src/vmemorymanager.pas @@ -90,13 +90,13 @@ var i : uint32; begin - console.writestringln('VMM: INIT BEGIN.'); + console.outputln('VMM','INIT BEGIN.'); PageDirectory:= load_current_page_directory; KERNEL_PAGE_DIRECTORY:= PageDirectory; map_page(KERNEL_PAGE_NUMBER + 1, 1); map_page(KERNEL_PAGE_NUMBER + 2, 2); map_page(KERNEL_PAGE_NUMBER + 3, 3); - console.writestringln('VMM: INIT END.'); + console.outputln('VMM','INIT END.'); end; function map_page_ex(page_number : uint16; block : uint16; PD : PPageDirectory) : boolean; @@ -139,7 +139,7 @@ var rldpd : uint32; begin - map_page:= false; + map_page:= false; PageDirectory^[page_number].Present:= true; addr:= block; PageDirectory^[page_number].Address:= addr SHL 10;