Skip to content
Snippets Groups Projects
Commit 3fa2870c authored by Per's avatar Per
Browse files

Initinal commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #162 canceled
[target.mipsel-unknown-none]
rustflags = [
"-C", "link-arg=-Tlink.ld",
# "-C", "link-arg=-nostartfiles",
"-C", "relocation-model=static",
"-C", "inline-threshold=275",
"-C", "lto"
]
[build]
target = "mipsel-unknown-none"
\ No newline at end of file
/target
**/*.rs.bk
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "reverse"
version = "0.1.0"
[package]
name = "reverse"
version = "0.1.0"
authors = ["pln <Per Lindgren>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[profile.release]
#opt-level = 'z' # Optimize for size.
opt-level = 3 # Aggressive optimization
debug = true # keep debug symbols
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = 'abort' # Abort on panic
\ No newline at end of file
link.ld 0 → 100644
START_ADDR = 0x00000000;
MEMORY_SIZE = 0x80000000;
ASSERT(DEFINED(_start), "Cannot find entry point: fn _start() -> !");
ENTRY(_start);
SECTIONS
{
. = START_ADDR;
.text :
{
*(.init)
*(.text*)
}
.rodata :
{
*(.rodata*)
}
_gp = ALIGN(16);
.data :
{
*(.data*)
}
_BSS_START = .;
.bss :
{
*(.bss*)
}
_BSS_END = .;
.vectors ALIGN(0x1000) :
{
_VECTOR_START = .;
KEEP(*(.tlb_exception))
. = _VECTOR_START + 0x180;
KEEP(*(.exception))
}
_STACK_END = .;
_STACK_START = START_ADDR + MEMORY_SIZE;
}
\ No newline at end of file
START_ADDR = 0x00000000;
MEMORY_SIZE = 0x80000000;
ASSERT(DEFINED(_start), "Cannot find entry point: fn _start() -> !");
ENTRY(_start);
SECTIONS
{
. = START_ADDR;
.text :
{
*(.init)
*(.text*)
}
.rodata :
{
*(.rodata*)
}
_gp = ALIGN(16);
.data :
{
*(.data*)
}
_BSS_START = .;
.bss :
{
*(.bss*)
}
_BSS_END = .;
.vectors ALIGN(0x1000) :
{
_VECTOR_START = .;
KEEP(*(.tlb_exception))
. = _VECTOR_START + 0x180;
KEEP(*(.exception))
}
_STACK_END = .;
_STACK_START = START_ADDR + MEMORY_SIZE;
}
\ No newline at end of file
{
"llvm-target": "mipsel-unknown-none",
"arch": "mips",
"cpu": "mips32r3",
"data-layout": "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64",
"executables": true,
"features": "+mips32r3,+soft-float",
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"max-atomic-width": 32,
"os": "none",
"target-c-int-width": "32",
"target-endian": "little",
"target-pointer-width": "32"
}
\ No newline at end of file
target/mipsel-unknown-none/release/reverse: file format ELF32-mips
Disassembly of section .text:
00000000 _start:
; pub extern "C" fn _start() -> ! {
0: f0 ff bd 27 addiu $sp, $sp, -16
4: 0c 00 bf af sw $ra, 12($sp)
; rev(&FROM[..], &mut to);
8: 00 00 01 3c lui $1, 0
c: 00 00 a6 27 addiu $6, $sp, 0
10: 0b 00 05 24 addiu $5, $zero, 11
14: 0b 00 07 24 addiu $7, $zero, 11
; let mut to: [u8; SIZE] = [0; SIZE];
18: 0a 00 a0 ab swl $zero, 10($sp)
1c: 07 00 a0 bb swr $zero, 7($sp)
20: 04 00 a0 af sw $zero, 4($sp)
24: 00 00 a0 af sw $zero, 0($sp)
; rev(&FROM[..], &mut to);
28: 19 00 00 0c jal 100 <reverse.a07il72d-cgu.0+0x64>
2c: f8 00 24 24 addiu $4, $1, 248
; intrinsics::volatile_load(src)
30: 0a 00 a1 93 lbu $1, 10($sp)
34: 09 00 a1 93 lbu $1, 9($sp)
38: 08 00 a1 93 lbu $1, 8($sp)
3c: 07 00 a1 93 lbu $1, 7($sp)
40: 06 00 a1 93 lbu $1, 6($sp)
44: 05 00 a1 93 lbu $1, 5($sp)
48: 04 00 a1 93 lbu $1, 4($sp)
4c: 03 00 a1 93 lbu $1, 3($sp)
50: 02 00 a1 93 lbu $1, 2($sp)
54: 01 00 a1 93 lbu $1, 1($sp)
58: 00 00 a1 93 lbu $1, 0($sp)
; loop {}
5c: 17 00 00 08 j 92 <reverse.a07il72d-cgu.0+0x5c>
60: 00 00 00 00 nop
00000064 reverse::rev::h99451ae97e77db4d:
; }
64: 15 00 a0 10 beqz $5, 88 <reverse.a07il72d-cgu.0+0xbc>
; if len > 0 {
68: 00 00 00 00 nop
6c: f0 ff bd 27 addiu $sp, $sp, -16
70: 0c 00 bf af sw $ra, 12($sp)
74: 08 00 b2 af sw $18, 8($sp)
78: 04 00 b1 af sw $17, 4($sp)
7c: 00 00 b0 af sw $16, 0($sp)
; from_raw_parts(slice.as_ptr().add(self.start), self.end - self.start)
80: ff ff b2 24 addiu $18, $5, -1
84: 25 88 80 00 move $17, $4
; intrinsics::offset(self, count)
88: 01 00 84 24 addiu $4, $4, 1
8c: 25 80 c0 00 move $16, $6
; rev(&from[1..], &mut to[..len - 1]);
90: 25 28 40 02 move $5, $18
94: 19 00 00 0c jal 100 <reverse.a07il72d-cgu.0+0x64>
98: 25 38 40 02 move $7, $18
; to[len - 1] = from[0];
9c: 21 08 12 02 addu $1, $16, $18
a0: 00 00 22 92 lbu $2, 0($17)
a4: 00 00 b0 8f lw $16, 0($sp)
a8: 04 00 b1 8f lw $17, 4($sp)
ac: 08 00 b2 8f lw $18, 8($sp)
b0: 0c 00 bf 8f lw $ra, 12($sp)
b4: 00 00 22 a0 sb $2, 0($1)
b8: 10 00 bd 27 addiu $sp, $sp, 16
; }
bc: 08 00 e0 03 jr $ra
c0: 00 00 00 00 nop
use std::env;
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
fn main() {
// let target = env::var("TARGET").unwrap();
// let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
// has_fpu(&target);
// if target.starts_with("thumbv") {
// fs::copy(
// format!("bin/{}.a", target),
// out_dir.join("libcortex-m-rt.a"),
// )
// .unwrap();
// println!("cargo:rustc-link-lib=static=cortex-m-rt");
// }
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let link_x = include_bytes!("link.x.in");
let mut f = if env::var_os("CARGO_FEATURE_DEVICE").is_some() {
let mut f = File::create(out.join("link.x")).unwrap();
f.write_all(link_x).unwrap();
// *IMPORTANT*: The weak aliases (i.e. `PROVIDED`) must come *after* `EXTERN(__INTERRUPTS)`.
// Otherwise the linker will ignore user defined interrupts and always populate the table
// with the weak aliases.
// writeln!(
// f,
// r#"
// /* Provides weak aliases (cf. PROVIDED) for device specific interrupt handlers */
// /* This will usually be provided by a device crate generated using svd2rust (see `device.x`) */
// INCLUDE device.x"#
// )
// .unwrap();
// f
// } else {
// let mut f = File::create(out.join("link.x")).unwrap();
// f.write_all(link_x).unwrap();
// f
// };
}
// let max_int_handlers = if target.starts_with("thumbv6m-") {
// println!("cargo:rustc-cfg=cortex_m");
// println!("cargo:rustc-cfg=armv6m");
// 32
// } else if target.starts_with("thumbv7m-") || target.starts_with("thumbv7em-") {
// println!("cargo:rustc-cfg=cortex_m");
// println!("cargo:rustc-cfg=armv7m");
// 240
// } else if target.starts_with("thumbv8m") {
// println!("cargo:rustc-cfg=cortex_m");
// println!("cargo:rustc-cfg=armv8m");
// 240
// } else {
// // Non ARM target. We assume you're just testing the syntax.
// // This value seems as soon as any
// 240
// };
// // checking the size of the interrupts portion of the vector table is sub-architecture dependent
// writeln!(
// f,
// r#"
// ASSERT(SIZEOF(.vector_table) <= 0x{:x}, "
// There can't be more than {1} interrupt handlers. This may be a bug in
// your device crate, or you may have registered more than {1} interrupt
// handlers.");
// "#,
// max_int_handlers * 4 + 0x40,
// max_int_handlers
// )
// .unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=link.x.in");
}
// fn has_fpu(target: &str) {
// if target.ends_with("eabihf") {
// println!("cargo:rustc-cfg=has_fpu");
// }
// }
// #![feature(const_generics)]
// fn rev<const X: usize>(from: &[u8; X], to: &mut [u8; X]) {
// if from.len() > 0 {}
// }
#![feature(lang_items)]
#![no_std]
#![no_main]
// use panic_abort;
// use libc;
fn rev(from: &[u8], to: &mut [u8]) {
let len = from.len();
if len > 0 {
rev(&from[1..], &mut to[..len - 1]);
to[len - 1] = from[0];
}
}
const FROM: &[u8] = b"Hello Word!";
const SIZE: usize = FROM.len();
#[no_mangle]
pub extern "C" fn main() {
let mut to: [u8; SIZE] = [0; SIZE];
rev(&FROM[..], &mut to);
unsafe {
core::ptr::read_volatile(&to);
}
// println!("from : {:?}", std::str::from_utf8(FROM).unwrap());
// println!("to : {:?}", std::str::from_utf8(&to).unwrap());
}
#[panic_handler]
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
// The reset vector, a pointer into the reset handler
#[link_section = ".init"]
#[no_mangle]
pub extern "C" fn _start() -> ! {
main();
loop {}
}
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
// #[lang = "panic_fmt"]
// extern "C" fn panic_fmt() -> ! {
// loop {}
// }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment