Skip to content

Commit

Permalink
bssl: explicit stack thunk yield
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Jul 25, 2024
1 parent 7e0d20e commit bef62c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
31 changes: 28 additions & 3 deletions cores/esp8266/StackThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
*/

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstdio>

#include "pgmspace.h"
#include "debug.h"
#include "StackThunk.h"

#include <ets_sys.h>
#include <umm_malloc/umm_malloc.h>
#include <umm_malloc/umm_heap_select.h>

extern "C" {

extern void yield();
extern bool can_yield();

uint32_t *stack_thunk_ptr = NULL;
uint32_t *stack_thunk_top = NULL;
uint32_t *stack_thunk_save = NULL; /* Saved A1 while in BearSSL */
Expand All @@ -45,6 +51,25 @@ uint32_t stack_thunk_refcnt = 0;
#define _stackSize (6200/4)
#define _stackPaint 0xdeadbeef

void stack_thunk_yield()
{
if (can_yield()) {
uint32_t tmp;
register uint32_t* save __asm__("a3") = stack_thunk_save;

__asm__ __volatile__ (
"mov.n %0, a1\n\t"
"mov.n a1, %1\n\t"
: "=r"(tmp) : "r"(save) : "memory");

yield();

__asm__ __volatile__ (
"mov.n a1, %0\n\t"
:: "r"(tmp) : "memory");
}
}

/* Add a reference, and allocate the stack if necessary */
void stack_thunk_add_ref()
{
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/StackThunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
extern "C" {
#endif

extern void stack_thunk_yield();

extern void stack_thunk_add_ref();
extern void stack_thunk_del_ref();
extern void stack_thunk_repaint();
Expand Down
Binary file modified tools/sdk/lib/libbearssl.a
Binary file not shown.

0 comments on commit bef62c1

Please sign in to comment.