/*===========================================================================* * sched_inherit * *===========================================================================*/ PUBLIC int sched_inherit(endpoint_t scheduler_e, endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio, endpoint_t *newscheduler_e) { int rv; message m; assert(_ENDPOINT_P(scheduler_e) >= 0); assert(_ENDPOINT_P(schedulee_e) >= 0); assert(_ENDPOINT_P(parent_e) >= 0); assert(maxprio >= 0); assert(maxprio < NR_SCHED_QUEUES); assert(newscheduler_e); m.SCHEDULING_ENDPOINT = schedulee_e; m.SCHEDULING_PARENT = parent_e; m.SCHEDULING_MAXPRIO = (int) maxprio; /* Send the request to the scheduler */ if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) { return rv; } /* Store the process' scheduler. Note that this might not be the * scheduler we sent the SCHEDULING_INHERIT message to. That scheduler * might have forwarded the scheduling message on to another scheduler * before returning the message. */ *newscheduler_e = m.SCHEDULING_SCHEDULER; return (OK); }
/*===========================================================================* * sched_start * *===========================================================================*/ PUBLIC int sched_start(endpoint_t scheduler_e, endpoint_t schedulee_e, endpoint_t parent_e, int maxprio, int quantum, int cpu, endpoint_t *newscheduler_e) { int rv; message m; /* No scheduler given? We are done. */ if(scheduler_e == NONE) { return OK; } assert(_ENDPOINT_P(schedulee_e) >= 0); assert(_ENDPOINT_P(parent_e) >= 0); assert(maxprio >= 0); assert(maxprio < NR_SCHED_QUEUES); assert(quantum > 0); assert(newscheduler_e); /* The KERNEL must schedule this process. */ if(scheduler_e == KERNEL) { if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL, schedulee_e, maxprio, quantum, cpu)) != OK) { return rv; } *newscheduler_e = scheduler_e; return OK; } /* A user-space scheduler must schedule this process. */ m.SCHEDULING_ENDPOINT = schedulee_e; m.SCHEDULING_PARENT = parent_e; m.SCHEDULING_MAXPRIO = (int) maxprio; m.SCHEDULING_QUANTUM = (int) quantum; /* Send the request to the scheduler */ if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) { return rv; } /* Store the process' scheduler. Note that this might not be the * scheduler we sent the SCHEDULING_START message to. That scheduler * might have forwarded the scheduling message on to another scheduler * before returning the message. */ *newscheduler_e = m.SCHEDULING_SCHEDULER; return (OK); }
int test_gesture(short length, unsigned short tolerance) { int ipc_status; message msg; int receive; int validation = 1; sumOfX = 0; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (validation) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { validation = gesture_handler(length, tolerance); } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_packet(unsigned short cnt) { int i = 0; int ipc_status; message msg; int receive; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (i < cnt * 3) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { mouse_handler(); i++; } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_scan(void) { int r; unsigned long data = 0, irq_set; irq_set = kbd_subscribe_int(); int ipc_status; message msg; int i = 0; while (data != BREAK_ESC){ if ( r = driver_receive(ANY, &msg, &ipc_status) != 0 ) { printf("driver_receive failed with: %d", r); continue;} if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG &irq_set) { data = kbd_read_out(); if(1 << 7 & data) printf("Break: 0x%X \n", data); else printf("Make: 0x%X \n", data); }break; default: break; } } } kbd_unsubscribe_int(); return 0; }
/* ** Name: int dpeth_task(void) ** Function: Main entry for dp task */ PUBLIC int main(int argc, char **argv) { message m; int ipc_status; int rc; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); while (TRUE) { if ((rc = netdriver_receive(ANY, &m, &ipc_status)) != OK){ panic(RecvErrMsg, rc); } DEBUG(printf("eth: got message %d, ", m.m_type)); if (is_ipc_notify(ipc_status)) { switch(_ENDPOINT_P(m.m_source)) { case CLOCK: /* to be defined */ do_watchdog(&m); break; case HARDWARE: /* Interrupt from device */ handle_hw_intr(); break; case TTY_PROC_NR: /* Function key pressed */ do_dump(&m); break; default: /* Invalid message type */ panic(TypeErrMsg, m.m_type); break; } /* message processed, get another one */ continue; } switch (m.m_type) { case DL_WRITEV_S: /* Write message to device */ do_vwrite_s(&m); break; case DL_READV_S: /* Read message from device */ do_vread_s(&m); break; case DL_CONF: /* Initialize device */ do_init(&m); break; case DL_GETSTAT_S: /* Get device statistics */ do_getstat_s(&m); break; default: /* Invalid message type */ panic(TypeErrMsg, m.m_type); break; } } return OK; /* Never reached, but keeps compiler happy */ }
int timer_test_int(unsigned long time) { if (timer_subscribe_int()) { return 1; } int r, ipc_status; message msg; time_counter = 0; while (time_counter <= time * TIMER_DEFAULT_FREQ) { /* Get a request message. */ if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & BIT(TIMER0_HOOK_BIT)) { /////// /* subscribed interrupt */ timer_int_handler(); if(time_counter % TIMER_DEFAULT_FREQ == 0) { printf("Segundos decorridos: %d\n", time_counter / TIMER_DEFAULT_FREQ); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return timer_unsubscribe_int(); }
int kbd_test_scan(unsigned short ass) { int irq_set = kbd_subscribe_int(); int ipc_status; message msg; unsigned char result = 0; if (irq_set == ERROR) { printf("kbd_test_scan()::kernel call didn't return 0\n"); return ERROR; } while (result != KEY_ESC) { if (driver_receive(ANY, &msg, &ipc_status) != OK) { printf("kbd_test_scan()::driver_receive failed\n"); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { if (ass) { result = kbd_int_handler_asm(); } else { result = kbd_int_handler_C(); } if (result == KEY_ESC) { printf( "kbd_test_scan()::esc was pressed, press any key to continue\n"); } } break; } } } kbd_unsubscribe_int(); return 0; }
/*===========================================================================* * isokendpt_f * *===========================================================================*/ int isokendpt_f(char *file, int line, endpoint_t endpoint, int *proc, int fatal) { int failed = 0; endpoint_t ke; *proc = _ENDPOINT_P(endpoint); if (endpoint == NONE) { printf("VFS %s:%d: endpoint is NONE\n", file, line); failed = 1; } else if (*proc < 0 || *proc >= NR_PROCS) { printf("VFS %s:%d: proc (%d) from endpoint (%d) out of range\n", file, line, *proc, endpoint); failed = 1; } else if ((ke = fproc[*proc].fp_endpoint) != endpoint) { if(ke == NONE) { printf("VFS %s:%d: endpoint (%d) points to NONE slot (%d)\n", file, line, endpoint, *proc); assert(fproc[*proc].fp_pid == PID_FREE); } else { printf("VFS %s:%d: proc (%d) from endpoint (%d) doesn't match " "known endpoint (%d)\n", file, line, *proc, endpoint, fproc[*proc].fp_endpoint); assert(fproc[*proc].fp_pid != PID_FREE); } failed = 1; } if(failed && fatal) panic("isokendpt_f failed"); return(failed ? EDEADEPT : OK); }
/*===========================================================================* * pm_fork * *===========================================================================*/ void pm_fork(endpoint_t pproc, endpoint_t cproc, pid_t cpid) { /* Perform those aspects of the fork() system call that relate to files. * In particular, let the child inherit its parent's file descriptors. * The parent and child parameters tell who forked off whom. The file * system uses the same slot numbers as the kernel. Only PM makes this call. */ struct fproc *cp, *pp; int i, parentno, childno; mutex_t c_fp_lock; /* Check up-to-dateness of fproc. */ okendpt(pproc, &parentno); /* PM gives child endpoint, which implies process slot information. * Don't call isokendpt, because that will verify if the endpoint * number is correct in fproc, which it won't be. */ childno = _ENDPOINT_P(cproc); if (childno < 0 || childno >= NR_PROCS) panic("VFS: bogus child for forking: %d", cproc); if (fproc[childno].fp_pid != PID_FREE) panic("VFS: forking on top of in-use child: %d", childno); /* Copy the parent's fproc struct to the child. */ /* However, the mutex variables belong to a slot and must stay the same. */ c_fp_lock = fproc[childno].fp_lock; fproc[childno] = fproc[parentno]; fproc[childno].fp_lock = c_fp_lock; /* Increase the counters in the 'filp' table. */ cp = &fproc[childno]; pp = &fproc[parentno]; for (i = 0; i < OPEN_MAX; i++) if (cp->fp_filp[i] != NULL) cp->fp_filp[i]->filp_count++; /* Fill in new process and endpoint id. */ cp->fp_pid = cpid; cp->fp_endpoint = cproc; /* A forking process never has an outstanding grant, as it isn't blocking on * I/O. */ if (GRANT_VALID(pp->fp_grant)) { panic("VFS: fork: pp (endpoint %d) has grant %d\n", pp->fp_endpoint, pp->fp_grant); } if (GRANT_VALID(cp->fp_grant)) { panic("VFS: fork: cp (endpoint %d) has grant %d\n", cp->fp_endpoint, cp->fp_grant); } /* A child is not a process leader, not being revived, etc. */ cp->fp_flags = FP_NOFLAGS; /* Record the fact that both root and working dir have another user. */ if (cp->fp_rd) dup_vnode(cp->fp_rd); if (cp->fp_wd) dup_vnode(cp->fp_wd); }
int test_square(unsigned short x, unsigned short y, unsigned short size, unsigned long color) { vg_init(GRAPHIC_MODE); int ipc_status; message msg; int request; int irq_set; irq_set = subscribe_kbd(); while (scanCode != EXIT_MAKE_CODE) { request = driver_receive(ANY, &msg, &ipc_status); if (request != 0) { printf("driver_receive failed with: %d", request); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { kbd_handler(); } vg_draw_rectangle(x,y,size,size,color); break; default: break; } } else { } } unsubscribe_kbd(); vg_exit(); return 0; }
/*===========================================================================* * do_fslogin * *===========================================================================*/ PUBLIC int do_fslogin() { /* Login before mount request */ if ((unsigned long)mount_m_in.m1_p3 != who_e) { last_login_fs_e = who_e; return SUSPEND; } /* Login after a suspended mount */ else { /* Copy back original mount request message */ m_in = mount_m_in; /* Set up last login FS */ last_login_fs_e = who_e; /* Set up endpoint and call nr */ who_e = m_in.m_source; who_p = _ENDPOINT_P(who_e); call_nr = m_in.m_type; fp = &fproc[who_p]; /* pointer to proc table struct */ super_user = (fp->fp_effuid == SU_UID ? TRUE : FALSE); /* su? */ return do_mount(); } }
/*===========================================================================* * root_mtab * *===========================================================================*/ void root_mounts(void) { struct vmnt vmnt[NR_MNTS]; struct vmnt *vmp; struct mproc *rmp; int slot; if (getsysinfo(VFS_PROC_NR, SI_VMNT_TAB, vmnt, sizeof(vmnt)) != OK) return; for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { if (vmp->m_dev == NO_DEV) continue; if (vmp->m_fs_e == PFS_PROC_NR) continue; /* Skip (special case) */ slot = _ENDPOINT_P(vmp->m_fs_e); if (slot < 0 || slot >= NR_PROCS) continue; rmp = &mproc[slot]; buf_printf("%s on %s type %s (%s)\n", vmp->m_mount_dev, vmp->m_mount_path, rmp->mp_name, (vmp->m_flags & VMNT_READONLY) ? "ro" : "rw"); } }
int test_date() { int ipc_status; message msg; unsigned int i=0; unsigned rtc_hook_id; rtc_subscribe_int(&rtc_hook_id); while(1) { if (driver_receive(ANY, &msg, &ipc_status) != 0) { if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & (1 << RTC_HOOK)) { /* subscribed interrupt */ i++; } break; default: break; } } } } rtc_unsubscribe_int(rtc_hook_id); sys_outb(RTC_ADDR_REG, RTC_CTRL_REG_B); /// }
/* * Generate a wchan message text for the cases that the process is blocked on * IPC with another process, of which the endpoint is given as 'endpt' here. * The name of the other process is to be stored in 'wmesg', which is a buffer * of size 'wmsz'. The result should be null terminated. If 'ipc' is set, the * process is blocked on a direct IPC call, in which case the name of the other * process is enclosed in parentheses. If 'ipc' is not set, the call is made * indirectly through VFS, and the name of the other process should not be * enclosed in parentheses. If no name can be obtained, we use the endpoint of * the other process instead. */ static void fill_wmesg(char * wmesg, size_t wmsz, endpoint_t endpt, int ipc) { const char *name; int mslot; switch (endpt) { case ANY: name = "any"; break; case SELF: name = "self"; break; case NONE: name = "none"; break; default: mslot = _ENDPOINT_P(endpt); if (mslot >= -NR_TASKS && mslot < NR_PROCS && (mslot < 0 || (mproc_tab[mslot].mp_flags & IN_USE))) name = proc_tab[NR_TASKS + mslot].p_name; else name = NULL; } if (name != NULL) snprintf(wmesg, wmsz, "%s%s%s", ipc ? "(" : "", name, ipc ? ")" : ""); else snprintf(wmesg, wmsz, "%s%d%s", ipc ? "(" : "", endpt, ipc ? ")" : ""); }
int kbd_test_scan_C(void) { int r; unsigned long data = 0, irq_set; int ipc_status; message msg; irq_set = kbd_subscribe_int(); while (data != ESC_CODE){ if ( r = driver_receive(ANY, &msg, &ipc_status) != 0 ) { printf("driver_receive failed with: %d", r); continue;} if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG &BIT(irq_set)) { data = kbd_read_buff(); if(BIT(7) & data) printf("Break code: 0x%2X", data); else printf("Make code: 0x%2X", data); printf("\n ----///---- \n"); }break; default: break; } } } kbd_unsubscribe_int(); return 0; }
PRIVATE void dispatcher_thread(void *unused) { /* * Gets all messages and dispatches them. * * NOTE: this thread runs only when no other ddekit is * ready. So please take care that youre threads * leave some time for the others! */ message m; int r; int i; _ddekit_thread_set_myprio(0); for( ; ; ) { /* Trigger a timer interrupt at each loop iteration */ _ddekit_timer_update(); /* Wait for messages */ if ((r = sef_receive(ANY, &m)) != 0) { ddekit_panic("ddekit", "sef_receive failed", r); } _ddekit_timer_interrupt(); _ddekit_thread_wakeup_sleeping(); if (is_notify(m.m_type)) { switch (_ENDPOINT_P(m.m_source)) { case HARDWARE: for (i =0 ; i < 32 ; i++) { if(m.NOTIFY_ARG & (1 << i)) { _ddekit_interrupt_trigger(i); } } break; case CLOCK: _ddekit_timer_pending = 0; break; default: ddekit_thread_schedule(); } } else { /* * I don't know how to handle this msg, * but maybe we have a msg queue which can * handle this msg. */ ddekit_minix_queue_msg(&m); } } }
/*===========================================================================* * init_scheduling * *===========================================================================*/ PUBLIC void sched_init(void) { struct mproc *trmp; endpoint_t parent_e; int proc_nr, s; for (proc_nr=0, trmp=mproc; proc_nr < NR_PROCS; proc_nr++, trmp++) { /* Don't take over system processes. When the system starts, * init is blocked on RTS_NO_QUANTUM until PM assigns a * scheduler, from which other. Given that all other user * processes are forked from init and system processes are * managed by RS, there should be no other process that needs * to be assigned a scheduler here */ if (trmp->mp_flags & IN_USE && !(trmp->mp_flags & PRIV_PROC)) { assert(_ENDPOINT_P(trmp->mp_endpoint) == INIT_PROC_NR); parent_e = mproc[trmp->mp_parent].mp_endpoint; assert(parent_e == trmp->mp_endpoint); s = sched_start(SCHED_PROC_NR, /* scheduler_e */ trmp->mp_endpoint, /* schedulee_e */ parent_e, /* parent_e */ USER_Q, /* maxprio */ USER_QUANTUM, /* quantum */ -1, /* don't change cpu */ &trmp->mp_scheduler); /* *newsched_e */ if (s != OK) { printf("PM: SCHED denied taking over scheduling of %s: %d\n", trmp->mp_name, s); } } } }
/*===========================================================================* * sef_cb_init_restart * *===========================================================================*/ static int sef_cb_init_restart(int type, sef_init_info_t *info) { /* Restart the reincarnation server. */ int r; struct rproc *old_rs_rp, *new_rs_rp; assert(info->endpoint == RS_PROC_NR); /* Perform default state transfer first. */ r = SEF_CB_INIT_RESTART_STATEFUL(type, info); if(r != OK) { printf("SEF_CB_INIT_RESTART_STATEFUL failed: %d\n", r); return r; } /* New RS takes over. */ old_rs_rp = rproc_ptr[_ENDPOINT_P(RS_PROC_NR)]; new_rs_rp = rproc_ptr[_ENDPOINT_P(info->old_endpoint)]; if(rs_verbose) printf("RS: %s is the new RS after restart\n", srv_to_string(new_rs_rp)); /* If an update was in progress, end it. */ if(SRV_IS_UPDATING(old_rs_rp)) { end_update(ERESTART, RS_REPLY); } /* Update the service into the replica. */ r = update_service(&old_rs_rp, &new_rs_rp, RS_DONTSWAP, 0); if(r != OK) { printf("update_service failed: %d\n", r); return r; } /* Initialize the new RS instance. */ r = init_service(new_rs_rp, SEF_INIT_RESTART, 0); if(r != OK) { printf("init_service failed: %d\n", r); return r; } /* Reschedule a synchronous alarm for the next period. */ if (OK != (r=sys_setalarm(RS_DELTA_T, 0))) panic("couldn't set alarm: %d", r); return OK; }
int start() { unsigned short character = 0x00; int ipc_status; message msg; int irq_set_kb = kb_subscribe_int(); int irq_set_timer = timer_subscribe_int(); int irq_set_mouse = mouse_subscribe_int(); int r; unsigned char packet[3]; unsigned short counter = 0; space_invaders_font = font_init("spaceinvader_font_transparent.bmp"); srand(1); options_load(); mouse_init(); init_state(); highscore_load(); vg_init(VBE_VIDEO_MODE); while (1) { //TODO change condition /* Get a request message. */ if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & irq_set_kb) { /* keyboard interrupt */ character = kb_int_handler(); if (character != KB_2BYTE_SCODE) kb_event_handler(character); } if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */ mouse_int_handler(counter, packet); if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3))) counter++; if(counter == 3){ counter = 0; mouse_event_handler(packet); } } if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return 0; }
int kbd_test_timed_scan(unsigned short n) { int ipc_status, r, exit = 0, max, counter = 0, flag = 0; unsigned long irq1, irq2, data; message msg; irq2 = subscribe_int(TIMER0_IRQ, IRQ_REENABLE, &timer0_id); irq1 = subscribe_int(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id); if (irq1 == -1 || irq2 == -1) return -1; // check if subscribe_int failed max = n*60; do { r = driver_receive(ANY, &msg, &ipc_status); if (r != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq1) { counter = 0; data = keyboard_handler(0); flag = print_scancodes(data, flag); if (data == ESC) { printf("Done\n"); exit = 1; } } if (msg.NOTIFY_ARG & irq2) { counter++; if (counter >= max) { printf("Done\n"); exit = 1; } } break; default: break; } } } while (exit == 0); unsubscribe_int(&kb_id); unsubscribe_int(&timer0_id); return 0; }
int main_menu() { continue_condition = true; fade_condition = false; function_to_call = NULL; darken = 127; int failure = 0; initialize_main_menu_buttons(); int ipc_status; message msg; int r; char * display_name = (char*)malloc(sizeof(char) * strlen("Player name: ")+MAX_PLAYER_NAME_LENGTH); strcpy(display_name, "Player name: "); display_name = strcat(display_name, get_program_playername()); if(!failure){ do{ /* Get a request message. */ if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & get_kbd_irq_set()){ /* subscribed kbd interrupt */ kbd_int_handler(); } if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */ if(rtc_ih()) failure = 1; getDateString(get_date_str_ptr()); } if(msg.NOTIFY_ARG & get_timer_irq_set()){ timer_int_handler(); main_menu_render(); } if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */ mouse_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } if(mouse_is_updated()) { assign_mouse(get_previous_mouse(), get_mouse()); assign_mouse(get_mouse(), get_mouse_state()); main_menu_mouse_event(get_previous_mouse(), get_mouse()); move_cursor(get_cursor(), get_mouse()->coords); } } while(continue_condition); } return failure; }
int test_line(unsigned short xi, unsigned short yi, unsigned short xf, unsigned short yf, unsigned long color) { char* video_mem = NULL; int failure =0; if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL) { printf("test_line(): vg_init() failed"); return 1; } draw_line(video_mem,xi,yi, xf,yf,color); int kbd_irq_set = 0; if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts printf("test_line(): kbd_subscribe_int() failed \n"); failure = 1; } int ipc_status; message msg; int r; if(!failure){ do{ /* Get a request message. */ if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & kbd_irq_set) { /* subscribed kbd interrupt */ if(kbd_int_handler()) failure = 1; } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } while(get_scancode() != ESC_BREAK && !failure); } if(kbd_unsubscribe_int()){//unsubscribe interrupts printf("test_square(): kbd_unsubscribe_int() failed\n"); failure = 1; } printf("Done\n"); if(vg_exit()){ printf("test_line(): vg_exit() failed"); return 1; } return failure; }
/*===========================================================================* * main *===========================================================================*/ PUBLIC void main() { int r, caller, proc_nr, s; message mess; dprint("sb16_dsp.c: main()\n"); /* Get a DMA buffer. */ init_buffer(); while(TRUE) { /* Wait for an incoming message */ receive(ANY, &mess); caller = mess.m_source; proc_nr = mess.IO_ENDPT; if (is_notify(mess.m_type)) { switch (_ENDPOINT_P(mess.m_source)) { case HARDWARE: dsp_hardware_msg(); continue; /* don't reply */ case SYSTEM: continue; /* don't reply */ default: r = EINVAL; } /* dont with this message */ goto send_reply; } /* Now carry out the work. */ switch(mess.m_type) { case DEV_OPEN: r = dsp_open(); break; case DEV_CLOSE: r = dsp_close(); break; #ifdef DEV_IOCTL case DEV_IOCTL: r = dsp_ioctl(&mess); break; #endif #ifdef DEV_READ case DEV_READ: r = EINVAL; break; /* Not yet implemented */ case DEV_WRITE: dsp_write(&mess); continue; /* don't reply */ #endif case DEV_STATUS: dsp_status(&mess); continue; /* don't reply */ default: r = EINVAL; } send_reply: /* Finally, prepare and send the reply message. */ reply(TASK_REPLY, caller, proc_nr, r); } }
/*===========================================================================* * sched_isemtyendpt * *===========================================================================*/ int sched_isemtyendpt(int endpoint, int *proc) { *proc = _ENDPOINT_P(endpoint); if (*proc < 0) return (EBADEPT); /* Don't schedule tasks */ if(*proc >= NR_PROCS) return (EINVAL); if(schedproc[*proc].flags & IN_USE) return (EDEADEPT); return (OK); }
/*===========================================================================* * get_work * *===========================================================================*/ static int get_work(void) { /* Normally wait for new input. However, if 'reviving' is nonzero, a * suspended process must be awakened. Return TRUE if there is a message to * process (usually newly received, but possibly a resumed request), or FALSE * if a thread for other activities has been spawned instead. */ int r, proc_p; register struct fproc *rp; if (reviving != 0) { /* Find a suspended process. */ for (rp = &fproc[0]; rp < &fproc[NR_PROCS]; rp++) if (rp->fp_pid != PID_FREE && (rp->fp_flags & FP_REVIVED)) return unblock(rp); /* So main loop can process job */ panic("VFS: get_work couldn't revive anyone"); } for(;;) { /* Normal case. No one to revive. Get a useful request. */ if ((r = sef_receive(ANY, &m_in)) != OK) { panic("VFS: sef_receive error: %d", r); } proc_p = _ENDPOINT_P(m_in.m_source); if (proc_p < 0 || proc_p >= NR_PROCS) fp = NULL; else fp = &fproc[proc_p]; /* Negative who_p is never used to access the fproc array. Negative * numbers (kernel tasks) are treated in a special way. */ if (fp && fp->fp_endpoint == NONE) { printf("VFS: ignoring request from %d: NONE endpoint %d (%d)\n", m_in.m_source, who_p, m_in.m_type); continue; } /* Internal consistency check; our mental image of process numbers and * endpoints must match with how the rest of the system thinks of them. */ if (fp && fp->fp_endpoint != who_e) { if (fproc[who_p].fp_endpoint == NONE) printf("slot unknown even\n"); panic("VFS: receive endpoint inconsistent (source %d, who_p " "%d, stored ep %d, who_e %d).\n", m_in.m_source, who_p, fproc[who_p].fp_endpoint, who_e); } return TRUE; } /* NOTREACHED */ }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char *argv[]) { int r; int ipc_status; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); while (TRUE) { if ((r = netdriver_receive(ANY, &m, &ipc_status)) != OK) panic("netdriver_receive failed: %d", r); if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(m.m_source)) { case CLOCK: /* * Under MINIX, synchronous alarms are used * instead of watchdog functions. * The approach is very different: MINIX VMD * timeouts are handled within the kernel * (the watchdog is executed by CLOCK), and * notify() the driver in some cases. MINIX * timeouts result in a SYN_ALARM message to * the driver and thus are handled where they * should be handled. Locally, watchdog * functions are used again. */ rl_watchdog_f(NULL); break; case HARDWARE: do_hard_int(); if (int_event_check) { check_int_events(); } break ; default: panic("illegal notify from: %d", m.m_type); } /* done, get nwe message */ continue; } switch (m.m_type) { case DL_WRITEV_S: rl_writev_s(&m, FALSE); break; case DL_READV_S: rl_readv_s(&m, FALSE); break; case DL_CONF: rl_init(&m); break; case DL_GETSTAT_S: rl_getstat_s(&m); break; default: panic("illegal message: %d", m.m_type); } } }
/*===========================================================================* * vm_isokendpt * *===========================================================================*/ int vm_isokendpt(endpoint_t endpoint, int *procn) { *procn = _ENDPOINT_P(endpoint); if(*procn < 0 || *procn >= NR_PROCS) return EINVAL; if(*procn >= 0 && endpoint != vmproc[*procn].vm_endpoint) return EDEADEPT; if(*procn >= 0 && !(vmproc[*procn].vm_flags & VMF_INUSE)) return EDEADEPT; return OK; }
/*===========================================================================* * main *===========================================================================*/ PUBLIC int main(int argc, char *argv[]) { int r; endpoint_t caller; int proc_nr; message mess; int ipc_status; /* SEF local startup. */ sef_local_startup(); while(TRUE) { /* Wait for an incoming message */ driver_receive(ANY, &mess, &ipc_status); caller = mess.m_source; proc_nr = mess.IO_ENDPT; if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(mess.m_source)) { case HARDWARE: dsp_hardware_msg(); continue; /* don't reply */ default: r = EINVAL; } /* dont with this message */ goto send_reply; } /* Now carry out the work. */ switch(mess.m_type) { case DEV_OPEN: r = dsp_open(); break; case DEV_CLOSE: r = dsp_close(); break; #ifdef DEV_IOCTL case DEV_IOCTL: r = dsp_ioctl(&mess); break; #endif #ifdef DEV_READ case DEV_READ: r = EINVAL; break; /* Not yet implemented */ case DEV_WRITE: dsp_write(&mess); continue; /* don't reply */ #endif case DEV_STATUS: dsp_status(&mess); continue; /* don't reply */ default: r = EINVAL; } send_reply: /* Finally, prepare and send the reply message. */ reply(TASK_REPLY, caller, proc_nr, r); } }
/*===========================================================================* * sched_stop * *===========================================================================*/ int sched_stop(endpoint_t scheduler_e, endpoint_t schedulee_e) { int rv; message m; /* If the kernel is the scheduler, it will implicitly stop scheduling * once another process takes over or the process terminates */ if (scheduler_e == KERNEL || scheduler_e == NONE) return(OK); /* User-scheduled, perform the call */ assert(_ENDPOINT_P(scheduler_e) >= 0); assert(_ENDPOINT_P(schedulee_e) >= 0); m.SCHEDULING_ENDPOINT = schedulee_e; if ((rv = _taskcall(scheduler_e, SCHEDULING_STOP, &m))) { return rv; } return (OK); }