Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
2d3ae920
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d3ae920
编写于
2月 21, 2020
作者:
B
bigmagic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
space instead of table keep the code style
上级
0458f0b7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
48 deletion
+48
-48
libcpu/aarch64/cortex-a53/mmu.c
libcpu/aarch64/cortex-a53/mmu.c
+48
-48
未找到文件。
libcpu/aarch64/cortex-a53/mmu.c
浏览文件 @
2d3ae920
...
...
@@ -12,17 +12,17 @@
#define TTBR_CNP 1
typedef
unsigned
long
int
uint64_t
;
typedef
unsigned
long
int
uint64_t
;
static
unsigned
long
main_tbl
[
512
*
20
]
__attribute__
((
aligned
(
4096
)));
#define IS_ALIGNED(x, a)
(((x) & ((typeof(x))(a) - 1)) == 0)
#define IS_ALIGNED(x, a)
(((x) & ((typeof(x))(a) - 1)) == 0)
#define PMD_TYPE_SECT
(1 << 0)
#define PMD_TYPE_SECT
(1 << 0)
#define PMD_TYPE_TABLE
(3 << 0)
#define PMD_TYPE_TABLE
(3 << 0)
#define PTE_TYPE_PAGE
(3 << 0)
#define PTE_TYPE_PAGE
(3 << 0)
#define BITS_PER_VA 39
...
...
@@ -31,7 +31,7 @@ static unsigned long main_tbl[512 * 20] __attribute__((aligned (4096)));
#define GRANULE_SIZE (1 << GRANULE_SIZE_SHIFT)
#define XLAT_ADDR_MASK ((1UL << BITS_PER_VA) - GRANULE_SIZE)
#define PMD_TYPE_MASK
(3 << 0)
#define PMD_TYPE_MASK
(3 << 0)
int
free_idx
=
1
;
...
...
@@ -178,9 +178,9 @@ int armv8_map_2M(unsigned long va, unsigned long pa, int count, unsigned long at
static
void
set_table
(
uint64_t
*
pt
,
uint64_t
*
table_addr
)
{
uint64_t
val
;
val
=
(
0x3UL
|
(
uint64_t
)
table_addr
);
*
pt
=
val
;
uint64_t
val
;
val
=
(
0x3UL
|
(
uint64_t
)
table_addr
);
*
pt
=
val
;
}
void
mmu_memset2
(
unsigned
char
*
dst
,
char
v
,
int
len
)
...
...
@@ -193,59 +193,59 @@ void mmu_memset2(unsigned char *dst, char v, int len)
static
uint64_t
*
create_table
(
void
)
{
uint64_t
*
new_table
=
(
uint64_t
*
)((
unsigned
char
*
)
&
main_tbl
[
0
]
+
free_idx
*
4096
);
//+ free_idx * GRANULE_SIZE;
/* Mark all entries as invalid */
mmu_memset2
((
unsigned
char
*
)
new_table
,
0
,
4096
);
free_idx
++
;
return
new_table
;
uint64_t
*
new_table
=
(
uint64_t
*
)((
unsigned
char
*
)
&
main_tbl
[
0
]
+
free_idx
*
4096
);
//+ free_idx * GRANULE_SIZE;
/* Mark all entries as invalid */
mmu_memset2
((
unsigned
char
*
)
new_table
,
0
,
4096
);
free_idx
++
;
return
new_table
;
}
static
int
pte_type
(
uint64_t
*
pte
)
{
return
*
pte
&
PMD_TYPE_MASK
;
return
*
pte
&
PMD_TYPE_MASK
;
}
static
int
level2shift
(
int
level
)
{
/* Page is 12 bits wide, every level translates 9 bits */
return
(
12
+
9
*
(
3
-
level
));
/* Page is 12 bits wide, every level translates 9 bits */
return
(
12
+
9
*
(
3
-
level
));
}
static
uint64_t
*
get_level_table
(
uint64_t
*
pte
)
{
uint64_t
*
table
=
(
uint64_t
*
)(
*
pte
&
XLAT_ADDR_MASK
);
if
(
pte_type
(
pte
)
!=
PMD_TYPE_TABLE
)
uint64_t
*
table
=
(
uint64_t
*
)(
*
pte
&
XLAT_ADDR_MASK
);
if
(
pte_type
(
pte
)
!=
PMD_TYPE_TABLE
)
{
table
=
create_table
();
set_table
(
pte
,
table
);
}
return
table
;
table
=
create_table
();
set_table
(
pte
,
table
);
}
return
table
;
}
static
void
map_region
(
uint64_t
virt
,
uint64_t
phys
,
uint64_t
size
,
uint64_t
attr
)
{
uint64_t
block_size
=
0
;
uint64_t
block_shift
=
0
;
uint64_t
*
pte
;
uint64_t
idx
=
0
;
uint64_t
addr
=
0
;
uint64_t
*
table
=
0
;
int
level
=
0
;
addr
=
virt
;
while
(
size
)
uint64_t
block_size
=
0
;
uint64_t
block_shift
=
0
;
uint64_t
*
pte
;
uint64_t
idx
=
0
;
uint64_t
addr
=
0
;
uint64_t
*
table
=
0
;
int
level
=
0
;
addr
=
virt
;
while
(
size
)
{
table
=
&
main_tbl
[
0
];
for
(
level
=
0
;
level
<
4
;
level
++
)
table
=
&
main_tbl
[
0
];
for
(
level
=
0
;
level
<
4
;
level
++
)
{
block_shift
=
level2shift
(
level
);
block_shift
=
level2shift
(
level
);
idx
=
addr
>>
block_shift
;
idx
=
idx
%
512
;
idx
=
idx
%
512
;
block_size
=
(
uint64_t
)(
1L
<<
block_shift
);
pte
=
table
+
idx
;
pte
=
table
+
idx
;
if
(
size
>=
block_size
&&
IS_ALIGNED
(
addr
,
block_size
))
if
(
size
>=
block_size
&&
IS_ALIGNED
(
addr
,
block_size
))
{
attr
&=
0xfff0000000000ffcUL
;
if
(
level
!=
3
)
...
...
@@ -256,14 +256,14 @@ static void map_region(uint64_t virt, uint64_t phys, uint64_t size, uint64_t att
{
*
pte
=
phys
|
(
attr
|
0x3UL
);
}
addr
+=
block_size
;
phys
+=
block_size
;
size
-=
block_size
;
break
;
}
table
=
get_level_table
(
pte
);
}
}
addr
+=
block_size
;
phys
+=
block_size
;
size
-=
block_size
;
break
;
}
table
=
get_level_table
(
pte
);
}
}
}
void
armv8_map
(
unsigned
long
va
,
unsigned
long
pa
,
unsigned
long
size
,
unsigned
long
attr
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录