Trouble with C return status value to Macro-32 code

Share your experience porting VMS applications to x86 here.
Post Reply

Topic author
ndcsupport
Member
Posts: 5
Joined: Fri Jul 14, 2023 1:30 pm
Reputation: 0
Status: Offline

Trouble with C return status value to Macro-32 code

Post by ndcsupport » Thu Nov 09, 2023 1:00 pm

I have a simple Macro-32 test program that calls a C function and checks the status returned in R0 using BLBC R0. The branch is not working.

Seems I've missed something somewhere in the documentation.

I'm not yet familiar with the X86 machine instructions, but they're clearly not doing what I expected.

Here the relevant part of the listing:

Code: Select all

 0000000E      397 CALLS   #2,get_lnm       ; Small routine written in C.
 00000015      398
 00000015      399 BLBC    R0,5300$
 00000018      400 PUSHAB  tmp1_BUF        ; Where trans goes as ASCIZ.
 0000001E      401 CALLS   #1,DECC$ATOI
The return status is 001BC (%SYSTEM-F-NOLOGNAM) but the branch is NOT taken.

And here's the relevant debug info:

Code: Select all

stepped to TMAR+43: callq   -000000D8
stepped to TMAR+48: movq    %rax,(%rbx)
DBG> ex %rax
0\%RAX: 00000000000001BC
stepped to TMAR+4B: movq    %rdx,08(%rbx)
stepped to TMAR+4F: btq     $00,(%rbx)
stepped to TMAR+54: jae     0000004D
DBG> ex %rbx
0\%RBX: 000000007ACC7F00
DBG> ex @%rbx
000000007ACC7F00:       0000000000000001
stepped to TMAR+5A: movq    00000027(%rip),%r10
stepped to TMAR+61: pushq   %r10
What am I missing?

Thanks, Don

Added in 3 minutes 38 seconds:
I tried playing with a .USE_LINKAGE for the get_lnm routine but what I tried didn't make any difference.

User avatar

arne_v
Master
Posts: 358
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: Trouble with C return status value to Macro-32 code

Post by arne_v » Thu Nov 09, 2023 2:56 pm

VSI may need a complete example.

A trivial attempt does not reproduce:

Code: Select all

$ type add.c
int add(int a, int b)
{
    return a + b;
}
$ cc add
$ type addmain.mar
        .title  addmain
        .psect  $PDATA quad,pic,con,lcl,shr,noexe,nowrt
odd:    .ascid  "odd"
even:   .ascid  "even"
        .psect  $CODE quad,pic,con,lcl,shr,exe,nowrt
        .entry  addmain,^m<>
        pushl   #1
        pushl   #2
        calls   #2, add
        blbc    r0, 100$
        pushab  odd
        calls   #1, G^LIB$PUT_OUTPUT
        brb     200$
100$:   pushab  even
        calls   #1, G^LIB$PUT_OUTPUT
200$:   pushl   #1
        pushl   #3
        calls   #2, add
        blbc    r0, 300$
        pushab  odd
        calls   #1, G^LIB$PUT_OUTPUT
        brb     400$
300$:   pushab  even
        calls   #1, G^LIB$PUT_OUTPUT
400$:   movl    #1, r0
        ret
        .end    addmain
$ mac addmain
$ link addmain + add
$ run addmain
odd
even
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
ndcsupport
Member
Posts: 5
Joined: Fri Jul 14, 2023 1:30 pm
Reputation: 0
Status: Offline

Re: Trouble with C return status value to Macro-32 code

Post by ndcsupport » Thu Nov 09, 2023 7:09 pm

Thanks Arne!

Preparing to submit a full reproducer, I discovered that the problem only occurs when stepping through with the debugger.

I guess the debugger must be trampling on the R0 value returned from the C function.


vmsxpert
Contributor
Posts: 15
Joined: Thu Apr 11, 2024 2:28 pm
Reputation: 0
Location: NEW DELHI
Status: Offline
Contact:

Re: Trouble with C return status value to Macro-32 code

Post by vmsxpert » Thu May 02, 2024 1:25 pm

Does DEC FORM kit available for x86 .If yes ,Please locate it .
Some example of DEC form and how to compile them (steps please ) .

Thanks
Last edited by vmsxpert on Fri May 03, 2024 4:23 am, edited 1 time in total.


jreagan
VSI Expert
Master
Posts: 141
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: Trouble with C return status value to Macro-32 code

Post by jreagan » Thu May 02, 2024 6:01 pm

The

DBG> ex @%rbx

In the debugger probably isn't showing you the correct Alpha R0 register. The real Alpha register values are inside some ICB or INTSTK data structure in the debugger. We are adding AR0, etc. as register names in the debugger to print the actual values. There was a new debugger in the V9.2-2 update1 kit (nothing new in the update2 kit). I'll go check on the status of that support.

Post Reply