andrzej-kaczmarek commented on code in PR #3042: URL: https://github.com/apache/mynewt-core/pull/3042#discussion_r1265228441
########## kernel/os/src/arch/sim/os_arch_stack_frame_64bit.s: ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#if defined MN_LINUX +#define sigsetjmp __sigsetjmp +#define CNAME(x) x +#elif defined MN_OSX +#define sigsetjmp sigsetjmp +#define CNAME(x) _ ## x +#elif defined MN_FreeBSD +#define sigsetjmp sigsetjmp +#define CNAME(x) x +#else +#error "unsupported platform" +#endif + + .text + .code64 + .p2align 4, 0x90 /* align on 16-byte boundary and fill with NOPs */ + + .globl CNAME(os_arch_frame_init_64bit) + .globl _os_arch_frame_init_64bit + /* + * void os_arch_frame_init(struct stack_frame *sf) + */ +CNAME(os_arch_frame_init_64bit): + pushq %rbp /* function prologue for backtrace */ + movq %rsp,%rbp + + /* + * At this point we are executing on the main() stack: + * ---------------- + * sf->sf_mainsp (%rdi) + * ---------------- + * return address 0x8(%rsp) + * ---------------- + * saved rbp 0x0(%rsp) + * ---------------- + */ + movq %rsp,(%rdi) /* sf->mainsp = %rsp */ + + /* + * Switch the stack so the stack pointer stored in 'sf->sf_jb' points + * to the task stack. This is slightly complicated because OS X wants + * the incoming stack pointer to be 16-byte aligned. + * + * ---------------- + * sf (other fields) + * ---------------- + * sf (sf_jb) 0x8(%rdi) + * ---------------- + * sf (sf_mainsp) 0x0(%rdi) + * ---------------- + * alignment padding variable (0 to 12 bytes) + * ---------------- + */ + movq %rdi,%rsp + subq $0x0c,%rsp /* make room for sigsetjmp() arguments */ + andq $0xfffffffffffffff0,%rsp /* align %rsp on 16-byte boundary */ Review Comment: `btrq $0xf,%rsp` should also work (and you don't need to count `f`s) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
