From 9ca91a0f9b1bd521c0ea4f7a2d80bbfe6e8cdbe8 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 15 Sep 2022 04:14:31 -0400 Subject: [PATCH 1/9] Port to 64-bit AIX --- psm/build.rs | 1 + psm/src/arch/powerpc64_aix.s | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 psm/src/arch/powerpc64_aix.s diff --git a/psm/build.rs b/psm/build.rs index ea00092..9d40212 100644 --- a/psm/build.rs +++ b/psm/build.rs @@ -41,6 +41,7 @@ fn find_assembly( ("powerpc", _, _, _) => Some(("src/arch/powerpc32.s", true)), ("powerpc64", _, _, "musl") => Some(("src/arch/powerpc64_openpower.s", true)), ("powerpc64", "little", _, _) => Some(("src/arch/powerpc64_openpower.s", true)), + ("powerpc64", _, "aix", _) => Some(("src/arch/powerpc64_aix.s", true)), ("powerpc64", _, _, _) => Some(("src/arch/powerpc64.s", true)), ("s390x", _, _, _) => Some(("src/arch/zseries_linux.s", true)), ("mips", _, _, _) => Some(("src/arch/mips_eabi.s", true)), diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s new file mode 100644 index 0000000..2a1c7a2 --- /dev/null +++ b/psm/src/arch/powerpc64_aix.s @@ -0,0 +1,124 @@ + .csect .text[PR],2 + .file "powerpc64.s" + .globl rust_psm_stack_direction[DS] + .globl .rust_psm_stack_direction + .align 4 + .csect rust_psm_stack_direction[DS],3 + .vbyte 8, .rust_psm_stack_direction + .vbyte 8, TOC[TC0] + .vbyte 8, 0 + .csect .text[PR],2 +.rust_psm_stack_direction: + li 3, 2 + blr +L..rust_psm_stack_direction_end: + .vbyte 4, 0x00000000 + .byte 0x00 + .byte 0x09 + .byte 0x20 + .byte 0x40 + .byte 0x80 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .vbyte 4, L..rust_psm_stack_direction_end-.rust_psm_stack_direction + .vbyte 2, 0x0018 + .byte "rust_psm_stack_direction" + + .globl rust_psm_stack_pointer[DS] + .globl .rust_psm_stack_pointer + .align 4 + .csect rust_psm_stack_pointer[DS],3 + .vbyte 8, .rust_psm_stack_pointer + .vbyte 8, TOC[TC0] + .vbyte 8, 0 + .csect .text[PR],2 +.rust_psm_stack_pointer: + mr 3, 1 + blr +L..rust_psm_stack_pointer_end: + .vbyte 4, 0x00000000 + .byte 0x00 + .byte 0x09 + .byte 0x20 + .byte 0x40 + .byte 0x80 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .vbyte 4, L..rust_psm_stack_pointer_end-.rust_psm_stack_pointer + .vbyte 2, 0x0016 + .byte "rust_psm_stack_pointer" + + + .globl rust_psm_replace_stack[DS] + .globl .rust_psm_replace_stack + .align 4 + .csect rust_psm_replace_stack[DS],3 + .vbyte 8, .rust_psm_replace_stack + .vbyte 8, TOC[TC0] + .vbyte 8, 0 + .csect .text[PR],2 +.rust_psm_replace_stack: + ld 2, 8(4) + ld 4, 0(4) + addi 5, 5, -48 + mr 1, 5 + mtctr 4 + bctr +L..rust_psm_replace_stack_end: + .vbyte 4, 0x00000000 + .byte 0x00 + .byte 0x09 + .byte 0x20 + .byte 0x40 + .byte 0x80 + .byte 0x00 + .byte 0x02 + .byte 0x01 + .vbyte 4, 0x00000000 + .vbyte 4, L..rust_psm_replace_stack_end-.rust_psm_replace_stack + .vbyte 2, 0x0016 + .byte "rust_psm_replace_stack" + + + .globl rust_psm_on_stack[DS] + .globl .rust_psm_on_stack + .align 4 + .csect rust_psm_on_stack[DS],3 + .vbyte 8, .rust_psm_on_stack + .vbyte 8, TOC[TC0] + .vbyte 8, 0 + .csect .text[PR],2 +.rust_psm_on_stack: + mflr 0 + std 2, -72(6) + std 0, -8(6) + sub 6, 6, 1 + addi 6, 6, -112 + stdux 1, 1, 6 + ld 2, 8(5) + ld 5, 0(5) + mtctr 5 + bctrl + ld 2, 40(1) + ld 0, 104(1) + mtlr 0 + ld 1, 0(1) + blr +L..rust_psm_on_stack_end: + .vbyte 4, 0x00000000 + .byte 0x00 + .byte 0x09 + .byte 0x20 + .byte 0x40 + .byte 0x80 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .vbyte 4, L..rust_psm_on_stack_end-.rust_psm_on_stack + .vbyte 2, 0x0011 + .byte "rust_psm_on_stack" + + .toc + From 5b45db15f645f5287043afd89ab98a4072edad0a Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 15 Sep 2022 04:21:50 -0400 Subject: [PATCH 2/9] Change .file --- psm/src/arch/powerpc64_aix.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s index 2a1c7a2..3db62e1 100644 --- a/psm/src/arch/powerpc64_aix.s +++ b/psm/src/arch/powerpc64_aix.s @@ -1,5 +1,5 @@ .csect .text[PR],2 - .file "powerpc64.s" + .file "powerpc64_aix.s" .globl rust_psm_stack_direction[DS] .globl .rust_psm_stack_direction .align 4 From 6fb1b1e269756fd7b9acb52c9f42007a3fb7ae41 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 15 Sep 2022 08:30:13 -0400 Subject: [PATCH 3/9] Fix indentation --- psm/src/arch/powerpc64_aix.s | 220 +++++++++++++++++------------------ 1 file changed, 109 insertions(+), 111 deletions(-) diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s index 3db62e1..4da8433 100644 --- a/psm/src/arch/powerpc64_aix.s +++ b/psm/src/arch/powerpc64_aix.s @@ -1,124 +1,122 @@ - .csect .text[PR],2 - .file "powerpc64_aix.s" - .globl rust_psm_stack_direction[DS] - .globl .rust_psm_stack_direction - .align 4 - .csect rust_psm_stack_direction[DS],3 - .vbyte 8, .rust_psm_stack_direction - .vbyte 8, TOC[TC0] - .vbyte 8, 0 - .csect .text[PR],2 +.csect .text[PR],2 +.file "powerpc64_aix.s" + +.globl rust_psm_stack_direction[DS] +.globl .rust_psm_stack_direction +.align 4 +.csect rust_psm_stack_direction[DS],3 +.vbyte 8, .rust_psm_stack_direction +.vbyte 8, TOC[TC0] +.vbyte 8, 0 +.csect .text[PR],2 .rust_psm_stack_direction: - li 3, 2 + li 3, 2 blr L..rust_psm_stack_direction_end: - .vbyte 4, 0x00000000 - .byte 0x00 - .byte 0x09 - .byte 0x20 - .byte 0x40 - .byte 0x80 - .byte 0x00 - .byte 0x00 - .byte 0x01 - .vbyte 4, L..rust_psm_stack_direction_end-.rust_psm_stack_direction - .vbyte 2, 0x0018 - .byte "rust_psm_stack_direction" +.vbyte 4, 0x00000000 +.byte 0x00 +.byte 0x09 +.byte 0x20 +.byte 0x40 +.byte 0x80 +.byte 0x00 +.byte 0x00 +.byte 0x01 +.vbyte 4, L..rust_psm_stack_direction_end-.rust_psm_stack_direction +.vbyte 2, 0x0018 +.byte "rust_psm_stack_direction" - .globl rust_psm_stack_pointer[DS] - .globl .rust_psm_stack_pointer - .align 4 - .csect rust_psm_stack_pointer[DS],3 - .vbyte 8, .rust_psm_stack_pointer - .vbyte 8, TOC[TC0] - .vbyte 8, 0 - .csect .text[PR],2 +.globl rust_psm_stack_pointer[DS] +.globl .rust_psm_stack_pointer +.align 4 +.csect rust_psm_stack_pointer[DS],3 +.vbyte 8, .rust_psm_stack_pointer +.vbyte 8, TOC[TC0] +.vbyte 8, 0 +.csect .text[PR],2 .rust_psm_stack_pointer: - mr 3, 1 - blr + mr 3, 1 + blr L..rust_psm_stack_pointer_end: - .vbyte 4, 0x00000000 - .byte 0x00 - .byte 0x09 - .byte 0x20 - .byte 0x40 - .byte 0x80 - .byte 0x00 - .byte 0x00 - .byte 0x01 - .vbyte 4, L..rust_psm_stack_pointer_end-.rust_psm_stack_pointer - .vbyte 2, 0x0016 - .byte "rust_psm_stack_pointer" - +.vbyte 4, 0x00000000 +.byte 0x00 +.byte 0x09 +.byte 0x20 +.byte 0x40 +.byte 0x80 +.byte 0x00 +.byte 0x00 +.byte 0x01 +.vbyte 4, L..rust_psm_stack_pointer_end-.rust_psm_stack_pointer +.vbyte 2, 0x0016 +.byte "rust_psm_stack_pointer" - .globl rust_psm_replace_stack[DS] - .globl .rust_psm_replace_stack - .align 4 - .csect rust_psm_replace_stack[DS],3 - .vbyte 8, .rust_psm_replace_stack - .vbyte 8, TOC[TC0] - .vbyte 8, 0 - .csect .text[PR],2 +.globl rust_psm_replace_stack[DS] +.globl .rust_psm_replace_stack +.align 4 +.csect rust_psm_replace_stack[DS],3 +.vbyte 8, .rust_psm_replace_stack +.vbyte 8, TOC[TC0] +.vbyte 8, 0 +.csect .text[PR],2 .rust_psm_replace_stack: - ld 2, 8(4) - ld 4, 0(4) - addi 5, 5, -48 - mr 1, 5 - mtctr 4 - bctr + ld 2, 8(4) + ld 4, 0(4) + addi 5, 5, -48 + mr 1, 5 + mtctr 4 + bctr L..rust_psm_replace_stack_end: - .vbyte 4, 0x00000000 - .byte 0x00 - .byte 0x09 - .byte 0x20 - .byte 0x40 - .byte 0x80 - .byte 0x00 - .byte 0x02 - .byte 0x01 - .vbyte 4, 0x00000000 - .vbyte 4, L..rust_psm_replace_stack_end-.rust_psm_replace_stack - .vbyte 2, 0x0016 - .byte "rust_psm_replace_stack" +.vbyte 4, 0x00000000 +.byte 0x00 +.byte 0x09 +.byte 0x20 +.byte 0x40 +.byte 0x80 +.byte 0x00 +.byte 0x02 +.byte 0x01 +.vbyte 4, 0x00000000 +.vbyte 4, L..rust_psm_replace_stack_end-.rust_psm_replace_stack +.vbyte 2, 0x0016 +.byte "rust_psm_replace_stack" - - .globl rust_psm_on_stack[DS] - .globl .rust_psm_on_stack - .align 4 - .csect rust_psm_on_stack[DS],3 - .vbyte 8, .rust_psm_on_stack - .vbyte 8, TOC[TC0] - .vbyte 8, 0 - .csect .text[PR],2 +.globl rust_psm_on_stack[DS] +.globl .rust_psm_on_stack +.align 4 +.csect rust_psm_on_stack[DS],3 +.vbyte 8, .rust_psm_on_stack +.vbyte 8, TOC[TC0] +.vbyte 8, 0 +.csect .text[PR],2 .rust_psm_on_stack: - mflr 0 - std 2, -72(6) - std 0, -8(6) - sub 6, 6, 1 - addi 6, 6, -112 - stdux 1, 1, 6 - ld 2, 8(5) - ld 5, 0(5) - mtctr 5 - bctrl - ld 2, 40(1) - ld 0, 104(1) - mtlr 0 - ld 1, 0(1) - blr + mflr 0 + std 2, -72(6) + std 0, -8(6) + sub 6, 6, 1 + addi 6, 6, -112 + stdux 1, 1, 6 + ld 2, 8(5) + ld 5, 0(5) + mtctr 5 + bctrl + ld 2, 40(1) + ld 0, 104(1) + mtlr 0 + ld 1, 0(1) + blr L..rust_psm_on_stack_end: - .vbyte 4, 0x00000000 - .byte 0x00 - .byte 0x09 - .byte 0x20 - .byte 0x40 - .byte 0x80 - .byte 0x00 - .byte 0x00 - .byte 0x01 - .vbyte 4, L..rust_psm_on_stack_end-.rust_psm_on_stack - .vbyte 2, 0x0011 - .byte "rust_psm_on_stack" - - .toc +.vbyte 4, 0x00000000 +.byte 0x00 +.byte 0x09 +.byte 0x20 +.byte 0x40 +.byte 0x80 +.byte 0x00 +.byte 0x00 +.byte 0x01 +.vbyte 4, L..rust_psm_on_stack_end-.rust_psm_on_stack +.vbyte 2, 0x0011 +.byte "rust_psm_on_stack" +.toc From 27b8416c6cfbe862bf3ecaaeaa32a6f1c8f46c7e Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 15 Sep 2022 22:07:58 -0400 Subject: [PATCH 4/9] Add more comments --- psm/src/arch/powerpc64_aix.s | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s index 4da8433..f3e2251 100644 --- a/psm/src/arch/powerpc64_aix.s +++ b/psm/src/arch/powerpc64_aix.s @@ -10,9 +10,12 @@ .vbyte 8, 0 .csect .text[PR],2 .rust_psm_stack_direction: +# extern "C" fn() -> u8 li 3, 2 blr L..rust_psm_stack_direction_end: +# Following bytes form the traceback table on AIX. +# See https://www.ibm.com/docs/en/aix/7.2?topic=processor-traceback-tables for more information. .vbyte 4, 0x00000000 .byte 0x00 .byte 0x09 @@ -35,6 +38,7 @@ L..rust_psm_stack_direction_end: .vbyte 8, 0 .csect .text[PR],2 .rust_psm_stack_pointer: +# extern "C" fn() -> *mut u8 mr 3, 1 blr L..rust_psm_stack_pointer_end: @@ -60,6 +64,7 @@ L..rust_psm_stack_pointer_end: .vbyte 8, 0 .csect .text[PR],2 .rust_psm_replace_stack: +# extern "C" fn(3: usize, 4: extern "C" fn(usize), 5: *mut u8) ld 2, 8(4) ld 4, 0(4) addi 5, 5, -48 @@ -90,6 +95,7 @@ L..rust_psm_replace_stack_end: .vbyte 8, 0 .csect .text[PR],2 .rust_psm_on_stack: +# extern "C" fn(3: usize, 4: extern "C" fn(usize), 5: *mut u8) mflr 0 std 2, -72(6) std 0, -8(6) From ce8669f4f9fb0817929d940ae9e287496746978d Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 15 Sep 2022 23:43:27 -0400 Subject: [PATCH 5/9] Add comments --- psm/src/arch/powerpc64_aix.s | 44 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s index f3e2251..18bd676 100644 --- a/psm/src/arch/powerpc64_aix.s +++ b/psm/src/arch/powerpc64_aix.s @@ -15,19 +15,26 @@ blr L..rust_psm_stack_direction_end: # Following bytes form the traceback table on AIX. -# See https://www.ibm.com/docs/en/aix/7.2?topic=processor-traceback-tables for more information. -.vbyte 4, 0x00000000 -.byte 0x00 -.byte 0x09 -.byte 0x20 -.byte 0x40 -.byte 0x80 -.byte 0x00 -.byte 0x00 -.byte 0x01 -.vbyte 4, L..rust_psm_stack_direction_end-.rust_psm_stack_direction -.vbyte 2, 0x0018 -.byte "rust_psm_stack_direction" +# For specification, see https://www.ibm.com/docs/en/aix/7.2?topic=processor-traceback-tables. +# For implementation, see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp, +# `PPCAIXAsmPrinter::emitTracebackTable`. +.vbyte 4, 0x00000000 # Traceback table begin, for unwinder to search the table. +.byte 0x00 # Version = 0 +.byte 0x09 # Language = CPlusPlus, since rust is using C++-like LSDA. +.byte 0x20 # -IsGlobaLinkage, -IsOutOfLineEpilogOrPrologue + # +HasTraceBackTableOffset, -IsInternalProcedure + # -HasControlledStorage, -IsTOCless + # -IsFloatingPointPresent + # -IsFloatingPointOperationLogOrAbortEnabled +.byte 0x40 # -IsInterruptHandler, +IsFunctionNamePresent, -IsAllocaUsed + # OnConditionDirective = 0, -IsCRSaved, -IsLRSaved +.byte 0x80 # +IsBackChainStored, -IsFixup, NumOfFPRsSaved = 0 +.byte 0x00 # -HasExtensionTable, -HasVectorInfo, NumOfGPRsSaved = 0 +.byte 0x00 # NumberOfFixedParms = 0 +.byte 0x01 # NumberOfFPParms = 0, +HasParmsOnStack +.vbyte 4, L..rust_psm_stack_direction_end-.rust_psm_stack_direction #Function size +.vbyte 2, 0x0018 # Function name len = 24 +.byte "rust_psm_stack_direction" # Function Name .globl rust_psm_stack_pointer[DS] .globl .rust_psm_stack_pointer @@ -79,9 +86,9 @@ L..rust_psm_replace_stack_end: .byte 0x40 .byte 0x80 .byte 0x00 -.byte 0x02 +.byte 0x03 .byte 0x01 -.vbyte 4, 0x00000000 +.vbyte 4, 0x00000000 # Parameter type = i, i, i .vbyte 4, L..rust_psm_replace_stack_end-.rust_psm_replace_stack .vbyte 2, 0x0016 .byte "rust_psm_replace_stack" @@ -95,7 +102,7 @@ L..rust_psm_replace_stack_end: .vbyte 8, 0 .csect .text[PR],2 .rust_psm_on_stack: -# extern "C" fn(3: usize, 4: extern "C" fn(usize), 5: *mut u8) +# extern "C" fn(3: usize, 4: usize, 5: extern "C" fn(usize, usize), 6: *mut u8) mflr 0 std 2, -72(6) std 0, -8(6) @@ -116,11 +123,12 @@ L..rust_psm_on_stack_end: .byte 0x00 .byte 0x09 .byte 0x20 -.byte 0x40 +.byte 0x41 .byte 0x80 .byte 0x00 -.byte 0x00 +.byte 0x04 .byte 0x01 +.vbyte 4, 0x00000000 # Parameter type = i, i, i, i .vbyte 4, L..rust_psm_on_stack_end-.rust_psm_on_stack .vbyte 2, 0x0011 .byte "rust_psm_on_stack" From 23fafc36d479f4c942eb6da0e575f2b0a6304334 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Fri, 16 Sep 2022 00:12:45 -0400 Subject: [PATCH 6/9] Add comments --- psm/src/arch/powerpc64_aix.s | 1 + 1 file changed, 1 insertion(+) diff --git a/psm/src/arch/powerpc64_aix.s b/psm/src/arch/powerpc64_aix.s index 18bd676..eed8660 100644 --- a/psm/src/arch/powerpc64_aix.s +++ b/psm/src/arch/powerpc64_aix.s @@ -72,6 +72,7 @@ L..rust_psm_stack_pointer_end: .csect .text[PR],2 .rust_psm_replace_stack: # extern "C" fn(3: usize, 4: extern "C" fn(usize), 5: *mut u8) + # Load the function pointer and toc pointer from TOC and make the call. ld 2, 8(4) ld 4, 0(4) addi 5, 5, -48 From b4b60dfe70959ad08cd64e3e93a6abc4fcb83cb7 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Fri, 16 Sep 2022 00:49:05 -0400 Subject: [PATCH 7/9] Updated README.mkd --- psm/README.mkd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/psm/README.mkd b/psm/README.mkd index b887c99..54bfaeb 100644 --- a/psm/README.mkd +++ b/psm/README.mkd @@ -289,7 +289,7 @@ compiler-generated code fails at similar points itself. -powerpc64 +powerpc64 linux Yes Yes @@ -302,6 +302,10 @@ Callstack generation may fail at certain well defined ranges of the program, alt compiler-generated code fails at similar points itself. +AIX +Yes +Yes +Unknown From e673b757f8426db3bb9845bc17eb27bdb807365c Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Fri, 16 Sep 2022 00:53:29 -0400 Subject: [PATCH 8/9] Updated README.mkd --- psm/README.mkd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/psm/README.mkd b/psm/README.mkd index 54bfaeb..0fb1ee2 100644 --- a/psm/README.mkd +++ b/psm/README.mkd @@ -302,12 +302,19 @@ Callstack generation may fail at certain well defined ranges of the program, alt compiler-generated code fails at similar points itself. + + + AIX Yes Yes Unknown + + + + powerpc64le linux From ef5bbd7b139b0f320056c4944003d693a052dc6e Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Fri, 16 Sep 2022 00:54:31 -0400 Subject: [PATCH 9/9] Remove newline --- psm/README.mkd | 1 - 1 file changed, 1 deletion(-) diff --git a/psm/README.mkd b/psm/README.mkd index 0fb1ee2..1b04a3c 100644 --- a/psm/README.mkd +++ b/psm/README.mkd @@ -314,7 +314,6 @@ compiler-generated code fails at similar points itself. - powerpc64le linux