blob: b0a5173e7a13060a5aec42f5be69847f0478106b [file] [log] [blame]
Pierre-Clément Tosi9a658f72022-10-10 15:18:54 +01001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Memory layout.
16
17use crate::linker;
18use core::ops::Range;
19use core::ptr::addr_of;
20
21/// Memory reserved for the DTB.
22pub fn dtb_range() -> Range<usize> {
23 unsafe { (addr_of!(linker::dtb_begin) as usize)..(addr_of!(linker::dtb_end) as usize) }
24}
25
26/// Executable code.
27pub fn text_range() -> Range<usize> {
28 unsafe { (addr_of!(linker::text_begin) as usize)..(addr_of!(linker::text_end) as usize) }
29}
30
31/// Read-only data.
32pub fn rodata_range() -> Range<usize> {
33 unsafe { (addr_of!(linker::rodata_begin) as usize)..(addr_of!(linker::rodata_end) as usize) }
34}
35
36/// Initialised writable data.
37pub fn data_range() -> Range<usize> {
38 unsafe { (addr_of!(linker::data_begin) as usize)..(addr_of!(linker::data_end) as usize) }
39}
40
41/// Zero-initialised writable data.
42pub fn bss_range() -> Range<usize> {
43 unsafe { (addr_of!(linker::bss_begin) as usize)..(addr_of!(linker::bss_end) as usize) }
44}
45
46/// Writable data region for the stack.
47pub fn boot_stack_range() -> Range<usize> {
48 unsafe {
49 (addr_of!(linker::boot_stack_begin) as usize)..(addr_of!(linker::boot_stack_end) as usize)
50 }
51}
52
53/// Writable data, including the stack.
54pub fn writable_region() -> Range<usize> {
55 data_range().start..boot_stack_range().end
56}
57
58/// Read-write data (original).
59pub fn data_load_address() -> usize {
60 unsafe { addr_of!(linker::data_lma) as usize }
61}
62
63/// End of the binary image.
64pub fn binary_end() -> usize {
65 unsafe { addr_of!(linker::bin_end) as usize }
66}