Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

task.h File Reference

Headers for the task manager. More...

#include <arch/paging.h>
#include <arch/i386.h>

Go to the source code of this file.

Data Structures

struct  task
 The task structure. More...

struct  tss
 TSS without I/O bit map. More...

struct  tss_IO
 TSS with I/O bit map. More...


Defines

#define STACK_SIZE   0x8000
 Stack size in byte for every kernel-mode task.

#define TASK_STACK_START   0xC0000000
 The address where the user-privilege task stack is placed.

#define TASK_HEAP_START   0x40000000
 The start of the heap for a user-mode task.

#define TASK_HEAP_DEFAULT_SIZE   0x40000000
 The size of the heap for a user-mode task.

#define READY   1
 The task is ready for the CPU.

#define WAIT   2
 The task is waiting for I/O.

#define ZOMBIE   3
 The task is dying.

#define KTHREAD_T   0x00
 A kernel thread type.

#define PROCESS_T   0x01
 A task type.

#define KERNEL_PRIVILEGE   0
 Max privilege (kernel).

#define USER_PRIVILEGE   3
 Min privilege (user).

#define MYSELF   ( get_curr_task() )
 Macro equivalent to get_curr_task() routine.

#define _exit(n)   auto_kill(n)
 Macro equivalent to auto_kill() (...for now).


Typedefs

typedef tss tss_t
 TSS without I/O bit map.

typedef tss_IO tss_IO_t
 TSS with I/O bit map.

typedef task task_t
 The task structure.


Functions

__inline__ void idle ()
 Halt the CPU until an interrupt occurs.

__inline__ void jmp_to_tss (word tss_sel)
 Perform a context switch between two tasks.
Parameters:
tss_sel  The selector of the next task.


void dispatcher ()
 The dispatcher.

void init_multitasking ()
 Initialize the multitasking management.

int get_pid ()
 Return the current task pid if there is a curr_task.
Returns:
The current task pid.


char * get_pname ()
 Return the current task name if there is a curr_task.
Returns:
The current task name.


task_tget_curr_task ()
 Get the current task.
Returns:
The current task structure pointer.


void do_idle ()
 Simply do nothing...

task_tcreate_kthread (void *address, char *pname)
 Create a new kernel thread.
Parameters:
address  The address of the starting point for the thread.
pname  The name of the new thread.
Returns:
A pointer to the new-created task structure.
Exceptions:
NULL  If an error occurs (in particular out-of-memory).


task_tcreate_process (void *address, void *buffer, size_t size, char *pname, int privilege)
 Create a new process.
Parameters:
address  The address of the starting point for the thread.
buffer  An address to a buffer where is placed the executable code.
size  The size of the executable code buffer.
pname  The name of the new task.
privilege  The privilege level of the new task:
Returns:
A pointer to the new-created task structure.
Exceptions:
NULL  If an error occurs (in particular out-of-memory).


task_tnew_task (char *filename, int argc, char **argv, int privilege)
 Execute a file creating a new task.
Parameters:
filename  The name of the file to execute.
argc  The number of arguments passed to the new process.
argv  The arguments passed to the new process.
argv  A pointer to the argument strings.
privilege  The privilege level of the new task:
Returns:
A pointer to the new-created task structure.
Exceptions:
NULL  If an error occurs (in particular out-of-memory).


void auto_kill (int n)
 Kill the current running task.
Parameters:
n  The return code.


bool kill (pid_t pid)
 Kill a task by the pid.
Parameters:
pid  The process id.
Returns:
  • TRUE if the task has been successfully killed
  • FALSE if the task cannot be killed.


pid_t waitpid (pid_t pid, int *status, int options)
 Wait for the exit of a child.
Parameters:
pid 
  • The child process id
  • -1 to wait for the exit of a generic child.
status  Reports the status of the child.
options  Options flags.
Returns:
The pid of the child or -1 if the process has not been found.


void sleep_task (task_t *p)
 Sleep a process if it is awake.
Parameters:
p  The structure of the task to sleep.


void wakeup_task (task_t *p)
 Wakeup a process if it is sleeping.
Parameters:
p  The structure of the task to wakeup.


void sched_enter_critical_region ()
 Disable the scheduling of the other tasks.
Warning:
ATTENTION!!! Remember to call sched_leave_critical_region() when the task exits from the critical region. Otherwise the whole system could be blocked, because the scheduling of the other tasks is disabled after a task calls this function.


void sched_leave_critical_region ()
 Re-enable scheduling for the other tasks.

bool is_sched_enabled ()
 Return if the scheduling is enabled or not.
Returns:
  • TRUE if the scheduling is enabled
  • FALSE otherwise.


void ps ()
 Print the state of every process from the ready, wait and zombie queues.


Detailed Description

Headers for the task manager.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2003-12-16
Note:
Copyright (©) 2003 Andrea Righi

Definition in file task.h.


Define Documentation

#define _exit      auto_kill(n)
 

Macro equivalent to auto_kill() (...for now).

Todo:
The exit returning values between tasks.

Definition at line 157 of file task.h.

#define KERNEL_PRIVILEGE   0
 

Max privilege (kernel).

Definition at line 31 of file task.h.

#define KTHREAD_T   0x00
 

A kernel thread type.

Definition at line 28 of file task.h.

#define MYSELF   ( get_curr_task() )
 

Macro equivalent to get_curr_task() routine.

Definition at line 142 of file task.h.

#define PROCESS_T   0x01
 

A task type.

Definition at line 29 of file task.h.

#define READY   1
 

The task is ready for the CPU.

Definition at line 24 of file task.h.

#define STACK_SIZE   0x8000
 

Stack size in byte for every kernel-mode task.

Definition at line 15 of file task.h.

#define TASK_HEAP_DEFAULT_SIZE   0x40000000
 

The size of the heap for a user-mode task.

Definition at line 22 of file task.h.

#define TASK_HEAP_START   0x40000000
 

The start of the heap for a user-mode task.

Definition at line 20 of file task.h.

#define TASK_STACK_START   0xC0000000
 

The address where the user-privilege task stack is placed.

Definition at line 18 of file task.h.

#define USER_PRIVILEGE   3
 

Min privilege (user).

Definition at line 32 of file task.h.

#define WAIT   2
 

The task is waiting for I/O.

Definition at line 25 of file task.h.

#define ZOMBIE   3
 

The task is dying.

Definition at line 26 of file task.h.


Typedef Documentation

typedef struct task task_t
 

The task structure.

typedef struct tss_IO tss_IO_t
 

TSS with I/O bit map.

typedef struct tss tss_t
 

TSS without I/O bit map.


Function Documentation

__inline__ void idle   [static]
 

Halt the CPU until an interrupt occurs.

Definition at line 109 of file task.h.

00110 {
00111         __asm__ __volatile__ ("hlt");
00112 }

__inline__ void jmp_to_tss word    tss_sel [static]
 

Perform a context switch between two tasks.

Parameters:
tss_sel  The selector of the next task.

This is an asm routine to jump to a TSS (TSS-based multitasking)

Definition at line 121 of file task.h.

00122 {
00123         static struct {
00124         unsigned eip : 32; // 32 bit
00125         unsigned cs  : 16; // 16 bit
00126         } __attribute__ ((packed)) tss_link = {0, 0};
00127 
00128         // Set the TSS link                                             //
00129         tss_link.cs = tss_sel;
00130 
00131         // Jump to the task                                             //
00132         __asm__ __volatile__ ("ljmp *(%0)" : : "m" (tss_link));
00133 }


Generated on Fri Feb 20 15:32:20 2004 for Minirighi by doxygen1.2.18