Skip to content

Commit 977e052

Browse files
committed
finally at el1
1 parent 5c96b72 commit 977e052

File tree

7 files changed

+95
-172
lines changed

7 files changed

+95
-172
lines changed

os/boot/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ INCLUDES := -I../lib/include/ -I../driver/include/ -I../mm/include/ -I../inclu
77

88
.PHONY: clean
99

10-
all: asm.o el3.o main.o
10+
all: asm.o el2.o main.o
1111

1212
asm.o :
13-
$(AS) asm.s -o asm.o
13+
$(AS) $(INCLUDES) asm.s -o asm.o
1414

1515
clean:
1616
rm -rf *~ *.o

os/boot/asm.s

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "sysconfig.h"
2+
13
.globl _start
24
_start:
35
MRS X0, MPIDR_EL1 // Check Core Id, we only use one core.
@@ -8,30 +10,46 @@ _start:
810

911
master:
1012
LDR X0, =0X04008000
11-
MOV SP, X0
12-
BL el3_main
13+
MOV SP, X0 // Set EL3 SP
14+
BL el2_main
1315

1416
hang:
1517
B hang
1618
1719
.globl get_current_el
1820
get_current_el:
1921
MRS X0, CURRENTEL
22+
MOV X1, #2
23+
LSR X0, X0, #2
2024
RET
2125
22-
.globl EL1_mmu_activate
23-
EL1_mmu_activate:
24-
LDR X0, =0X04008000 // Set TTBR0
25-
MSR TTBR0_EL3, X0 // Set TTBR0
26-
LDR X2, =0X20018
27-
MSR TCR_EL3, X2 // Set TCR
28-
ISB // The ISB forces these changes to be seen before the MMU is enabled.
29-
RET
30-
TLBI ALLE3IS // Invalidate the entire TLB.
31-
MRS X0, SCTLR_EL3 // Read System Control Register configuration data.
32-
ORR X0, X0, #1 // Set [M] bit and enable the MMU.
33-
MSR SCTLR_EL3, X0 // Write System Control Register configuration data.
34-
ISB // The ISB forces these changes to be seen by the next instruction.
26+
.globl el1_mmu_activate
27+
el1_mmu_activate:
28+
LDR X0, =0X04CC
29+
MSR MAIR_EL1, X0
30+
ISB
31+
32+
LDR X1, =0X02000000
33+
MSR TTBR0_EL1, X1
34+
ISB
35+
36+
MRS X2, TCR_EL1
37+
LDR X3, =0x70040FFBF
38+
BIC X2, X2, X3
39+
40+
LDR X3, =0X200803F18
41+
ORR X2, X2, X3
42+
MSR TCR_EL1, X2
43+
ISB
44+
45+
MRS X3, SCTLR_EL1
46+
LDR X4, =0X80000
47+
BIC X3, X3, X4
48+
49+
LDR X4, =0X1005
50+
ORR X3, X3, X4
51+
MSR SCTLR_EL1, X3
52+
ISB
3553
RET
3654

3755
.globl jump_to_el1

os/boot/el3.c

Lines changed: 0 additions & 30 deletions
This file was deleted.

os/boot/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44
#include "pmap.h"
55

66
extern u_long get_current_el();
7+
extern void el1_mmu_activate();
78

89
void main (void)
910
{
10-
11-
printf("%lx\n", get_current_el());
11+
printf("We are finally at EL%lx!\n", get_current_el());
12+
13+
// activate mmu for el1
14+
el1_mmu_activate();
1215

13-
printf("We are finally at EL1!\n");
14-
1516
page_check();
1617

17-
printf("Page check passed!\n");
18+
printf("Page check passed!\n\n\n\n");
1819

1920
gpio_output_init(17);
2021
for (;;)
2122
{
2223
gpio_set(17);
2324
sleep(1000);
24-
25+
2526
gpio_clr(17);
2627
sleep(1000);
2728
}

os/env/include/env.h

Lines changed: 0 additions & 66 deletions
This file was deleted.

os/mm/include/mmu.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _MMU_H_
22
#define _MMU_H_
33

4+
#include "sysconfig.h"
5+
46
/*
57
* This file contains:
68
*
@@ -12,7 +14,6 @@
1214
/*
1315
* Part 1. ARM definitions.
1416
*/
15-
#define MAXPA (512 * 1024 * 1024)
1617
#define BY2PG 4096 // bytes to a page
1718
#define PDMAP (4*1024) // bytes mapped by a third page table entry
1819

@@ -36,14 +37,23 @@
3637
/* Page Table/Directory Entry flags
3738
* these are defined by the hardware
3839
*/
39-
#define PTE_V 0x0003 // Table Entry Valid bit
40-
#define PBE_V 0x0001 // Block Entry Valid bit
41-
#define PTE_R 0x0000 // Dirty bit ,'0' means only read ,otherwise make interrupt
42-
// #define PTE_G 0x0100 // Global bit
43-
// #define PTE_D 0x0002 // fileSystem Cached is dirty
44-
// #define PTE_COW 0x0001 // Copy On Write
45-
// #define PTE_UC 0x0800 // unCached
46-
// #define PTE_LIBRARY 0x0004 // share memmory
40+
#define PTE_V 0x3 << 0 // Table Entry Valid bit
41+
#define PBE_V 0x1 << 0 // Block Entry Valid bit
42+
#define PTE_R 0x0 << 0 // Dirty bit ,'0' means only read ,otherwise make interrupt
43+
#define ATTRIB_AP_RW_EL1 0x0 << 6
44+
#define ATTRIB_AP_RW_ALL 0x1 << 6
45+
#define ATTRIB_AP_RO_EL1 0x2 << 6
46+
#define ATTRIB_AP_RO_ALL 0x3 << 6
47+
#define ATTRIB_SH_NON_SHAREABLE 0x0 << 8
48+
#define ATTRIB_SH_OUTER_SHAREABLE 0x2 << 8
49+
#define ATTRIB_SH_INNER_SHAREABLE 0x3 << 8
50+
#define AF 0x1 << 10
51+
#define PXN 0x0 << 53
52+
#define UXN 0x1UL << 54
53+
54+
#define ATTRINDX_NORMAL 0 // inner/outer write-back non-transient, non-allocating
55+
#define ATTRINDX_DEVICE 1 // Device-nGnRE
56+
#define ATTRINDX_COHERENT 2 // Device-nGnRnE
4757

4858
/*
4959
* Part 2. Our conventions.
@@ -54,32 +64,22 @@
5464
o | |
5565
o | ... |
5666
o | |
57-
o UTOP -----> +----------------------------+------------0x 0430 9000
67+
o EL2STACKTOP -----> +----------------------------+------------0x 0400 0000
68+
o | EL2 stack |
69+
o KSTACKTOP -----> +----------------------------+------------0x 03C0 0000
70+
o | Kernel stack |
71+
o UTOP -----> +----------------------------+------------0x 0230 1000
5872
o | PAGES |
59-
o UPAGES -----> +----------------------------+------------0x 0400 9000
73+
o UPAGES -----> +----------------------------+------------0x 0200 1000
6074
o | Page Table |
61-
o UVPT, EL3STACKTOP -----> +----------------------------+------------0x 0400 8000
62-
o | EL3 stack |
63-
o KSTACKTOP -----> +----------------------------+------------0x 03C0 8000
64-
o | Kernel stack |
65-
o | |
75+
o UVPT -----> +----------------------------|------------0x 0200 0000
6676
o | Kernel Text |
6777
o KERNBASE -----> +----------------------------+------------0x 8 0000
6878
o | reserved |
6979
a 0 ------------> +----------------------------+------------0x 0000
7080
o
7181
*/
7282

73-
#define KERNBASE 0x8000
74-
75-
#define KSTACKTOP EL3STACKTOP - 0x400000
76-
#define EL3STACKTOP 0x04008000
77-
#define UVPT EL3STACKTOP
78-
#define UPAGES UVPT + 0x1000
79-
#define UTOP UPAGES + 0x300000
80-
81-
#define KSTKSIZE (60*1024*1024)
82-
8383
#ifndef __ASSEMBLER__
8484

8585
/*

0 commit comments

Comments
 (0)