<commit_before>/*
 * port.c
 *
 *  Created on: 2017.1.25
 *      Author: xzy47
 */


#include "lightos.h"
#include "task.h"


void LPortSysTickHandler(void)
{
    LTickIncrement();
//	if(l_nextTaskID != l_curTaskID)
//	    LPORT_NVIC_INT_CTRL_REG = LPORT_NVIC_PENDSVSET_BIT;
}

void LPortInitScheduler(void)
{
	void (*p_funcFirst)();
	l_uint32_t curPSP;

#if defined(__CC_ARM)
	curPSP = l_PSPArray[l_curTaskID] + 16*4;
	__asm
	{
		MSR psp, curPSP
		
#ifdef LCONFIG_TASK_PRIVILEGE_LEVELS
	  MSR control, 0x2 
#else
	  MSR control, 0x3
#endif
		
		isb 0xF
	}
#elif defined(__GNUC__)
	__asm volatile ("MSR psp, %0\n" : : "r" ((l_PSPArray[l_curTaskID] + 16*4)) :"sp" );
	
#ifdef LCONFIG_TASK_PRIVILEGE_LEVELS
	__asm volatile ("MSR control, %0" : : "r" (0x2) : "memory");
#else
	__asm volatile ("MSR control, %0" : : "r" (0x3) : "memory");
#endif
	
	__asm volatile ("isb 0xF":::"memory");
#endif
	
  LTaskStartScheduler();
	curPriority = l_priorityBitmap[l_taskPriorityTable];

	p_funcFirst = (void (*)())*(uint32_t *)(l_PSPArray[l_nextTaskID] + 56);
	p_funcFirst();

}

l_stack_t *LPortInitStack(l_stack_t *pxTopOfStack, LTaskFunction_t pxEntry)
{
    l_stack_t  *p_stk;
    l_uint32_t  *p_stk32;
                                                                    /* Load and pre-align stack pointer.                    */
    p_stk = pxTopOfStack;
    p_stk--;
    p_stk32 = (l_uint32_t *)p_stk;
                                                                    /* Save registers as if auto-saved.                     */
                                                                    /* Follow stacking method in "9) Perform automatic ...  */
                                                                    /* ..context save" of section 3.4 in "SPRU430E"         */
    *p_stk32-- = 0x01000000;                                    /*   T:ST0                                              */
    *p_stk32-- = (l_uint32_t)pxEntry;                           /*   AH:AL                                              */<commit_msg>Updated inline ASM to CMSIS define<commit_after>/*
 * port.c
 *
 *  Created on: 2017.1.25
 *      Author: xzy47
 */


#include "lightos.h"
#include "task.h"


void LPortSysTickHandler(void)
{
    LTickIncrement();
//	if(l_nextTaskID != l_curTaskID)
//	    LPORT_NVIC_INT_CTRL_REG = LPORT_NVIC_PENDSVSET_BIT;
}

void LPortInitScheduler(void)
{
	void (*p_funcFirst)();

	__set_PSP(l_PSPArray[l_curTaskID] + 16*4);
	
#ifdef LCONFIG_TASK_PRIVILEGE_LEVELS
	__set_CONTROL(0x2);
#else
	__set_CONTROL(0x3);
#endif
	
	__ISB();

  LTaskStartScheduler();
	curPriority = l_priorityBitmap[l_taskPriorityTable];

	p_funcFirst = (void (*)())*(uint32_t *)(l_PSPArray[l_nextTaskID] + 56);
	p_funcFirst();

}

l_stack_t *LPortInitStack(l_stack_t *pxTopOfStack, LTaskFunction_t pxEntry)
{
    l_stack_t  *p_stk;
    l_uint32_t  *p_stk32;
                                                                    /* Load and pre-align stack pointer.                    */
    p_stk = pxTopOfStack;
    p_stk--;
    p_stk32 = (l_uint32_t *)p_stk;
                                                                    /* Save registers as if auto-saved.                     */
                                                                    /* Follow stacking method in "9) Perform automatic ...  */
                                                                    /* ..context save" of section 3.4 in "SPRU430E"         */
    *p_stk32-- = 0x01000000;                                    /*   T:ST0                                              */
    *p_stk32-- = (l_uint32_t)pxEntry;                           /*   AH:AL                                              */
{'fraction_non_alphanumeric': 0.11228928765633496, 'fraction_numerical': 0.03099510603588907, 'mean_word_length': 1.4445182724252492, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3489249', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1211, 'n_words': 225}