diff --git a/os/sb/user/sbuser.h b/os/sb/user/sbuser.h index e5232f9ed..4d1b35e05 100644 --- a/os/sb/user/sbuser.h +++ b/os/sb/user/sbuser.h @@ -168,7 +168,7 @@ typedef uint32_t eventflags_t; #define __syscall0rr(x) \ register uint32_t r0 asm ("r0"); \ - register uint32_t r0 asm ("r1"); \ + register uint32_t r1 asm ("r1"); \ asm volatile ("svc " #x : "=r" (r0), "=r" (r1) : : "memory") #define __syscall1r(x, p1) \ @@ -177,7 +177,7 @@ typedef uint32_t eventflags_t; #define __syscall1rr(x, p1) \ register uint32_t r0 asm ("r0") = (uint32_t)(p1); \ - register uint32_t r0 asm ("r1"); \ + register uint32_t r1 asm ("r1"); \ asm volatile ("svc " #x : "=r" (r0), "=r" (r1) : \ "r" (r0) : \ "memory") diff --git a/os/sb/vio/sbvio.h b/os/sb/vio/sbvio.h index 0f4a78b0b..73fa50d0b 100644 --- a/os/sb/vio/sbvio.h +++ b/os/sb/vio/sbvio.h @@ -100,6 +100,22 @@ typedef struct vio_conf { /* Module macros. */ /*===========================================================================*/ +/** + * @brief Sub-code part of VIO calls 1st parameter. + * + * @param[n] n the VIO 1st parameter + * @return The VIO call sub-code. + */ +#define VIO_CALL_SUBCODE(n) ((uint32_t)(n) & 0xFFU) + +/** + * @brief Unit identifier part of VIO calls 1st parameter. + * + * @param[n] n the VIO 1st parameter + * @return The VIO call unit identifier. + */ +#define VIO_CALL_UNIT(n) ((uint32_t)(n) >> 24) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/sb/vio/sbvio_gpio.c b/os/sb/vio/sbvio_gpio.c index bbe53210d..f967474ac 100644 --- a/os/sb/vio/sbvio_gpio.c +++ b/os/sb/vio/sbvio_gpio.c @@ -55,8 +55,8 @@ void sb_fastc_vio_gpio(struct port_extctx *ectxp) { sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; - uint32_t sub = (unsigned)ectxp->r0; - uint32_t unit = (unsigned)ectxp->r1; + uint32_t sub = VIO_CALL_SUBCODE(ectxp->r0); + uint32_t unit = VIO_CALL_UNIT(ectxp->r0); const vio_gpio_unit_t *unitp; ectxp->r0 = 0U; @@ -69,25 +69,25 @@ void sb_fastc_vio_gpio(struct port_extctx *ectxp) { switch (sub) { case SB_VGPIO_WRITE: if ((unitp->permissions & VIO_GPIO_PERM_WRITE) != 0U) { - palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r2); + palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r1); } break; case SB_VGPIO_SET: if ((unitp->permissions & VIO_GPIO_PERM_WRITE) != 0U) { uint32_t val = palReadGroup(unitp->port, unitp->mask, unitp->offset); - palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r2 | val); + palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r1 | val); } break; case SB_VGPIO_CLEAR: if ((unitp->permissions & VIO_GPIO_PERM_WRITE) != 0U) { uint32_t val = palReadGroup(unitp->port, unitp->mask, unitp->offset); - palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r2 & ~val); + palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r1 & ~val); } break; case SB_VGPIO_TOGGLE: if ((unitp->permissions & VIO_GPIO_PERM_WRITE) != 0U) { uint32_t val = palReadGroup(unitp->port, unitp->mask, unitp->offset); - palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r2 ^ val); + palWriteGroup(unitp->port, unitp->mask, unitp->offset, ectxp->r1 ^ val); } break; case SB_VGPIO_READLATCH: diff --git a/os/sb/vio/sbvio_spi.c b/os/sb/vio/sbvio_spi.c index 6b2919acb..77030b3b8 100644 --- a/os/sb/vio/sbvio_spi.c +++ b/os/sb/vio/sbvio_spi.c @@ -62,8 +62,8 @@ static void vspi_cb(void *ip) { void sb_sysc_vio_spi(struct port_extctx *ectxp) { sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; - uint32_t sub = ectxp->r0; - uint32_t unit = ectxp->r1; + uint32_t sub = VIO_CALL_SUBCODE(ectxp->r0); + uint32_t unit = VIO_CALL_UNIT(ectxp->r0); ectxp->r0 = (uint32_t)CH_RET_INNER_ERROR; const vio_spi_unit_t *unitp; @@ -108,8 +108,8 @@ void sb_sysc_vio_spi(struct port_extctx *ectxp) { void sb_fastc_vio_spi(struct port_extctx *ectxp) { sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; - uint32_t sub = ectxp->r0; - uint32_t unit = ectxp->r1; + uint32_t sub = VIO_CALL_SUBCODE(ectxp->r0); + uint32_t unit = VIO_CALL_UNIT(ectxp->r0); const vio_spi_unit_t *unitp; /* Returned value in case of error or illegal sub-code.*/ @@ -130,7 +130,7 @@ void sb_fastc_vio_spi(struct port_extctx *ectxp) { switch (sub) { case SB_VSPI_SETCFG: { - uint32_t conf = ectxp->r2; + uint32_t conf = ectxp->r1; const vio_spi_config_t *confp; /* Check on configuration index.*/ diff --git a/os/sb/vio/sbvio_uart.c b/os/sb/vio/sbvio_uart.c index 540ea2ab6..b134b7535 100644 --- a/os/sb/vio/sbvio_uart.c +++ b/os/sb/vio/sbvio_uart.c @@ -62,8 +62,8 @@ static void vuart_cb(void *ip) { void sb_sysc_vio_uart(struct port_extctx *ectxp) { sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; - uint32_t sub = ectxp->r0; - uint32_t unit = ectxp->r1; + uint32_t sub = VIO_CALL_SUBCODE(ectxp->r0); + uint32_t unit = VIO_CALL_UNIT(ectxp->r0); ectxp->r0 = (uint32_t)CH_RET_INNER_ERROR; const vio_uart_unit_t *unitp; @@ -108,8 +108,8 @@ void sb_sysc_vio_uart(struct port_extctx *ectxp) { void sb_fastc_vio_uart(struct port_extctx *ectxp) { sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; - uint32_t sub = ectxp->r0; - uint32_t unit = ectxp->r1; + uint32_t sub = VIO_CALL_SUBCODE(ectxp->r0); + uint32_t unit = VIO_CALL_UNIT(ectxp->r0); const vio_uart_unit_t *unitp; /* Returned value in case of error or illegal sub-code.*/ @@ -130,7 +130,7 @@ void sb_fastc_vio_uart(struct port_extctx *ectxp) { switch (sub) { case SB_VUART_SETCFG: { - uint32_t conf = ectxp->r2; + uint32_t conf = ectxp->r1; const vio_uart_config_t *confp; /* Check on configuration index.*/ @@ -172,8 +172,8 @@ void sb_fastc_vio_uart(struct port_extctx *ectxp) { } case SB_VUART_READ: { - uint8_t *buffer = (uint8_t *)ectxp->r2; - size_t n = (size_t)ectxp->r3; + uint8_t *buffer = (uint8_t *)ectxp->r1; + size_t n = (size_t)ectxp->r2; if (!sb_is_valid_write_range(sbp, buffer, n)) { ectxp->r0 = (uint32_t)0; @@ -186,8 +186,8 @@ void sb_fastc_vio_uart(struct port_extctx *ectxp) { } case SB_VUART_WRITE: { - const uint8_t *buffer = (const uint8_t *)ectxp->r2; - size_t n = (size_t)ectxp->r3; + const uint8_t *buffer = (const uint8_t *)ectxp->r1; + size_t n = (size_t)ectxp->r2; if (!sb_is_valid_read_range(sbp, buffer, n)) { ectxp->r0 = (uint32_t)0; @@ -205,13 +205,13 @@ void sb_fastc_vio_uart(struct port_extctx *ectxp) { } case SB_VUART_PUT: { - sioPutX(unitp->siop, (uint_fast16_t)ectxp->r2); + sioPutX(unitp->siop, (uint_fast16_t)ectxp->r1); ectxp->r0 = (uint32_t)0; break; } case SB_VUART_WREN: { - sioWriteEnableFlagsX(unitp->siop, (sioevents_t)ectxp->r2); + sioWriteEnableFlagsX(unitp->siop, (sioevents_t)ectxp->r1); ectxp->r0 = (uint32_t)0; break; } @@ -223,7 +223,7 @@ void sb_fastc_vio_uart(struct port_extctx *ectxp) { case SB_VUART_GCEVT: { ectxp->r0 = (uint32_t)sioGetAndClearEventsX(unitp->siop, - (sioevents_t)ectxp->r2); + (sioevents_t)ectxp->r1); break; } case SB_VUART_GEVT: diff --git a/os/xhal/ports/vio/hal_lld.h b/os/xhal/ports/vio/hal_lld.h index aa82012b1..fe89993e8 100644 --- a/os/xhal/ports/vio/hal_lld.h +++ b/os/xhal/ports/vio/hal_lld.h @@ -80,6 +80,15 @@ typedef unsigned halclkpt_t; #define __MK_VECTOR(n) __sb_vector##n #define MK_VECTOR(n) __MK_VECTOR(n) +/** + * @brief Builds a VIO call 1st parameter. + * + * @param[in] c the sub-code + * @param[in] u the unit identifier + * @return The formatted VIO call 1st parameter. + */ +#define VIO_CALL(c, u) (((uint32_t)(u) << 24) | (uint32_t)(c)) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/xhal/ports/vio/hal_pal_lld.h b/os/xhal/ports/vio/hal_pal_lld.h index 917110953..9e0cb6213 100644 --- a/os/xhal/ports/vio/hal_pal_lld.h +++ b/os/xhal/ports/vio/hal_pal_lld.h @@ -233,39 +233,39 @@ extern "C" { __attribute__((always_inline)) static inline uint32_t __pal_lld_readport(ioportid_t port) { - __syscall2r(96, SB_VGPIO_READ, port); + __syscall1r(96, VIO_CALL(SB_VGPIO_READ, port)); return (ioportmask_t)r0; } __attribute__((always_inline)) static inline uint32_t __pal_lld_readlatch(ioportid_t port) { - __syscall2r(96, SB_VGPIO_READLATCH, port); + __syscall1r(96, VIO_CALL(SB_VGPIO_READLATCH, port)); return (ioportmask_t)r0; } __attribute__((always_inline)) static inline void __pal_lld_writeport(ioportid_t port, uint32_t bits) { - __syscall3r(96, SB_VGPIO_WRITE, port, bits); + __syscall2r(96, VIO_CALL(SB_VGPIO_WRITE, port), bits); } __attribute__((always_inline)) static inline void __pal_lld_setport(ioportid_t port, uint32_t bits) { - __syscall3r(96, SB_VGPIO_SET, port, bits); + __syscall2r(96, VIO_CALL(SB_VGPIO_SET, port), bits); } __attribute__((always_inline)) static inline void __pal_lld_clearport(ioportid_t port, uint32_t bits) { - __syscall3r(96, SB_VGPIO_CLEAR, port, bits); + __syscall2r(96, VIO_CALL(SB_VGPIO_CLEAR, port), bits); } __attribute__((always_inline)) static inline void __pal_lld_toggleport(ioportid_t port, uint32_t bits) { - __syscall3r(96, SB_VGPIO_TOGGLE, port, bits); + __syscall2r(96, VIO_CALL(SB_VGPIO_TOGGLE, port), bits); } #endif /* HAL_USE_PAL == TRUE */ diff --git a/os/xhal/ports/vio/hal_sio_lld.c b/os/xhal/ports/vio/hal_sio_lld.c index 3da2a348a..54230d73f 100644 --- a/os/xhal/ports/vio/hal_sio_lld.c +++ b/os/xhal/ports/vio/hal_sio_lld.c @@ -66,21 +66,21 @@ static const SIOConfig default_config = { CC_FORCE_INLINE static inline uint32_t __sio_vuart_init(uint32_t nvuart) { - __syscall2r(225, SB_VUART_INIT, nvuart); + __syscall1r(225, VIO_CALL(SB_VUART_INIT, nvuart)); return (uint32_t)r0; } CC_FORCE_INLINE static inline uint32_t __sio_vuart_deinit(uint32_t nvuart) { - __syscall2r(225, SB_VUART_DEINIT, nvuart); + __syscall1r(225, VIO_CALL(SB_VUART_DEINIT, nvuart)); return (uint32_t)r0; } CC_FORCE_INLINE static inline uint32_t __sio_vuart_setcfg(uint32_t nvuart, uint32_t ncfg) { - __syscall3r(225, SB_VUART_SETCFG, nvuart, ncfg); + __syscall2r(225, VIO_CALL(SB_VUART_SETCFG, nvuart), ncfg); return (uint32_t)r0; } @@ -219,7 +219,7 @@ msg_t sio_lld_configure(SIODriver *siop, const SIOConfig *config) { */ bool sio_lld_is_rx_empty(SIODriver *siop) { - __syscall2r(97, SB_VUART_ISRXE, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_ISRXE, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (bool)r0; @@ -237,7 +237,7 @@ bool sio_lld_is_rx_empty(SIODriver *siop) { */ bool sio_lld_is_rx_idle(SIODriver *siop) { - __syscall2r(97, SB_VUART_ISRXI, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_ISRXI, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (bool)r0; @@ -257,7 +257,7 @@ bool sio_lld_is_rx_idle(SIODriver *siop) { */ bool sio_lld_has_rx_errors(SIODriver *siop) { - __syscall2r(97, SB_VUART_HASERR, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_HASERR, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (bool)r0; @@ -275,7 +275,7 @@ bool sio_lld_has_rx_errors(SIODriver *siop) { */ bool sio_lld_is_tx_full(SIODriver *siop) { - __syscall2r(97, SB_VUART_ISTXF, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_ISTXF, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (bool)r0; @@ -293,7 +293,7 @@ bool sio_lld_is_tx_full(SIODriver *siop) { */ bool sio_lld_is_tx_ongoing(SIODriver *siop) { - __syscall2r(97, SB_VUART_ISTXO, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_ISTXO, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (bool)r0; @@ -306,7 +306,7 @@ bool sio_lld_is_tx_ongoing(SIODriver *siop) { */ void sio_lld_update_enable_flags(SIODriver *siop) { - __syscall3r(97, SB_VUART_WREN, siop->nvuart, siop->enabled); + __syscall2r(97, VIO_CALL(SB_VUART_WREN, siop->nvuart), siop->enabled); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); } @@ -320,7 +320,7 @@ void sio_lld_update_enable_flags(SIODriver *siop) { */ sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop) { - __syscall2r(97, SB_VUART_GCERR, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_GCERR, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (sioevents_t)r0; @@ -337,7 +337,7 @@ sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop) { */ sioevents_t sio_lld_get_and_clear_events(SIODriver *siop, sioevents_t events) { - __syscall3r(97, SB_VUART_GCEVT, siop->nvuart, events); + __syscall2r(97, VIO_CALL(SB_VUART_GCEVT, siop->nvuart), events); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (sioevents_t)r0; @@ -353,7 +353,7 @@ sioevents_t sio_lld_get_and_clear_events(SIODriver *siop, sioevents_t events) { */ sioevents_t sio_lld_get_events(SIODriver *siop) { - __syscall2r(97, SB_VUART_GEVT, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_GEVT, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (sioevents_t)r0; @@ -372,7 +372,7 @@ sioevents_t sio_lld_get_events(SIODriver *siop) { */ size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n) { - __syscall4r(97, SB_VUART_READ, siop->nvuart, buffer, n); + __syscall3r(97, VIO_CALL(SB_VUART_READ, siop->nvuart), buffer, n); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (size_t)r0; @@ -391,7 +391,7 @@ size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n) { */ size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n) { - __syscall4r(97, SB_VUART_WRITE, siop->nvuart, buffer, n); + __syscall3r(97, VIO_CALL(SB_VUART_WRITE, siop->nvuart), buffer, n); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (size_t)r0; @@ -408,7 +408,7 @@ size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n) { */ msg_t sio_lld_get(SIODriver *siop) { - __syscall2r(97, SB_VUART_GET, siop->nvuart); + __syscall1r(97, VIO_CALL(SB_VUART_GET, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (size_t)r0; @@ -425,7 +425,7 @@ msg_t sio_lld_get(SIODriver *siop) { */ void sio_lld_put(SIODriver *siop, uint_fast16_t data) { - __syscall3r(97, SB_VUART_PUT, siop->nvuart, data); + __syscall2r(97, VIO_CALL(SB_VUART_PUT, siop->nvuart), data); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); } @@ -445,7 +445,7 @@ void sio_lld_put(SIODriver *siop, uint_fast16_t data) { */ msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg) { - __syscall4r(97, SB_VUART_CTL, siop->nvuart, operation, arg); + __syscall3r(97, VIO_CALL(SB_VUART_CTL, siop->nvuart), operation, arg); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); return (msg_t)r0; @@ -462,7 +462,7 @@ void sio_lld_serve_interrupt(SIODriver *siop) { sioevents_t events; #if SIO_USE_SYNCHRONIZATION == TRUE - __syscall2rr(97, SB_VUART_GEVT, siop->nvuart); + __syscall1rr(97, VIO_CALL(SB_VUART_GEVT, siop->nvuart)); osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure"); /* Processing enabled events, if any.*/