bergercookie / asm-lsp

Language server for NASM/GAS/GO Assembly
https://crates.io/crates/asm-lsp
BSD 2-Clause "Simplified" License
269 stars 18 forks source link

Add ARM Keil assembler language #174

Closed Schievel1 closed 4 days ago

Schievel1 commented 6 days ago

For some reason ARM Keil v5 projects (with their own armcc, so pre armclang) do not have the usual arm assembly language. They have the same instructions, but they happen to have like endings and different way to set an area like .text and .data, i.e. AREA |.text|, CODE, READONLY ; The instruction also has to end with a ;, which makes is pretty unusable with the normal ARM assemblers in asm-lsp because everything is red. Here is a snippet from an assembly file to get an idea

    AREA    |.text|, CODE, READONLY ;
RAMTEST PROC
    LDR R5,  =0x00008000    ;    Size of ram in 32Bit registers
    LDR R4,  =0x20000000        ; First address in RAM
    LDR R8,  =0x00000000    ; template
    MVN R9,  R8                 ; =0xFFFFFFFF // template
    LDR R10, =0xAAAAAAAA    ; template
    MVN R11, R10            ; =0x55555555 // template

RAMLOOP
    LDR R1, [R4]        ; cache content of ram cell into r1
...

From what I can tell the Keil Microvision IDE uses armasm.exe in ...Keil_v5/ARM/ARMCC/bin

➜ ls
 armar.exe    armcc.exe                armlink.exe
 armasm.exe   armcompiler_libFNP.dll   fromelf.exe

Is there any way we can add this? v5 is still in widespread use in the industry as their new Keil v6 armclang compiler isn't certified to be used in safety critical projects.
Problem is that is MS Windows all the way, but I can run the .exe in WSL.

WillLillis commented 5 days ago

The instruction also has to end with a ;, which makes is pretty unusable with the normal ARM assemblers in asm-lsp because everything is red.

By red, do you mean that there's a lot of error diagnostics on screen? If so, this can be fixed by specifying the path to the assembler/ compiler you want to be used on your source file inside your .asm-lsp.toml config file.

Schievel1 commented 5 days ago

Yes I mean theres lot of errors on the screen. I did not know you can specify a path. I tried this:

[default_config]
version = "0.9.0"
assembler = "C:/Keil_v5/ARM/ARMCC506/armasm.exe"
instruction_set = "arm"

but in emacs it says

LSP :: Invalid global config file -- TOML parse error at line 3, column 13
  |
3 | assembler = "C:/Keil_v5/ARM/ARMCC506/armasm.exe"
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
unknown variant `C:/Keil_v5/ARM/ARMCC506/armasm.exe`, expected one of `gas`, `go`, `masm`, `nasm`

so I thought I only have those four options.

WillLillis commented 5 days ago

The config field you're looking for is opts.compiler. The assembler field controls which assembler is considered for things like hover documentation and autocomplete. I suggest running "asm-lsp gen-config" from your project's root directory and following those steps to create a config :)

I'll try and revise the docs to make this clearer as well.

Schievel1 commented 4 days ago

Ok I did

[default_config]
version = "0.9.0"
assembler = "nasm"
instruction_set = "arm"

[default_config.opts]
compiler = "/mnt/c/Keil_v5/ARM/ARMCC506/bin/armasm.exe"
compile_flags_txt = []
diagnostics = true
default_diagnostics = false

Judging from the *arm-lsp::stderr* buffer it seems to work (at least there arent compilation errors):

INFO [asm_lsp::handle] Selected compile command(s) for request: [
    CompileCommand {
        directory: "",
        file: File(
            "/mnt/c/svn/Pool-Module/mtb4/mcu/BaseLibrary/trunk/src/main/c/HardwareLayer/Memorytest.s",
        ),
        arguments: Some(
            Arguments(
                [
                    "/mnt/c/Keil_v5/ARM/ARMCC506/bin/armasm.exe",
                    "/mnt/c/svn/Pool-Module/mtb4/mcu/BaseLibrary/trunk/src/main/c/HardwareLayer/Memorytest.s",
                ],
            ),
        ),
        command: None,
        output: None,
    },
]
INFO [asm_lsp::handle] textDocument/diagnostic request serviced in 314ms
INFO [asm_lsp::types] Selected root config
INFO [asm_lsp::handle] textDocument/hover request serviced in 5ms

But now it doesn't display any diagnostics.

Maybe what I am trying to do here is to complicated. I am running Emacs and asm-lsp in WSL2 and runnig an .exe from there. It runs on the command line though.

WillLillis commented 4 days ago

Yeah, asm-lsp isn't going to be able to use a windows executable from within WSL. Is it possible for you to obtain a linux version of the assembler program?

Schievel1 commented 4 days ago

No, there is none for armcc (v5). There is an assembler in the armclang (v6) package but I think it is a different assembly, much like the normal arm assembly. But I can not use armclang because it's not certified.

WillLillis commented 4 days ago

Gotcha. The only other option I see is to run eMacs natively from Windows rather than WSL. Unfortunately the server's current diagnostics implementation requires that the assembler/compiler tool and the server can run on the same system.