Author Topic: [SOLVED] Help with a very peculiar flash-related Axe bug  (Read 2682 times)

0 Members and 1 Guest are viewing this topic.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
[SOLVED] Help with a very peculiar flash-related Axe bug
« on: October 23, 2013, 07:01:50 pm »
Foreword: the solution to this issue probably has to deal with something like OS flash modification procedures or the certificate, so expect to need to know about these things.
* Runer112 looks at BrandonW, DrDnar, and thepenguin77


Here's the issue I'm experiencing with Axe. I'll start with a high-level description. Since at least Axe 1.2.1, I have experienced a very peculiar bug. On the few occasions when I've sent a new development version of Axe to my calculator, the very first compile would result in a seemingly random compilation error occurring almost instantly. This error would never occur again for the same version of Axe, as far as I can tell. I've tried replacing it with the old version of Axe and re-upgrading it, I've tried clearing RAM, and I've tried sending new "dummy" upgraded versions of Axe that have one small thing changed to make the application slightly different. None of these seem to replicate the bug. The bug also doesn't seem to ever occur in wabbitemu.

I'm fairly certain this is not a fluke. This exact scenario of me making a ton of changes and sending the new version of Axe to my calculator months after the last build was sent has happened at least three times so far; once with an older version (perhaps 1.2.1, or an early 1.2.2 build?), and twice with sending the most recent 1.2.2 to two of my calculators. I have one calcultor left still with Axe 1.2.1 on it. I predict that sending Axe 1.2.2 to this calculator will replicate the bug one more time, but I'm saving it to add more debugging tools as necessary to a build of Axe 1.2.2 to hopefully pin down this bug.

Now, for some lower-level details. The error occurs due to a failed B_CALL(_WriteAByteSafe), oddly on what I believe is the second call to that routine with the fresh version of Axe. The write is to the first page of the swap sector, which should have been erased by a B_CALL(_FindSwapSector) \ B_CALL(_EraseFlashPage). In the register dump that follows, the swap sector perhaps unusually starts on page $0C, but I don't think that's part of the issue. From what little I remember of the dump I got from my first calculator, which I didn't save, I believe everything was the same except the swap sector started on page $08.

Anyways, here are the known input and output register values from B_CALL(_WriteAByteSafe) that I got from the existing debug dumper in Axe 1.2.2 when the error occurred on the second of the two calculators I sent it to:
  • INPUT: af=$0C80, bc=$4701, de=$4011, hl=$8686    (note: the value of b is not officially known, but that's what it ideally should  have been)
  • OUTPUT: af=$1F08, bc=$0000, de=$4011, hl=$8478


If anyone already has any ideas as to what the problem is, or ideas of what to add to a debug version of Axe to hopefully replicate and better debug the issue on my third calculator or your calculator, I would appreciate them. If not and I can't solve the issue myself, I'll just write this off as a minor bug since it only happens once per Axe upgrade anyways.
« Last Edit: October 25, 2013, 05:22:28 pm by Runer112 »

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Help with a very peculiar flash-related Axe bug
« Reply #1 on: October 23, 2013, 09:09:40 pm »
For reference, here is _writeAByte:
Code: [Select]
_WriteAByte:
ld hl, 8478h
ld (hl), b
ld bc, 1

_WriteFlashUnsafe:
push af
ld a, b
or c
jr z, loc_4CB7
pop af
res 1, (iy+25h)
push ix
ld ix, WriteFlashUnsafeRun
call sub_48C5 ; this function runs whatever IX is pointing to
pop ix
ret

loc_4CB7:
pop af
ret


WriteFlashUnsafeRun:

.dw 7Ch

and 7Fh
out (6), a
bit 7, h
jr nz, loc_4CC7
set 1, (iy+25h)

loc_4CC7:
bit 1, (iy+25h)
push hl
jr nz, loc_4CE2
ld hl, 7FFFh
or a
sbc hl, de
jr nc, loc_4CE2
in a, (6)
inc a
cp 7Eh
jr z, loc_4CDF
out (6), a

loc_4CDF:
ld de, 4000h

loc_4CE2:
pop hl
in a, (6)
push af
ld a, 2
out (6), a
ld a, 0AAh
ld (loc_6AA8+2), a
ld a, 1
out (6), a
ld a, 55h
ld (byte_5555), a
ld a, 2
out (6), a
ld a, 0A0h
ld (loc_6AA8+2), a
pop af
out (6), a
ldi
dec de
dec hl

loc_4D08:
ld a, (de)
push af
xor (hl)
and 80h
jr z, loc_4D1C
pop af
bit 5, a
jr z, loc_4D08
ld a, (de)
xor (hl)
and 80h
jr nz, loc_4D2E
jr loc_4D1D


loc_4D1C:
pop af

loc_4D1D:
inc de
inc hl
ld a, b
or c
jr nz, loc_4CC7
dec de
ld a, 0F0h
ld (de), a
inc de
ld a, 7Fh
out (6), a
xor a
ret


loc_4D2E:
ld a, 0F0h
ld (de), a
ld a, 7Fh
out (6), a
or a
ret

How is writeAByte failing? The typical way that writeAByte fails is by hanging.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Help with a very peculiar flash-related Axe bug
« Reply #2 on: October 23, 2013, 11:27:59 pm »
Oh, perhaps I should have clarified that. It returns, but with nz, meaning that the write was unsuccessful.

EDIT: I just noticed, I don't see any logic in that code to clip de from $8011 to $4011, but the register values (and the fact that the code works the other 99.99999% of the time) mean that it must have that logic.

EDIT 2: I'm an idiot, Axe handles masking de to the range $4000-$7FFF itself.

EDIT 3: Issue solved! Basically TI sucks and one of their B_CALLs is buggy.

EDIT 4: Issue re-solved! Basically I suck and I was just derping out this whole time. I still have no idea what convinced past me to make the code relocation change that caused this bug in the first place...
« Last Edit: October 27, 2013, 06:37:00 pm by Runer112 »

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [SOLVED] Help with a very peculiar flash-related Axe bug
« Reply #3 on: October 27, 2013, 04:35:13 pm »
EDIT 3: Issue solved! Basically TI sucks and one of their B_CALLs is buggy.
Nothing new here.
* Streetwalker runs

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: [SOLVED] Help with a very peculiar flash-related Axe bug
« Reply #4 on: October 27, 2013, 06:24:06 pm »
Also, for future reference. bcall(_delVarArc) locks flash if a variable is in flash :P

And all OS errors lock flash as well.
« Last Edit: October 27, 2013, 06:38:15 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112