I love assembly…
I think I’ve found the related code:
(decompiling the gdb given JoystickOpen give a call just before the error:
0x40086611 <SDL_SYS_JoystickOpen+161>: call 0x400862a0
<SDL_SYS_JoystickName+1280>
that, in the C code, refers to
if ( ! EV_ConfigJoystick(joystick, fd) )
So, I try to make the assembly match to the EV_Config C dode.
Then, I found this part:
0x400864a1 <SDL_SYS_JoystickName+1793>: cmp %eax,0x34(%esp,1)
0x400864a5 <SDL_SYS_JoystickName+1797>: je 0x40086541
<SDL_SYS_JoystickName+1953>
0x400864ab <SDL_SYS_JoystickName+1803>: mov 0x28(%edi),%edx
0x400864ae <SDL_SYS_JoystickName+1806>: mov %esi,%eax
0x400864b0 <SDL_SYS_JoystickName+1808>: mov $0x1,%ecx
0x400864b5 <SDL_SYS_JoystickName+1813>: shl $0x4,%eax
0x400864b8 <SDL_SYS_JoystickName+1816>: add %edx,%eax
0x400864ba <SDL_SYS_JoystickName+1818>: mov %ecx,0x150(%eax)
0x400864c0 <SDL_SYS_JoystickName+1824>: mov 0x38(%esp,1),%edx
0x400864c4 <SDL_SYS_JoystickName+1828>: mov %eax,0x2c(%esp,1)
0x400864c8 <SDL_SYS_JoystickName+1832>: mov 0x34(%esp,1),%eax
0x400864cc <SDL_SYS_JoystickName+1836>: mov 0x40(%esp,1),%ecx
0x400864d0 <SDL_SYS_JoystickName+1840>: add %edx,%eax
0x400864d2 <SDL_SYS_JoystickName+1842>: mov %eax,%edx
0x400864d4 <SDL_SYS_JoystickName+1844>: shr $0x1f,%edx
0x400864d7 <SDL_SYS_JoystickName+1847>: add %edx,%eax
0x400864d9 <SDL_SYS_JoystickName+1849>: sar %eax
0x400864db <SDL_SYS_JoystickName+1851>: sub %ecx,%eax
—Type to continue, or q to quit—
0x400864dd <SDL_SYS_JoystickName+1853>: mov 0x2c(%esp,1),%ecx
0x400864e1 <SDL_SYS_JoystickName+1857>: mov %eax,0x154(%ecx)
0x400864e7 <SDL_SYS_JoystickName+1863>: mov 0x38(%esp,1),%edx
0x400864eb <SDL_SYS_JoystickName+1867>: mov 0x34(%esp,1),%eax
0x400864ef <SDL_SYS_JoystickName+1871>: add %edx,%eax
0x400864f1 <SDL_SYS_JoystickName+1873>: mov %eax,%edx
0x400864f3 <SDL_SYS_JoystickName+1875>: shr $0x1f,%edx
0x400864f6 <SDL_SYS_JoystickName+1878>: add %edx,%eax
0x400864f8 <SDL_SYS_JoystickName+1880>: mov 0x40(%esp,1),%edx
0x400864fc <SDL_SYS_JoystickName+1884>: sar %eax
0x400864fe <SDL_SYS_JoystickName+1886>: add %edx,%eax
0x40086500 <SDL_SYS_JoystickName+1888>: mov %eax,0x158(%ecx)
0x40086506 <SDL_SYS_JoystickName+1894>: mov 0x34(%esp,1),%eax
0x4008650a <SDL_SYS_JoystickName+1898>: mov 0x38(%esp,1),%edx
0x4008650e <SDL_SYS_JoystickName+1902>: sub %eax,%edx
0x40086510 <SDL_SYS_JoystickName+1904>: mov %edx,%eax
0x40086512 <SDL_SYS_JoystickName+1906>: shr $0x1f,%eax
0x40086515 <SDL_SYS_JoystickName+1909>: add %eax,%edx
0x40086517 <SDL_SYS_JoystickName+1911>: mov 0x40(%esp,1),%eax
0x4008651b <SDL_SYS_JoystickName+1915>: sar %edx
0x4008651d <SDL_SYS_JoystickName+1917>: add %eax,%eax
0x4008651f <SDL_SYS_JoystickName+1919>: sub %eax,%edx
0x40086521 <SDL_SYS_JoystickName+1921>: mov $0x20000000,%eax
0x40086526 <SDL_SYS_JoystickName+1926>: mov %edx,%ecxam Lantinga
0x40086528 <SDL_SYS_JoystickName+1928>: cltd
0x40086529 <SDL_SYS_JoystickName+1929>: idiv %ecx
0x4008652b <SDL_SYS_JoystickName+1931>: mov 0x2c(%esp,1),%edx
0x4008652f <SDL_SYS_JoystickName+1935>: mov %eax,0x1c(%esp,1)
0x40086533 <SDL_SYS_JoystickName+1939>: mov %eax,0x15c(%edx)
0x40086539 <SDL_SYS_JoystickName+1945>: incl 0x8(%edi)
0x4008653c <SDL_SYS_JoystickName+1948>: jmp 0x400863d0
<SDL_SYS_JoystickName+1584>
to me, it refers to:
joystick->hwdata->abs_map[i] = joystick->naxes;
if ( values[1] == values[2] ) {
joystick->hwdata->abs_correct[i].used = 0;
} else {
joystick->hwdata->abs_correct[i].used = 1;
joystick->hwdata->abs_correct[i].coef[0] =
(values[2] + values[1]) / 2 - values[4];
joystick->hwdata->abs_correct[i].coef[1] =
(values[2] + values[1]) / 2 + values[4];
joystick->hwdata->abs_correct[i].coef[2] =
(1 << 29) / ((values[2] - values[1]) / 2 - 2 * values[4]);
}
++joystick->naxes;
in function
static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd)
of file
SDL-1.2.7/src/joystick/linux/SDL_sysjoystick.c
The idiv may refer to the main divizion in:
(1 << 29) / ((values[2] - values[1]) / 2 - 2 * values[4]);
so, the problem may come from… a lot of things.
As it is well documented, we understand at first eye look what it is supposed
to do, and where the data are coming from…
Now that I have pointed it out, may the writter of this code (Sam) help me?
Any suggestion?
Fred
Le jeudi 4 Mars 2004 21:44, Stephane Marchesin a ?crit?:> Fred Marmond wrote:
[…]
My joystick is:
[fred at myHost]$ jstest /dev/js0
Joystick (Saitek Saitek X36) has 9 axes and 26 buttons. Driver version is
2.1.0.
Do you reproduce it?
Ahem… well, I have no joystick
But could you please again run it under gdb, and send us a disassembly
of the area around the place it crashes (say 20 lines before and 20
after), and send the ouput so that I can locate which idiv %ecx is
causing the crash inside the SDL binary ?
I’ll look at it when I have some time, probably this WE.
Stephane
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl