xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Leonard <talex5@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Thomas Leonard <talex5@gmail.com>,
	Dave.Scott@eu.citrix.com, anil@recoil.org,
	stefano.stabellini@eu.citrix.com, samuel.thibault@ens-lyon.org
Subject: [PATCH ARM v6 09/14] mini-os: arm: scheduling
Date: Wed, 16 Jul 2014 12:07:49 +0100	[thread overview]
Message-ID: <1405508874-3921-10-git-send-email-talex5@gmail.com> (raw)
In-Reply-To: <1405508874-3921-1-git-send-email-talex5@gmail.com>

Based on an initial patch by Karim Raslan.

Signed-off-by: Karim Allah Ahmed <karim.allah.ahmed@gmail.com>
Signed-off-by: Thomas Leonard <talex5@gmail.com>
---
 extras/mini-os/arch/arm/arm32.S | 22 ++++++++++++++++++++++
 extras/mini-os/arch/arm/sched.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
 create mode 100644 extras/mini-os/arch/arm/sched.c

diff --git a/extras/mini-os/arch/arm/arm32.S b/extras/mini-os/arch/arm/arm32.S
index 88efe24..56429b1 100644
--- a/extras/mini-os/arch/arm/arm32.S
+++ b/extras/mini-os/arch/arm/arm32.S
@@ -204,8 +204,30 @@ irq_handler:
 IRQ_handler:
 	.long	0x0
 
+
+.globl __arch_switch_threads
+@ => r0 = &prev->sp
+@    r1 = &next->sp
+@ <= returns to next thread's saved return address
+__arch_switch_threads:
+	stmia	r0, {sp, lr}	@ Store current sp and ip to prev's struct thread
+	str	fp, [sp, #-4]	@ Store fp on the old stack
+
+	ldmia	r1, {sp, lr}	@ Load new sp, ip from next's struct thread
+	ldr	fp, [sp, #-4]	@ Restore fp from the stack
+
+	mov	pc, lr
+
 @ This is called if you try to divide by zero. For now, we make a supervisor call,
 @ which will make us halt.
 .globl raise
 raise:
 	svc	0
+
+.globl arm_start_thread
+arm_start_thread:
+	pop	{r0, r1}
+	@ r0 = user data
+	@ r1 -> thread's main function
+	ldr	lr, =exit_thread
+	bx	r1
diff --git a/extras/mini-os/arch/arm/sched.c b/extras/mini-os/arch/arm/sched.c
new file mode 100644
index 0000000..9fb884e
--- /dev/null
+++ b/extras/mini-os/arch/arm/sched.c
@@ -0,0 +1,38 @@
+#include <mini-os/sched.h>
+#include <mini-os/xmalloc.h>
+#include <mini-os/console.h>
+
+void arm_start_thread(void);
+
+/* Architecture specific setup of thread creation */
+struct thread* arch_create_thread(char *name, void (*function)(void *),
+                                  void *data)
+{
+    struct thread *thread;
+
+    thread = xmalloc(struct thread);
+    /* We can't use lazy allocation here since the trap handler runs on the stack */
+    thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
+    thread->name = name;
+    printk("Thread \"%s\": pointer: 0x%lx, stack: 0x%lx\n", name, thread,
+            thread->stack);
+
+    /* Save pointer to the thread on the stack, used by current macro */
+    *((unsigned long *)thread->stack) = (unsigned long)thread;
+
+    /* Push the details to pass to arm_start_thread onto the stack */
+    int *sp = (int *) (thread->stack + STACK_SIZE);
+    *(--sp) = (int) function;
+    *(--sp) = (int) data;
+    thread->sp = (unsigned long) sp;
+
+    thread->ip = (unsigned long) arm_start_thread;
+
+    return thread;
+}
+
+void run_idle_thread(void)
+{
+    __asm__ __volatile__ ("mov sp, %0; mov pc, %1"::"r"(idle_thread->sp), "r"(idle_thread->ip));
+    /* Never arrive here! */
+}
-- 
2.0.1

  parent reply	other threads:[~2014-07-16 11:08 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 11:07 [PATCH ARM v6 00/14] mini-os: initial ARM support Thomas Leonard
2014-07-16 11:07 ` [PATCH ARM v6 01/14] mini-os: x86_64: make thread stacks 16-byte aligned Thomas Leonard
2014-07-17 15:50   ` Ian Campbell
2014-07-17 18:15     ` Samuel Thibault
2014-07-18 10:00       ` Ian Campbell
2014-07-18 13:22         ` Samuel Thibault
2014-07-17 18:15   ` Samuel Thibault
2014-07-16 11:07 ` [PATCH ARM v6 02/14] mini-os: don't include lib.h from mm.h Thomas Leonard
2014-07-16 13:30   ` Thomas Leonard
2014-07-17 15:51     ` Ian Campbell
2014-07-17 18:17     ` Samuel Thibault
2014-07-16 11:07 ` [PATCH ARM v6 03/14] mini-os: added HYPERVISOR_xsm_op Thomas Leonard
2014-07-16 11:07 ` [PATCH ARM v6 04/14] mini-os: headers for ARM Thomas Leonard
2014-07-16 21:25   ` Julien Grall
2014-07-17  8:14     ` Thomas Leonard
2014-07-17  9:04       ` Ian Campbell
2014-07-17 11:41         ` Julien Grall
2014-07-17 15:59   ` Ian Campbell
2014-07-18  1:29     ` Chen Baozi
2014-07-18  7:58     ` Thomas Leonard
2014-07-17 18:27   ` Samuel Thibault
2014-07-18  7:54     ` Thomas Leonard
2014-07-16 11:07 ` [PATCH ARM v6 05/14] mini-os: import libfdt Thomas Leonard
2014-07-16 11:44   ` Andrew Cooper
2014-07-16 12:29     ` Ian Campbell
2014-07-16 13:02       ` Andrew Cooper
2014-07-16 13:34         ` Ian Campbell
2014-07-16 14:13           ` Anil Madhavapeddy
2014-07-16 14:35             ` Ian Campbell
2014-07-17 18:30           ` Samuel Thibault
2014-07-16 11:07 ` [PATCH ARM v6 06/14] mini-os: use generic local_irq_enable function Thomas Leonard
2014-07-17 16:00   ` Ian Campbell
2014-07-17 18:32   ` Samuel Thibault
2014-07-16 11:07 ` [PATCH ARM v6 07/14] mini-os: arm: boot code Thomas Leonard
2014-07-16 21:49   ` Julien Grall
2014-07-17  9:37     ` Thomas Leonard
2014-07-17  9:46       ` Ian Campbell
2014-07-17  9:48         ` Thomas Leonard
2014-07-17 16:28   ` Ian Campbell
2014-07-30 10:47     ` Thomas Leonard
2014-07-30 11:26       ` Ian Campbell
2014-07-30 12:20         ` Thomas Leonard
2014-07-30 12:54           ` Ian Campbell
2014-07-30 13:37             ` Thomas Leonard
2014-07-30 13:43               ` Ian Campbell
2014-07-16 11:07 ` [PATCH ARM v6 08/14] mini-os: arm: memory management Thomas Leonard
2014-07-21 17:36   ` Julien Grall
2014-08-03 10:23     ` Thomas Leonard
2014-07-16 11:07 ` Thomas Leonard [this message]
2014-07-28 10:53   ` [PATCH ARM v6 09/14] mini-os: arm: scheduling Ian Campbell
2014-07-28 11:20     ` Thomas Leonard
2014-07-28 11:26       ` Ian Campbell
2014-07-16 11:07 ` [PATCH ARM v6 10/14] mini-os: arm: events Thomas Leonard
2014-07-28 10:55   ` Ian Campbell
2014-07-16 11:07 ` [PATCH ARM v6 11/14] mini-os: arm: time Thomas Leonard
2014-07-21 17:45   ` Julien Grall
2014-07-28 10:41     ` Ian Campbell
2014-07-16 11:07 ` [PATCH ARM v6 12/14] mini-os: arm: interrupt controller Thomas Leonard
2014-07-21 17:56   ` Julien Grall
2014-07-16 11:07 ` [PATCH ARM v6 13/14] mini-os: arm: build system Thomas Leonard
2014-07-16 22:03   ` Julien Grall
2014-07-17 10:16     ` Thomas Leonard
2014-07-28 10:58   ` Ian Campbell
2014-07-16 11:07 ` [PATCH ARM v6 14/14] mini-os: arm: show registers, stack and exception vector on fault Thomas Leonard
2014-07-28 11:13   ` Ian Campbell
2014-07-28 11:49     ` Thomas Leonard
2014-07-28 12:01       ` Ian Campbell
2014-07-16 21:29 ` [PATCH ARM v6 00/14] mini-os: initial ARM support Julien Grall
2014-07-17 15:55   ` Ian Campbell
2014-07-17 16:17     ` Ian Campbell
2014-07-18  8:07       ` Thomas Leonard
2014-07-18  8:17     ` Thomas Leonard
2014-07-18 10:07       ` Ian Campbell
2014-07-18 12:45 ` Ian Campbell
2014-08-05 10:56   ` Thomas Leonard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405508874-3921-10-git-send-email-talex5@gmail.com \
    --to=talex5@gmail.com \
    --cc=Dave.Scott@eu.citrix.com \
    --cc=anil@recoil.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).