Skip to content

Commit

Permalink
Fundamental changes to context handling in order to enable guests on …
Browse files Browse the repository at this point in the history
…several cores
  • Loading branch information
didriklundberg committed Aug 17, 2015
1 parent 1a0b0ba commit b993b5d
Show file tree
Hide file tree
Showing 21 changed files with 3,757 additions and 31 deletions.
30 changes: 15 additions & 15 deletions core/hw/cpu/arm/arm_common/arm_pt.S
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,29 @@ arm_setup_initial_pt:
nop @ For PC jump above
nop @ For PC jump abovez

/* Now running in virt space, we can remove 1:1 mapping now - or NOT.
* TODO: Current version should not remove the temporary mapping.
* We should instead copy it to */

/* TODO: Copy multiple words at a time? Which registers are used?
LDMCopy:
push {r4-r10}
LDMloop:
ldmia r1!, {r3 - r10}
stmia r0!, {r3 - r10}
subs r2, r2, #32
bge LDMloop
*/
/* Now running in virt space, we can remove 1:1 mapping now - but we copy
* it to another location for later usage first. */

/* The starting address of the secondary page table. */
ldr r0, =__hyper_pt_start_slave__
ldr r0, =__hyper_pt_start__
ldr r2, r6
ldr r1, =HAL_OFFSET
add r0, r0, r1

/* The starting address of the primary page table. */
ldr r1, =__hyper_pt_start__

/* r2 should hold the size of the secondary page table, in bytes. */
ldr r2, #0x4000

/* The temporary page table is copied onto the secondary page table memory
* TODO: There are more efficient ways to do this... */
copy_loop:
ldr r3, [r1], #4
str r3, [r0], #4
subs r2, r2, #4
bge copy_loop

/* Deletion of temporary page table from primary page table memory addresses */
mov r0, #0
ldr r3, =(HAL_PHYS_START >> 20)
str r0, [r4, r3, lsl #2]
Expand Down
211 changes: 202 additions & 9 deletions core/hw/cpu/arm/arm_common/family_context_bottom.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,165 @@


/*
* CPU context functions
* CPU context functions
*/
.code 32
.global cpu_context_current_get
.global cpu_context_current_set
.global cpu_context_initial_set
.global cpu_context_depth_get
.global cpu_context_depth_get

get_cpu_index:
/* Does not use r0 but r1, in order to not overwrite anything in r0. */

/* Load address of stack pointer into register 0. */
ldr r1, sp

/* Subtract the base address of the first stack from r0 (r0 holding the
value of the stack pointer). */
sub r1, r1, =__hyper_stack_bottom__

/* Do a logical right-shift by 13 bits of the above result. */
lsr r1, r1, #13

/* Return - at this point the index of the current core will be stored in
register 1. */
bx lr

get_current_vm:
/* Uses r0 and r1 */

/* Load address of stack pointer into register 0. */
ldr r0, sp

/* Subtract the base address of the first stack from r0 (r0 holding the
value of the stack pointer). */
sub r0, r0, =__hyper_stack_bottom__

/* Do a logical right-shift by 13 bits of the above result.
NOTE: Dependent on stack size... */
lsr r0, r0, #13

/* Load the address of the virtual machines in r1. */
ldr r1, =vms

/* Multiply r0 by 4 (NOTE: since pointer size is 32 bits). */
mul r0, r0, #4

/* Load into r0 the value at address r1+r0 - should be a pointer to the
current virtual machine. */
ldr r0, [r1, r0]

/* Return - at this point a pointer to the current virtual machine will be
stored in r0. */
bx lr


cpu_context_current_get:

/* Fetches CPU core index into register 1. */
bl get_cpu_index
/* 92: The size of one stack is 23 words, one word is 4 bytes. */
mul r1, r1, #92
/* Add resulting offset to context_stack_curr (first stack) */
add r1, r1, =context_stack_curr
/* Store in r0 the value at r1 */
ldr r0, [r1]
/* r0 will now hold the address of the current stack */

add r1, r0, #4
ldr r0, [r0]
ldr r0, [r1, r0, lsl #2]
bx lr

/* Old version:
ldr r0, =context_stack_curr
add r1, r0, #4 @ ldr r1, =context_stack
ldr r0, [r0]
ldr r0, [r1, r0, lsl #2]
bx lr
*/

cpu_context_current_set:
/* r1, r2 clear to use - r0 used */
bl get_cpu_index
/* 92: The size of one stack is 23 words, one wird is 4 bytes. */
mul r1, r1, #92
/* Add resulting offset to context_stack_curr (first stack) */
add r1, r1, =context_stack_curr
/* Store in r1 the value at r1 */
ldr r1, [r1]
/* r1 will now hold the */

add r2, r1, #4
ldr r1, [r1]
str r0, [r2, r1, lsl #2]
bx lr

/* OLD:
ldr r1, =context_stack_curr
add r2, r1, #4 @ ldr r2, =context_stack
ldr r1, [r1]
str r0, [r2, r1, lsl #2]
bx lr
bx lr
*/

/* TODO: Should this set all initial stacks, or just for the current core?
This is currently done by the first core for all cores, so...
Changed this call to supply the ID of current VM. */
cpu_context_initial_set:
/* r2 clear to use - r0, r1 used */
bl get_cpu_index


/* 92: The size of one stack is 23 words, one word is 4 bytes. */
mul r1, r1, #92
/* Add resulting offset to context_stack_curr (first stack) */
add r1, r1, =context_stack_curr

add r1, r1, #4
/* Store in r2 the value at r1 */
ldr r2, [r1]

str r0, [r2, #4]
bx lr

/* OLD:
ldr r2, =context_stack
str r0, [r2, #4]
bx lr
*/

cpu_context_depth_get:
/* r0 clear to use */
bl get_cpu_index
/* 92: The size of one stack is 23 words, one word is 4 bytes. */
mul r1, r1, #92
/* Add resulting offset to context_stack_curr (first stack) */
add r1, r1, =context_stack_curr

add r1, r1, #4
/* Store in r1 the value at r1 */
ldr r0, [r1]

ldr r0, [r0]
bx lr
/* OLD:
ldr r0, =context_stack_curr
ldr r0, [r0]
bx lr
*/

/*
* exception handler data
* Exception handler data
*
* NOTE: it is important that context_stack == context_stack_curr + 4
*/

/* Core 0 */
.data
context_stack_curr:
.word 0
Expand All @@ -60,7 +178,55 @@ context_stack:
.word def_context6
.word def_context7
.word 0

/* Core 1 */
.data
context_stack_curr_1:
.word 0
context_stack_1:
.word 0
.word def_context_1_1
.word def_context_1_2
.word def_context_1_3
.word def_context_1_4
.word def_context_1_5
.word def_context_1_6
.word def_context_1_7
.word 0

/* Core 2 */
.data
context_stack_curr_2:
.word 0
context_stack_2:
.word 0
.word def_context_2_1
.word def_context_2_2
.word def_context_2_3
.word def_context_2_4
.word def_context_2_5
.word def_context_2_6
.word def_context_2_7
.word 0

/* Core 3 */
.data
context_stack_curr_3:
.word 0
context_stack_3:
.word 0
.word def_context_3_1
.word def_context_3_2
.word def_context_3_3
.word def_context_3_4
.word def_context_3_5
.word def_context_3_6
.word def_context_3_7
.word 0

/* The context space are defined here. TODO: Is it really necessary to replicate
* everything? */

.data
def_context1: .space 4 * 20, 0
def_context2: .space 4 * 20, 0
Expand All @@ -70,4 +236,31 @@ def_context5: .space 4 * 20, 0
def_context6: .space 4 * 20, 0
def_context7: .space 4 * 20, 0

.data
def_context_1_1: .space 4 * 20, 0
def_context_1_2: .space 4 * 20, 0
def_context_1_3: .space 4 * 20, 0
def_context_1_4: .space 4 * 20, 0
def_context_1_5: .space 4 * 20, 0
def_context_1_6: .space 4 * 20, 0
def_context_1_7: .space 4 * 20, 0

.data
def_context_2_1: .space 4 * 20, 0
def_context_2_2: .space 4 * 20, 0
def_context_2_3: .space 4 * 20, 0
def_context_2_4: .space 4 * 20, 0
def_context_2_5: .space 4 * 20, 0
def_context_2_6: .space 4 * 20, 0
def_context_2_7: .space 4 * 20, 0

.data
def_context_3_1: .space 4 * 20, 0
def_context_3_2: .space 4 * 20, 0
def_context_3_3: .space 4 * 20, 0
def_context_3_4: .space 4 * 20, 0
def_context_3_5: .space 4 * 20, 0
def_context_3_6: .space 4 * 20, 0
def_context_3_7: .space 4 * 20, 0


6 changes: 3 additions & 3 deletions core/hypervisor/init_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,17 @@ void guests_init_multicore(){
} while(curr_vm != &vm_0);

memory_commit();


//Define the active virtual machine for each core
vms[0] = &vm_0;
vms[1] = &vm_1;
vms[2] = &vm_2;
vms[3] = &vm_3;

//Set-up for each core current_context to point to the context of the active virtual machine
//Set-up for each core current_context to point to the context of the active
//virtual machine.
do{
cpu_context_initial_set(&curr_vm->mode_states[HC_GM_KERNEL].ctx);
cpu_context_initial_set(&curr_vm->mode_states[HC_GM_KERNEL].ctx, curr_vm->id);
} while(curr_vm != &vm_0);
}

Expand Down
2 changes: 1 addition & 1 deletion guests/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

SUBDIRS = minimal trusted dtest
SUBDIRS = minimal trusted dtest dtest1 dtest2 dtest3

all:
set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d ; done
Expand Down
3 changes: 3 additions & 0 deletions guests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ README
======

This directory contains guests, to be run on the hypervisor.

The multiple dtests is a temporary solution for loading multiple instances of
the same guest.
26 changes: 26 additions & 0 deletions guests/dtest1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TARGET=dtest
SRC_DIRS += src

DEPENDS = ../../library/uc ../../drivers ../../library/guest
LIB_FILES=guest uc drivers

LDSCRIPT = ../../library/guest/default.ld

# get platform dependent flags
include ../../target
include ../../templates/platform/$(PLATFORM).cfg
include ../../templates/cpu/$(PLATFORM_CPU).cfg

ifndef TEST_NAME
TEST_NAME = TEST_UNDEFINED
endif
SRC_CFLAGS += -D$(TEST_NAME)=1

# include templates
include ../../templates/make/toolchain.inc
include ../../templates/make/generic.inc
include ../../templates/make/application.inc


# force update when something changes
$(OBJ_FILES): Makefile ../../target
Loading

0 comments on commit b993b5d

Please sign in to comment.