Optimizations, stable point, not finished.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15779 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2022-09-10 12:13:40 +00:00
parent d4919dae33
commit 4d0df2442b
5 changed files with 69 additions and 15 deletions

View File

@ -68,15 +68,19 @@ CC_NO_INLINE uint32_t port_get_s_psp(void) {
return (uint32_t)__port_syscall_get_s_psp(__sch_get_currthread());
}
CC_WEAK void __port_do_fastcall_entry(uint32_t n) {
CC_WEAK void __port_do_fastcall_entry(struct port_extctx *ectxp,
uint32_t n) {
(void)ectxp;
(void)n;
chSysHalt("unimplemented fastcall");
}
CC_WEAK void __port_do_syscall_entry(uint32_t n) {
CC_WEAK void __port_do_syscall_entry(struct port_extctx *ectxp,
uint32_t n) {
(void)ectxp;
(void)n;
chSysHalt("unimplemented syscall");

View File

@ -218,26 +218,26 @@
.thumb_func
.globl SVC_Handler
SVC_Handler:
mrs r2, PSP
#if PORT_USE_SYSCALL
mrs r12, CONTROL
tst r12, #1
beq frompriv
/* SVC called from non-privileged mode for a syscall.*/
/* Note, LR already contains the return address.*/
ldr r3, [r2, #24] /* PC position. */
ldrh r0, [r3, #-2] /* SVC opcode. */
and r0, #255
cmp r0, #0x80
mrs r0, PSP /* Position of the exc.frame.*/
ldr r3, [r0, #24] /* PC position.*/
ldrb r1, [r3, #-2] /* SVC parameter.*/
cmp r1, #0x80
bge __port_do_fastcall_entry
bic r12, #1
msr CONTROL, r12 /* Switching to privileged. */
msr CONTROL, r12 /* Switching to privileged.*/
b __port_do_syscall_entry
frompriv:
/* SVC called from privileged mode for unprivileged return.*/
ldr r3, [r2, #24] /* PC position. */
ldrh r3, [r3, #-2] /* SVC opcode. */
mrs r2, PSP /* Position of the exc.frame.*/
ldr r3, [r2, #24] /* PC position.*/
ldrh r3, [r3, #-2] /* SVC opcode.*/
ands r3, #255
beq ctxswitch
/* Called for non-privileged mode change.*/
@ -247,6 +247,8 @@ frompriv:
ctxswitch:
/* SVC called from privilege mode for context switch.*/
#else
mrs r2, PSP /* Position of the exc.frame.*/
#endif
/* Context store for old thread through R1.*/
adds r1, #CONTEXT_OFFSET

View File

@ -51,12 +51,23 @@
.thumb_func
.global __sb_dispatch_syscall
__sb_dispatch_syscall:
ldr r3, =sb_syscalls
movw r3, #:lower16:sb_syscalls
movt r3, #:upper16:sb_syscalls
ldr.w r3, [r3, r1, lsl #2]
blx r3
svc 1
.zombies1: b .zombies1
.align 2
.thumb_func
.global __port_do_fastcall_entry
__port_do_fastcall_entry:
movw r3, #:lower16:sb_fastcalls
movt r3, #:upper16:sb_fastcalls
subs r1, #128
ldr.w r3, [r3, r1, lsl #2]
bx r3
.align 2
.thumb_func
.global HardFault_Handler

View File

@ -1216,12 +1216,15 @@ void __sb_abort(msg_t msg) {
chSysHalt("zombies");
}
void __port_do_syscall_entry(uint32_t n) {
void __port_do_syscall_entry(struct port_extctx *ectxpxx,
uint32_t n) {
extern void __sb_dispatch_syscall(struct port_extctx *ctxp, uint32_t n);
thread_t *tp = __sch_get_currthread();
struct port_extctx *ectxp, *newctxp;
uint32_t u_psp;
(void)ectxpxx;
/* Caller context in unprivileged memory.*/
u_psp = __get_PSP();
ectxp = (struct port_extctx *)u_psp;
@ -1260,11 +1263,16 @@ void __port_do_syscall_return(void) {
#endif
}
void __port_do_fastcall_entry(uint32_t n) {
#if 0 /* Moved in asm module.*/
void __port_do_fastcall_entry(struct port_extctx *ectxpxx,
uint32_t n) {
struct port_extctx *ectxp;
(void)ectxpxx;
ectxp = (struct port_extctx *)__get_PSP();
sb_fastcalls[n - 128](ectxp);
}
#endif
/** @} */

View File

@ -99,6 +99,27 @@ static struct port_extctx * vrq_pushctx(sb_class_t *sbp,
return ectxp;
}
CC_NO_INLINE
static void vrq_pushctx2(struct port_extctx *ectxp,
sb_class_t *sbp,
sb_vrqmask_t active_mask) {
/* Checking if the new frame is within the sandbox else failure.*/
if (!sb_is_valid_write_range(sbp,
(void *)(ectxp - 1),
sizeof (struct port_extctx))) {
/* Making the sandbox return on a privileged address, this
will cause a fault and sandbox termination.*/
ectxp->pc = (uint32_t)vrq_privileged_code;
}
else {
/* Creating a new context for return the VRQ handler.*/
ectxp--;
vrq_makectx(sbp, ectxp, active_mask);
__set_PSP((uint32_t)ectxp);
}
}
static void delay_cb(virtual_timer_t *vtp, void *arg) {
sb_class_t *sbp = (sb_class_t *)arg;
@ -326,10 +347,18 @@ void sb_api_vrq_disable(struct port_extctx *ectxp) {
void sb_api_vrq_enable(struct port_extctx *ectxp) {
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
sb_vrqmask_t active_mask;
sbp->vrq_isr = 0U;
active_mask = sbp->vrq_wtmask & sbp->vrq_enmask;
if (active_mask != 0U) {
sbp->vrq_isr = 0U;
__sb_vrq_check_pending(sbp, ectxp);
/* Creating a return context.*/
vrq_pushctx2(ectxp, sbp, active_mask);
}
else {
sbp->vrq_isr = 0U;
}
}
void sb_api_vrq_getisr(struct port_extctx *ectxp) {