ESP8266
cont.h
1 /*
2  cont.h - continuations support for Xtensa call0 ABI
3  Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
4  This file is part of the esp8266 core for Arduino environment.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef CONT_H_
22 #define CONT_H_
23 
24 #include <stdbool.h>
25 
26 #ifndef CONT_STACKSIZE
27 #define CONT_STACKSIZE 4096
28 #endif
29 
30 typedef struct cont_ {
31  void (*pc_ret)(void);
32  unsigned* sp_ret;
33 
34  void (*pc_yield)(void);
35  unsigned* sp_yield;
36 
37  unsigned* stack_end;
38  unsigned unused1;
39  unsigned unused2;
40  unsigned stack_guard1;
41 
42  unsigned stack[CONT_STACKSIZE / 4];
43 
44  unsigned stack_guard2;
45  unsigned* struct_start;
46 } cont_t;
47 
48 // Initialize the cont_t structure before calling cont_run
49 void cont_init(cont_t*);
50 
51 // Run function pfn in a separate stack, or continue execution
52 // at the point where cont_yield was called
53 void cont_run(cont_t*, void (*pfn)(void));
54 
55 // Return to the point where cont_run was called, saving the
56 // execution state (registers and stack)
57 void cont_yield(cont_t*);
58 
59 // Check guard bytes around the stack. Return 0 in case everything is ok,
60 // return 1 if guard bytes were overwritten.
61 int cont_check(cont_t* cont);
62 
63 // Go through stack and check how many bytes are most probably still unchanged
64 // and thus weren't used by the user code. i.e. that stack space is free. (high water mark)
65 int cont_get_free_stack(cont_t* cont);
66 
67 // Check if yield() may be called. Returns true if we are running inside
68 // continuation stack
69 bool cont_can_yield(cont_t* cont);
70 
71 #endif /* CONT_H_ */
void(* pc_ret)(void)
Definition: cont.h:31
unsigned stack_guard2
Definition: cont.h:44
unsigned * sp_ret
Definition: cont.h:32
void(* pc_yield)(void)
Definition: cont.h:34
unsigned stack[4096/4]
Definition: cont.h:42
unsigned * sp_yield
Definition: cont.h:35
unsigned unused2
Definition: cont.h:39
Definition: cont.h:30
unsigned stack_guard1
Definition: cont.h:40
unsigned * stack_end
Definition: cont.h:37
unsigned unused1
Definition: cont.h:38
unsigned * struct_start
Definition: cont.h:45