mirror of
https://github.com/AsahiLinux/m1n1
synced 2025-02-16 21:58:27 +00:00
sysreg.py: Add sysreg_parse() function
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
09cdebf08b
commit
7bdff8ad10
1 changed files with 16 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: MIT
|
||||
import json, os
|
||||
import json, os, re
|
||||
from enum import IntEnum
|
||||
from utils import Register64, Register32
|
||||
|
||||
|
@ -19,6 +19,21 @@ def sysreg_name(enc):
|
|||
return sysreg_rev[enc]
|
||||
return f"s{enc[0]}_{enc[1]}_c{enc[2]}_c{enc[3]}_{enc[4]}"
|
||||
|
||||
def sysreg_parse(s):
|
||||
if isinstance(s, tuple) or isinstance(s, list):
|
||||
return tuple(s)
|
||||
s = s.strip()
|
||||
for r in (r"s(\d+)_(\d+)_c(\d+)_c(\d+)_(\d+)", r"(\d+), *(\d+), *(\d+), *(\d+), *(\d+)"):
|
||||
if m := re.match(r, s):
|
||||
enc = tuple(map(int, m.groups()))
|
||||
break
|
||||
else:
|
||||
try:
|
||||
enc = sysreg_fwd[s]
|
||||
except KeyError:
|
||||
raise Exception(f"Unknown sysreg name {s}")
|
||||
return enc
|
||||
|
||||
class ESR_EC(IntEnum):
|
||||
UNKNOWN = 0b000000
|
||||
WFI = 0b000001
|
||||
|
|
Loading…
Add table
Reference in a new issue