summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-21 20:03:17 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-23 13:53:35 -0700
commit1f644055705aa698af3a248cba938ddb95524a1b (patch)
treea04307f1ca31ed9e3b21e85cdee4152997986440
parent1f5b2284fd1b0b00f6f7ef5a26dccf1ea26077b4 (diff)
lint rp2040.py
-rw-r--r--.editorconfig2
-rw-r--r--.gitignore1
-rw-r--r--GNUmakefile19
-rw-r--r--build-aux/requirements.txt9
-rw-r--r--gdb-helpers/rp2040.py (renamed from gdb/rp2040.py)113
5 files changed, 83 insertions, 61 deletions
diff --git a/.editorconfig b/.editorconfig
index 26a1c9c..62b7bb2 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -36,7 +36,7 @@ _mode = sh
[{build-aux/linux-errno.txt.gen,libusb/include/libusb/tusb_helpers.h.gen}]
_mode = bash
-[{lib9p/idl.gen,lib9p/include/lib9p/linux-errno.h.gen,build-aux/stack.c.gen}]
+[{lib9p/idl.gen,lib9p/include/lib9p/linux-errno.h.gen,build-aux/stack.c.gen,gdb-helpers/*.py}]
_mode = python3
indent_style = space
indent_size = 4
diff --git a/.gitignore b/.gitignore
index 2fd72bb..64e74ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@
/build/
/build-aux/sources.mk
+/build-aux/venv/
diff --git a/GNUmakefile b/GNUmakefile
index dc94e46..518f8d6 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -87,15 +87,20 @@ sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v))
get_dscname = sed -n '1,3{ /^\#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*\# ]*,,; s/ - .*//;p; q; }'
+build-aux/venv: build-aux/requirements.txt
+ python3 -m venv $@
+ $@/bin/pip install -r $<
+ touch --no-create $@
+
# `lint` ###########
lint:
$(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES)))
lint/sh lint/bash: lint/%:
shellcheck $(sources_$*)
-lint/python3: lint/%:
- mypy --strict --scripts-are-modules $(sources_$*)
- black --check $(sources_$*)
- isort --check $(sources_$*)
+lint/python3: lint/%: build-aux/venv
+ ./build-aux/venv/bin/mypy --strict --scripts-are-modules $(sources_$*)
+ ./build-aux/venv/bin/black --check $(sources_$*)
+ ./build-aux/venv/bin/isort --check $(sources_$*)
lint/c: lint/%:
@for filename in $(filter %.h,$(sources_$*)); do \
dscname=$$($(get_dscname) $$filename); \
@@ -141,9 +146,9 @@ lint/all: lint/%:
# `format` #########
format:
$(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES))))
-format/python3: format/%:
- black $(sources_$*)
- isort $(sources_$*)
+format/python3: format/%: ./build-aux/venv
+ ./build-aux/venv/bin/black $(sources_$*)
+ ./build-aux/venv/bin/isort $(sources_$*)
format/sh format/bash: format/%
@:
format/c: format/%:
diff --git a/build-aux/requirements.txt b/build-aux/requirements.txt
new file mode 100644
index 0000000..03c0b3d
--- /dev/null
+++ b/build-aux/requirements.txt
@@ -0,0 +1,9 @@
+# build-aux/requirements.txt - List of Python dev requirements
+#
+# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+mypy
+types-gdb
+black
+isort
diff --git a/gdb/rp2040.py b/gdb-helpers/rp2040.py
index e517ee3..30a936a 100644
--- a/gdb/rp2040.py
+++ b/gdb-helpers/rp2040.py
@@ -1,3 +1,8 @@
+# gdb-helpers/rp2040.py - GDB helpers for the RP2040 CPU.
+#
+# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
import gdb
@@ -6,14 +11,14 @@ def read_mmreg(addr: int) -> int:
def read_reg(name: str) -> int:
- return gdb.selected_frame().read_register(name)
+ return int(gdb.selected_frame().read_register(name))
def fmt32(x: int) -> str:
return "0b" + bin(x)[2:].rjust(32, "0")
-def read_prio(addr: 0) -> str:
+def read_prio(addr: int) -> str:
prios: list[int] = 32 * [0]
for regnum in range(0, 8):
regval = read_mmreg(addr + (regnum * 4))
@@ -23,63 +28,65 @@ def read_prio(addr: 0) -> str:
prios[(regnum * 4) + 3] = (regval >> (24 + 6)) & 0b11
return " " + "".join(str(p) for p in reversed(prios))
+
nvic_names = [
- "TIMER_0", # 0
- "TIMER_1", # 1
- "TIMER_2", # 2
- "TIMER_3", # 3
- "PWM", # 4
- "USB", # 5
- "XIP", # 6
- "PIO0_0", # 7
- "PIO0_1", # 8
- "PIO1_0", # 9
- "PIO1_1", # 10
- "DMA_0", # 11
- "DMA_1", # 12
+ "TIMER_0", # 0
+ "TIMER_1", # 1
+ "TIMER_2", # 2
+ "TIMER_3", # 3
+ "PWM", # 4
+ "USB", # 5
+ "XIP", # 6
+ "PIO0_0", # 7
+ "PIO0_1", # 8
+ "PIO1_0", # 9
+ "PIO1_1", # 10
+ "DMA_0", # 11
+ "DMA_1", # 12
"IO_BANK0", # 13
- "IO_QSPI", # 14
- "SIO_PROC0", # 15
- "SIO_PROC1", # 16
- "CLOCKS", # 17
- "SPI0", # 18
- "SPI1", # 19
- "UART0", # 20
- "UART1", # 21
+ "IO_QSPI", # 14
+ "SIO_PROC0", # 15
+ "SIO_PROC1", # 16
+ "CLOCKS", # 17
+ "SPI0", # 18
+ "SPI1", # 19
+ "UART0", # 20
+ "UART1", # 21
"ADC_FIFO", # 22
- "I2C0", # 23
- "I2C1", # 24
- "RTC", # 25
- "unused(26)", # 26
- "unused(27)", # 27
- "unused(28)", # 28
- "unused(29)", # 29
- "unused(30)", # 30
- "unused(31)", # 31
+ "I2C0", # 23
+ "I2C1", # 24
+ "RTC", # 25
+ "unused(26)", # 26
+ "unused(27)", # 27
+ "unused(28)", # 28
+ "unused(29)", # 29
+ "unused(30)", # 30
+ "unused(31)", # 31
]
exception_names = [
- "none", # 0
- "reset", # 1
- "NMI", # 2
- "hard fault", # 3
- "reserved(4)", # 4
- "reserved(5)", # 5
- "reserved(6)", # 6
- "reserved(7)", # 7
- "reserved(8)", # 8
- "reserved(9)", # 9
- "reserved(10)", # 10
- "SVCall", # 11
- "reserved(12)", # 12
- "reserved(13)", # 13
- "PendSV", # 14
- "SysTick", # 15
- *[f"nvic_{nvic}" for nvic in nvic_names]
+ "none", # 0
+ "reset", # 1
+ "NMI", # 2
+ "hard fault", # 3
+ "reserved(4)", # 4
+ "reserved(5)", # 5
+ "reserved(6)", # 6
+ "reserved(7)", # 7
+ "reserved(8)", # 8
+ "reserved(9)", # 9
+ "reserved(10)", # 10
+ "SVCall", # 11
+ "reserved(12)", # 12
+ "reserved(13)", # 13
+ "PendSV", # 14
+ "SysTick", # 15
+ *[f"nvic_{nvic}" for nvic in nvic_names],
]
-while len(exception_names) < 1<<9:
+while len(exception_names) < 1 << 9:
exception_names += [f"unused({len(exception_names)})"]
+
class RP2040ShowInterrupts(gdb.Command):
"""Show the RP2040's interrupt state."""
@@ -90,8 +97,8 @@ class RP2040ShowInterrupts(gdb.Command):
def invoke(self, arg: str, from_tty: bool) -> None:
base: int = 0xE0000000
- icsr = read_mmreg(base+0xed04)
- psr = read_reg('xPSR')
+ icsr = read_mmreg(base + 0xED04)
+ psr = read_reg("xPSR")
# ║├┤║├┤├┤║├┤║║├┤├──┤║║║├──┤
# 10987654321098765432109876543210 (dec bitnum)
# 3 2 1 0
@@ -148,7 +155,7 @@ PRIMASK : {fmt32(read_reg('primask')) } Priority Mask
xPSR : {fmt32(psr) } {{Application,Execution,Interrupt}} Program Status
└────┬──┘
└{psr&0x1FF} ({exception_names[psr&0x1FF]})
-
+
"""
)