[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/include/alloca.h b/src/bsp/lk/include/alloca.h
new file mode 100644
index 0000000..ce617fe
--- /dev/null
+++ b/src/bsp/lk/include/alloca.h
@@ -0,0 +1,6 @@
+#if !defined(__ALLOCA_H)
+#define __ALLOCA_H
+
+#define alloca(size) __builtin_alloca (size)
+
+#endif  /* !__ALLOCA_H */
diff --git a/src/bsp/lk/include/app.h b/src/bsp/lk/include/app.h
new file mode 100644
index 0000000..95cd13b
--- /dev/null
+++ b/src/bsp/lk/include/app.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2009-2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __APP_H
+#define __APP_H
+
+#include <stddef.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+/* app support api */
+void apps_init(void); /* one time setup */
+
+/* app entry point */
+struct app_descriptor;
+typedef void (*app_init)(const struct app_descriptor *);
+typedef void (*app_entry)(const struct app_descriptor *, void *args);
+
+/* app startup flags */
+#define APP_FLAG_DONT_START_ON_BOOT 0x1
+#define APP_FLAG_CUSTOM_STACK_SIZE 0x2
+
+/* each app needs to define one of these to define its startup conditions */
+struct app_descriptor {
+	const char *name;
+	app_init  init;
+	app_entry entry;
+	unsigned int flags;
+	size_t stack_size;
+};
+
+#define APP_START(appname) const struct app_descriptor _app_##appname __ALIGNED(sizeof(void *)) __SECTION(".apps") = { .name = #appname,
+
+#define APP_END };
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/arch.h b/src/bsp/lk/include/arch.h
new file mode 100644
index 0000000..43e2719
--- /dev/null
+++ b/src/bsp/lk/include/arch.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ARCH_H
+#define __ARCH_H
+
+#include <compiler.h>
+#include <sys/types.h>
+
+__BEGIN_CDECLS
+
+void arch_early_init(void);
+void arch_init(void);
+void arch_quiesce(void);
+void arch_chain_load(void *entry, ulong arg0, ulong arg1, ulong arg2, ulong arg3) __NO_RETURN;
+void arch_enter_uspace(vaddr_t entry_point, vaddr_t user_stack_top) __NO_RETURN;
+
+__END_CDECLS
+
+/* arch specific bits */
+#include <arch/defines.h>
+
+#endif
diff --git a/src/bsp/lk/include/arch/mmu.h b/src/bsp/lk/include/arch/mmu.h
new file mode 100644
index 0000000..dc6386b
--- /dev/null
+++ b/src/bsp/lk/include/arch/mmu.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <arch.h>
+#include <sys/types.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+#define ARCH_MMU_FLAG_CACHED            (0<<0)
+#define ARCH_MMU_FLAG_UNCACHED          (1<<0)
+#define ARCH_MMU_FLAG_UNCACHED_DEVICE   (2<<0) /* only exists on some arches, otherwise UNCACHED */
+#define ARCH_MMU_FLAG_CACHE_MASK        (3<<0)
+
+#define ARCH_MMU_FLAG_PERM_USER         (1<<2)
+#define ARCH_MMU_FLAG_PERM_RO           (1<<3)
+#define ARCH_MMU_FLAG_PERM_NO_EXECUTE   (1<<4)
+#define ARCH_MMU_FLAG_NS                (1<<5) /* NON-SECURE */
+#define ARCH_MMU_FLAG_INVALID           (1<<7)  /* indicates that flags are not specified */
+
+int arch_mmu_map(vaddr_t vaddr, paddr_t paddr, uint count, uint flags);
+int arch_mmu_unmap(vaddr_t vaddr, uint count);
+status_t arch_mmu_query(vaddr_t vaddr, paddr_t *paddr, uint *flags);
+vaddr_t arch_mmu_pick_spot(vaddr_t base, uint prev_region_arch_mmu_flags,
+                           vaddr_t end,  uint next_region_arch_mmu_flags,
+                           vaddr_t align, size_t size, uint arch_mmu_flags);
+
+void arch_disable_mmu(void);
+
+__END_CDECLS
+
diff --git a/src/bsp/lk/include/arch/mp.h b/src/bsp/lk/include/arch/mp.h
new file mode 100644
index 0000000..2c3b2c5
--- /dev/null
+++ b/src/bsp/lk/include/arch/mp.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <sys/types.h>
+#include <kernel/mp.h>
+
+/* send inter processor interrupt, if supported */
+status_t arch_mp_send_ipi(mp_cpu_mask_t target, mp_ipi_t ipi);
+
+void arch_mp_init_percpu(void);
diff --git a/src/bsp/lk/include/arch/ops.h b/src/bsp/lk/include/arch/ops.h
new file mode 100644
index 0000000..f097751
--- /dev/null
+++ b/src/bsp/lk/include/arch/ops.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ARCH_OPS_H
+#define __ARCH_OPS_H
+
+#ifndef ASSEMBLY
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdbool.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+/* fast routines that most arches will implement inline */
+static void arch_enable_ints(void);
+static void arch_disable_ints(void);
+static bool arch_ints_disabled(void);
+static bool arch_in_int_handler(void);
+
+static int atomic_swap(volatile int *ptr, int val);
+static int atomic_add(volatile int *ptr, int val);
+static int atomic_and(volatile int *ptr, int val);
+static int atomic_or(volatile int *ptr, int val);
+
+static uint32_t arch_cycle_count(void);
+
+static uint arch_curr_cpu_num(void);
+
+/* Use to align structures on cache lines to avoid cpu aliasing. */
+#define __CPU_ALIGN __ALIGNED(CACHE_LINE)
+
+#endif // !ASSEMBLY
+#define ICACHE 1
+#define DCACHE 2
+#define UCACHE (ICACHE|DCACHE)
+#ifndef ASSEMBLY
+
+void arch_disable_cache(uint flags);
+void arch_enable_cache(uint flags);
+
+void arch_clean_cache_range(addr_t start, size_t len);
+void arch_clean_invalidate_cache_range(addr_t start, size_t len);
+void arch_invalidate_cache_range(addr_t start, size_t len);
+void arch_sync_cache_range(addr_t start, size_t len);
+
+void arch_idle(void);
+
+__END_CDECLS
+
+#endif // !ASSEMBLY
+
+#include <arch/arch_ops.h>
+
+#endif
diff --git a/src/bsp/lk/include/arch/thread.h b/src/bsp/lk/include/arch/thread.h
new file mode 100644
index 0000000..06de51d
--- /dev/null
+++ b/src/bsp/lk/include/arch/thread.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ARCH_THREAD_H
+#define __ARCH_THREAD_H
+
+// give the arch code a chance to declare the arch_thread struct
+#include <arch/arch_thread.h>
+
+struct thread;
+
+void arch_thread_initialize(struct thread *);
+void arch_context_switch(struct thread *oldthread, struct thread *newthread);
+
+#endif
diff --git a/src/bsp/lk/include/asm.h b/src/bsp/lk/include/asm.h
new file mode 100644
index 0000000..92ba270
--- /dev/null
+++ b/src/bsp/lk/include/asm.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2008-2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ASM_H
+#define __ASM_H
+
+#define FUNCTION(x) .global x; .type x,STT_FUNC; x:
+#define DATA(x) .global x; .type x,STT_OBJECT; x:
+
+#define LOCAL_FUNCTION(x) .type x,STT_FUNC; x:
+#define LOCAL_DATA(x) .type x,STT_OBJECT; x:
+
+#endif
+
diff --git a/src/bsp/lk/include/assert.h b/src/bsp/lk/include/assert.h
new file mode 100644
index 0000000..dec406e
--- /dev/null
+++ b/src/bsp/lk/include/assert.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ASSERT_H
+#define __ASSERT_H
+
+#include <compiler.h>
+#include <debug.h>
+
+#define ASSERT(x) \
+    do { if (unlikely(!(x))) { panic("ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
+
+#if LK_DEBUGLEVEL > 1
+#define DEBUG_ASSERT(x) \
+    do { if (unlikely(!(x))) { panic("DEBUG ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
+#else
+#define DEBUG_ASSERT(x) \
+    do { } while(0)
+#endif
+
+#define assert(e) DEBUG_ASSERT(e)
+
+#ifndef __cplusplus
+#define static_assert(e) STATIC_ASSERT(e)
+#endif
+
+#endif
diff --git a/src/bsp/lk/include/bits.h b/src/bsp/lk/include/bits.h
new file mode 100644
index 0000000..7b9b8aa
--- /dev/null
+++ b/src/bsp/lk/include/bits.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __BITS_H
+#define __BITS_H
+
+#include <compiler.h>
+#include <arch/ops.h>
+
+__BEGIN_CDECLS;
+
+#define clz(x) __builtin_clz(x)
+#define ctz(x) __builtin_ctz(x)
+
+#define BIT(x, bit) ((x) & (1UL << (bit)))
+#define BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
+#define BITS(x, high, low) ((x) & (((1UL<<((high)+1))-1) & ~((1UL<<(low))-1)))
+#define BITS_SHIFT(x, high, low) (((x) >> (low)) & ((1UL<<((high)-(low)+1))-1))
+#define BIT_SET(x, bit) (((x) & (1UL << (bit))) ? 1 : 0)
+
+#define BITMAP_BITS_PER_WORD (sizeof(unsigned long) * 8)
+#define BITMAP_NUM_WORDS(x) (((x) + BITMAP_BITS_PER_WORD - 1) / BITMAP_BITS_PER_WORD)
+#define BITMAP_WORD(x) ((x) / BITMAP_BITS_PER_WORD)
+#define BITMAP_BIT_IN_WORD(x) ((x) & (BITMAP_BITS_PER_WORD - 1))
+
+#define BITMAP_BITS_PER_INT (sizeof(unsigned int) * 8)
+#define BITMAP_BIT_IN_INT(x) ((x) & (BITMAP_BITS_PER_INT - 1))
+#define BITMAP_INT(x) ((x) / BITMAP_BITS_PER_INT)
+
+#define BIT_MASK(x) (((x) >= sizeof(unsigned long) * 8) ? (0UL-1) : ((1UL << (x)) - 1))
+
+static inline int bitmap_set(unsigned long *bitmap, int bit)
+{
+	unsigned long mask = 1UL << BITMAP_BIT_IN_INT(bit);
+	return atomic_or(&((int*)bitmap)[BITMAP_INT(bit)], mask) & mask ? 1 : 0;
+}
+
+static inline int bitmap_clear(unsigned long *bitmap, int bit)
+{
+	unsigned long mask = 1UL << BITMAP_BIT_IN_INT(bit);
+
+	return atomic_and(&((int*)bitmap)[BITMAP_INT(bit)], ~mask) & mask ? 1:0;
+}
+
+static inline int bitmap_test(unsigned long *bitmap, int bit)
+{
+	return BIT_SET(bitmap[BITMAP_WORD(bit)], BITMAP_BIT_IN_WORD(bit));
+}
+
+/* find first zero bit starting from LSB */
+static inline unsigned long _ffz(unsigned long x)
+{
+	return __builtin_ffsl(~x) - 1;
+}
+
+static inline int bitmap_ffz(unsigned long *bitmap, int numbits)
+{
+	uint i;
+	int bit;
+
+	for (i = 0; i < BITMAP_NUM_WORDS(numbits); i++) {
+		if (bitmap[i] == ~0UL)
+			continue;
+		bit = i * BITMAP_BITS_PER_WORD + _ffz(bitmap[i]);
+		if (bit < numbits)
+			return bit;
+		return -1;
+	}
+	return -1;
+}
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/boot_args.h b/src/bsp/lk/include/boot_args.h
new file mode 100644
index 0000000..bd5a751
--- /dev/null
+++ b/src/bsp/lk/include/boot_args.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _MT_BOOT_ARGS_H_
+#define _MT_BOOT_ARGS_H_
+
+#include <sys/types.h>
+#include <platform/emi_info_v1.h>
+
+typedef struct {
+    u32 maggic_number;
+    u32 boot_mode;
+    u32 boot_reason;
+    u32 rgu_mode;
+    u32 ddr_reserve_enable;
+    u32 ddr_reserve_success;
+    u32 ddr_reserve_ready;
+    emi_info_t emi_info;
+    u64 dram_size;
+    u32 cold_reset;
+} BOOT_ARGUMENT;
+
+#define BOOT_ARGUMENT_MAGIC 0x504c504c
+#endif
diff --git a/src/bsp/lk/include/boot_mode.h b/src/bsp/lk/include/boot_mode.h
new file mode 100644
index 0000000..a0ca654
--- /dev/null
+++ b/src/bsp/lk/include/boot_mode.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _MT_BOOT_MODE_H_
+#define _MT_BOOT_MODE_H_
+
+#include <stdint.h>
+
+/*
+ *uint32_t get_boot_mode() - determine which boot mode to boot
+ *
+ * return:
+ *     code of boot_mode which represent normal, recovery or fastboot mode.
+ *
+ */
+uint32_t get_boot_mode(void);
+
+enum {
+    NORMAL_BOOT = 0,
+    RECOVERY_BOOT,
+    FASTBOOT_BOOT
+};
+
+#endif
diff --git a/src/bsp/lk/include/compiler.h b/src/bsp/lk/include/compiler.h
new file mode 100644
index 0000000..44e2587
--- /dev/null
+++ b/src/bsp/lk/include/compiler.h
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2008-2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __COMPILER_H
+#define __COMPILER_H
+
+#ifndef __ASSEMBLY__
+
+#if __GNUC__
+#define likely(x)       __builtin_expect(!!(x), 1)
+#define unlikely(x)     __builtin_expect(!!(x), 0)
+#define __UNUSED __attribute__((__unused__))
+#define __PACKED __attribute__((packed))
+#define __ALIGNED(x) __attribute__((aligned(x)))
+#define __PRINTFLIKE(__fmt,__varargs) __attribute__((__format__ (__printf__, __fmt, __varargs)))
+#define __SCANFLIKE(__fmt,__varargs) __attribute__((__format__ (__scanf__, __fmt, __varargs)))
+#define __SECTION(x) __attribute((section(x)))
+#define __PURE __attribute((pure))
+#define __CONST __attribute((const))
+#define __NO_RETURN __attribute__((noreturn))
+#define __MALLOC __attribute__((malloc))
+#define __WEAK __attribute__((weak))
+#define __GNU_INLINE __attribute__((gnu_inline))
+#define __GET_CALLER(x) __builtin_return_address(0)
+#define __GET_FRAME(x) __builtin_frame_address(0)
+#define __NAKED __attribute__((naked))
+#define __ISCONSTANT(x) __builtin_constant_p(x)
+#define __NO_INLINE __attribute((noinline))
+#define __SRAM __NO_INLINE __SECTION(".sram.text")
+#define __CONSTRUCTOR __attribute__((constructor))
+#define __DESTRUCTOR __attribute__((destructor))
+#define __OPTIMIZE(x) __attribute__((optimize(x)))
+
+#define INCBIN(symname, sizename, filename, section)                    \
+    __asm__ (".section " section "; .align 4; .globl "#symname);        \
+    __asm__ (""#symname ":\n.incbin \"" filename "\"");                 \
+    __asm__ (".section " section "; .align 1;");                        \
+    __asm__ (""#symname "_end:");                                       \
+    __asm__ (".section " section "; .align 4; .globl "#sizename);       \
+    __asm__ (""#sizename ": .long "#symname "_end - "#symname " - 1");  \
+    extern unsigned char symname[];                                     \
+    extern unsigned int sizename
+
+#define INCFILE(symname, sizename, filename) INCBIN(symname, sizename, filename, ".rodata")
+
+/* look for gcc 3.0 and above */
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)
+#define __ALWAYS_INLINE __attribute__((always_inline))
+#else
+#define __ALWAYS_INLINE
+#endif
+
+/* look for gcc 3.1 and above */
+#if !defined(__DEPRECATED) // seems to be built in in some versions of the compiler
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define __DEPRECATED __attribute((deprecated))
+#else
+#define __DEPRECATED
+#endif
+#endif
+
+/* look for gcc 3.3 and above */
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+/* the may_alias attribute was introduced in gcc 3.3; before that, there
+ * was no way to specify aliasiang rules on a type-by-type basis */
+#define __MAY_ALIAS __attribute__((may_alias))
+
+/* nonnull was added in gcc 3.3 as well */
+#define __NONNULL(x) __attribute((nonnull x))
+#else
+#define __MAY_ALIAS
+#define __NONNULL(x)
+#endif
+
+/* look for gcc 3.4 and above */
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define __WARN_UNUSED_RESULT __attribute((warn_unused_result))
+#else
+#define __WARN_UNUSED_RESULT
+#endif
+
+#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) && !defined(__clang__))
+#define __EXTERNALLY_VISIBLE __attribute__((externally_visible))
+#else
+#define __EXTERNALLY_VISIBLE
+#endif
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)
+#define __UNREACHABLE __builtin_unreachable()
+#else
+#define __UNREACHABLE
+#endif
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#ifdef __cplusplus
+#define STATIC_ASSERT(e) static_assert(e, #e)
+#else
+#define STATIC_ASSERT(e) _Static_assert(e, #e)
+#endif
+#else
+#define STATIC_ASSERT(e) extern char (*ct_assert(void)) [sizeof(char[1 - 2*!(e)])]
+#endif
+
+/* compiler fence */
+#define CF do { __asm__ volatile("" ::: "memory"); } while(0)
+
+#define __WEAK_ALIAS(x) __attribute__((weak, alias(x)))
+#define __ALIAS(x) __attribute__((alias(x)))
+
+#define __EXPORT __attribute__ ((visibility("default")))
+#define __LOCAL  __attribute__ ((visibility("hidden")))
+
+#define __THREAD __thread
+
+#define __offsetof(type, field) __builtin_offsetof(type, field)
+
+#else
+
+#define likely(x)       (x)
+#define unlikely(x)     (x)
+#define __UNUSED
+#define __PACKED
+#define __ALIGNED(x)
+#define __PRINTFLIKE(__fmt,__varargs)
+#define __SCANFLIKE(__fmt,__varargs)
+#define __SECTION(x)
+#define __PURE
+#define __CONST
+#define __NONNULL(x)
+#define __DEPRECATED
+#define __WARN_UNUSED_RESULT
+#define __ALWAYS_INLINE
+#define __MAY_ALIAS
+#define __NO_RETURN
+#endif
+
+#endif
+
+/* TODO: add type check */
+#define countof(a) (sizeof(a) / sizeof((a)[0]))
+
+/* macro-expanding concat */
+#define concat(a, b) __ex_concat(a, b)
+#define __ex_concat(a, b) a ## b
+
+/* CPP header guards */
+#ifdef __cplusplus
+#define __BEGIN_CDECLS  extern "C" {
+#define __END_CDECLS    }
+#else
+#define __BEGIN_CDECLS
+#define __END_CDECLS
+#endif
+
+#endif
diff --git a/src/bsp/lk/include/ctype.h b/src/bsp/lk/include/ctype.h
new file mode 100644
index 0000000..c330e68
--- /dev/null
+++ b/src/bsp/lk/include/ctype.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __CTYPE_H
+#define __CTYPE_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+int isalnum(int c);
+int isalpha(int c);
+int isblank(int c);
+int iscntrl(int c);
+int isdigit(int c);
+int isgraph(int c);
+int islower(int c);
+int isprint(int c);
+int ispunct(int c);
+int isspace(int c);
+int isupper(int c);
+int isxdigit(int c);
+
+int tolower(int c);
+int toupper(int c);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/debug.h b/src/bsp/lk/include/debug.h
new file mode 100644
index 0000000..e0e1111
--- /dev/null
+++ b/src/bsp/lk/include/debug.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2008-2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEBUG_H
+#define __DEBUG_H
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <compiler.h>
+#include <platform/debug.h>
+#include <list.h>
+#include <stdio.h>
+
+#if !defined(LK_DEBUGLEVEL)
+#define LK_DEBUGLEVEL 0
+#endif
+
+/* debug levels */
+#define CRITICAL 0
+#define ALWAYS 0
+#define INFO 1
+#define SPEW 2
+
+__BEGIN_CDECLS
+
+typedef struct __print_callback print_callback_t;
+struct __print_callback {
+	struct list_node entry;
+	void (*print)(print_callback_t *cb, const char *str, size_t len);
+};
+
+#if !DISABLE_DEBUG_OUTPUT
+
+/* input/output */
+int _dprintf(const char *fmt, ...) __PRINTFLIKE(1, 2);
+
+// Obtain the panic file descriptor.
+FILE get_panic_fd(void);
+
+/* dump memory */
+void hexdump(const void *ptr, size_t len);
+void hexdump8_ex(const void *ptr, size_t len, uint64_t disp_addr_start);
+
+#else
+
+/* input/output */
+static inline int __PRINTFLIKE(1, 2) _dprintf(const char *fmt, ...) { return 0; }
+
+/* dump memory */
+static inline void hexdump(const void *ptr, size_t len) { }
+static inline void hexdump8_ex(const void *ptr, size_t len, uint64_t disp_addr_start) { }
+
+#endif /* DISABLE_DEBUG_OUTPUT */
+
+static inline void hexdump8(const void *ptr, size_t len)
+{
+	hexdump8_ex(ptr, len, (uint64_t)((addr_t)ptr));
+}
+
+/* register callback to receive debug prints */
+void register_print_callback(print_callback_t *cb);
+void unregister_print_callback(print_callback_t *cb);
+
+#define dprintf(level, x...) do { if ((level) <= LK_DEBUGLEVEL) { _dprintf(x); } } while (0)
+
+/* systemwide halts */
+void _panic(void *caller, const char *fmt, ...) __PRINTFLIKE(2, 3) __NO_RETURN;
+#define panic(x...) _panic(__GET_CALLER(), x)
+
+#define PANIC_UNIMPLEMENTED panic("%s unimplemented\n", __PRETTY_FUNCTION__)
+
+/* spin the cpu for a period of (short) time */
+void spin(uint32_t usecs);
+
+/* spin the cpu for a certain number of cpu cycles */
+void spin_cycles(uint32_t usecs);
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/dev/accelerometer.h b/src/bsp/lk/include/dev/accelerometer.h
new file mode 100644
index 0000000..343a68c
--- /dev/null
+++ b/src/bsp/lk/include/dev/accelerometer.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_ACCELEROMETER_H
+#define __DEV_ACCELEROMETER_H
+typedef struct
+{
+        double x;
+        double y;
+        double z;
+} position_vector_t;
+
+status_t acc_read_xyz(position_vector_t * pos_vector);
+
+#endif
diff --git a/src/bsp/lk/include/dev/class/block.h b/src/bsp/lk/include/dev/class/block.h
new file mode 100644
index 0000000..240699d
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/block.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_BLOCK_H
+#define __DEV_CLASS_BLOCK_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* block interface */
+struct block_ops {
+	struct driver_ops std;
+
+	ssize_t (*get_block_size)(struct device *dev);
+	ssize_t (*get_block_count)(struct device *dev);
+
+	ssize_t (*write)(struct device *dev, off_t offset, const void *buf, size_t count);
+	ssize_t (*read)(struct device *dev, off_t offset, void *buf, size_t count);
+	
+	status_t (*flush)(struct device *dev);
+};
+
+__BEGIN_CDECLS
+
+ssize_t class_block_get_size(struct device *dev);
+ssize_t class_block_get_count(struct device *dev);
+ssize_t class_block_write(struct device *dev, off_t offset, const void *buf, size_t count);
+ssize_t class_block_read(struct device *dev, off_t offset, void *buf, size_t count);
+status_t class_block_flush(struct device *dev);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/fb.h b/src/bsp/lk/include/dev/class/fb.h
new file mode 100644
index 0000000..e29b266
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/fb.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_FB_H
+#define __DEV_CLASS_FB_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+struct fb_info {
+	void *addr;
+	size_t line_width;
+	size_t width;
+	size_t height;
+	size_t bpp;
+};
+
+/* fb interface */
+struct fb_ops {
+	struct driver_ops std;
+
+	status_t (*set_mode)(struct device *dev, size_t width, size_t height, size_t bpp);
+	status_t (*get_info)(struct device *dev, struct fb_info *info);
+	status_t (*update)(struct device *dev);
+	status_t (*update_region)(struct device *dev, size_t x, size_t y, size_t width, size_t height);
+};
+
+__BEGIN_CDECLS
+
+status_t class_fb_set_mode(struct device *dev, size_t width, size_t height, size_t bpp);
+status_t class_fb_get_info(struct device *dev, struct fb_info *info);
+status_t class_fb_update(struct device *dev);
+status_t class_fb_update_region(struct device *dev, size_t x, size_t y, size_t width, size_t height);
+
+__END_CDECLS
+
+#endif
+
+
diff --git a/src/bsp/lk/include/dev/class/i2c.h b/src/bsp/lk/include/dev/class/i2c.h
new file mode 100644
index 0000000..d38fbcb
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/i2c.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_I2C_H
+#define __DEV_CLASS_I2C_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* i2c interface */
+struct i2c_ops {
+	struct driver_ops std;
+
+	status_t (*write)(struct device *dev, uint8_t addr, const void *buf, size_t len);
+	status_t (*read)(struct device *dev, uint8_t addr, void *buf, size_t len);
+
+	status_t (*write_reg)(struct device *dev, uint8_t addr, uint8_t reg, uint8_t value);
+	status_t (*read_reg)(struct device *dev, uint8_t addr, uint8_t reg, void *value);
+};
+
+__BEGIN_CDECLS
+
+status_t class_i2c_write(struct device *dev, uint8_t addr, const void *buf, size_t len);
+status_t class_i2c_read(struct device *dev, uint8_t addr, void *buf, size_t len);
+status_t class_i2c_write_reg(struct device *dev, uint8_t addr, uint8_t reg, uint8_t value);
+status_t class_i2c_read_reg(struct device *dev, uint8_t addr, uint8_t reg, void *value);
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/dev/class/netif.h b/src/bsp/lk/include/dev/class/netif.h
new file mode 100644
index 0000000..099b40c
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/netif.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_NETIF_H
+#define __DEV_CLASS_NETIF_H
+
+#include <list.h>
+#include <compiler.h>
+#include <dev/driver.h>
+
+struct netstack_state;
+struct pbuf;
+
+/* netif interface */
+struct netif_ops {
+	struct driver_ops std;
+
+	status_t (*set_state)(struct device *dev, struct netstack_state *state);
+	ssize_t (*get_hwaddr)(struct device *dev, void *buf, size_t max_len);
+	ssize_t (*get_mtu)(struct device *dev);
+
+	status_t (*set_status)(struct device *dev, bool up);
+	status_t (*output)(struct device *dev, struct pbuf *p);
+	status_t (*mcast_filter)(struct device *dev, const uint8_t *mac, int action);
+};
+
+__BEGIN_CDECLS
+
+/* netif API */
+status_t class_netif_set_state(struct device *dev, struct netstack_state *state);
+ssize_t class_netif_get_hwaddr(struct device *dev, void *buf, size_t max_len);
+ssize_t class_netif_get_mtu(struct device *dev);
+status_t class_netif_set_status(struct device *dev, bool up);
+status_t class_netif_output(struct device *dev, struct pbuf *p);
+status_t class_netif_mcast_filter(struct device *dev, const uint8_t *mac, int action);
+
+status_t class_netif_add(struct device *dev);
+
+/* network stack API - called by drivers */
+status_t class_netstack_input(struct device *dev, struct netstack_state *state, struct pbuf *p);
+
+status_t class_netstack_wait_for_network(lk_time_t timeout);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/spi.h b/src/bsp/lk/include/dev/class/spi.h
new file mode 100644
index 0000000..dad8959
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/spi.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_SPI_H
+#define __DEV_CLASS_SPI_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* spi transaction flags */
+enum spi_flags {
+	SPI_READ        = (1<<0),
+	SPI_WRITE       = (1<<1),
+	SPI_CS_ASSERT   = (1<<2),
+	SPI_CS_DEASSERT = (1<<3),
+};
+
+/* spi transaction */
+struct spi_transaction {
+	enum spi_flags flags;
+	void *tx_buf;
+	void *rx_buf;
+	size_t len;
+};
+
+/* spi interface */
+struct spi_ops {
+	struct driver_ops std;
+
+	ssize_t (*transaction)(struct device *dev, struct spi_transaction *txn, size_t count);
+};
+
+__BEGIN_CDECLS
+
+ssize_t class_spi_transaction(struct device *dev, struct spi_transaction *txn, size_t count);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/uart.h b/src/bsp/lk/include/dev/class/uart.h
new file mode 100644
index 0000000..aabf101
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/uart.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_UART_H
+#define __DEV_CLASS_UART_H
+
+#include <dev/driver.h>
+
+/* uart interface */
+struct uart_ops {
+	struct driver_ops std;
+
+	ssize_t (*read)(struct device *dev, void *buf, size_t len);
+	ssize_t (*write)(struct device *dev, const void *buf, size_t len);
+};
+
+
+ssize_t class_uart_read(struct device *dev, void *buf, size_t len);
+ssize_t class_uart_write(struct device *dev, const void *buf, size_t len);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/display.h b/src/bsp/lk/include/dev/display.h
new file mode 100644
index 0000000..5da46b8
--- /dev/null
+++ b/src/bsp/lk/include/dev/display.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008-2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_DISPLAY_H
+#define __DEV_DISPLAY_H
+
+#include <stdbool.h>
+#include <lib/gfx.h>
+
+int display_init(void *framebuffer);
+int display_enable(bool enable);
+void display_pre_freq_change(void);
+void display_post_freq_change(void);
+
+struct display_info {
+	void *framebuffer;
+	gfx_format format;
+	uint width;
+	uint height;
+	uint stride;
+
+	// Update function
+	void (*flush)(uint starty, uint endy);
+};
+
+status_t display_get_info(struct display_info *info);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/driver.h b/src/bsp/lk/include/dev/driver.h
new file mode 100644
index 0000000..787a593
--- /dev/null
+++ b/src/bsp/lk/include/dev/driver.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_DRIVER_H
+#define __DEV_DRIVER_H
+
+#include <sys/types.h>
+#include <list.h> // for containerof
+#include <compiler.h>
+
+struct driver;
+
+/*
+ * Contains the data pertaining to an instance of a device. More than one
+ * instance may exist for a given driver type (i.e. uart0, uart1, etc..).
+ */
+struct device {
+	const char *name;
+	const struct driver *driver;
+
+	/* instance specific config data populated at instantiation */
+	const void *config;
+
+	/* instance specific data populated by the driver at init */
+	void *state;
+	
+	// TODO: add generic state, such as suspend/resume state, etc...
+};
+
+/* device class, mainly used as a unique magic pointer to validate ops */
+struct device_class {
+	const char *name;
+};
+
+/* standard driver ops; extensions should contain this ops structure */
+struct driver_ops {
+	const struct device_class *device_class;
+
+	status_t (*init)(struct device *dev);
+	status_t (*fini)(struct device *dev);
+
+	status_t (*suspend)(struct device *dev);
+	status_t (*resume)(struct device *dev);
+};
+
+/* describes a driver, one per driver type */
+struct driver {
+	const char *type;
+	const struct driver_ops *ops;
+};
+
+#define DRIVER_EXPORT(type_, ops_) \
+	const struct driver concat(__driver_, type_) \
+		__ALIGNED(sizeof(void *)) __SECTION(".drivers") = { \
+		.type = #type_, \
+		.ops = ops_, \
+	}
+
+#define DEVICE_INSTANCE(type_, name_, config_) \
+	extern struct driver concat(__driver_, type_); \
+	struct device concat(__device_, concat(type_, concat(_, name_))) \
+		__ALIGNED(sizeof(void *)) __SECTION(".devices") = { \
+		.name = #name_, \
+		.driver = &concat(__driver_, type_), \
+		.config = config_, \
+	}
+
+/*
+ * returns the driver specific ops pointer given the device instance, specifc
+ * ops type, and generic ops member name within the specific ops structure.
+ */
+#define device_get_driver_ops(dev, type, member) ({ \
+	type *__ops = NULL; \
+	if (dev && dev->driver && dev->driver->ops) \
+		__ops = containerof(dev->driver->ops, type, member); \
+	__ops; \
+})
+
+#define device_get_by_name(type_, name_) ({ \
+	extern struct device concat(__device_, concat(type_, concat(_, name_))); \
+	&concat(__device_, concat(type_, concat(_, name_))); \
+})
+
+status_t device_init_all(void);
+status_t device_fini_all(void);
+
+status_t device_init(struct device *dev);
+status_t device_fini(struct device *dev);
+
+status_t device_suspend(struct device *dev);
+status_t device_resume(struct device *dev);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/ethernet.h b/src/bsp/lk/include/dev/ethernet.h
new file mode 100644
index 0000000..7042cea
--- /dev/null
+++ b/src/bsp/lk/include/dev/ethernet.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_ETHERNET_H
+#define __DEV_ETHERNET_H
+
+#include <sys/types.h>
+
+/* Queue an ethernet frame for send.
+**
+** CRC and minimum length padding are handled by the driver.
+**
+** Data is malloc()'d and ownership is transfered to the ethernet
+** device which will free() it once the packet is transmitted.
+**
+*/
+int ethernet_send(void *data, unsigned length);
+
+status_t ethernet_init(void); /* initialize the ethernet device */
+
+#endif
diff --git a/src/bsp/lk/include/dev/fbcon.h b/src/bsp/lk/include/dev/fbcon.h
new file mode 100644
index 0000000..131f093
--- /dev/null
+++ b/src/bsp/lk/include/dev/fbcon.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DEV_FBCON_H
+#define __DEV_FBCON_H
+
+#define FB_FORMAT_RGB565 0
+
+struct fbcon_config {
+	void        *base;
+	unsigned    width;
+	unsigned    height;
+	unsigned    stride;
+	unsigned    bpp;
+	unsigned    format;
+
+	void        (*update_start)(void);
+	int     (*update_done)(void);
+};
+
+void fbcon_setup(struct fbcon_config *cfg);
+void fbcon_putc(char c);
+
+#endif /* __DEV_FBCON_H */
diff --git a/src/bsp/lk/include/dev/flash_nor.h b/src/bsp/lk/include/dev/flash_nor.h
new file mode 100644
index 0000000..5d74636
--- /dev/null
+++ b/src/bsp/lk/include/dev/flash_nor.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_FLASH_NOR_H
+#define __DEV_FLASH_NOR_H
+
+#include <sys/types.h>
+
+struct flash_nor_bank {
+	addr_t base;
+	size_t len;
+	size_t page_size;
+	uint flags;
+};
+
+#define FLASH_NOR_FLAG_NONE 0
+
+const struct flash_nor_bank *flash_nor_get_bank(unsigned int bank);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/gpio.h b/src/bsp/lk/include/dev/gpio.h
new file mode 100644
index 0000000..0f2c972
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * Copyright (c) 2012, Travis Geiselbrecht
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DEV_GPIO_H
+#define __DEV_GPIO_H
+
+enum gpio_flags {
+    GPIO_INPUT      = (1 << 0),
+    GPIO_OUTPUT     = (1 << 1),
+    GPIO_LEVEL      = (1 << 2),
+    GPIO_EDGE       = (1 << 3),
+    GPIO_RISING     = (1 << 4),
+    GPIO_FALLING    = (1 << 5),
+    GPIO_HIGH       = (1 << 6),
+    GPIO_LOW        = (1 << 7),
+    GPIO_PULLUP     = (1 << 8),
+    GPIO_PULLDOWN   = (1 << 9),
+};
+
+/* top 16 bits of the gpio flags are platform specific */
+#define GPIO_PLATFORM_MASK 0xffff0000
+
+int gpio_config(unsigned nr, unsigned flags);
+void gpio_set(unsigned nr, unsigned on);
+int gpio_get(unsigned nr);
+
+#endif
diff --git a/src/bsp/lk/include/dev/gpio_i2c.h b/src/bsp/lk/include/dev/gpio_i2c.h
new file mode 100644
index 0000000..59403be
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio_i2c.h
@@ -0,0 +1,57 @@
+/* vim: set expandtab ts=4 sw=4 tw=100: */
+/*
+ * Copyright (c) 2013 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __GPIO_I2C__
+#define __GPIO_I2C__
+
+#include <stdint.h>
+#include <dev/i2c.h>
+
+typedef struct gpio_i2c_info {
+    const int sda;
+    const int scl;
+    uint32_t  hcd;  /* 1/2 I2C clock delay in cpu cycles */
+    uint32_t  qcd;  /* 1/4 I2C clock delay in cpu cycles */
+} gpio_i2c_info_t;
+
+#define DEFINE_GPIO_I2C(_name,                 \
+                        _sda_gpio_id,          \
+                        _scl_gpio_id,          \
+                        _clk_ticks)            \
+static const gpio_i2c_info_t _name = {         \
+    .sda            = _sda_gpio_id,            \
+    .scl            = _scl_gpio_id,            \
+    .hcd            = ((_clk_ticks + 1) >> 1), \
+    .qcd            = ((_clk_ticks + 3) >> 2), \
+}
+
+void gpio_i2c_add_bus(uint32_t bus_id, const gpio_i2c_info_t* info);
+
+void gpio_i2c_init_early(void);
+void gpio_i2c_init(void);
+status_t gpio_i2c_transmit(int, uint8_t, const void*, size_t);
+status_t gpio_i2c_receive(int, uint8_t, void*, size_t);
+status_t gpio_i2c_write_reg_bytes(int, uint8_t, uint8_t, const uint8_t*, size_t);
+status_t gpio_i2c_read_reg_bytes(int, uint8_t, uint8_t, uint8_t*, size_t);
+
+#endif  // __GPIO_I2C__
diff --git a/src/bsp/lk/include/dev/gpio_keypad.h b/src/bsp/lk/include/dev/gpio_keypad.h
new file mode 100644
index 0000000..445e65a
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio_keypad.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  * Neither the name of Google, Inc. nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DEV_GPIO_KEYPAD_H
+#define __DEV_GPIO_KEYPAD_H
+
+#include <sys/types.h>
+
+/* unset: drive active output low, set: drive active output high */
+#define GPIOKPF_ACTIVE_HIGH     (1U << 0)
+#define GPIOKPF_DRIVE_INACTIVE      (1U << 1)
+
+struct gpio_keypad_info {
+	/* size must be ninputs * noutputs */
+	const uint16_t *keymap;
+	unsigned *input_gpios;
+	unsigned *output_gpios;
+	int ninputs;
+	int noutputs;
+	/* time to wait before reading inputs after driving each output */
+	time_t settle_time;
+	time_t poll_time;
+	unsigned flags;
+};
+
+void gpio_keypad_init(struct gpio_keypad_info *kpinfo);
+
+#endif /* __DEV_GPIO_KEYPAD_H */
diff --git a/src/bsp/lk/include/dev/i2c.h b/src/bsp/lk/include/dev/i2c.h
new file mode 100644
index 0000000..68ed008
--- /dev/null
+++ b/src/bsp/lk/include/dev/i2c.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_I2C_H
+#define __DEV_I2C_H
+
+#include <stdint.h>
+
+#include <stddef.h>		// size_t
+#include <sys/types.h>	// status_t
+
+void i2c_init(void);
+void i2c_init_early(void);
+
+/* Notes about I2C addresses
+ * + Currently, there is no API support for 10-bit I2C addresses.  7-bit only.
+ * + Addresses should be supplied as the actual 7-bit address of the device.
+ *   The platform driver is responsible for left shifting this address by 1 and
+ *   suppling the appropriate value for the R/W bit.
+ */
+
+/* send and receive blocks of data */
+status_t i2c_transmit(int bus, uint8_t address, const void *buf, size_t count);
+status_t i2c_receive(int bus, uint8_t address, void *buf, size_t count);
+
+/* A few convenience routines based on the usual way of accessing registers on
+ * i2c slave devices.
+ */
+status_t i2c_write_reg_bytes(int bus, uint8_t address, uint8_t reg, const uint8_t* val, size_t cnt);
+status_t i2c_read_reg_bytes(int bus, uint8_t address, uint8_t reg, uint8_t *val, size_t cnt);
+
+static inline status_t i2c_write_reg(int bus, uint8_t address, uint8_t reg, uint8_t val)
+{
+	return i2c_write_reg_bytes(bus, address, reg, &val, 1);
+}
+
+static inline status_t i2c_read_reg(int bus, uint8_t address, uint8_t reg, uint8_t *val)
+{
+	return i2c_read_reg_bytes(bus, address, reg, val, 1);
+}
+#endif
+
diff --git a/src/bsp/lk/include/dev/keys.h b/src/bsp/lk/include/dev/keys.h
new file mode 100644
index 0000000..165505a
--- /dev/null
+++ b/src/bsp/lk/include/dev/keys.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  * Neither the name of Google, Inc. nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DEV_KEYS_H
+#define __DEV_KEYS_H
+
+#include <sys/types.h>
+
+/* these are just the ascii values for the chars */
+#define KEY_0       0x30
+#define KEY_1       0x31
+#define KEY_2       0x32
+#define KEY_3       0x33
+#define KEY_4       0x34
+#define KEY_5       0x35
+#define KEY_6       0x36
+#define KEY_7       0x37
+#define KEY_8       0x38
+#define KEY_9       0x39
+
+#define KEY_A       0x61
+
+#define KEY_ESC     0x100
+#define KEY_F1      0x101
+#define KEY_F2      0x102
+#define KEY_F3      0x103
+#define KEY_F4      0x104
+#define KEY_F5      0x105
+#define KEY_F6      0x106
+#define KEY_F7      0x107
+#define KEY_F8      0x108
+#define KEY_F9      0x109
+
+#define KEY_LEFT    0x110
+#define KEY_RIGHT   0x111
+#define KEY_UP      0x112
+#define KEY_DOWN    0x113
+#define KEY_CENTER  0x114
+
+#define KEY_VOLUMEUP    0x115
+#define KEY_VOLUMEDOWN  0x116
+#define KEY_MUTE    0x117
+
+#define KEY_SOFT1   0x11a
+#define KEY_SOFT2   0x11b
+#define KEY_STAR    0x11c
+#define KEY_SHARP   0x11d
+#define KEY_MAIL    0x11e
+
+#define KEY_SEND    0x120
+#define KEY_CLEAR   0x121
+#define KEY_HOME    0x122
+#define KEY_BACK    0x123
+
+#define MAX_KEYS    0x1ff
+
+void keys_init(void);
+void keys_post_event(uint16_t code, int16_t value);
+int keys_get_state(uint16_t code);
+
+#endif /* __DEV_KEYS_H */
diff --git a/src/bsp/lk/include/dev/pci.h b/src/bsp/lk/include/dev/pci.h
new file mode 100644
index 0000000..ec64d147
--- /dev/null
+++ b/src/bsp/lk/include/dev/pci.h
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2009 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PCI_H
+#define __PCI_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+/*
+ * PCI access return codes
+ */
+#define _PCI_SUCCESSFUL             0x00
+#define _PCI_FUNC_NOT_SUPPORTED     0x81
+#define _PCI_BAD_VENDOR_ID          0x83
+#define _PCI_DEVICE_NOT_FOUND       0x86
+#define _PCI_BAD_REGISTER_NUMBER    0x87
+#define _PCI_SET_FAILED             0x88
+#define _PCI_BUFFER_TOO_SMALL       0x89
+
+/*
+ * PCI configuration space offsets
+ */
+#define PCI_CONFIG_VENDOR_ID        0x00
+#define PCI_CONFIG_DEVICE_ID        0x02
+#define PCI_CONFIG_COMMAND          0x04
+#define PCI_CONFIG_STATUS           0x06
+#define PCI_CONFIG_REVISION_ID      0x08
+#define PCI_CONFIG_CLASS_CODE       0x09
+#define PCI_CONFIG_CLASS_CODE_INTR  0x09
+#define PCI_CONFIG_CLASS_CODE_SUB   0x0a
+#define PCI_CONFIG_CLASS_CODE_BASE  0x0b
+#define PCI_CONFIG_CACHE_LINE_SIZE  0x0c
+#define PCI_CONFIG_LATENCY_TIMER    0x0d
+#define PCI_CONFIG_HEADER_TYPE      0x0e
+#define PCI_CONFIG_BIST             0x0f
+#define PCI_CONFIG_BASE_ADDRESSES   0x10
+#define PCI_CONFIG_CARDBUS_CIS_PTR  0x28
+#define PCI_CONFIG_SUBSYS_VENDOR_ID 0x2c
+#define PCI_CONFIG_SUBSYS_ID        0x2e
+#define PCI_CONFIG_EXP_ROM_ADDRESS  0x30
+#define PCI_CONFIG_CAPABILITIES     0x34
+#define PCI_CONFIG_INTERRUPT_LINE   0x3c
+#define PCI_CONFIG_INTERRUPT_PIN    0x3d
+#define PCI_CONFIG_MIN_GRANT        0x3e
+#define PCI_CONFIG_MAX_LATENCY      0x3f
+
+/*
+ * PCI header type register bits
+ */
+#define PCI_HEADER_TYPE_MASK        0x7f
+#define PCI_HEADER_TYPE_MULTI_FN    0x80
+
+/*
+ * PCI header types
+ */
+#define PCI_HEADER_TYPE_STANDARD    0x00
+#define PCI_HEADER_TYPE_PCI_BRIDGE  0x01
+#define PCI_HEADER_TYPE_CARD_BUS    0x02
+
+/*
+ * PCI command register bits
+ */
+#define PCI_COMMAND_IO_EN           0x0001
+#define PCI_COMMAND_MEM_EN          0x0002
+#define PCI_COMMAND_BUS_MASTER_EN   0x0004
+#define PCI_COMMAND_SPECIAL_EN      0x0008
+#define PCI_COMMAND_MEM_WR_INV_EN   0x0010
+#define PCI_COMMAND_PAL_SNOOP_EN    0x0020
+#define PCI_COMMAND_PERR_RESP_EN    0x0040
+#define PCI_COMMAND_AD_STEP_EN      0x0080
+#define PCI_COMMAND_SERR_EN         0x0100
+#define PCI_COMMAND_FAST_B2B_EN     0x0200
+
+/*
+ * PCI status register bits
+ */
+#define PCI_STATUS_NEW_CAPS         0x0010
+#define PCI_STATUS_66_MHZ           0x0020
+#define PCI_STATUS_FAST_B2B         0x0080
+#define PCI_STATUS_MSTR_PERR        0x0100
+#define PCI_STATUS_DEVSEL_MASK      0x0600
+#define PCI_STATUS_TARG_ABORT_SIG   0x0800
+#define PCI_STATUS_TARG_ABORT_RCV   0x1000
+#define PCI_STATUS_MSTR_ABORT_RCV   0x2000
+#define PCI_STATUS_SERR_SIG         0x4000
+#define PCI_STATUS_PERR             0x8000
+
+typedef struct {
+	uint16_t vendor_id;
+	uint16_t device_id;
+	uint16_t command;
+	uint16_t status;
+	uint8_t revision_id_0;
+	uint8_t program_interface;
+	uint8_t sub_class;
+	uint8_t base_class;
+	uint8_t cache_line_size;
+	uint8_t latency_timer;
+	uint8_t header_type;
+	uint8_t bist;
+	uint32_t base_addresses[6];
+	uint32_t cardbus_cis_ptr;
+	uint16_t subsystem_vendor_id;
+	uint16_t subsystem_id;
+	uint32_t expansion_rom_address;
+	uint8_t capabilities_ptr;
+	uint8_t reserved_0[3];
+	uint32_t reserved_1;
+	uint8_t interrupt_line;
+	uint8_t interrupt_pin;
+	uint8_t min_grant;
+	uint8_t max_latency;
+} __PACKED pci_config_t;
+
+/*
+ * PCI address structure
+ */
+typedef struct {
+	uint8_t bus;
+	uint8_t dev_fn;
+} pci_location_t;
+
+typedef struct {
+	uint8_t id;
+	uint8_t next;
+} __PACKED pci_capability_t;
+
+typedef struct {
+	uint8_t bus;
+	uint8_t device;
+	uint8_t link_int_a;
+	uint16_t irq_int_a;
+	uint8_t link_int_b;
+	uint16_t irq_int_b;
+	uint8_t link_int_c;
+	uint16_t irq_int_c;
+	uint8_t link_int_d;
+	uint16_t irq_int_d;
+	uint8_t slot;
+	uint8_t reserved;
+} __PACKED irq_routing_entry;
+
+void pci_init(void);
+
+int pci_get_last_bus(void);
+
+int pci_find_pci_device(pci_location_t *state, uint16_t device_id, uint16_t vendor_id, uint16_t index);
+int pci_find_pci_class_code(pci_location_t *state, uint32_t class_code, uint16_t index);
+
+int pci_read_config_byte(const pci_location_t *state, uint32_t reg, uint8_t *value);
+int pci_read_config_half(const pci_location_t *state, uint32_t reg, uint16_t *value);
+int pci_read_config_word(const pci_location_t *state, uint32_t reg, uint32_t *value);
+
+int pci_write_config_byte(const pci_location_t *state, uint32_t reg, uint8_t value);
+int pci_write_config_half(const pci_location_t *state, uint32_t reg, uint16_t value);
+int pci_write_config_word(const pci_location_t *state, uint32_t reg, uint32_t value);
+
+int pci_get_irq_routing_options(irq_routing_entry *entries, uint16_t *count, uint16_t *pci_irqs);
+int pci_set_irq_hw_int(const pci_location_t *state, uint8_t int_pin, uint8_t irq);
+
+#endif
diff --git a/src/bsp/lk/include/dev/uart.h b/src/bsp/lk/include/dev/uart.h
new file mode 100644
index 0000000..db35ee1
--- /dev/null
+++ b/src/bsp/lk/include/dev/uart.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_UART_H
+#define __DEV_UART_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+void uart_init_early(void);
+
+int uart_putc(int port, char c);
+int uart_getc(int port, bool wait);
+void uart_flush_tx(int port);
+void uart_flush_rx(int port);
+void uart_init_port(int port, uint baud);
+
+/* panic-time uart accessors, intended to be run with interrupts disabled */
+int uart_pputc(int port, char c);
+int uart_pgetc(int port);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/udc.h b/src/bsp/lk/include/dev/udc.h
new file mode 100644
index 0000000..84d4783
--- /dev/null
+++ b/src/bsp/lk/include/dev/udc.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DEV_UDC_H
+#define __DEV_UDC_H
+
+#include <stdint.h>
+
+typedef struct udc_request udc_request_t;
+typedef struct udc_gadget udc_gadget_t;
+typedef struct udc_device udc_device_t;
+
+/* endpoints are opaque handles specific to the particular device controller */
+typedef struct udc_endpoint udc_endpoint_t;
+
+/* USB Device Controller Transfer Request */
+struct udc_request {
+	void *buffer;
+	unsigned length;
+	void (*complete)(udc_request_t *req, unsigned actual, int status);
+	void *context;
+};
+
+udc_request_t *udc_request_alloc(void);
+void udc_request_free(udc_request_t *req);
+int udc_request_queue(udc_endpoint_t *ept, udc_request_t *req);
+int udc_request_cancel(udc_endpoint_t *ept, udc_request_t *req);
+
+#define UDC_BULK_IN    0x82
+#define UDC_BULK_OUT   0x02
+
+udc_endpoint_t *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
+void udc_endpoint_free(udc_endpoint_t *ept);
+
+#define UDC_EVENT_ONLINE    1
+#define UDC_EVENT_OFFLINE   2
+
+struct udc_gadget {
+	void (*notify)(udc_gadget_t *gadget, unsigned event);
+	void *context;
+
+	struct udc_gadget *next; // do not modify
+
+	uint8_t ifc_class;
+	uint8_t ifc_subclass;
+	uint8_t ifc_protocol;
+	uint8_t ifc_endpoints;
+	const char *ifc_string;
+	unsigned flags;
+
+	udc_endpoint_t **ept;
+};
+
+struct udc_device {
+	uint16_t vendor_id;
+	uint16_t product_id;
+	uint16_t version_id;
+
+	const char *manufacturer;
+	const char *product;
+	const char *serialno;
+};
+
+int udc_init(udc_device_t *devinfo);
+int udc_register_gadget(udc_gadget_t *gadget);
+int udc_start(void);
+int udc_stop(void);
+
+#endif
diff --git a/src/bsp/lk/include/dev/usb.h b/src/bsp/lk/include/dev/usb.h
new file mode 100644
index 0000000..de91da7
--- /dev/null
+++ b/src/bsp/lk/include/dev/usb.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_USB_H
+#define __DEV_USB_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+/* top level initialization for usb client, abstracts away the interfaces */
+typedef struct {
+    void *desc;
+    size_t len;
+    uint flags;
+} usb_descriptor __ALIGNED(2);
+
+#define USB_DESC_FLAG_STATIC (0x1)
+
+#define USB_DESC_STATIC(x) { .desc = (void *)(x), .len = sizeof(x), .flags = USB_DESC_FLAG_STATIC }
+
+typedef struct {
+    usb_descriptor string;
+    uint8_t id;
+} usb_string;
+
+/* complete usb config struct, passed in to usb_setup() */
+typedef struct {
+    struct usb_descriptor_speed {
+        usb_descriptor device;
+        usb_descriptor device_qual;
+        usb_descriptor config;
+    } lowspeed, highspeed;
+    usb_descriptor langid;
+} usb_config;
+
+/* external code needs to set up the usb stack via the following calls */
+status_t usb_setup(usb_config *config);
+
+/* apped new interface descriptors to the existing config if desired */
+status_t usb_append_interface_highspeed(const uint8_t *int_descr, size_t len);
+status_t usb_append_interface_lowspeed(const uint8_t *int_descr, size_t len);
+
+status_t usb_add_string(const char *string, uint8_t id);
+
+status_t usb_start(void);
+status_t usb_stop(void);
+
+/* callbacks from usbc and usb layers */
+typedef enum {
+    USB_CB_RESET,
+    USB_CB_SUSPEND,
+    USB_CB_RESUME,
+    USB_CB_DISCONNECT,
+    USB_CB_ONLINE,
+    USB_CB_OFFLINE,
+    USB_CB_SETUP_MSG,
+} usb_callback_op_t;
+
+/* setup arg is valid during CB_SETUP_MSG */
+union usb_callback_args {
+    const struct usb_setup *setup;
+};
+
+typedef status_t (*usb_callback_t)(void *cookie, usb_callback_op_t op, const union usb_callback_args *args);
+
+/* callback api the usbc driver uses */
+status_t usbc_callback(usb_callback_op_t op, const union usb_callback_args *args);
+
+/* callback api that anyone can register for */
+status_t usb_register_callback(usb_callback_t, void *cookie);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/usbc.h b/src/bsp/lk/include/dev/usbc.h
new file mode 100644
index 0000000..7a12280
--- /dev/null
+++ b/src/bsp/lk/include/dev/usbc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_USBC_H
+#define __DEV_USBC_H
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <hw/usb.h>
+
+void usbc_init(void);
+
+typedef uint ep_t;
+
+typedef enum {
+    USB_IN = 0,
+    USB_OUT
+} ep_dir_t;
+
+struct usbc_transfer;
+typedef status_t (*ep_callback)(ep_t endpoint, struct usbc_transfer *transfer);
+
+typedef struct usbc_transfer {
+    ep_callback callback;
+    status_t result;
+    void *buf;
+    size_t buflen;
+    uint bufpos;
+    void *extra; // extra pointer to store whatever you want
+} usbc_transfer_t;
+
+enum {
+    USB_TRANSFER_RESULT_OK = 0,
+    USB_TRANSFER_RESULT_ERR = -1,
+    USB_TRANSFER_RESULT_CANCELLED = -2,
+};
+
+status_t usbc_setup_endpoint(ep_t ep, ep_dir_t dir, uint width);
+status_t usbc_queue_rx(ep_t ep, usbc_transfer_t *transfer);
+status_t usbc_queue_tx(ep_t ep, usbc_transfer_t *transfer);
+
+status_t usbc_set_active(bool active);
+void usbc_set_address(uint8_t address);
+
+/* called back from within a callback to handle setup responses */
+void usbc_ep0_ack(void);
+void usbc_ep0_stall(void);
+void usbc_ep0_send(const void *buf, size_t len, size_t maxlen);
+void usbc_ep0_recv(void *buf, size_t len, ep_callback);
+
+bool usbc_is_highspeed(void);
+
+static inline void usbc_dump_transfer(const usbc_transfer_t *t)
+{
+    printf("usb transfer %p: cb %p buf %p, buflen %zd, bufpos %u, result %d\n", t, t->callback, t->buf, t->buflen, t->bufpos, t->result);
+}
+
+#endif
+
diff --git a/src/bsp/lk/include/endian.h b/src/bsp/lk/include/endian.h
new file mode 100644
index 0000000..90da5ea
--- /dev/null
+++ b/src/bsp/lk/include/endian.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ENDIAN_H
+#define __ENDIAN_H
+
+#include <sys/types.h>
+
+#ifndef __BYTE_ORDER__
+#error Compiler does not provide __BYTE_ORDER__
+#endif
+
+/* the compiler provides it, use what it says */
+#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#define BYTE_ORDER __BYTE_ORDER__
+
+// define a macro that unconditionally swaps
+#define SWAP_32(x) \
+    (((uint32_t)(x) << 24) | (((uint32_t)(x) & 0xff00) << 8) |(((uint32_t)(x) & 0x00ff0000) >> 8) | ((uint32_t)(x) >> 24))
+#define SWAP_16(x) \
+    ((((uint16_t)(x) & 0xff) << 8) | ((uint16_t)(x) >> 8))
+#define SWAP_64(x) ((((uint64_t)(SWAP_32((uint64_t)(x)))) << 32) | (SWAP_32(((uint64_t)(x)) >> 32)))
+
+// standard swap macros
+#if BYTE_ORDER == BIG_ENDIAN
+#define LE64(val) SWAP_64(val)
+#define LE32(val) SWAP_32(val)
+#define LE16(val) SWAP_16(val)
+#define BE64(val) (val)
+#define BE32(val) (val)
+#define BE16(val) (val)
+#else
+#define LE64(val) (val)
+#define LE32(val) (val)
+#define LE16(val) (val)
+#define BE64(val) SWAP_64(val)
+#define BE32(val) SWAP_32(val)
+#define BE16(val) SWAP_16(val)
+#endif
+
+#define LE32SWAP(var) (var) = LE32(var);
+#define LE16SWAP(var) (var) = LE16(var);
+#define BE32SWAP(var) (var) = BE32(var);
+#define BE16SWAP(var) (var) = BE16(var);
+
+/* classic network byte swap stuff */
+#define ntohs(n) BE16(n)
+#define htons(h) BE16(h)
+#define ntohl(n) BE32(n)
+#define htonl(h) BE32(h)
+
+/* 64-bit network byte swap stuff */
+#define htobe64(h) BE64(h)
+#define be64toh(b) BE64(b)
+
+// some memory access macros
+#if __POWERPC__
+#include <ppc_intrinsics.h>
+
+#define READ_MEM_WORD(ptr)      __lwbrx((word *)(ptr), 0)
+#define READ_MEM_HALFWORD(ptr)  __lhbrx((halfword *)(ptr), 0)
+#define READ_MEM_BYTE(ptr)      (*(byte *)(ptr))
+#define WRITE_MEM_WORD(ptr, data)   __stwbrx(data, (word *)(ptr), 0)
+#define WRITE_MEM_HALFWORD(ptr, data)   __sthbrx(data, (halfword *)(ptr), 0)
+#define WRITE_MEM_BYTE(ptr, data)   (*(byte *)(ptr) = (data))
+#else
+#define READ_MEM_WORD(ptr)      SWAPIT_32(*(word *)(ptr))
+#define READ_MEM_HALFWORD(ptr)  SWAPIT_16(*(halfword *)(ptr))
+#define READ_MEM_BYTE(ptr)      (*(byte *)(ptr))
+#define WRITE_MEM_WORD(ptr, data)   (*(word *)(ptr) = SWAPIT_32(data))
+#define WRITE_MEM_HALFWORD(ptr, data)   (*(halfword *)(ptr) = SWAPIT_16(data))
+#define WRITE_MEM_BYTE(ptr, data)   (*(byte *)(ptr) = (data))
+#endif
+
+
+#endif
diff --git a/src/bsp/lk/include/err.h b/src/bsp/lk/include/err.h
new file mode 100644
index 0000000..de73f4e
--- /dev/null
+++ b/src/bsp/lk/include/err.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ERR_H
+#define __ERR_H
+
+#ifndef ASSEMBLY
+#include <sys/types.h> // for status_t
+#endif
+
+#define NO_ERROR                (0)
+#define ERR_GENERIC             (-1)
+#define ERR_NOT_FOUND           (-2)
+#define ERR_NOT_READY           (-3)
+#define ERR_NO_MSG              (-4)
+#define ERR_NO_MEMORY           (-5)
+#define ERR_ALREADY_STARTED     (-6)
+#define ERR_NOT_VALID           (-7)
+#define ERR_INVALID_ARGS        (-8)
+#define ERR_NOT_ENOUGH_BUFFER   (-9)
+#define ERR_NOT_SUSPENDED       (-10)
+#define ERR_OBJECT_DESTROYED    (-11)
+#define ERR_NOT_BLOCKED         (-12)
+#define ERR_TIMED_OUT           (-13)
+#define ERR_ALREADY_EXISTS      (-14)
+#define ERR_CHANNEL_CLOSED      (-15)
+#define ERR_OFFLINE             (-16)
+#define ERR_NOT_ALLOWED         (-17)
+#define ERR_BAD_PATH            (-18)
+#define ERR_ALREADY_MOUNTED     (-19)
+#define ERR_IO                  (-20)
+#define ERR_NOT_DIR             (-21)
+#define ERR_NOT_FILE            (-22)
+#define ERR_RECURSE_TOO_DEEP    (-23)
+#define ERR_NOT_SUPPORTED       (-24)
+#define ERR_TOO_BIG             (-25)
+#define ERR_CANCELLED           (-26)
+#define ERR_NOT_IMPLEMENTED     (-27)
+#define ERR_CHECKSUM_FAIL       (-28)
+#define ERR_CRC_FAIL            (-29)
+#define ERR_CMD_UNKNOWN         (-30)
+#define ERR_BAD_STATE           (-31)
+#define ERR_BAD_LEN             (-32)
+#define ERR_BUSY                (-33)
+#define ERR_THREAD_DETACHED     (-34)
+#define ERR_I2C_NACK            (-35)
+#define ERR_ALREADY_EXPIRED     (-36)
+#define ERR_OUT_OF_RANGE        (-37)
+#define ERR_NOT_CONFIGURED      (-38)
+#define ERR_NOT_MOUNTED         (-39)
+#define ERR_FAULT               (-40)
+#define ERR_NO_RESOURCES        (-41)
+#define ERR_BAD_HANDLE          (-42)
+#define ERR_ACCESS_DENIED       (-43)
+#define ERR_PARTIAL_WRITE       (-44)
+
+#define ERR_USER_BASE           (-16384)
+
+#endif
diff --git a/src/bsp/lk/include/errno.h b/src/bsp/lk/include/errno.h
new file mode 100644
index 0000000..ef8fbac
--- /dev/null
+++ b/src/bsp/lk/include/errno.h
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __ERRNO_H
+#define __ERRNO_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+extern int *__geterrno(void);
+
+#define errno (*__geterrno())
+
+#define	EPERM 1		/* Not super-user */
+#define	ENOENT 2	/* No such file or directory */
+#define	ESRCH 3		/* No such process */
+#define	EINTR 4		/* Interrupted system call */
+#define	EIO 5		/* I/O error */
+#define	ENXIO 6		/* No such device or address */
+#define	E2BIG 7		/* Arg list too long */
+#define	ENOEXEC 8	/* Exec format error */
+#define	EBADF 9		/* Bad file number */
+#define	ECHILD 10	/* No children */
+#define	EAGAIN 11	/* No more processes */
+#define	ENOMEM 12	/* Not enough core */
+#define	EACCES 13	/* Permission denied */
+#define	EFAULT 14	/* Bad address */
+#define	ENOTBLK 15	/* Block device required */
+#define	EBUSY 16	/* Mount device busy */
+#define	EEXIST 17	/* File exists */
+#define	EXDEV 18	/* Cross-device link */
+#define	ENODEV 19	/* No such device */
+#define	ENOTDIR 20	/* Not a directory */
+#define	EISDIR 21	/* Is a directory */
+#define	EINVAL 22	/* Invalid argument */
+#define	ENFILE 23	/* Too many open files in system */
+#define	EMFILE 24	/* Too many open files */
+#define	ENOTTY 25	/* Not a typewriter */
+#define	ETXTBSY 26	/* Text file busy */
+#define	EFBIG 27	/* File too large */
+#define	ENOSPC 28	/* No space left on device */
+#define	ESPIPE 29	/* Illegal seek */
+#define	EROFS 30	/* Read only file system */
+#define	EMLINK 31	/* Too many links */
+#define	EPIPE 32	/* Broken pipe */
+#define	EDOM 33		/* Math arg out of domain of func */
+#define	ERANGE 34	/* Math result not representable */
+#define	ENOMSG 35	/* No message of desired type */
+#define	EIDRM 36	/* Identifier removed */
+#define	ECHRNG 37	/* Channel number out of range */
+#define	EL2NSYNC 38	/* Level 2 not synchronized */
+#define	EL3HLT 39	/* Level 3 halted */
+#define	EL3RST 40	/* Level 3 reset */
+#define	ELNRNG 41	/* Link number out of range */
+#define	EUNATCH 42	/* Protocol driver not attached */
+#define	ENOCSI 43	/* No CSI structure available */
+#define	EL2HLT 44	/* Level 2 halted */
+#define	EDEADLK 45	/* Deadlock condition */
+#define	ENOLCK 46	/* No record locks available */
+#define EBADE 50	/* Invalid exchange */
+#define EBADR 51	/* Invalid request descriptor */
+#define EXFULL 52	/* Exchange full */
+#define ENOANO 53	/* No anode */
+#define EBADRQC 54	/* Invalid request code */
+#define EBADSLT 55	/* Invalid slot */
+#define EDEADLOCK 56	/* File locking deadlock error */
+#define EBFONT 57	/* Bad font file fmt */
+#define ENOSTR 60	/* Device not a stream */
+#define ENODATA 61	/* No data (for no delay io) */
+#define ETIME 62	/* Timer expired */
+#define ENOSR 63	/* Out of streams resources */
+#define ENONET 64	/* Machine is not on the network */
+#define ENOPKG 65	/* Package not installed */
+#define EREMOTE 66	/* The object is remote */
+#define ENOLINK 67	/* The link has been severed */
+#define EADV 68		/* Advertise error */
+#define ESRMNT 69	/* Srmount error */
+#define	ECOMM 70	/* Communication error on send */
+#define EPROTO 71	/* Protocol error */
+#define	EMULTIHOP 74	/* Multihop attempted */
+#define	ELBIN 75	/* Inode is remote (not really error) */
+#define	EDOTDOT 76	/* Cross mount point (not really error) */
+#define EBADMSG 77	/* Trying to read unreadable message */
+#define EFTYPE 79	/* Inappropriate file type or format */
+#define ENOTUNIQ 80	/* Given log. name not unique */
+#define EBADFD 81	/* f.d. invalid for this operation */
+#define EREMCHG 82	/* Remote address changed */
+#define ELIBACC 83	/* Can't access a needed shared lib */
+#define ELIBBAD 84	/* Accessing a corrupted shared lib */
+#define ELIBSCN 85	/* .lib section in a.out corrupted */
+#define ELIBMAX 86	/* Attempting to link in too many libs */
+#define ELIBEXEC 87	/* Attempting to exec a shared library */
+#define ENOSYS 88	/* Function not implemented */
+#define ENMFILE 89      /* No more files */
+#define ENOTEMPTY 90	/* Directory not empty */
+#define ENAMETOOLONG 91	/* File or path name too long */
+#define ELOOP 92	/* Too many symbolic links */
+#define EOPNOTSUPP 95	/* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define ECONNRESET 104  /* Connection reset by peer */
+#define ENOBUFS 105	/* No buffer space available */
+#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
+#define EPROTOTYPE 107	/* Protocol wrong type for socket */
+#define ENOTSOCK 108	/* Socket operation on non-socket */
+#define ENOPROTOOPT 109	/* Protocol not available */
+#define ESHUTDOWN 110	/* Can't send after socket shutdown */
+#define ECONNREFUSED 111	/* Connection refused */
+#define EADDRINUSE 112		/* Address already in use */
+#define ECONNABORTED 113	/* Connection aborted */
+#define ENETUNREACH 114		/* Network is unreachable */
+#define ENETDOWN 115		/* Network interface is not configured */
+#define ETIMEDOUT 116		/* Connection timed out */
+#define EHOSTDOWN 117		/* Host is down */
+#define EHOSTUNREACH 118	/* Host is unreachable */
+#define EINPROGRESS 119		/* Connection already in progress */
+#define EALREADY 120		/* Socket already connected */
+#define EDESTADDRREQ 121	/* Destination address required */
+#define EMSGSIZE 122		/* Message too long */
+#define EPROTONOSUPPORT 123	/* Unknown protocol */
+#define ESOCKTNOSUPPORT 124	/* Socket type not supported */
+#define EADDRNOTAVAIL 125	/* Address not available */
+#define ENETRESET 126
+#define EISCONN 127		/* Socket is already connected */
+#define ENOTCONN 128		/* Socket is not connected */
+#define ETOOMANYREFS 129
+#define EPROCLIM 130
+#define EUSERS 131
+#define EDQUOT 132
+#define ESTALE 133
+#define ENOTSUP 134		/* Not supported */
+#define ENOMEDIUM 135   /* No medium (in tape drive) */
+#define ENOSHARE 136    /* No such host or network path */
+#define ECASECLASH 137  /* Filename exists with different case */
+#define EILSEQ 138
+#define EOVERFLOW 139	/* Value too large for defined data type */
+
+#define EWOULDBLOCK EAGAIN	/* Operation would block */
+
+#define __ELASTERROR 2000	/* Users can add values starting here */
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/hw/mii.h b/src/bsp/lk/include/hw/mii.h
new file mode 100644
index 0000000..0ff8979
--- /dev/null
+++ b/src/bsp/lk/include/hw/mii.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2006 Brian Swetland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __HW_MII_H
+#define __HW_MII_H
+
+#define MII_REG_BCR           0x00
+#define MII_REG_BSR           0x01
+#define MII_REG_PHY_ID1       0x02
+#define MII_REG_PHY_ID2       0x03
+#define MII_REG_AUTO_ADV      0x04
+#define MII_REG_AUTO_LINK     0x05
+#define MII_REG_AUTO_EXPN     0x06
+#define MII_REG_AUTO_NEXT     0x07
+#define MII_REG_LINK_NEXT     0x08
+#define MII_REG_RXER_CNT      0x15
+#define MII_REG_ICSR          0x1b
+#define MII_REG_100TX_PHY     0x1f
+
+#define MII_BCR_RESET         0x8000
+#define MII_BCR_LOOPBACK      0x4000
+#define MII_BCR_100MBPS       0x2000
+#define MII_BCR_AUTO_ENABLE   0x1000
+#define MII_BCR_PWR_DOWN      0x0800
+#define MII_BCR_ISOLATE       0x0400
+#define MII_BCR_AUTO_RESTART  0x0200
+#define MII_BCR_FULL_DUPLEX   0x0100
+#define MII_BCR_COL_TEST      0x0080
+#define MII_BCR_TX_DISABLE    0x0001
+
+#define MII_BSR_T4            0x8000
+#define MII_BSR_100TX_FULL    0x4000
+#define MII_BSR_100TX_HALF    0x2000
+#define MII_BSR_10T_FULL      0x1000
+#define MII_BSR_10T_HALF      0x0800
+#define MII_BSR_NO_PREAMBLE   0x0040
+#define MII_BSR_AUTO_COMPLETE 0x0020
+#define MII_BSR_REMOTE_FAULT  0x0010
+#define MII_BSR_AUTO_ABLE     0x0008
+#define MII_BSR_LINK_UP       0x0004
+#define MII_BSR_JABBER        0x0002
+#define MII_BSR_EXTEND        0x0001
+
+#define MII_100TX_PHY_ISOLATE  0x0040
+#define MII_100TX_MODE_MASK    0x001C
+#define MII_100TX_MODE_AUTO    0x0000
+#define MII_100TX_MODE_10T_H   0x0004
+#define MII_100TX_MODE_100TX_H 0x0008
+#define MII_100TX_MODE_10T_F   0x0014
+#define MII_100TX_MODE_100TX_F 0x0018
+#define MII_100TX_MODE_ISOLATE 0x001C
+#define MII_100TX_SQE_TEST     0x0002
+#define MII_100TX_NO_SCRAMBLE  0x0001
+
+#endif
diff --git a/src/bsp/lk/include/hw/usb.h b/src/bsp/lk/include/hw/usb.h
new file mode 100644
index 0000000..06c4d57
--- /dev/null
+++ b/src/bsp/lk/include/hw/usb.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __HW_USB_H
+#define __HW_USB_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+/* GLOBAL STATUS VALUES */
+#define STD_COMMAND                 0x00
+#define SETUP_COMMAND_PHASE         0x40
+#define FUNCTION_ERROR              0x7F    /* Used when we are stalling the function EP0 */
+#define HUB_ERROR                   0xFF    /* Used when we are stalling the HUB EP0 */
+
+/* Request Types */
+#define DIR_OUT                     (0 << 7)
+#define DIR_IN                      (1 << 7)
+#define DIR_MASK                    (1 << 7)
+#define TYPE_STANDARD               (0 << 5)
+#define TYPE_CLASS                  (1 << 5)
+#define TYPE_VENDOR                 (2 << 5)
+#define TYPE_MASK                   (3 << 5)
+#define RECIP_DEVICE                (0 << 0)
+#define RECIP_INTERFACE             (1 << 0)
+#define RECIP_ENDPOINT              (2 << 0)
+#define RECIP_OTHER                 (3 << 0)
+#define RECIP_MASK                  (0x1f << 0)
+
+/* 1.0 Request Values */
+#define GET_STATUS                  0x00
+#define CLEAR_FEATURE               0x01
+#define SET_FEATURE                 0x03
+#define SET_ADDRESS                 0x05
+#define GET_DESCRIPTOR              0x06
+#define SET_DESCRIPTOR              0x07
+#define GET_CONFIGURATION           0x08
+#define SET_CONFIGURATION           0x09
+#define GET_INTERFACE               0x0A
+#define SET_INTERFACE               0x0B
+#define SYNCH_FRAME                 0x0C
+
+/* Mass storage requests */
+#define MASS_STORAGE_GET_MAX_LUN    0xfe
+#define MASS_STORAGE_RESET          0xff
+
+/* DFU requests */
+#define DFU_DETACH                  0x00
+#define DFU_DNLOAD                  0x01
+#define DFU_UPLOAD                  0x02
+#define DFU_GETSTATUS               0x03
+#define DFU_CLRSTATUS               0x04
+#define DFU_GETSTATE                0x05
+#define DFU_ABORT                   0x06
+
+/* HID Request Values */
+#define GET_REPORT                  0x01
+#define GET_IDLE                    0x02
+#define GET_PROTOCOL                0x03
+#define SET_REPORT                  0x09
+#define SET_IDLE                    0x0A
+#define SET_PROTOCOL                0x0B
+
+/* Descriptor Types */
+#define DEVICE                      0x01
+#define CONFIGURATION               0x02
+#define STRING                      0x03
+#define INTERFACE                   0x04
+#define ENDPOINT                    0x05
+#define DEVICE_QUALIFIER            0x06
+#define OTHER_SPEED_CONFIGURATION   0x07
+#define INTERFACE_POWER             0x08
+#define BOS                         0x0F
+#define HID                         0x21
+#define HIDREPORT                   0x22
+#define HIDPHYSICAL                 0x23
+#define SS_EP_COMP                  0x30
+
+/* general USB defines */
+struct usb_setup {
+    uint8_t request_type;
+    uint8_t request;
+    uint16_t value;
+    uint16_t index;
+    uint16_t length;
+} __PACKED;
+
+#endif
+
diff --git a/src/bsp/lk/include/inttypes.h b/src/bsp/lk/include/inttypes.h
new file mode 100644
index 0000000..4e542d4
--- /dev/null
+++ b/src/bsp/lk/include/inttypes.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __INTTYPES_H
+#define __INTTYPES_H
+
+#define PRIu32 "u"
+#define PRIx32 "x"
+
+#include <stdint.h>
+
+#endif
+
diff --git a/src/bsp/lk/include/iovec.h b/src/bsp/lk/include/iovec.h
new file mode 100644
index 0000000..6d28c4b
--- /dev/null
+++ b/src/bsp/lk/include/iovec.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __IOVEC_H
+#define __IOVEC_H
+
+#include <compiler.h>
+#include <stddef.h>
+#include <sys/types.h>
+
+__BEGIN_CDECLS;
+
+typedef struct iovec {
+	void *iov_base;
+	size_t iov_len;
+} iovec_t;
+
+ssize_t iovec_size(const iovec_t *iov, uint iov_cnt);
+
+ssize_t iovec_to_membuf(uint8_t *buf, uint buf_len,
+                        const iovec_t *iov, uint iov_cnt, uint iov_pos);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/kernel/debug.h b/src/bsp/lk/include/kernel/debug.h
new file mode 100644
index 0000000..3677caf
--- /dev/null
+++ b/src/bsp/lk/include/kernel/debug.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2012-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_DEBUG_H
+#define __KERNEL_DEBUG_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+#include <debug.h>
+
+/* kernel event log */
+#if WITH_KERNEL_EVLOG
+
+#include <lib/evlog.h>
+
+#ifndef KERNEL_EVLOG_LEN
+#define KERNEL_EVLOG_LEN 1024
+#endif
+
+void kernel_evlog_init(void);
+
+void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1);
+void kernel_evlog_dump(void);
+
+#else // !WITH_KERNEL_EVLOG
+
+/* do nothing versions */
+static inline void kernel_evlog_init(void) {}
+static inline void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1) {}
+static inline void kernel_evlog_dump(void) {}
+
+#endif
+
+enum {
+	KERNEL_EVLOG_NULL = 0,
+	KERNEL_EVLOG_CONTEXT_SWITCH,
+	KERNEL_EVLOG_PREEMPT,
+	KERNEL_EVLOG_TIMER_TICK,
+	KERNEL_EVLOG_TIMER_CALL,
+	KERNEL_EVLOG_IRQ_ENTER,
+	KERNEL_EVLOG_IRQ_EXIT,
+};
+
+#define KEVLOG_THREAD_SWITCH(from, to) kernel_evlog_add(KERNEL_EVLOG_CONTEXT_SWITCH, (uintptr_t)from, (uintptr_t)to)
+#define KEVLOG_THREAD_PREEMPT(thread) kernel_evlog_add(KERNEL_EVLOG_PREEMPT, (uintptr_t)thread, 0)
+#define KEVLOG_TIMER_TICK() kernel_evlog_add(KERNEL_EVLOG_TIMER_TICK, 0, 0)
+#define KEVLOG_TIMER_CALL(ptr, arg) kernel_evlog_add(KERNEL_EVLOG_TIMER_CALL, (uintptr_t)ptr, (uintptr_t)arg)
+#define KEVLOG_IRQ_ENTER(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_ENTER, (uintptr_t)irqn, 0)
+#define KEVLOG_IRQ_EXIT(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_EXIT, (uintptr_t)irqn, 0)
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/kernel/event.h b/src/bsp/lk/include/kernel/event.h
new file mode 100644
index 0000000..65074ca
--- /dev/null
+++ b/src/bsp/lk/include/kernel/event.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_EVENT_H
+#define __KERNEL_EVENT_H
+
+#include <compiler.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <kernel/thread.h>
+
+__BEGIN_CDECLS;
+
+#define EVENT_MAGIC 'evnt'
+
+typedef struct event {
+	int magic;
+	bool signalled;
+	uint flags;
+	wait_queue_t wait;
+} event_t;
+
+#define EVENT_FLAG_AUTOUNSIGNAL 1
+
+#define EVENT_INITIAL_VALUE(e, initial, _flags) \
+{ \
+	.magic = EVENT_MAGIC, \
+	.signalled = initial, \
+	.flags = _flags, \
+	.wait = WAIT_QUEUE_INITIAL_VALUE((e).wait), \
+}
+
+/* Rules for Events:
+ * - Events may be signaled from interrupt context *but* the reschedule
+ *   parameter must be false in that case.
+ * - Events may not be waited upon from interrupt context.
+ * - Events without FLAG_AUTOUNSIGNAL:
+ *   - Wake up any waiting threads when signaled.
+ *   - Continue to do so (no threads will wait) until unsignaled.
+ * - Events with FLAG_AUTOUNSIGNAL:
+ *   - If one or more threads are waiting when signaled, one thread will
+ *     be woken up and return.  The signaled state will not be set.
+ *   - If no threads are waiting when signaled, the Event will remain
+ *     in the signaled state until a thread attempts to wait (at which
+ *     time it will unsignal atomicly and return immediately) or
+ *     event_unsignal() is called.
+*/
+
+void event_init(event_t *, bool initial, uint flags);
+void event_destroy(event_t *);
+status_t event_wait_timeout(event_t *, lk_time_t); /* wait on the event with a timeout */
+status_t event_signal(event_t *, bool reschedule);
+status_t event_unsignal(event_t *);
+
+static inline bool event_initialized(event_t *e) {
+	return e->magic == EVENT_MAGIC;
+}
+
+static inline status_t event_wait(event_t *e) {
+	return event_wait_timeout(e, INFINITE_TIME);
+}
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/kernel/mp.h b/src/bsp/lk/include/kernel/mp.h
new file mode 100644
index 0000000..a015ebd
--- /dev/null
+++ b/src/bsp/lk/include/kernel/mp.h
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <compiler.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <kernel/thread.h>
+
+__BEGIN_CDECLS;
+
+typedef uint32_t mp_cpu_mask_t;
+
+#define MP_CPU_ALL_BUT_LOCAL (UINT32_MAX)
+
+/* by default, mp_mbx_reschedule does not signal to cpus that are running realtime
+ * threads. Override this behavior.
+ */
+#define MP_RESCHEDULE_FLAG_REALTIME (0x1)
+
+typedef enum {
+    MP_IPI_GENERIC,
+    MP_IPI_RESCHEDULE,
+} mp_ipi_t;
+
+#ifdef WITH_SMP
+void mp_init(void);
+
+void mp_reschedule(mp_cpu_mask_t target, uint flags);
+void mp_set_curr_cpu_active(bool active);
+
+/* called from arch code during reschedule irq */
+enum handler_return mp_mbx_reschedule_irq(void);
+
+/* global mp state to track what the cpus are up to */
+struct mp_state {
+    volatile mp_cpu_mask_t active_cpus;
+
+    /* only safely accessible with thread lock held */
+    mp_cpu_mask_t idle_cpus;
+    mp_cpu_mask_t realtime_cpus;
+};
+
+extern struct mp_state mp;
+
+static inline int mp_is_cpu_active(uint cpu)
+{
+    return mp.active_cpus & (1 << cpu);
+}
+
+static inline int mp_is_cpu_idle(uint cpu)
+{
+    return mp.idle_cpus & (1 << cpu);
+}
+
+/* must be called with the thread lock held */
+static inline void mp_set_cpu_idle(uint cpu)
+{
+    mp.idle_cpus |= 1UL << cpu;
+}
+
+static inline void mp_set_cpu_busy(uint cpu)
+{
+    mp.idle_cpus &= ~(1UL << cpu);
+}
+
+static inline mp_cpu_mask_t mp_get_idle_mask(void)
+{
+    return mp.idle_cpus;
+}
+
+static inline void mp_set_cpu_realtime(uint cpu)
+{
+    mp.realtime_cpus |= 1UL << cpu;
+}
+
+static inline void mp_set_cpu_non_realtime(uint cpu)
+{
+    mp.realtime_cpus &= ~(1UL << cpu);
+}
+
+static inline mp_cpu_mask_t mp_get_realtime_mask(void)
+{
+    return mp.realtime_cpus;
+}
+#else
+static inline void mp_init(void) {}
+static inline void mp_reschedule(mp_cpu_mask_t target, uint flags) {}
+static inline void mp_set_curr_cpu_active(bool active) {}
+
+static inline enum handler_return mp_mbx_reschedule_irq(void) { return 0; }
+
+// only one cpu exists in UP and if you're calling these functions, it's active...
+static inline int mp_is_cpu_active(uint cpu) { return 1; }
+static inline int mp_is_cpu_idle(uint cpu) { return 0; }
+
+static inline void mp_set_cpu_idle(uint cpu) {}
+static inline void mp_set_cpu_busy(uint cpu) {}
+
+static inline mp_cpu_mask_t mp_get_idle_mask(void) { return 0; }
+
+static inline void mp_set_cpu_realtime(uint cpu) {}
+static inline void mp_set_cpu_non_realtime(uint cpu) {}
+
+static inline mp_cpu_mask_t mp_get_realtime_mask(void) { return 0; }
+#endif
+
+__END_CDECLS;
diff --git a/src/bsp/lk/include/kernel/mutex.h b/src/bsp/lk/include/kernel/mutex.h
new file mode 100644
index 0000000..ae7e233
--- /dev/null
+++ b/src/bsp/lk/include/kernel/mutex.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ * Copyright (c) 2012 Shantanu Gupta
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_MUTEX_H
+#define __KERNEL_MUTEX_H
+
+#include <compiler.h>
+#include <debug.h>
+#include <stdint.h>
+#include <kernel/thread.h>
+
+__BEGIN_CDECLS;
+
+#define MUTEX_MAGIC 'mutx'
+
+typedef struct mutex {
+	uint32_t magic;
+	thread_t *holder;
+	int count;
+	wait_queue_t wait;
+} mutex_t;
+
+#define MUTEX_INITIAL_VALUE(m) \
+{ \
+	.magic = MUTEX_MAGIC, \
+	.holder = NULL, \
+	.count = 0, \
+	.wait = WAIT_QUEUE_INITIAL_VALUE((m).wait), \
+}
+
+/* Rules for Mutexes:
+ * - Mutexes are only safe to use from thread context.
+ * - Mutexes are non-recursive.
+*/
+
+void mutex_init(mutex_t *);
+void mutex_destroy(mutex_t *);
+status_t mutex_acquire_timeout(mutex_t *, lk_time_t); /* try to acquire the mutex with a timeout value */
+status_t mutex_release(mutex_t *);
+
+static inline status_t mutex_acquire(mutex_t *m) {
+	return mutex_acquire_timeout(m, INFINITE_TIME);
+}
+
+/* does the current thread hold the mutex? */
+static bool is_mutex_held(mutex_t *m) {
+	return m->holder == get_current_thread();
+}
+
+__END_CDECLS;
+#endif
+
diff --git a/src/bsp/lk/include/kernel/novm.h b/src/bsp/lk/include/kernel/novm.h
new file mode 100644
index 0000000..c55c320
--- /dev/null
+++ b/src/bsp/lk/include/kernel/novm.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 Google, Inc. All rights reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_NOVM_H
+#define __KERNEL_NOVM_H
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <arch.h>
+
+#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE)
+#define IS_PAGE_ALIGNED(x) IS_ALIGNED(x, PAGE_SIZE)
+
+// arena bitmaps for novm_alloc_pages
+#define NOVM_ARENA_ANY (UINT32_MAX)
+#define NOVM_ARENA_MAIN (1<<0)
+#define NOVM_ARENA_SECONDARY (~NOVM_ARENA_MAIN)
+
+void *novm_alloc_pages(size_t pages, uint32_t arena_bitmap);
+void novm_free_pages(void* address, size_t pages);
+status_t novm_alloc_specific_pages(void *address, size_t pages);
+
+// You can call this once and it will give you some possibly unaligned memory
+// that would otherwise go to waste.  The memory can't be freed.
+void *novm_alloc_unaligned(size_t *size_return);
+
+void novm_add_arena(const char *name, uintptr_t arena_start, uintptr_t arena_size);
+
+#endif
diff --git a/src/bsp/lk/include/kernel/port.h b/src/bsp/lk/include/kernel/port.h
new file mode 100644
index 0000000..347125e
--- /dev/null
+++ b/src/bsp/lk/include/kernel/port.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2015 Carlos Pizano-Uribe  cpu@chromium.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_PORT_H
+#define __KERNEL_PORT_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+
+__BEGIN_CDECLS;
+
+/* Ports are named, opaque objects and come in tree flavors, the
+ * write-side, the read-side and a port group which is a collection
+ * of read-side ports.
+ */
+
+#define PORT_NAME_LEN 12
+
+typedef void* port_t;
+
+typedef struct {
+    char value[8];
+} port_packet_t;
+
+typedef struct {
+    void* ctx;
+    port_packet_t packet;
+} port_result_t;
+
+typedef enum {
+    PORT_MODE_BROADCAST   = 0,
+    PORT_MODE_UNICAST     = 1,
+    PORT_MODE_BIG_BUFFER  = 2,
+} port_mode_t;
+
+/* Inits the port subsystem
+ */
+void port_init(void);
+
+/* Make a named write-side port. broadcast ports can be opened by any
+ * number of read-clients. |name| can be up to PORT_NAME_LEN chars. If
+ * the write port exists it is returned even if the |mode| does not match.
+ */
+status_t port_create(const char* name, port_mode_t mode, port_t* port);
+
+/* Make a read-side port. Only non-destroyed existing write ports can
+ * be opened with this api. Unicast ports can only be opened once. For
+ * broadcast ports, each call if successful returns a new port.
+ */
+status_t port_open(const char* name, void* ctx, port_t* port);
+
+/* Creates a read-side port group which behaves just like a regular
+ * read-side port. A given port can only be assoicated with one port group.
+ */
+status_t port_group(port_t* ports, size_t count, port_t* group);
+
+/* Write to a port |count| packets, non-blocking, all or none atomic success.
+ */
+status_t port_write(port_t port, const port_packet_t* pk, size_t count);
+
+/* Read one packet from the port or port group, blocking. The |result| contains
+ * the port that the message was read from. If |timeout| is zero the call
+ * does not block.
+ */
+status_t port_read(port_t port, lk_time_t timeout, port_result_t* result);
+
+/* Destroy the write-side port, flush queued packets and release all resources,
+ * all calls will now fail on that port. Only a closed port can be destroyed.
+ */
+status_t port_destroy(port_t port);
+
+/* Close the read-side port or the write side port. A closed write side port
+ * can be opened and the pending packets read. closing a port group does not
+ * close the included ports.
+ */
+status_t port_close(port_t port);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/kernel/semaphore.h b/src/bsp/lk/include/kernel/semaphore.h
new file mode 100644
index 0000000..99d9a20
--- /dev/null
+++ b/src/bsp/lk/include/kernel/semaphore.h
@@ -0,0 +1,49 @@
+/* semaphore.h
+ *
+ * Copyright 2012 Christopher Anderson <chris@nullcode.org>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __KERNEL_SEMAPHORE_H
+#define __KERNEL_SEMAPHORE_H
+
+#include <compiler.h>
+#include <kernel/thread.h>
+#include <kernel/mutex.h>
+
+__BEGIN_CDECLS;
+
+#define SEMAPHORE_MAGIC 'sema'
+
+typedef struct semaphore {
+	int magic;
+	int count;
+	wait_queue_t wait;
+} semaphore_t;
+
+#define SEMAPHORE_INITIAL_VALUE(s, _count) \
+{ \
+	.magic = SEMAPHORE_MAGIC, \
+	.count = _count, \
+	.wait = WAIT_QUEUE_INITIAL_VALUE((s).wait), \
+}
+
+void sem_init(semaphore_t *, unsigned int);
+void sem_destroy(semaphore_t *);
+int sem_post(semaphore_t *, bool resched);
+status_t sem_wait(semaphore_t *);
+status_t sem_trywait(semaphore_t *);
+status_t sem_timedwait(semaphore_t *, lk_time_t);
+
+__END_CDECLS;
+#endif
diff --git a/src/bsp/lk/include/kernel/spinlock.h b/src/bsp/lk/include/kernel/spinlock.h
new file mode 100644
index 0000000..b9bf246
--- /dev/null
+++ b/src/bsp/lk/include/kernel/spinlock.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <compiler.h>
+#include <arch/spinlock.h>
+
+__BEGIN_CDECLS
+
+/* interrupts should already be disabled */
+static inline void spin_lock(spin_lock_t *lock)
+{
+    arch_spin_lock(lock);
+}
+
+ /* Returns 0 on success, non-0 on failure */
+static inline int spin_trylock(spin_lock_t *lock)
+{
+    return arch_spin_trylock(lock);
+}
+
+/* interrupts should already be disabled */
+static inline void spin_unlock(spin_lock_t *lock)
+{
+    arch_spin_unlock(lock);
+}
+
+static inline void spin_lock_init(spin_lock_t *lock)
+{
+    arch_spin_lock_init(lock);
+}
+
+static inline bool spin_lock_held(spin_lock_t *lock)
+{
+    return arch_spin_lock_held(lock);
+}
+
+/* spin lock irq save flags: */
+
+/* Possible future flags:
+ * SPIN_LOCK_FLAG_PMR_MASK         = 0x000000ff
+ * SPIN_LOCK_FLAG_PREEMPTION       = 0x00000100
+ * SPIN_LOCK_FLAG_SET_PMR          = 0x00000200
+ */
+
+/* Generic flags */
+#define SPIN_LOCK_FLAG_INTERRUPTS ARCH_DEFAULT_SPIN_LOCK_FLAG_INTERRUPTS
+
+/* same as spin lock, but save disable and save interrupt state first */
+static inline void spin_lock_save(
+        spin_lock_t *lock,
+        spin_lock_saved_state_t *statep,
+        spin_lock_save_flags_t flags)
+{
+    arch_interrupt_save(statep, flags);
+    spin_lock(lock);
+}
+
+/* restore interrupt state before unlocking */
+static inline void spin_unlock_restore(
+        spin_lock_t *lock,
+        spin_lock_saved_state_t old_state,
+        spin_lock_save_flags_t flags)
+{
+    spin_unlock(lock);
+    arch_interrupt_restore(old_state, flags);
+}
+
+/* hand(ier) routines */
+#define spin_lock_irqsave(lock, statep) spin_lock_save(lock, &(statep), SPIN_LOCK_FLAG_INTERRUPTS)
+#define spin_unlock_irqrestore(lock, statep) spin_unlock_restore(lock, statep, SPIN_LOCK_FLAG_INTERRUPTS)
+
+__END_CDECLS
diff --git a/src/bsp/lk/include/kernel/thread.h b/src/bsp/lk/include/kernel/thread.h
new file mode 100644
index 0000000..7ddbf21
--- /dev/null
+++ b/src/bsp/lk/include/kernel/thread.h
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2008-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_THREAD_H
+#define __KERNEL_THREAD_H
+
+#include <sys/types.h>
+#include <list.h>
+#include <compiler.h>
+#include <arch/defines.h>
+#include <arch/ops.h>
+#include <arch/thread.h>
+#include <kernel/wait.h>
+#include <kernel/spinlock.h>
+#include <debug.h>
+
+__BEGIN_CDECLS;
+
+/* debug-enable runtime checks */
+#if LK_DEBUGLEVEL > 1
+#define THREAD_STATS 1
+#define THREAD_STACK_BOUNDS_CHECK 1
+#ifndef THREAD_STACK_PADDING_SIZE
+#define THREAD_STACK_PADDING_SIZE 256
+#endif
+#endif
+
+enum thread_state {
+	THREAD_SUSPENDED = 0,
+	THREAD_READY,
+	THREAD_RUNNING,
+	THREAD_BLOCKED,
+	THREAD_SLEEPING,
+	THREAD_DEATH,
+};
+
+typedef int (*thread_start_routine)(void *arg);
+
+/* thread local storage */
+enum thread_tls_list {
+#ifdef WITH_LIB_UTHREAD
+	TLS_ENTRY_UTHREAD,
+#endif
+#ifdef WITH_LIB_LKUSER
+	TLS_ENTRY_LKUSER,
+#endif
+	MAX_TLS_ENTRY
+};
+
+#define THREAD_FLAG_DETACHED                  (1<<0)
+#define THREAD_FLAG_FREE_STACK                (1<<1)
+#define THREAD_FLAG_FREE_STRUCT               (1<<2)
+#define THREAD_FLAG_REAL_TIME                 (1<<3)
+#define THREAD_FLAG_IDLE                      (1<<4)
+#define THREAD_FLAG_DEBUG_STACK_BOUNDS_CHECK  (1<<5)
+
+#define THREAD_MAGIC 'thrd'
+
+typedef struct thread {
+	int magic;
+	struct list_node thread_list_node;
+
+	/* active bits */
+	struct list_node queue_node;
+	int priority;
+	enum thread_state state;
+	int remaining_quantum;
+	unsigned int flags;
+#if WITH_SMP
+	int curr_cpu;
+	int pinned_cpu; /* only run on pinned_cpu if >= 0 */
+#endif
+
+	/* if blocked, a pointer to the wait queue */
+	struct wait_queue *blocking_wait_queue;
+	status_t wait_queue_block_ret;
+
+	/* architecture stuff */
+	struct arch_thread arch;
+
+	/* stack stuff */
+	void *stack;
+	size_t stack_size;
+
+	/* entry point */
+	thread_start_routine entry;
+	void *arg;
+
+	/* return code */
+	int retcode;
+	struct wait_queue retcode_wait_queue;
+
+	/* thread local storage */
+	uintptr_t tls[MAX_TLS_ENTRY];
+
+	char name[32];
+} thread_t;
+
+#if WITH_SMP
+#define thread_curr_cpu(t) ((t)->curr_cpu)
+#define thread_pinned_cpu(t) ((t)->pinned_cpu)
+#define thread_set_curr_cpu(t,c) ((t)->curr_cpu = (c))
+#define thread_set_pinned_cpu(t, c) ((t)->pinned_cpu = (c))
+#else
+#define thread_curr_cpu(t) (0)
+#define thread_pinned_cpu(t) (-1)
+#define thread_set_curr_cpu(t,c) do {} while(0)
+#define thread_set_pinned_cpu(t, c) do {} while(0)
+#endif
+
+/* thread priority */
+#define NUM_PRIORITIES 32
+#define LOWEST_PRIORITY 0
+#define HIGHEST_PRIORITY (NUM_PRIORITIES - 1)
+#define DPC_PRIORITY (NUM_PRIORITIES - 2)
+#define IDLE_PRIORITY LOWEST_PRIORITY
+#define LOW_PRIORITY (NUM_PRIORITIES / 4)
+#define DEFAULT_PRIORITY (NUM_PRIORITIES / 2)
+#define HIGH_PRIORITY ((NUM_PRIORITIES / 4) * 3)
+
+/* stack size */
+#ifdef CUSTOM_DEFAULT_STACK_SIZE
+#define DEFAULT_STACK_SIZE CUSTOM_DEFAULT_STACK_SIZE
+#else
+#define DEFAULT_STACK_SIZE ARCH_DEFAULT_STACK_SIZE
+#endif
+
+/* functions */
+void thread_init_early(void);
+void thread_init(void);
+void thread_become_idle(void) __NO_RETURN;
+void thread_secondary_cpu_init_early(void);
+void thread_secondary_cpu_entry(void) __NO_RETURN;
+void thread_set_name(const char *name);
+void thread_set_priority(int priority);
+thread_t *thread_create(const char *name, thread_start_routine entry, void *arg, int priority, size_t stack_size);
+thread_t *thread_create_etc(thread_t *t, const char *name, thread_start_routine entry, void *arg, int priority, void *stack, size_t stack_size);
+status_t thread_resume(thread_t *);
+void thread_exit(int retcode) __NO_RETURN;
+void thread_sleep(lk_time_t delay);
+status_t thread_detach(thread_t *t);
+status_t thread_join(thread_t *t, int *retcode, lk_time_t timeout);
+status_t thread_detach_and_resume(thread_t *t);
+status_t thread_set_real_time(thread_t *t);
+
+void dump_thread(thread_t *t);
+void arch_dump_thread(thread_t *t);
+void dump_all_threads(void);
+
+/* scheduler routines */
+void thread_yield(void); /* give up the cpu voluntarily */
+void thread_preempt(void); /* get preempted (inserted into head of run queue) */
+void thread_block(void); /* block on something and reschedule */
+void thread_unblock(thread_t *t, bool resched); /* go back in the run queue */
+
+#ifdef WITH_LIB_UTHREAD
+void uthread_context_switch(thread_t *oldthread, thread_t *newthread);
+#endif
+
+/* called on every timer tick for the scheduler to do quantum expiration */
+struct timer;
+enum handler_return thread_timer_tick(struct timer *, lk_time_t now, void *arg);
+
+/* the current thread */
+thread_t *get_current_thread(void);
+void set_current_thread(thread_t *);
+
+/* scheduler lock */
+extern spin_lock_t thread_lock;
+
+#define THREAD_LOCK(state) spin_lock_saved_state_t state; spin_lock_irqsave(&thread_lock, state)
+#define THREAD_UNLOCK(state) spin_unlock_irqrestore(&thread_lock, state)
+
+/* thread local storage */
+static inline __ALWAYS_INLINE uintptr_t tls_get(uint entry)
+{
+	return get_current_thread()->tls[entry];
+}
+
+static inline __ALWAYS_INLINE uintptr_t __tls_set(uint entry, uintptr_t val)
+{
+	uintptr_t oldval = get_current_thread()->tls[entry];
+	get_current_thread()->tls[entry] = val;
+	return oldval;
+}
+
+#define tls_set(e,v) \
+	({ \
+		STATIC_ASSERT((e) < MAX_TLS_ENTRY); \
+		__tls_set(e, v); \
+	})
+
+/* thread level statistics */
+#if THREAD_STATS
+struct thread_stats {
+	lk_bigtime_t idle_time;
+	lk_bigtime_t last_idle_timestamp;
+	ulong reschedules;
+	ulong context_switches;
+	ulong preempts;
+	ulong yields;
+	ulong interrupts; /* platform code increment this */
+	ulong timer_ints; /* timer code increment this */
+	ulong timers; /* timer code increment this */
+
+#if WITH_SMP
+	ulong reschedule_ipis;
+#endif
+};
+
+extern struct thread_stats thread_stats[SMP_MAX_CPUS];
+
+#define THREAD_STATS_INC(name) do { thread_stats[arch_curr_cpu_num()].name++; } while(0)
+
+#else
+
+#define THREAD_STATS_INC(name) do { } while (0)
+
+#endif
+
+__END_CDECLS;
+
+#endif
+
+/* vim: set ts=4 sw=4 noexpandtab: */
diff --git a/src/bsp/lk/include/kernel/timer.h b/src/bsp/lk/include/kernel/timer.h
new file mode 100644
index 0000000..bd1d8af
--- /dev/null
+++ b/src/bsp/lk/include/kernel/timer.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008-2009 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_TIMER_H
+#define __KERNEL_TIMER_H
+
+#include <compiler.h>
+#include <list.h>
+#include <sys/types.h>
+
+__BEGIN_CDECLS;
+
+void timer_init(void);
+
+struct timer;
+typedef enum handler_return (*timer_callback)(struct timer *, lk_time_t now, void *arg);
+
+#define TIMER_MAGIC 'timr'
+
+typedef struct timer {
+	int magic;
+	struct list_node node;
+
+	lk_time_t scheduled_time;
+	lk_time_t periodic_time;
+
+	timer_callback callback;
+	void *arg;
+} timer_t;
+
+#define TIMER_INITIAL_VALUE(t) \
+{ \
+	.magic = TIMER_MAGIC, \
+	.node = LIST_INITIAL_CLEARED_VALUE, \
+	.scheduled_time = 0, \
+	.periodic_time = 0, \
+	.callback = NULL, \
+	.arg = NULL, \
+}
+
+/* Rules for Timers:
+ * - Timer callbacks occur from interrupt context
+ * - Timers may be programmed or canceled from interrupt or thread context
+ * - Timers may be canceled or reprogrammed from within their callback
+ * - Timers currently are dispatched from a 10ms periodic tick
+*/
+void timer_initialize(timer_t *);
+void timer_set_oneshot(timer_t *, lk_time_t delay, timer_callback, void *arg);
+void timer_set_periodic(timer_t *, lk_time_t period, timer_callback, void *arg);
+void timer_cancel(timer_t *);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/kernel/vm.h b/src/bsp/lk/include/kernel/vm.h
new file mode 100644
index 0000000..552e7e8
--- /dev/null
+++ b/src/bsp/lk/include/kernel/vm.h
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+/* some assembly #defines, need to match the structure below */
+#if IS_64BIT
+#define __MMU_INITIAL_MAPPING_PHYS_OFFSET 0
+#define __MMU_INITIAL_MAPPING_VIRT_OFFSET 8
+#define __MMU_INITIAL_MAPPING_SIZE_OFFSET 16
+#define __MMU_INITIAL_MAPPING_FLAGS_OFFSET 24
+#define __MMU_INITIAL_MAPPING_SIZE        40
+#else
+#define __MMU_INITIAL_MAPPING_PHYS_OFFSET 0
+#define __MMU_INITIAL_MAPPING_VIRT_OFFSET 4
+#define __MMU_INITIAL_MAPPING_SIZE_OFFSET 8
+#define __MMU_INITIAL_MAPPING_FLAGS_OFFSET 12
+#define __MMU_INITIAL_MAPPING_SIZE        20
+#endif
+
+/* flags for initial mapping struct */
+#define MMU_INITIAL_MAPPING_TEMPORARY     (0x1)
+#define MMU_INITIAL_MAPPING_FLAG_UNCACHED (0x2)
+#define MMU_INITIAL_MAPPING_FLAG_DEVICE   (0x4)
+#define MMU_INITIAL_MAPPING_FLAG_DYNAMIC  (0x8)  /* entry has to be patched up by platform_reset */
+
+#ifndef ASSEMBLY
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <compiler.h>
+#include <list.h>
+#include <stdlib.h>
+#include <arch.h>
+#include <arch/mmu.h>
+
+__BEGIN_CDECLS
+
+#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE)
+#define IS_PAGE_ALIGNED(x) IS_ALIGNED(x, PAGE_SIZE)
+
+struct mmu_initial_mapping {
+    paddr_t phys;
+    vaddr_t virt;
+    size_t  size;
+    unsigned int flags;
+    const char *name;
+};
+
+/* Assert that the assembly macros above match this struct. */
+STATIC_ASSERT(__offsetof(struct mmu_initial_mapping, phys) == __MMU_INITIAL_MAPPING_PHYS_OFFSET);
+STATIC_ASSERT(__offsetof(struct mmu_initial_mapping, virt) == __MMU_INITIAL_MAPPING_VIRT_OFFSET);
+STATIC_ASSERT(__offsetof(struct mmu_initial_mapping, size) == __MMU_INITIAL_MAPPING_SIZE_OFFSET);
+STATIC_ASSERT(__offsetof(struct mmu_initial_mapping, flags) == __MMU_INITIAL_MAPPING_FLAGS_OFFSET);
+STATIC_ASSERT(sizeof(struct mmu_initial_mapping) == __MMU_INITIAL_MAPPING_SIZE);
+
+/* Platform or target must fill out one of these to set up the initial memory map
+ * for kernel and enough IO space to boot.
+ */
+extern struct mmu_initial_mapping mmu_initial_mappings[];
+
+/* core per page structure */
+typedef struct vm_page {
+    struct list_node node;
+
+    uint flags : 8;
+    uint ref : 24;
+} vm_page_t;
+
+#define VM_PAGE_FLAG_NONFREE  (0x1)
+
+/* kernel address space */
+#ifndef KERNEL_ASPACE_BASE
+#define KERNEL_ASPACE_BASE ((vaddr_t)0x80000000UL)
+#endif
+#ifndef KERNEL_ASPACE_SIZE
+#define KERNEL_ASPACE_SIZE ((vaddr_t)0x80000000UL)
+#endif
+
+STATIC_ASSERT(KERNEL_ASPACE_BASE + (KERNEL_ASPACE_SIZE - 1) > KERNEL_ASPACE_BASE);
+
+static inline bool is_kernel_address(vaddr_t va)
+{
+    return (va >= KERNEL_ASPACE_BASE && va <= (KERNEL_ASPACE_BASE + KERNEL_ASPACE_SIZE - 1));
+}
+
+/* user address space, defaults to below kernel space with a 16MB guard gap on either side */
+#ifndef USER_ASPACE_BASE
+#define USER_ASPACE_BASE ((vaddr_t)0x01000000UL)
+#endif
+#ifndef USER_ASPACE_SIZE
+#define USER_ASPACE_SIZE ((vaddr_t)KERNEL_ASPACE_BASE - USER_ASPACE_BASE - 0x01000000UL)
+#endif
+
+STATIC_ASSERT(USER_ASPACE_BASE + (USER_ASPACE_SIZE - 1) > USER_ASPACE_BASE);
+
+static inline bool is_user_address(vaddr_t va)
+{
+    return (va >= USER_ASPACE_BASE && va <= (USER_ASPACE_BASE + USER_ASPACE_SIZE - 1));
+}
+
+
+/* physical allocator */
+typedef struct pmm_arena {
+    struct list_node node;
+    const char *name;
+
+    uint flags;
+    uint priority;
+
+    paddr_t base;
+    size_t  size;
+
+    size_t free_count;
+
+    struct vm_page *page_array;
+    struct list_node free_list;
+} pmm_arena_t;
+
+#define PMM_ARENA_FLAG_KMAP (0x1) /* this arena is already mapped and useful for kallocs */
+
+/* Add a pre-filled memory arena to the physical allocator. */
+status_t pmm_add_arena(pmm_arena_t *arena);
+
+/* Allocate count pages of physical memory, adding to the tail of the passed list.
+ * The list must be initialized.
+ * Returns the number of pages allocated.
+ */
+size_t pmm_alloc_pages(uint count, struct list_node *list);
+
+/* Allocate a specific range of physical pages, adding to the tail of the passed list.
+ * The list must be initialized.
+ * Returns the number of pages allocated.
+ */
+size_t pmm_alloc_range(paddr_t address, uint count, struct list_node *list);
+
+/* Free a list of physical pages.
+ * Returns the number of pages freed.
+ */
+size_t pmm_free(struct list_node *list);
+
+/* Helper routine for the above. */
+size_t pmm_free_page(vm_page_t *page);
+
+/* Allocate a run of contiguous pages, aligned on log2 byte boundary (0-31)
+ * If the optional physical address pointer is passed, return the address.
+ * If the optional list is passed, append the allocate page structures to the tail of the list.
+ */
+size_t pmm_alloc_contiguous(uint count, uint8_t align_log2, paddr_t *pa, struct list_node *list);
+
+/* Allocate a run of pages out of the kernel area and return the pointer in kernel space.
+ * If the optional list is passed, append the allocate page structures to the tail of the list.
+ */
+void *pmm_alloc_kpages(uint count, struct list_node *list);
+
+/* Helper routine for pmm_alloc_kpages. */
+static inline void *pmm_alloc_kpage(void) { return pmm_alloc_kpages(1, NULL); }
+
+size_t pmm_free_kpages(void *ptr, uint count);
+
+/* physical to virtual */
+void *paddr_to_kvaddr(paddr_t pa);
+
+/* virtual to physical */
+paddr_t kvaddr_to_paddr(void *va);
+
+/* virtual allocator */
+typedef struct vmm_aspace {
+    struct list_node node;
+    char name[32];
+
+    uint flags;
+
+    vaddr_t base;
+    size_t  size;
+
+    struct list_node region_list;
+} vmm_aspace_t;
+
+typedef struct vmm_region {
+    struct list_node node;
+    char name[32];
+
+    uint flags;
+    uint arch_mmu_flags;
+
+    vaddr_t base;
+    size_t  size;
+
+    struct list_node page_list;
+} vmm_region_t;
+
+#define VMM_REGION_FLAG_RESERVED 0x1
+#define VMM_REGION_FLAG_PHYSICAL 0x2
+
+/* grab a handle to the kernel address space */
+extern vmm_aspace_t _kernel_aspace;
+static inline vmm_aspace_t *vmm_get_kernel_aspace(void) {
+    return &_kernel_aspace;
+}
+
+/* reserve a chunk of address space to prevent allocations from that space */
+status_t vmm_reserve_space(vmm_aspace_t *aspace, const char *name, size_t size, vaddr_t vaddr);
+
+/* allocate a region of virtual space that maps a physical piece of address space.
+   the physical pages that back this are not allocated from the pmm. */
+status_t vmm_alloc_physical_etc(vmm_aspace_t *aspace, const char *name, size_t size, void **ptr, uint8_t align_log2, paddr_t *paddr, uint paddr_count, uint vmm_flags, uint arch_mmu_flags);
+
+/* allocate a region of virtual space that maps a physical piece of address space.
+   the physical pages that back this are not allocated from the pmm. */
+status_t vmm_alloc_physical(vmm_aspace_t *aspace, const char *name, size_t size, void **ptr, uint8_t align_log2, paddr_t paddr, uint vmm_flags, uint arch_mmu_flags);
+
+/* allocate a region of memory backed by newly allocated contiguous physical memory  */
+status_t vmm_alloc_contiguous(vmm_aspace_t *aspace, const char *name, size_t size, void **ptr, uint8_t align_log2, uint vmm_flags, uint arch_mmu_flags);
+
+/* allocate a region of memory backed by newly allocated physical memory */
+status_t vmm_alloc(vmm_aspace_t *aspace, const char *name, size_t size, void **ptr, uint8_t align_log2, uint vmm_flags, uint arch_mmu_flags);
+
+/* Unmap previously allocated region and free physical memory pages backing it (if any) */
+status_t vmm_free_region(vmm_aspace_t *aspace, vaddr_t va);
+
+    /* For the above region creation routines. Allocate virtual space at the passed in pointer. */
+#define VMM_FLAG_VALLOC_SPECIFIC 0x1
+
+/* allocate a new address space */
+status_t vmm_create_aspace(vmm_aspace_t **aspace, const char *name, uint flags);
+
+/* destroy everything in the address space */
+status_t vmm_free_aspace(vmm_aspace_t *aspace);
+
+#define VMM_FLAG_ASPACE_KERNEL 0x1
+
+__END_CDECLS
+
+#endif // !ASSEMBLY
diff --git a/src/bsp/lk/include/kernel/wait.h b/src/bsp/lk/include/kernel/wait.h
new file mode 100644
index 0000000..d0fa2f0
--- /dev/null
+++ b/src/bsp/lk/include/kernel/wait.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_WAIT_H
+#define __KERNEL_WAIT_H
+
+#include <sys/types.h>
+#include <list.h>
+#include <compiler.h>
+#include <arch/defines.h>
+#include <arch/ops.h>
+#include <arch/thread.h>
+
+__BEGIN_CDECLS;
+
+/* wait queue stuff */
+#define WAIT_QUEUE_MAGIC 'wait'
+
+typedef struct wait_queue {
+	int magic;
+	struct list_node list;
+	int count;
+} wait_queue_t;
+
+#define WAIT_QUEUE_INITIAL_VALUE(q) \
+{ \
+	.magic = WAIT_QUEUE_MAGIC, \
+	.list = LIST_INITIAL_VALUE((q).list), \
+	.count = 0 \
+}
+
+/* wait queue primitive */
+/* NOTE: must be inside critical section when using these */
+void wait_queue_init(wait_queue_t *wait);
+
+/*
+ * release all the threads on this wait queue with a return code of ERR_OBJECT_DESTROYED.
+ * the caller must assure that no other threads are operating on the wait queue during or
+ * after the call.
+ */
+void wait_queue_destroy(wait_queue_t *, bool reschedule);
+
+/*
+ * block on a wait queue.
+ * return status is whatever the caller of wait_queue_wake_*() specifies.
+ * a timeout other than INFINITE_TIME will set abort after the specified time
+ * and return ERR_TIMED_OUT. a timeout of 0 will immediately return.
+ */
+status_t wait_queue_block(wait_queue_t *, lk_time_t timeout);
+
+/*
+ * release one or more threads from the wait queue.
+ * reschedule = should the system reschedule if any is released.
+ * wait_queue_error = what wait_queue_block() should return for the blocking thread.
+ */
+int wait_queue_wake_one(wait_queue_t *, bool reschedule, status_t wait_queue_error);
+int wait_queue_wake_all(wait_queue_t *, bool reschedule, status_t wait_queue_error);
+
+/*
+ * remove the thread from whatever wait queue it's in.
+ * return an error if the thread is not currently blocked (or is the current thread)
+ */
+status_t thread_unblock_from_wait_queue(struct thread *t, status_t wait_queue_error);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/aes.h b/src/bsp/lk/include/lib/aes.h
new file mode 100644
index 0000000..85c0c51
--- /dev/null
+++ b/src/bsp/lk/include/lib/aes.h
@@ -0,0 +1,51 @@
+/* aes.h 
+ * Jason E. Holt
+ * released into the public domain
+ */
+
+#ifndef AES_H
+#define AES_H
+
+#include <stdint.h>
+
+enum AES_KEYSIZE {
+    AES_KEYSIZE_128 = 0,
+    AES_KEYSIZE_192,
+    AES_KEYSIZE_256
+};
+
+#if HW_AES_IMPL
+
+// XXX get from a better source?
+typedef struct {
+    enum AES_KEYSIZE size;
+    uint8_t key[256/8];
+} AES_KEY;
+
+#else // software implementation
+
+struct aes_key_struct_sw {
+    unsigned long rd_key[60];
+    int rounds;
+};
+
+typedef struct aes_key_struct_sw AES_KEY;
+
+#endif
+
+#define AES_BLOCK_SIZE 16
+
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+                            AES_KEY *key);
+
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
+                             AES_KEY *key);
+
+void AES_decrypt(const unsigned char *in, unsigned char *out,
+                         const AES_KEY *key);
+
+void AES_encrypt(const unsigned char *in, unsigned char *out,
+                         const AES_KEY *key);
+
+
+#endif
diff --git a/src/bsp/lk/include/lib/bytes.h b/src/bsp/lk/include/lib/bytes.h
new file mode 100644
index 0000000..45e5583
--- /dev/null
+++ b/src/bsp/lk/include/lib/bytes.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __BYTES_H
+#define __BYTES_H
+
+#include <endian.h>
+#include <stdint.h>
+
+#if BYTE_ORDER == BIG_ENDIAN
+#define bytes_read_u16(x)       bytes_read_u16_be(x)
+#define bytes_read_u24(x)       bytes_read_u24_be(x)
+#define bytes_read_u32(x)       bytes_read_u32_be(x)
+#define bytes_write_u16(x, y)   bytes_write_u16_be(x, y)
+#define bytes_write_u24(x, y)   bytes_write_u24_be(x, y)
+#define bytes_write_u32(x, y)   bytes_write_u32_be(x, y)
+#elif BYTE_ORDER == LITTLE_ENDIAN
+#define bytes_read_u16(x)       bytes_read_u16_le(x)
+#define bytes_read_u24(x)       bytes_read_u24_le(x)
+#define bytes_read_u32(x)       bytes_read_u32_le(x)
+#define bytes_write_u16(x, y)   bytes_write_u16_le(x, y)
+#define bytes_write_u24(x, y)   bytes_write_u24_le(x, y)
+#define bytes_write_u32(x, y)   bytes_write_u32_le(x, y)
+#else
+#error "Endianness not defined!"
+#endif
+
+
+// Big endian interfaces
+uint16_t bytes_read_u16_be(const uint8_t *buf);
+uint32_t bytes_read_u24_be(const uint8_t *buf);
+uint32_t bytes_read_u32_be(const uint8_t *buf);
+
+uint8_t* bytes_write_u16_be(uint8_t *buf, uint16_t val);
+uint8_t* bytes_write_u24_be(uint8_t *buf, uint32_t val);
+uint8_t* bytes_write_u32_be(uint8_t *buf, uint32_t val);
+
+// Little endian interfaces
+uint16_t bytes_read_u16_le(const uint8_t *buf);
+uint32_t bytes_read_u24_le(const uint8_t *buf);
+uint32_t bytes_read_u32_le(const uint8_t *buf);
+
+uint8_t* bytes_write_u16_le(uint8_t *buf, uint16_t val);
+uint8_t* bytes_write_u24_le(uint8_t *buf, uint32_t val);
+uint8_t* bytes_write_u32_le(uint8_t *buf, uint32_t val);
+
+// Bit swapping interfaces
+uint8_t  bytes_swap_bits_u8(uint8_t val);
+uint16_t bytes_swap_bits_u16(uint16_t val);
+uint32_t bytes_swap_bits_u24(uint32_t val);
+uint32_t bytes_swap_bits_u32(uint32_t val);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/cksum.h b/src/bsp/lk/include/lib/cksum.h
new file mode 100644
index 0000000..130e095
--- /dev/null
+++ b/src/bsp/lk/include/lib/cksum.h
@@ -0,0 +1,32 @@
+#ifndef __CKSUM_H
+#define __CKSUM_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+ /*
+  * Computes the CRC-CCITT, starting with an initialization value.
+  * buf: the data on which to apply the checksum
+  * length: the number of bytes of data in 'buf' to be calculated.
+  */
+unsigned short crc16(const unsigned char *buf, unsigned int length);
+
+ /*
+  * Computes an updated version of the CRC-CCITT from existing CRC.
+  * crc: the previous values of the CRC
+  * buf: the data on which to apply the checksum
+  * length: the number of bytes of data in 'buf' to be calculated.
+  */
+unsigned short update_crc16(unsigned short crc, const unsigned char *buf, unsigned int len);
+
+unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len);
+
+unsigned long adler32(unsigned long adler, const unsigned char *buf, unsigned int len);
+
+uint32_t crc32_no_comp(uint32_t crc, const unsigned char *buf, unsigned int len);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/console.h b/src/bsp/lk/include/lib/console.h
new file mode 100644
index 0000000..1bbe854
--- /dev/null
+++ b/src/bsp/lk/include/lib/console.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2008-2009 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_CONSOLE_H
+#define __LIB_CONSOLE_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <compiler.h>
+
+/* command args */
+typedef struct {
+	const char *str;
+	unsigned long u;
+	void* p;
+	long i;
+	bool b;
+} cmd_args;
+
+typedef int (*console_cmd)(int argc, const cmd_args *argv);
+
+#define CMD_AVAIL_NORMAL (0x1 << 0)
+#define CMD_AVAIL_PANIC  (0x1 << 1)
+#define CMD_AVAIL_ALWAYS (CMD_AVAIL_NORMAL | CMD_AVAIL_PANIC)
+
+/* a block of commands to register */
+typedef struct {
+	const char *cmd_str;
+	const char *help_str;
+	const console_cmd cmd_callback;
+	uint8_t availability_mask;
+} cmd;
+
+typedef struct _cmd_block {
+	struct _cmd_block *next;
+	size_t count;
+	const cmd *list;
+} cmd_block;
+
+/* register a static block of commands at init time */
+#if WITH_LIB_CONSOLE
+
+/* enable the panic shell if we're being built */
+#if !defined(ENABLE_PANIC_SHELL) && PLATFORM_SUPPORTS_PANIC_SHELL
+#define ENABLE_PANIC_SHELL 1
+#endif
+
+#define STATIC_COMMAND_START static const cmd _cmd_list[] = {
+
+#define STATIC_COMMAND_END(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION(".commands") = \
+    { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
+
+#define STATIC_COMMAND_START_NAMED(name) static const cmd _cmd_list_##name[] = {
+
+#define STATIC_COMMAND_END_NAMED(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION(".commands") = \
+    { NULL, sizeof(_cmd_list_##name) / sizeof(_cmd_list_##name[0]), _cmd_list_##name }
+
+#define STATIC_COMMAND(command_str, help_str, func) { command_str, help_str, func, CMD_AVAIL_NORMAL },
+#define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) { command_str, help_str, func, availability_mask },
+
+#else
+
+/* no command blocks, so null them out */
+#define STATIC_COMMAND_START
+#define STATIC_COMMAND_END(name)
+#define STATIC_COMMAND_START_NAMED(name)
+#define STATIC_COMMAND_END_NAMED(name)
+
+#define STATIC_COMMAND(command_str, help_str, func)
+
+#endif
+
+#define COMMAND_BLOCK_INIT_ITEM(cmd_block_ptr, cmd_ptr) {(cmd_block_ptr)->next = NULL; (cmd_block_ptr)->count = 1; (cmd_block_ptr)->list = cmd_ptr;}
+
+/* external api */
+int console_init(void);
+void console_start(void);
+void console_register_commands(cmd_block *block);
+int console_run_script(const char *string);
+int console_run_script_locked(const char *string); // special case from inside a command
+console_cmd console_get_command_handler(const char *command);
+void console_abort_script(void);
+
+/* panic shell api */
+void panic_shell_start(void);
+
+extern int lastresult;
+
+#endif
diff --git a/src/bsp/lk/include/lib/dpc.h b/src/bsp/lk/include/lib/dpc.h
new file mode 100644
index 0000000..36fcb53
--- /dev/null
+++ b/src/bsp/lk/include/lib/dpc.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_DPC_H
+#define __KERNEL_DPC_H
+
+#include <list.h>
+#include <sys/types.h>
+
+typedef void (*dpc_callback)(void *arg);
+
+#define DPC_FLAG_NORESCHED 0x1
+
+status_t dpc_queue(dpc_callback, void *arg, uint flags);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/evlog.h b/src/bsp/lk/include/lib/evlog.h
new file mode 100644
index 0000000..53f50e4
--- /dev/null
+++ b/src/bsp/lk/include/lib/evlog.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_EVLOG_H
+#define __LIB_EVLOG_H
+
+#include <inttypes.h>
+#include <sys/types.h>
+
+typedef struct evlog {
+	uint head;
+	uint unitsize;
+	uint len_pow2;
+	uintptr_t *items;
+} evlog_t;
+
+status_t evlog_init_etc(evlog_t *e, uint len, uint unitsize, uintptr_t *items);
+status_t evlog_init(evlog_t *e, uint len, uint unitsize);
+
+/* callback to evlog_dump. */
+typedef void (*evlog_dump_cb)(const uintptr_t *);
+
+void evlog_dump(evlog_t *e, evlog_dump_cb cb);
+
+/* bump the head pointer and return the old one.
+ */
+uint evlog_bump_head(evlog_t *e);
+
+/*
+ * It's assumed you're following a pattern similar to the following:
+ *
+void evlog_add2(evlog_t *e, uintptr_t a, uintptr_t b)
+{
+	uint index = evlog_bump_head(e);
+
+	e->items[index] = a;
+	e->items[index + 1] = b;
+}
+*/
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/font.h b/src/bsp/lk/include/lib/font.h
new file mode 100644
index 0000000..288d984
--- /dev/null
+++ b/src/bsp/lk/include/lib/font.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_FONT_H
+#define __LIB_FONT_H
+
+#include <lib/gfx.h>
+
+#define FONT_X  6
+#define FONT_Y  12
+
+void font_draw_char(gfx_surface *surface, unsigned char c, int x, int y, uint32_t color);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/gfx.h b/src/bsp/lk/include/lib/gfx.h
new file mode 100644
index 0000000..8c68daa
--- /dev/null
+++ b/src/bsp/lk/include/lib/gfx.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_GFX_H
+#define __LIB_GFX_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <inttypes.h>
+
+// gfx library
+
+// different graphics formats
+typedef enum {
+    GFX_FORMAT_NONE,
+    GFX_FORMAT_RGB_565,
+    GFX_FORMAT_RGB_332,
+    GFX_FORMAT_RGB_2220,
+    GFX_FORMAT_ARGB_8888,
+    GFX_FORMAT_RGB_x888,
+    GFX_FORMAT_MONO,
+
+    GFX_FORMAT_MAX
+} gfx_format;
+
+#define MAX_ALPHA 255
+
+/**
+ * @brief  Describe a graphics drawing surface
+ *
+ * The gfx_surface object represents a framebuffer that can be rendered
+ * to.  Elements include a pointer to the actual pixel memory, its size, its
+ * layout, and pointers to basic drawing functions.
+ *
+ * @ingroup graphics
+ */
+typedef struct gfx_surface {
+    void *ptr;
+    bool free_on_destroy;
+    gfx_format format;
+    uint width;
+    uint height;
+    uint stride;
+    uint pixelsize;
+    size_t len;
+    uint alpha;
+
+    // function pointers
+    uint32_t (*translate_color)(uint32_t input);
+    void (*copyrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint x2, uint y2);
+    void (*fillrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint color);
+    void (*putpixel)(struct gfx_surface *, uint x, uint y, uint color);
+    void (*flush)(uint starty, uint endy);
+} gfx_surface;
+
+// copy a rect from x,y with width x height to x2, y2
+void gfx_copyrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint x2, uint y2);
+
+// fill a rect within the surface with a color
+void gfx_fillrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint color);
+
+// draw a pixel at x, y in the surface
+void gfx_putpixel(gfx_surface *surface, uint x, uint y, uint color);
+
+// draw a single pixel line between x1,y1 and x2,y1
+void gfx_line(gfx_surface *surface, uint x1, uint y1, uint x2, uint y2, uint color);
+
+// clear the entire surface with a color
+static inline void gfx_clear(gfx_surface *surface, uint color)
+{
+    surface->fillrect(surface, 0, 0, surface->width, surface->height, color);
+
+    if (surface->flush)
+        surface->flush(0, surface->height-1);
+}
+
+// blend between two surfaces
+void gfx_surface_blend(struct gfx_surface *target, struct gfx_surface *source, uint destx, uint desty);
+
+void gfx_flush(struct gfx_surface *surface);
+
+void gfx_flush_rows(struct gfx_surface *surface, uint start, uint end);
+
+// surface setup
+gfx_surface *gfx_create_surface(void *ptr, uint width, uint height, uint stride, gfx_format format);
+
+// utility routine to make a surface out of a display info
+struct display_info;
+gfx_surface *gfx_create_surface_from_display(struct display_info *);
+
+// free the surface
+// optionally frees the buffer if the free bit is set
+void gfx_surface_destroy(struct gfx_surface *surface);
+
+// utility routine to fill the display with a little moire pattern
+void gfx_draw_pattern(void);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/gfxconsole.h b/src/bsp/lk/include/lib/gfxconsole.h
new file mode 100644
index 0000000..5a85b07
--- /dev/null
+++ b/src/bsp/lk/include/lib/gfxconsole.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_GFXCONSOLE_H
+#define __LIB_GFXCONSOLE_H
+
+#include <lib/gfx.h>
+
+void gfxconsole_start_on_display(void);
+void gfxconsole_start(gfx_surface *surface);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/nftl.h b/src/bsp/lk/include/lib/nftl.h
new file mode 100644
index 0000000..735e96b
--- /dev/null
+++ b/src/bsp/lk/include/lib/nftl.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <list.h>
+#include <sys/types.h>
+
+struct nftl_info {
+    char *name;
+    char *label;
+    u64 total_size;
+    u32 erase_size;
+    u32 write_size;
+
+    int (*block_isbad)(struct nftl_info *info, u32 page);
+    ssize_t (*erase)(struct nftl_info *info, off_t offset, ssize_t len);
+    ssize_t (*read)(struct nftl_info *info, void *buf, off_t offset,
+                    ssize_t len);
+    ssize_t (*write)(struct nftl_info *info, const void *buf, off_t offset,
+                     ssize_t len);
+    int (*ioctl)(struct nftl_info *info, int request, void *argp);
+};
+
+int nftl_mount_bdev(struct nftl_info *info);
+struct nftl_info *nftl_search_by_address(u64 address, u64 *start);
+struct nftl_info *nftl_open(const char *name);
+void nftl_close(struct nftl_info *info);
+int nftl_add_part(const char *main_part, const char *sub_part,
+                  const char *sub_label, u64 offset, u64 len);
+struct nftl_info *nftl_add_master(const char *name);
+int nftl_delete_part(const char *name);
+void nftl_dump_parts(void);
+int nftl_block_mapping(struct nftl_info *info, u32 *page);
+int nftl_block_isbad(struct nftl_info *info, u32 page);
+ssize_t nftl_erase(struct nftl_info *info, off_t offset, ssize_t len);
+ssize_t nftl_read(struct nftl_info *info, void *buf, off_t offset, ssize_t len);
+ssize_t nftl_write(struct nftl_info *info, const void *buf, off_t offset,
+                   ssize_t len);
diff --git a/src/bsp/lk/include/lib/page_alloc.h b/src/bsp/lk/include/lib/page_alloc.h
new file mode 100644
index 0000000..858d83f
--- /dev/null
+++ b/src/bsp/lk/include/lib/page_alloc.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Google, Inc. All rights reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_PAGE_ALLOC_H
+#define __LIB_PAGE_ALLOC_H
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <compiler.h>
+
+// to pick up PAGE_SIZE, PAGE_ALIGN, etc
+#if WITH_KERNEL_VM
+#include <kernel/vm.h>
+#else
+#include <kernel/novm.h>
+#endif
+
+/* A simple page-aligned wrapper around the pmm or novm implementation of
+ * the underlying physical page allocator. Used by system heaps or any
+ * other user that wants pages of memory but doesn't want to use LK
+ * specific apis.
+ */
+
+__BEGIN_CDECLS;
+
+void *page_alloc(size_t pages);
+void page_free(void *ptr, size_t pages);
+
+// You can call this once at the start, and it will either return a page or it
+// will return some non-page-aligned memory that would otherwise go to waste.
+void *page_first_alloc(size_t *size_return);
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/lib/partition.h b/src/bsp/lk/include/lib/partition.h
new file mode 100644
index 0000000..cc6b0a9
--- /dev/null
+++ b/src/bsp/lk/include/lib/partition.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_PARTITION_H
+#define __LIB_PARTITION_H
+
+#include <sys/types.h>
+
+/* examine and try to publish partitions on a particular device at a particular offset */
+int partition_publish(const char *device, off_t offset);
+
+/* remove any published subdevices on this device */
+int partition_unpublish(const char *device);
+
+/* update partition table on a particular device at a particular offset */
+int partition_update(const char *device, off_t offset, const char *data, size_t sz);
+#endif
+
diff --git a/src/bsp/lk/include/lib/ptable.h b/src/bsp/lk/include/lib/ptable.h
new file mode 100644
index 0000000..79a4fd0
--- /dev/null
+++ b/src/bsp/lk/include/lib/ptable.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, Google, Inc. All rights reserved
+ * Copyright (c) 2014, Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <compiler.h>
+#include <sys/types.h>
+#include <lib/bio.h>
+
+#define MAX_FLASH_PTABLE_NAME_LEN 12
+#define FLASH_PTABLE_ALLOC_END 0x1
+
+struct ptable_entry {
+    uint64_t offset;
+    uint64_t length;
+    uint32_t flags;
+    uint8_t name[MAX_FLASH_PTABLE_NAME_LEN];
+};
+
+bool     ptable_found_valid(void);
+bdev_t*  ptable_get_device(void);
+status_t ptable_scan(const char* bdev_name, uint64_t offset);
+status_t ptable_find(const char *name, struct ptable_entry *entry) __NONNULL((1));
+status_t ptable_create_default(const char* bdev_name, uint64_t offset) __NONNULL();
+status_t ptable_add(const char *name, uint64_t min_len, uint32_t flags) __NONNULL();
+status_t ptable_remove(const char *name) __NONNULL();
+void     ptable_dump(void);
diff --git a/src/bsp/lk/include/lib/sysparam.h b/src/bsp/lk/include/lib/sysparam.h
new file mode 100644
index 0000000..4841a21
--- /dev/null
+++ b/src/bsp/lk/include/lib/sysparam.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, Google, Inc. All rights reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <lib/bio.h>
+
+#ifndef SYSPARAM_ALLOW_WRITE
+#define SYSPARAM_ALLOW_WRITE 0
+#endif
+
+status_t sysparam_scan(bdev_t *bdev, off_t offset, size_t len);
+status_t sysparam_reload(void);
+
+void sysparam_dump(bool show_all);
+
+ssize_t sysparam_length(const char *name);
+ssize_t sysparam_read(const char *name, void *data, size_t len);
+status_t sysparam_get_ptr(const char *name, const void **ptr, size_t *len);
+
+#if SYSPARAM_ALLOW_WRITE
+status_t sysparam_add(const char *name, const void *value, size_t len);
+status_t sysparam_remove(const char *name);
+status_t sysparam_lock(const char *name);
+status_t sysparam_write(void);
+#endif
+
diff --git a/src/bsp/lk/include/lib/text.h b/src/bsp/lk/include/lib/text.h
new file mode 100644
index 0000000..02ed823
--- /dev/null
+++ b/src/bsp/lk/include/lib/text.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_TEXT_H
+#define __LIB_TEXT_H
+
+#include <lib/font.h>
+
+/* super cheezy mechanism to stick lines of text up on top of whatever is being drawn */
+/* XXX replace with something more generic later */
+void text_draw(int x, int y, const char *string);
+
+/* super dumb, someone has to call this to refresh everything */
+void text_update(void);
+
+#endif
+
diff --git a/src/bsp/lk/include/limits.h b/src/bsp/lk/include/limits.h
new file mode 100644
index 0000000..b74af6a
--- /dev/null
+++ b/src/bsp/lk/include/limits.h
@@ -0,0 +1,4 @@
+/* use the GCC builtins until we need something ourselves */
+#if !defined(_GCC_LIMITS_H_)
+#include_next <limits.h>
+#endif
diff --git a/src/bsp/lk/include/list.h b/src/bsp/lk/include/list.h
new file mode 100644
index 0000000..583e149
--- /dev/null
+++ b/src/bsp/lk/include/list.h
@@ -0,0 +1,279 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIST_H
+#define __LIST_H
+
+#include <compiler.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+__BEGIN_CDECLS;
+
+#define containerof(ptr, type, member) \
+    ((type *)((addr_t)(ptr) - offsetof(type, member)))
+
+struct list_node {
+	struct list_node *prev;
+	struct list_node *next;
+};
+
+#define LIST_INITIAL_VALUE(list) { &(list), &(list) }
+#define LIST_INITIAL_CLEARED_VALUE { NULL, NULL }
+
+static inline void list_initialize(struct list_node *list)
+{
+	list->prev = list->next = list;
+}
+
+static inline void list_clear_node(struct list_node *item)
+{
+	item->prev = item->next = 0;
+}
+
+static inline bool list_in_list(struct list_node *item)
+{
+	if (item->prev == 0 && item->next == 0)
+		return false;
+	else
+		return true;
+}
+
+static inline void list_add_head(struct list_node *list, struct list_node *item)
+{
+	item->next = list->next;
+	item->prev = list;
+	list->next->prev = item;
+	list->next = item;
+}
+
+#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
+
+static inline void list_add_tail(struct list_node *list, struct list_node *item)
+{
+	item->prev = list->prev;
+	item->next = list;
+	list->prev->next = item;
+	list->prev = item;
+}
+
+#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
+
+static inline void list_delete(struct list_node *item)
+{
+	item->next->prev = item->prev;
+	item->prev->next = item->next;
+	item->prev = item->next = 0;
+}
+
+static inline struct list_node* list_remove_head(struct list_node *list) {
+	if (list->next != list) {
+		struct list_node *item = list->next;
+		list_delete(item);
+		return item;
+	} else {
+		return NULL;
+	}
+}
+
+#define list_remove_head_type(list, type, element) ({\
+    struct list_node *__nod = list_remove_head(list);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_remove_tail(struct list_node *list) {
+	if (list->prev != list) {
+		struct list_node *item = list->prev;
+		list_delete(item);
+		return item;
+	} else {
+		return NULL;
+	}
+}
+
+#define list_remove_tail_type(list, type, element) ({\
+    struct list_node *__nod = list_remove_tail(list);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_peek_head(struct list_node *list) {
+	if (list->next != list) {
+		return list->next;
+	} else {
+		return NULL;
+	}
+}
+
+#define list_peek_head_type(list, type, element) ({\
+    struct list_node *__nod = list_peek_head(list);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_peek_tail(struct list_node *list) {
+	if (list->prev != list) {
+		return list->prev;
+	} else {
+		return NULL;
+	}
+}
+
+#define list_peek_tail_type(list, type, element) ({\
+    struct list_node *__nod = list_peek_tail(list);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_prev(struct list_node *list, struct list_node *item) {
+	if (item->prev != list)
+		return item->prev;
+	else
+		return NULL;
+}
+
+#define list_prev_type(list, item, type, element) ({\
+    struct list_node *__nod = list_prev(list, item);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_prev_wrap(struct list_node *list, struct list_node *item) {
+	if (item->prev != list)
+		return item->prev;
+	else if (item->prev->prev != list)
+		return item->prev->prev;
+	else
+		return NULL;
+}
+
+#define list_prev_wrap_type(list, item, type, element) ({\
+    struct list_node *__nod = list_prev_wrap(list, item);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_next(struct list_node *list, struct list_node *item) {
+	if (item->next != list)
+		return item->next;
+	else
+		return NULL;
+}
+
+#define list_next_type(list, item, type, element) ({\
+    struct list_node *__nod = list_next(list, item);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+static inline struct list_node* list_next_wrap(struct list_node *list, struct list_node *item) {
+	if (item->next != list)
+		return item->next;
+	else if (item->next->next != list)
+		return item->next->next;
+	else
+		return NULL;
+}
+
+#define list_next_wrap_type(list, item, type, element) ({\
+    struct list_node *__nod = list_next_wrap(list, item);\
+    type *__t;\
+    if(__nod)\
+        __t = containerof(__nod, type, element);\
+    else\
+        __t = (type *)0;\
+    __t;\
+})
+
+// iterates over the list, node should be struct list_node*
+#define list_for_every(list, node) \
+    for(node = (list)->next; node != (list); node = node->next)
+
+// iterates over the list in a safe way for deletion of current node
+// node and temp_node should be struct list_node*
+#define list_for_every_safe(list, node, temp_node) \
+    for(node = (list)->next, temp_node = (node)->next;\
+    node != (list);\
+    node = temp_node, temp_node = (node)->next)
+
+// iterates over the list, entry should be the container structure type *
+#define list_for_every_entry(list, entry, type, member) \
+    for((entry) = containerof((list)->next, type, member);\
+        &(entry)->member != (list);\
+        (entry) = containerof((entry)->member.next, type, member))
+
+// iterates over the list in a safe way for deletion of current node
+// entry and temp_entry should be the container structure type *
+#define list_for_every_entry_safe(list, entry, temp_entry, type, member) \
+    for(entry = containerof((list)->next, type, member),\
+        temp_entry = containerof((entry)->member.next, type, member);\
+        &(entry)->member != (list);\
+        entry = temp_entry, temp_entry = containerof((temp_entry)->member.next, type, member))
+
+static inline bool list_is_empty(struct list_node *list)
+{
+	return (list->next == list) ? true : false;
+}
+
+static inline size_t list_length(struct list_node *list)
+{
+    size_t cnt = 0;
+    struct list_node *node = list;
+    list_for_every(list, node) {
+        cnt++;
+    }
+
+    return cnt;
+}
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/lk/init.h b/src/bsp/lk/include/lk/init.h
new file mode 100644
index 0000000..0232b74
--- /dev/null
+++ b/src/bsp/lk/include/lk/init.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <compiler.h>
+#include <sys/types.h>
+
+/*
+ * LK's init system
+ */
+
+typedef void (*lk_init_hook)(uint level);
+
+enum lk_init_level {
+    LK_INIT_LEVEL_EARLIEST = 1,
+
+    LK_INIT_LEVEL_ARCH_EARLY     = 0x10000,
+    LK_INIT_LEVEL_PLATFORM_EARLY = 0x20000,
+    LK_INIT_LEVEL_TARGET_EARLY   = 0x30000,
+    LK_INIT_LEVEL_HEAP           = 0x40000,
+    LK_INIT_LEVEL_VM             = 0x50000,
+    LK_INIT_LEVEL_KERNEL         = 0x60000,
+    LK_INIT_LEVEL_THREADING      = 0x70000,
+    LK_INIT_LEVEL_ARCH           = 0x80000,
+    LK_INIT_LEVEL_PLATFORM       = 0x90000,
+    LK_INIT_LEVEL_TARGET         = 0xa0000,
+    LK_INIT_LEVEL_APPS           = 0xb0000,
+
+    LK_INIT_LEVEL_LAST = UINT_MAX,
+};
+
+enum lk_init_flags {
+    LK_INIT_FLAG_PRIMARY_CPU     = 0x1,
+    LK_INIT_FLAG_SECONDARY_CPUS  = 0x2,
+    LK_INIT_FLAG_ALL_CPUS        = LK_INIT_FLAG_PRIMARY_CPU | LK_INIT_FLAG_SECONDARY_CPUS,
+    LK_INIT_FLAG_CPU_SUSPEND     = 0x4,
+    LK_INIT_FLAG_CPU_RESUME      = 0x8,
+};
+
+void lk_init_level(enum lk_init_flags flags, uint start_level, uint stop_level);
+
+static inline void lk_primary_cpu_init_level(uint start_level, uint stop_level) {
+    lk_init_level(LK_INIT_FLAG_PRIMARY_CPU, start_level, stop_level);
+}
+
+static inline void lk_init_level_all(enum lk_init_flags flags) {
+    lk_init_level(flags, LK_INIT_LEVEL_EARLIEST, LK_INIT_LEVEL_LAST);
+}
+
+struct lk_init_struct {
+    uint level;
+    uint flags;
+    lk_init_hook hook;
+    const char *name;
+};
+
+#define LK_INIT_HOOK_FLAGS(_name, _hook, _level, _flags) \
+    const struct lk_init_struct _init_struct_##_name __ALIGNED(sizeof(void *)) __SECTION(".lk_init") = { \
+        .level = _level, \
+        .flags = _flags, \
+        .hook = _hook, \
+        .name = #_name, \
+    };
+
+#define LK_INIT_HOOK(_name, _hook, _level) \
+    LK_INIT_HOOK_FLAGS(_name, _hook, _level, LK_INIT_FLAG_PRIMARY_CPU)
+
+// vim: set ts=4 sw=4 expandtab:
diff --git a/src/bsp/lk/include/lk/main.h b/src/bsp/lk/include/lk/main.h
new file mode 100644
index 0000000..bcf0042
--- /dev/null
+++ b/src/bsp/lk/include/lk/main.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <compiler.h>
+#include <sys/types.h>
+
+
+void lk_main(ulong arg0, ulong arg1, ulong arg2, ulong arg3) __NO_RETURN __EXTERNALLY_VISIBLE;
+void lk_secondary_cpu_entry(void);
+void lk_init_secondary_cpus(uint secondary_cpu_count);
diff --git a/src/bsp/lk/include/malloc.h b/src/bsp/lk/include/malloc.h
new file mode 100644
index 0000000..abafbe9
--- /dev/null
+++ b/src/bsp/lk/include/malloc.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2008-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __MALLOC_H
+#define __MALLOC_H
+
+#include <sys/types.h>
+#include <compiler.h>
+#include <stddef.h>
+
+/* lib/heap provides malloc/free definitions */
+#include <lib/heap.h>
+
+#endif
+
diff --git a/src/bsp/lk/include/new.h b/src/bsp/lk/include/new.h
new file mode 100644
index 0000000..d150c18
--- /dev/null
+++ b/src/bsp/lk/include/new.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __NEW_H
+#define __NEW_H
+
+#include <sys/types.h>
+
+void *operator new(size_t);
+void *operator new(size_t, void *ptr);
+void *operator new[](size_t);
+void *operator new[](size_t, void *ptr);
+void operator delete(void *p);
+void operator delete[](void *p);
+
+#endif
diff --git a/src/bsp/lk/include/platform.h b/src/bsp/lk/include/platform.h
new file mode 100644
index 0000000..6a4f055
--- /dev/null
+++ b/src/bsp/lk/include/platform.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PLATFORM_H
+#define __PLATFORM_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+typedef enum {
+    HALT_ACTION_HALT = 0,       // Spin forever.
+    HALT_ACTION_REBOOT,         // Reset the CPU.
+    HALT_ACTION_SHUTDOWN,       // Shutdown and power off.
+} platform_halt_action;
+
+typedef enum {
+    HALT_REASON_UNKNOWN = 0,
+    HALT_REASON_POR,            // Cold-boot
+    HALT_REASON_HW_WATCHDOG,    // HW watchdog timer
+    HALT_REASON_LOWVOLTAGE,     // LV/Brownout condition
+    HALT_REASON_HIGHVOLTAGE,    // High voltage condition.
+    HALT_REASON_THERMAL,        // Thermal reason (probably overtemp)
+    HALT_REASON_OTHER_HW,       // Other hardware (platform) specific reason
+    HALT_REASON_SW_RESET,       // Generic Software Initiated Reboot
+    HALT_REASON_SW_WATCHDOG,    // Reboot triggered by a SW watchdog timer
+    HALT_REASON_SW_PANIC,       // Reboot triggered by a SW panic or ASSERT
+    HALT_REASON_SW_UPDATE,      // SW triggered reboot in order to begin firmware update
+} platform_halt_reason;
+
+lk_time_t current_time(void);
+lk_bigtime_t current_time_hires(void);
+
+/* Add the function for platform to have a chance to initialize hardware
+ * in EL3. This function would be called by start.S.
+ */
+void platform_el3_init(void);
+
+/* super early platform initialization, before almost everything */
+void platform_early_init(void);
+
+/* later init, after the kernel has come up */
+void platform_init(void);
+
+/* called by the arch init code to get the platform to set up any mmu mappings it may need */
+void platform_init_mmu_mappings(void);
+
+/* if the platform has knowledge of what caused the latest reboot, it can report
+ * it to applications with this function.  */
+platform_halt_reason platform_get_reboot_reason(void);
+
+/* platform_halt is a method which is called from various places in the LK
+ * system, and may be implemented by platforms and called by applications.  This
+ * call represents the end of the life of SW for a device; there is no returning
+ * from this function.  Callers will provide a reason for the halt, and a
+ * suggested action for the platform to take, but it is the platform's
+ * responsibility to determine the final action taken.  For example, in the case
+ * of a failed ASSERT or a panic, LK will call platform halt and suggest a Halt
+ * action, but a release build on a platform with no debug channel may choose to
+ * reboot instead as there is no one to tell about the ASSERT, and no one
+ * waiting to debug the device in its halted state.  If not overloaded by the
+ * platform, the default behavior of platform halt will be to dprintf the
+ * reason, and then halt execution by turning off interrupts and spinning
+ * forever.
+ */
+void platform_halt(platform_halt_action suggested_action,
+                   platform_halt_reason reason) __NO_RETURN;
+
+/* called during chain loading to make sure drivers and platform is put into a stopped state */
+void platform_quiesce(void);
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/platform/debug.h b/src/bsp/lk/include/platform/debug.h
new file mode 100644
index 0000000..8cbf024
--- /dev/null
+++ b/src/bsp/lk/include/platform/debug.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PLATFORM_DEBUG_H
+#define __PLATFORM_DEBUG_H
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+void platform_dputc(char c);
+int platform_dgetc(char *c, bool wait);
+
+// Should be available even if the system has panicked.
+void platform_pputc(char c);
+int platform_pgetc(char *c, bool wait);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/platform/interrupts.h b/src/bsp/lk/include/platform/interrupts.h
new file mode 100644
index 0000000..7ee25bc
--- /dev/null
+++ b/src/bsp/lk/include/platform/interrupts.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PLATFORM_INTERRUPTS_H
+#define __PLATFORM_INTERRUPTS_H
+
+#include <sys/types.h>
+
+status_t mask_interrupt(unsigned int vector);
+status_t unmask_interrupt(unsigned int vector);
+
+typedef enum handler_return (*int_handler)(void *arg);
+
+void register_int_handler(unsigned int vector, int_handler handler, void *arg);
+
+#endif
diff --git a/src/bsp/lk/include/platform/timer.h b/src/bsp/lk/include/platform/timer.h
new file mode 100644
index 0000000..62cc111
--- /dev/null
+++ b/src/bsp/lk/include/platform/timer.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PLATFORM_TIMER_H
+#define __PLATFORM_TIMER_H
+
+#include <sys/types.h>
+
+typedef enum handler_return (*platform_timer_callback)(void *arg, lk_time_t now);
+
+status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, lk_time_t interval);
+
+#if PLATFORM_HAS_DYNAMIC_TIMER
+status_t platform_set_oneshot_timer (platform_timer_callback callback, void *arg, lk_time_t interval);
+void     platform_stop_timer(void);
+#endif
+
+#endif
+
diff --git a/src/bsp/lk/include/pow2.h b/src/bsp/lk/include/pow2.h
new file mode 100644
index 0000000..3966143
--- /dev/null
+++ b/src/bsp/lk/include/pow2.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __POW2_H
+#define __POW2_H
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+/* routines for dealing with power of 2 values for efficiency */
+static inline __ALWAYS_INLINE bool ispow2(uint val)
+{
+	return ((val - 1) & val) == 0;
+}
+
+static inline __ALWAYS_INLINE uint log2_uint(uint val)
+{
+	if (val == 0)
+		return 0; // undefined
+
+	return (sizeof(val) * 8) - 1 - __builtin_clz(val);
+}
+
+static inline __ALWAYS_INLINE uint valpow2(uint valp2)
+{
+	return 1U << valp2;
+}
+
+static inline __ALWAYS_INLINE uint divpow2(uint val, uint divp2)
+{
+	return val >> divp2;
+}
+
+static inline __ALWAYS_INLINE uint modpow2(uint val, uint modp2)
+{
+	return val & ((1UL << modp2) - 1);
+}
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/printf.h b/src/bsp/lk/include/printf.h
new file mode 100644
index 0000000..367d3a0
--- /dev/null
+++ b/src/bsp/lk/include/printf.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_PRINTF_H
+#define __LIB_PRINTF_H
+
+#include <stdarg.h>
+#include <compiler.h>
+#include <stddef.h>
+
+__BEGIN_CDECLS
+
+#if !DISABLE_DEBUG_OUTPUT
+#define printf(x...) _printf(x)
+#else
+static inline int __PRINTFLIKE(1, 2) printf(const char *fmt, ...) { return 0; }
+#endif
+
+int _printf(const char *fmt, ...) __PRINTFLIKE(1, 2);
+int sprintf(char *str, const char *fmt, ...) __PRINTFLIKE(2, 3);
+int snprintf(char *str, size_t len, const char *fmt, ...) __PRINTFLIKE(3, 4);
+int vsprintf(char *str, const char *fmt, va_list ap);
+int vsnprintf(char *str, size_t len, const char *fmt, va_list ap);
+
+/* printf engine that parses the format string and generates output */
+
+/* function pointer to pass the printf engine, called back during the formatting.
+ * input is a string to output, length bytes to output (or null on string),
+ * return code is number of characters that would have been written, or error code (if negative)
+ */
+typedef int (*_printf_engine_output_func)(const char *str, size_t len, void *state);
+
+int _printf_engine(_printf_engine_output_func out, void *state, const char *fmt, va_list ap);
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/rand.h b/src/bsp/lk/include/rand.h
new file mode 100644
index 0000000..a313041
--- /dev/null
+++ b/src/bsp/lk/include/rand.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __RAND_H
+#define __RAND_H
+
+#include <compiler.h>
+#include <sys/types.h>
+
+__BEGIN_CDECLS;
+
+int rand(void);
+void srand(unsigned int seed);
+
+/* non standard extension to add some entropy to the seed */
+void rand_add_entropy(const void *buf, size_t len);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/reg.h b/src/bsp/lk/include/reg.h
new file mode 100644
index 0000000..1f58626
--- /dev/null
+++ b/src/bsp/lk/include/reg.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __REG_H
+#define __REG_H
+
+#include <stdint.h>
+
+/* low level macros for accessing memory mapped hardware registers */
+#define REG64(addr) ((volatile uint64_t *)(uintptr_t)(addr))
+#define REG32(addr) ((volatile uint32_t *)(uintptr_t)(addr))
+#define REG16(addr) ((volatile uint16_t *)(uintptr_t)(addr))
+#define REG8(addr) ((volatile uint8_t *)(uintptr_t)(addr))
+
+#define RMWREG64(addr, startbit, width, val) *REG64(addr) = (*REG64(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
+#define RMWREG32(addr, startbit, width, val) *REG32(addr) = (*REG32(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
+#define RMWREG16(addr, startbit, width, val) *REG16(addr) = (*REG16(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
+#define RMWREG8(addr, startbit, width, val) *REG8(addr) = (*REG8(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
+
+#define writel(v, a) (*REG32(a) = (v))
+#define readl(a) (*REG32(a))
+#define writeb(v, a) (*REG8(a) = (v))
+#define readb(a) (*REG8(a))
+
+#endif
diff --git a/src/bsp/lk/include/stdint.h b/src/bsp/lk/include/stdint.h
new file mode 100644
index 0000000..e86a742
--- /dev/null
+++ b/src/bsp/lk/include/stdint.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __STDINT_H
+#define __STDINT_H
+
+#include <limits.h> // for ULONG_MAX
+
+typedef unsigned char      uint8_t;
+typedef unsigned short     uint16_t;
+typedef unsigned int       uint32_t;
+typedef unsigned long long uint64_t;
+typedef signed char        int8_t;
+typedef short              int16_t;
+typedef int                int32_t;
+typedef long long          int64_t;
+
+#define INT8_MIN    CHAR_MIN
+#define INT16_MIN   SHORT_MIN
+#define INT32_MIN   INT_MIN
+
+#if defined(LLONG_MIN)
+#define INT64_MIN   LLONG_MIN
+#elif defined(__LONG_LONG_MAX__)
+#define INT64_MIN (-__LONG_LONG_MAX__-1LL)
+#endif
+
+#define INT8_MAX    CHAR_MAX
+#define INT16_MAX   SHORT_MAX
+#define INT32_MAX   INT_MAX
+
+#if defined(LLONG_MAX)
+#define INT64_MAX   LLONG_MAX
+#elif defined(__LONG_LONG_MAX__)
+#define INT64_MAX  __LONG_LONG_MAX__
+#endif
+
+#define UINT8_MAX   UCHAR_MAX
+#define UINT16_MAX  USHORT_MAX
+#define UINT32_MAX  UINT_MAX
+
+#if defined(ULLONG_MAX)
+#define UINT64_MAX  ULLONG_MAX
+#elif defined(__LONG_LONG_MAX__)
+#define UINT64_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
+#endif
+
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+#define INT_LEAST8_MIN  INT8_MIN
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST8_MAX  INT8_MAX
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MAX INT64_MAX
+
+#define UINT_LEAST8_MAX  UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+#define INT_FAST8_MIN  INT8_MIN
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST8_MAX  INT8_MAX
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MAX INT64_MAX
+
+#define UINT_FAST8_MAX  UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+#define INTPTR_MIN        LONG_MIN
+#define INTPTR_MAX        LONG_MAX
+#define UINTPTR_MAX       ULONG_MAX
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
+
+#define INTMAX_MAX        LLONG_MAX
+#define INTMAX_MIN        LLONG_MIN
+#define UINTMAX_MAX       ULLONG_MAX
+
+#define SIZE_MAX ULONG_MAX
+
+#endif
+
diff --git a/src/bsp/lk/include/stdio.h b/src/bsp/lk/include/stdio.h
new file mode 100644
index 0000000..5d0dcf2
--- /dev/null
+++ b/src/bsp/lk/include/stdio.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008-2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __STDIO_H
+#define __STDIO_H
+
+#include <compiler.h>
+#include <printf.h>
+#include <sys/types.h>
+
+__BEGIN_CDECLS
+
+typedef struct FILE {
+	void *ctx;
+	int (*fputc)(void *ctx, int c);
+	int (*fputs)(void *ctx, const char *s);
+	int (*fgetc)(void *ctx);
+	int (*vfprintf)(void *ctx, const char *fmt, va_list ap);
+} FILE;
+
+extern FILE __stdio_FILEs[];
+
+#define stdin  (&__stdio_FILEs[0])
+#define stdout (&__stdio_FILEs[1])
+#define stderr (&__stdio_FILEs[2])
+
+FILE *fopen(const char *filename, const char *mode);
+int fclose(FILE *stream);
+size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
+size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
+int fflush(FILE *stream);
+int feof(FILE *stream);
+
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+
+int fseek(FILE *stream, long offset, int whence);
+long ftell(FILE *stream);
+
+int fputc(int c, FILE *fp);
+#define putc(c, fp) fputc(c, fp)
+int putchar(int c);
+
+int fputs(const char *s, FILE *fp);
+int puts(const char *str);
+
+int getc(FILE *fp);
+int getchar(void);
+
+int fprintf(FILE *fp, const char *fmt, ...);
+int vfprintf(FILE *fp, const char *fmt, va_list ap);
+
+int sscanf(const char *buf, const char *fmt, ...);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/stdlib.h b/src/bsp/lk/include/stdlib.h
new file mode 100644
index 0000000..ec2b32c
--- /dev/null
+++ b/src/bsp/lk/include/stdlib.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2008-2014 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __STDLIB_H
+#define __STDLIB_H
+
+#include <compiler.h>
+#include <sys/types.h>
+#include <stddef.h>
+#include <malloc.h>
+#include <endian.h>
+#include <rand.h>
+#include <arch/defines.h>
+
+__BEGIN_CDECLS;
+
+int atoi(const char *num);
+unsigned int atoui(const char *num);
+long atol(const char *num);
+unsigned long atoul(const char *num);
+unsigned long long atoull(const char *num);
+
+long strtol(const char *nptr, char **endptr, int base);
+long long strtoll(const char *nptr, char **endptr, int base);
+
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+
+#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
+#define ROUNDDOWN(a, b) ((a) & ~((b)-1))
+
+#define ALIGN(a, b) ROUNDUP(a, b)
+#define IS_ALIGNED(a, b) (!(((uintptr_t)(a)) & (((uintptr_t)(b))-1)))
+
+/* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
+#define STACKBUF_DMA_ALIGN(var, size) \
+	uint8_t var[ROUNDUP(size, CACHE_LINE)] __ALIGNED(CACHE_LINE);
+void abort(void) __attribute__((noreturn));
+void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *));
+void *bsearch(const void *key, const void *base, size_t num_elems, size_t size,
+              int (*compare)(const void *, const void *));
+unsigned long int strtoul(const char *nptr, char **endptr, int base);
+char *getenv(const char *name);
+
+__END_CDECLS;
+
+#endif
+
diff --git a/src/bsp/lk/include/string.h b/src/bsp/lk/include/string.h
new file mode 100644
index 0000000..0cb659c
--- /dev/null
+++ b/src/bsp/lk/include/string.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_STRING_H
+#define __LIB_STRING_H
+
+#include <stddef.h>
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+void *memchr (void const *, int, size_t) __PURE;
+int   memcmp (void const *, const void *, size_t) __PURE;
+void *memcpy (void *, void const *, size_t);
+void *memmove(void *, void const *, size_t);
+void *memset (void *, int, size_t);
+
+char       *strcat(char *, char const *);
+char       *strchr(char const *, int) __PURE;
+int         strcmp(char const *, char const *) __PURE;
+char       *strcpy(char *, char const *);
+char       *strerror(int) __CONST;
+size_t      strlen(char const *) __PURE;
+char       *strncat(char *, char const *, size_t);
+int         strncmp(char const *, char const *, size_t) __PURE;
+char       *strncpy(char *, char const *, size_t);
+char       *strpbrk(char const *, char const *) __PURE;
+char       *strrchr(char const *, int) __PURE;
+size_t      strspn(char const *, char const *) __PURE;
+size_t      strcspn(const char *s, const char *) __PURE;
+char       *strstr(char const *, char const *) __PURE;
+char       *strtok(char *, char const *);
+int         strcoll(const char *s1, const char *s2) __PURE;
+size_t      strxfrm(char *dest, const char *src, size_t n) __PURE;
+char       *strdup(const char *str) __MALLOC;
+
+/* non standard */
+void   bcopy(void const *, void *, size_t);
+void   bzero(void *, size_t);
+size_t strlcat(char *, char const *, size_t);
+size_t strlcpy(char *, char const *, size_t);
+int    strncasecmp(char const *, char const *, size_t)  __PURE;
+int    strnicmp(char const *, char const *, size_t) __PURE;
+size_t strnlen(char const *s, size_t count) __PURE;
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/strings.h b/src/bsp/lk/include/strings.h
new file mode 100644
index 0000000..ea890cf
--- /dev/null
+++ b/src/bsp/lk/include/strings.h
@@ -0,0 +1,12 @@
+#if !defined(__STRINGS_H)
+#define __STRINGS_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS;
+
+int strcasecmp(const char *s1, const char *s2);
+
+__END_CDECLS;
+
+#endif  /* !__STRINGS_H */
diff --git a/src/bsp/lk/include/sys/types.h b/src/bsp/lk/include/sys/types.h
new file mode 100644
index 0000000..d1769eb
--- /dev/null
+++ b/src/bsp/lk/include/sys/types.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008-2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __SYS_TYPES_H
+#define __SYS_TYPES_H
+
+#include <limits.h>
+#include <stdint.h>
+#include <stddef.h>
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+
+typedef long long     off_t;
+
+typedef int status_t;
+
+typedef uintptr_t addr_t;
+typedef uintptr_t vaddr_t;
+typedef uintptr_t paddr_t;
+
+typedef int kobj_id;
+
+typedef uint32_t lk_time_t;
+typedef unsigned long long lk_bigtime_t;
+#define INFINITE_TIME UINT32_MAX
+
+#define TIME_GTE(a, b) ((int32_t)((a) - (b)) >= 0)
+#define TIME_LTE(a, b) ((int32_t)((a) - (b)) <= 0)
+#define TIME_GT(a, b) ((int32_t)((a) - (b)) > 0)
+#define TIME_LT(a, b) ((int32_t)((a) - (b)) < 0)
+
+enum handler_return {
+    INT_NO_RESCHEDULE = 0,
+    INT_RESCHEDULE,
+};
+
+typedef signed long int ssize_t;
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+typedef int8_t s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
+
+typedef uint8_t u_int8_t;
+typedef uint16_t u_int16_t;
+typedef uint32_t u_int32_t;
+typedef uint64_t u_int64_t;
+
+#endif
diff --git a/src/bsp/lk/include/target.h b/src/bsp/lk/include/target.h
new file mode 100644
index 0000000..91e0f24
--- /dev/null
+++ b/src/bsp/lk/include/target.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008-2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __TARGET_H
+#define __TARGET_H
+
+#include <compiler.h>
+#include <stdbool.h>
+
+__BEGIN_CDECLS;
+
+/* super early platform initialization, before almost everything */
+void target_early_init(void);
+
+/* later init, after the kernel has come up */
+void target_init(void);
+
+/* called during chain loading to make sure target specific bits are put into a stopped state */
+void target_quiesce(void);
+
+/* a target can optionally define a set of debug leds that can be used
+ * in various locations in the system.
+ */
+#if TARGET_HAS_DEBUG_LED
+void target_set_debug_led(unsigned int led, bool on);
+#else
+#define target_set_debug_led(led, on) ((void)(0))
+#endif
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/trace.h b/src/bsp/lk/include/trace.h
new file mode 100644
index 0000000..a970c4b
--- /dev/null
+++ b/src/bsp/lk/include/trace.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008-2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __TRACE_H
+#define __TRACE_H
+
+#include <stdio.h>
+
+/* trace routines */
+#define TRACE_ENTRY printf("%s: entry\n", __PRETTY_FUNCTION__)
+#define TRACE_EXIT printf("%s: exit\n", __PRETTY_FUNCTION__)
+#define TRACE_ENTRY_OBJ printf("%s: entry obj %p\n", __PRETTY_FUNCTION__, this)
+#define TRACE_EXIT_OBJ printf("%s: exit obj %p\n", __PRETTY_FUNCTION__, this)
+#define TRACE printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__)
+#define TRACEF(str, x...) do { printf("%s:%d: " str, __PRETTY_FUNCTION__, __LINE__, ## x); } while (0)
+
+/* trace routines that work if LOCAL_TRACE is set */
+#define LTRACE_ENTRY do { if (LOCAL_TRACE) { TRACE_ENTRY; } } while (0)
+#define LTRACE_EXIT do { if (LOCAL_TRACE) { TRACE_EXIT; } } while (0)
+#define LTRACE do { if (LOCAL_TRACE) { TRACE; } } while (0)
+#define LTRACEF(x...) do { if (LOCAL_TRACE) { TRACEF(x); } } while (0)
+#define LTRACEF_LEVEL(level, x...) do { if (LOCAL_TRACE >= (level)) { TRACEF(x); } } while (0)
+
+#endif