Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MASM64 #72

Open
IbrahimHindawi opened this issue Apr 28, 2024 · 14 comments
Open

Support for MASM64 #72

IbrahimHindawi opened this issue Apr 28, 2024 · 14 comments
Labels
0.10.0 To be completed before the 0.10.0 release enhancement New feature or request

Comments

@IbrahimHindawi
Copy link

Hello,
This lsp is amazing! Does it work for MASM64?

@WillLillis
Copy link
Collaborator

Hi! It's not something I've explicitly tested for, but the LSP should have limited support for MASM64. Nearly all of the instruction information (used for instruction hover and autocomplete support) is based off of the xml files produced by the opcodes python package, which indicates that MASM instruction names are supported here.

I'm really glad you like the project! If you run into any issues or have a feature request in mind, don't hesitate to open up an issue and/or discussion :).

@IbrahimHindawi
Copy link
Author

IbrahimHindawi commented May 1, 2024

Hi! Thanks for the quick reply!
image
I can only see GAS | GO suggestions but no luck with NASM style suggestions.
I tried to edit the toml to no avail:

version = "0.1"

[assemblers]
gas = true
go = true
nasm = true

[instruction_sets]
x86 = false
x86_64 = true

@WillLillis
Copy link
Collaborator

Yeah, unfortunately the only instruction forms supported by the python opcodes repo are GAS and GO. The NASM names should still be in the autocomplete lists, but the associated documentation won't be there. Adding the NASM forms would be a great addition to the project, but it would require either a change upstream or some automated means of collecting the NASM documentation here. Once we have the data in a usable form (e.g. this repo's xml file containing x86 instructions) adding support is pretty straightforward.

This is something I can look into more once school wraps up, but if there's any relevant resources/ documentation (e.g. the ARM resources listed in this placeholder issue )you could link in the meantime to get started that would be greatly appreciated :).

@IbrahimHindawi
Copy link
Author

Awesome, thanks for creating this repo, really!
I'll have a look and see what I can do to contribute. I'm mostly interested in MASM64 so I'll probably focus on that. I hope to contribute to the repo soon. Good luck with school and thanks!

@IbrahimHindawi
Copy link
Author

Didn't see anything related to MASM in the xml in the OpCodes repo btw, weird...

@WillLillis
Copy link
Collaborator

Awesome, thanks for creating this repo, really!

I've contributed a few features recently, but the majority of the credit goes to @bergercookie. Really glad it's been helpful for you though :)

I'll have a look and see what I can do to contribute. I'm mostly interested in MASM64 so I'll probably focus on that. I hope to contribute to the repo soon. Good luck with school and thanks!

That would be great, but no pressure. Thank you!

@WillLillis WillLillis added the enhancement New feature or request label May 2, 2024
@WillLillis WillLillis mentioned this issue Jun 29, 2024
13 tasks
@WillLillis
Copy link
Collaborator

Still haven't found a great reference for the opcodes, but we should be able to add partial MASM support by adding the directives specified here: https://learn.microsoft.com/en-us/cpp/assembler/masm/directives-reference?view=msvc-170

@IbrahimHindawi
Copy link
Author

Hi, from my understanding, opcodes are just the instructions that the ISA has. So shouldn't it be the same for any x8664 assembler?

@WillLillis
Copy link
Collaborator

WillLillis commented Jul 11, 2024

Hi, from my understanding, opcodes are just the instructions that the ISA has. So shouldn't it be the same for any x8664 assembler?

I meant to refer to the NASM-style suggestions you asked about in the earlier comments in this issue rather than the opcodes, but misspoke. Sorry about that! 😁

@IbrahimHindawi
Copy link
Author

https://github.com/HJLebbink/asm-dude
this might help

@WillLillis
Copy link
Collaborator

https://github.com/HJLebbink/asm-dude
this might help

Thanks so much for the source! It's going to take me some time to work out the parsing code so this information can get loaded in by asm-lsp, but this should be pretty doable. From what I've read through, I'll be able to pull out instructions with descriptions and operands, as well as some assembler directives for MASM and NASM.

Just to be clarify, as this isn't my area of expertise, the instruction forms in the file aren't labeled with a particular assembler flavor. For example,

XOR	R/M8,IMM8	8086	XOR R/M8,IMM8	r/m8 XOR imm8.
XOR	R/M8,R8	8086	XOR R/M8,R8	r/m8 XOR r8.
XOR	R/M16,IMM16	8086	XOR R/M16,IMM16	r/m16 XOR imm16.
XOR	R/M16,IMM8	8086	XOR R/M16,IMM8	r/m16 XOR imm8 (sign-extended).
XOR	R/M16,R16	8086	XOR R/M16,R16	r/m16 XOR r16.
XOR	R/M32,IMM32	386	XOR R/M32,IMM32	r/m32 XOR imm32.
XOR	R/M32,IMM8	386	XOR R/M32,IMM8	r/m32 XOR imm8 (sign-extended).
XOR	R/M32,R32	386	XOR R/M32,R32	r/m32 XOR r32.
XOR	R/M64,IMM32	X64	XOR R/M64,IMM32	r/m64 XOR imm32 (sign-extended).
XOR	R/M64,IMM8	X64	XOR R/M64,IMM8	r/m64 XOR imm8 (sign-extended).
XOR	R/M64,R64	X64	XOR R/M64,R64	r/m64 XOR r64.
XOR	R8,R/M8	8086	XOR R8,R/M8	r8 XOR r/m8.
XOR	R16,R/M16	8086	XOR R16,R/M16	r16 XOR r/m16.
XOR	R32,R/M32	386	XOR R32,R/M32	r32 XOR r/m32.
XOR	R64,R/M64	X64	XOR R64,R/M64	r64 XOR r/m64.

Am I correct in reading that the information here corresponds to MASM/NASM-style suggestions for the XOR instruction?

@IbrahimHindawi
Copy link
Author

Hello, glad you liked the source, I am more than happy to help.
I believe these would be all the variants of the XOR instruction which should work for both MASM & NASM.
Here are some more resources:

https://www.felixcloutier.com/x86/

https://software.intel.com/en-us/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4

Do you need to parse the instructions into some xml format for asm-lsp to consume?

I think the main differences between MASM & NASM is things that are specific to the assemblers themselves like macros and procedure definitions and such but the general x8664 instructions should be the same if I'm not mistaken.

@WillLillis
Copy link
Collaborator

WillLillis commented Aug 18, 2024

Do you need to parse the instructions into some xml format for asm-lsp to consume?

That's the basic approach yeah. Currently all of our x86/x86-64 instruction info comes from the opcodes python project which we've copied into the repo under docs_store/opcodes/raw/x86.xml and docs_store/opcodes/raw/x86_64.xml As you noted earlier, the instruction forms from these sources only include gas and go names. The basic approach I was planning on going with was to parse the information file from asm-dude into an xml file that can then be used to add additional forms with nasm/masm names to the existing Instruction structs at load time.

To illustrate, we have the following snippet from docs_store/opcodes/raw/x86.xml representing the XOR instruction:

<Instruction name="XOR" summary="Logical Exclusive OR">
    <InstructionForm gas-name="xorb" go-name="XORB">
      <Operand type="al" input="true" output="true"/>
      <Operand type="imm8"/>
      <Encoding>
        <Opcode byte="34"/>
        <Immediate size="1" value="#1"/>
      </Encoding>
    </InstructionForm>
    <InstructionForm gas-name="xorb" go-name="XORB">
      <Operand type="r8" input="true" output="true"/>
      <Operand type="imm8"/>
      <Encoding>
        <Opcode byte="80"/>
        <ModRM mode="11" reg="6" rm="#0"/>
        <Immediate size="1" value="#1"/>
      </Encoding>
    </InstructionForm>
Many more instruction forms follow...
</Instruction>

After parsing the additional information from asm-dude, we could insert additional InstructionForm entries for each corresponding instruction. An entry in asm-dude like the following:

XOR	R/M8,IMM8	8086	XOR R/M8,IMM8	r/m8 XOR imm8.

could look like the following after being parsed and inserted into the main xml file

<InstructionForm nasm-name="xor" masm-name="xor">
      <Operand type="r8" input="true" output="true"/>
      <Operand type="imm8"/>
</InstructionForm>
<InstructionForm nasm-name="xor" masm-name="xor">
      <Operand type="m8" input="true" output="true"/>
      <Operand type="imm8"/>
</InstructionForm>

We could then add nasm and masm assembler configuration options for .asm-lsp.toml, allowing the user to choose whether they these forms should be displayed for things like documentation hover (as is aslready the case with gas and go).

I think the main differences between MASM & NASM is things that are specific to the assemblers themselves like macros and procedure definitions and such but the general x8664 instructions should be the same if I'm not mistaken.

👍

Does that sound right? Thanks so much for the help! :)

@WillLillis
Copy link
Collaborator

Oh also for reference, this is the main asm-dude file to parse:

signature-hand-1.txt

@WillLillis WillLillis mentioned this issue Nov 15, 2024
9 tasks
@WillLillis WillLillis added the 0.10.0 To be completed before the 0.10.0 release label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.10.0 To be completed before the 0.10.0 release enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants