Skip to content

Commit

Permalink
为 user 部分添加 LinkerScript 手动为不同字段进行对齐 chyyuu#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuyixiang committed Jun 28, 2020
1 parent 1d448a5 commit 4a3ee10
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions os/src/memory/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ use super::config::{KERNEL_MAP_OFFSET, PAGE_SIZE};
use bit_field::BitField;

/// 虚拟地址
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct VirtualAddress(pub usize);

/// 物理地址
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct PhysicalAddress(pub usize);

/// 虚拟页号
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct VirtualPageNumber(pub usize);

/// 物理页号
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct PhysicalPageNumber(pub usize);

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2020-04-23
nightly-2020-06-27
8 changes: 7 additions & 1 deletion user/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 编译的目标平台
[build]
target = "riscv64imac-unknown-none-elf"
target = "riscv64imac-unknown-none-elf"

# 使用我们的 linker script 来进行链接
[target.riscv64imac-unknown-none-elf]
rustflags = [
"-C", "link-arg=-Tsrc/linker/linker.ld",
]
33 changes: 33 additions & 0 deletions user/src/linker/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Linker Script 语法可以参见:http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html */

/* 目标架构 */
OUTPUT_ARCH(riscv)

/* 执行入口 */
ENTRY(_start)

/* 数据存放起始地址 */
BASE_ADDRESS = 0x10000;

SECTIONS
{
/* .text 字段 */
.text : ALIGN(4K) {
*(.text)
}

/* .rodata 字段 */
.rodata : ALIGN(4K) {
*(.rodata)
}

/* .data 字段 */
.data : ALIGN(4K) {
*(.data)
}

/* .bss 字段 */
.bss : ALIGN(4K) {
*(.sbss .bss)
}
}

0 comments on commit 4a3ee10

Please sign in to comment.