UnnamedOS
Task

Task. More...

+ Collaboration diagram for Task:

Data Structures

struct  task_t
 internal representation of a task More...
 

Macros

#define MAX_TASKS   1024
 maximum number of tasks
 
#define _4KB   0x1000
 4KB are 4096 bytes, often used for stacks
 

Typedefs

typedef uint8_t task_stack_t
 stacks are measured in bytes
 
typedef uint32_t task_pid_t
 unique process ID
 

Enumerations

enum  task_state_t { TASK_STOPPED, TASK_RUNNING }
 state of a task
 

Functions

static task_ttask_get (task_pid_t pid)
 Returns the internal task structure associated with the given PID. More...
 
task_pid_t task_add (task_t *task)
 Adds a new task to the task list and associates a PID. More...
 
static void task_remove (task_pid_t pid)
 Removes a task from the task list. More...
 
static task_pid_t task_create_detailed (void *entry_point, page_directory_t *page_directory, size_t kernel_stack_len, size_t user_stack_len, elf_t *elf, size_t code_segment, size_t data_segment)
 Creates a task. More...
 
task_pid_t task_create_kernel (void *entry_point, page_directory_t *page_directory, size_t kernel_stack_len)
 Creates a kernel task. More...
 
task_pid_t task_create_user (void *entry_point, page_directory_t *page_directory, size_t kernel_stack_len, size_t user_stack_len, void *elf)
 Creates a user task. More...
 
void task_stop (task_pid_t pid)
 Stops a task. More...
 
void task_destroy (task_pid_t pid)
 Destroys a task. More...
 
task_pid_t task_get_next_task (task_pid_t pid)
 Returns the next task from the task list. More...
 
task_pid_t task_get_next_task_with_state (task_pid_t pid, task_state_t state)
 Returns the next task from the task list with a specified state. More...
 
task_state_t task_get_ticks (task_pid_t pid)
 Returns a task's number of remaining ticks. More...
 
uint32_t task_set_ticks (task_pid_t pid, uint32_t ticks)
 Sets a task's number of remaining ticks. More...
 
cpu_state_ttask_get_cpu (task_pid_t pid)
 Returns a task's CPU state. More...
 
void task_set_cpu (task_pid_t pid, cpu_state_t *cpu)
 Sets a task's CPU state. More...
 
page_directory_ttask_get_page_directory (task_pid_t pid)
 Returns a task's page directory. More...
 
uint8_t task_get_vm86 (task_pid_t pid)
 Returns whether a task is a VM86 task. More...
 
void * task_get_elf (task_pid_t pid)
 Returns a task's ELF file. More...
 
void task_dump ()
 Dumps the task list. More...
 

Variables

static task_ttasks [MAX_TASKS]
 Array of tasks. More...
 

Detailed Description

Task.

This controls multitasking. Each tasks has two associated stacks, a kernel stack for interrupt handling and a user stack that serves as user call stack. Also each task has its own page directory and therefore virtual address space.

See also
http://www.lowlevel.eu/wiki/Teil_6_-_Multitasking

Function Documentation

task_pid_t task_add ( task_t task)

Adds a new task to the task list and associates a PID.

Parameters
taskthe task structure
Returns
the task's PID

Definition at line 46 of file task.c.

+ Here is the caller graph for this function:

static task_pid_t task_create_detailed ( void *  entry_point,
page_directory_t page_directory,
size_t  kernel_stack_len,
size_t  user_stack_len,
elf_t elf,
size_t  code_segment,
size_t  data_segment 
)
static

Creates a task.

Parameters
entry_pointthe virtual address where to start execution
page_directorya page directory for the task, if 0 a new one is created
kernel_stack_lennumber of bytes to allocate for the kernel stack
user_stack_lennumber of bytes to allocate for the user stack
elfan ELF file, if 0 this is not an ELF task
code_segmenta code segment in the GDT
data_segmenta data segment in the GDT
Returns
the task's PID

Prepares a CPU state to pop off when a timer interrupt occurs. The CPU state lies at the top of the task's kernel stack.

Makes an initial CPU state, setting the registers popped off in isr_asm.S.

Tells the scheduler to run this task.

Definition at line 75 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

task_pid_t task_create_kernel ( void *  entry_point,
page_directory_t page_directory,
size_t  kernel_stack_len 
)

Creates a kernel task.

Parameters
entry_pointthe virtual address where to start execution
page_directorya page directory for the task, if 0 a new one is created
kernel_stack_lennumber of bytes to allocate for the kernel stack
Returns
the task's PID

Definition at line 128 of file task.c.

+ Here is the call graph for this function:

task_pid_t task_create_user ( void *  entry_point,
page_directory_t page_directory,
size_t  kernel_stack_len,
size_t  user_stack_len,
void *  elf 
)

Creates a user task.

Parameters
entry_pointthe virtual address where to start execution
page_directorya page directory for the task, if 0 a new one is created
kernel_stack_lennumber of bytes to allocate for the kernel stack
user_stack_lennumber of bytes to allocate for the user stack
elfan ELF file, if 0 this is not an ELF task
Returns
the task's PID

Definition at line 143 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void task_destroy ( task_pid_t  pid)

Destroys a task.

This requires the task to have been stopped before.

Parameters
pidthe task's PID

Definition at line 161 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void task_dump ( )

Dumps the task list.

The dump is logged.

Definition at line 283 of file task.c.

+ Here is the call graph for this function:

static task_t* task_get ( task_pid_t  pid)
static

Returns the internal task structure associated with the given PID.

Parameters
pidthe task's PID
Returns
the task structure

Definition at line 33 of file task.c.

+ Here is the caller graph for this function:

cpu_state_t * task_get_cpu ( task_pid_t  pid)

Returns a task's CPU state.

Parameters
pidthe task's PID
Returns
the task's CPU state

Definition at line 240 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * task_get_elf ( task_pid_t  pid)

Returns a task's ELF file.

Parameters
pidthe task's PID
Returns
the task's ELF file or 0

Definition at line 276 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

task_pid_t task_get_next_task ( task_pid_t  pid)

Returns the next task from the task list.

Parameters
pidthe current task's PID
Returns
the next task's PID

Definition at line 184 of file task.c.

+ Here is the caller graph for this function:

task_pid_t task_get_next_task_with_state ( task_pid_t  pid,
task_state_t  state 
)

Returns the next task from the task list with a specified state.

Parameters
pidthe current task's PID
statethe next task's desired state
Returns
the next task's PID

Definition at line 200 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

page_directory_t * task_get_page_directory ( task_pid_t  pid)

Returns a task's page directory.

Parameters
pidthe task's PID
Returns
the task's page directory

Definition at line 258 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

task_state_t task_get_ticks ( task_pid_t  pid)

Returns a task's number of remaining ticks.

Parameters
pidthe task's PID
Returns
the task's number of remaining ticks

Definition at line 218 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8_t task_get_vm86 ( task_pid_t  pid)

Returns whether a task is a VM86 task.

Parameters
pidthe task's PID
Returns
whether the task is a VM86 task

Definition at line 267 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void task_remove ( task_pid_t  pid)
static

Removes a task from the task list.

Parameters
pidthe task's PID

Definition at line 60 of file task.c.

+ Here is the caller graph for this function:

void task_set_cpu ( task_pid_t  pid,
cpu_state_t cpu 
)

Sets a task's CPU state.

Parameters
pidthe task's PID
cputhe task's CPU state

Definition at line 249 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32_t task_set_ticks ( task_pid_t  pid,
uint32_t  ticks 
)

Sets a task's number of remaining ticks.

Parameters
pidthe task's PID
ticksthe number of remaining ticks
Returns
the old number of remaining ticks

Definition at line 228 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void task_stop ( task_pid_t  pid)

Stops a task.

This does not remove the task from the task list.

Parameters
pidthe task's PID

Definition at line 153 of file task.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

task_t* tasks[MAX_TASKS]
static

Array of tasks.

Fixed-size array for now, may change in the future.

Definition at line 26 of file task.c.