Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: Run
strategy:
matrix:
target: [x86_64, aarch64, riscv64]
target: [x86_64, aarch64, aarch64_be, riscv64]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- target: x86_64
Expand Down Expand Up @@ -83,8 +83,11 @@ jobs:
- uses: actions/checkout@v5
with:
lfs: true
- name: Install stable Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.target == 'aarch64_be' && 'nightly' || 'stable' }}
components: ${{ matrix.target == 'aarch64_be' && 'rust-src' || '' }}
- name: Dowload OpenSBI
if: matrix.target == 'riscv64'
run: |
Expand Down
3 changes: 3 additions & 0 deletions data/aarch64_be/hello_world
Git LFS file not shown
10 changes: 7 additions & 3 deletions src/arch/aarch64/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ unsafe fn pre_init() -> ! {
or if loading and not setting them would be the appropriate action.
*/

#[cfg(target_endian = "big")]
let endian = SCTLR_EL1::EE::BigEndian + SCTLR_EL1::E0E::BigEndian;
#[cfg(target_endian = "little")]
let endian = SCTLR_EL1::EE::LittleEndian + SCTLR_EL1::E0E::LittleEndian;

SCTLR_EL1.write(
SCTLR_EL1::UCI::DontTrap
+ SCTLR_EL1::EE::LittleEndian
+ SCTLR_EL1::E0E::LittleEndian
+ SCTLR_EL1::WXN::Disable
+ SCTLR_EL1::NTWE::DontTrap
+ SCTLR_EL1::NTWI::DontTrap
Expand All @@ -181,7 +184,8 @@ unsafe fn pre_init() -> ! {
+ SCTLR_EL1::SA::Enable
+ SCTLR_EL1::C::Cacheable
+ SCTLR_EL1::A::Disable
+ SCTLR_EL1::M::Disable,
+ SCTLR_EL1::M::Disable
+ endian,
);

// Enter loader
Expand Down
2 changes: 0 additions & 2 deletions src/arch/aarch64/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/master/16_virtual_mem_part4_higher_half_kernel/src/bsp/raspberrypi/link.ld
*/

OUTPUT_FORMAT("elf64-littleaarch64")
OUTPUT_ARCH("aarch64")
Comment on lines -5 to -6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work, but do you happen to have any knowledge on where the default value comes from and what it is now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't, but I imagine the linker is well aware of the architecture it is linking for and therefore doesn't need this explicit hint

ENTRY(_start)
phys = 0x40200000;

Expand Down
10 changes: 5 additions & 5 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl Qemu {
}

let target = self.build.target();
let arch = target.arch();
let qemu = env::var("QEMU").unwrap_or_else(|_| format!("qemu-system-{arch}"));
let qemu = target.qemu();
let qemu = env::var("QEMU").unwrap_or_else(|_| format!("qemu-system-{qemu}"));
let program = if self.sudo { "sudo" } else { qemu.as_str() };
let arg = self.sudo.then_some(qemu.as_str());

Expand Down Expand Up @@ -96,7 +96,7 @@ impl Qemu {
"-append".to_string(),
format!("-freq {frequency}"),
]
} else if self.build.target() == Target::Aarch64 {
} else if matches!(self.build.target(), Target::Aarch64 | Target::Aarch64Be) {
vec!["-machine".to_string(), "virt,gic-version=3".to_string()]
} else if self.build.target() == Target::Riscv64 {
vec![
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Qemu {
cpu_args
}
Target::X86_64Fc => panic!("unsupported"),
Target::Aarch64 => {
Target::Aarch64 | Target::Aarch64Be => {
let mut cpu_args = if self.accel {
todo!()
} else {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl Qemu {
Target::X86_64Uefi => {
memory = memory.max(512);
}
Target::Aarch64 => {
Target::Aarch64 | Target::Aarch64Be => {
memory = memory.max(256);
}
Target::Riscv64 => {
Expand Down
32 changes: 29 additions & 3 deletions xtask/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ pub enum Target {
X86_64Fc,
X86_64Uefi,
Aarch64,
Aarch64Be,
Riscv64,
}

impl Target {
pub fn install(&self) -> xshell::Result<()> {
let sh = Shell::new()?;

let triple = self.triple();
cmd!(sh, "rustup target add {triple}").run()?;
if self.tier() <= 2 {
let triple = self.triple();
cmd!(sh, "rustup target add {triple}").run()?;
}

if self == &Self::X86_64 {
cmd!(sh, "rustup component add llvm-tools-preview").run()?;
Expand All @@ -32,6 +35,7 @@ impl Target {
Self::X86_64Fc => "x86_64",
Self::X86_64Uefi => "x86_64",
Self::Aarch64 => "aarch64",
Self::Aarch64Be => "aarch64_be",
Self::Riscv64 => "riscv64",
}
}
Expand All @@ -42,16 +46,28 @@ impl Target {
Self::X86_64Fc => "x86_64-unknown-none",
Self::X86_64Uefi => "x86_64-unknown-uefi",
Self::Aarch64 => "aarch64-unknown-none-softfloat",
Self::Aarch64Be => "aarch64_be-unknown-none-softfloat",
Self::Riscv64 => "riscv64imac-unknown-none-elf",
}
}

pub fn tier(&self) -> u8 {
match self {
Self::Aarch64Be => 3,
_ => 2,
}
}

pub fn cargo_args(&self) -> &'static [&'static str] {
match self {
Self::X86_64 => &["--target=x86_64-unknown-none"],
Self::X86_64Fc => &["--target=x86_64-unknown-none"],
Self::X86_64Uefi => &["--target=x86_64-unknown-uefi"],
Self::Aarch64 => &["--target=aarch64-unknown-none-softfloat"],
Self::Aarch64Be => &[
"--target=aarch64_be-unknown-none-softfloat",
"-Zbuild-std=core,alloc,panic_abort",
],
Self::Riscv64 => &["--target=riscv64imac-unknown-none-elf"],
}
}
Expand All @@ -67,7 +83,7 @@ impl Target {
"-Crelocation-model=static",
],
Self::X86_64Uefi => &[],
Self::Aarch64 => &["-Clink-arg=-Tsrc/arch/aarch64/link.ld"],
Self::Aarch64 | Self::Aarch64Be => &["-Clink-arg=-Tsrc/arch/aarch64/link.ld"],
Self::Riscv64 => &["-Clink-arg=-Tsrc/arch/riscv64/link.ld"],
}
}
Expand All @@ -92,9 +108,18 @@ impl Target {
Self::X86_64Fc => "hermit-loader-x86_64-fc",
Self::X86_64Uefi => "hermit-loader-x86_64.efi",
Self::Aarch64 => "hermit-loader-aarch64",
Self::Aarch64Be => "hermit-loader-aarch64_be",
Self::Riscv64 => "hermit-loader-riscv64",
}
}

pub fn qemu(&self) -> &'static str {
match self {
Self::X86_64 | Self::X86_64Fc | Self::X86_64Uefi => "x86_64",
Self::Aarch64 | Self::Aarch64Be => "aarch64",
Self::Riscv64 => "riscv64",
}
}
}

impl FromStr for Target {
Expand All @@ -106,6 +131,7 @@ impl FromStr for Target {
"x86_64-fc" => Ok(Self::X86_64Fc),
"x86_64-uefi" => Ok(Self::X86_64Uefi),
"aarch64" => Ok(Self::Aarch64),
"aarch64_be" => Ok(Self::Aarch64Be),
"riscv64" => Ok(Self::Riscv64),
s => Err(anyhow!("Unsupported target: {s}")),
}
Expand Down
Loading