-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial bringup for Linux/Thumb2 #8683
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2015-2021 Zig Contributors | ||
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. | ||
// The MIT license requires this copyright notice to be included in all copies | ||
// and substantial portions of the software. | ||
usingnamespace @import("../bits.zig"); | ||
|
||
// The syscall interface is identical to the ARM one but we're facing an extra | ||
// challenge: r7, the register where the syscall number is stored, may be | ||
// reserved for the frame pointer. | ||
// Save and restore r7 around the syscall without touching the stack pointer not | ||
// to break the frame chain. | ||
|
||
pub fn syscall0(number: SYS) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r1}" (buf) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall1(number: SYS, arg1: usize) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r1}" (buf), | ||
[arg1] "{r0}" (arg1) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r2}" (buf), | ||
[arg1] "{r0}" (arg1), | ||
[arg2] "{r1}" (arg2) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r3}" (buf), | ||
[arg1] "{r0}" (arg1), | ||
[arg2] "{r1}" (arg2), | ||
[arg3] "{r2}" (arg3) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r4}" (buf), | ||
[arg1] "{r0}" (arg1), | ||
[arg2] "{r1}" (arg2), | ||
[arg3] "{r2}" (arg3), | ||
[arg4] "{r3}" (arg4) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r5}" (buf), | ||
[arg1] "{r0}" (arg1), | ||
[arg2] "{r1}" (arg2), | ||
[arg3] "{r2}" (arg3), | ||
[arg4] "{r3}" (arg4), | ||
[arg5] "{r4}" (arg5) | ||
: "memory" | ||
); | ||
} | ||
|
||
pub fn syscall6( | ||
number: SYS, | ||
arg1: usize, | ||
arg2: usize, | ||
arg3: usize, | ||
arg4: usize, | ||
arg5: usize, | ||
arg6: usize, | ||
) usize { | ||
@setRuntimeSafety(false); | ||
|
||
var buf: [2]usize = .{ @enumToInt(number), undefined }; | ||
return asm volatile ( | ||
\\ str r7, [%[tmp], #4] | ||
\\ ldr r7, [%[tmp]] | ||
\\ svc #0 | ||
\\ ldr r7, [%[tmp], #4] | ||
: [ret] "={r0}" (-> usize) | ||
: [tmp] "{r6}" (buf), | ||
[arg1] "{r0}" (arg1), | ||
[arg2] "{r1}" (arg2), | ||
[arg3] "{r2}" (arg3), | ||
[arg4] "{r3}" (arg4), | ||
[arg5] "{r4}" (arg5), | ||
[arg6] "{r5}" (arg6) | ||
: "memory" | ||
); | ||
} | ||
|
||
/// This matches the libc clone function. | ||
pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; | ||
|
||
pub fn restore() callconv(.Naked) void { | ||
return asm volatile ( | ||
\\ mov r7, %[number] | ||
\\ svc #0 | ||
: | ||
: [number] "I" (@enumToInt(SYS.sigreturn)) | ||
); | ||
} | ||
|
||
pub fn restore_rt() callconv(.Naked) void { | ||
return asm volatile ( | ||
\\ mov r7, %[number] | ||
\\ svc #0 | ||
: | ||
: [number] "I" (@enumToInt(SYS.rt_sigreturn)) | ||
: "memory" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fundamental problem here is that we have multiple different ways of representing the same state.
Let's try to eliminate redundancies. Here are some (breaking) ideas:
thumb_mode
CPU feature. Instead of-target thumb-linux
it would be-target arm-linux -mcpu=generic+v7m
noarm
CPU feature since it appears to be completely redundant withthumb_mode
. All feature sets that includethumb_mode
also includenoarm
.noarm
when lowering thumb_mode cpu features to LLVMAfter a few minutes considering this I think I would be in favor of both these ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The former makes more sense,
noarm
is effectively a CPU feature that signals no interworking is possible at all.Clang takes a similar approach and requires
-mthumb
or-mno-thumb
to be specified, that's another possible solution to take into account.