Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rust-mips3k
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
rust-mips3k
Commits
9d9f5ca9
Commit
9d9f5ca9
authored
5 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
Init sections added
parent
c39ec435
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#164
canceled
5 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/reverse.rs
+3
-1
3 additions, 1 deletion
examples/reverse.rs
link.ld
+9
-2
9 additions, 2 deletions
link.ld
src/lib.rs
+71
-6
71 additions, 6 deletions
src/lib.rs
with
83 additions
and
9 deletions
examples/reverse.rs
+
3
−
1
View file @
9d9f5ca9
...
@@ -20,10 +20,12 @@ const FROM: &[u8] = b"Hello Word!";
...
@@ -20,10 +20,12 @@ const FROM: &[u8] = b"Hello Word!";
const
SIZE
:
usize
=
FROM
.len
();
const
SIZE
:
usize
=
FROM
.len
();
#[no_mangle]
#[no_mangle]
fn
main
()
{
fn
main
()
->
!
{
let
mut
to
:
[
u8
;
SIZE
]
=
[
0
;
SIZE
];
let
mut
to
:
[
u8
;
SIZE
]
=
[
0
;
SIZE
];
rev
(
&
FROM
[
..
],
&
mut
to
);
rev
(
&
FROM
[
..
],
&
mut
to
);
unsafe
{
unsafe
{
core
::
ptr
::
read_volatile
(
&
to
);
core
::
ptr
::
read_volatile
(
&
to
);
}
}
loop
{}
}
}
This diff is collapsed.
Click to expand it.
link.ld
+
9
−
2
View file @
9d9f5ca9
...
@@ -22,13 +22,20 @@ SECTIONS
...
@@ -22,13 +22,20 @@ SECTIONS
.data :
.data :
{
{
*(.data*)
__sdata = .;
*(.data*);
__edata = .;
}
}
/* LMA of .data */
__sidata = LOADADDR(.data);
_BSS_START = .;
_BSS_START = .;
.bss :
.bss :
{
{
*(.bss*)
__sbss = .;
*(.bss*);
__ebss = .;
}
}
_BSS_END = .;
_BSS_END = .;
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
71
−
6
View file @
9d9f5ca9
#![feature(lang_items)]
#![feature(lang_items)]
#![no_std]
#![no_std]
#![no_main]
use
core
::{
mem
,
ptr
,
slice
};
#[panic_handler]
#[panic_handler]
fn
my_panic
(
_info
:
&
core
::
panic
::
PanicInfo
)
->
!
{
fn
my_panic
(
_info
:
&
core
::
panic
::
PanicInfo
)
->
!
{
loop
{}
loop
{}
}
}
/// Initializes the `.data` section
///
/// # Arguments
///
/// - `sdata`. Pointer to the start of the `.data` section.
/// - `edata`. Pointer to the open/non-inclusive end of the `.data` section.
/// (The value behind this pointer will not be modified)
/// - `sidata`. `.data` section Load Memory Address (LMA)
/// - Use `T` to indicate the alignment of the `.data` section and its LMA.
///
/// # Safety
///
/// - Must be called exactly once
/// - `mem::size_of::<T>()` must be non-zero
/// - `edata >= sdata`
/// - The `sdata -> edata` region must not overlap with the `sidata -> ...`
/// region
/// - `sdata`, `edata` and `sidata` must be `T` aligned.
pub
unsafe
fn
init_data
<
T
>
(
mut
sdata
:
*
mut
T
,
edata
:
*
mut
T
,
mut
sidata
:
*
const
T
)
where
T
:
Copy
,
{
while
sdata
<
edata
{
ptr
::
write
(
sdata
,
ptr
::
read
(
sidata
));
sdata
=
sdata
.offset
(
1
);
sidata
=
sidata
.offset
(
1
);
}
}
pub
unsafe
fn
run_init_array
(
init_array_start
:
&
extern
"C"
fn
(),
init_array_end
:
&
extern
"C"
fn
())
{
let
n
=
(
init_array_end
as
*
const
_
as
usize
-
init_array_start
as
*
const
_
as
usize
)
/
mem
::
size_of
::
<
extern
"C"
fn
()
>
();
for
f
in
slice
::
from_raw_parts
(
init_array_start
,
n
)
{
f
();
}
}
/// Zeroes the `.bss` section
///
/// # Arguments
///
/// - `sbss`. Pointer to the start of the `.bss` section.
/// - `ebss`. Pointer to the open/non-inclusive end of the `.bss` section.
/// (The value behind this pointer will not be modified)
/// - Use `T` to indicate the alignment of the `.bss` section.
///
/// # Safety
///
/// - Must be called exactly once
/// - `mem::size_of::<T>()` must be non-zero
/// - `ebss >= sbss`
/// - `sbss` and `ebss` must be `T` aligned.
pub
unsafe
fn
zero_bss
<
T
>
(
mut
sbss
:
*
mut
T
,
ebss
:
*
mut
T
)
where
T
:
Copy
,
{
while
sbss
<
ebss
{
// NOTE(volatile) to prevent this from being transformed into `memclr`
ptr
::
write_volatile
(
sbss
,
mem
::
zeroed
());
sbss
=
sbss
.offset
(
1
);
}
}
// The reset vector, a pointer into the reset handler
// The reset vector, a pointer into the reset handler
#[link_section
=
".init"
]
#[link_section
=
".init"
]
#[no_mangle]
#[no_mangle]
...
@@ -28,11 +93,11 @@ pub extern "C" fn _start() -> ! {
...
@@ -28,11 +93,11 @@ pub extern "C" fn _start() -> ! {
}
}
// Initialize RAM
// Initialize RAM
// r0::zero_bss(&mut __sbss, &mut __ebss);
unsafe
{
// r0::init_data
(&mut __s
data
, &mut __e
data, &__sidata
);
zero_bss
(
&
mut
__s
bss
,
&
mut
__e
bss
);
init_data
(
&
mut
__sdata
,
&
mut
__edata
,
&
__sidata
);
unsafe
{
main
()
}
unsafe
{
main
()
}
loop
{
}
}
}
}
#[lang
=
"eh_personality"
]
#[lang
=
"eh_personality"
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment