<commit_before>/**
 * ARM architecture common support functions
 *
 * Copyright (C) 2008, 2009  <NAME> <<EMAIL>>
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This file is subject to the terms and conditions of the GNU Lesser General
 * Public License. See the file LICENSE in the top level directory for more
 * details.
 *
 * @ingroup arm_common
 * @{
 * @file
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @}
 */

#include <stdio.h>
#include "arm_cpu.h"
#include "sched.h"
#include "kernel_internal.h"

#define STACK_MARKER    (0x77777777)
#define REGISTER_CNT    (12)

void thread_yield(void)
{
    asm("svc 0\n");
}

/*----------------------------------------------------------------------------
 * Processor specific routine - here for ARM7
 * sizeof(void*) = sizeof(int)
 *--------------------------------------------------------------------------*/
char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_size)
{
    unsigned int *stk;
    int i;
    stk = (unsigned int *)((unsigned int)stack_start + stack_size);
    stk--;

    *stk = STACK_MARKER;

    /* set the return address (LR) */
    stk--;
    *stk = (unsigned int) sched_task_exit;

    /* set the stack pointer (SP) */
    stk--;
    *stk = (unsigned int)((unsigned int)stack_start + stack_size) - 4;

    /* build base stack */
    for (i = REGISTER_CNT; i >= 0 ; i--) {
        stk--;
        *stk = i;
    }

    /* set the entry point */
    stk--;
    *stk = ((unsigned int) task_func);
    /* set the saved program status register */
    stk--;
    *stk = (unsigned int) NEW_TASK_CPSR;

    return (char *)stk;
}

void thread_print_stack(void)
{
    register void *stack = 0;
    asm("mov %0, sp" : "=r"(stack));

    register unsigned int *s = (unsigned int *)stack;
    printf("task: %X SP: %X\n", (unsigned int) active_thread, (unsigned int) stack);
    register int i = 0;
    s += 5;

    while (*s != STACK_MARKER) {
        printf("STACK (%u) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s);
        s++;
        i++;
    }

    printf("STACK (%u)= %X \n", i, *s);
}<commit_msg>Implemented reboot() function for ARM-based MCUs<commit_after>/**
 * ARM architecture common support functions
 *
 * Copyright (C) 2008, 2009  <NAME> <hwill@inf.fu-berlin.de>
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This file is subject to the terms and conditions of the GNU Lesser General
 * Public License. See the file LICENSE in the top level directory for more
 * details.
 *
 * @ingroup arm_common
 * @{
 * @file
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @}
 */

#include <stdio.h>
#include "arm_cpu.h"
#include "sched.h"
#include "kernel.h"
#include "kernel_internal.h"

#define STACK_MARKER    (0x77777777)
#define REGISTER_CNT    (12)

void thread_yield(void)
{
    asm("svc 0\n");
}

/*----------------------------------------------------------------------------
 * Processor specific routine - here for ARM7
 * sizeof(void*) = sizeof(int)
 *--------------------------------------------------------------------------*/
char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_size)
{
    unsigned int *stk;
    int i;
    stk = (unsigned int *)((unsigned int)stack_start + stack_size);
    stk--;

    *stk = STACK_MARKER;

    /* set the return address (LR) */
    stk--;
    *stk = (unsigned int) sched_task_exit;

    /* set the stack pointer (SP) */
    stk--;
    *stk = (unsigned int)((unsigned int)stack_start + stack_size) - 4;

    /* build base stack */
    for (i = REGISTER_CNT; i >= 0 ; i--) {
        stk--;
        *stk = i;
    }

    /* set the entry point */
    stk--;
    *stk = ((unsigned int) task_func);
    /* set the saved program status register */
    stk--;
    *stk = (unsigned int) NEW_TASK_CPSR;

    return (char *)stk;
}

void thread_print_stack(void)
{
    register void *stack = 0;
    asm("mov %0, sp" : "=r"(stack));

    register unsigned int *s = (unsigned int *)stack;
    printf("task: %X SP: %X\n", (unsigned int) active_thread, (unsigned int) stack);
    register int i = 0;
    s += 5;

    while (*s != STACK_MARKER) {
        printf("STACK (%u) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s);
        s++;
        i++;
    }

    printf("STACK (%u)= %X \n", i, *s);
}

NORETURN void reboot(void)
{
  arm_reset();
}

{'fraction_non_alphanumeric': 0.22058144900784496, 'fraction_numerical': 0.01430549146285187, 'mean_word_length': 2.17117776152158, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4771694', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1439, 'n_words': 439}