does cc for x86 support asm ?


Topic author
crgnz
Member
Posts: 7
Joined: Thu Apr 13, 2023 4:42 pm
Reputation: 0
Location: Auckland, New Zealand
Status: Offline

does cc for x86 support asm ?

Post by crgnz » Sat May 18, 2024 6:00 am

Sorry if this is more of a "porting from unix" question rather than a specific DEC C for x86 query but I'll ask anyway:

I'm trying to port this function:

Code: Select all


static void __cpuid(int dst[4], int ax) {
 
	asm volatile("cpuid"
		: "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
		: "0" (ax)); 
}

#pragma intrinsic (__cpuid)
I kept getting all sorts of compiler issues. Here is my shortest code as an example of the sort of errors I was getting:

Code: Select all

#include <c_asm.h> 
static void dumbtest() {
 	asm("cpuid;" );
 }
#pragma intrinsic (__cpuid)
but I get the compiler error:

Code: Select all

        asm("cpuid 
........^
%CC-E-ASMNOTAVAIL, In-line assembly code directive asm is not available on this platform.
Its been 15+ years since I did any programming on OpenVMS, let alone try anything on the x86 Community release, so I'm way out of my depth here!

Any suggestions on how I can port the __cpuid() function to OpenVMS x86? Or maybe I should just hardcode the result as a work around for now... (only half joking)


mgdaniel
Valued Contributor
Posts: 72
Joined: Mon Feb 28, 2022 5:16 pm
Reputation: 0
Location: Adelaide, South Australia
Status: Offline
Contact:

Re: does cc for x86 support asm ?

Post by mgdaniel » Tue May 21, 2024 4:59 am

dgordon wrote:
Mon May 20, 2024 7:54 pm
A casual inspection shows that x86_cpuid_get_brand_string() has an incorrect bounds check
on the output buffer (x86_cpuid_get_manufacturer_string() doesn't, though). Another way to
look at it is it is correctly checking for a minimum 49 byte buffer and incorrectly writing to the 50th byte.
I've opened a ticket for this.

I've also prodded the ticket to make the CPUID structures referenced off the SWRPB to be user-readable.

--D

Thanks. That would be better. I noticed the bounds issue too and thinking it must be benign (presumably in production for a couple of years plus) allowed for it in the code.

Code: Select all

#ifdef __x86_64

#define exe$gpq_swrpb EXE$GPQ_SWRPB
#pragma message save
#pragma message disable (mayhideloss)
#include <x86_cpuid_info.h>
#pragma message restore

/* +1 due buf[49] = '\0'; */
static char HttpdX86brand [49+1];

static int HttpdKrnlX86CpuInfo (long *arglist)
{
   int  status;
   status = x86_cpuid_get_brand_string (sizeof(HttpdX86brand), HttpdX86brand);
   return (status);
}

static char* HttpdX86CpuInfo ()

{
   int  status;
   status = sys$cmkrnl (&HttpdKrnlX86CpuInfo, 0);
   if (VMSnok (status)) sprintf (HttpdX86brand, " (%%X%08.08X)", status);
   return (HttpdX86brand);
}

#endif


roberbrooks
VSI Expert
Valued Contributor
Posts: 58
Joined: Thu Jun 20, 2019 11:48 am
Reputation: 0
Status: Offline

Re: does cc for x86 support asm ?

Post by roberbrooks » Tue May 21, 2024 10:58 pm

I am considering making the CPUID data available by SYS/LIB/F$GETSYI item codes.

I have no idea how complete our implementation of providing that data is, nor do I know
how possible it is to return potentially-complicated data via that interface. I'm not particularly
fond of incomplete implementations, but it may be that 90% is better than not. I'd like to make it readily available for all languages, not just C/C++/X86_64 assembler.

Thoughts?
--
-- Rob


mgdaniel
Valued Contributor
Posts: 72
Joined: Mon Feb 28, 2022 5:16 pm
Reputation: 0
Location: Adelaide, South Australia
Status: Offline
Contact:

Re: does cc for x86 support asm ?

Post by mgdaniel » Tue May 21, 2024 11:49 pm

+1
It would be useful supplementary information in general and for such tools as @VUPS.COM
WASD's use:

Code: Select all


System: innotek GmbH VirtualBox "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz" with 3 CPUs and 7GB running VMS V9.2-2


User avatar

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

Re: does cc for x86 support asm ?

Post by arne_v » Wed May 22, 2024 8:55 am

roberbrooks wrote:
Tue May 21, 2024 10:58 pm
I am considering making the CPUID data available by SYS/LIB/F$GETSYI item codes.

I have no idea how complete our implementation of providing that data is, nor do I know
how possible it is to return potentially-complicated data via that interface. I'm not particularly
fond of incomplete implementations, but it may be that 90% is better than not. I'd like to make it readily available for all languages, not just C/C++/X86_64 assembler.

Thoughts?
Super idea.

Available to all languages. No need for privs. Taking it from cache => efficient. Documented.

What is not to like.

Traditional VMS style with one itemcode per item returning either integer or string?

(single item code returning a block requires a record definition per language)
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
crgnz
Member
Posts: 7
Joined: Thu Apr 13, 2023 4:42 pm
Reputation: 0
Location: Auckland, New Zealand
Status: Offline

Re: does cc for x86 support asm ?

Post by crgnz » Sat Jul 20, 2024 5:56 am

arne_v wrote:
Sat May 18, 2024 10:15 am
You need to use clang instead of cc.
I hope you all don't get too tired of me asking dumb questions about clang, but here goes...

So I thought I'd try out clang using some of the examples from this page: https://clang.llvm.org/get_started.html,
first hello.c, then t.c

clang :== $sys$system:clang.exe
clang t.c "-S" -emit-llvm

produces T.LL and T.S

but:

clang hello.c "-S" -emit-llvm

did not produce a HELLO.S, but instead a HELLO.BC which apparently is a ByteCode file. I am curious to know why I didn't get a HELLO.S as I'm more interested in reading the x86 assembly.

(another question is, is there an x86 Assembler for OpenVMS x86?)

(I know this is probably not the correct nomenclature for LLVM but I'm new to LLVM, but since i get the impression that LLVM is important to OpenVMS on x86 I need to learn it!)

Also does the OpenVMS community VM come with some of the LLVM command line utilities such as "llc" (there is no SYS$SYSTEM:LLC.EXE)

Then out of curiosity I copied the files over to Linux and readelf recognises HELLO.EXE as an ELF file and objdump recognises HELLO.OBJ as an ELF file as well so now I'm starting to wonder if it is possible to cross compile a program for OpenVMS x86 on a Linux (x86) machine - (assuming one could reference the DECC runtime correctly)

An then, while still on Linux, I tried llc hello.ll and amazingly it produced a hello.s file without error!

Continuing that cross-compilation thought experiment, it might be easier to generate LLVM IR on Linux and then compile and link on OpenVMS if VSI made all the LLVM tools available? Come to think of it, is a most interesting question, I should have stated with this question first!

Thanks again for your time
CRG
Last edited by crgnz on Sat Jul 20, 2024 6:00 am, edited 1 time in total.

User avatar

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

Re: does cc for x86 support asm ?

Post by arne_v » Sat Jul 20, 2024 6:50 pm

crgnz wrote:
Sat Jul 20, 2024 5:56 am
(another question is, is there an x86 Assembler for OpenVMS x86?)
There is a VSI-X86VMS-X86ASM-V1000-0001-1 kit which per release notes contain:
1 X86-64 Assembler
This kit includes the LLVM tool named "llvm-mc". This provides a
native x86-64 assembler that is highly compatible with the gnu "gas"
assembler.
It needs to be actived as a "foreign command". Use the following command
to create the foreign command:
$ llvmmc :== $sys$system:llvm-mc
Added in 4 minutes 56 seconds:
crgnz wrote:
Sat Jul 20, 2024 5:56 am
(I know this is probably not the correct nomenclature for LLVM but I'm new to LLVM, but since i get the impression that LLVM is important to OpenVMS on x86 I need to learn it!)
LLVM is important for VSI as it is used as backend for almost all of the compilers.

It is therefore also indirectly important for all VMS users as they will be producing EXE files using that LLVM backend or be running EXE files produced with that LLVM backend.

But 99.5% of VMS users will not care about LLVM as such. The VSI compiler produces an EXE that works. What backend the VSI compiler uses to produce that EXE is not important.

Very few VMS Alpha/Itanium users cared about the GEM backend.

Added in 6 minutes 34 seconds:
crgnz wrote:
Sat Jul 20, 2024 5:56 am
Then out of curiosity I copied the files over to Linux and readelf recognises HELLO.EXE as an ELF file and objdump recognises HELLO.OBJ as an ELF file as well so now I'm starting to wonder if it is possible to cross compile a program for OpenVMS x86 on a Linux (x86) machine - (assuming one could reference the DECC runtime correctly)
VSI has cross-compilers on VMS Itanium.

In theory they could produce a cross compiler for Linux. But I don't see a business case for doing that.

You do not have access to the VMS compiler frontend so you can't do it.

Trying to get a Linux LLVM frontend to use LLVM to crosscompile for VMS as target is obviously possible, but I suspect that it would require a huge effort.
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
crgnz
Member
Posts: 7
Joined: Thu Apr 13, 2023 4:42 pm
Reputation: 0
Location: Auckland, New Zealand
Status: Offline

Re: does cc for x86 support asm ?

Post by crgnz » Sun Jul 21, 2024 12:47 am

Hi Arne,

Thanks for taking the time to reply. Am I correct in understanding that Community users cannot download VSI kits? If so, I very much hope that llvm-mc will be included in next year's Community VM image!

Cheers
Chris

User avatar

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

Re: does cc for x86 support asm ?

Post by arne_v » Sun Jul 21, 2024 9:45 am

I believe that is correct. CLP (as opposed to ambassador program) does not grant kit access only access to prepackaged images.

I don't know how frequently VSI will release prepackaged images. Most seems to assume once per year. But that would mean that people getting it 1 week before will only get 1 week before needing to upgrade - to me a new version each quarter with a years license giving 9-12 months usage would make more sense. But only VSI knows what their plans are in that regard.
Arne
arne@vajhoej.dk
VMS user since 1986


pjacobi
VSI Expert
Active Contributor
Posts: 30
Joined: Wed Jun 28, 2023 11:46 am
Reputation: 0
Status: Offline

Re: does cc for x86 support asm ?

Post by pjacobi » Wed Oct 09, 2024 12:47 pm

Attached is a simple X86 assembly program that can be called from a user mode C program to fetch CPUID information. You will need to rename the files after downloading.

Paul A. Jacobi
VMS Software
Attachments
CPUID_S.TXT
(2.2 KiB) Downloaded 80 times
BUILD_COM.TXT
(132 Bytes) Downloaded 70 times
HELLO.C
(1.4 KiB) Downloaded 73 times


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

Re: does cc for x86 support asm ?

Post by jreagan » Tue Oct 15, 2024 12:05 am

By the way, LLVM-MC is not part of the standard OpenVMS distribution. It is provided with an X86ASM kit that is available for download from the service portal. [I don't know if it was included in the Community disk image]

Post Reply