Page 1 of 1
Megacd bios jumping
Posted: Tue Feb 13, 2007 12:48 pm
by Fonzie
Hi

its again me
In the process of implementing a "jump" log to GensKmod (not me, Kaneda), I wanted to know if there is a fixed ram area where appear the "current" function number.
I mean, each time the user jump to the bios, does the bios write the function number (d0) somewhere?
I vaguely remember the function number is written somewhere but i cannot recall where I read that.
If someone recall

don't hesitate
Pfew... My english is more and more bad... I wonder what's happen.
Sorry.
Posted: Tue Feb 13, 2007 2:07 pm
by KanedaFr
all of this because Starcream allows hook on read/write memory but not program section
so I tried to mod i_jsr but Starscream is really hard to understand

I tried to add a call to my function but everything explode since x86 registers are lost with this call...
and I discovered sub68k_context.pc != sub68k_readPC( ), which I don't understand!
Stef, if you have any hint

Posted: Tue Feb 13, 2007 2:40 pm
by Stef
sub68k_context.pc contains "Fetch Region pointer + PC value" then you can directly do :
mov eax, [sub68k_context.pc]
to fetch/read the current intruction. This is done for speed reason of course. If you want the real PC value, use ReadPC or unbase pc : sub68k_context.pc - sub68k_context.basePC
I'm not sur about the sub68k_context.basePC variable name since i'm doing it from head :p
Posted: Tue Feb 13, 2007 2:42 pm
by KanedaFr
basePC is for the 32X not the 68k

Posted: Tue Feb 13, 2007 3:04 pm
by Stef
32X SH2 cores uses the same type of based PC.
Well, i just had a look in starscream source, here's register value at "alive" (in execution) time :
- esi = based pc
- ebp = fetch base
If you want only the pc value you have to do that :
mov eax, esi ; get based pc
sub eax, ebx ; unbase it --> eax = pc value
hope it helps you

Posted: Tue Feb 13, 2007 3:18 pm
by KanedaFr
so it means my PC value is wrong for a long time (on main 68k part)
thanks for the hint, and now understand better some stuff on Starscream (like the code below)
can you help me on this too
Code: Select all
mov ecx,esi
sub ecx,ebp
mov esi,edx
call _SpyCDBiosCall
it's the code of the jsr + my call
this code is executed the first time but freeze Gens after that..
I suspect the call to the C function SpyCDBiosCall to mod the x86 register

can you confirm this and if yes, how can i backup reg/call/restore reg?
(movem ? push ?)
Posted: Tue Feb 13, 2007 3:50 pm
by Stef
KanedaFr wrote:so it means my PC value is wrong for a long time (on main 68k part)
thanks for the hint, and now understand better some stuff on Starscream (like the code below)
can you help me on this too
Code: Select all
mov ecx,esi
sub ecx,ebp
mov esi,edx
call _SpyCDBiosCall
it's the code of the jsr + my call
this code is executed the first time but freeze Gens after that..
I suspect the call to the C function SpyCDBiosCall to mod the x86 register

can you confirm this and if yes, how can i backup reg/call/restore reg?
(movem ? push ?)
Seems your _SpyCDBiosCall is using fastcall convention (ecx and edx as parameters).
I do understand you're putting PC in ecx, but what the "mov esi, edx" is supposed to do ? by doing that, you're just erasing the current pc...
Also when you do a function call, you lost your eax, ecx, edx registers values so push them if needed

Posted: Tue Feb 13, 2007 3:56 pm
by KanedaFr
the first 3 lines are the original 'jsr xxx' emulation stuff
I just add the call _Spy....
I found this
http://nasm.sourceforge.net/doc/html/na ... tion-8.1.2 but they talk about save.restore inside the callee function...
does it mean VC isn't making a clean function ?
and this
http://www.delorie.com/djgpp/doc/ug/asm/calling.html
talk about
Expect the registers %eax, %ecx, and %edx, as well as the floating-point stack, to have changed. Standard library functions may modify the %gs register, and the _far* functions may modify %fs. Other registers will be preserved.