all: Update reserved function names

Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
diff --git a/kernel/msg_q.c b/kernel/msg_q.c
index 2bf87e3..460c05c 100644
--- a/kernel/msg_q.c
+++ b/kernel/msg_q.c
@@ -59,14 +59,14 @@
 	q->write_ptr = buffer;
 	q->used_msgs = 0;
 	q->flags = 0;
-	_waitq_init(&q->wait_q);
+	z_waitq_init(&q->wait_q);
 	q->lock = (struct k_spinlock) {};
 	SYS_TRACING_OBJ_INIT(k_msgq, q);
 
-	_k_object_init(q);
+	z_object_init(q);
 }
 
-int _impl_k_msgq_alloc_init(struct k_msgq *q, size_t msg_size,
+int z_impl_k_msgq_alloc_init(struct k_msgq *q, size_t msg_size,
 			    u32_t max_msgs)
 {
 	void *buffer;
@@ -95,13 +95,13 @@
 {
 	Z_OOPS(Z_SYSCALL_OBJ_NEVER_INIT(q, K_OBJ_MSGQ));
 
-	return _impl_k_msgq_alloc_init((struct k_msgq *)q, msg_size, max_msgs);
+	return z_impl_k_msgq_alloc_init((struct k_msgq *)q, msg_size, max_msgs);
 }
 #endif
 
 void k_msgq_cleanup(struct k_msgq *q)
 {
-	__ASSERT_NO_MSG(!_waitq_head(&q->wait_q));
+	__ASSERT_NO_MSG(!z_waitq_head(&q->wait_q));
 
 	if ((q->flags & K_MSGQ_FLAG_ALLOC) != 0) {
 		k_free(q->buffer_start);
@@ -110,9 +110,9 @@
 }
 
 
-int _impl_k_msgq_put(struct k_msgq *q, void *data, s32_t timeout)
+int z_impl_k_msgq_put(struct k_msgq *q, void *data, s32_t timeout)
 {
-	__ASSERT(!_is_in_isr() || timeout == K_NO_WAIT, "");
+	__ASSERT(!z_is_in_isr() || timeout == K_NO_WAIT, "");
 
 	k_spinlock_key_t key = k_spin_lock(&q->lock);
 	struct k_thread *pending_thread;
@@ -120,15 +120,15 @@
 
 	if (q->used_msgs < q->max_msgs) {
 		/* message queue isn't full */
-		pending_thread = _unpend_first_thread(&q->wait_q);
+		pending_thread = z_unpend_first_thread(&q->wait_q);
 		if (pending_thread != NULL) {
 			/* give message to waiting thread */
 			(void)memcpy(pending_thread->base.swap_data, data,
 			       q->msg_size);
 			/* wake up waiting thread */
-			_set_thread_return_value(pending_thread, 0);
-			_ready_thread(pending_thread);
-			_reschedule(&q->lock, key);
+			z_set_thread_return_value(pending_thread, 0);
+			z_ready_thread(pending_thread);
+			z_reschedule(&q->lock, key);
 			return 0;
 		} else {
 			/* put message in queue */
@@ -146,7 +146,7 @@
 	} else {
 		/* wait for put message success, failure, or timeout */
 		_current->base.swap_data = data;
-		return _pend_curr(&q->lock, key, &q->wait_q, timeout);
+		return z_pend_curr(&q->lock, key, &q->wait_q, timeout);
 	}
 
 	k_spin_unlock(&q->lock, key);
@@ -162,11 +162,11 @@
 	Z_OOPS(Z_SYSCALL_OBJ(q, K_OBJ_MSGQ));
 	Z_OOPS(Z_SYSCALL_MEMORY_READ(data, q->msg_size));
 
-	return _impl_k_msgq_put(q, (void *)data, timeout);
+	return z_impl_k_msgq_put(q, (void *)data, timeout);
 }
 #endif
 
-void _impl_k_msgq_get_attrs(struct k_msgq *q, struct k_msgq_attrs *attrs)
+void z_impl_k_msgq_get_attrs(struct k_msgq *q, struct k_msgq_attrs *attrs)
 {
 	attrs->msg_size = q->msg_size;
 	attrs->max_msgs = q->max_msgs;
@@ -180,14 +180,14 @@
 
 	Z_OOPS(Z_SYSCALL_OBJ(q, K_OBJ_MSGQ));
 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(attrs, sizeof(struct k_msgq_attrs)));
-	_impl_k_msgq_get_attrs(q, (struct k_msgq_attrs *) attrs);
+	z_impl_k_msgq_get_attrs(q, (struct k_msgq_attrs *) attrs);
 	return 0;
 }
 #endif
 
-int _impl_k_msgq_get(struct k_msgq *q, void *data, s32_t timeout)
+int z_impl_k_msgq_get(struct k_msgq *q, void *data, s32_t timeout)
 {
-	__ASSERT(!_is_in_isr() || timeout == K_NO_WAIT, "");
+	__ASSERT(!z_is_in_isr() || timeout == K_NO_WAIT, "");
 
 	k_spinlock_key_t key = k_spin_lock(&q->lock);
 	struct k_thread *pending_thread;
@@ -203,7 +203,7 @@
 		q->used_msgs--;
 
 		/* handle first thread waiting to write (if any) */
-		pending_thread = _unpend_first_thread(&q->wait_q);
+		pending_thread = z_unpend_first_thread(&q->wait_q);
 		if (pending_thread != NULL) {
 			/* add thread's message to queue */
 			(void)memcpy(q->write_ptr, pending_thread->base.swap_data,
@@ -215,9 +215,9 @@
 			q->used_msgs++;
 
 			/* wake up waiting thread */
-			_set_thread_return_value(pending_thread, 0);
-			_ready_thread(pending_thread);
-			_reschedule(&q->lock, key);
+			z_set_thread_return_value(pending_thread, 0);
+			z_ready_thread(pending_thread);
+			z_reschedule(&q->lock, key);
 			return 0;
 		}
 		result = 0;
@@ -227,7 +227,7 @@
 	} else {
 		/* wait for get message success or timeout */
 		_current->base.swap_data = data;
-		return _pend_curr(&q->lock, key, &q->wait_q, timeout);
+		return z_pend_curr(&q->lock, key, &q->wait_q, timeout);
 	}
 
 	k_spin_unlock(&q->lock, key);
@@ -243,11 +243,11 @@
 	Z_OOPS(Z_SYSCALL_OBJ(q, K_OBJ_MSGQ));
 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(data, q->msg_size));
 
-	return _impl_k_msgq_get(q, (void *)data, timeout);
+	return z_impl_k_msgq_get(q, (void *)data, timeout);
 }
 #endif
 
-int _impl_k_msgq_peek(struct k_msgq *q, void *data)
+int z_impl_k_msgq_peek(struct k_msgq *q, void *data)
 {
 	k_spinlock_key_t key = k_spin_lock(&q->lock);
 	int result;
@@ -274,25 +274,25 @@
 	Z_OOPS(Z_SYSCALL_OBJ(q, K_OBJ_MSGQ));
 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(data, q->msg_size));
 
-	return _impl_k_msgq_peek(q, (void *)data);
+	return z_impl_k_msgq_peek(q, (void *)data);
 }
 #endif
 
-void _impl_k_msgq_purge(struct k_msgq *q)
+void z_impl_k_msgq_purge(struct k_msgq *q)
 {
 	k_spinlock_key_t key = k_spin_lock(&q->lock);
 	struct k_thread *pending_thread;
 
 	/* wake up any threads that are waiting to write */
-	while ((pending_thread = _unpend_first_thread(&q->wait_q)) != NULL) {
-		_set_thread_return_value(pending_thread, -ENOMSG);
-		_ready_thread(pending_thread);
+	while ((pending_thread = z_unpend_first_thread(&q->wait_q)) != NULL) {
+		z_set_thread_return_value(pending_thread, -ENOMSG);
+		z_ready_thread(pending_thread);
 	}
 
 	q->used_msgs = 0;
 	q->read_ptr = q->write_ptr;
 
-	_reschedule(&q->lock, key);
+	z_reschedule(&q->lock, key);
 }
 
 #ifdef CONFIG_USERSPACE