LCOV - code coverage report
Current view: top level - py - nlrx64.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-343-g7b050b366.info Lines: 5 7 71.4 %
Date: 2024-04-25 17:00:48 Functions: 2 2 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of the MicroPython project, http://micropython.org/
       3                 :            :  *
       4                 :            :  * The MIT License (MIT)
       5                 :            :  *
       6                 :            :  * Copyright (c) 2013-2017 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                 :            : 
      27                 :            : #include "py/mpstate.h"
      28                 :            : 
      29                 :            : #if MICROPY_NLR_X64
      30                 :            : 
      31                 :            : #undef nlr_push
      32                 :            : 
      33                 :            : // x86-64 callee-save registers are:
      34                 :            : //  rbx, rbp, rsp, r12, r13, r14, r15
      35                 :            : 
      36                 :            : __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr);
      37                 :            : 
      38                 :            : #if !MICROPY_NLR_OS_WINDOWS
      39                 :            : #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 8)
      40                 :            : #define USE_NAKED 1
      41                 :            : #else
      42                 :            : // On older gcc the equivalent here is to force omit-frame-pointer
      43                 :            : __attribute__((optimize("omit-frame-pointer")))
      44                 :            : #endif
      45                 :            : #endif
      46                 :            : 
      47                 :            : #if !defined(USE_NAKED)
      48                 :            : #define USE_NAKED 0
      49                 :            : #endif
      50                 :            : 
      51                 :            : #if USE_NAKED
      52                 :            : // nlr_push prelude should never push frame pointer register ebp onto the stack
      53                 :            : __attribute__((naked))
      54                 :            : #endif
      55                 :    8846889 : unsigned int nlr_push(nlr_buf_t *nlr) {
      56                 :            :     #if !USE_NAKED
      57                 :            :     (void)nlr;
      58                 :            :     #endif
      59                 :            : 
      60                 :            :     #if MICROPY_NLR_OS_WINDOWS
      61                 :            : 
      62                 :            :     __asm volatile (
      63                 :            :         "movq   (%rsp), %rax        \n" // load return %rip
      64                 :            :         "movq   %rax, 16(%rcx)      \n" // store %rip into nlr_buf
      65                 :            :         "movq   %rbp, 24(%rcx)      \n" // store %rbp into nlr_buf
      66                 :            :         "movq   %rsp, 32(%rcx)      \n" // store %rsp into nlr_buf
      67                 :            :         "movq   %rbx, 40(%rcx)      \n" // store %rbx into nlr_buf
      68                 :            :         "movq   %r12, 48(%rcx)      \n" // store %r12 into nlr_buf
      69                 :            :         "movq   %r13, 56(%rcx)      \n" // store %r13 into nlr_buf
      70                 :            :         "movq   %r14, 64(%rcx)      \n" // store %r14 into nlr_buf
      71                 :            :         "movq   %r15, 72(%rcx)      \n" // store %r15 into nlr_buf
      72                 :            :         "movq   %rdi, 80(%rcx)      \n" // store %rdr into nlr_buf
      73                 :            :         "movq   %rsi, 88(%rcx)      \n" // store %rsi into nlr_buf
      74                 :            :         "jmp    nlr_push_tail       \n" // do the rest in C
      75                 :            :         );
      76                 :            : 
      77                 :            :     #else
      78                 :            : 
      79                 :    8846889 :     __asm volatile (
      80                 :            :         "movq   (%rsp), %rax        \n" // load return %rip
      81                 :            :         "movq   %rax, 16(%rdi)      \n" // store %rip into nlr_buf
      82                 :            :         "movq   %rbp, 24(%rdi)      \n" // store %rbp into nlr_buf
      83                 :            :         "movq   %rsp, 32(%rdi)      \n" // store %rsp into nlr_buf
      84                 :            :         "movq   %rbx, 40(%rdi)      \n" // store %rbx into nlr_buf
      85                 :            :         "movq   %r12, 48(%rdi)      \n" // store %r12 into nlr_buf
      86                 :            :         "movq   %r13, 56(%rdi)      \n" // store %r13 into nlr_buf
      87                 :            :         "movq   %r14, 64(%rdi)      \n" // store %r14 into nlr_buf
      88                 :            :         "movq   %r15, 72(%rdi)      \n" // store %r15 into nlr_buf
      89                 :            :         #if defined(__APPLE__) && defined(__MACH__)
      90                 :            :         "jmp    _nlr_push_tail      \n" // do the rest in C
      91                 :            :         #else
      92                 :            :         "jmp    nlr_push_tail       \n" // do the rest in C
      93                 :            :         #endif
      94                 :            :         );
      95                 :            : 
      96                 :            :     #endif
      97                 :            : 
      98                 :            :     #if !USE_NAKED
      99                 :            :     return 0; // needed to silence compiler warning
     100                 :            :     #endif
     101                 :          0 : }
     102                 :            : 
     103                 :     235475 : NORETURN void nlr_jump(void *val) {
     104         [ -  + ]:     235475 :     MP_NLR_JUMP_HEAD(val, top)
     105                 :            : 
     106                 :     235475 :     __asm volatile (
     107                 :            :         "movq   %0, %%rcx           \n" // %rcx points to nlr_buf
     108                 :            :         #if MICROPY_NLR_OS_WINDOWS
     109                 :            :         "movq   88(%%rcx), %%rsi    \n" // load saved %rsi
     110                 :            :         "movq   80(%%rcx), %%rdi    \n" // load saved %rdi
     111                 :            :         #endif
     112                 :            :         "movq   72(%%rcx), %%r15    \n" // load saved %r15
     113                 :            :         "movq   64(%%rcx), %%r14    \n" // load saved %r14
     114                 :            :         "movq   56(%%rcx), %%r13    \n" // load saved %r13
     115                 :            :         "movq   48(%%rcx), %%r12    \n" // load saved %r12
     116                 :            :         "movq   40(%%rcx), %%rbx    \n" // load saved %rbx
     117                 :            :         "movq   32(%%rcx), %%rsp    \n" // load saved %rsp
     118                 :            :         "movq   24(%%rcx), %%rbp    \n" // load saved %rbp
     119                 :            :         "movq   16(%%rcx), %%rax    \n" // load saved %rip
     120                 :            :         "movq   %%rax, (%%rsp)      \n" // store saved %rip to stack
     121                 :            :         "xorq   %%rax, %%rax        \n" // clear return register
     122                 :            :         "inc    %%al                \n" // increase to make 1, non-local return
     123                 :            :         "ret                        \n" // return
     124                 :            :         :                           // output operands
     125                 :            :         : "r" (top)                 // input operands
     126                 :            :         : "memory"                  // clobbered registers
     127                 :            :         );
     128                 :            : 
     129                 :          0 :     MP_UNREACHABLE
     130                 :            : }
     131                 :            : 
     132                 :            : #endif // MICROPY_NLR_X64

Generated by: LCOV version 1.15-5-g462f71d