Changes
git-svn-id: https://spexeah.com:8443/svn/Asuro@165 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
101
src/driver/AHCI.pas
Normal file
101
src/driver/AHCI.pas
Normal file
@ -0,0 +1,101 @@
|
||||
{ ************************************************
|
||||
* Asuro
|
||||
* Unit: Drivers/AHCI
|
||||
* Description: AHCI SATA Driver
|
||||
************************************************
|
||||
* Author: Aaron Hance
|
||||
* Contributors:
|
||||
************************************************ }
|
||||
|
||||
unit AHCI
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
system,
|
||||
util,
|
||||
isr46;
|
||||
|
||||
type
|
||||
|
||||
//Struct hell
|
||||
|
||||
TFIS_Type = (
|
||||
REG_H2D, REG_D2H,
|
||||
DMA_ACT, DMA_SETUP,
|
||||
DATA, BIST,
|
||||
PIO_SETUP, DEV_BITS
|
||||
);
|
||||
|
||||
TFIS_REG_H2D bitpacked record
|
||||
fis_type : uint8;
|
||||
port_mult : UBit4;
|
||||
rsv0 : UBit3;
|
||||
coc : boolean;
|
||||
command : uint8;
|
||||
feature_low : uint8;
|
||||
lba0 : uint8;
|
||||
lba1 : uint8;
|
||||
lba2 : uint8;
|
||||
device : uint8;
|
||||
lba3 : uint8;
|
||||
lba4 : uint8;
|
||||
lba5 : uint8;
|
||||
feature_high : uint8;
|
||||
count_low : uint8;
|
||||
count_high : uint8;
|
||||
icc : uint8;
|
||||
control : uint8;
|
||||
rsvl : uint32;
|
||||
end;
|
||||
|
||||
TFIS_REG_D2H bitpacked record
|
||||
fis_type : uint8;
|
||||
port_mult : UBit4;
|
||||
rsv0 : UBit2;
|
||||
i : boolean;
|
||||
rsvl : boolean;
|
||||
status : uint8;
|
||||
error : uint8;
|
||||
lba0 : uint8;
|
||||
lba1 : uint8;
|
||||
lba2 : uint8;
|
||||
device : uint8;
|
||||
lba3 : uint8;
|
||||
lba4 : uint8;
|
||||
lba5 : uint8;
|
||||
rsv2 : uint8;
|
||||
count_low : uint8;
|
||||
count_high : uint8;
|
||||
rsv3 : uint16;
|
||||
rsv4 : uint32;
|
||||
end;
|
||||
|
||||
TFIS_Data bitpacked record
|
||||
fis_type : uint8;
|
||||
port_mult : UBit4;
|
||||
rsv0 : UBit4;
|
||||
rsv1 : uint16;
|
||||
data : ^uint32;
|
||||
end;
|
||||
|
||||
TFIS_PIO_Setup bitpakced record
|
||||
end;
|
||||
|
||||
TFIS_DMA_Setup bitpacked record
|
||||
end;
|
||||
|
||||
THBA_Memory bitpacked record
|
||||
end;
|
||||
|
||||
THBA_Port bitpacked record
|
||||
end;
|
||||
|
||||
THBA_FIS bitpacked record
|
||||
end;
|
||||
|
||||
var
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
251
src/driver/PCI.pas
Normal file
251
src/driver/PCI.pas
Normal file
@ -0,0 +1,251 @@
|
||||
{ ************************************************
|
||||
* Asuro
|
||||
* Unit: Drivers/PCI
|
||||
* Description: PCI Driver
|
||||
************************************************
|
||||
* Author: Aaron Hance
|
||||
* Contributors:
|
||||
************************************************ }
|
||||
|
||||
unit PCI
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
system,
|
||||
util;
|
||||
|
||||
type
|
||||
|
||||
TClass_Code = (
|
||||
LEGACY, MASS_STORAGE_CONTROLLER, NETWORK_CONTROLLER,
|
||||
DISPLAY_CONTROLLER, MULTIMEDIA_CONTROLLER, MEMORY_CONTROLLER,
|
||||
BRIDGE_DEVICE, SIMPLE_COMM_CONTROLLER, BASE_SYS_PERIPHERALS,
|
||||
INPUT_DEVICE, DOCKING_STATION, PROCESSOR, SERIAL_BUS_CONTROLLER,
|
||||
WIRELESS_CONTROLLER, INTELLIGENT_IO_CONTROLLER,
|
||||
SATELLITE_COMM_CONTROLLER, ENCRYPTION_CONTROLLER,
|
||||
SIGNAL_PROCESSING_CONTROLLER, RESERVED
|
||||
); // 0XFF = OTHER DEVICE
|
||||
|
||||
TSub_Class_Codes record // first half sub device, second half prog id
|
||||
any_non_vga_compatible : uint16 = $0000;
|
||||
any_vga_compatible : uint16 = $0100;
|
||||
scsi_bus_controller : uint16 = $0000;
|
||||
ide_controller : uint16 = $01FF;
|
||||
floppy_controller : uint16 = $0200;
|
||||
ipi_bus_controller : uint16 = $0300;
|
||||
raid_controller : uint16 = $0400;
|
||||
ata_single_dma : uint16 = $0520;
|
||||
ata_chained_dma : uint16 = $0530;
|
||||
serial_ata_ahci_vsi : uint16 = $0600;
|
||||
serial_ata_ahci : uint16 = $0601;
|
||||
serial_attached_scsi : uint16 = $0700;
|
||||
other_mass_storage : uint16 = $8000;
|
||||
ethernet_controller : uint16 = $0000;
|
||||
token_ring_controller : uint16 = $0100;
|
||||
fddi_controller : uint16 = $0200;
|
||||
atm_controller : uint16 = $0300;
|
||||
isdn_controller : uint16 = $0400;
|
||||
worldfip_controller : uint16 = $0500;
|
||||
picmg_multi_computing : uint16 = $0600;
|
||||
other_network_controller : uint16 = $8000;
|
||||
vga_compatible_controller : uint16 = $0000;
|
||||
c8512_compatible_controller : uint16 = $0001;
|
||||
xga_controller : uint16 = $0100;
|
||||
c3d_controller : uint16 = $0200;
|
||||
other_display_controller : uint16 = $8000;
|
||||
video_device : uint16 = $0000;
|
||||
audio_device : uint16 = $0100;
|
||||
computer_telephony_device : uint16 = $0200;
|
||||
other_multimedia_device : uint16 = $8000;
|
||||
ram_controller : uint16 = $0000;
|
||||
flash_controller : uint16 = $0100;
|
||||
other_memory_controller : uint16 = $8000;
|
||||
host_bridge : uint16 = $0100;
|
||||
isa_bridge : uint16 = $0200;
|
||||
eisa_bridge : uint16 = $0300;
|
||||
pci_2_pci_bridge : uint16 = $0400;
|
||||
subtractive_pci_2_pci_bridge : uint16 = $0401;
|
||||
pcmcia_bridge : uint16 = $0500;
|
||||
nubus_bridge : uint16 = $0600;
|
||||
cardbus_bridge : uint16 = $0700;
|
||||
raceway_bridge : uint16 = $0800;
|
||||
semi_pci_2_pci_bridge_p : uint16 = $0940;
|
||||
semi_pci_2_pci_bridge_s : uint16 = $0980;
|
||||
infiniband_2_pci_bridge : uint16 = $0A00;
|
||||
other_bridge_device : uint16 = $8000;
|
||||
end;
|
||||
|
||||
TPCI_Config bitpacked record
|
||||
enable_bit : boolean;
|
||||
reserved : ubit7;
|
||||
bus_number : uint8;
|
||||
device_number : ubit5;
|
||||
function_number : ubit3;
|
||||
register_offset : ubit6;
|
||||
always_0 : ubit2;
|
||||
end;
|
||||
|
||||
TPCI_BIST bitpacked record
|
||||
capable : boolean;
|
||||
start : boolean;
|
||||
reserved : ubit2;
|
||||
completion_code : ubit3;
|
||||
end;
|
||||
|
||||
TPCI_Header_Type bitpacked record
|
||||
MF : boolean;
|
||||
header_type : ubit7;
|
||||
end;
|
||||
|
||||
TPCI_Memory_BAR bitpacked record
|
||||
address : ubit28; //16-Byte aligned
|
||||
prefetchable : boolean;
|
||||
bar_type : ubit2;
|
||||
always_0 : boolean = 0;
|
||||
end;
|
||||
|
||||
TPCI_IO_BAR bitpacked record
|
||||
address : ubit30; //4-byte aligned
|
||||
reserved : boolean;
|
||||
always_0 : boolean = 0;
|
||||
end;
|
||||
|
||||
TPCI_Device bitpacked record
|
||||
device_id : uint16;
|
||||
vendor_id : uint16;
|
||||
status : uint16;
|
||||
command : uint16;
|
||||
class_code : uint8;
|
||||
subclass_class : uint8;
|
||||
prog_if : uint8;
|
||||
revision_id : uint8;
|
||||
BIST : TPCI_BIST;
|
||||
header_type : TPCI_Header_Type;
|
||||
latency_timer : uint8;
|
||||
cache_size : uint8;
|
||||
address0 : TPCI_Memory_BAR;
|
||||
address1 : TPCI_Memory_BAR;
|
||||
address2 : TPCI_Memory_BAR;
|
||||
address3 : TPCI_Memory_BAR;
|
||||
address4 : TPCI_Memory_BAR;
|
||||
address5 : TPCI_Memory_BAR;
|
||||
CIS_pointer : uint32;
|
||||
subsystem_id : uint16;
|
||||
subsystem_vid : uint16;
|
||||
exp_rom_addr : uint32;
|
||||
reserved0 : uint16;
|
||||
reserved1 : uint8;
|
||||
capabilities : uint8;
|
||||
reserved2 : uint32;
|
||||
max_latency : uint8;
|
||||
min_grant : uint8;
|
||||
interrupt_pin : uint8;
|
||||
interrupt_line : uint8;
|
||||
end;
|
||||
|
||||
TPCI_Device_Bridge bitpacked record
|
||||
|
||||
end;
|
||||
|
||||
TCommand_Register bitpacked record
|
||||
reserved : ubit5;
|
||||
interupt_disable : boolean;
|
||||
fast_b2b_enable : boolean;
|
||||
seer_enable : boolean;
|
||||
reserved0 : boolean;
|
||||
parity_err_response : boolean;
|
||||
VGA_palette_snoop : boolean;
|
||||
mem_wai_enable : boolean;
|
||||
special_cycles : boolean;
|
||||
bus_master : boolean;
|
||||
memory_space : boolean;
|
||||
io_space : boolean;
|
||||
end;
|
||||
|
||||
TStatus_Register bitpacked record
|
||||
detected_parity_error,
|
||||
signaled_sys_error,
|
||||
received_master_abort,
|
||||
received_target_abort,
|
||||
signaled_target_abort : boolean;
|
||||
DEVSEL_timing : ubit2;
|
||||
master_data_parity_error,
|
||||
fast_b2b_capable,
|
||||
reserved,
|
||||
c66Mhz_compatible,
|
||||
capabilities_list,
|
||||
interrupt_status : boolean
|
||||
reserved0 : ubit2;
|
||||
end;
|
||||
|
||||
var
|
||||
devices : array[0..(256 * 32)] of TPCI_Device;
|
||||
busses : array[0..256] of TPCI_Device_Bridge;
|
||||
|
||||
device_count, bus_count : uint16 = 0;
|
||||
|
||||
procedure init();
|
||||
procedure loadConfig(bus : uint8; slot : uint8; func : uint8; offset : uint8);
|
||||
function check_device(bus : uint8; device : uint8) :
|
||||
function get_vendor_ID() : uint16;
|
||||
function get_function() : boolean;
|
||||
function read_device_config();
|
||||
function read_bridge_config();
|
||||
|
||||
implementation
|
||||
|
||||
function init();
|
||||
var
|
||||
i : uint16;
|
||||
begin
|
||||
|
||||
//enumerate all pci devices
|
||||
for i:=0 to 31 do begin
|
||||
check_and_get(0, i);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure loadConfig(bus : uint8; slot : uint8; func : uint8; offset : uint8);
|
||||
var
|
||||
packet : TPCI_Config;
|
||||
begin
|
||||
packet.bus_number := bus;
|
||||
packet.device_number := slot;
|
||||
packet.function_number := func;
|
||||
packet.register_offset := offset;
|
||||
|
||||
util.outl(0xCF8, packet);
|
||||
|
||||
|
||||
end;
|
||||
|
||||
function check_device(bus : uint8; device : uint8) : boolean;
|
||||
var
|
||||
i : uint8;
|
||||
vendor_id : uint16;
|
||||
isDevice : boolean;
|
||||
begin
|
||||
|
||||
loadConfig(bus, slot, 0, 0);
|
||||
|
||||
vendor_id := get_vendor_ID();
|
||||
if vendor_id = $0xFFFF then exit;
|
||||
|
||||
isDevice := get_function();
|
||||
if isDevice then begin
|
||||
devices[device_count] := TPCI_Device(read_device_config);
|
||||
device_count := device_count + 1;
|
||||
end;
|
||||
else begin
|
||||
busses[bus_count] := TPCI_Device_Bridge(read_bridge_config);
|
||||
end;
|
||||
end;
|
||||
|
||||
function get_vendor_ID(bus : uint8; device : uint8) : uint16;
|
||||
begin
|
||||
end;
|
||||
|
||||
end.
|
||||
|
147
src/driver/keyboard.pas
Normal file
147
src/driver/keyboard.pas
Normal file
@ -0,0 +1,147 @@
|
||||
{ ************************************************
|
||||
* Asuro
|
||||
* Unit: Drivers/keyboard
|
||||
* Description: Keyboard driver
|
||||
************************************************
|
||||
* Author: Aaron Hance
|
||||
* Contributors:
|
||||
************************************************ }
|
||||
|
||||
unit keyboard;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
console,
|
||||
util,
|
||||
isr33;
|
||||
|
||||
|
||||
type
|
||||
TKeyInfo = packed record
|
||||
key_code : byte;
|
||||
pressed : boolean;
|
||||
end;
|
||||
|
||||
PKeyInfo = ^TKeyInfo;
|
||||
|
||||
var
|
||||
key_matrix : array [1..256] of TKeyInfo;
|
||||
key_buffer : array[1..128] of TkeyInfo;
|
||||
|
||||
|
||||
procedure init(keyboard_layout : array of TKeyInfo);
|
||||
procedure callback(scan_code : void);
|
||||
procedure buffer_push_sc(scan_code : uInt8);
|
||||
procedure lang_USA();
|
||||
|
||||
implementation
|
||||
|
||||
procedure init(keyboard_layout : array of TKeyInfo);
|
||||
begin
|
||||
memset(uint32(@key_matrix[0]), 0, sizeof(TKeyInfo)*256);
|
||||
memset(uint32(@key_buffer), 0, sizeof(TKeyInfo)*128);
|
||||
|
||||
if keyboard_layout[1].key_code = 0 then lang_USA();
|
||||
|
||||
isr33.hook(uint32(@callback));
|
||||
|
||||
end;
|
||||
|
||||
procedure callback(scan_code : void);
|
||||
begin
|
||||
if key_matrix[uint8(scan_code)].key_code <> 0 then begin
|
||||
buffer_push_sc(uint8(scan_code));
|
||||
console.writechar(char(key_buffer[0].key_code));
|
||||
console.writehexln(uint8(scan_code));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure buffer_push_sc(scan_code : uInt8);
|
||||
var
|
||||
i : uInt8;
|
||||
begin
|
||||
for i:=127 downto 1 do begin
|
||||
key_buffer[i] := key_buffer[i - 1];
|
||||
end;
|
||||
|
||||
key_buffer[0] := key_matrix[scan_code];
|
||||
|
||||
end;
|
||||
|
||||
procedure lang_USA();
|
||||
begin
|
||||
key_matrix[1].key_code := $1B;
|
||||
key_matrix[2].key_code := $31;
|
||||
key_matrix[3].key_code := $32;
|
||||
key_matrix[4].key_code := $33;
|
||||
key_matrix[5].key_code := $34;
|
||||
key_matrix[6].key_code := $35;
|
||||
key_matrix[7].key_code := $36;
|
||||
key_matrix[8].key_code := $37;
|
||||
key_matrix[9].key_code := $38;
|
||||
key_matrix[10].key_code := $39;
|
||||
key_matrix[11].key_code := $30;
|
||||
key_matrix[12].key_code := $2D;
|
||||
key_matrix[13].key_code := $3D;
|
||||
key_matrix[14].key_code := $08;
|
||||
key_matrix[15].key_code := $09;
|
||||
key_matrix[16].key_code := $71;
|
||||
key_matrix[17].key_code := $77;
|
||||
key_matrix[18].key_code := $65;
|
||||
key_matrix[19].key_code := $72;
|
||||
key_matrix[20].key_code := $74;
|
||||
key_matrix[21].key_code := $79;
|
||||
key_matrix[22].key_code := $75;
|
||||
key_matrix[23].key_code := $69;
|
||||
key_matrix[24].key_code := $6F;
|
||||
key_matrix[25].key_code := $70;
|
||||
key_matrix[26].key_code := $5B;
|
||||
key_matrix[27].key_code := $5D;
|
||||
key_matrix[28].key_code := $0D;
|
||||
key_matrix[29].key_code := $00; //no ascii
|
||||
key_matrix[30].key_code := $61;
|
||||
key_matrix[31].key_code := $73;
|
||||
key_matrix[32].key_code := $64;
|
||||
key_matrix[33].key_code := $66;
|
||||
key_matrix[34].key_code := $67;
|
||||
key_matrix[35].key_code := $68;
|
||||
key_matrix[36].key_code := $6A;
|
||||
key_matrix[37].key_code := $6B;
|
||||
key_matrix[38].key_code := $6C;
|
||||
key_matrix[39].key_code := $3B;
|
||||
key_matrix[40].key_code := $27;
|
||||
key_matrix[41].key_code := $60;
|
||||
key_matrix[42].key_code := $00; //no ascii
|
||||
key_matrix[43].key_code := $5C;
|
||||
key_matrix[44].key_code := $7A;
|
||||
key_matrix[45].key_code := $78;
|
||||
key_matrix[46].key_code := $63;
|
||||
key_matrix[47].key_code := $76;
|
||||
key_matrix[48].key_code := $62;
|
||||
key_matrix[49].key_code := $6E;
|
||||
key_matrix[50].key_code := $6D;
|
||||
key_matrix[51].key_code := $2C;
|
||||
key_matrix[52].key_code := $2E;
|
||||
key_matrix[53].key_code := $2F;
|
||||
key_matrix[54].key_code := $00; //no ascii
|
||||
key_matrix[55].key_code := $2A;
|
||||
key_matrix[56].key_code := $00; //no ascii
|
||||
key_matrix[57].key_code := $20;
|
||||
key_matrix[58].key_code := $00; //no ascii
|
||||
key_matrix[59].key_code := $3B;
|
||||
key_matrix[60].key_code := $3C;
|
||||
key_matrix[61].key_code := $3D;
|
||||
key_matrix[62].key_code := $3E;
|
||||
key_matrix[63].key_code := $3F;
|
||||
key_matrix[64].key_code := $40;
|
||||
key_matrix[65].key_code := $41;
|
||||
key_matrix[66].key_code := $42;
|
||||
key_matrix[67].key_code := $43;
|
||||
key_matrix[68].key_code := $44;
|
||||
|
||||
key_matrix[87].key_code := $85;
|
||||
key_matrix[88].key_code := $86;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user