Skip to content

Commit aaec1be

Browse files
committed
Initial aarch64_msvc support, untested
1 parent ed59c3b commit aaec1be

File tree

8 files changed

+208
-1
lines changed

8 files changed

+208
-1
lines changed

lib/win_arm64/stackman.lib

6.03 KB
Binary file not shown.

src/platforms/platform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include "switch_arm_msvc.h" /* MS Visual Studio on ARM */
4242
#define _STACKMAN_PLATFORM arm_msvc
4343
#define _STACKMAN_ABI win_arm
44+
#elif defined(_M_ARM64)
45+
#include "switch_arm64_msvc.h" /* MS Visual Studio on ARM */
46+
#define _STACKMAN_PLATFORM arm64_msvc
47+
#define _STACKMAN_ABI win_aarch64
4448
#endif
4549

4650

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
3+
; this code is adopted from the switch_aarch64_gcc.S
4+
; which again was generated from switch_arm_gcc.h
5+
; This code is also modelled on the hand-customized switch_arm_msvc.asm
6+
; see https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160
7+
8+
;ARM64
9+
10+
EXPORT |stackman_switch|
11+
ALIGN
12+
|stackman_switch| PROC
13+
; args "callback", "context" are in x0, x1
14+
; push non-volatile x18-x28 registers, in addition to fp,rl pair.
15+
; x29 is fp, x30 is lr.
16+
stp x29, x30, [sp, -176]! ; store fp,lr pair, allocate stack space
17+
mov x29, sp ; and set fp pointing to old fp on stack
18+
; push non-volatile registers 18-x28 and fp regs d8-d15)
19+
; also fpcr (fp control register)
20+
mrs x2,fpcr
21+
stp x2, x18, [sp, 16]
22+
stp x19, x20, [sp, 32]
23+
stp x21, x22, [sp, 48]
24+
stp x23, x24, [sp, 64]
25+
stp x25, x26, [sp, 80]
26+
stp x27, x28, [sp, 96]
27+
stp d8, d9, [sp, 112]
28+
stp d10, d11, [sp, 128]
29+
stp d12, d13, [sp, 144]
30+
stp d14, d15, [sp, 160]
31+
32+
; args are x0=callback, x1=context
33+
; shuffle calling arguments into r0, r1 and r2
34+
; for the call to the callback.
35+
mov x3, x0
36+
mov x0, x1 ;context
37+
mov x2, sp ;stack pointer
38+
mov x1, #0 ;operation
39+
mov x19, x0 ;store these a bit in nv registers
40+
mov x18, x3
41+
blr x3 ;first callback
42+
mov x2, x0 ;store new stackpointer in register, for next cb,
43+
; switch stack, maintaining fp offset
44+
sub x1, sp, x0
45+
mov sp, x0 ;switch stack pointer
46+
sub fp, fp, x1
47+
48+
mov x1, #1 ;operation
49+
mov x0, x19 ;context
50+
blr x18 ;second callback
51+
52+
; restore registers from stack
53+
ldp x2, x18, [sp, 16]
54+
ldp x19, x20, [sp, 32]
55+
ldp x21, x22, [sp, 48]
56+
ldp x23, x24, [sp, 64]
57+
ldp x25, x26, [sp, 80]
58+
ldp x27, x28, [sp, 96]
59+
ldp d8, d9, [sp, 112]
60+
ldp d10, d11, [sp, 128]
61+
ldp d12, d13, [sp, 144]
62+
ldp d14, d15, [sp, 160]
63+
msr fpcr,x2
64+
;return
65+
ldp x29, x30, [sp], 176
66+
ret
67+
ENDP
68+
69+
EXPORT |stackman_call|
70+
ALIGN
71+
|stackman_call| PROC
72+
; args "callback", "context" are in x0, x1
73+
; push non-volatile x18-x28 registers, in addition to fp,rl pair.
74+
; x29 is fp, x30 is lr.
75+
stp x29, x30, [sp, -32]! ; store fp,lr pair, allocate stack space
76+
mov x29, sp ; and set fp pointing to old fp on stack
77+
; push non-volatile register 18
78+
str x18, [sp, 16]
79+
80+
; args are x0 = callback, x1 = context, x2=stack
81+
mov x3, x0
82+
mov x0, x1 ;context
83+
mov x1, x2 ;stack
84+
; store current sp in nv register
85+
mov x18, sp
86+
mov x2, sp ; new stack
87+
88+
; change stack
89+
mov sp, x1
90+
mov x1, #2 ; callback opcode
91+
blr x3 ; call callback, with context, opcode, new stack
92+
93+
; restore stack (could do: sub sp, fp #12)
94+
mov sp, x18
95+
96+
; return
97+
ldr x18, [sp, 16]
98+
ldp x29, x30, [sp], 32
99+
ret
100+
ENDP
101+
102+
END

src/platforms/switch_arm64_msvc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* The actual stack saving function, which just stores the stack,
2+
* this declared in an .asm file
3+
*/
4+
#ifndef STACKMAN_ASSEMBLY_SRC
5+
#define STACKMAN_ASSEMBLY_SRC switch_arm64_msvc.asm
6+
#define STACKMAN_HAVE_CALL 1
7+
#define STACKMAN_STACK_ALIGN 16
8+
#endif

vs2019/stackman.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ EndProject
1313
Global
1414
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1515
Debug|ARM = Debug|ARM
16+
Debug|ARM64 = Debug|ARM64
1617
Debug|x64 = Debug|x64
1718
Debug|x86 = Debug|x86
1819
EndGlobalSection
1920
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2021
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.ActiveCfg = Debug|ARM
2122
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.Build.0 = Debug|ARM
23+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.ActiveCfg = Debug|ARM64
24+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.Build.0 = Debug|ARM64
2225
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.ActiveCfg = Debug|x64
2326
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.Build.0 = Debug|x64
2427
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.ActiveCfg = Debug|Win32
2528
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.Build.0 = Debug|Win32
2629
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.ActiveCfg = Debug|ARM
2730
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.Build.0 = Debug|ARM
31+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.ActiveCfg = Debug|ARM64
32+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.Build.0 = Debug|ARM64
2833
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.ActiveCfg = Debug|x64
2934
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.Build.0 = Debug|x64
3035
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x86.ActiveCfg = Debug|Win32

vs2019/stackman/stackman.vcxproj

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<Configuration>Debug</Configuration>
66
<Platform>ARM</Platform>
77
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|ARM64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>ARM64</Platform>
11+
</ProjectConfiguration>
812
<ProjectConfiguration Include="Debug|Win32">
913
<Configuration>Debug</Configuration>
1014
<Platform>Win32</Platform>
@@ -41,6 +45,12 @@
4145
<PlatformToolset>v142</PlatformToolset>
4246
<CharacterSet>Unicode</CharacterSet>
4347
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
49+
<ConfigurationType>StaticLibrary</ConfigurationType>
50+
<UseDebugLibraries>true</UseDebugLibraries>
51+
<PlatformToolset>v142</PlatformToolset>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
4454
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
4555
<ImportGroup Label="ExtensionSettings">
4656
<Import Project="$(VCTargetsPath)\BuildCustomizations\marmasm.props" />
@@ -57,6 +67,9 @@
5767
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="PropertySheets">
5868
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
5969
</ImportGroup>
70+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
6073
<PropertyGroup Label="UserMacros" />
6174
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
6275
<LinkIncremental>true</LinkIncremental>
@@ -71,6 +84,10 @@
7184
<LinkIncremental>true</LinkIncremental>
7285
<OutDir>$(SolutionDir)\..\lib\win_arm\</OutDir>
7386
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
88+
<LinkIncremental>true</LinkIncremental>
89+
<OutDir>$(SolutionDir)\..\lib\win_arm64\</OutDir>
90+
</PropertyGroup>
7491
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7592
<ClCompile>
7693
<WarningLevel>Level3</WarningLevel>
@@ -128,8 +145,28 @@
128145
<AdditionalOptions>/Brepro %(AdditionalOptions)</AdditionalOptions>
129146
</Lib>
130147
</ItemDefinitionGroup>
148+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
149+
<ClCompile>
150+
<WarningLevel>Level3</WarningLevel>
151+
<SDLCheck>true</SDLCheck>
152+
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
153+
<ConformanceMode>true</ConformanceMode>
154+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
155+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
156+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
157+
</ClCompile>
158+
<Link>
159+
<SubSystem>
160+
</SubSystem>
161+
<GenerateDebugInformation>true</GenerateDebugInformation>
162+
</Link>
163+
<Lib>
164+
<AdditionalOptions>/Brepro %(AdditionalOptions)</AdditionalOptions>
165+
</Lib>
166+
</ItemDefinitionGroup>
131167
<ItemGroup>
132168
<ClInclude Include="..\..\src\platforms\platform.h" />
169+
<ClInclude Include="..\..\src\platforms\switch_arm64_msvc.h" />
133170
<ClInclude Include="..\..\src\platforms\switch_arm_msvc.h" />
134171
<ClInclude Include="..\..\src\platforms\switch_x64_msvc.h" />
135172
<ClInclude Include="..\..\src\platforms\switch_x86_msvc.h" />
@@ -142,26 +179,40 @@
142179
<ClCompile Include="template.c">
143180
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AssemblyCode</AssemblerOutput>
144181
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">AssemblyCode</AssemblerOutput>
182+
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">AssemblyCode</AssemblerOutput>
145183
<SupportJustMyCode Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</SupportJustMyCode>
146184
<SupportJustMyCode Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</SupportJustMyCode>
185+
<SupportJustMyCode Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</SupportJustMyCode>
147186
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Default</BasicRuntimeChecks>
148187
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Default</BasicRuntimeChecks>
188+
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Default</BasicRuntimeChecks>
149189
<OmitFramePointers Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</OmitFramePointers>
150190
<OmitFramePointers Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</OmitFramePointers>
191+
<OmitFramePointers Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</OmitFramePointers>
151192
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
152193
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
194+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
153195
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
154196
</ClCompile>
155197
</ItemGroup>
156198
<ItemGroup>
157-
<MARMASM Include="..\..\src\platforms\switch_arm_msvc.asm" />
199+
<MARMASM Include="..\..\src\platforms\switch_arm_msvc.asm">
200+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild>
201+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
202+
</MARMASM>
203+
<MARMASM Include="..\..\src\platforms\switch_arm64_msvc.asm">
204+
<FileType>Document</FileType>
205+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
206+
</MARMASM>
158207
<MASM Include="..\..\src\platforms\switch_x64_msvc.asm">
159208
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
160209
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
210+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
161211
</MASM>
162212
<MASM Include="..\..\src\platforms\switch_x86_msvc.asm">
163213
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
164214
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
215+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
165216
</MASM>
166217
</ItemGroup>
167218
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

vs2019/stackman/stackman.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<ClInclude Include="..\..\src\platforms\switch_arm_msvc.h">
3737
<Filter>Header Files</Filter>
3838
</ClInclude>
39+
<ClInclude Include="..\..\src\platforms\switch_arm64_msvc.h">
40+
<Filter>Header Files</Filter>
41+
</ClInclude>
3942
</ItemGroup>
4043
<ItemGroup>
4144
<ClCompile Include="..\..\src\stackman.c">
@@ -57,5 +60,8 @@
5760
<MARMASM Include="..\..\src\platforms\switch_arm_msvc.asm">
5861
<Filter>Source Files</Filter>
5962
</MARMASM>
63+
<MARMASM Include="..\..\src\platforms\switch_arm64_msvc.asm">
64+
<Filter>Source Files</Filter>
65+
</MARMASM>
6066
</ItemGroup>
6167
</Project>

vs2019/test/test.vcxproj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<Configuration>Debug</Configuration>
66
<Platform>ARM</Platform>
77
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|ARM64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>ARM64</Platform>
11+
</ProjectConfiguration>
812
<ProjectConfiguration Include="Debug|Win32">
913
<Configuration>Debug</Configuration>
1014
<Platform>Win32</Platform>
@@ -40,6 +44,12 @@
4044
<PlatformToolset>v142</PlatformToolset>
4145
<CharacterSet>Unicode</CharacterSet>
4246
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>true</UseDebugLibraries>
50+
<PlatformToolset>v142</PlatformToolset>
51+
<CharacterSet>Unicode</CharacterSet>
52+
</PropertyGroup>
4353
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
4454
<ImportGroup Label="ExtensionSettings">
4555
</ImportGroup>
@@ -54,6 +64,9 @@
5464
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="PropertySheets">
5565
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
5666
</ImportGroup>
67+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
5770
<PropertyGroup Label="UserMacros" />
5871
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
5972
<LinkIncremental>true</LinkIncremental>
@@ -66,6 +79,9 @@
6679
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
6780
<LinkIncremental>true</LinkIncremental>
6881
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
83+
<LinkIncremental>true</LinkIncremental>
84+
</PropertyGroup>
6985
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7086
<ClCompile>
7187
<WarningLevel>Level3</WarningLevel>
@@ -112,6 +128,21 @@
112128
<AdditionalLibraryDirectories>..\..\lib\win_arm;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
113129
</Link>
114130
</ItemDefinitionGroup>
131+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
132+
<ClCompile>
133+
<WarningLevel>Level3</WarningLevel>
134+
<SDLCheck>true</SDLCheck>
135+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
136+
<ConformanceMode>true</ConformanceMode>
137+
<AdditionalIncludeDirectories>..\..\src</AdditionalIncludeDirectories>
138+
</ClCompile>
139+
<Link>
140+
<SubSystem>Console</SubSystem>
141+
<GenerateDebugInformation>true</GenerateDebugInformation>
142+
<AdditionalDependencies>stackman.lib;%(AdditionalDependencies)</AdditionalDependencies>
143+
<AdditionalLibraryDirectories>..\..\lib\win_arm64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
144+
</Link>
145+
</ItemDefinitionGroup>
115146
<ItemGroup>
116147
<ClCompile Include="..\..\tests\test.c" />
117148
</ItemGroup>

0 commit comments

Comments
 (0)