@@ -12,6 +12,8 @@ SUBDIRS-y += misc
SUBDIRS-y += examples
SUBDIRS-y += hotplug
SUBDIRS-y += xentrace
+SUBDIRS-y += golang
+#FIXME: Have golang controlled by a configure variable
SUBDIRS-$(CONFIG_XCUTILS) += xcutils
SUBDIRS-$(CONFIG_X86) += firmware
SUBDIRS-y += console
@@ -312,6 +314,20 @@ subdir-install-debugger/gdbsx: .phony
subdir-all-debugger/gdbsx: .phony
$(MAKE) -C debugger/gdbsx all
+subdir-all-golang/xenlight: .phony
+ $(MAKE) -C golang all
+
+subdir-clean-golang/xenlight: .phony
+ $(MAKE) -C golang clean
+
+subdir-install-golang/xenlight: .phony
+ $(MAKE) -C golang install
+
+subdir-build-golang/xenlight: .phony
+ $(MAKE) -C golang build
+
+subdir-distclean-golang/xenlight: .phony
+ $(MAKE) -C golang distclean
subdir-clean-debugger/kdd subdir-distclean-debugger/kdd: .phony
$(MAKE) -C debugger/kdd clean
new file mode 100644
@@ -0,0 +1,29 @@
+XEN_ROOT=$(CURDIR)/../..
+GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight
+include $(XEN_ROOT)/tools/Rules.mk
+
+BINARY = xenlight.a
+GO ?= go
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build: xenlight/xenlight.a
+
+.PHONY: install
+install: build
+ $(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
+ $(INSTALL_DATA) xenlight/xenlight.go $(DESTDIR)$(GOLANG_SRC)
+
+.PHONY: clean
+clean:
+ $(RM) xenlight/$(BINARY)
+
+.PHONY: distclean
+distclean: clean
+
+xenlight/xenlight.a: xenlight/xenlight.go
+ $(GO) build -o $@ $<
+
+-include $(DEPS)
new file mode 100644
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of the
+ * License only.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+package xenlight
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "time"
+ "unsafe"
+)
+
+/*
+ * Types: Builtins
+ */
+type Context struct {
+ ctx *C.libxl_ctx
+}
+
+/*
+ * Context
+ */
+var Ctx Context
+
+func (Ctx *Context) IsOpen() bool {
+ return Ctx.ctx != nil
+}
+
+func (Ctx *Context) Open() (err error) {
+ if Ctx.ctx != nil {
+ return
+ }
+
+ ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
+
+ if ret != 0 {
+ //FIXME: proper error
+ err = createError("Allocating libxl context: ", ret)
+ }
+ return
+}
+
+func (Ctx *Context) Close() (err error) {
+ ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
+ Ctx.ctx = nil
+
+ if ret != 0 {
+ //FIXME: proper error
+ err = createError("Freeing libxl context: ", ret)
+ }
+ return
+}
+
+func (Ctx *Context) CheckOpen() (err error) {
+ if Ctx.ctx == nil {
+ err = fmt.Errorf("Context not opened")
+ }
+ return
+}