Newer
Older
ubixos / src / sys / kernel / syscall.c
@reddawg reddawg on 6 Jun 2002 2 KB Enhancements
/**************************************************************************************
 Copyright (c) 2002 The UbixOS Project
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification,
 are prohibited.

 $Id$

**************************************************************************************/

#include <ubixos/syscall.h>
#include <ubixos/syscalls.h>
#include <ubixos/schedule.h>
#include <ubixos/types.h>
#include <drivers/video.h>

asm(
  ".globl _sysCall             \n"
  "_sysCall:                   \n"
  //"  pusha                     \n" /* Save all registers           */
  //"  pushw %ds                 \n" /* Set up the data segment      */
  //"  pushw %es                 \n"
  //"  pushw %ss                 \n" /* Note that ss is always valid */
  //"  pushw %ss                 \n"
  //"  popw %ds                  \n"
  //"  popw %es                  \n"
  "  cmpl totalCalls,%eax      \n"
  "  jae invalidCall           \n"
  "  call *systemCalls(,%eax,4) \n"
  //"  popw %es                  \n"
  //"  popw %ds                  \n" /* Restore registers            */
  //"  popa                      \n"
  "  iret                      \n" /* Exit interrupt               */
  );

void invalidCall() {
  kprintf("Invalid System Call!!\n");
  //_current->status = AVAILABLE;
  //schedule();
  }

void sysFwrite() {
  char *ptr;
  char data[1024];
  int i=0;
  int size;
  int fd;
  asm("": "=b" (ptr),"=c" (size),"=d" (fd));
  if (fd == 0) {
    for (i=0;i<size;i++) {
      data[i] = ptr[i];
      }
    kprintf("%s",data);
    }
  else {
    kprintf("Id: [%i],Size: [%i]\n",fd,size);
    }
  }

void sysGetpid() {
  char *pid;
    asm (
    ""
    : "=b" (pid)
    );
  pid[0] = _current->id;
  }

void sysExit() {
  int *status;
  asm("":"=b" (status));
  freeProcesspages(_current->id);
  _current->status = AVAILABLE;
  schedule();
  kprintf("Status: [%i]\n",status);
  }

void sysExec() {
  char *file;
  asm("":"=b" (file));
  kprintf("File [%s]\n",file);
  disableIrq(0);
  asm("sti");
  execFile(file);
  kprintf("Executed File\n");
//  while(1);
  enableIrq(0);
  }