Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
josecm committed May 13, 2020
0 parents commit 2b0d23a
Show file tree
Hide file tree
Showing 21 changed files with 2,543 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/*
*.o
*.d
*.elf
100 changes: 100 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#
# 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 := bao_bare-metal_guest

CROSS_COMPILE ?= aarch64-elf-
CC:=$(CROSS_COMPILE)gcc
AS:=$(CROSS_COMPILE)as
LD:=$(CROSS_COMPILE)ld
OBJCOPY:=$(CROSS_COMPILE)objcopy
OBJDUMP:=$(CROSS_COMPILE)objdump

OPT_LEVEL = 3
DEBUG_LEVEL = 0

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

SRC_DIR:=./src
BUILD_DIR:=build/$(PLAT)
TARGET:=$(BUILD_DIR)/$(NAME)
PLAT_DIR:=$(SRC_DIR)/platform/$(PLAT)
SRC_DIRS:=$(SRC_DIR) $(PLAT_DIR)
INC_DIRS:=$(addsuffix /inc, $(SRC_DIRS))

ifeq ($(wildcard $(PLAT_DIR)),)
$(error unsupported platform $(PLAT))
endif

LINKER_SCRIPT:=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)
DIRS:=$(sort $(dir $(OBJS) $(DEPS)))

GENERIC_FLAGS = -march=armv8-a -O$(OPT_LEVEL) -g$(DEBUG_LEVEL)
ASFLAGS = $(GENERIC_FLAGS)
CFLAGS = $(GENERIC_FLAGS)
CPPFLAGS = $(addprefix -I, $(INC_DIRS)) -MD -MF $@.d
LDFLAGS = $(GENERIC_FLAGS) -nostartfiles -ffreestanding -static

all: $(TARGET).bin

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

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

$(TARGET).elf: $(OBJS) $(LD_FILE)
$(CC) $(LDFLAGS) -T$(LINKER_SCRIPT) $(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 $@

.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
50 changes: 50 additions & 0 deletions linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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.
*
*/

SECTIONS {

.start : {
*(.start)
}

.text : {
*(.text*)
}

.rodata : {
*(.rodata*)
}

.data : {
*(.data .data.*)
*(.sdata .sdata.* .sdata2.*)
}

.page_tables : {
*(.page_tables)
}

.bss (NOLOAD) : {
__bss_start = .;
*(.bss* .sbss*)
*(COMMON)
__bss_end = .;
}

_stack_base = .;
. += 0x4000 * 4;
_heap_base = .;
}
127 changes: 127 additions & 0 deletions src/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 2b0d23a

Please sign in to comment.