Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.o
*.flat
*.elf
*.raw
.pc
patches
.stgit-*
Expand Down
2 changes: 2 additions & 0 deletions guest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ all: directories $(shell cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD >
standalone: all
@scripts/mkstandalone.sh

stitched: $(TEST_DIR)/stitched.raw

install: standalone
mkdir -p $(DESTDIR)
install tests/* $(DESTDIR)
Expand Down
6 changes: 6 additions & 0 deletions guest/lib/x86/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "fwcfg.h"
#include "alloc_phys.h"

extern char bss_start;
extern char edata;

struct mbi_bootinfo {
Expand Down Expand Up @@ -42,6 +43,11 @@ u32 initrd_size;

static char env[ENV_SIZE];

void bss_init(void)
{
memset(&bss_start, 0, &edata - &bss_start);
}

void setup_multiboot(struct mbi_bootinfo *bootinfo)
{
struct mbi_module *mods;
Expand Down
30 changes: 30 additions & 0 deletions guest/scripts/mkcasetable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

output=$1
shift 1

cat <<EOF > $output
#include "stitched.h"

EOF

IFS=$'\n' tests=($(sort <<< "$*"))
unset IFS

for test in ${tests[*]}; do
echo "extern int main_$test(int ac, char **av);" >> $output
done

cat <<EOF >> $output

struct unit_test unit_tests[] = {
EOF

for test in ${tests[*]}; do
echo "{ .name = \"$test\", .fn = main_$test }," >> $output
done

cat <<EOF >> $output
{ .name = NULL, .fn = NULL },
};
EOF
1 change: 1 addition & 0 deletions guest/x86/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case_table.c
47 changes: 39 additions & 8 deletions guest/x86/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ KEEP_FRAME_POINTER := y

libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)

# We want to keep intermediate file: %.elf and %.o
.PRECIOUS: %.elf %.o
# We want to keep intermediate file: %.elf and %.o
.PRECIOUS: %.elf %.o $(TEST_DIR)/%_prelink.o

FLATLIBS = lib/libcflat.a $(libgcc)
%.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
%.elf: %_prelink.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds \
$(filter %.o, $^) $(FLATLIBS)
@chmod a-x $@
Expand All @@ -48,6 +48,13 @@ FLATLIBS = lib/libcflat.a $(libgcc)
$(OBJCOPY) -O elf32-i386 $^ $@
@chmod a-x $@

%.raw: %.elf
$(OBJCOPY) -O binary $^ $@.tmp
dd if=/dev/zero of=$@ bs=1 count=$(shell echo $$((0x`readelf -S $< | grep "\.text" | grep -E -o "[0-9a-f]{16}"` - 0x400000)))
dd if=$@.tmp of=$@ conv=notrunc oflag=append
@rm $@.tmp
@chmod a-x $@

tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
$(TEST_DIR)/smptest.flat $(TEST_DIR)/port80.flat \
$(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
Expand All @@ -68,25 +75,49 @@ endif

test_cases: $(tests-common) $(tests) $(tests-api)

unstitched-test-cases = $(TEST_DIR)/realmode.flat
stitched-test-cases = $(filter-out $(unstitched-test-cases),$(tests-common) $(tests))
case_table.o = $(TEST_DIR)/case_table.o
stitched.o = $(TEST_DIR)/stitched.o

$(case_table.o:.o=.c):
scripts/mkcasetable.sh $@ $(patsubst $(TEST_DIR)/%.flat,%,$(stitched-test-cases))

$(TEST_DIR)/stitched.elf: $(stitched-test-cases:.flat=_prelink.o) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o) $(case_table.o) $(stitched.o)
$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds \
$(filter %.o, $^) $(FLATLIBS)
@chmod a-x $@

$(TEST_DIR)/%_prelink.o: $(TEST_DIR)/%.o
$(LD) -r -o $@ $^
@$(OBJCOPY) \
--keep-global-symbol=main \
--add-symbol main_$*=.text:0x`nm $@ | grep "T main" | egrep -o "[0-9a-f]{16}"`,function,global \
--weaken-symbol=main \
$@

$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/x86 -I lib

$(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
$(CC) -m32 -nostdlib -o $@ -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^

$(TEST_DIR)/realmode.o: bits = 32

$(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o
$(TEST_DIR)/kvmclock_test_prelink.o: $(TEST_DIR)/kvmclock.o

$(TEST_DIR)/hyperv_synic_prelink.o: $(TEST_DIR)/hyperv.o

$(TEST_DIR)/hyperv_synic.elf: $(TEST_DIR)/hyperv.o
$(TEST_DIR)/hyperv_stimer_prelink.o: $(TEST_DIR)/hyperv.o

$(TEST_DIR)/hyperv_stimer.elf: $(TEST_DIR)/hyperv.o
$(TEST_DIR)/hyperv_connections_prelink.o: $(TEST_DIR)/hyperv.o

$(TEST_DIR)/hyperv_connections.elf: $(TEST_DIR)/hyperv.o
$(TEST_DIR)/vmx_prelink.o: $(TEST_DIR)/vmx_tests.o

arch_clean:
$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
$(TEST_DIR)/.*.d lib/x86/.*.d \
$(tests-api) api/*.o api/*.a api/.*.d
$(tests-api) api/*.o api/*.a api/.*.d \
$(case_table.o:.o=.c)

api/%.o: CXXFLAGS += -m32 -std=gnu++11

Expand Down
7 changes: 2 additions & 5 deletions guest/x86/Makefile.x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ tests += $(TEST_DIR)/syscall.flat
tests += $(TEST_DIR)/svm.flat
tests += $(TEST_DIR)/vmx.flat
tests += $(TEST_DIR)/tscdeadline_latency.flat
tests += $(TEST_DIR)/intel-iommu.flat
tests += $(TEST_DIR)/intel_iommu.flat
tests += $(TEST_DIR)/vmware_backdoors.flat
tests += $(TEST_DIR)/hyperv_clock.flat

include $(SRCDIR)/$(TEST_DIR)/Makefile.common

$(TEST_DIR)/hyperv_clock.elf: $(TEST_DIR)/hyperv_clock.o

$(TEST_DIR)/vmx.elf: $(TEST_DIR)/vmx_tests.o
9 changes: 8 additions & 1 deletion guest/x86/cstart64.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ipi_vector = 0x20

max_cpus = 64

.bss
.section stack

. = . + 4096 * max_cpus
.align 16
Expand Down Expand Up @@ -148,6 +148,12 @@ switch_to_5level:

prepare_64:
lgdt gdt64_desc
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss

enter_long_mode:
mov %cr4, %eax
Expand Down Expand Up @@ -220,6 +226,7 @@ ap_start64:
jmp 1b

start64:
call bss_init
call load_tss
call mask_pic_interrupts
call enable_apic
Expand Down
7 changes: 7 additions & 0 deletions guest/x86/flat.lds
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ SECTIONS
. = ALIGN(16);
.rodata : { *(.rodata) }
. = ALIGN(16);
.stack : { *(stack) }
. = ALIGN(16);
bss_start = .;
.bss : { *(.bss) }
. = ALIGN(4K);
edata = .;

/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}

ENTRY(start)
File renamed without changes.
33 changes: 33 additions & 0 deletions guest/x86/stitched.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "stitched.h"

int main(int ac, char **av)
{
struct unit_test *ut;

if (ac > 0) {
ut = unit_tests;
while (ut->fn != NULL) {
if (strcmp(av[0], ut->name) == 0) {
printf("Run test %s\n", av[0]);
return ut->fn(ac, av);
} else {
ut++;
}
}

printf("No test found for %s\n", av[0]);
}

/* Print the list of available tests */
printf("Available tests:\n");

ut = unit_tests;
while (ut->fn != NULL) {
printf("\t%s\n", ut->name);
ut++;
}

printf("End of available tests\n");

return 0;
}
13 changes: 13 additions & 0 deletions guest/x86/stitched.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __MAIN_H
#define __MAIN_H

#include "libcflat.h"

struct unit_test {
const char *name;
int (*fn)(int ac, char **av);
};

extern struct unit_test unit_tests[];

#endif