Skip to content

Commit 4b34c76

Browse files
committed
Changes to get unix/ port compiling on Cygwin.
1 parent 3996611 commit 4b34c76

4 files changed

Lines changed: 81 additions & 5 deletions

File tree

py/nlr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ struct _nlr_buf_t {
1111
#if defined(__i386__)
1212
void *regs[6];
1313
#elif defined(__x86_64__)
14+
#if defined(__CYGWIN__)
15+
void *regs[12];
16+
#else
1417
void *regs[8];
18+
#endif
1519
#elif defined(__thumb2__)
1620
void *regs[10];
1721
#else

py/nlrx64.S

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.file "nlr.s"
55
.text
66

7+
#if !defined(__CYGWIN__)
8+
79
/* uint nlr_push(rdi=nlr_buf_t *nlr) */
810
#if !(defined(__APPLE__) && defined(__MACH__))
911
.globl nlr_push
@@ -82,4 +84,63 @@ nlr_jump:
8284
.local nlr_top
8385
#endif
8486
.comm nlr_top,8,8
85-
#endif
87+
88+
#else // !defined(__CYGWIN__)
89+
90+
/* uint nlr_push(rcx=nlr_buf_t *nlr) */
91+
.globl nlr_push
92+
nlr_push:
93+
movq (%rsp), %rax # load return %rip
94+
movq %rax, 16(%rcx) # store %rip into nlr_buf
95+
movq %rbp, 24(%rcx) # store %rbp into nlr_buf
96+
movq %rsp, 32(%rcx) # store %rsp into nlr_buf
97+
movq %rbx, 40(%rcx) # store %rbx into nlr_buf
98+
movq %r12, 48(%rcx) # store %r12 into nlr_buf
99+
movq %r13, 56(%rcx) # store %r13 into nlr_buf
100+
movq %r14, 64(%rcx) # store %r14 into nlr_buf
101+
movq %r15, 72(%rcx) # store %r15 into
102+
movq %rdi, 80(%rcx) # store %rdr into
103+
movq %rsi, 88(%rcx) # store %rsi into
104+
movq nlr_top(%rip), %rax # get last nlr_buf
105+
movq %rax, (%rcx) # store it
106+
movq %rcx, nlr_top(%rip) # stor new nlr_buf (to make linked list)
107+
xorq %rax, %rax # return 0, normal return
108+
ret # return
109+
110+
/* void nlr_jump(rcx=uint val) */
111+
112+
.globl nlr_jump
113+
nlr_jump:
114+
movq %rcx, %rax # put return value in %rax
115+
movq nlr_top(%rip), %rcx # get nlr_top into %rsi
116+
movq %rax, 8(%rcx) # store return value
117+
movq (%rcx), %rax # load prev nlr_buf
118+
movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list)
119+
movq 72(%rcx), %r15 # load saved %r15
120+
movq 64(%rcx), %r14 # load saved %r14
121+
movq 56(%rcx), %r13 # load saved %r13
122+
movq 48(%rcx), %r12 # load saved %r12
123+
movq 40(%rcx), %rbx # load saved %rbx
124+
movq 32(%rcx), %rsp # load saved %rsp
125+
movq 24(%rcx), %rbp # load saved %rbp
126+
movq 16(%rcx), %rax # load saved %rip
127+
movq 80(%rcx), %rdi # store %rdr into
128+
movq 88(%rcx), %rsi # store %rsi into
129+
movq %rax, (%rsp) # store saved %rip to stack
130+
xorq %rax, %rax # clear return register
131+
inc %al # increase to make 1, non-local return
132+
ret # return
133+
134+
.comm nlr_top,8,8
135+
136+
/* void nlr_pop() */
137+
.globl nlr_pop
138+
nlr_pop:
139+
movq nlr_top(%rip), %rax # get nlr_top into %rax
140+
movq (%rax), %rax # load prev nlr_buf
141+
movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list)
142+
ret # return
143+
144+
#endif // !defined(__CYGWIN__)
145+
146+
#endif // __x86_64__

tests/run-tests

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ if test_on_pyboard:
3636
for test_file in tests:
3737
test_name = os.path.splitext(os.path.basename(test_file))[0]
3838

39-
output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
39+
# run CPython
40+
try:
41+
output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
42+
except subprocess.CalledProcessError:
43+
output_expected = b'CPYTHON3 CRASH'
44+
45+
# run Micro Python
4046
try:
4147
if test_on_pyboard:
4248
pyb.enter_raw_repl()

unix/gccollect.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ void gc_collect(void) {
7878

7979
gc_collect_start();
8080
// this traces .data and .bss sections
81-
extern char __bss_start, _end;
82-
//printf(".bss: %p-%p\n", &__bss_start, &_end);
83-
gc_collect_root((void**)&__bss_start, ((machine_uint_t)&_end - (machine_uint_t)&__bss_start) / sizeof(machine_uint_t));
81+
#ifdef __CYGWIN__
82+
#define BSS_START __bss_start__
83+
#else
84+
#define BSS_START __bss_start
85+
#endif
86+
extern char BSS_START, _end;
87+
//printf(".bss: %p-%p\n", &BSS_START, &_end);
88+
gc_collect_root((void**)&BSS_START, ((machine_uint_t)&_end - (machine_uint_t)&BSS_START) / sizeof(machine_uint_t));
8489
regs_t regs;
8590
gc_helper_get_regs(regs);
8691
// GC stack (and regs because we captured them)

0 commit comments

Comments
 (0)