Skip to content

Commit

Permalink
working with pmu_interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
maskedarray committed Aug 7, 2023
0 parents commit f52340b
Show file tree
Hide file tree
Showing 599 changed files with 62,744 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bao-baremetal-guest/build/
bao-hypervisor/build/
bao-hypervisor/bin/
bao-hypervisor/.git/
bao-hypervisor/.vscode/
opensbi/build/
opensbi/.git/
bitstream/
linux/
linux_image/
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Prologue
Follow the same prologue as [here](https://github.com/ninolomata/bao-cva6-guide).

# Linux
Build the Linux image + dtb blob:
```
make ARCH=rv64 IMAGE=../../linux_image/Image DTB=../occamy_bao.dtb TARGET=linux-rv64-alsaqr
```
# Bao-Hypervisor
```
git clone https://github.com/ninolomata/bao-hypervisor.git
git checkout openpiton-temp
cp -r ../bao/configs/* ./configs
cp -r ../bao/platform/* ./src/platform
make PLATFORM=alsaqr CONFIG=alsaqr-linux CONFIG_BUILTIN=y
```
# Opensbi
```
git clone https://github.com/AlSaqr-platform/opensbi.git
make PLATFORM=fpga/alsaqr FW_PAYLOAD=y FW_PAYLOAD_PATH=../bao-hypervisor/bin/alsaqr/builtin-configs/alsaqr-linux/bao.bin FW_FDT_PATH=../linux/occamy.dtb
```

# Running code

As of now, to interface with Alsaqr on FPGA we use [openocd](https://github.com/riscv/riscv-openocd). The debugger we use is [this one](https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/).

* Open the hw manager and load the bitstream **alsaqr_xilinx_llc_pc.bit** (pre-built available on the folder **bitstream**)

* Open 3 terminals:

### Terminal 1

```
openocd -f zcu-102-ariane.cfg
```
### Terminal 2

```
screen -L /dev/ttyUSBi 115200
```
### Terminal 3

```
riscv64-unknown-elf-gdb <path-to-compiled-elf>
from gdb terminal
(a) target remote :3333
(b) monitor reset halt
(c) load
(d) c
```
At this point you are supposed to see the uart prints on the screen.
4 changes: 4 additions & 0 deletions bao-baremetal-guest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/*
*.o
*.d
*.elf
6 changes: 6 additions & 0 deletions bao-baremetal-guest/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"uart.h": "c",
"irq.h": "c"
}
}
134 changes: 134 additions & 0 deletions bao-baremetal-guest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#
# Bao, a Lightweight Static Partitioning Hypervisor
#
# Copyright (c) Bao Project (www.bao-project.org), 2019-
#
# Authors:
# Jose Martins <[email protected]>
# Sandro Pinto <[email protected]>
#
# Bao is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2 as published by the Free
# Software Foundation, with a special exception exempting guest code from such
# license. See the COPYING file in the top-level directory for details.
#
#


NAME := baremetal
OPT_LEVEL = 2
DEBUG_LEVEL = 3


ifneq ($(MAKECMDGOALS), clean)
ifeq ($(PLATFORM),)
$(error Undefined platform)
endif
endif

SRC_DIR:=./src
BUILD_DIR:=build/$(PLATFORM)
TARGET:=$(BUILD_DIR)/$(NAME)
CORE_DIR:=$(SRC_DIR)/core
PLATFORM_DIR:=$(SRC_DIR)/platform/$(PLATFORM)
DRIVERS_DIR:=$(SRC_DIR)/drivers
SRC_DIRS:=$(SRC_DIR) $(CORE_DIR) $(PLATFORM_DIR)
INC_DIRS:=$(addsuffix /inc, $(SRC_DIRS))

ifeq ($(wildcard $(PLATFORM_DIR)),)
$(error unsupported platform $(PLATFORM))
endif

-include $(SRC_DIR)/sources.mk
C_SRC+=$(addprefix $(SRC_DIR)/, $(src_c_srcs))

-include $(CORE_DIR)/sources.mk
C_SRC+=$(addprefix $(CORE_DIR)/, $(core_c_srcs))

-include $(PLATFORM_DIR)/plat.mk
-include $(PLATFORM_DIR)/sources.mk
C_SRC+=$(addprefix $(PLATFORM_DIR)/, $(plat_c_srcs))
ASM_SRC+=$(addprefix $(PLATFORM_DIR)/, $(plat_s_srcs))

SRC_DIRS+= $(foreach driver, $(drivers), $(DRIVERS_DIR)/$(driver))
INC_DIRS+= $(foreach driver, $(drivers), $(DRIVERS_DIR)/$(driver)/inc)
-include $(foreach driver, $(drivers), $(DRIVERS_DIR)/$(driver)/sources.mk)
C_SRC+=$(addprefix $(DRIVERS_DIR)/, $(driver_c_srcs))
ASM_SRC+=$(addprefix $(DRIVERS_DIR)/, $(driver_s_srcs))

ARCH_DIR:= $(SRC_DIR)/arch/$(ARCH)
SRC_DIRS+= $(ARCH_DIR)
INC_DIRS+= $(ARCH_DIR)/inc
-include $(ARCH_DIR)/arch.mk
-include $(ARCH_DIR)/sources.mk
C_SRC+=$(addprefix $(ARCH_DIR)/, $(arch_c_srcs))
ASM_SRC+=$(addprefix $(ARCH_DIR)/, $(arch_s_srcs))

LD_FILE:= $(SRC_DIR)/linker.ld
GEN_LD_FILE:= $(BUILD_DIR)/linker.ld
#C_SRC = $(foreach src_dir, $(SRC_DIRS), $(wildcard $(src_dir)/*.c))
#ASM_SRC = $(foreach src_dir, $(SRC_DIRS), $(wildcard $(src_dir)/*.S))
OBJS = $(C_SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) $(ASM_SRC:$(SRC_DIR)/%.S=$(BUILD_DIR)/%.o)
DEPS = $(OBJS:%=%.d) $(GEN_LD_FILE).d
DIRS:=$(sort $(dir $(OBJS) $(DEPS)))

CC=$(CROSS_COMPILE)gcc
AS=$(CROSS_COMPILE)as
LD=$(CROSS_COMPILE)ld
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump

GENERIC_FLAGS = $(ARCH_GENERIC_FLAGS) -O$(OPT_LEVEL) -g$(DEBUG_LEVEL) -static
ASFLAGS = $(GENERIC_FLAGS) $(ARCH_ASFLAGS)
CFLAGS = $(GENERIC_FLAGS) $(ARCH_CFLAGS)
CPPFLAGS = $(ARCH_CPPFLAGS) $(addprefix -I, $(INC_DIRS)) -MD -MF $@.d
ifneq ($(SINGLE_CORE),)
CPPFLAGS+=-DSINGLE_CORE=y
endif
LDFLAGS = $(GENERIC_FLAGS) $(ARCH_LDFLAGS) -nostartfiles
all: $(TARGET).bin

ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif

$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@

$(TARGET).elf: $(OBJS) $(GEN_LD_FILE)
$(CC) $(LDFLAGS) -T$(GEN_LD_FILE) $(OBJS) -o $@
$(OBJDUMP) -S $@ > $(TARGET).asm
$(OBJDUMP) -x -d --wide $@ > $(TARGET).lst

$(BUILD_DIR):
mkdir -p $@

$(OBJS): | $(BUILD_DIR)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.S
$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@

$(GEN_LD_FILE): $(LD_FILE)
$(CC) $(CPPFLAGS) -E -x assembler-with-cpp $< | grep "^[^#;]" > $@

.SECONDEXPANSION:

$(OBJS) $(DEPS): | $$(@D)/

$(DIRS):
mkdir -p $@


clean:
@rm -rf build
@rm -f *.elf
@rm -f *.bin
@rm -f *.asm
@rm -f *.lst



.PHONY: all clean
7 changes: 7 additions & 0 deletions bao-baremetal-guest/src/arch/armv8/arch.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CROSS_COMPILE ?=aarch64-none-elf-

ARCH_GENERIC_FLAGS = -march=armv8-a -DGIC_VERSION=$(GIC_VERSION) #-mtls-dialect=trad
ARCH_ASFLAGS =
ARCH_CFLAGS =
ARCH_CPPFLAGS =
ARCH_LDFLAGS =
127 changes: 127 additions & 0 deletions bao-baremetal-guest/src/arch/armv8/exceptions.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Bao, a Lightweight Static Partitioning Hypervisor
*
* Copyright (c) Bao Project (www.bao-project.org), 2019-
*
* Authors:
* Jose Martins <[email protected]>
* Sandro Pinto <[email protected]>
*
* Bao is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License version 2 as published by the Free
* Software Foundation, with a special exception exempting guest code from such
* license. See the COPYING file in the top-level directory for details.
*
*/

#define ENTRY_SIZE (0x80)

.macro SAVE_REGS

sub sp, sp, #(22 * 8)

stp x0, x1, [sp, #(8*0)]
stp x2, x3, [sp, #(8*2)]
stp x4, x5, [sp, #(8*4)]
stp x6, x7, [sp, #(8*6)]
stp x8, x9, [sp, #(8*8)]
stp x10, x11, [sp, #(8*10)]
stp x12, x13, [sp, #(8*12)]
stp x14, x15, [sp, #(8*14)]
stp x16, x17, [sp, #(8*16)]
stp x18, x19, [sp, #(8*18)]
stp x29, x30, [sp, #(8*28)]
.endm

.macro RESTORE_REGS
ldp x0, x1, [sp, #(8*0)]
ldp x2, x3, [sp, #(8*2)]
ldp x4, x5, [sp, #(8*4)]
ldp x6, x7, [sp, #(8*6)]
ldp x8, x9, [sp, #(8*8)]
ldp x10, x11, [sp, #(8*10)]
ldp x12, x13, [sp, #(8*12)]
ldp x14, x15, [sp, #(8*14)]
ldp x16, x17, [sp, #(8*16)]
ldp x18, x19, [sp, #(8*18)]
ldp x29, x30, [sp, #(8*28)]

add sp, sp, #(22 * 8)
.endm

.balign 0x800
.global _exception_vector
_exception_vector:
/*
* EL1 with SP0
*/
.balign ENTRY_SIZE
curr_el_sp0_sync:
b .
.balign ENTRY_SIZE
curr_el_sp0_irq:
b .
.balign ENTRY_SIZE
curr_el_sp0_fiq:
b .
.balign ENTRY_SIZE
curr_el_sp0_serror:
b .


/*
* EL1 with SPx
*/
.balign ENTRY_SIZE
curr_el_spx_sync:
b .
.balign ENTRY_SIZE
curr_el_spx_irq:
SAVE_REGS
bl gic_handle
RESTORE_REGS
eret
.balign ENTRY_SIZE
curr_el_spx_fiq:
SAVE_REGS
bl gic_handle
RESTORE_REGS
eret
.balign ENTRY_SIZE
curr_el_spx_serror:
b .

/*
* Lower EL using AArch64
*/

.balign ENTRY_SIZE
lower_el_aarch64_sync:
b .
.balign ENTRY_SIZE
lower_el_aarch64_irq:
b .
.balign ENTRY_SIZE
lower_el_aarch64_fiq:
b .
.balign ENTRY_SIZE
lower_el_aarch64_serror:
b .

/*
* Lower EL using AArch32
*/
.balign ENTRY_SIZE
lower_el_aarch32_sync:
b .
.balign ENTRY_SIZE
lower_el_aarch32_irq:
b .
.balign ENTRY_SIZE
lower_el_aarch32_fiq:
b .
.balign ENTRY_SIZE
lower_el_aarch32_serror:
b .

.balign ENTRY_SIZE
Loading

0 comments on commit f52340b

Please sign in to comment.