Author Topic: Jwasm 13 debugging source mode in 64 bits  (Read 5102 times)

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #15 on: May 09, 2016, 08:25:11 AM »
I think we should actually create 3 kind of HJWasm:
1) HJWasm32.exe              ;for 32 bit computers
2) HJWasmx86.exe            ;for 64 bit computers
3) HJWasmx64                  ;for 64 bit computers
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #16 on: May 09, 2016, 08:49:16 AM »
It works in debug mode but generate an error without:
Code: [Select]
        .x64
        .model flat

        .code
        OPTION EVEX:1

        vgatherdpd zmm15{k1}, [r14+ymm31*8+7bh]
 Error A2168: General Failure
end

Well that is at least a clue.
So, lets remove the exception handler: it doesn’t tell much.
Code: [Select]
#ifndef DEBUG_OUT
// signal(SIGSEGV, genfailure);
#endif

Now we have a crash point with some info:
Code: [Select]
0041904F   je          00419097
00419051   xor         edx,edx
00419053   mov         dl,byte ptr [eax+1]
00419056   push        edx
00419057   call        00402890
0041905C   add         esp,4
0041905F   test        eax,eax
00419061   je          00419097
00419063   cmp        dword ptr [eax+14h],0C4h <<<< eax = 1
0041906A   jne         00419074
0041906C   mov         eax,dword ptr [eax+34h]
0041906F   mov         dword ptr [esi+40h],eax
00419072   pop         esi
00419073   ret
00419074   cmp         byte ptr [eax+1Dh],1
00419078   jne         00419097
0041907A   mov         ecx,dword ptr [eax+20h]
0041907D   mov         dword ptr [esi+40h],ecx
00419080   mov         ecx,dword ptr [eax+20h]
00419083   test        ecx,ecx
00419085   je          0041908F
00419087   mov         edx,dword ptr [ecx+14h]
0041908A   mov         dword ptr [esi+2Ch],edx
0041908D   pop         esi
0041908E   ret

0C4h is MT_TYPE, so we looking for:
Code: [Select]
if (struct.[eax+14h] == MT_TYPE)
return ?
else if (struct.[eax+1Dh] == 1)

Some clues from the build process:
Code: [Select]
\HJWASM\SRC\expreval.c(2465) : warning C4047: '!=' : 'struct asym *' differs in levels of indirection from 'const int '

Leads to this code:
Code: [Select]
/* v2.07: moved out from get_operand, case T_REG
 * this function is now called from calculate() only.
 */
static void CheckAssume( struct expr *opnd )
...
    if ( opnd->base_reg ) {
        sym = GetStdAssumeEx( opnd->base_reg->bytval ); <<<<<< ?
    }
    if (!sym && opnd->idx_reg ) {
sym = GetStdAssumeEx( opnd->idx_reg->bytval ); <<<<<< ?
    }
      if ((opnd->type != 0x7b)&&(opnd->type != NULL)){//this is temporary fix for VGATHER instructions in DEBUG mode
        DebugMsg1(( "CheckAssume(%s, type=>%s<, mbr=>%s<): assume=%s [memtype=%X isptr=%u type=%s target_type=%s ptr_memt=%X]\n",
                   GetResWName( ( opnd->idx_reg ? opnd->idx_reg->tokval : opnd->base_reg->tokval ), NULL ),
                   opnd->type ? opnd->type->name : "NULL",
                   opnd->mbr ? opnd->mbr->name : "NULL",
                   sym->name, sym->mem_type, sym->is_ptr,
                   sym->type ? sym->type->name : "NULL",
                   sym->target_type ? sym->target_type->name : "NULL",
                   sym->ptr_memtype ));
      }
        /* v2.08: skip ASSUMEd type if type or mbr is set */
        //if ( opnd->type || opnd->mbr )
        //    return;
        /* skip "alias" types */
        /* v2.05: obsolete */
        //for ( ; sym->type; sym = sym->type );
        /* v2.05: new */
if ( sym->mem_type == MT_TYPE ) <<<<<< sym = 1
            opnd->type = sym->type;
        else if ( sym->is_ptr == 1 ) { /* v2.10: only dereference if indirection is 1 */

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #17 on: May 09, 2016, 08:53:41 AM »
Hi nidud,
I know that you had to tweak HJWasm source to be able to build it with VC v6.0
Can you please upload that project to your The Doszip Commander page so that I can download that project.
I would like to keep it separated from x64 project on Terraspae and when I make change to HJWasm I would be able to do the same to that project as well. It will be there available to you so that you can build binaries for 32 bit folks.
I think that Johnsa will be glad to include you as well on Terraspae as a developer of HJWasm 
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #18 on: May 09, 2016, 09:20:30 AM »
Habran, I downloaded the source a few hours ago:
Code: [Select]
HJWasm-master.zip              21674K    8.05.16 15:30
So I have not done any tweaking at all. I just copied the src directory to \hjwasm and run a batch file to build it:
Code: [Select]
SET SRC=\HJWASM\SRC
SET INC=%SRC%\h

\VC\bin\cl -c -nologo -O2 -Ot -Zm200 -DNDEBUG -I%INC% -I\VC\include %SRC%\*.c
\vc\bin\link /out:hjwasm.exe /subsystem:console /libpath:\vc\lib *.obj
@del *.obj

That's it.

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #19 on: May 09, 2016, 09:27:12 AM »
That is good :t
So you will need to build for 32 bit computers because I don't have that VC v6.0
We will include your binaries to Terraspace if you agree with it.
I will see if I can find a better solution for :
      if ((opnd->type != 0x7b)&&(opnd->type != NULL)){ //this is temporary fix for VGATHER instructions in DEBUG mode

Cod-Father

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #20 on: May 09, 2016, 09:29:05 AM »
nidud, what about the version I posted, did you try it?
Cod-Father

HSE

  • Member
  • ****
  • Posts: 532
  • <AMD>< 7-32>
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #21 on: May 09, 2016, 09:39:27 AM »
Yes, 32 bit machine. No evident problem (except no messages).

I post my modified compilation for ObjAsm32 in http://masm32.com/board/index.php?topic=5244.msg57297#msg57297

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #22 on: May 09, 2016, 09:43:46 AM »
Thanks HSE  :t
I will see if I can fix that
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #23 on: May 09, 2016, 09:44:46 AM »
 :biggrin:

Think it would be best if you just install VC 6.0 on your machine.

Or even better to install the build tools that currently holds the copyright to HJWasm: http://www.openwatcom.org/

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #24 on: May 09, 2016, 10:02:15 AM »
I don't have VC 6.0
I have installed WATCOM on my machine, I will try to build with it.
For now here is one build with speed option build with C:B:
Cod-Father

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #25 on: May 09, 2016, 10:25:23 AM »
OK, line : if ((opnd->type != 0x7b)&&(opnd->type != NULL)){ //this is temporary fix for VGATHER instructions in DEBUG mode
can be replaced wit
  if ( opnd->type != NULL ){

and it works fine :biggrin:
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #26 on: May 09, 2016, 10:29:15 AM »
Here's the batch for Open Watcom:
Code: [Select]
SET SRC=\HJWASM\SRC

for %%q in (%SRC%\*.c) do \WATCOM\binnt\wcc386 -q -bt=nt -bc -zc -I\WATCOM\h;%SRC%\h -3r -obmilrt -s -DNDEBUG %%q
\WATCOM\binnt\wlink N hjwasm.exe OP q, m System nt file { *.obj }
@del *.obj

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #27 on: May 09, 2016, 10:41:20 AM »
OK, line : if ((opnd->type != 0x7b)&&(opnd->type != NULL)){ //this is temporary fix for VGATHER instructions in DEBUG mode
can be replaced wit
  if ( opnd->type != NULL ){

and it works fine :biggrin:

Well, the problem with the symbol is still there, so it still crashes if you remove (or fix) the debug code.

Code: [Select]
/* v2.05: new, used by
 * expression evaluator if a register is used for indirect addressing
 */

struct asym *GetStdAssumeEx( int reg )
/************************************/
{
    return( StdAssumeTable[reg].symbol );
}

Code: [Select]
/* table StdAssume is for the standard registers;
 * order does match regno in special.h:
 * (R|E)AX=0, (R|E)CX=1, (R|E)DX=2, (R|E)BX=3
 * (R|E)SP=4, (R|E)BP=5, (R|E)SI=6, (R|E)DI=7
 * R8 .. R15.
 */
struct assume_info StdAssumeTable[NUM_STDREGS];

Code: [Select]
    x = opnd->base_reg->bytval;
    if ( opnd->base_reg ) {
        sym = GetStdAssumeEx( opnd->base_reg->bytval );
    }
    sym->is_ptr = x;

Code: [Select]
EBX = 0000000E = opnd->base_reg->bytval --> sym = 0
EBX = 0000001F = opnd->idx_reg->bytval  --> sym = 1 <<<< crash

nidud

  • Member
  • *****
  • Posts: 1370
    • https://github.com/nidud/asmc
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #28 on: May 09, 2016, 10:50:40 AM »
Code: [Select]
#if AMD64_SUPPORT
#define NUM_STDREGS 16
#else
#define NUM_STDREGS 8
#endif

So..
Code: [Select]
struct asym *GetStdAssumeEx( int reg )
/************************************/
{
    if ( reg >= NUM_STDREGS )
return NULL;
    return( StdAssumeTable[reg].symbol );
}

habran

  • Member
  • *****
  • Posts: 1107
    • uasm
Re: Jwasm 13 debugging source mode in 64 bits
« Reply #29 on: May 09, 2016, 12:38:03 PM »
OK, thanks nidud, it will be fixed in next release :t
and thanks for the batch for Open Watcom, I will try to build it now.
Cod-Father