HV: fix "use -- or ++ operations"

ACRN coding guidelines banned -- or ++ operations.
V1->V2:
  add comments to struct stack_frame

Tracked-On: #861
Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
This commit is contained in:
Huihuang Shi 2019-07-10 16:40:06 +08:00 committed by ACRN System Integration
parent 1884bb0551
commit 304ae38161

View File

@ -20,6 +20,20 @@
#include <sprintf.h> #include <sprintf.h>
#include <cat.h> #include <cat.h>
/* stack_frame is linked with the sequence of stack operation in arch_switch_to() */
struct stack_frame {
uint64_t rdi;
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t rbp;
uint64_t rbx;
uint64_t rflag;
uint64_t rip;
uint64_t maigc;
};
uint64_t vcpu_get_gpreg(const struct acrn_vcpu *vcpu, uint32_t reg) uint64_t vcpu_get_gpreg(const struct acrn_vcpu *vcpu, uint32_t reg)
{ {
const struct run_context *ctx = const struct run_context *ctx =
@ -677,26 +691,32 @@ void schedule_vcpu(struct acrn_vcpu *vcpu)
release_schedule_lock(vcpu->pcpu_id); release_schedule_lock(vcpu->pcpu_id);
} }
/*
* @pre (&vcpu->stack[CONFIG_STACK_SIZE] & (CPU_STACK_ALIGN - 1UL)) == 0
*/
static uint64_t build_stack_frame(struct acrn_vcpu *vcpu) static uint64_t build_stack_frame(struct acrn_vcpu *vcpu)
{ {
uint64_t rsp = (uint64_t)&vcpu->stack[CONFIG_STACK_SIZE - 1]; uint64_t stacktop = (uint64_t)&vcpu->stack[CONFIG_STACK_SIZE];
uint64_t *sp; struct stack_frame *frame;
uint64_t *ret;
rsp &= ~(CPU_STACK_ALIGN - 1UL); frame = (struct stack_frame *)stacktop;
sp = (uint64_t *)rsp; frame -= 1;
*sp-- = SP_BOTTOM_MAGIC; frame->maigc = SP_BOTTOM_MAGIC;
*sp-- = (uint64_t)run_sched_thread; /*return address*/ frame->rip = (uint64_t)run_sched_thread; /*return address*/
*sp-- = 0UL; /* flag */ frame->rflag = 0UL;
*sp-- = 0UL; /* rbx */ frame->rbx = 0UL;
*sp-- = 0UL; /* rbp */ frame->rbp = 0UL;
*sp-- = 0UL; /* r12 */ frame->r12 = 0UL;
*sp-- = 0UL; /* r13 */ frame->r13 = 0UL;
*sp-- = 0UL; /* r14 */ frame->r14 = 0UL;
*sp-- = 0UL; /* r15 */ frame->r15 = 0UL;
*sp = (uint64_t)&vcpu->sched_obj; /*rdi*/ frame->rdi = (uint64_t)&vcpu->sched_obj;
return (uint64_t)sp; ret = &frame->rdi;
return (uint64_t) ret;
} }
/* help function for vcpu create */ /* help function for vcpu create */