Sync changes required to build firmware in test env.

Fixes to allow building CHRE's firmware in 64-bit architectures.

Change-Id: I2d23e5694b990eaadb03f74c75d26f9bcd4a0e33
diff --git a/firmware/inc/atomic.h b/firmware/inc/atomic.h
index e90ca1c..5a44624 100644
--- a/firmware/inc/atomic.h
+++ b/firmware/inc/atomic.h
@@ -23,6 +23,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <cpu/inc/atomic.h>
 #include <cpu/inc/barrier.h>
 
 /* almost all platforms support byte and 32-bit operations of this sort. please do not add other sizes here */
diff --git a/firmware/inc/cpu/cortexm4f/atomic.h b/firmware/inc/cpu/cortexm4f/atomic.h
new file mode 100644
index 0000000..1f8c767
--- /dev/null
+++ b/firmware/inc/cpu/cortexm4f/atomic.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * 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 _CM4F_ATOMIC_H_
+#define _CM4F_ATOMIC_H_
+
+// real definition available in CPU-independent header file
+extern bool atomicCmpXchg32bits(volatile uint32_t *word, uint32_t prevVal, uint32_t newVal);
+
+inline bool atomicCmpXchgPtr(volatile uintptr_t *word, uintptr_t prevVal, uintptr_t newVal) {
+    // 32-bit CPU architecture so fall back appropriately
+    return atomicCmpXchg32bits((uint32_t*) word, (uintptr_t) prevVal, (uintptr_t) newVal);
+}
+
+#endif
+
diff --git a/firmware/inc/nanohubCommand.h b/firmware/inc/nanohubCommand.h
index 992575e..0c4c522 100644
--- a/firmware/inc/nanohubCommand.h
+++ b/firmware/inc/nanohubCommand.h
@@ -17,6 +17,8 @@
 #ifndef __NANOHUBCOMMAND_H
 #define __NANOHUBCOMMAND_H
 
+#include <stdint.h>
+
 #define NANOHUB_FAST_DONT_ACK       0xFFFFFFFE
 #define NANOHUB_FAST_UNHANDLED_ACK  0xFFFFFFFF
 
diff --git a/firmware/src/seos.c b/firmware/src/seos.c
index c6e027e..85b30f3 100644
--- a/firmware/src/seos.c
+++ b/firmware/src/seos.c
@@ -146,8 +146,9 @@
     struct Task *old = mCurrentTask;
     while (true) {
         old = mCurrentTask;
-        if (atomicCmpXchg32bits((uint32_t*)&mCurrentTask, (uint32_t)old, (uint32_t)task))
+        if (atomicCmpXchgPtr((uintptr_t*)&mCurrentTask, (uintptr_t)old, (uintptr_t)task)) {
             break;
+        }
     }
     return old;
 }
@@ -197,7 +198,11 @@
 
 uint32_t osGetCurrentTid()
 {
-    return osGetCurrentTask()->tid;
+    struct Task *task = osGetCurrentTask();
+    if (task == NULL) {
+        return UINT32_MAX;
+    }
+    return task->tid;
 }
 
 uint32_t osSetCurrentTid(uint32_t tid)