metalsvm/include/metalsvm/tasks.h
2011-06-29 12:31:32 -07:00

156 lines
3.8 KiB
C

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
/**
* @author Stefan Lankes
* @file include/metalsvm/tasks.h
* @brief Task related
*
* Create and leave tasks or fork them.
*/
#ifndef __TASKS_H__
#define __TASKS_H__
#include <metalsvm/config.h>
#include <metalsvm/stddef.h>
#include <metalsvm/tasks_types.h>
#include <asm/tasks.h>
#include <asm/irqflags.h>
#ifdef CONFIG_ROCKCREEK
#include <asm/icc.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* tasks, which are currently running */
//DECLARE_PER_CORE(task_t*, current_task);
/** @brief Initialize the multitasking subsystem
*
* This procedure sets the current task to the
* current "task" (there are no tasks, yet) and that was it.
*
* @return
* - 0 on success
* - -ENOMEM (-12) on failure
*/
int multitasking_init(void);
/** @brief create a kernel task.
*
* @param id The value behind this pointer will be set to the new task's id
* @param ep Pointer to the entry function for the new task
* @param arg Arguments the task shall start with
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int create_kernel_task(tid_t* id, entry_point_t ep, void* arg);
/** @brief Create a user level task.
*
* @param id The value behind this pointer will be set to the new task's id
* @param fname Filename of the executable to start the task with
* @param argv Pointer to arguments array
*
* @return
* - 0 on success
* - -EINVAL (-22) or -ENOMEM (-12)on failure
*/
int create_user_task(tid_t* id, const char* fame, char** argv);
/** @brief Block current task until the child task is terminated
* @param result The terminated child's return value
* @return The terminated child task id
*/
tid_t wait(int32_t* result);
/** @brief Task switcher
*
* Timer-interrupted use of this function for task switching */
void scheduler(void);
/** @brief Wake up a blocked task
*
* The task's status will be changed to TASK_READY
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int wakeup_task(tid_t);
/** @brief Change a task's status to TASK_BLOCKED
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int block_task(tid_t);
/** @brief Abort current task */
void NORETURN abort(void);
/** @brief This function shall be called by leaving kernel level tasks */
void NORETURN leave_kernel_task(void);
/** @brief This function shall be called by leaving user level tasks */
void NORETURN leave_user_task(void);
/** @brief System call to terminate a user level process */
void NORETURN sys_exit(int);
/** @brief System call to create a new child process
* @return
* - 0 on success
* - -ENOMEM (-12) on failure
* */
int sys_fork(void);
/** @brief System call to execute a program
*
* @param fname Filename of the executable
* @param argv Pointer to the argument array the task shall start with
* @param env Pointer to the environment array the task shall start with
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int sys_execve(const char* fname, char** argv, char** env);
static inline void check_workqueues(void)
{
uint32_t flags = irq_nested_disable();
#ifdef CONFIG_ROCKCREEK
icc_mail_check();
#endif
irq_nested_enable(flags);
}
#ifdef __cplusplus
}
#endif
#endif