Skip to contentSkip to conversation

target/xtensa: import core lx106

PATCH Superseded Simon Safar via 2 participants 6 messages Apr 21, 2022 – Apr 25, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/xtensa: import core lx106

This is the core used in e.g. ESP8266 chips. Importing them using import_core.sh, with the required files sourced from

https://github.com/espressif/xtensa-overlays

core-lx106.c was generated by the script; the only change is removing the reference to core-matmap.h which doesn't seem to be available.

---
 target/xtensa/core-lx106.c                    |   52 +
 target/xtensa/core-lx106/core-isa.h           |  470 +
 target/xtensa/core-lx106/gdb-config.c.inc     |   83 +
 target/xtensa/core-lx106/xtensa-modules.c.inc | 7668 +++++++++++++++++
 4 files changed, 8273 insertions(+)
 create mode 100644 target/xtensa/core-lx106.c
 create mode 100644 target/xtensa/core-lx106/core-isa.h
 create mode 100644 target/xtensa/core-lx106/gdb-config.c.inc
 create mode 100644 target/xtensa/core-lx106/xtensa-modules.c.inc
target/xtensa/core-lx106.c new file +52 -0
new file mode 100644
index 0000000000..75eeb1a018
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2022, Simon Safar, Max Filippov, Open Source and Linux Lab.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the Open Source and Linux Lab nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "exec/gdbstub.h"
+#include "qemu-common.h"
+#include "qemu/host-utils.h"
+
+#include "core-lx106/core-isa.h"
+#include "overlay_tool.h"
+
+#define xtensa_modules xtensa_modules_lx106
+#include "core-lx106/xtensa-modules.c.inc"
+
+static XtensaConfig lx106 __attribute__((unused)) = {
+    .name = "lx106",
+    .gdb_regmap = {
+        .reg = {
+#include "core-lx106/gdb-config.c.inc"
+        }
+    },
+    .isa_internal = &xtensa_modules,
+    .clock_freq_khz = 40000,
+    DEFAULT_SECTIONS
+};
+
+REGISTER_CORE(lx106)
target/xtensa/core-lx106/core-isa.h new file +470 -0

470 lines not on this page · raw message

target/xtensa/core-lx106/gdb-config.c.inc new file +83 -0

83 lines not on this page · raw message

target/xtensa/core-lx106/xtensa-modules.c.inc new file +7668 -0

2,395 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.20.1

Part of the diff is not shown here. View the raw message.

Reviewed-by on v1 1/1
#1 lore raw

Hi Simon,

Quoted 10 lines · Simon Safar via

This is the core used in e.g. ESP8266 chips. Importing them using import_core.sh, with the required files sourced from

https://github.com/espressif/xtensa-overlays

core-lx106.c was generated by the script; the only change is removing the reference to core-matmap.h which doesn't seem to be available.

Quoted 10 lines
---
 target/xtensa/core-lx106.c                    |   52 +
 target/xtensa/core-lx106/core-isa.h           |  470 +
 target/xtensa/core-lx106/gdb-config.c.inc     |   83 +
 target/xtensa/core-lx106/xtensa-modules.c.inc | 7668 +++++++++++++++++
 4 files changed, 8273 insertions(+)
 create mode 100644 target/xtensa/core-lx106.c
 create mode 100644 target/xtensa/core-lx106/core-isa.h
 create mode 100644 target/xtensa/core-lx106/gdb-config.c.inc
 create mode 100644 target/xtensa/core-lx106/xtensa-modules.c.inc

An update to target/xtensa/cores.list is needed for this core to be built in qemu-6.2+. Please keep that file alphabetically sorted. With that addressed:

I'm curious how is it supposed to be used?

Signature · 2 lines
Thanks.
-- Max
#2 lore raw

Hi Max,

Quoted 3 lines · Max Filippov

An update to target/xtensa/cores.list is needed for this core to be built in qemu-6.2+. Please keep that file alphabetically sorted.

sounds great, thank you for the review!!! Will send out v2 soon.

Quoted 1 line

I'm curious how is it supposed to be used?

It's for a (future...) Lisp compiler! Somewhat in the style of MicroPython; the idea is to make code editable on the fly, without reflashing (... or restarting, even). Given how it's one person's side project (mine), it's a lot closer to a (not-even-self-hosting) lispy-syntax lx106 assembler (... written in Common Lisp) at this point though.

Specifically, qemu is being used for testing code generation; within test cases, we generate an object file, link it up into an ELF image, launch it under qemu & check the output. Current top achievement: a loop that iterates 10 times and quits successfully, by using the emulated syscall interface. Even so, having actual test cases for this (& occasionally attaching gdb to them) is really useful.

(Admittedly, I can't really think of a lot of other use cases; probably everyone else is just using the official C toolchain?)

Simon

#3 lore raw
Quoted 2 lines · Simon Safar

It's for a (future...) Lisp compiler! Somewhat in the style of MicroPython; the idea is to make code editable on the fly, without reflashing (... or restarting, even).

Interesting. Do you use libisa or do you do instruction encoding on your own?

Signature · 2 lines
Thanks.
-- Max
#4 lore raw
Quoted 4 lines · Max Filippov
Quoted 2 lines

It's for a (future...) Lisp compiler! Somewhat in the style of MicroPython; the idea is to make code editable on the fly, without reflashing (... or restarting, even).

Interesting. Do you use libisa or do you do instruction encoding on your own?

It's my own; it's generating opcodes from the tree of tables in the Xtensa reference. A large part of the actual code looks a lot like those tables themselves; there are still some missing parts for some (e.g. overriding some defaults on which instruction is taking what kinds of parameters), which I'm just filling in on the go. It's fairly hacky, but it might fit together well with the eventual purpose of maybe running some of this in that 40k RAM onboard & keeping it all Lisp.

(I'll put it up somewhere eventually once it's not a complete mess & starts doing something interesting! assuming this ever happens, of course.)

Simon

#5 lore raw
Quoted 10 lines · Simon Safar
Quoted 2 lines · Max Filippov

It's for a (future...) Lisp compiler! Somewhat in the style of MicroPython; the idea is to make code editable on the fly, without reflashing (... or restarting, even).

Interesting. Do you use libisa or do you do instruction encoding on your own?

It's my own; it's generating opcodes from the tree of tables in the Xtensa reference. A large part of the actual code looks a lot like those tables themselves; there are still some missing parts for some (e.g. overriding some defaults on which instruction is taking what kinds of parameters), which I'm just filling in on the go.

I see. I once did something like that for QEMU TCG:
https://github.com/OSLL/qemu-xtensa/commit/53604287d6fdad1ce9659135a8ecbb569be90380

Quoted 2 lines

It's fairly hacky, but it might fit together well with the eventual purpose of maybe running some of this in that 40k RAM onboard & keeping it all Lisp.

40k of RAM is a reasonable concern (: I would guess though that libisa + xtensa core description are purely code and constant data, and as such they may be put into FLASH and not consume any RAM.

Quoted 2 lines

(I'll put it up somewhere eventually once it's not a complete mess & starts doing something interesting! assuming this ever happens, of course.)

Have fun and good luck!

Signature · 2 lines
Thanks.
-- Max