GitOS
Operating system exercise
Loading...
Searching...
No Matches
task.c File Reference
#include "task.h"
#include <common/assert.h>
#include "common/status.h"
#include "memory/paging/paging.h"
#include "memory/heap/kheap.h"
#include "gdt/gdt.h"
#include "idt/idt.h"
#include "memory/memory.h"
#include "process.h"
#include "kernel.h"
#include "common/string.h"

Functions

int task_init (struct task *task, struct process *process)
 Initializes task struct's ip,ss,esp registers and created new paging directory.
 
struct tasktask_current ()
 Returns currently running task.
 
void task_save_state (struct task *task, struct interrupt_frame *frame)
 
void task_current_save_state (struct interrupt_frame *frame)
 
struct tasktask_get_next ()
 Returns next task in list (or first if there is no next task in current_task)
 
int task_free (struct task *task)
 Frees all data associated with task struct.
 
int task_switch (struct task *task)
 Switch current task (switch pages)
 
int task_page ()
 Loads into the task's page.
 
void task_run_first_ever_task ()
 
struct tasktask_new (struct process *process)
 
int task_copy_string_from (struct task *task, void *virtual_address, void *physical_address, int max)
 
void task_page_task (struct task *task)
 
void * task_peek_stack (struct task *task, int offset)
 

Variables

struct taskcurrent_task = 0
 
struct tasktask_tail = 0
 
struct tasktask_head = 0
 

Function Documentation

◆ task_copy_string_from()

int task_copy_string_from ( struct task task,
void *  virtual_address,
void *  physical_address,
int  max 
)

◆ task_current()

struct task * task_current ( )

Returns currently running task.

Returns
struct task* Current task

References current_task.

◆ task_current_save_state()

void task_current_save_state ( struct interrupt_frame frame)

◆ task_free()

int task_free ( struct task task)

Frees all data associated with task struct.

Parameters
taskTask to free
Returns
int Error code

References kfree(), task::page_directory, and paging_free_directory().

◆ task_get_next()

struct task * task_get_next ( )

Returns next task in list (or first if there is no next task in current_task)

Returns
struct task* Next task

References current_task, task::next, and task_head.

◆ task_init()

int task_init ( struct task task,
struct process process 
)

Initializes task struct's ip,ss,esp registers and created new paging directory.

Parameters
taskStruct to be initialized
Returns
int Error code

References registers::cs, EIO, process::elf_entry, registers::esp, registers::flags, registers::ip, memset(), task::page_directory, PAGING_ACCESS_FROM_ALL, PAGING_IS_PRESENT, paging_new_directory(), task::process, PROGRAM_VIRTUAL_STACK_ADDRESS_START, task::registers, registers::ss, USER_CODE_SELECTOR, and USER_DATA_SELECTOR.

◆ task_new()

struct task * task_new ( struct process process)

◆ task_page()

int task_page ( )

Loads into the task's page.

Returns
int Error code

References current_task, task_switch(), and user_registers().

◆ task_page_task()

void task_page_task ( struct task task)

References task_switch(), and user_registers().

◆ task_peek_stack()

void * task_peek_stack ( struct task task,
int  offset 
)

◆ task_run_first_ever_task()

void task_run_first_ever_task ( )

◆ task_save_state()

◆ task_switch()

int task_switch ( struct task task)

Switch current task (switch pages)

Parameters
taskTask to switch to
Returns
int Error code

References current_task, task::page_directory, and paging_switch().

Variable Documentation

◆ current_task

struct task* current_task = 0

◆ task_head

struct task* task_head = 0

◆ task_tail

struct task* task_tail = 0