The RISC-V-specific pseudo ops (which start with a "." prefix, as opposed to
assembler aliases which look like instructions) live in gas/config/tc-riscv.c
static const pseudo_typeS riscv_pseudo_table[] =
{
/* RISC-V-specific pseudo-ops. */
{"option", s_riscv_option, 0},
{"half", cons, 2},
{"word", cons, 4},
{"dword", cons, 8},
{"dtprelword", s_dtprel, 4},
{"dtpreldword", s_dtprel, 8},
{"bss", s_bss, 0},
{"uleb128", s_riscv_leb128, 0},
{"sleb128", s_riscv_leb128, 1},
{ NULL, NULL, 0 },
};
with ".option" having a staticly defined list of arguments
static void
s_riscv_option (int x ATTRIBUTE_UNUSED)
{
char *name = input_line_pointer, ch;
while (!is_end_of_line[(unsigned char) *input_line_pointer])
++input_line_pointer;
ch = *input_line_pointer;
*input_line_pointer = '\0';
if (strcmp (name, "rvc") == 0)
riscv_set_rvc (TRUE);
else if (strcmp (name, "norvc") == 0)
riscv_set_rvc (FALSE);
else if (strcmp (name, "pic") == 0)
riscv_opts.pic = TRUE;
else if (strcmp (name, "nopic") == 0)
riscv_opts.pic = FALSE;
else if (strcmp (name, "relax") == 0)
riscv_opts.relax = TRUE;
else if (strcmp (name, "norelax") == 0)
riscv_opts.relax = FALSE;
else if (strcmp (name, "push") == 0)
{
struct riscv_option_stack *s;
s = (struct riscv_option_stack *) xmalloc (sizeof *s);
s->next = riscv_opts_stack;
s->options = riscv_opts;
riscv_opts_stack = s;
}
else if (strcmp (name, "pop") == 0)
{
struct riscv_option_stack *s;
s = riscv_opts_stack;
if (s == NULL)
as_bad (_(".option pop with no .option push"));
else
{
riscv_opts = s->options;
riscv_opts_stack = s->next;
free (s);
}
}
else
{
as_warn (_("Unrecognized .option directive: %s\n"), name);
}
*input_line_pointer = ch;
demand_empty_rest_of_line ();
}
Additionally, the generic ELF pseudo ops live in gas/config/obj-elf.c
static const pseudo_typeS elf_pseudo_table[] =
{
{"comm", obj_elf_common, 0},
{"common", obj_elf_common, 1},
{"ident", obj_elf_ident, 0},
{"lcomm", obj_elf_lcomm, 0},
{"local", obj_elf_local, 0},
{"previous", obj_elf_previous, 0},
{"section", obj_elf_section, 0},
{"section.s", obj_elf_section, 0},
{"sect", obj_elf_section, 0},
{"sect.s", obj_elf_section, 0},
{"pushsection", obj_elf_section, 1},
{"popsection", obj_elf_popsection, 0},
{"size", obj_elf_size, 0},
{"type", obj_elf_type, 0},
{"version", obj_elf_version, 0},
{"weak", obj_elf_weak, 0},
/* These define symbol visibility. */
{"internal", obj_elf_visibility, STV_INTERNAL},
{"hidden", obj_elf_visibility, STV_HIDDEN},
{"protected", obj_elf_visibility, STV_PROTECTED},
/* These are used for stabs-in-elf configurations. */
{"line", obj_elf_line, 0},
/* This is a GNU extension to handle symbol versions. */
{"symver", obj_elf_symver, 0},
/* A GNU extension to change subsection only. */
{"subsection", obj_elf_subsection, 0},
/* These are GNU extensions to aid in garbage collecting C++ vtables. */
{"vtable_inherit", (void (*) (int)) &obj_elf_vtable_inherit, 0},
{"vtable_entry", (void (*) (int)) &obj_elf_vtable_entry, 0},
/* A GNU extension for object attributes. */
{"gnu_attribute", obj_elf_gnu_attribute, 0},
/* These are used for dwarf. */
{"2byte", cons, 2},
{"4byte", cons, 4},
{"8byte", cons, 8},
/* These are used for dwarf2. */
{ "file", (void (*) (int)) dwarf2_directive_file, 0 },
{ "loc", dwarf2_directive_loc, 0 },
{ "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
/* We need to trap the section changing calls to handle .previous. */
{"data", obj_elf_data, 0},
{"offset", obj_elf_struct, 0},
{"struct", obj_elf_struct, 0},
{"text", obj_elf_text, 0},
{"tls_common", obj_elf_tls_common, 0},
/* End sentinel. */
{NULL, NULL, 0},
};
I think that should be the full list of things you can put into our assembler.
Thanks for documenting this! If you'd like, we can provide you with some sort
of hosting on the RISC-V github (much like the PS ABI document has).
On Tue, 23 May 2017 07:15:43 PDT (-0700),
michae...@mac.com wrote:
> Hi Megan,
>
> Yes. The source is pretty straightforward. I spent a little time reading parts of binutils (mostly to do with relocs), writing small C programs and running objdump on the resulting objects to understand the transform from C to RISC-V asm as well as the emitted ELF relocations. I’m still discovering new things…
>
> I didn’t know we can use “move” instead of “mv”, “jump” instead of “j” and I’ve just spotted “unimp” i.e. the canonical illegal instruction.
>
> What’s not listed in riscv-op.c but is somewhere else in binutils is the list of dot prefixed assembler directives. I recently discovered .2byte, .4byte and .8byte which are not in the list I assembled. I must add them. I initially thought they were synonyms for .half, .word and .dword however it appears that they the numeric versions emit unaligned data:
>
> -
https://reviews.llvm.org/D4582 <
https://reviews.llvm.org/D4582>
>
> Michael.
>
>> On 24 May 2017, at 1:59 AM, Megan Wachs <
me...@sifive.com> wrote:
>>
>> Michael, great doc!
>>
>> I was recently pointed to the relevant code, which is pretty straightforward if you just want the list of pseudo ops binutils would recognize (you may have them all already):
>>
>>
https://github.com/riscv/riscv-binutils-gdb/blob/riscv-next/opcodes/riscv-opc.c <
https://github.com/riscv/riscv-binutils-gdb/blob/riscv-next/opcodes/riscv-opc.c>
>>
>>
>> On Tue, May 23, 2017 at 09:22 Michael Clark <
michae...@mac.com <mailto:
michae...@mac.com>> wrote:
>> Hi Nitin,
>>
>> I have a small doc, however it is very much a work in progress and is not what I would call a complete guide however it lists all assembler directives that I have discovered from reversing GCC output:
>>
>>
https://github.com/rv8-io/rv8/blob/master/doc/src/asm.md <
https://github.com/rv8-io/rv8/blob/master/doc/src/asm.md>
>>
>> There are also some complete but small assembly language programs in the test directory (the .S files):
>>
>>
https://github.com/rv8-io/rv8/tree/master/src/test <
https://github.com/rv8-io/rv8/tree/master/src/test>
>>
>> Michael
>>
>> Sent from my iPhone
>>
>> On 23/05/2017, at 10:36 PM, ataowa <
ataowa....@gmail.com <mailto:
ataowa....@gmail.com>> wrote:
>>
>>> Thanks Nicolas,
>>> I have been referring to that. Calling convention is helpful but It just is not sufficient in terms of different instructions arguments directives etc.
>>>
>>> Regards,
>>> Nitin
>>>
>>> On Tuesday, May 23, 2017 at 3:02:46 PM UTC+5:30, n.oje.bar wrote:
>>> Hi ataowa,
>>>
>>> There is something (not much) in Chapter 20 of the RISC-V spec.
>>>
>>> Best wishes,
>>> Nicolas
>>>
>>>
>>> On Tue, May 23, 2017 at 11:30 AM, ataowa <
ataowa....@gmail.com <>> wrote:
>>> Hello,
>>> Is there a "RISC-V Assembly Programmer's handbook" available?
>>> Could someone please point to it?
>>> If a finalized handbook is not available yet, then any pointers which can help would also be helpful.
>>>
>>> Thanks,
>>> ataowa
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org <>.
>>> To post to this group, send email to
sw-...@groups.riscv.org <>.
>>> Visit this group at
https://groups.google.com/a/groups.riscv.org/group/sw-dev/ <
https://groups.google.com/a/groups.riscv.org/group/sw-dev/>.
>>> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/ebfd5c49-b54d-4dfa-817c-308e5ad84b1b%40groups.riscv.org <
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/ebfd5c49-b54d-4dfa-817c-308e5ad84b1b%40groups.riscv.org?utm_medium=email&utm_source=footer>.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org <mailto:
sw-dev+un...@groups.riscv.org>.
>>> To post to this group, send email to
sw-...@groups.riscv.org <mailto:
sw-...@groups.riscv.org>.
>>> Visit this group at
https://groups.google.com/a/groups.riscv.org/group/sw-dev/ <
https://groups.google.com/a/groups.riscv.org/group/sw-dev/>.
>>> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/fe02085b-f6ba-4929-9b6c-1bad6f7b6e2a%40groups.riscv.org <
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/fe02085b-f6ba-4929-9b6c-1bad6f7b6e2a%40groups.riscv.org?utm_medium=email&utm_source=footer>.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org <mailto:
sw-dev+un...@groups.riscv.org>.
>> To post to this group, send email to
sw-...@groups.riscv.org <mailto:
sw-...@groups.riscv.org>.
>> Visit this group at
https://groups.google.com/a/groups.riscv.org/group/sw-dev/ <
https://groups.google.com/a/groups.riscv.org/group/sw-dev/>.
>> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/049C4A9A-CFE7-4897-954C-FE34481636EB%40mac.com <
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/049C4A9A-CFE7-4897-954C-FE34481636EB%40mac.com?utm_medium=email&utm_source=footer>.
>> --
>> Megan A. Wachs
>> Engineer | SiFive, Inc
>> 300 Brannan St, Suite 403
>> San Francisco, CA 94107
>>
me...@sifive.com <mailto:
me...@sifive.com>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org <mailto:
sw-dev+un...@groups.riscv.org>.
>> To post to this group, send email to
sw-...@groups.riscv.org <mailto:
sw-...@groups.riscv.org>.
>> Visit this group at
https://groups.google.com/a/groups.riscv.org/group/sw-dev/ <
https://groups.google.com/a/groups.riscv.org/group/sw-dev/>.
>> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/CAKnTnFTNMkx7yqtg51Ebxn4s-1j1Zp7f%2BjpH%3DHyUTFUSiMg7uw%40mail.gmail.com <
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/CAKnTnFTNMkx7yqtg51Ebxn4s-1j1Zp7f%2BjpH%3DHyUTFUSiMg7uw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/8FDBC8F2-72D2-4034-B12E-C73B419EC546%40mac.com.