Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: ukvm backend for OSX #173

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
efbe53f
refactor ukvm to add ukvm backend
djwillia Dec 19, 2016
b557632
make ukvmclock look more like tscclock
djwillia Jan 10, 2017
9c1a416
fix spacing and run checkpatch
djwillia Jan 30, 2017
99c01e7
remove USE_LOCKS from malloc: clang 3.9 takes issues with the macros …
djwillia Feb 1, 2017
699753a
virtio backend builds on MacOSX
djwillia Feb 1, 2017
dd9d309
no need to drop -nostdlib if using GNU binutils ld
djwillia Feb 2, 2017
b303e0c
run-virtio on OSX
djwillia Feb 2, 2017
354434b
build mach-o (except for link)
djwillia Feb 10, 2017
4056fb6
refactor to consolidate ukvm asm parts
djwillia Feb 15, 2017
8761f20
merge
djwillia Feb 15, 2017
19e6ea8
replace old license header
djwillia Feb 15, 2017
8168bcb
linker flags for mach-o
djwillia Feb 15, 2017
e1ca780
merge with asm-refactor
djwillia Feb 15, 2017
c00bc12
mach-o can now be built
djwillia Feb 15, 2017
9019153
replace load_code
djwillia Feb 16, 2017
de567c6
move elf loader out of the way
djwillia Feb 16, 2017
8d648a5
deciphering lc_unixthread
djwillia Feb 16, 2017
6b3dd2a
can load and run a mach-o
djwillia Feb 16, 2017
c9dae33
merge mach-o build
djwillia Feb 16, 2017
ac33155
move loaders into platform-specific monitor code
djwillia Feb 16, 2017
09a7f6a
make new test dir for rdtsc tests
djwillia Mar 8, 2017
d564985
toggle rdtsc trapping
djwillia Mar 9, 2017
0a2b86f
loop 1000000 times
djwillia Mar 14, 2017
01a7d99
try to pass correct things to mirage linker
djwillia Mar 14, 2017
7ba1ac5
remove linker offset hacks
djwillia Mar 15, 2017
32ead88
Merge branch 'monitors-mach-o-load-merge' into rdtsc-testing
djwillia Mar 15, 2017
116b266
new traps etc for https app
djwillia Mar 24, 2017
710dd6c
merge with master
djwillia Mar 27, 2017
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ opam-virtio-uninstall:
opam-ukvm-install: solo5-kernel-ukvm.pc ukvm
mkdir -p $(OPAM_UKVM_INCDIR) $(OPAM_UKVM_LIBDIR)
cp kernel/solo5.h $(OPAM_UKVM_INCDIR)/solo5.h
cp ukvm/ukvm.h $(OPAM_UKVM_INCDIR)/ukvm.h
cp monitors/ukvm.h $(OPAM_UKVM_INCDIR)/ukvm.h
mkdir -p $(OPAM_UKVM_INCDIR)/host
cp -R include-host/. $(OPAM_UKVM_INCDIR)/host
cp kernel/ukvm/solo5.o kernel/ukvm/solo5.lds $(OPAM_UKVM_LIBDIR)
mkdir -p $(OPAM_BINDIR)
mkdir -p $(OPAM_UKVM_LIBDIR)/src
cp -R ukvm $(OPAM_UKVM_LIBDIR)/src
cp ukvm/ukvm-configure $(OPAM_BINDIR)
cp -R monitors $(OPAM_UKVM_LIBDIR)/src
cp monitors/ukvm-configure $(OPAM_BINDIR)
mkdir -p $(PREFIX)/lib/pkgconfig
cp solo5-kernel-ukvm.pc $(PREFIX)/lib/pkgconfig

Expand Down
10 changes: 5 additions & 5 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Be clear about some common programs we use!
AS=as
CC=cc
LD=ld
OBJCOPY=objcopy
CC?=cc
LD?=ld
OBJCOPY?=objcopy

# This Makefile defines global defaults for building Solo5 (kernel/) and the
# in-tree test programs. These can be overriden either on the command line, or
Expand All @@ -30,6 +29,7 @@ include $(TOP)/Makeconf
# Exported to OPAM via pkg-config.
MD_CFLAGS=$(HOST_CFLAGS) -ffreestanding -mno-red-zone
# Likewise.
LDFLAGS=-nostdlib -z max-page-size=0x1000 -static
# LDFLAGS=-nostdlib -z max-page-size=0x1000 -static
LDFLAGS=-static -arch x86_64
# CFLAGS used for building kernel/ and in-tree tests.
CFLAGS=$(MD_CFLAGS) -isystem $(TOP)/include-host -std=gnu99 -Wall -Wextra -Werror -O2 -g
63 changes: 62 additions & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ die()

cc_is_clang()
{
${CC:-cc} -v 2>&1 | grep -q "clang version"
${CC:-cc} -v 2>&1 | grep -q "clang"
}

cc_is_gcc()
{
${CC:-cc} -v 2>&1 | grep -q "^gcc version"
}

ld_is_x86_64_elf()
{
${LD:-ld} --help 2>&1 |grep "supported targets" 2>&1 | grep -q elf64-x86-64
}

objcopy_exists()
{
${OBJCOPY:-objcopy} --version 2>&1 | grep -q "GNU objcopy"
}

# Host-provided header files are installed here for in-tree builds. OPAM will
# install these to $(OPAM_INCDIR)/host where they will be picked up by
# pkg-config.
Expand Down Expand Up @@ -76,6 +86,57 @@ case $(uname -s) in
BUILD_UKVM=
BUILD_VIRTIO="yes"
;;
Darwin)
# On MacOSX we use clang and approximate the FreeBSD header
# copying. While clang is good enough to build the kernel, we
# need a cross-linker that understands ELF, rather than
# Mach-O. As of Jan 2016, the llvm linker was not able to
# link the unikernel, so we require a GNU binutils linker (and
# objcopy).
#
# Binutils from Homebrew does not contain ld, so you can build
# from source. After downloading binutils source, do:
#
# ./configure --prefix=/usr/local/opt/binutils-x86_64 \
# --target=x86_64-elf --disable-nls --disable-werror
# make
# make install
#
# Then add the newly compiled cross-binutils to your path
# export PATH="/usr/local/opt/binutils-x86_64/bin:$PATH"
cc_is_clang || die "Only 'clang' is supported on MacOSX"
# ld_is_x86_64_elf || die "LD must be a cross-linker for elf64-x86-64." \
# "You may need to build GNU binutils from source."
# objcopy_exists || die "OBJCOPY should point to GNU objcopy." \
# "You may need to build GNU binutils from source."
INCDIR=/usr/include
SRCS_MACH="machine/_types.h machine/endian.h \
machine/_limits.h"
SRCS_SYS="sys/cdefs.h sys/_symbol_aliasing.h sys/_posix_availability.h \
sys/_endian.h sys/_types.h"
SRCS_SYS_PTHREAD="sys/_pthread/_pthread_types.h"
SRCS_X86="i386/endian.h i386/_types.h i386/_limits.h"
SRCS_LIBKERN="libkern/_OSByteOrder.h"
SRCS_LIBKERN_I386="libkern/i386/_OSByteOrder.h"
SRCS="_types.h"

mkdir -p ${HOST_INCDIR}
mkdir -p ${HOST_INCDIR}/machine ${HOST_INCDIR}/sys ${HOST_INCDIR}/i386 \
${HOST_INCDIR}/libkern ${HOST_INCDIR}/libkern/i386 \
${HOST_INCDIR}/sys/_pthread
for f in ${SRCS_MACH}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/machine; done
for f in ${SRCS_SYS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/sys; done
for f in ${SRCS_SYS_PTHREAD}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/sys/_pthread; done
for f in ${SRCS_X86}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/i386; done
for f in ${SRCS_LIBKERN}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/libkern; done
for f in ${SRCS_LIBKERN_I386}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/libkern/i386; done
for f in ${SRCS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}; done

# Where is the stack protector library on OSX?
HOST_CFLAGS="-nostdlibinc -arch x86_64 -fno-stack-protector"
BUILD_UKVM="yes"
BUILD_VIRTIO=
;;
*)
die "Unsupported build OS: $(uname -s)"
;;
Expand Down
11 changes: 5 additions & 6 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,28 @@ include $(TOP)/Makefile.common

COMMON_COBJS=\
abort.o \
cpu.o \
cpu_vectors.o \
ee_printf.o \
intr.o \
lib.o \
malloc.o \
exit.o \
pvclock.o

UKVM_COBJS=\
ukvm/kernel.o \
ukvm/gdt.o \
ukvm/io.o \
ukvm/platform.o \
ukvm/platform_intr.o \
ukvm/mem.o \
ukvm/time.o \
ukvm/ukvmclock.o \
$(COMMON_COBJS)

VIRTIO_COBJS=\
virtio/boot.o \
virtio/cpu.o \
virtio/cpu_vectors.o \
virtio/kernel.o \
virtio/platform.o \
virtio/intr.o \
virtio/platform_intr.o \
virtio/mem.o \
virtio/pci.o \
Expand Down Expand Up @@ -78,7 +77,7 @@ virtio/solo5.o: $(VIRTIO_COBJS) virtio/solo5.lds

ukvm/solo5.o: $(UKVM_COBJS) ukvm/solo5.lds
$(LD) -r $(LDFLAGS) -o $@ $(UKVM_COBJS)
$(OBJCOPY) -w -G solo5_\* -G _start $@ $@
# $(OBJCOPY) -w -G solo5_\* -G _start $@ $@

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion kernel/abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

static void puts(const char *s)
{
(void)platform_puts(s, strlen(s));
(void)solo5_console_write(s, strlen(s));
}

void _assert_fail(const char *file, const char *line, const char *e)
Expand Down
85 changes: 85 additions & 0 deletions kernel/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2015-2017 Contributors as noted in the AUTHORS file
*
* This file is part of Solo5, a unikernel base layer.
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose with or without fee is hereby granted, provided
* that the above copyright notice and this permission notice appear
* in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef __CPU_H__
#define __CPU_H__

/* compiler-only memory "barrier" */
#define cpu_cc_barrier() __asm__ __volatile__("" : : : "memory")
#define cpu_mfence_memory() __asm__ ("mfence" ::: "memory");

static inline void cpu_halt(void) __attribute__((noreturn));
static inline void cpu_halt(void) {
for (;;)
__asm__("hlt");
}

static inline uint64_t cpu_rdtsc(void)
{
uint32_t edx_, eax_;

__asm__("rdtsc" : "=a" (eax_), "=d" (edx_));
return (uint64_t)eax_ + ((uint64_t)edx_ << 32);
}

static inline void cpu_wrmsr(uint64_t a, uint32_t b, uint32_t c)
{
__asm__ __volatile("wrmsr" ::
"c" (a),
"a" (b),
"d" (c)
);
}

static inline void cpu_x86_cpuid(uint32_t level,
uint32_t *eax_out, uint32_t *ebx_out,
uint32_t *ecx_out, uint32_t *edx_out)
{
uint32_t eax_, ebx_, ecx_, edx_;

__asm__(
"cpuid"
: "=a" (eax_), "=b" (ebx_), "=c" (ecx_), "=d" (edx_)
: "0" (level)
);
*eax_out = eax_;
*ebx_out = ebx_;
*ecx_out = ecx_;
*edx_out = edx_;
}



static inline uint64_t cpu_mul64_32(uint64_t a, uint32_t b)
{
uint64_t prod;

__asm__ (
"mul %%rdx ; "
"shrd $32, %%rdx, %%rax"
: "=a" (prod)
: "0" (a), "d" ((uint64_t)b)
);

return prod;
}


#endif
2 changes: 1 addition & 1 deletion kernel/ee_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static int ee_vprintf(const char *fmt, va_list args)
n = vsnprintf(buf, PRINTF_BUF_LEN, fmt, args);
assert(n < PRINTF_BUF_LEN);

return platform_puts(buf, n);
return solo5_console_write(buf, n);
}

int printf(const char *fmt, ...)
Expand Down
Loading