blob: 8ce93f227b136966936bb6f44bf23c277df6f493 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Paul Sokolovskyb1ce37d2014-04-30 04:19:20 +030027#if defined(__i386__) && !MICROPY_NLR_SETJMP
Damien George133b0832014-09-26 13:07:26 +000028
29// We only need the functions here if we are on x86, and we are not
30// using setjmp/longjmp.
31//
32// For reference, x86 callee save regs are:
33// ebx, esi, edi, ebp, esp, eip
Damience89a212013-10-15 22:25:17 +010034
35 .file "nlr.s"
36 .text
37
Damien George133b0832014-09-26 13:07:26 +000038/**************************************/
39// mp_uint_t nlr_push(4(%esp)=nlr_buf_t *nlr)
40
Markus Siemens242856c2014-01-28 19:52:04 +010041#ifdef _WIN32
42 .globl _nlr_push
43 .def _nlr_push; .scl 2; .type 32; .endef
44_nlr_push:
45#else
Damience89a212013-10-15 22:25:17 +010046 .globl nlr_push
47 .type nlr_push, @function
48nlr_push:
Markus Siemens19ccc6b2014-01-27 22:53:28 +010049#endif
Damience89a212013-10-15 22:25:17 +010050 mov 4(%esp), %edx # load nlr_buf
51 mov (%esp), %eax # load return %ip
52 mov %eax, 8(%edx) # store %ip into nlr_buf+8
53 mov %ebp, 12(%edx) # store %bp into nlr_buf+12
54 mov %esp, 16(%edx) # store %sp into nlr_buf+16
55 mov %ebx, 20(%edx) # store %bx into nlr_buf+20
56 mov %edi, 24(%edx) # store %di into nlr_buf
57 mov %esi, 28(%edx) # store %si into nlr_buf
58 mov nlr_top, %eax # load nlr_top
59 mov %eax, (%edx) # store it
60 mov %edx, nlr_top # stor new nlr_buf (to make linked list)
61 xor %eax, %eax # return 0, normal return
62 ret # return
Markus Siemens242856c2014-01-28 19:52:04 +010063#ifndef _WIN32
Damience89a212013-10-15 22:25:17 +010064 .size nlr_push, .-nlr_push
Markus Siemens19ccc6b2014-01-27 22:53:28 +010065#endif
Damience89a212013-10-15 22:25:17 +010066
Damien George133b0832014-09-26 13:07:26 +000067/**************************************/
68// void nlr_pop()
69
Markus Siemens242856c2014-01-28 19:52:04 +010070#ifdef _WIN32
71 .globl _nlr_pop
72 .def _nlr_pop; .scl 2; .type 32; .endef
73_nlr_pop:
74#else
Damience89a212013-10-15 22:25:17 +010075 .globl nlr_pop
76 .type nlr_pop, @function
77nlr_pop:
Markus Siemens19ccc6b2014-01-27 22:53:28 +010078#endif
Damience89a212013-10-15 22:25:17 +010079 mov nlr_top, %eax # load nlr_top
80 mov (%eax), %eax # load prev nlr_buf
81 mov %eax, nlr_top # store nlr_top (to unlink list)
82 ret # return
Markus Siemens242856c2014-01-28 19:52:04 +010083#ifndef _WIN32
Damience89a212013-10-15 22:25:17 +010084 .size nlr_pop, .-nlr_pop
Markus Siemens19ccc6b2014-01-27 22:53:28 +010085#endif
Damience89a212013-10-15 22:25:17 +010086
Damien George133b0832014-09-26 13:07:26 +000087/**************************************/
88// void nlr_jump(4(%esp)=mp_uint_t val)
89
Markus Siemens242856c2014-01-28 19:52:04 +010090#ifdef _WIN32
91 .globl _nlr_jump
92 .def _nlr_jump; .scl 2; .type 32; .endef
93_nlr_jump:
94#else
Damience89a212013-10-15 22:25:17 +010095 .globl nlr_jump
96 .type nlr_jump, @function
97nlr_jump:
Markus Siemens19ccc6b2014-01-27 22:53:28 +010098#endif
Damience89a212013-10-15 22:25:17 +010099 mov nlr_top, %edx # load nlr_top
Damien George26cf55a2014-04-08 14:08:14 +0000100 test %edx, %edx # check for nlr_top being NULL
Paul Sokolovsky41809a12014-04-20 22:14:58 +0300101#ifdef _WIN32
102 je _nlr_jump_fail # fail if nlr_top is NULL
103#else
Damien George26cf55a2014-04-08 14:08:14 +0000104 je nlr_jump_fail # fail if nlr_top is NULL
Paul Sokolovsky41809a12014-04-20 22:14:58 +0300105#endif
Damience89a212013-10-15 22:25:17 +0100106 mov 4(%esp), %eax # load return value
107 mov %eax, 4(%edx) # store return value
108 mov (%edx), %eax # load prev nlr_top
109 mov %eax, nlr_top # store nlr_top (to unlink list)
110 mov 28(%edx), %esi # load saved %si
111 mov 24(%edx), %edi # load saved %di
112 mov 20(%edx), %ebx # load saved %bx
113 mov 16(%edx), %esp # load saved %sp
114 mov 12(%edx), %ebp # load saved %bp
115 mov 8(%edx), %eax # load saved %ip
116 mov %eax, (%esp) # store saved %ip to stack
117 xor %eax, %eax # clear return register
118 inc %al # increase to make 1, non-local return
119 ret # return
Markus Siemens242856c2014-01-28 19:52:04 +0100120#ifndef _WIN32
Damience89a212013-10-15 22:25:17 +0100121 .size nlr_jump, .-nlr_jump
Markus Siemens19ccc6b2014-01-27 22:53:28 +0100122#endif
Damience89a212013-10-15 22:25:17 +0100123
Damien George133b0832014-09-26 13:07:26 +0000124/**************************************/
125// local variable nlr_top
126
Damien George26cf55a2014-04-08 14:08:14 +0000127 .bss
Markus Siemens242856c2014-01-28 19:52:04 +0100128#ifndef _WIN32
Damience89a212013-10-15 22:25:17 +0100129 .local nlr_top
Markus Siemens19ccc6b2014-01-27 22:53:28 +0100130#endif
Damience89a212013-10-15 22:25:17 +0100131 .comm nlr_top,4,4
Markus Siemens242856c2014-01-28 19:52:04 +0100132
Damien George133b0832014-09-26 13:07:26 +0000133#endif // defined(__i386__) && !MICROPY_NLR_SETJMP