Skip to content

How to Add New Architectures #1

@cbdm

Description

@cbdm

This issue describes the general steps of adding a new architecture into the project. I will use x86-64 as the example since it was the last one added as of now.

  1. Get qiling's rootfs for the architecture and add it to this repo, e.g., https://github.com/assembliss/webassembliss/tree/main/webassembliss/rootfs/x8664_linux

  2. create user workspace (i.e., userprograms folder) inside rootfs, e.g., https://github.com/assembliss/webassembliss/tree/main/webassembliss/rootfs/x8664_linux/userprograms

  3. install required tooling in dockerfile, e.g.,

    webassembliss/Dockerfile

    Lines 22 to 23 in ecf9695

    # x8664 linux toolchain (assemble/link x8664 linux assembly code)
    make gcc-x86-64-linux-gnu\

  4. create an editor template for the architecture, e.g., https://github.com/assembliss/webassembliss/blob/main/webassembliss/templates/x8664_linux.html.j2

  • if needed, also include the status flags, e.g.,
    {% block statusFlags %}
    <th>Status Flags</th>
    {# The ID should be formatted as "<flag name>Flag" so the tracing logic can update values without changes. #}
    <td>SF: <span id="sfFlag">⭕</span></td>
    <td>ZF: <span id="zfFlag">⭕</span></td>
    <td>CF: <span id="cfFlag">⭕</span></td>
    <td>OF: <span id="ofFlag">⭕</span></td>
    {% endblock %}
  1. create matching javascript file with syntax highlighting, e.g., https://github.com/assembliss/webassembliss/blob/main/webassembliss/static/js/x8664_linux.js
  • if needed, add any extra setup you might need for the base functions, e.g.,
    // Initialize all flags as false.
    document.getElementById("sfFlag").innerHTML = ERROR_SYMBOL;
    document.getElementById("zfFlag").innerHTML = ERROR_SYMBOL;
    document.getElementById("cfFlag").innerHTML = ERROR_SYMBOL;
    document.getElementById("ofFlag").innerHTML = ERROR_SYMBOL;
    BASE_startTracing(combineAllSteps);
  1. add new editor to dropdown menu, e.g.,

    <li><hr class="dropdown-divider"></li>
    <li><a class="dropdown-item" href="/editor/x8664_linux">x86-64 (linux)</a></li>

  2. add new editor to landing page, e.g.,

    <li><hr class="dropdown-divider"></li>
    <li><a class="text-center dropdown-item" href="/editor/x8664_linux">x86-64</a></li>

  3. create a new emulation file to use appropriate commands and flags for the architecture, e.g., https://github.com/assembliss/webassembliss/blob/main/webassembliss/emulation/x8664_linux.py

  4. add at least a hello world example for the architecture, e.g., https://github.com/assembliss/webassembliss/tree/main/webassembliss/examples/x8664_linux

  5. add new entry in the ARCH_CONFIG_MAP, e.g.,

    "x8664_linux": ArchConfig(
    trace=x8664_linux_trace,
    template_path="x8664_linux.html.j2",
    example_path=join(EXAMPLES_PATH, "x8664_linux", "hello.s"),
    example_name="hello.s",
    inline_comment_tokens=["#"],
    ),

  6. add new enum value in the project_config.proto, e.g.,

  • Important: this value should match the key you added to ARCH_CONFIG_MAP
  1. recompile project_config.proto so the python backend can see the new enum value:
    // This file can be compiled with: protoc project_config.proto --python_out=../../pyprotos
    // That will generate the project_config_pb2.py file that we can import in the python backend.

All done! Make sure to test things out and double check everything works fine.

Eventually, we'll have unit testing for all modules (once file structure and naming are stable); at that time, I'll add follow-up comments to this issue with instructions of how to add tests for your new architecture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions