Skip to content

Commit

Permalink
Continuing with support for guests on several cores...
Browse files Browse the repository at this point in the history
  • Loading branch information
didriklundberg committed Aug 2, 2015
1 parent 7521daa commit fdf7b09
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 61 deletions.
4 changes: 2 additions & 2 deletions core/hw/board/raspberrypi2/board_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ memory_layout_entry memory_padr_layout[] = {
MLT_IO_RW_REG, MLF_READABLE | MLF_WRITEABLE},

//Quad-Core processor control (0x40000000 to 0x400000FF)
//Nota bene: All other peripherals are mapped from 3F to FA, this will be
//N.B.: All other peripherals are mapped from 3F to FA, while this will be
//mapped to FB. Crude methods which simply assume peripherals to be in the
//range FA will fail here.
//range FA-FB will fail for these registers.
{ADDR_TO_PAGE(0x40000000), ADDR_TO_PAGE(0x40000000 + 0x1000),
MLT_IO_RW_REG, MLF_READABLE | MLF_WRITEABLE},

Expand Down
3 changes: 2 additions & 1 deletion core/hw/cpu/arm/armv7a/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ adr_undef: .word impl_undef
impl_reset:
/* Start in supervisor mode, disable interrupts. */
msr CPSR_c, #ARM_MODE_SUPERVISOR | ARM_INTERRUPT_MASK
/* Stack pointer starts at the physical address of the hyper stack top. */
/* Stack pointer starts at the physical address of the hyper stack top.
* In this file, we always boot the primary core. */
ldr sp, =(__hyper_stack_top__ + HAL_OFFSET)

//TODO: TEST:
Expand Down
18 changes: 9 additions & 9 deletions core/hw/cpu/arm/armv7a/cpu_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

extern uint32_t __hyper_pt_start__[]; // Symbols address is the value (linker script)

/* forward refrence */
/* Forward reference */
static return_value default_catcher(uint32_t r0, uint32_t r1, uint32_t r2);

/* callback functions */
/* Callback functions */
cpu_callback family_callback_inst_abort = default_catcher;
cpu_callback family_callback_data_abort = default_catcher;

Expand Down Expand Up @@ -44,8 +44,8 @@ void cpu_break_to_debugger()


/*
* default exception catcher so we dont crash into NULL
* due to very early exceptions
* Default exception catcher so we dont crash into NULL due to very early
* exceptions.
*/
static return_value default_catcher(uint32_t r0, uint32_t r1, uint32_t r2)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ static return_value default_catcher(uint32_t r0, uint32_t r1, uint32_t r2)

void cpu_init()
{
/* Invalidate and enable cache*/
/* Invalidate and enable cache */
//mem_cache_invalidate(TRUE,TRUE,TRUE); //instr, data, writeback
//mem_cache_set_enable(TRUE);
CacheDataCleanInvalidateAll();
Expand All @@ -92,9 +92,9 @@ void cpu_init()
uint32_t pt = (uint32_t)GET_PHYS(__hyper_pt_start__);
uint32_t ttb_flags = ( pt | TTB_IRGN_WB | TTB_RGN_OC_WB);
COP_WRITE(COP_SYSTEM,COP_SYSTEM_TRANSLATION_TABLE1,ttb_flags);
/*The following is Linux specific configuration on armV7,
*These configuration are used to identify what kind of memory
*the address space is by looking at the page attributes */
/* The following is Linux specific configuration on armV7,
* These configuration are used to identify what kind of memory
* the address space is by looking at the page attributes */

/*
* Memory region attributes with SCTLR.TRE=1
Expand Down Expand Up @@ -141,7 +141,7 @@ void cpu_init()
COP_READ(COP_SYSTEM,COP_SYSTEM_CONTROL, mmu_config);
mmu_config &= (~clear);
mmu_config |= set;
/*Setting alignment fault with beagleboard crashes it*/
/* Setting alignment fault with beagleboard crashes it */
//mmu_config |= CR_A; // Set Alignment fault checking
COP_WRITE(COP_SYSTEM, COP_SYSTEM_CONTROL, mmu_config);
//mem_cache_set_enable(TRUE);
Expand Down
6 changes: 3 additions & 3 deletions core/hw/cpu/arm/armv7a/cpu_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void mem_mmu_tlb_invalidate_one(BOOL inst, BOOL data, uint32_t virtual_addr)
* CACHES
*/

/* XXX: this can be simplified alot! /AV */
/* XXX: this can be simplified a lot! /AV */
static inline signed int log_2_n_round_up(uint32_t n)
{
signed int log2n = -1;
Expand Down Expand Up @@ -138,12 +138,12 @@ void mem_cache_set_enable(BOOL enable)
void mem_cache_invalidate(BOOL inst_inv, BOOL data_inv, BOOL data_writeback)
{
uint32_t tmp = 1;
/* first, handle the data cache */
/* First, handle the data cache. */
if(data_inv) {
mem_icache_invalidate(data_writeback);
}

/* now, the instruction cache */
/* Then, the instruction cache. */
if(inst_inv) {
COP_WRITE(COP_SYSTEM, COP_ICACHE_INVALIDATE_ALL, tmp);
}
Expand Down
6 changes: 3 additions & 3 deletions core/hypervisor/dmmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void dmmu_init()
uint32_t i;
dmmu_entry_t * bft = (dmmu_entry_t *) DMMU_BFT_BASE_VA;

/* clear all entries in the table */
/* Clear all entries in the table. */
for(i = 0; i < DMMU_BFT_COUNT ; i++) {
bft[i].all = 0;
}
Expand Down Expand Up @@ -274,7 +274,7 @@ int dmmu_create_L1_pt(addr_t l1_base_pa_add)
return ERR_MMU_OUT_OF_CACHEABLE_RANGE;
#endif

/* 16KB aligned ? */
/* 16 KiB aligned ? */
if (l1_base_pa_add != (l1_base_pa_add & 0xFFFFC000))
return ERR_MMU_L1_BASE_IS_NOT_16KB_ALIGNED;

Expand Down Expand Up @@ -371,7 +371,7 @@ int dmmu_unmap_L1_pt(addr_t l1_base_pa_add)
if (!guest_pa_range_checker(l1_base_pa_add, 4*PAGE_SIZE))
return ERR_MMU_OUT_OF_RANGE_PA;

/* 16KB aligned ? */
/* 16 KiB aligned ? */
if (l1_base_pa_add != (l1_base_pa_add & 0xFFFFC000))
return ERR_MMU_L1_BASE_IS_NOT_16KB_ALIGNED;

Expand Down
10 changes: 5 additions & 5 deletions core/hypervisor/dmmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Disabling aggressive flushing
//#define AGGRESSIVE_FLUSHING_HANDLERS

/* bft base and size definition */
/* BFT base and size definition */
#define DMMU_BFT_BASE_PY (MB + HAL_PHYS_START)
#define DMMU_BFT_BASE_VA (DMMU_BFT_BASE_PY - HAL_OFFSET)

Expand All @@ -20,12 +20,12 @@
#define PG_ADDR_LOWER_BOUND curr_vm->config->firmware->pstart + 0x6800000
#define PG_ADDR_UPPER_BOUND curr_vm->config->firmware->pstart + 0x6A00000

/* bft entry type */
/* BFT entry type */
enum dmmu_entry_type {
DMMU_TYPE_DATA, DMMU_TYPE_L1PT, DMMU_TYPE_L2PT, DMMU_TYPE_INVALID
};

/* a single bft table */
/* A single BFT table */
typedef union dmmu_entry {
uint32_t all;
__PACKED struct {
Expand Down Expand Up @@ -170,11 +170,11 @@ void mmu_bft_region_set(addr_t start, size_t size, uint32_t refc, uint32_t typ);



/* in translate.c */
/* In translate.c */
int mmu_lookup_guest(addr_t vadr, addr_t *padr, int user_write);
int mmu_lookup_hv(addr_t vadr, addr_t *padr, int hv_write);

/*Function prototypes*/
/* Function prototypes */
int dmmu_switch_mm(addr_t l1_base_pa_add);

int dmmu_create_L1_pt(addr_t l1_base_pa_add);
Expand Down
6 changes: 3 additions & 3 deletions core/hypervisor/hyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef void(*pabort_handler_fn)(void);



/*Data structures
/* Data structures
*
* */

Expand All @@ -25,14 +25,14 @@ typedef struct guest_info_ {
uint32_t phys_offset;
addr_t vmalloc_end;
uint32_t guest_size;
}guest_info;
} guest_info;

typedef struct boot_info_ {
guest_info guest;
uint32_t cpu_id;
uint32_t cpu_mmf;
uint32_t cpu_cr;
}boot_info;
} boot_info;


/* Virtual machine data structures */
Expand Down
28 changes: 15 additions & 13 deletions core/hypervisor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void memory_commit()

void memory_init()
{
/*Setup heap pointer*/
/* Setup heap pointer. */
core_mem_init();

uint32_t j; //TODO: Note: Removed unused variable va_offset here.
Expand Down Expand Up @@ -176,7 +176,7 @@ void guests_init()
// dump_mmu(flpt_va); // DEBUG


/* show guest information */
/* Show guest information */
printf("We have %d guests in physical memory area %x %x\n",
guests_db.count, guests_db.pstart, guests_db.pend);

Expand Down Expand Up @@ -340,7 +340,7 @@ void guests_init()

// Init the context with the physical addresses
do{
/*Init default values*/
/* Init default values */
for(i = 0; i < HC_NGUESTMODES;i++){
curr_vm->mode_states[i].mode_config = (curr_vm->config->guest_modes[i]);
curr_vm->mode_states[i].rpc_for = MODE_NONE;
Expand Down Expand Up @@ -369,39 +369,41 @@ void guests_init()

void start_guest()
{

/*Change guest mode to KERNEL before going into guest*/
/* Change guest mode to KERNEL before going into guest. */
change_guest_mode(HC_GM_KERNEL);

/*Starting Guest*/
/* Start guest! */
start();

}

//Contains a function call to an assembly function which is an infinite loop.
//Contains a function call to an assembly label above an infinite loop.
void debug_temp(){
debug_inf_loop();
}

void start_()
{
/* Flush and enable the cache, among other things. Defined in
* core/hw/cpu/family/model/cpu_init.c. */
cpu_init();

/* Set up pagetable rules. */
/* Set up pagetable rules - defined further up in this file. */
memory_init();

/* Initialize hardware. */
/* Initialize hardware - defined in core/hw/soc/platform and
* core/hw/board/platform, respectively. */
soc_init();
board_init();

/* Set up exception handlers and starting timer. */
/* Set up exception handlers and starting timer - defined further up in this
* file. */
setup_handlers();

/* DMMU initialization. */
/* DMMU initialization - defined in dmmu.c. */
dmmu_init();

/* Initialize hypervisor guest modes and data structures
* according to config file in guest*/
* according to config file in guest - defined further up in this file. */
guests_init();

printf("Hypervisor initialized.\n Entering Guest...\n");
Expand Down
52 changes: 30 additions & 22 deletions core/hypervisor/init_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@
//to do what you want.

void slave_start_(){
//TODO: Which of these needs to be done?
//cpu_init();

/* Set up pagetable rules. */
//memory_init();

/* Initialize hardware. */
//soc_init();
//board_init();

/* Set up exception handlers and starting timer. */
//setup_handlers();

/* DMMU initialization. */
//dmmu_init();

/* Initialize hypervisor guest modes and data structures
* according to config file in guest*/
//guests_init();

//Move along, main core...
//start_guest();
/* Flush and enable the cache, among other things. Defined in
* core/hw/cpu/family/model/cpu_init.c. */
cpu_init(); //TODO: I think this needs to be done a second time.

/* Set up pagetable rules - defined in init.c. */
//memory_init(); //TODO: This sets up the heap and the memory layout...

/* Initialize peripherals - defined in core/hw/soc/platform and
* core/hw/board/platform, respectively. */
//soc_init(); //TODO: I'm 99% this does not need to be done a second time.
//board_init(); //TODO: This does nothing, but what could be found in here
// should probably only be called once.

/* Set up exception handlers and starting timer - defined in init.c. */
//setup_handlers(); //TODO: This does not do anything core-specific, as far
// as I'm aware...

/* DMMU initialization - defined in dmmu.c. */
//dmmu_init(); //TODO: This needs to be done once per core if every core
// requires a separate BFT - but that will require some
// modification...

/* Initialize hypervisor guest modes and data structures according to config
* file in guest - defined in init.c. */
//guests_init(); //TODO: This appears hard-coded to load only one guest and/
// or the trusted guest, and takes no arguments.
// Currently, everything related to choosing guests
// is done by pre-processor macros.

//start_guest(); //TODO: Simply swaps to kernel mode and starts guest.
}

0 comments on commit fdf7b09

Please sign in to comment.