kernel: implement some more system calls
These are needed to demonstrate the Philosophers demo with threads
running in user mode.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/include/kernel.h b/include/kernel.h
index a34d27a..76b3553 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -599,7 +599,7 @@
*
* @return N/A
*/
-extern void k_sleep(s32_t duration);
+__syscall void k_sleep(s32_t duration);
/**
* @brief Cause the current thread to busy wait.
@@ -640,7 +640,7 @@
*
* @return ID of current thread.
*/
-extern k_tid_t k_current_get(void);
+__syscall k_tid_t k_current_get(void);
/**
* @brief Cancel thread performing a delayed start.
@@ -779,7 +779,7 @@
*
* @return Priority of @a thread.
*/
-extern int k_thread_priority_get(k_tid_t thread);
+__syscall int k_thread_priority_get(k_tid_t thread);
/**
* @brief Set a thread's priority.
@@ -1414,7 +1414,7 @@
*
* @return Current uptime.
*/
-extern u32_t k_uptime_get_32(void);
+__syscall u32_t k_uptime_get_32(void);
/**
* @brief Get elapsed time.
diff --git a/kernel/sched.c b/kernel/sched.c
index 3dab1da..0de0d60 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -10,6 +10,7 @@
#include <ksched.h>
#include <wait_q.h>
#include <misc/util.h>
+#include <syscall_handler.h>
/* the only struct _kernel instance */
struct _kernel _kernel = {0};
@@ -257,11 +258,26 @@
#endif
}
-int k_thread_priority_get(k_tid_t thread)
+int _impl_k_thread_priority_get(k_tid_t thread)
{
return thread->base.prio;
}
+#ifdef CONFIG_USERSPACE
+u32_t _handler_k_thread_priority_get(u32_t arg1, u32_t arg2, u32_t arg3,
+ u32_t arg4, u32_t arg5, u32_t arg6,
+ void *ssf)
+{
+ struct k_thread *thread;
+
+ _SYSCALL_ARG1;
+
+ thread = (struct k_thread *)arg1;
+ _SYSCALL_IS_OBJ(thread, K_OBJ_THREAD, 0, ssf);
+ return (u32_t)_impl_k_thread_priority_get(thread);
+}
+#endif
+
void k_thread_priority_set(k_tid_t tid, int prio)
{
/*
@@ -322,7 +338,7 @@
}
}
-void k_sleep(s32_t duration)
+void _impl_k_sleep(s32_t duration)
{
#ifdef CONFIG_MULTITHREADING
/* volatile to guarantee that irq_lock() is executed after ticks is
@@ -352,6 +368,19 @@
#endif
}
+#ifdef CONFIG_USERSPACE
+u32_t _handler_k_sleep(u32_t arg1, u32_t arg2, u32_t arg3,
+ u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
+{
+ _SYSCALL_ARG1;
+
+ _SYSCALL_VERIFY(arg1 != K_FOREVER, ssf);
+ _impl_k_sleep(arg1);
+
+ return 0;
+}
+#endif
+
void k_wakeup(k_tid_t thread)
{
int key = irq_lock();
@@ -376,11 +405,21 @@
}
}
-k_tid_t k_current_get(void)
+k_tid_t _impl_k_current_get(void)
{
return _current;
}
+#ifdef CONFIG_USERSPACE
+u32_t _handler_k_current_get(u32_t arg1, u32_t arg2, u32_t arg3, u32_t arg4,
+ u32_t arg5, u32_t arg6, void *ssf)
+{
+ _SYSCALL_ARG0;
+
+ return (u32_t)_impl_k_current_get();
+}
+#endif
+
#ifdef CONFIG_TIMESLICING
extern s32_t _time_slice_duration; /* Measured in ms */
extern s32_t _time_slice_elapsed; /* Measured in ms */
diff --git a/kernel/sys_clock.c b/kernel/sys_clock.c
index f459f70..0671a12 100644
--- a/kernel/sys_clock.c
+++ b/kernel/sys_clock.c
@@ -12,6 +12,7 @@
#include <linker/sections.h>
#include <wait_q.h>
#include <drivers/system_timer.h>
+#include <syscall_handler.h>
#ifdef CONFIG_SYS_CLOCK_EXISTS
#ifdef _NON_OPTIMIZED_TICKS_PER_SEC
@@ -68,7 +69,7 @@
}
FUNC_ALIAS(_tick_get_32, sys_tick_get_32, u32_t);
-u32_t k_uptime_get_32(void)
+u32_t _impl_k_uptime_get_32(void)
{
#ifdef CONFIG_TICKLESS_KERNEL
__ASSERT(_sys_clock_always_on,
@@ -77,6 +78,19 @@
return __ticks_to_ms(_tick_get_32());
}
+#ifdef CONFIG_USERSPACE
+u32_t _handler_k_uptime_get_32(u32_t arg1, u32_t arg2, u32_t arg3,
+ u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
+{
+ _SYSCALL_ARG0;
+
+#ifdef CONFIG_TICKLESS_KERNEL
+ _SYSCALL_VERIFY(_sys_clock_always_on, ssf);
+#endif
+ return _impl_k_uptime_get_32();
+}
+#endif
+
/**
*
* @brief Return the current system tick count