Can't memset HBA_CMD_HEADER
Posted: Sat Nov 20, 2021 9:45 am
I recently got my SATA/AHCI driver to properly detect and initialize drives, and now I'm on to updating my filesystem logic to use SATA instead of IDE.
When I initialize my drive, I first perform a read. That seems to work correctly, or at the least it doesn't crash. However, when I call the same method again from my filesystem module, it crashes.
Through debugging, I've determined that the crash occurs in my read method, right when it tries to memset the cmd header:
In the above console output, you can see the outputs "C.2" and "D" near the top. This is from the initialization of the drive, and then that's followed by "Init success: /dev/sd0", so all's good there.
However, when I try to read from it again (after the OS boots) to read files from the filesystem, we only get as far as "C.2" before the OS crashes.
I'm positive this is because I'm doing something wrong in the read method, but I'm not sure what. The full source for my AHCI driver is hereif you're interested.
Edit:
What's interesting to me, and why I output it in the console, is that both cmdheader->ctbau and cmdheader->ctba and different the second time I invoke it, and oddly the same as one another on the second invocation. I suspect that is ultimately the root cause of the problem, but I'm not sure what that implies.
When I initialize my drive, I first perform a read. That seems to work correctly, or at the least it doesn't crash. However, when I call the same method again from my filesystem module, it crashes.
Code: Select all
Intel ICH9 controller found (bus=0, slot=3, func=0, abar=0xfebf1000)
HBA in AHCI-only mode
SATA device detected:
port[0].sig = 101
ipm=1, spd=1, det=3
rebasing port...DONE
C.2
cmdtbl: 80401400, cmdheader: 80400000, prdtl: 1, ctbau: 0, ctba: 401400
D
Init success: /dev/sd0
cpu#1 (AuthenticAMD - 13): ready
cpu#2 (AuthenticAMD - 13): ready
cpu#0 (AuthenticAMD???? - 13): ready
C.2
Welcome to Xv64
cmdtbl: 81010101, cmdheader: 80400000, prdtl: 1, ctbau: 1010101, ctba: 1010101
lock '(null)':
ffffffff80106fc9 ffffffff8010889a ffffffff801086e0 ffffffff8010ad1c ffffffff80100b03 ffffffff801009ba ffffffff8010033f ffffffff8010282a ffffffff80104863 ffffffff80106b80
PANIC on cpu 1
acquire
PROC: initcode
last sys call: 0
STACK:
[0] ffffffff8010172d
[1] ffffffff80106f89
[2] ffffffff80108b27
[3] ffffffff801088ac
[4] ffffffff801086e0
[5] ffffffff8010ad1c
[6] ffffffff80100b03
[7] ffffffff801009ba
[8] ffffffff8010033f
[9] ffffffff8010282a
HLT
Code: Select all
cprintf("C.2\n");
cprintf("cmdtbl: %x, cmdheader: %x, prdtl: %x, ctbau: %x, ctba: %x\n", cmdtbl, cmdheader, cmdheader->prdtl, cmdheader->ctbau, cmdheader->ctba);
memset(cmdtbl, 0, sizeof(HBA_CMD_TBL) +
(cmdheader->prdtl-1)*sizeof(HBA_PRDT_ENTRY));
cprintf("D\n");
However, when I try to read from it again (after the OS boots) to read files from the filesystem, we only get as far as "C.2" before the OS crashes.
I'm positive this is because I'm doing something wrong in the read method, but I'm not sure what. The full source for my AHCI driver is hereif you're interested.
Edit:
What's interesting to me, and why I output it in the console, is that both cmdheader->ctbau and cmdheader->ctba and different the second time I invoke it, and oddly the same as one another on the second invocation. I suspect that is ultimately the root cause of the problem, but I'm not sure what that implies.