News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

HJWasm 2.31 release

Started by johnsa, May 15, 2017, 07:32:11 PM

Previous topic - Next topic

johnsa

Not silly at all! We just spent a huge amount of time getting a proper SystemV 64bit ABI support in, so apart from my trivial Linux n00b testing it'll be great to have someone actually use/try it out!

For printf :



printf PROTO SYSTEMV fmtStr:PTR, opt:VARARG

.data
   bMsg db "Hello from me %s %d",10,0
   cMsg db "..ME..",0

.code
invoke printf, ADDR bMsg, ADDR cMsg, 10



Please wait 10 min before trying and use Hasm v2.33 (which I'm busy updating now.. It has a lot of fixes, but one especially relevant here is allowing ADDR to be used in VARARGS) :)


GoneFishing

Thanks, JOHNSA   :t
I'll wait for new version of HASM

johnsa

2.33 is up (for Linux only so-far, others will follow this evening).

That sorts out the printf issue, let me know how that works for you!

Cheers
John

GoneFishing

 :t
Works fine with my test piece:
Quote
;. /hasm -elf64 -Fo=test.o test.asm
; gcc -o test test.o   -lc
; ./test ; echo $?

printf PROTO SYSTEMV fmtStr:PTR, opt:VARARG
exit   PROTO SYSTEMV exitCode:DWORD ;  QWORD was incorrect , edited.

.data

mystring db  "Hello, world!",10,0

.code

main PROC SYSTEMV
     invoke printf, ADDR mystring
     invoke exit, 42
     ret
main ENDP

end

Looks like you've done a big amount of work  in developing HJWASM , now HASM .
I'll need some time to learn changes and new features.

Cheers

johnsa

I think exit still takes a 32bit int, but in that case making it a qword won't break anything

GoneFishing

That's right .  I edited that line in exit proto

mineiro

hello GoneFishing;
On that code that generates segmentation fault insert 'mov rax,0' before call printf function.

hello johnsa;
Thanks for updated hasm.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

GoneFishing

@mineiro:
                   nice find

@johnsa :
                  printf function is very helpful in testing SYSTEMV ABI  implementeion:  we can gradually increase number of arguments     and change its type. I've just performed quick test with floating point argument and got "Illegal instruction" response" ( without crashing )

That's all for today, now I must go 

mineiro

Same here GoneFishing;
This error happens here because my computer is old, only support SSE 2 instructions.
objdump -M intel -d test
  4005ea:       c5 f9 6e c0             vmovd  xmm0,eax

I'd rather be this ambulant metamorphosis than to have that old opinion about everything

johnsa

If you're machine doesn't support AVX, use the command line switch -archSSE

When ever HASM generates any code (for prologue/epilogue/invoke/macro library etc) it will respect that switch and use the corresponding opcodes/instructions in the generated code.

The mov eax,0 shouldn't be necessary to add manually for vararg as hasm adds it automatically as either mov eax,count or xor,eax,eax if there are no used vector registers in the varargs.

In terms of gradually expanding and testing the combinations of SystemV ABI I'm attaching my test-case for it so you can see all the ones we've already gone through :)

PS, just like with Vectorcall support on Windows Hasm has built-in data types for __m128, __m256, __m512 and then new union initialisation syntax.
So these types along with normal xmm/ymm/zmm registers can be passed to PROCs under SystemV as per the ABI.

There are a bunch of examples of this in the attached source.


New union initializer allows you to specify which sub-type to use as opposed to only allowing the first, very helpful when working with these vector types for SIMD.

align 16
myVec  __m128.i32 { <0,1,2,3> }

align 32
myVec2 __m256.i32 { <0,1,2,3,4,5,6,7> }




mineiro

hello johnsa
working fine here with that switch option -archSSE  :t
thank you

-edit-
I have faced some problems johnsa, follow testcase code, disasm and output
;hasm  -archSSE -elf64 -Fo=test.o test.asm
;gcc test.o -o test

.x64
exit proto systemv status:dword
printf PROTO SYSTEMV pformat:PTR, arg:VARARG

.data
teste dq 123.456
number dq 23.78
veja db "%f %f",10,0
format db "%s %d %f",10,0
string db "string",0

.code

main PROC
    movd xmm1,qword ptr [number] ;movq don't works!
    movd xmm0,qword ptr [teste]
    mov rax,2
    lea rdi,veja
    call printf
    invoke printf, addr format, addr string, 42, 123.456
    invoke exit,0
ret
main ENDP

end


$ ./test
123.456000 23.780000
string 42 0.000000


0000000000400580 <main>:
  400580:       48 83 ec 08             sub    rsp,0x8
  400584:       66 48 0f 6e 0d cb 0a    movq   xmm1,QWORD PTR [rip+0x200acb]        # 601058 <number>
  40058b:       20 00
  40058d:       66 48 0f 6e 05 ba 0a    movq   xmm0,QWORD PTR [rip+0x200aba]        # 601050 <teste>
  400594:       20 00
  400596:       48 c7 c0 02 00 00 00    mov    rax,0x2
  40059d:       48 8d 3d bc 0a 20 00    lea    rdi,[rip+0x200abc]        # 601060 <veja>
  4005a4:       e8 a7 fe ff ff          call   400450 <printf@plt>
  4005a9:       48 8d 3d b7 0a 20 00    lea    rdi,[rip+0x200ab7]        # 601067 <format>
  4005b0:       48 8d 35 ba 0a 20 00    lea    rsi,[rip+0x200aba]        # 601071 <string>
  4005b7:       48 c7 c2 2a 00 00 00    mov    rdx,0x2a
  4005be:       b8 79 e9 f6 42          mov    eax,0x42f6e979
  4005c3:       66 0f 6e c0             movd   xmm0,eax
  4005c7:       b8 01 00 00 00          mov    eax,0x1
  4005cc:       e8 7f fe ff ff          call   400450 <printf@plt>
  4005d1:       33 ff                   xor    edi,edi
  4005d3:       e8 a8 fe ff ff          call   400480 <exit@plt>
  4005d8:       48 83 c4 08             add    rsp,0x8
  4005dc:       c3                      ret   

I'd rather be this ambulant metamorphosis than to have that old opinion about everything

johnsa

disasm looks right ?  Wonder why it's printing a 0.00 though

johnsa

Ok.. think I found the issue..

C99 standard specifies that ALL float arguments to a variadic are promoted to double.

So..
to conform, %f actually needs a double input so you need to invoke like :

invoke printf, addr format, addr string, 42, real8 ptr 123.456

however.. for some reason real8 ptr isn't working on Linux build, it works perfectly when assembling on Windows however. I will investigate.

mineiro

thanks johnsa;
a command line to disassemble files on linux is:
objdump -M intel -d executable
Saying this because you have c language skills, so you can see whats happening on background based on c language.

This is not a priority to me ok, if you have other issues resolve them first.
again thank you.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

johnsa

Right it's all fixed up, please grab 2.33 dated 18th of May and you can now do the following:



.data

bMsg db "Hello from me %s %d",10,0
cMsg db "..ME..",0
format db "%s %d %f",10,0
string db "string",0
aNum REAL8 123.456

.code

main PROC SYSTEMV
    MEMALLOC(200)
    MEMFREE(rax)
    invoke WriteToConsole, CSTR("Hello, world!"), 13, stdout
    invoke printf, addr format, addr string, 42, real8 ptr 123.456
    invoke printf, ADDR bMsg, ADDR cMsg, 10
    invoke printf, addr format, addr string, 42, aNum