<commit_before>/*
 *
 * TINKER Source Code
 * 
 *
 *  [2009] - [2013] <NAME>
 *  All Rights Reserved.
 */

#include "arm.h"

#include "config.h"
#include "arm_cpsr.h"
#include "arm_vec.h"
#include "arm_mmu.h"

#include "tinker_api_types.h"
#include "kernel_initialise.h"
#include "interrupts/interrupt_manager.h"

void tgt_initialise(void)
{
	if (is_debug_enabled(TARGET))
	{
		debug_prints(TARGET, "Target: Disable MMU\n");
	}
	arm_disable_mmu();
	if (is_debug_enabled(TARGET))
	{
		debug_prints(TARGET, "Target: Invalidate TLBs\n");
	}
	arm_invalidate_all_tlbs();
}

return_t tgt_initialise_process(process_t * const process)
{
    return_t ok = NO_ERROR;

    if (!process_is_kernel(process))
    {
        tgt_mem_t segment_info;
        segment_info.unused = 0;
        process_set_mem_info(process, &segment_info);

        /* setup pages for all the memory sections, i.e. code, data, rdata, sdata, bss */
        const mem_section_t * section = process_get_first_section(process);
        while (section && (ok == NO_ERROR))
        {
            /* setup virt -> real mapping for size */
        	tgt_map_memory(process, section);
        	if (is_debug_enabled(TARGET))
        	{
        		debug_print(TARGET, "mapping %x to %x\n", mem_sec_get_virt_addr(section), mem_sec_get_real_addr(section));
        	}
            section = mem_sec_get_next(section);
        }
    }

    return ok;
}

static void __attribute__((naked)) arm_bootstrap(
		thread_entry_point * const entry,
		uint32_t exit_function,
		const uint32_t sp) TINKER_API_SUFFIX;

static void __attribute__((naked)) arm_bootstrap(
		 /* R0 */ thread_entry_point * const entry,
		 /* R1 */ uint32_t exit_function,
		 /* R2 */ const uint32_t sp)
{
	asm volatile("mrs %r7, cpsr");			/* get cpsr */
	asm volatile("mov r8, #0xFFFFFF20");	/* blat out the mode and enable interrupts */
	asm volatile("and r7, r7, r8");			/* and cpsr and mode wipe */
	asm volatile("orr r7, r7, #0x10");		/* set the mode */
	asm volatile("msr cpsr, r7");			/* move the mode into cpsr */

	asm volatile("mov sp, r2");				/* set the programs stack */
	asm volatile("push {fp, lr}");			/* move the new stack on the stack for the first frame */
	asm volatile("mov r0, r5");				/* set arg1 */
	asm volatile("mov r1, r6");				/* set arg2 */
	tinker_debug("STARTIING APP\n", 14);
	entry();<commit_msg>Move the hello message to a separate function so it's on the stack<commit_after>/*
 *
 * TINKER Source Code
 * 
 *
 *  [2009] - [2013] <NAME>
 *  All Rights Reserved.
 */

#include "arm.h"

#include "config.h"
#include "arm_cpsr.h"
#include "arm_vec.h"
#include "arm_mmu.h"

#include "tinker_api_types.h"
#include "kernel_initialise.h"
#include "interrupts/interrupt_manager.h"

void tgt_initialise(void)
{
	if (is_debug_enabled(TARGET))
	{
		debug_prints(TARGET, "Target: Disable MMU\n");
	}
	arm_disable_mmu();
	if (is_debug_enabled(TARGET))
	{
		debug_prints(TARGET, "Target: Invalidate TLBs\n");
	}
	arm_invalidate_all_tlbs();
}

return_t tgt_initialise_process(process_t * const process)
{
    return_t ok = NO_ERROR;

    if (!process_is_kernel(process))
    {
        tgt_mem_t segment_info;
        segment_info.unused = 0;
        process_set_mem_info(process, &segment_info);

        /* setup pages for all the memory sections, i.e. code, data, rdata, sdata, bss */
        const mem_section_t * section = process_get_first_section(process);
        while (section && (ok == NO_ERROR))
        {
            /* setup virt -> real mapping for size */
        	tgt_map_memory(process, section);
        	if (is_debug_enabled(TARGET))
        	{
        		debug_print(TARGET, "mapping %x to %x\n", mem_sec_get_virt_addr(section), mem_sec_get_real_addr(section));
        	}
            section = mem_sec_get_next(section);
        }
    }

    return ok;
}

static void __attribute__((naked)) arm_bootstrap(
		thread_entry_point * const entry,
		uint32_t exit_function,
		const uint32_t sp) TINKER_API_SUFFIX;

static void hello_world(void) TINKER_API_SUFFIX;

static void hello_world(void)
{
	char message[] = "STARTIING APP\n";
	tinker_debug(message, 14);
}

static void __attribute__((naked)) arm_bootstrap(
		 /* R0 */ thread_entry_point * const entry,
		 /* R1 */ uint32_t exit_function,
		 /* R2 */ const uint32_t sp)
{
	asm volatile("mrs %r7, cpsr");			/* get cpsr */
	asm volatile("mov r8, #0xFFFFFF20");	/* blat out the mode and enable interrupts */
	asm volatile("and r7, r7, r8");			/* and cpsr and mode wipe */
	asm volatile("orr r7, r7, #0x10");		/* set the mode */
	asm volatile("msr cpsr, r7");			/* move the mode into cpsr */

	asm volatile("mov sp, r2");				/* set the programs stack */
	asm volatile("push {fp, lr}");			/* move the new stack on the stack for the first frame */
	asm volatile("mov r0, r5");				/* set arg1 */
	asm volatile("mov r1, r6");				/* set arg2 */
	hello_world();
	entry();
{'fraction_non_alphanumeric': 0.1329907502569373, 'fraction_numerical': 0.017677286742034944, 'mean_word_length': 3.294792586054722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3072250', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1766, 'n_words': 442}