Skip to content

Commit d17506e

Browse files
committed
runtime/cgo: make crosscall2 5a/6a/8a-assembled
There is a #pragma dynexport crosscall2, to help SWIG, and 6l cannot export the symbol if it doesn't get to see it. R=golang-dev, iant CC=golang-dev https://golang.org/cl/7448044
1 parent 83c5d07 commit d17506e

File tree

7 files changed

+100
-98
lines changed

7 files changed

+100
-98
lines changed

src/pkg/runtime/cgo/asm_386.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
/*
6+
* void crosscall2(void (*fn)(void*, int32), void*, int32)
7+
* Save registers and call fn with two arguments.
8+
*/
9+
TEXT crosscall2(SB),7,$0
10+
PUSHL BP
11+
MOVL SP, BP
12+
PUSHL BX
13+
PUSHL SI
14+
PUSHL DI
15+
16+
SUBL $8, SP
17+
MOVL 16(BP), AX
18+
MOVL AX, 4(SP)
19+
MOVL 12(BP), AX
20+
MOVL AX, 0(SP)
21+
MOVL 8(BP), AX
22+
CALL AX
23+
ADDL $8, SP
24+
25+
POPL DI
26+
POPL SI
27+
POPL BX
28+
POPL BP
29+
RET

src/pkg/runtime/cgo/asm_amd64.s

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
/*
6+
* void crosscall2(void (*fn)(void*, int32), void*, int32)
7+
* Save registers and call fn with two arguments.
8+
*/
9+
TEXT crosscall2(SB),7,$0
10+
SUBQ $0x58, SP /* keeps stack pointer 32-byte aligned */
11+
MOVQ BX, 0x10(SP)
12+
MOVQ BP, 0x18(SP)
13+
MOVQ R12, 0x20(SP)
14+
MOVQ R13, 0x28(SP)
15+
MOVQ R14, 0x30(SP)
16+
MOVQ R15, 0x38(SP)
17+
18+
#ifdef GOOS_windows
19+
// Win64 save RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15
20+
MOVQ DI, 0x40(SP)
21+
MOVQ SI, 0x48(SP)
22+
23+
MOVQ DX, 0(SP) /* arg */
24+
MOVQ R8, 8(SP) /* argsize (includes padding) */
25+
26+
CALL CX /* fn */
27+
28+
MOVQ 0x40(SP), DI
29+
MOVQ 0x48(SP), SI
30+
#else
31+
MOVQ SI, 0(SP) /* arg */
32+
MOVQ DX, 8(SP) /* argsize (includes padding) */
33+
34+
CALL DI /* fn */
35+
#endif
36+
37+
MOVQ 0x10(SP), BX
38+
MOVQ 0x18(SP), BP
39+
MOVQ 0x20(SP), R12
40+
MOVQ 0x28(SP), R13
41+
MOVQ 0x30(SP), R14
42+
MOVQ 0x38(SP), R15
43+
44+
ADDQ $0x58, SP
45+
RET

src/pkg/runtime/cgo/asm_arm.s

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
/*
6+
* void crosscall2(void (*fn)(void*, int32), void*, int32)
7+
* Save registers and call fn with two arguments.
8+
*/
9+
TEXT crosscall2(SB),7,$-4
10+
/*
11+
* We still need to save all callee save register as before, and then
12+
* push 2 args for fn (R1 and R2).
13+
* Also note that at procedure entry in 5c/5g world, 4(R13) will be the
14+
* first arg, so we must push another dummy reg (R0) for 0(R13).
15+
* Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0
16+
* nevertheless.
17+
*/
18+
MOVM.WP [R0, R1, R2, R4, R5, R6, R7, R8, R9, R10, R11, R12, R14], (R13)
19+
BL x_cgo_load_gm(SB)
20+
MOVW PC, R14
21+
MOVW -4(R13), PC
22+
MOVM.IAW (R13), [R0, R1, R2, R4, R5, R6, R7, R8, R9, R10, R11, R12, PC]

src/pkg/runtime/cgo/callbacks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ _cgo_panic(void *a, int32 n)
7878
runtime·cgocallback((void(*)(void))_cgo_panic_internal, a, n);
7979
}
8080

81-
#pragma cgo_static_import x_cgo_init
81+
#pragma cgo_import_static x_cgo_init
8282
extern void x_cgo_init(G*);
8383
void (*_cgo_init)(G*) = x_cgo_init;
8484

85-
#pragma cgo_static_import x_cgo_malloc
85+
#pragma cgo_import_static x_cgo_malloc
8686
extern void x_cgo_malloc(void*);
8787
void (*_cgo_malloc)(void*) = x_cgo_malloc;
8888

89-
#pragma cgo_static_import x_cgo_free
89+
#pragma cgo_import_static x_cgo_free
9090
extern void x_cgo_free(void*);
9191
void (*_cgo_free)(void*) = x_cgo_free;
9292

93-
#pragma cgo_static_import x_cgo_thread_start
93+
#pragma cgo_import_static x_cgo_thread_start
9494
extern void x_cgo_thread_start(void*);
9595
void (*_cgo_thread_start)(void*) = x_cgo_thread_start;

src/pkg/runtime/cgo/gcc_386.S

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,6 @@ EXT(crosscall_386):
3535
popl %ebp
3636
ret
3737

38-
/*
39-
* void crosscall2(void (*fn)(void*, int32), void*, int32)
40-
*
41-
* Save registers and call fn with two arguments.
42-
*/
43-
.globl EXT(crosscall2)
44-
EXT(crosscall2):
45-
pushl %ebp
46-
movl %esp, %ebp
47-
pushl %ebx
48-
pushl %esi
49-
pushl %edi
50-
51-
pushl 16(%ebp)
52-
pushl 12(%ebp)
53-
mov 8(%ebp), %eax
54-
call *%eax
55-
addl $8,%esp
56-
57-
popl %edi
58-
popl %esi
59-
popl %ebx
60-
popl %ebp
61-
ret
62-
6338
.globl EXT(__stack_chk_fail_local)
6439
EXT(__stack_chk_fail_local):
6540
1:

src/pkg/runtime/cgo/gcc_amd64.S

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
* are callee-save so they must be saved explicitly.
2020
* The standard x86-64 ABI passes the three arguments m, g, fn
2121
* in %rdi, %rsi, %rdx.
22-
*
23-
* Also need to set %r15 to g and %r14 to m (see ../pkg/runtime/mkasmh.sh)
24-
* during the call.
2522
*/
2623
.globl EXT(crosscall_amd64)
2724
EXT(crosscall_amd64):
@@ -45,48 +42,3 @@ EXT(crosscall_amd64):
4542
popq %rbp
4643
popq %rbx
4744
ret
48-
49-
/*
50-
* void crosscall2(void (*fn)(void*, int32), void *arg, int32 argsize)
51-
*
52-
* Save registers and call fn with two arguments. fn is a Go function
53-
* which takes parameters on the stack rather than in registers.
54-
*/
55-
.globl EXT(crosscall2)
56-
EXT(crosscall2):
57-
subq $0x58, %rsp /* keeps stack pointer 32-byte aligned */
58-
movq %rbx, 0x10(%rsp)
59-
movq %rbp, 0x18(%rsp)
60-
movq %r12, 0x20(%rsp)
61-
movq %r13, 0x28(%rsp)
62-
movq %r14, 0x30(%rsp)
63-
movq %r15, 0x38(%rsp)
64-
65-
#if defined(_WIN64)
66-
// Win64 save RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15
67-
movq %rdi, 0x40(%rsp)
68-
movq %rsi, 0x48(%rsp)
69-
70-
movq %rdx, 0(%rsp) /* arg */
71-
movq %r8, 8(%rsp) /* argsize (includes padding) */
72-
73-
call *%rcx /* fn */
74-
#else
75-
movq %rsi, 0(%rsp) /* arg */
76-
movq %rdx, 8(%rsp) /* argsize (includes padding) */
77-
78-
call *%rdi /* fn */
79-
#endif
80-
81-
movq 0x10(%rsp), %rbx
82-
movq 0x18(%rsp), %rbp
83-
movq 0x20(%rsp), %r12
84-
movq 0x28(%rsp), %r13
85-
movq 0x30(%rsp), %r14
86-
movq 0x38(%rsp), %r15
87-
#if defined(__WIN64)
88-
movq 0x40(%rsp), %rdi
89-
movq 0x48(%rsp), %rsi
90-
#endif
91-
addq $0x58, %rsp
92-
ret

src/pkg/runtime/cgo/gcc_arm.S

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ EXT(crosscall_arm2):
2929
mov pc, r3
3030
pop {r4, r5, r6, r7, r8, r9, r10, r11, ip, pc}
3131

32-
/*
33-
* void crosscall2(void (*fn)(void*, int32), void*, int32)
34-
*
35-
* Save registers and call fn with two arguments.
36-
*/
37-
.globl EXT(crosscall2)
38-
EXT(crosscall2):
39-
/*
40-
* We still need to save all callee save register as before, and then
41-
* push 2 args for fn (R1 and R2).
42-
* Also note that at procedure entry in 5c/5g world, 4(R13) will be the
43-
* first arg, so we must push another dummy reg (R0) for 0(R13).
44-
* Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0
45-
* nevertheless.
46-
*/
47-
push {r0, r1, r2, r4, r5, r6, r7, r8, r9, r10, r11, ip, lr}
48-
bl EXT(x_cgo_load_gm) // set up g and m from TLS
49-
mov lr, pc
50-
ldr pc, [sp, #0]
51-
pop {r0, r1, r2, r4, r5, r6, r7, r8, r9, r10, r11, ip, pc}
52-
5332
.globl EXT(__stack_chk_fail_local)
5433
EXT(__stack_chk_fail_local):
5534
1:

0 commit comments

Comments
 (0)