Skip to content

Commit 40cf542

Browse files
committed
hv: riscv: Add riscv build skeleton and hello world binary
This commit adds riscv build skeleton and adds some dummy files that prints out hello world. To build riscv acrn.out/acrn.bin, simply: make hypervisor \ BOARD=<any existing board> \ SCENARIO=<any existing scenario> \ ARCH=riscv We still need to specify board and scenario as those were required by project level makefile. Tracked-On: #8782 Signed-off-by: Yifan Liu <[email protected]> Acked-by: Wang, Yu1 <[email protected]>
1 parent f996b1f commit 40cf542

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed

hypervisor/arch/riscv/Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
CROSS_COMPILE ?= riscv64-linux-gnu-
2+
3+
CC = $(CROSS_COMPILE)gcc
4+
AS = $(CROSS_COMPILE)as
5+
AR = $(CROSS_COMPILE)ar
6+
LD = $(CROSS_COMPILE)ld
7+
OBJCOPY = $(CROSS_COMPILE)objcopy
8+
9+
ARCH_LDSCRIPT_IN = arch/riscv/link_ram.ld.in
10+
11+
CFLAGS +=
12+
13+
ASFLAGS +=
14+
15+
# g expands to i, m, a, f, d, zicsr and zifencei.
16+
# h for hypervisor extension
17+
RV_ISA += gh
18+
RV_ISA += zbb
19+
RV_ISA += zicbom
20+
21+
ARCH_CFLAGS += -march=rv64$(subst $() $(),_,$(RV_ISA))
22+
ARCH_CFLAGS += -mabi=lp64d
23+
ARCH_CFLAGS += -mcmodel=medany
24+
25+
ARCH_ASFLAGS += -march=rv64$(subst $() $(),_,$(RV_ISA))
26+
27+
# HV host assembly sources
28+
HOST_S_SRCS += arch/riscv/dummy_entry.S
29+
30+
# HV host C sources
31+
HOST_C_SRCS += arch/riscv/dummy.c
32+
33+
# Virtual platform assembly sources
34+
VP_S_SRCS +=
35+
36+
# Virtual platform C sources
37+
VP_C_SRCS += arch/riscv/guest/dummy_guest.c
38+
39+
HOST_C_OBJS := $(patsubst %.c,$(HV_OBJDIR)/%.o,$(HOST_C_SRCS))
40+
HOST_S_OBJS := $(patsubst %.S,$(HV_OBJDIR)/%.o,$(HOST_S_SRCS))
41+
VP_C_OBJS := $(patsubst %.c,$(HV_OBJDIR)/%.o,$(VP_C_SRCS))
42+
VP_S_OBJS := $(patsubst %.S,$(HV_OBJDIR)/%.o,$(VP_S_SRCS))
43+
44+
HOST_MOD := $(HV_MODDIR)/host_mod.a
45+
VP_MOD := $(HV_MODDIR)/vp_mod.a
46+
47+
MODULES += $(HOST_MOD)
48+
MODULES += $(VP_MOD)
49+
50+
$(HOST_MOD): $(HOST_C_OBJS) $(HOST_S_OBJS)
51+
$(AR) $(ARFLAGS) $(HOST_MOD) $(HOST_C_OBJS) $(HOST_S_OBJS)
52+
53+
$(VP_MOD): $(VP_C_OBJS) $(VP_S_OBJS)
54+
$(AR) $(ARFLAGS) $(VP_MOD) $(VP_C_OBJS) $(VP_S_OBJS)

hypervisor/arch/riscv/dummy.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#define SBI_EXT_CONSOLE_PUTCHAR 0x01
2+
#define SBI_EXT_CONSOLE_GETCHAR 0x02
3+
4+
#define SBI_FID_CONSOLE_PUTCHAR 0x0
5+
#define SBI_FID_CONSOLE_GETCHAR 0x0
6+
7+
extern long sbi_call(long eid, long fid, long arg0, long arg1, long arg2, long arg3);
8+
9+
static void sbi_putchar(int ch) {
10+
sbi_call(SBI_EXT_CONSOLE_PUTCHAR, SBI_FID_CONSOLE_PUTCHAR, ch, 0, 0, 0);
11+
}
12+
13+
static void sbi_puts(const char *str) {
14+
while (*str) {
15+
sbi_putchar(*str);
16+
str++;
17+
}
18+
}
19+
20+
void print_hello_world(void) {
21+
sbi_puts("Hello World!\n");
22+
}
23+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.section .text
2+
.global _start
3+
4+
_start:
5+
csrci sstatus, 0x2
6+
li sp, 0x81010000
7+
call print_hello_world
8+
9+
wait_loop:
10+
wfi
11+
j wait_loop
12+
13+
.global sbi_call
14+
sbi_call:
15+
mv t0, a0
16+
mv t1, a1
17+
18+
mv a0, a2
19+
mv a1, a3
20+
mv a2, a4
21+
mv a3, a5
22+
mv a4, a6
23+
mv a5, a7
24+
25+
mv a6, t1
26+
mv a7, t0
27+
28+
ecall
29+
30+
ret
31+

hypervisor/arch/riscv/guest/dummy_guest.c

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ENTRY(_start)
2+
3+
MEMORY {
4+
RAM : ORIGIN = 0x81000000, LENGTH = 64K
5+
}
6+
7+
SECTIONS {
8+
/* TODO: Replace hardcodes with macros defined in config header */
9+
. = 0x81000000;
10+
11+
.text : {
12+
*(.text)
13+
*(.text.*)
14+
*(.note.gnu.build-id)
15+
} > RAM
16+
17+
.rodata : {
18+
*(.rodata)
19+
*(.rodata.*)
20+
} > RAM
21+
22+
.data : {
23+
*(.data)
24+
*(.data.*)
25+
} > RAM
26+
27+
.bss (NOLOAD) : {
28+
*(.bss)
29+
*(.bss.*)
30+
*(COMMON)
31+
} > RAM
32+
33+
. = ALIGN(8);
34+
_end = .;
35+
36+
. = 0x81010000;
37+
_stack_top = .;
38+
}

0 commit comments

Comments
 (0)