Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 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 Sokolovsky | b1ce37d | 2014-04-30 04:19:20 +0300 | [diff] [blame] | 27 | #if defined(__i386__) && !MICROPY_NLR_SETJMP |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 28 | /* x86 callee save: bx, di, si, bp, sp */ |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 29 | |
| 30 | .file "nlr.s" |
| 31 | .text |
| 32 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 33 | /* uint nlr_push(4(%esp)=nlr_buf_t *nlr) */ |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 34 | #ifdef _WIN32 |
| 35 | .globl _nlr_push |
| 36 | .def _nlr_push; .scl 2; .type 32; .endef |
| 37 | _nlr_push: |
| 38 | #else |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 39 | .globl nlr_push |
| 40 | .type nlr_push, @function |
| 41 | nlr_push: |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 42 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 43 | mov 4(%esp), %edx # load nlr_buf |
| 44 | mov (%esp), %eax # load return %ip |
| 45 | mov %eax, 8(%edx) # store %ip into nlr_buf+8 |
| 46 | mov %ebp, 12(%edx) # store %bp into nlr_buf+12 |
| 47 | mov %esp, 16(%edx) # store %sp into nlr_buf+16 |
| 48 | mov %ebx, 20(%edx) # store %bx into nlr_buf+20 |
| 49 | mov %edi, 24(%edx) # store %di into nlr_buf |
| 50 | mov %esi, 28(%edx) # store %si into nlr_buf |
| 51 | mov nlr_top, %eax # load nlr_top |
| 52 | mov %eax, (%edx) # store it |
| 53 | mov %edx, nlr_top # stor new nlr_buf (to make linked list) |
| 54 | xor %eax, %eax # return 0, normal return |
| 55 | ret # return |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 56 | #ifndef _WIN32 |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 57 | .size nlr_push, .-nlr_push |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 58 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 59 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 60 | /* void nlr_pop() */ |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 61 | #ifdef _WIN32 |
| 62 | .globl _nlr_pop |
| 63 | .def _nlr_pop; .scl 2; .type 32; .endef |
| 64 | _nlr_pop: |
| 65 | #else |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 66 | .globl nlr_pop |
| 67 | .type nlr_pop, @function |
| 68 | nlr_pop: |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 69 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 70 | mov nlr_top, %eax # load nlr_top |
| 71 | mov (%eax), %eax # load prev nlr_buf |
| 72 | mov %eax, nlr_top # store nlr_top (to unlink list) |
| 73 | ret # return |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 74 | #ifndef _WIN32 |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 75 | .size nlr_pop, .-nlr_pop |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 76 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 77 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 78 | /* void nlr_jump(4(%esp)=uint val) */ |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 79 | #ifdef _WIN32 |
| 80 | .globl _nlr_jump |
| 81 | .def _nlr_jump; .scl 2; .type 32; .endef |
| 82 | _nlr_jump: |
| 83 | #else |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 84 | .globl nlr_jump |
| 85 | .type nlr_jump, @function |
| 86 | nlr_jump: |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 87 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 88 | mov nlr_top, %edx # load nlr_top |
Damien George | 26cf55a | 2014-04-08 14:08:14 +0000 | [diff] [blame] | 89 | test %edx, %edx # check for nlr_top being NULL |
Paul Sokolovsky | 41809a1 | 2014-04-20 22:14:58 +0300 | [diff] [blame] | 90 | #ifdef _WIN32 |
| 91 | je _nlr_jump_fail # fail if nlr_top is NULL |
| 92 | #else |
Damien George | 26cf55a | 2014-04-08 14:08:14 +0000 | [diff] [blame] | 93 | je nlr_jump_fail # fail if nlr_top is NULL |
Paul Sokolovsky | 41809a1 | 2014-04-20 22:14:58 +0300 | [diff] [blame] | 94 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 95 | mov 4(%esp), %eax # load return value |
| 96 | mov %eax, 4(%edx) # store return value |
| 97 | mov (%edx), %eax # load prev nlr_top |
| 98 | mov %eax, nlr_top # store nlr_top (to unlink list) |
| 99 | mov 28(%edx), %esi # load saved %si |
| 100 | mov 24(%edx), %edi # load saved %di |
| 101 | mov 20(%edx), %ebx # load saved %bx |
| 102 | mov 16(%edx), %esp # load saved %sp |
| 103 | mov 12(%edx), %ebp # load saved %bp |
| 104 | mov 8(%edx), %eax # load saved %ip |
| 105 | mov %eax, (%esp) # store saved %ip to stack |
| 106 | xor %eax, %eax # clear return register |
| 107 | inc %al # increase to make 1, non-local return |
| 108 | ret # return |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 109 | #ifndef _WIN32 |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 110 | .size nlr_jump, .-nlr_jump |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 111 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 112 | |
Damien George | 26cf55a | 2014-04-08 14:08:14 +0000 | [diff] [blame] | 113 | .bss |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 114 | #ifndef _WIN32 |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 115 | .local nlr_top |
Markus Siemens | 19ccc6b | 2014-01-27 22:53:28 +0100 | [diff] [blame] | 116 | #endif |
Damien | ce89a21 | 2013-10-15 22:25:17 +0100 | [diff] [blame] | 117 | .comm nlr_top,4,4 |
Markus Siemens | 242856c | 2014-01-28 19:52:04 +0100 | [diff] [blame] | 118 | |
| 119 | #endif /* __i386__ */ |