Skip to content

Commit

Permalink
Clear TLB before switching to a new memory context.
Browse files Browse the repository at this point in the history
Fixes the strange behaviours when starting processes:
 * Instructions in 1st MB of virtual memory in Raspberry Pi didn't execute,
 * 2nd execution of a process hanged.
  • Loading branch information
pykello committed Aug 16, 2014
1 parent 96a3e51 commit 2d1d483
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions kernel/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void proc_expand_memory(struct Process *proc, int page_count)

for (i = 0; i < page_count; i++) {
char *page = kalloc();
memset(page, 0, PAGE_SIZE);

map_pages(proc->vm, (struct MemoryMapping){
proc->heap_size,
V2P(page),
Expand Down Expand Up @@ -166,5 +168,10 @@ void proc_start(struct Process *proc)
proc->context[CPSR] = 0x10;
proc->context[RESTART_ADDR] = (int) proc->entry;
proc->context[SP] = USER_STACK_BOTTOM + PAGE_SIZE;

/* clear TLB */
__asm__ volatile("mov R4, #0");
__asm__ volatile("MCR p15, 0, R4, c8, c7, 0");

switch_to_context(proc->context);
}
2 changes: 1 addition & 1 deletion user/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EXTRA_CLEAN += $(USER_PROGRAMS) user/base16 user/user_programs.c

user/%: user/%.c lib/libarunos.a
$(USER_CC) $(USER_CFLAGS) -c -o $@.o $<
$(LD) -Ttext=100000 $@.o lib/libarunos.a -o $@
$(LD) -Ttext=100 $@.o lib/libarunos.a -o $@
rm -f $@.o

user/base16: user/base16.c
Expand Down

0 comments on commit 2d1d483

Please sign in to comment.