Avatar billede bulla Nybegynder
28. september 2007 - 17:47

Operating Systems

Hej
Jeg har fået til opgave at impelemnetere to nye system kald til min kernel. Disse to kald tillader programmet at create nye processer og "terminere" dem selv. Til at starte med Vil jeg tjekke om der ikke allerede kører en kopi af programmet.
Der er blevet udleveret følgende kode:

/*! \file syscall.c
This files holds the implementations of all system calls.
  fortsætter switch case'n i main.c: # include "syscall.c"
  i headerfilen kernel.h #define KERNEL_VERSION (0x0000000100000000)

*/

case SYSCALL_PRINTS:
{
  kprints((char*) (SYSCALL_ARGUMENTS.rdi)); // printer
    SYSCALL_ARGUMENTS.rax=ALL_OK; // vigtigt at læse den når den kommer, rax register

break;
}
case SYSCALL_PRINTHEX:
{
kprinthex(SYSCALL_ARGUMENTS.rdi); // printer hex tal
      SYSCALL_ARGUMENTS.rax=ALL_OK; // lægger ind i rdi registeret
  break;
}


case SYSCALL_DEBUGGER:
{
/* Enable the bochs iodevice and force a return to the debugger. */
outw(0x8a00, 0x8a00);
outw(0x8a00, 0x8ae0);

SYSCALL_ARGUMENTS.rax=ALL_OK;
break;
}

/* Add the implementation of more system calls here. */
case SYSCALL_VERSION:
{
    SYSCALL_ARGUMENTS.rax=KERNEL_VERSION; // returner kernel versionen, fra headerfil
    break;
/* Bruger ikke ALL_OK, da den vil overskrive versions-værdien */
}


Dette er så kernel filen.
/*! \file kernel.h

This file holds kernel wide macros and declarations.

*/

#ifndef _KERNEL_H_
#define _KERNEL_H_

/* Macros */

#define SYSCALL_ARGUMENTS (thread_table[current_thread].data.registers.\
                          integer_registers)
/*!< Macro used in the system call switch to access the arguments to the
    system call. */

#define KERNEL_VERSION          (0x0000000100000000)
/*!< Kernel version number. */

#define MAX_NUMBER_OF_PROCESSES (16)
#define MAX_NUMBER_OF_THREADS  (256)

#define ALL_OK                  (0)
#define ERROR                  (-1)
#define ERROR_ILLEGAL_SYSCALL  (-2)

#define SYSCALL_VERSION        (0)
#define SYSCALL_PRINTS          (1)
#define SYSCALL_PRINTHEX        (2)
#define SYSCALL_DEBUGGER        (3)

/* System calls to implement in task B2 */
/* Takes no parameters. Terminates the currently running
  thread. Terminates the process when there are no threads
  left. */
#define SYSCALL_TERMINATE      (4)

/* Takes an index into the executable table in rdi. Creates
  a new thread with one single thread. The program used is
  the executable whose index is passed in rdi. */
#define SYSCALL_CREATEPROCESS  (5)


/* Type declarations */

struct context
{
char    fpu_context[512];
/*!< Stores the fpu/mmx/sse context */
struct
{
  long    rax;
  long    rbx;
  long    rcx;
  long    rdx;
  long    rdi;
  long    rsi;
  long    rbp;
  long    rsp;
  long    r8;
  long    r9;
  long    r10;
  long    r11;
  long    r12;
  long    r13;
  long    r14;
  long    r15;
  long    rflags;
  long    rip;
}        integer_registers;
/*!< Stores all user visible integer registers. The segment registers are not
      stored as the user mode processes can only use a code and a data segment
      descriptor. We assume that the cs is set to the code and all the rest
      of the segment registers are set to the data segment all the time. */
};
/*!< Defines a execution context. */

union thread
{
struct
{
  struct context registers;    /*!< The context of the thread. Note: the
                                    context of the thread could include more
                                    than the accessible registers. */
  int            owner;        /*!< This is an index into process_table. The
                                    index corresponds to the process that owns
                                    this thread. */
}              data;
char            padding[1024];
};
/*!< Defines a thread. */

struct process
{
int            threads;      /*!< The number of threads running in this
                                    process. */
int            parent;        /*!< This is an index into process_table. The
                                    index corresponds to the parent process. */
};
/*!< Defines a process. */

struct executable
{
unsigned long  start;        /*!< Start address of the program */
};
/*!< Defines an executable program. */

/* Variable declarations */

extern union thread
thread_table[MAX_NUMBER_OF_THREADS];
/*!< Array holding all threads in the systems. */

extern struct process
process_table[MAX_NUMBER_OF_PROCESSES];
/*!< Array holding all processes in the system. */

extern struct executable *
executable_table;
/*!< Array holding descriptions of all executable programs. */

extern int
executable_table_size;
/*!< The number of executable programs in the executable_table */


extern int
current_thread;
/*!< The index, into thread_table, of the currently running thread. */

/* Function declarations */

/*! This fuction initializes the kernel after the assembly code portion has
    set the system and the CPU up. */
extern void
initialize(void);

/*! This function gets called from the syscall handler and responds to the
    system calls. */
extern void
system_call_handler(void);

/*! Outputs a string to the bochs console. */
extern void
kprints(const char* const string
        /*!< points to a null terminated string */
        );

/*! Prints a long formatted as a hexadecimal number to the bochs console. */
extern void
kprinthex(const register long value
          /*!< the value to be written */);

#endif


Jeg har gjort følgende:
case SYSCALL_CREATEPROCESS{
   
    if(process_table[i].data.owner==-1)

        return i;
}Men dette er helt rigtigt eftersom det skal kunne anvendes på multithreads.

Håber virkelig at der er en der kan hjælpe, for er virkelig forvirret. På forhånd mange tak.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester