From 95ee43d4a187fede7aaea4089edd8a2b49a632c1 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Mon, 12 Sep 2022 16:23:54 -0400 Subject: [PATCH 01/23] Put debug prints and HLT in AHCIPortInit to diagnose bare-metal AHCIPortInit Page Fault bug on doodguy's UEFI machine. --- src/Kernel/BlkDev/DiskAHCI.ZC | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index a21bb5eb..9c162ea3 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -992,6 +992,24 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) port->fis_base = CAllocAligned(sizeof(CFisReceived), 256, sys_task->code_heap); port->fis_base_upper = 0; + + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "AHCI: DEBUG: AHCIPortInit variable check\n"; + "___________\n"; + "port (addr): 0x%016X\n", port; + "port->fis_base: 0x%016X\n", port->fis_base; + "&port->fis_base: 0x%016X\n", &port->fis_base; + "port->cmd_list_base: 0x%016X\n", port->cmd_list_base; + "&port->cmd_list_base: 0x%016X\n", &port->cmd_list_base; + "port->cmd_list_base(CPortCmdHeader *): 0x%016X\n", port->cmd_list_base(CPortCmdHeader *); + "&port->cmd_list_base(CPortCmdHeader *): 0x%016X\n", &port->cmd_list_base(CPortCmdHeader *); + "&port->cmd_list_base(CPortCmdHeader *)[0]: 0x%016X\n", &port->cmd_list_base(CPortCmdHeader *)[0]; + "blkdev.cmd_slot_count: %d\n", blkdev.cmd_slot_count; + "___________\nAHCI: DEBUG: Halting..."; + while(TRUE){HLT}; + } + for (i = 0; i < blkdev.cmd_slot_count; i++) { cmd_header = &port->cmd_list_base(CPortCmdHeader *)[i]; From 8c132e2536b18682d202a4170852d6f4b8cf0cd6 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Tue, 13 Sep 2022 01:45:25 -0400 Subject: [PATCH 02/23] Replace AHCIPortInit CPortCmdHeader pointer cast(s) with declared variable. --- src/Kernel/BlkDev/DiskAHCI.ZC | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 9c162ea3..9eabedbf 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -961,8 +961,9 @@ I64 AHCIAtapiBlksWrite(CBlkDev *bd, U8 *buf, I64 blk, I64 count, Bool lock=TRUE) U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) {//Initialize base addresses for command list and FIS receive area and start command execution on port. - CPortCmdHeader *cmd_header; - I64 i; + CPortCmdHeader *cmd_header, + *cmd_header_base; + I64 i; if (!(port->signature == AHCI_PxSIG_ATAPI || port->signature == AHCI_PxSIG_ATA)) Debug("AHCI Port/BlkDev error: Invalid Port Signature"); @@ -993,8 +994,9 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) port->fis_base_upper = 0; + cmd_header_base = port->cmd_list_base; if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { + { "AHCI: DEBUG: AHCIPortInit variable check\n"; "___________\n"; "port (addr): 0x%016X\n", port; @@ -1002,17 +1004,13 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) "&port->fis_base: 0x%016X\n", &port->fis_base; "port->cmd_list_base: 0x%016X\n", port->cmd_list_base; "&port->cmd_list_base: 0x%016X\n", &port->cmd_list_base; - "port->cmd_list_base(CPortCmdHeader *): 0x%016X\n", port->cmd_list_base(CPortCmdHeader *); - "&port->cmd_list_base(CPortCmdHeader *): 0x%016X\n", &port->cmd_list_base(CPortCmdHeader *); - "&port->cmd_list_base(CPortCmdHeader *)[0]: 0x%016X\n", &port->cmd_list_base(CPortCmdHeader *)[0]; - "blkdev.cmd_slot_count: %d\n", blkdev.cmd_slot_count; - "___________\nAHCI: DEBUG: Halting..."; - while(TRUE){HLT}; - } - + "cmd_header_base: 0x%016X\n", cmd_header_base; + "&cmd_header_base[0]: 0x%016X\n", &cmd_header_base[0]; + "___________\n"; + } for (i = 0; i < blkdev.cmd_slot_count; i++) { - cmd_header = &port->cmd_list_base(CPortCmdHeader *)[i]; + cmd_header = &cmd_header_base[i]; //Write Command FIS Length (CFL, a fixed size) in bits 4:0 of the desc. Takes size in U32s. cmd_header->desc = sizeof(CFisH2D) / sizeof(U32); From 0561a21eaac1667b0e8be42b47c1b64ad4614b5c Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Wed, 14 Sep 2022 18:17:36 -0400 Subject: [PATCH 03/23] Add debug variable report and timeout count to AHCI methods that doodguy's computer is hanging at. --- src/Kernel/BlkDev/DiskAHCI.ZC | 55 ++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 9eabedbf..c42b58ea 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -222,6 +222,10 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) CAHCIPort *port = &blkdev.ahci_hba->ports[port_num]; U8 str[STR_LEN]; + U64 debug_timeout = 0; + U64 debug_retries = 16; + "DEBUG: AHCI: AHCIPortCmdWait"; + while (TRUE) { if (!Bt(&port->cmd_issue, cmd_slot)) //When command has been processed @@ -230,6 +234,11 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Task File Error ($LK,"ATAS_ERR",A="MN:ATAS_ERR"$) { error: + "\nDEBUG: AHCI: AHCIPortCmdWait Task File Error!\n"; + AHCIDebug(port_num); + "\nPausing for 10 seconds...\n"; + Busy(10 * 1000 * 1000); + if (AHCI_DEBUG) { StrPrint(str, "Run AHCIDebug(%d);", port_num); @@ -240,10 +249,24 @@ error: throw('AHCI'); } + if (++debug_timeout > U16_MAX * 6) + { + debug_timeout = 0; + "."; + if (!--debug_retries) + { + "\nDEBUG: AHCI: AHCIPortCmdWait stuck !\n"; + AHCIDebug(port_num); + "\nDEBUG: AHCI: Halting.\n"; + while (TRUE) {asm{HLT};}; + } + } + Yield; // don't hang OS } + "\n"; - if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check + if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check goto error; } @@ -579,6 +602,23 @@ U0 AHCIPortIdentify(CBlkDev *bd) AHCIPortWait(bd->port_num, tS + 2); Bts(&port->cmd_issue, cmd_slot); //Issue the command. + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "AHCI: DEBUG: AHCIPortIdentify variable check\n"; + "___________\n"; + "bd : 0x%016X\n", bd; + "cmd_table: 0x%016X\n", cmd_table; + "cmd_fis: 0x%016X\n", cmd_fis; + "port: 0x%016X\n", port; + "cmd_slot: %d\n", cmd_slot; + "cmd_header: 0x%016X\n", cmd_header; + "dev_id_record: 0x%016X\n", dev_id_record; + "port->signature: 0x%016X\n", port->signature; + "cmd_fis->command: 0x%016X\n", cmd_fis->command; + "port->cmd_issue: 0x%016X\n", port->cmd_issue; + + "___________\n"; + } AHCIPortCmdWait(bd->port_num, cmd_slot); Free(bd->dev_id_record); @@ -995,19 +1035,6 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) cmd_header_base = port->cmd_list_base; - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "AHCI: DEBUG: AHCIPortInit variable check\n"; - "___________\n"; - "port (addr): 0x%016X\n", port; - "port->fis_base: 0x%016X\n", port->fis_base; - "&port->fis_base: 0x%016X\n", &port->fis_base; - "port->cmd_list_base: 0x%016X\n", port->cmd_list_base; - "&port->cmd_list_base: 0x%016X\n", &port->cmd_list_base; - "cmd_header_base: 0x%016X\n", cmd_header_base; - "&cmd_header_base[0]: 0x%016X\n", &cmd_header_base[0]; - "___________\n"; - } for (i = 0; i < blkdev.cmd_slot_count; i++) { cmd_header = &cmd_header_base[i]; From af27249c4302cb259b335ebf5b33d345e582dfbb Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 15 Sep 2022 10:51:32 -0400 Subject: [PATCH 04/23] Update debug reporting. --- src/Kernel/BlkDev/DiskAHCI.ZC | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index c42b58ea..a43e941f 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -224,7 +224,8 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) U64 debug_timeout = 0; U64 debug_retries = 16; - "DEBUG: AHCI: AHCIPortCmdWait"; + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + "DEBUG: AHCI: AHCIPortCmdWait"; while (TRUE) { @@ -234,11 +235,13 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Task File Error ($LK,"ATAS_ERR",A="MN:ATAS_ERR"$) { error: - "\nDEBUG: AHCI: AHCIPortCmdWait Task File Error!\n"; - AHCIDebug(port_num); - "\nPausing for 10 seconds...\n"; - Busy(10 * 1000 * 1000); - + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "\nDEBUG: AHCI: AHCIPortCmdWait Task File Error!\n"; + AHCIDebug(port_num); + "\nPausing for 10 seconds...\n"; + Busy(10 * 1000 * 1000); + } if (AHCI_DEBUG) { StrPrint(str, "Run AHCIDebug(%d);", port_num); @@ -264,7 +267,8 @@ error: Yield; // don't hang OS } - "\n"; + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + "\n";  if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check goto error; @@ -571,6 +575,16 @@ U0 AHCIPortIdentify(CBlkDev *bd) CPortCmdHeader *cmd_header = AHCIPortActiveHeaderGet(bd->port_num, cmd_slot); U16 *dev_id_record; + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; + "___________\n"; + "port->cmd_issue: 0x%016X\n", port->cmd_issue; + "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; + "___________\n"; + } + port->interrupt_status = port->interrupt_status; //TODO: Why? //Using the code heap for this alloc to stay under 32-bit address space. @@ -604,7 +618,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) Bts(&port->cmd_issue, cmd_slot); //Issue the command. if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { - "AHCI: DEBUG: AHCIPortIdentify variable check\n"; + "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; "___________\n"; "bd : 0x%016X\n", bd; "cmd_table: 0x%016X\n", cmd_table; @@ -616,7 +630,8 @@ U0 AHCIPortIdentify(CBlkDev *bd) "port->signature: 0x%016X\n", port->signature; "cmd_fis->command: 0x%016X\n", cmd_fis->command; "port->cmd_issue: 0x%016X\n", port->cmd_issue; - + "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; "___________\n"; } AHCIPortCmdWait(bd->port_num, cmd_slot); From 008e68cc29b855cf4b89eed45cfca327fcaa09ac Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Mon, 3 Oct 2022 05:12:43 -0400 Subject: [PATCH 05/23] Try setting CFL bits in AHCIPortIdentify. --- src/Kernel/BlkDev/DiskAHCI.ZC | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index a43e941f..71208e24 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -270,7 +270,7 @@ error: if (sys_boot_src.u16[0] == BOOT_SRC_DVD) "\n"; - if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check + if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check goto error; } @@ -579,8 +579,9 @@ U0 AHCIPortIdentify(CBlkDev *bd) { "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; "___________\n"; + "cmd_header->desc: 0x%016X\n", cmd_header->desc; "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->device_sleep: 0x%016X\n", port->device_sleep; "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; "___________\n"; } @@ -599,6 +600,9 @@ U0 AHCIPortIdentify(CBlkDev *bd) cmd_table->prdt[0].data_byte_count = 512 - 1; //Zero-based value cmd_header->prdt_len = 1; //1 PRD, as described above, which contains the address to put the ID record. + cmd_header->desc &= ~0b11111; // clear CFL bits + cmd_header->desc |= sizeof(CFisH2D) / 4; // set CFL to size of FIS (represented as U32) + //Setup command FIS cmd_fis = cmd_table->cmd_fis; @@ -620,14 +624,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) { "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; "___________\n"; - "bd : 0x%016X\n", bd; - "cmd_table: 0x%016X\n", cmd_table; - "cmd_fis: 0x%016X\n", cmd_fis; - "port: 0x%016X\n", port; - "cmd_slot: %d\n", cmd_slot; - "cmd_header: 0x%016X\n", cmd_header; - "dev_id_record: 0x%016X\n", dev_id_record; - "port->signature: 0x%016X\n", port->signature; + "cmd_header->desc: 0x%016X\n", cmd_header->desc; "cmd_fis->command: 0x%016X\n", cmd_fis->command; "port->cmd_issue: 0x%016X\n", port->cmd_issue; "port->device_sleep: 0x%016X\n", port->device_sleep; From 6624bba48e4f47fc1c1dbdc68fb944a842a90390 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Mon, 3 Oct 2022 21:19:14 -0400 Subject: [PATCH 06/23] Replace magic number in AHCIPortIdentify cmd header desc fix attempt. --- src/Kernel/BlkDev/DiskAHCI.ZC | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 71208e24..5f15645f 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -581,7 +581,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) "___________\n"; "cmd_header->desc: 0x%016X\n", cmd_header->desc; "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->device_sleep: 0x%016X\n", port->device_sleep; "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; "___________\n"; } @@ -601,7 +601,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) cmd_header->prdt_len = 1; //1 PRD, as described above, which contains the address to put the ID record. cmd_header->desc &= ~0b11111; // clear CFL bits - cmd_header->desc |= sizeof(CFisH2D) / 4; // set CFL to size of FIS (represented as U32) + cmd_header->desc |= sizeof(CFisH2D) / sizeof(U32); // set CFL to size of FIS (represented as U32) //Setup command FIS cmd_fis = cmd_table->cmd_fis; From 52db1e115c0f7d785c43218ca84aee6d249dca57 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:14:23 -0400 Subject: [PATCH 07/23] Fix KernelA typo on AHCI_CF_DESCF_C value. --- src/Kernel/KernelA.HH | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KernelA.HH b/src/Kernel/KernelA.HH index 6add4936..c62bb9b2 100755 --- a/src/Kernel/KernelA.HH +++ b/src/Kernel/KernelA.HH @@ -2717,7 +2717,7 @@ class CPCIDev //Command FIS flags #define AHCI_CF_DESCf_C 7 //'Command' bit. Set when FIS is an ATA command. -#define AHCI_CF_DESCF_C (1 << AHCI_CF_DESCF_C) +#define AHCI_CF_DESCF_C (1 << AHCI_CF_DESCf_C) //Port register flags //Command and Status register flags From 896239cd77a56561940a8a3dc450393d7cf5cefe Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:15:38 -0400 Subject: [PATCH 08/23] Fix kernel compile warn on debug var dup type. --- src/Kernel/BlkDev/DiskAHCI.ZC | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 5f15645f..3b3aa133 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -222,8 +222,7 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) CAHCIPort *port = &blkdev.ahci_hba->ports[port_num]; U8 str[STR_LEN]; - U64 debug_timeout = 0; - U64 debug_retries = 16; + U64 debug_timeout = 0, debug_retries = 16; if (sys_boot_src.u16[0] == BOOT_SRC_DVD) "DEBUG: AHCI: AHCIPortCmdWait"; From 0cbbe5a74b084beff633351b377869071f2af33f Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:16:56 -0400 Subject: [PATCH 09/23] Add debug AHCIPortIdentify device_sleep clear and another var check. --- src/Kernel/BlkDev/DiskAHCI.ZC | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 3b3aa133..160a8290 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -574,6 +574,17 @@ U0 AHCIPortIdentify(CBlkDev *bd) CPortCmdHeader *cmd_header = AHCIPortActiveHeaderGet(bd->port_num, cmd_slot); U16 *dev_id_record; + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "AHCI: DEBUG: AHCIPortIdentify variable check 0\n"; + "port->command: 0x%016X\n", port->command; + "cmd_header->desc: 0x%016X\n", cmd_header->desc; + "port->cmd_issue: 0x%016X\n", port->cmd_issue; + "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; + } + + port->device_sleep = 0; // clear device sleep bits for debug sake if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; From 1145ab3b9b00d67d307d3232833b5ae412344984 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:17:45 -0400 Subject: [PATCH 10/23] Remove debug known-good vals from check in AHCIPortIdentify. --- src/Kernel/BlkDev/DiskAHCI.ZC | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 160a8290..5b70d6ed 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -588,12 +588,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; - "___________\n"; - "cmd_header->desc: 0x%016X\n", cmd_header->desc; - "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; - "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; - "___________\n"; + "port->device_sleep: 0x%016X\n", port->device_sleep; } port->interrupt_status = port->interrupt_status; //TODO: Why? From f813da610701cf545ed3a7888df86abea3fa5d05 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:18:13 -0400 Subject: [PATCH 11/23] Add debug AHCIPortIdentify PxCMD.ICC set to 1. --- src/Kernel/BlkDev/DiskAHCI.ZC | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 5b70d6ed..a73e12e8 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -593,6 +593,8 @@ U0 AHCIPortIdentify(CBlkDev *bd) port->interrupt_status = port->interrupt_status; //TODO: Why? + port->command |= 1 << 28; // set ICC to 1 (try cause HBA to transition Port to Active state) + //Using the code heap for this alloc to stay under 32-bit address space. dev_id_record = CAlloc(512, sys_task->code_heap); From 7c6f6117d2199dccd704acd92bef63ef04cb9647 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:19:08 -0400 Subject: [PATCH 12/23] Change AHCIPortIdentify cmd_fis desc set to debug approach, add another var check. --- src/Kernel/BlkDev/DiskAHCI.ZC | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index a73e12e8..3717e0f7 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -614,7 +614,14 @@ U0 AHCIPortIdentify(CBlkDev *bd) cmd_fis = cmd_table->cmd_fis; cmd_fis->type = FISt_H2D; - Bts(&cmd_fis->desc, AHCI_CF_DESCf_C); //Set Command bit in H2D FIS. +// Bts(&cmd_fis->desc, AHCI_CF_DESCf_C); //Set Command bit in H2D FIS. + cmd_fis->desc |= AHCI_CF_DESCF_C; //set command bit in h2d fis with |= for debug + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) + { + "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; + "port->command: 0x%016X\n", port->command; + "cmd_fis->desc: 0x%016X\n", cmd_fis->desc; + } if (port->signature == AHCI_PxSIG_ATAPI) cmd_fis->command = ATA_IDENTIFY_PACKET; From 0d517f15bb181f7a530b06df991d8fb5bc8705f7 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:19:51 -0400 Subject: [PATCH 13/23] Change AHCIPortIdentify port cmd_issue set to debug approach with or-equals. --- src/Kernel/BlkDev/DiskAHCI.ZC | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 3717e0f7..455100aa 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -633,7 +633,9 @@ U0 AHCIPortIdentify(CBlkDev *bd) //Wait on previous command to complete. AHCIPortWait(bd->port_num, tS + 2); - Bts(&port->cmd_issue, cmd_slot); //Issue the command. +// Bts(&port->cmd_issue, cmd_slot); //Issue the command. + port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake + if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; From 56107409dbabbd7b41b5805efb58dce19f34e11d Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Thu, 6 Oct 2022 18:20:31 -0400 Subject: [PATCH 14/23] Alter AHCIPortIdentify last debug var check. --- src/Kernel/BlkDev/DiskAHCI.ZC | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 455100aa..5002b1ab 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -638,14 +638,15 @@ U0 AHCIPortIdentify(CBlkDev *bd) if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { - "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; - "___________\n"; - "cmd_header->desc: 0x%016X\n", cmd_header->desc; - "cmd_fis->command: 0x%016X\n", cmd_fis->command; - "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; - "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; - "___________\n"; + "AHCI: DEBUG: AHCIPortIdentify variable check 3\n"; + "port->command: 0x%016X\n", port->command; + "cmd_header->desc: 0x%016X\n", cmd_header->desc; + "cmd_fis->command: 0x%016X\n", cmd_fis->command; + "port->cmd_issue: 0x%016X\n", port->cmd_issue; + "port->device_sleep: 0x%016X\n", port->device_sleep; + "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; + if (port->cmd_issue > 0xFF) + "Why is port->cmd_issue invalid ? >:( \n"; } AHCIPortCmdWait(bd->port_num, cmd_slot); @@ -813,7 +814,7 @@ I64 AHCIAtaBlksRead(CBlkDev *bd, U8 *buf, I64 blk, I64 count) blk += AHCI_PRDT_MAX_BLOCKS; buf += AHCI_PRDT_MAX_BLOCKS * BLK_SIZE; // "$$GREEN$$read count: %d\n$$FG$$", count; - }$ER$ + } byte_count += AHCIAtaBlksRW(bd, buf, blk, count, FALSE); } From 276e58e43fa4135e65d4275b0a0a4c929a8dd9f9 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 18:52:27 -0400 Subject: [PATCH 15/23] Replace AHCIPortCmdWait processed-check with debug bit shift AND comparison. --- src/Kernel/BlkDev/DiskAHCI.ZC | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 5002b1ab..e1735f5a 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -228,7 +228,8 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) while (TRUE) { - if (!Bt(&port->cmd_issue, cmd_slot)) //When command has been processed +// if (!Bt(&port->cmd_issue, cmd_slot)) //When command has been processed + if (!(port->cmd_issue & (1 << cmd_slot))) //When command has been processed (using & and 1 << for debug) break; if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Task File Error ($LK,"ATAS_ERR",A="MN:ATAS_ERR"$) From c4e5fbe2da0d285ad5c76ada3fbf655d287aaf2f Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 18:53:32 -0400 Subject: [PATCH 16/23] Change AHCI ATAPI cmd_issue sets to debug OR-equals with bit shift. --- src/Kernel/BlkDev/DiskAHCI.ZC | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index e1735f5a..b39748d1 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -309,7 +309,8 @@ I64 AHCIAtapiCapacityGet(CBlkDev *bd) cmd_table->acmd[0] = ATAPI_READ_CAPACITY >> 8; AHCIPortWait(bd->port_num, tS + 2); - Bts(&port->cmd_issue, cmd_slot); //Issue the command. +// Bts(&port->cmd_issue, cmd_slot); //Issue the command. + port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake try AHCIPortCmdWait(bd->port_num, cmd_slot); @@ -531,7 +532,8 @@ Bool AHCIAtapiStartStop(CBlkDev *bd, Bool start) cmd_table->acmd[4] = start; AHCIPortWait(bd->port_num, tS + 2); - Bts(&port->cmd_issue, cmd_slot); //Issue the command. +// Bts(&port->cmd_issue, cmd_slot); //Issue the command. + port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake try AHCIPortCmdWait(bd->port_num, cmd_slot); @@ -777,7 +779,8 @@ I64 AHCIAtaBlksRW(CBlkDev *bd, U8 *buf, I64 blk, I64 count, Bool write) //Wait on previous command to complete. AHCIPortWait(bd->port_num, tS + 2); //Issue the command. - Bts(&port->cmd_issue, cmd_slot); +// Bts(&port->cmd_issue, cmd_slot); + port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake //Wait on command to finish. AHCIPortCmdWait(bd->port_num, cmd_slot); @@ -929,7 +932,8 @@ I64 AHCIAtapiBlksRead(CBlkDev *bd, U8 *buf, I64 blk, I64 count, Bool lock=TRUE) AHCIPortWait(bd->port_num, tS + 2); - Bts(&port->cmd_issue, cmd_slot); +// Bts(&port->cmd_issue, cmd_slot); + port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake AHCIPortCmdWait(bd->port_num, cmd_slot); if (bd->flags & BDF_INTERNAL_BUF) From 004f762b2668a09e26e57ffc2123d4590a5880c2 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 18:54:16 -0400 Subject: [PATCH 17/23] Add AHCI debug Bt/Bts values and checks. --- src/Kernel/BlkDev/DiskAHCI.ZC | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index b39748d1..da947e5f 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -576,7 +576,9 @@ U0 AHCIPortIdentify(CBlkDev *bd) I64 cmd_slot = AHCIPortCmdSlotGet(bd->port_num); CPortCmdHeader *cmd_header = AHCIPortActiveHeaderGet(bd->port_num, cmd_slot); U16 *dev_id_record; + U64 debug_val1 = 0, debug_val2 = 0;; + Bts(&debug_val1, cmd_slot); if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 0\n"; @@ -585,14 +587,22 @@ U0 AHCIPortIdentify(CBlkDev *bd) "port->cmd_issue: 0x%016X\n", port->cmd_issue; "port->device_sleep: 0x%016X\n", port->device_sleep; "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; + "debug_val1: 0x%016X\n", debug_val1; } port->device_sleep = 0; // clear device sleep bits for debug sake + debug_val1 = 0; + debug_val1 |= 1 << cmd_slot; + debug_val2 = Bt(&debug_val1, cmd_slot); if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; "port->device_sleep: 0x%016X\n", port->device_sleep; + "debug_val1: 0x%016X\n", debug_val1; + "debug_val2: 0x%016X\n", debug_val2; } + debug_val1 = 0; + debug_val2 = 0; port->interrupt_status = port->interrupt_status; //TODO: Why? From 27193fe5e0265653ce770e6d62bfa7b43b1f024e Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 18:54:56 -0400 Subject: [PATCH 18/23] Add AHCI GHC.AE debug check with both & and Bt. --- src/Kernel/BlkDev/DiskAHCI.ZC | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index da947e5f..020715a2 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -1169,6 +1169,8 @@ U0 AHCIInit() Bts(&blkdev.ahci_hba->ghc, AHCI_GHCf_AHCI_ENABLE); "AHCI: GHC.AE set\n"; + "AHCI: GHC.AE value confirm with &: %d\n", blkdev.ahci_hba->ghc & (1 << AHCI_GHCf_AHCI_ENABLE); + "AHCI: GHC.AE value confirm with Bt(): %d\n", Bt(&blkdev.ahci_hba->ghc, AHCI_GHCf_AHCI_ENABLE); //Transferring ownership from BIOS if supported. if (Bt(&hba->caps_ext, AHCI_CAPSEXTf_BOH)) From 7dac5c3019ee77bb40076a4ac74991fea08328e0 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 18:55:44 -0400 Subject: [PATCH 19/23] Change ACHI HBA ports_implemented check to debug AND with bitshift. --- src/Kernel/BlkDev/DiskAHCI.ZC | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 020715a2..e111d264 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -1190,7 +1190,8 @@ U0 AHCIInit() for (i = 0; i < AHCI_MAX_PORTS; i++) { - if (Bt(&hba->ports_implemented, i)) +// if (Bt(&hba->ports_implemented, i)) + if (hba->ports_implemented & (1 << i)) {//$BK,1$Make ports idle?$BK,0$ port = &hba->ports[i]; "AHCI: Port %2d signature 0x%08X ", i, port->signature; @@ -1228,7 +1229,8 @@ Bool AHCIBootDVDProbeAll(CBlkDev *bd) for (i = 0; i < AHCI_MAX_PORTS; i++) { - if (Bt(&blkdev.ahci_hba->ports_implemented, i)) +// if (Bt(&blkdev.ahci_hba->ports_implemented, i)) + if (blkdev.ahci_hba->ports_implemented & (1 << i)) { port = &blkdev.ahci_hba->ports[i]; "AHCI: BootDVDProbeAll: Saw port at %2d with signature 0x%0X\n", i, port->signature; From 8f93766df7c44c1ee57ffd0d8cda89e4824fb50c Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 7 Oct 2022 20:22:13 -0400 Subject: [PATCH 20/23] Change AHCIAtaInit cmd_header_base cast to proper declared variable. --- src/Kernel/BlkDev/DiskAHCI.ZC | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index e111d264..df260940 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -593,7 +593,7 @@ U0 AHCIPortIdentify(CBlkDev *bd) port->device_sleep = 0; // clear device sleep bits for debug sake debug_val1 = 0; debug_val1 |= 1 << cmd_slot; - debug_val2 = Bt(&debug_val1, cmd_slot); + debug_val2 = Bt(&debug_val1, cmd_slot); if (sys_boot_src.u16[0] == BOOT_SRC_DVD) { "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; @@ -1097,6 +1097,7 @@ Bool AHCIAtaInit(CBlkDev *bd) { Bool unlock, okay = FALSE; CPortCmdHeader *cmd_header; + CPortCmdHeader *cmd_header_base; I64 i; if (!bd->ahci_port) @@ -1109,7 +1110,8 @@ Bool AHCIAtaInit(CBlkDev *bd) { for (i = 0; i < blkdev.cmd_slot_count; i++) { - cmd_header = &bd->ahci_port->cmd_list_base(CPortCmdHeader *)[i]; + cmd_header_base = bd->ahci_port->cmd_list_base; + cmd_header = &cmd_header_base[i]; Free(cmd_header->cmd_table_base); } Free(bd->ahci_port->cmd_list_base); From eaea4915a140e0ecafbff6191d6c79bb2facea19 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Sun, 9 Oct 2022 20:29:28 -0400 Subject: [PATCH 21/23] Begin removing debug lines from AHCI code, document bugs identified and current workarounds. --- src/Kernel/BlkDev/DiskAHCI.ZC | 83 +++++------------------------------ 1 file changed, 11 insertions(+), 72 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index df260940..1a7ad626 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -1,11 +1,16 @@ /* -- Perhaps make more references to spec in comments +- Make more references to spec in comments -- ATAPI RW +- ATAPI RW needs cleaning up / improving - Remove Buffer alignment check and just do it on every call -- AHCIATAPISetMaxSpeed? +- AHCIATAPISetMaxSpeed needs to be implemented + +- TODO FIXME: certain Bt() and Bts() on AHCI memory areas, and variable casting, + caused strange crashes on a Ryzen with Gigabyte brand motherboard. Bit test + function implementation and compiler casting internal functionality need + to be researched to fix those bugs. */ I64 AHCI_DEBUG = FALSE; @@ -222,10 +227,6 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) CAHCIPort *port = &blkdev.ahci_hba->ports[port_num]; U8 str[STR_LEN]; - U64 debug_timeout = 0, debug_retries = 16; - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - "DEBUG: AHCI: AHCIPortCmdWait"; - while (TRUE) { // if (!Bt(&port->cmd_issue, cmd_slot)) //When command has been processed @@ -235,13 +236,6 @@ U0 AHCIPortCmdWait(I64 port_num, I64 cmd_slot) if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Task File Error ($LK,"ATAS_ERR",A="MN:ATAS_ERR"$) { error: - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "\nDEBUG: AHCI: AHCIPortCmdWait Task File Error!\n"; - AHCIDebug(port_num); - "\nPausing for 10 seconds...\n"; - Busy(10 * 1000 * 1000); - } if (AHCI_DEBUG) { StrPrint(str, "Run AHCIDebug(%d);", port_num); @@ -252,23 +246,8 @@ error: throw('AHCI'); } - if (++debug_timeout > U16_MAX * 6) - { - debug_timeout = 0; - "."; - if (!--debug_retries) - { - "\nDEBUG: AHCI: AHCIPortCmdWait stuck !\n"; - AHCIDebug(port_num); - "\nDEBUG: AHCI: Halting.\n"; - while (TRUE) {asm{HLT};}; - } - } - Yield; // don't hang OS } - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - "\n"; if (Bt(&port->interrupt_status, AHCI_PxIf_TFE)) //Second safety check goto error; @@ -576,7 +555,6 @@ U0 AHCIPortIdentify(CBlkDev *bd) I64 cmd_slot = AHCIPortCmdSlotGet(bd->port_num); CPortCmdHeader *cmd_header = AHCIPortActiveHeaderGet(bd->port_num, cmd_slot); U16 *dev_id_record; - U64 debug_val1 = 0, debug_val2 = 0;; Bts(&debug_val1, cmd_slot); if (sys_boot_src.u16[0] == BOOT_SRC_DVD) @@ -587,27 +565,10 @@ U0 AHCIPortIdentify(CBlkDev *bd) "port->cmd_issue: 0x%016X\n", port->cmd_issue; "port->device_sleep: 0x%016X\n", port->device_sleep; "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; - "debug_val1: 0x%016X\n", debug_val1; } - port->device_sleep = 0; // clear device sleep bits for debug sake - debug_val1 = 0; - debug_val1 |= 1 << cmd_slot; - debug_val2 = Bt(&debug_val1, cmd_slot); - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "AHCI: DEBUG: AHCIPortIdentify variable check 1\n"; - "port->device_sleep: 0x%016X\n", port->device_sleep; - "debug_val1: 0x%016X\n", debug_val1; - "debug_val2: 0x%016X\n", debug_val2; - } - debug_val1 = 0; - debug_val2 = 0; - port->interrupt_status = port->interrupt_status; //TODO: Why? - port->command |= 1 << 28; // set ICC to 1 (try cause HBA to transition Port to Active state) - //Using the code heap for this alloc to stay under 32-bit address space. dev_id_record = CAlloc(512, sys_task->code_heap); @@ -620,21 +581,11 @@ U0 AHCIPortIdentify(CBlkDev *bd) cmd_table->prdt[0].data_byte_count = 512 - 1; //Zero-based value cmd_header->prdt_len = 1; //1 PRD, as described above, which contains the address to put the ID record. - cmd_header->desc &= ~0b11111; // clear CFL bits - cmd_header->desc |= sizeof(CFisH2D) / sizeof(U32); // set CFL to size of FIS (represented as U32) - //Setup command FIS cmd_fis = cmd_table->cmd_fis; cmd_fis->type = FISt_H2D; -// Bts(&cmd_fis->desc, AHCI_CF_DESCf_C); //Set Command bit in H2D FIS. - cmd_fis->desc |= AHCI_CF_DESCF_C; //set command bit in h2d fis with |= for debug - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "AHCI: DEBUG: AHCIPortIdentify variable check 2\n"; - "port->command: 0x%016X\n", port->command; - "cmd_fis->desc: 0x%016X\n", cmd_fis->desc; - } + Bts(&cmd_fis->desc, AHCI_CF_DESCf_C); //Set Command bit in H2D FIS. if (port->signature == AHCI_PxSIG_ATAPI) cmd_fis->command = ATA_IDENTIFY_PACKET; @@ -649,18 +600,6 @@ U0 AHCIPortIdentify(CBlkDev *bd) // Bts(&port->cmd_issue, cmd_slot); //Issue the command. port->cmd_issue |= 1 << cmd_slot; //issue the command with |= for debug sake - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "AHCI: DEBUG: AHCIPortIdentify variable check 3\n"; - "port->command: 0x%016X\n", port->command; - "cmd_header->desc: 0x%016X\n", cmd_header->desc; - "cmd_fis->command: 0x%016X\n", cmd_fis->command; - "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; - "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; - if (port->cmd_issue > 0xFF) - "Why is port->cmd_issue invalid ? >:( \n"; - } AHCIPortCmdWait(bd->port_num, cmd_slot); Free(bd->dev_id_record); @@ -1081,6 +1020,7 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) cmd_header_base = port->cmd_list_base; for (i = 0; i < blkdev.cmd_slot_count; i++) { +// cmd_header = &port->cmd_list_base(CPortCmdHeader *)[i]; cmd_header = &cmd_header_base[i]; //Write Command FIS Length (CFL, a fixed size) in bits 4:0 of the desc. Takes size in U32s. cmd_header->desc = sizeof(CFisH2D) / sizeof(U32); @@ -1111,6 +1051,7 @@ Bool AHCIAtaInit(CBlkDev *bd) for (i = 0; i < blkdev.cmd_slot_count; i++) { cmd_header_base = bd->ahci_port->cmd_list_base; +// cmd_header = &bd->ahci_port->cmd_list_base(CPortCmdHeader *)[i]; cmd_header = &cmd_header_base[i]; Free(cmd_header->cmd_table_base); } @@ -1171,8 +1112,6 @@ U0 AHCIInit() Bts(&blkdev.ahci_hba->ghc, AHCI_GHCf_AHCI_ENABLE); "AHCI: GHC.AE set\n"; - "AHCI: GHC.AE value confirm with &: %d\n", blkdev.ahci_hba->ghc & (1 << AHCI_GHCf_AHCI_ENABLE); - "AHCI: GHC.AE value confirm with Bt(): %d\n", Bt(&blkdev.ahci_hba->ghc, AHCI_GHCf_AHCI_ENABLE); //Transferring ownership from BIOS if supported. if (Bt(&hba->caps_ext, AHCI_CAPSEXTf_BOH)) From ff5a901185a1d446b7606af080575db64590dcd1 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Sun, 9 Oct 2022 20:37:09 -0400 Subject: [PATCH 22/23] Remove debug check lines from AHCIPortIdentify. --- src/Kernel/BlkDev/DiskAHCI.ZC | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index 1a7ad626..e2d23749 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -556,17 +556,6 @@ U0 AHCIPortIdentify(CBlkDev *bd) CPortCmdHeader *cmd_header = AHCIPortActiveHeaderGet(bd->port_num, cmd_slot); U16 *dev_id_record; - Bts(&debug_val1, cmd_slot); - if (sys_boot_src.u16[0] == BOOT_SRC_DVD) - { - "AHCI: DEBUG: AHCIPortIdentify variable check 0\n"; - "port->command: 0x%016X\n", port->command; - "cmd_header->desc: 0x%016X\n", cmd_header->desc; - "port->cmd_issue: 0x%016X\n", port->cmd_issue; - "port->device_sleep: 0x%016X\n", port->device_sleep; - "port->fis_switch_ctrl: 0x%016X\n", port->fis_switch_ctrl; - } - port->interrupt_status = port->interrupt_status; //TODO: Why? //Using the code heap for this alloc to stay under 32-bit address space. From 41d32c699ec6e4c6ffb0a9c554f1e71f92cbb959 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Sun, 9 Oct 2022 20:37:24 -0400 Subject: [PATCH 23/23] Fix dup var type compiler warn in AHCIPortInit. --- src/Kernel/BlkDev/DiskAHCI.ZC | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kernel/BlkDev/DiskAHCI.ZC b/src/Kernel/BlkDev/DiskAHCI.ZC index e2d23749..0adcb595 100755 --- a/src/Kernel/BlkDev/DiskAHCI.ZC +++ b/src/Kernel/BlkDev/DiskAHCI.ZC @@ -1025,8 +1025,7 @@ U0 AHCIPortInit(CBlkDev *bd, CAHCIPort *port, I64 port_num) Bool AHCIAtaInit(CBlkDev *bd) { Bool unlock, okay = FALSE; - CPortCmdHeader *cmd_header; - CPortCmdHeader *cmd_header_base; + CPortCmdHeader *cmd_header, *cmd_header_base; I64 i; if (!bd->ahci_port)