From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Leonard Subject: [PATCH ARM v6 09/14] mini-os: arm: scheduling Date: Wed, 16 Jul 2014 12:07:49 +0100 Message-ID: <1405508874-3921-10-git-send-email-talex5@gmail.com> References: <1405508874-3921-1-git-send-email-talex5@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X7N4H-0003OC-JC for xen-devel@lists.xenproject.org; Wed, 16 Jul 2014 11:08:13 +0000 Received: by mail-wg0-f49.google.com with SMTP id k14so706472wgh.20 for ; Wed, 16 Jul 2014 04:08:09 -0700 (PDT) In-Reply-To: <1405508874-3921-1-git-send-email-talex5@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Thomas Leonard , Dave.Scott@eu.citrix.com, anil@recoil.org, stefano.stabellini@eu.citrix.com, samuel.thibault@ens-lyon.org List-Id: xen-devel@lists.xenproject.org Based on an initial patch by Karim Raslan. Signed-off-by: Karim Allah Ahmed Signed-off-by: Thomas Leonard --- 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 +#include +#include + +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