Пример #1
0
void
start(void)
{
	int i;
	sys_share(SHARE);
	sys_priority(PRIORITY);
	#ifdef __EXERCISE_4A__ 
	sys_yield();//for 4a
	#endif
	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//cursorpos++ = PRINTCHAR;
		//atomic_swap(uint32_t *addr, uint32_t val);
		#ifdef __EXERCISE_8__  // exercise 8 sync method
			sys_atomic_print(PRINTCHAR);
		#else // exercise 6 sync method
		while(atomic_swap(&lock,1)!= 0)
		{
			//return 0 means get the lock;
			continue;
		}
		*cursorpos++ = PRINTCHAR;
		atomic_swap(&lock,0);
		#endif
		sys_yield();
		
		//release the lock
	}

	// Yield forever.
	sys_exit(0);
}
Пример #2
0
int main(char **argv, char **environ)
{
    
    int input = open("/dev/tty0", O_RDONLY);
    printf("\x1B[12h");
    char c = NULL;
    while(read(0, &c, 1) > 0) {
        printf("%c", c);
        int x, y;
        get_pos(input, &x, &y);
        if(y == 24) {
            printf("\x1B[0;24r");
            printf("\x1B[0;24f\x1B[1;47;2;30m--- More ---");
            printf("\x1B[8m");
            fflush(stdout);
            char c;
            read(input, &c, 1);
            printf("\x1B[0m");
            printf("\x1B[%d;23f", x);
            fflush(stdout);
        }
    }
    printf("\x1B[12l\n");
    fflush(stdout);
    sys_exit(0);
}
Пример #3
0
void sys_stat(char * pathname, struct stat * stat_buf)
{
	if (stat(pathname,stat_buf) < 0) {
		log_err("error while stating file -- bailing out\n");
		sys_exit();
	}
}
Пример #4
0
void sys_close(int filedes)
{
	if (close(filedes) < 0) {
		log_err("error while closing file -- bailing out\n");
		sys_exit();
	}
}
Пример #5
0
void sys_fstat(int filedes, struct stat * stat_buf)
{
	if (fstat(filedes,stat_buf) < 0) {
		log_err("error while fstating file (fd = %d) -- bailing out\n",filedes);
		sys_exit();
	}
}
Пример #6
0
void sys_munmap(void* addr, size_t length)
{
	if (munmap(addr, length) == -1) {
		log_err("cannot un-map file");
		sys_exit();
	}
}
Пример #7
0
void
start(void)
{

	sys_priority(PRIORITY);
	sys_share(SHARE);
	sys_yield();

	int i;

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//*cursorpos++ = PRINTCHAR;
		//call system call instead
		#ifndef __EXERCISE_8__
		sys_print(PRINTCHAR);
		#endif

		#ifdef __EXERCISE_8__
		while(atomic_swap(&spin_lock, 1) != 0){ //run 4ever until locked
			continue;
		}
		*cursorpos++ = PRINTCHAR;
		atomic_swap(&spin_lock, 0); //free
		#endif

		sys_yield();
	}

	// Yield forever.
	while (1)
		//sys_yield();
		sys_exit(0);
}
Пример #8
0
void
start(void)
{
	int i;

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//*cursorpos++ = PRINTCHAR;

		// Atomic syscall version
		#ifdef __EXERCISE_6__
		sys_print(PRINTCHAR);
		#endif

		// Atomic lock version
		#ifdef __EXERCISE_8__
		while (atomic_swap(&lock, 1) != 0)
			continue;

		*cursorpos++ = PRINTCHAR;
		atomic_swap(&lock, 0);
		#endif

		sys_yield();
	}

	/*// Yield forever.
	while (1)
		sys_yield();*/

	sys_exit(0);
}
Пример #9
0
/* Open a file. */
static int
sys_open (const char *file)
{
  struct file *sys_f;
  struct user_file *f;

#if PRINT_DEBUG
  printf ("[SYSCALL] SYS_OPEN: file: %s\n", file);
#endif

  if (file == NULL || !is_user_vaddr (file))
    sys_exit (-1);

  lock_acquire (&file_lock);
  sys_f = filesys_open (file);
  lock_release (&file_lock);
  if (sys_f == NULL)
    return -1;

  f = (struct user_file *) malloc (sizeof (struct user_file));
  if (f == NULL)
    {
      lock_acquire (&file_lock);
      file_close (sys_f);
      lock_release (&file_lock);
      return -1;
    }

  f->file = sys_f;
  f->fid = allocate_fid ();
  list_push_back (&thread_current ()->files, &f->thread_elem);

  return f->fid;
}
Пример #10
0
void
os_error (const char *message)
{
  recursion_check ();
  st_printf ("Operating system error: %s\n%s\n", get_oserror (), message);
  sys_exit (1);
}
Пример #11
0
static int
setcontext(uw7_context_t * uc, struct pt_regs * regs)
{
	if (!uc) /* SVR4 says setcontext(NULL) => exit(0) */
		sys_exit(0);
	return 0;
}
Пример #12
0
void
start(void)
{
	int i;
	
	sys_set_priority(__PRIORITY__);
	sys_set_share(__SHARE__);
	sys_set_lottery_tickets(__LOTTERY_TICKETS__);

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.

		#ifdef __PRINT_METHOD_LOCK__

		while(atomic_swap(&lock, 1) != 0) 
			continue;
		*cursorpos++ = PRINTCHAR;
		atomic_swap(&lock, 0);
		
		#else
		
		sys_atomic_print(PRINTCHAR);

		#endif

		sys_yield();
	}

	// Yield forever.
	//while (1)
	//	sys_yield();
	sys_exit(0);
}
Пример #13
0
/* Write to a file. */
static int
sys_write (int fd, const void *buffer, unsigned size)
{
  struct user_file *f;
  int ret = -1;

#if PRINT_DEBUG
  printf ("[SYSCALL] SYS_WRITE: fd: %d, buffer: %p, size: %u\n", fd, buffer, size);
#endif

  if (fd == STDIN_FILENO)
    ret = -1;
  else if (fd == STDOUT_FILENO)
    {
      putbuf (buffer, size);
      ret = size;
    }
  else if (!is_user_vaddr (buffer) || !is_user_vaddr (buffer + size))
    sys_exit (-1);
  else
    {
      f = file_by_fid (fd);
      if (f == NULL)
        ret = -1;
      else
        {
          lock_acquire (&file_lock);
          ret = file_write (f->file, buffer, size);
          lock_release (&file_lock);
        }
    }
  return ret;
}
Пример #14
0
void sys_fclose(FILE* file)
{
	if (fclose(file) < 0) {
		log_err("error while closing file -- bailing out\n");
		sys_exit();
	}
}
Пример #15
0
void
start(void)
{
	int i;

	for (i = 0; i < RUNCOUNT; i++) {
		#ifndef __EXERCISE_8__
		/* EXERCISE 6: use a system call to print characters *****************/
		sys_print(PRINTCHAR);
		#endif

		#ifdef __EXERCISE_8__
		/* EXERCISE 8: use a lock to prevent race conditions *****************/
		// spinlock until we obtain write lock
		while (atomic_swap(&spinlock, 1) != 0)
			continue;
		// write
		*cursorpos++ = PRINTCHAR;

		// release write lock
		atomic_swap(&spinlock, 0);
		#endif

		sys_yield();
	}

	// Yield forever.
	while (1)
		sys_exit(0);
}
Пример #16
0
static void signal_default(struct task *current, int signum)
{
    /* Init ignores every signal */
    if (current->pid == 1)
        return ;

    switch (signum) {
    case SIGCHLD:
    case SIGCONT:
    case SIGWINCH:
        /* Ignore */
        break;

    case SIGSTOP:
    case SIGTSTP:
    case SIGTTIN:
    case SIGTTOU:
        kp(KP_TRACE, "task %d: Handling stop (%d)\n", current->pid, signum);
        current->ret_signal = TASK_SIGNAL_STOP | signum;
        current->state = TASK_STOPPED;

        if (current->parent)
            scheduler_task_wake(current->parent);

        scheduler_task_yield();
        break;

    default:
        current->ret_signal = signum;
        sys_exit(0);
    }
}
Пример #17
0
void
start(void)
{
	int i;

	proc_priority(PRIORITYCHECK);
	proc_share(PRIORITYCHECK);
	sys_yield();

	for (i = 0; i < RUNCOUNT; i++) {
#ifdef USE_SYSTEM_SYNC
		// use a safe system call to print character to avoid a race condition
		proc_print(PRINTCHAR);
#else
		// use atomic_swap to get a lock
		while (atomic_swap(&lock, 1) !=0 ) {
			continue;
		}
		// Write characters to the console, yielding after each one.
		*cursorpos++ = PRINTCHAR;

		// use atomic_swap to release lock
		atomic_swap(&lock, 0);
#endif
		sys_yield();
	}

	// Yield forever.
	// while (1)
	// 	sys_yield();
	sys_exit(0);
}
Пример #18
0
int SYS_WRITE_handler(int32_t* esp)
{
  // Default to error...
  int retVal = -1;

  int fd = *(esp + 1);
  char* buffer = (char*)*(esp + 2);
  int len = *(esp + 3);
	
  if(verify_fix_length(esp[2], esp[3]) == false){
	sys_exit(-1);
  }
  if(fd == STDOUT_FILENO){

    putbuf(buffer, len);
    // Since we wrote data, set return value to bytes written.
    retVal = len;
  } else if(fd > 1){

	// A file descriptor has been used.
	struct file* file = flist_get_process_file(fd);
	if(file != NULL){
		retVal = file_write(file, buffer, len);
	}
	
  }

  return retVal;
}
Пример #19
0
void
exit(int error_code) {
	cprintf("\n==> exit\n");
    sys_exit(error_code);
    cprintf("BUG: exit failed.\n");
    while (1);
}
Пример #20
0
void _start(int argc, char *argv[], char *envp[])
{
    int res;

    res = main(argc, argv, envp);
    sys_exit(res);
}
Пример #21
0
void
start(void)
{
	int i;
	//exercise 4A
	//sys_priority (PRIORITY);
	//exercise 7
	queue_t frontground = initQueue();
	queue_t background = initQueue();
	sys_multilevelq (QUEUE);
	sys_yield();
	for (i = 0; i < RUNCOUNT; i++) {
		if (current->queue_name == q_foreground)
		{
			enQueue (frontground, pid_t current->p_pid);
		}
		else if (current->queue_name == q_background)
		{
			enQueue (background, pid_t current->p_pid);
		}
		else
		{
			console_printf(cursorpos, 0x100, "error on enqueue");
		}
		// Write characters to the console, yielding after each one.
		*cursorpos++ = PRINTCHAR;
		sys_yield();
	}

	// Yield forever.
	//while (1)
		//sys_yield();
	sys_exit(0);
}
Пример #22
0
static int
btn_check_reset(void)
{
    unsigned int i_button_value = !BTN_PRESSED;
#if defined (BOARD_GPIO_LED_POWER)
    int i_led;
#endif

#if defined (BOARD_GPIO_BTN_WPS)
    /* check WPS pressed */
    if (btn_count_wps > 0)
        return 0;
#endif
#if defined (BOARD_GPIO_BTN_WLTOG)
    /* check WLTOG pressed */
    if (btn_count_wlt > 0)
        return 0;
#endif
    if (cpu_gpio_get_pin(BOARD_GPIO_BTN_RESET, &i_button_value) < 0)
        return 0;

    if (i_button_value == BTN_PRESSED) {
        /* "RESET" pressed */
        btn_count_reset++;

#if defined (BOARD_GPIO_LED_POWER)
        /* flash power LED */
        i_led = get_state_led_pwr();
        if (btn_count_reset == 1)
            cpu_gpio_set_pin(BOARD_GPIO_LED_POWER, i_led);
        else if (btn_count_reset > BTN_RESET_WAIT_COUNT) {
            cpu_gpio_set_pin(BOARD_GPIO_LED_POWER, (btn_count_reset % 2) ? !i_led : i_led);
            dbg("You can release RESET button now!\n");
        }
#endif
    } else {
        /* "RESET" released */
        int press_count = btn_count_reset;
        btn_count_reset = 0;

        if (press_count > BTN_RESET_WAIT_COUNT) {
            /* pressed >= 5sec, reset! */
            wd_alarmtimer(0, 0);
#if defined (BOARD_GPIO_LED_POWER)
            cpu_gpio_set_pin(BOARD_GPIO_LED_POWER, LED_OFF);
#endif
            erase_nvram();
            erase_storage();
            sys_exit();
        } else if (press_count > 0) {
#if defined (BOARD_GPIO_LED_POWER)
            LED_CONTROL(BOARD_GPIO_LED_POWER, LED_ON);
#endif
        }
    }

    return (i_button_value != BTN_PRESSED) ? 0 : 1;
}
Пример #23
0
void
pmain(void)
{
	volatile int checker = 30; /* This variable checks for some common
				      stack errors. */
	pid_t p;
	int i, status;

	app_printf("About to start a new process...\n");

	p = sys_fork();
	if (p == 0) {
		// Check that the kernel correctly copied the parent's stack.
		check(checker, 30, "new child");
		checker = 30 + sys_getpid();

		// Yield several times to help test Exercise 3
		app_printf("Child process %d!\n", sys_getpid());
		for (i = 0; i < 20; i++)
			sys_yield();

		// Check that no one else corrupted our stack.
		check(checker, 30 + sys_getpid(), "end child");
		sys_exit(1000);

	} else if (p > 0) {
		// Check that the child didn't corrupt our stack.
		check(checker, 30, "main parent");

		app_printf("Main process %d!\n", sys_getpid());
		do {
			status = sys_wait(p);
		} while (status == WAIT_TRYAGAIN);
		app_printf("Child %d exited with status %d!\n", p, status);
		check(status, 1000, "sys_wait for child");

		// Check again that the child didn't corrupt our stack.
		check(checker, 30, "end parent");
		sys_exit(0);

	} else {
		app_printf("Error!\n");
		sys_exit(1);
	}
}
Пример #24
0
static void valid_address(void *addr)
{
  if(!is_user_vaddr(addr) || addr<0x8048000)
    sys_exit(-1);
/*  else if( pagedir_get_page( thread_current()->pagedir , addr) == NULL )
  {
      sys_exit(-1);
  }*/
}
Пример #25
0
void main ()
{
	video_mode = 8;
	fps_max = 60;
	wait(2);
	bmap_zbuffer ( bmap_createblack(2048,2048,32) );
	mouse_mode = 4;
	mouse_map = bmap_create ( "arrow_yellow.pcx" );
	vec_fill ( &screen_color, 128 );
	
	level_load ( "" );
	camera->pan = -40;
	camera->tilt = -30;
	evnCameraLocate ();
	vec_set ( &colCameraBG, vector(150,150,150) );
	camera->bg = pixel_for_vec ( &colCameraBG, 100, 8888 );
	
	ENTITY *ent = ent_create ( CUBE_MDL, nullvector, NULL );
	
	// Create style for the menues
	// CMMEMBER *myMenuStyle = cmstyle_create ( FONT *font, COLOR *colText, COLOR *colBack, COLOR *colOver )
	FONT *fntTTF = font_create("Arial#16");
	CMStyle *myMenuStyle01 = cmstyle_create ( fntTTF, vector(40,40,40), vector(250,250,250), vector(210,210,210) );
	FONT *fntBitmap = font_create("ackfont.pcx");
	CMStyle *myMenuStyle02 = cmstyle_create ( fntBitmap, vector(170,170,255), vector(30,20,0), vector(0,0,185) );
	
	// Create a compact menu panel
	// PANEL *cmenu_create ( char *chrMember, var pos_x, var pos_y, var size_x, var layer, var flags, CMStyle *style )
	PANEL *myMenu01 = cmenu_create ( "menu name.submenu=txtMain", 110, 20, 200, 1, SHOW, myMenuStyle01 );
	PANEL *myMenu02 = cmenu_create ( "debug & statics.submenu=txtCMDebug", 500, 20, 200, 1, SHOW, myMenuStyle01 );
	
	cmenu_modify ( myMenu02, 120, myMenuStyle02 );
	
	bmpSky = bmap_create ( "sky_fu_256+6.tga" );
	
	while ( !key_esc && !nExit )
	{
		str_setchr ( strString, 1, random(32)+32 );
		wait(1);
	}
	
	bmap_remove ( bmpSky );
	bmpSky = NULL;
	bmap_remove ( mouse_map );
	mouse_map = NULL;
	
	cmenu_remove ( myMenu01 );
	sys_free ( myMenuStyle01 ); 
	font_remove ( fntTTF );
	
	cmenu_remove ( myMenu02 );
	sys_free ( myMenuStyle02 );
	font_remove ( fntBitmap ); 
	
	sys_exit ( NULL );

}
Пример #26
0
int SYS_EXEC_handler(int32_t* esp)
{
    if(verify_variable_length(esp[1]) == false){
	sys_exit(-1);
    }
    char *command_line = esp[1];//(char*)*(esp + 1);
    int retVal = process_execute(command_line);	
    return retVal;
}
Пример #27
0
void trap_disk_handler(struct user_context *user_ctx)
{
	_enter();

	sys_exit(ERROR, user_ctx);

	_leave();
	return;
}
Пример #28
0
int
sys_penguin_exit(struct penguin_exit_args *args)
{
	kprintf("sys_exit\n");
	int error = sys_exit((void*)args);
	kprintf("sys_exit returns error %d\n", error);
	args->sysmsg_result64 = error;
	return 0;
}
Пример #29
0
static void
check(int actual_value, int expected_value, const char *type)
{
	if (actual_value != expected_value) {
		app_printf("Problem at %s (got %d, expected %d)!\n",
			   type, actual_value, expected_value);
		sys_exit(1);
	}
}
Пример #30
0
void* sys_memset(void * block, int c, size_t size)
{
	void* tmp;
	if ((tmp = memset(block,c,size)) == NULL) {
		log_err("malloc failed, size is: %d\n",size);
		sys_exit();
	}
	return tmp;
}