Skip to content

Commit 4a6f96a

Browse files
committed
move kernel to 0xFFFFFF0000080000
1 parent 21297fb commit 4a6f96a

40 files changed

+2285
-560
lines changed

bottom/bootcode.bin

100755100644
File mode changed.

os/.tags

Lines changed: 448 additions & 0 deletions
Large diffs are not rendered by default.

os/.tags1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2+
!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
3+
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4+
!_TAG_PROGRAM_NAME Exuberant Ctags //
5+
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6+
!_TAG_PROGRAM_VERSION 5.8 //
7+
curenv Z:\RaspberryPi3_OS_new\os\lib\env.c /^struct Env *curenv; \/\/ the current env$/;" variable line:10 typeref:struct:Env
8+
env_free_list Z:\RaspberryPi3_OS_new\os\lib\env.c /^static struct Env_list env_free_list; \/\/ Free list$/;" variable line:12 typeref:struct:Env_list file:
9+
mkenvid Z:\RaspberryPi3_OS_new\os\lib\env.c /^u_int mkenvid(struct Env *e)$/;" function line:28 signature:(struct Env *e)
10+
envid2env Z:\RaspberryPi3_OS_new\os\lib\env.c /^int envid2env(u_int envid, struct Env **penv, int checkperm)$/;" function line:51 signature:(u_int envid, struct Env **penv, int checkperm)
11+
env_init Z:\RaspberryPi3_OS_new\os\lib\env.c /^void env_init(void)$/;" function line:95 signature:(void)
12+
env_setup_vm Z:\RaspberryPi3_OS_new\os\lib\env.c /^static int env_setup_vm(struct Env *e)$/;" function line:126 file: signature:(struct Env *e)
13+
env_alloc Z:\RaspberryPi3_OS_new\os\lib\env.c /^int env_alloc(struct Env **new, u_int parent_id)$/;" function line:166 signature:(struct Env **new, u_int parent_id)
14+
load_icode_mapper Z:\RaspberryPi3_OS_new\os\lib\env.c /^static int load_icode_mapper(u_long va, u_int32_t sgsize,$/;" function line:218 file: signature:(u_long va, u_int32_t sgsize, u_char *bin, u_int32_t bin_size, void *user_data)
15+
load_icode Z:\RaspberryPi3_OS_new\os\lib\env.c /^static void load_icode(struct Env *e, u_char *binary, u_int size)$/;" function line:297 file: signature:(struct Env *e, u_char *binary, u_int size)
16+
env_create Z:\RaspberryPi3_OS_new\os\lib\env.c /^void env_create(u_char *binary, int size)$/;" function line:337 signature:(u_char *binary, int size)
17+
env_free Z:\RaspberryPi3_OS_new\os\lib\env.c /^void env_free(struct Env *e)$/;" function line:351 signature:(struct Env *e)
18+
env_destroy Z:\RaspberryPi3_OS_new\os\lib\env.c /^void env_destroy(struct Env *e)$/;" function line:419 signature:(struct Env *e)
19+
env_run Z:\RaspberryPi3_OS_new\os\lib\env.c /^void env_run(struct Env *e)$/;" function line:447 signature:(struct Env *e)

os/Makefile

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
2-
driver_dir := driver
3-
boot_dir := boot
4-
lib_dir := lib
5-
mm_dir := mm
6-
user_dir := user
7-
8-
link_script := loader
9-
10-
modules := boot driver lib mm user
11-
objects := $(boot_dir)/*.o \
12-
$(driver_dir)/*.o \
13-
$(lib_dir)/*.o \
14-
$(mm_dir)/*.o \
15-
$(user_dir)/*.o
16-
17-
18-
.PHONY: all $(modules) clean
19-
20-
all: clean $(modules) kernel8
21-
22-
kernel8: $(modules)
23-
$(LD) $(objects) -T $(link_script) -e _start -o bootloader.elf
24-
$(OBJCOPY) bootloader.elf -O binary kernel8.img
25-
26-
$(modules):
27-
$(MAKE) --directory=$@
28-
29-
clean:
30-
for d in $(modules); \
31-
do \
32-
$(MAKE) --directory=$$d clean; \
33-
done; \
34-
rm -rf *.o *~ kernel8.img bootloader.elf
35-
36-
debug:
37-
$(OBJDUMP) -D -m aarch64 bootloader.elf > bootloader.list
38-
39-
include include.mk
1+
2+
driver_dir := driver
3+
boot_dir := boot
4+
lib_dir := lib
5+
mm_dir := mm
6+
user_dir := user
7+
8+
link_script := loader
9+
10+
modules := boot driver lib mm user
11+
objects := $(boot_dir)/*.o \
12+
$(driver_dir)/*.o \
13+
$(lib_dir)/*.o \
14+
$(mm_dir)/*.o \
15+
$(user_dir)/*.o
16+
17+
18+
.PHONY: all $(modules) clean
19+
20+
all: clean $(modules) kernel8
21+
22+
kernel8: $(modules)
23+
$(LD) $(objects) -T $(link_script) -e _start -o bootloader.elf
24+
$(OBJCOPY) bootloader.elf -O binary kernel8.img
25+
26+
$(modules):
27+
$(MAKE) --directory=$@
28+
29+
clean:
30+
for d in $(modules); \
31+
do \
32+
$(MAKE) --directory=$$d clean; \
33+
done; \
34+
rm -rf *.o *~ kernel8.img bootloader.elf
35+
36+
debug: all
37+
$(OBJDUMP) -D -m aarch64 bootloader.elf > bootloader.list
38+
readelf bootloader.elf -a
39+
40+
include include.mk

os/boot/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ INCLUDES := -I../lib/include/ -I../driver/include/ -I../mm/include/ -I../inclu
77

88
.PHONY: clean
99

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

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

15+
init.o :
16+
$(AS) $(INCLUDES) init.s -o init.o
17+
1518
clean:
1619
rm -rf *~ *.o
1720

os/boot/asm.s

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,34 @@
11
#include "sysconfig.h"
22

3-
.globl _start
4-
_start:
5-
mrs x0, mpidr_el1 // check core id, only one core is used.
6-
mov x1, #0xc1000000
7-
bic x0, x0, x1
8-
cbz x0, master
9-
b hang
10-
11-
master:
12-
ldr x0, =0x1000000
13-
mov sp, x0 // set el2 sp
14-
bl el2_main
15-
16-
hang:
17-
b hang
18-
193
.globl get_current_el
204
get_current_el:
215
mrs x0, currentel
226
mov x1, #2
237
lsr x0, x0, #2
248
ret
259

26-
.globl el1_mmu_activate
27-
el1_mmu_activate:
28-
ldr x0, =0x04cc
29-
msr mair_el1, x0
30-
isb
31-
32-
ldr x1, =0x01000000
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, =0x2bf183f18
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
53-
ret
54-
55-
.globl jump_to_el1
56-
jump_to_el1:
57-
mrs x0, currentel // check if already in el1
58-
cmp x0, #4
59-
beq 1f
60-
61-
ldr x0, =0xf00000
62-
msr sp_el1, x0 // init the stack of el1
63-
64-
// disable coprocessor traps
65-
mov x0, #0x33ff
66-
msr cptr_el2, x0 // disable coprocessor traps to el2
67-
msr hstr_el2, xzr // disable coprocessor traps to el2
68-
mov x0, #3 << 20
69-
msr cpacr_el1, x0 // enable fp/simd at el1
70-
71-
// initialize hcr_el2
72-
mov x0, #(1 << 31)
73-
msr hcr_el2, x0 // set el1 to 64 bit
74-
mov x0, #0x0800
75-
movk x0, #0x30d0, lsl #16
76-
msr sctlr_el1, x0
77-
78-
// return to the el1_sp1 mode from el2
79-
mov x0, #0x5
80-
msr spsr_el2, x0 // el1_sp1 with DAIF = 0
81-
adr x0, 1f
82-
msr elr_el2, x0
83-
eret
84-
85-
1:
86-
mrs x0, sctlr_el1
87-
orr x0, x0, #(1 << 12)
88-
msr sctlr_el1, x0 // enable instruction cache
89-
90-
ldr x0, =vectors
91-
msr vbar_el1, x0 // init exception vector table
92-
93-
b main
94-
9510
.globl jump_to_el0
9611
jump_to_el0:
9712
mov x1, x0
98-
mrs x0, currentel // check if in el2
13+
mrs x0, currentel // check if in el2
9914
cmp x0, #8
10015
beq 2f
10116

10217
ldr x0, =0xe00000
103-
msr sp_el0, x0 // init the stack of el0
18+
msr sp_el0, x0 // init the stack of el0
10419

10520
// return to el0 from el1
10621
mov x0, #0x0
10722
msr spsr_el1, x0 // el0 with DAIF = 0
10823
msr elr_el1, x1
109-
11024
eret
111-
11225
2:
113-
ret
26+
ret
11427

11528
.globl tlb_invalidate
11629
tlb_invalidate:
11730
dsb ishst // ensure write has completed
118-
tlbi vmalle1is // invalidate tlb, all asid, el1.
31+
tlbi vmalle1is // invalidate tlb, all asid, el1.
11932
dsb ish // ensure completion of tlb invalidation
12033
isb // synchronize context and ensure that no instructions
12134
// are fetched using the old translation
@@ -135,16 +48,16 @@ get32:
13548
dummy:
13649
ret
13750

138-
.globl load_ttbr1_context
139-
load_ttbr1_context:
140-
msr ttbr1_el1, x0
141-
ret
142-
14351
.globl load_ttbr0_context
14452
load_ttbr0_context:
14553
msr ttbr0_el1, x0
14654
ret
14755

56+
.globl load_ttbr1_context
57+
load_ttbr1_context:
58+
msr ttbr1_el1, x0
59+
ret
60+
14861
.globl get_sctlr_el1
14962
get_sctlr_el1:
15063
mrs x0, sctlr_el1

os/boot/el2.c

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

os/boot/init.s

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "sysconfig.h"
2+
3+
.globl _start
4+
_start:
5+
mrs x0, mpidr_el1 // check core id, only one core is used.
6+
mov x1, #0xc1000000
7+
bic x0, x0, x1
8+
cbz x0, master
9+
b hang
10+
11+
master:
12+
ldr x0, =0x1000000
13+
mov sp, x0 // set el2 sp
14+
bl vm_init
15+
bl jump_to_el1
16+
17+
hang:
18+
b hang
19+
20+
.globl jump_to_el1
21+
jump_to_el1:
22+
mrs x0, currentel // check if already in el1
23+
cmp x0, #4
24+
beq 1f
25+
26+
ldr x0, =0xffffff0001000000
27+
msr sp_el1, x0 // init the stack of el1
28+
29+
// disable coprocessor traps
30+
mov x0, #0x33ff
31+
msr cptr_el2, x0 // disable coprocessor traps to el2
32+
msr hstr_el2, xzr // disable coprocessor traps to el2
33+
mov x0, #3 << 20
34+
msr cpacr_el1, x0 // enable fp/simd at el1
35+
36+
// initialize hcr_el2
37+
mov x0, #(1 << 31)
38+
msr hcr_el2, x0 // set el1 to 64 bit
39+
mov x0, #0x0800
40+
movk x0, #0x30d0, lsl #16
41+
msr sctlr_el1, x0
42+
43+
// return to the el1_sp1 mode from el2
44+
mov x0, #0x5
45+
msr spsr_el2, x0 // el1_sp1 with DAIF = 0
46+
adr x0, 1f
47+
msr elr_el2, x0
48+
eret
49+
50+
1:
51+
mrs x0, sctlr_el1
52+
orr x0, x0, #(1 << 12)
53+
msr sctlr_el1, x0 // enable instruction cache
54+
55+
ldr x0, =vectors
56+
msr vbar_el1, x0 // init exception vector table
57+
58+
b el1_mmu_activate
59+
60+
.globl el1_mmu_activate
61+
el1_mmu_activate:
62+
ldr x0, =0x04cc
63+
msr mair_el1, x0
64+
isb
65+
66+
ldr x1, =0x01000000
67+
msr ttbr0_el1, x1
68+
msr ttbr1_el1, x1
69+
isb
70+
71+
mrs x2, tcr_el1
72+
ldr x3, =0x70040ffbf
73+
bic x2, x2, x3
74+
75+
ldr x3, =0x2bf183f18
76+
orr x2, x2, x3
77+
msr tcr_el1, x2
78+
isb
79+
80+
ldr x5, =main
81+
mrs x3, sctlr_el1
82+
ldr x4, =0x80000
83+
bic x3, x3, x4
84+
85+
ldr x4, =0x1005
86+
orr x3, x3, x4
87+
msr sctlr_el1, x3
88+
isb
89+
br x5

0 commit comments

Comments
 (0)