1/** 2 * \file 3 * \brief Arch-specific system calls implementation. 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <kernel.h> 16#include <arch/x86/syscall.h> 17#include <barrelfish_kpi/syscalls.h> 18#include <arch/x86/start_aps.h> 19#include <arch/x86/timing.h> 20#include <x86.h> 21 22/** 23 * \brief TSC value at beginning of the last timeslice. 24 */ 25uint64_t tsc_lasttime = 0; 26 27struct sysret sys_io(struct capability *to, enum io_cmd cmd, 28 uint16_t port, uint32_t data) 29{ 30 // Check whether IO operation is allowed 31 if(port < to->u.io.start || port > to->u.io.end) { 32 printk(LOG_ERR, 33 "handle_io: illegal operation: port %" PRIx16 " out of range\n", port); 34 return SYSRET(SYS_ERR_IO_PORT_INVALID); 35 } 36 37 debug(SUBSYS_IO, "handle_io: IO cmd 0x%x to port 0x%" PRIx16 "\n", cmd, port); 38 switch(cmd) { 39 case IOCmd_Outb: 40 outb(port, data); 41 break; 42 43 case IOCmd_Outw: 44 outw(port, data); 45 break; 46 47 case IOCmd_Outd: 48 outd(port, data); 49 break; 50 51 case IOCmd_Inb: 52 data = inb(port); 53 break; 54 55 case IOCmd_Inw: 56 data = inw(port); 57 break; 58 59 case IOCmd_Ind: 60 data = ind(port); 61 break; 62 63 default: 64 panic("invalid IO command"); 65 } 66 67 return (struct sysret){ .error = SYS_ERR_OK, .value = data }; 68} 69 70struct sysret sys_monitor_handle_sync_timer(uint64_t synctime) 71{ 72 if(rdtsc() > synctime) { 73 return SYSRET(SYS_ERR_SYNC_MISS); 74 } 75 76 while(rdtsc() < synctime); 77 timing_apic_timer_set_ms(config_timeslice); 78 tsc_lasttime = rdtsc(); 79 scheduler_reset_time(); 80 81 return SYSRET(SYS_ERR_OK); 82} 83