Skip to content

Commit 479f809

Browse files
committed
fix off-by-one error for when working with ULP addresses
binutils-esp32ulp allows peripheral registers to be specified either as a full address (e.g. 0x3ff48000) or as a direct ULP address (e.g. 0x120), i.e. the address as seen from the ULP. "direct" addresses are anything from 0x0 to 0x3ff (inclusive). This change ensures that 0x3ff is included in what is treated as a direct ULP address. (See https://github.com/espressif/binutils-esp32ulp/blob/249ec34/gas/config/tc-esp32ulp_esp32.c#L145 for reference to how binutils treats anything larger than DR_REG_MAX_DIRECT (0x3ff) as a full address, so everything less *AND* equal to DR_REG_MAX_DIRECT is therefore a direct ULP address.) This commit contributes to being able to eventually assemble the esp32ulp_ranges.s test from binutils-esp32ulp. It addresses this line: https://github.com/espressif/binutils-esp32ulp/blob/249ec34/gas/testsuite/gas/esp32ulp/esp32/esp32ulp_ranges.s#L136
1 parent 02e94ba commit 479f809

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

esp32_ulp/opcodes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def get_cond(arg):
358358

359359
def _soc_reg_to_ulp_periph_sel(reg):
360360
# Map SoC peripheral register to periph_sel field of RD_REG and WR_REG instructions.
361-
if reg < DR_REG_MAX_DIRECT:
361+
if reg <= DR_REG_MAX_DIRECT:
362362
ret = RD_REG_PERIPH_RTC_CNTL
363363
elif reg < DR_REG_RTCCNTL_BASE:
364364
raise ValueError("invalid register base")
@@ -377,7 +377,7 @@ def _soc_reg_to_ulp_periph_sel(reg):
377377

378378
def i_reg_wr(reg, high_bit, low_bit, val):
379379
reg = get_imm(reg)
380-
if reg < DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
380+
if reg <= DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
381381
_wr_reg.addr = reg
382382
else:
383383
_wr_reg.addr = (reg & 0xff) >> 2
@@ -391,7 +391,7 @@ def i_reg_wr(reg, high_bit, low_bit, val):
391391

392392
def i_reg_rd(reg, high_bit, low_bit):
393393
reg = get_imm(reg)
394-
if reg < DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
394+
if reg <= DR_REG_MAX_DIRECT: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
395395
_rd_reg.addr = reg
396396
else:
397397
_rd_reg.addr = (reg & 0xff) >> 2

0 commit comments

Comments
 (0)