| ... | ... | @@ -101,30 +101,32 @@ export nakedcc fn __aeabi_uidivmod() { |
| 101 | 101 | export nakedcc fn __chkstk() { |
| 102 | 102 | @setDebugSafety(this, false); |
| 103 | 103 | |
| 104 | | if (comptime builtin.arch == builtin.Arch.x86_64) { |
| 105 | | asm volatile ( |
| 106 | | \\ push %%rcx |
| 107 | | \\ cmp $0x1000,%%rax |
| 108 | | \\ lea 16(%%rsp),%%rcx // rsp before calling this routine -> rcx |
| 109 | | \\ jb 1f |
| 110 | | \\ 2: |
| 111 | | \\ sub $0x1000,%%rcx |
| 112 | | \\ test %%rcx,(%%rcx) |
| 113 | | \\ sub $0x1000,%%rax |
| 114 | | \\ cmp $0x1000,%%rax |
| 115 | | \\ ja 2b |
| 116 | | \\ 1: |
| 117 | | \\ sub %%rax,%%rcx |
| 118 | | \\ test %%rcx,(%%rcx) |
| 119 | | \\ |
| 120 | | \\ lea 8(%%rsp),%%rax // load pointer to the return address into rax |
| 121 | | \\ mov %%rcx,%%rsp // install the new top of stack pointer into rsp |
| 122 | | \\ mov -8(%%rax),%%rcx // restore rcx |
| 123 | | \\ push (%%rax) // push return address onto the stack |
| 124 | | \\ sub %%rsp,%%rax // restore the original value in rax |
| 125 | | \\ ret |
| 126 | | ); |
| 127 | | unreachable; |
| 104 | if (comptime builtin.os == builtin.Os.windows) { |
| 105 | if (comptime builtin.arch == builtin.Arch.x86_64) { |
| 106 | asm volatile ( |
| 107 | \\ push %%rcx |
| 108 | \\ cmp $0x1000,%%rax |
| 109 | \\ lea 16(%%rsp),%%rcx // rsp before calling this routine -> rcx |
| 110 | \\ jb 1f |
| 111 | \\ 2: |
| 112 | \\ sub $0x1000,%%rcx |
| 113 | \\ test %%rcx,(%%rcx) |
| 114 | \\ sub $0x1000,%%rax |
| 115 | \\ cmp $0x1000,%%rax |
| 116 | \\ ja 2b |
| 117 | \\ 1: |
| 118 | \\ sub %%rax,%%rcx |
| 119 | \\ test %%rcx,(%%rcx) |
| 120 | \\ |
| 121 | \\ lea 8(%%rsp),%%rax // load pointer to the return address into rax |
| 122 | \\ mov %%rcx,%%rsp // install the new top of stack pointer into rsp |
| 123 | \\ mov -8(%%rax),%%rcx // restore rcx |
| 124 | \\ push (%%rax) // push return address onto the stack |
| 125 | \\ sub %%rsp,%%rax // restore the original value in rax |
| 126 | \\ ret |
| 127 | ); |
| 128 | unreachable; |
| 129 | } |
| 128 | 130 | } |
| 129 | 131 | |
| 130 | 132 | @setGlobalLinkage(__chkstk, builtin.GlobalLinkage.Internal); |