本文整理汇总了C++中cons_getc函数的典型用法代码示例。如果您正苦于以下问题:C++ cons_getc函数的具体用法?C++ cons_getc怎么用?C++ cons_getc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cons_getc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trap_dispatch
/* trap_dispatch - dispatch based on what type of trap occurred */
static void trap_dispatch(struct trapframe *tf) {
char c;
switch (tf->tf_trapno) {
case IRQ_OFFSET + IRQ_TIMER:
/* LAB1 YOUR CODE : STEP 3 */
/* handle the timer interrupt */
/* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
* (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
* (3) Too Simple? Yes, I think so!
*/
if(++ticks % TICK_NUM == 0) {
print_ticks();
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
cprintf("serial [%03d] %c\n", c, c);
break;
case IRQ_OFFSET + IRQ_KBD:
c = cons_getc();
cprintf("kbd [%03d] %c\n", c, c);
break;
//LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
case T_SWITCH_TOU:
if(tf->tf_cs != USER_CS) {
user_stack = *tf;
user_stack.tf_cs = USER_CS;
user_stack.tf_ds = USER_DS;
user_stack.tf_ss = USER_DS;
user_stack.tf_es = USER_DS;
user_stack.tf_esp = (uint32_t)tf + sizeof(struct trapframe) - 8;
user_stack.tf_eflags |= FL_IOPL_MASK;
*((uint32_t *)tf - 1) = (uint32_t)&user_stack;
}
break;
case T_SWITCH_TOK:
if(tf->tf_cs != KERNEL_CS) {
tf->tf_cs = KERNEL_CS;
tf->tf_ds = KERNEL_DS;
tf->tf_es = KERNEL_DS;
tf->tf_eflags &= ~FL_IOPL_MASK;
struct trapframe* k = (struct trapframe*)(tf->tf_esp - (sizeof(struct trapframe) - 8));
memmove(k, tf, sizeof(struct trapframe) -8);
*((uint32_t *)tf - 1) = (uint32_t)k;
}
break;
case IRQ_OFFSET + IRQ_IDE1:
case IRQ_OFFSET + IRQ_IDE2:
/* do nothing */
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例2: trap_dispatch
static void
trap_dispatch(struct trapframe *tf) {
char c;
int ret;
switch (tf->tf_trapno) {
case T_PGFLT: //page fault
if ((ret = pgfault_handler(tf)) != 0) {
print_trapframe(tf);
panic("handle pgfault failed. %e\n", ret);
}
break;
case IRQ_OFFSET + IRQ_TIMER:
#if 0
LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages,
then you can add code here.
#endif
/* LAB1 YOUR CODE : STEP 3 */
/* handle the timer interrupt */
/* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
* (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
* (3) Too Simple? Yes, I think so!
*/
ticks ++;
if (ticks % TICK_NUM == 0) {
print_ticks();
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
cprintf("serial [%03d] %c\n", c, c);
break;
case IRQ_OFFSET + IRQ_KBD:
c = cons_getc();
cprintf("kbd [%03d] %c\n", c, c);
break;
//LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
case T_SWITCH_TOU:
case T_SWITCH_TOK:
panic("T_SWITCH_** ??\n");
break;
case IRQ_OFFSET + IRQ_IDE1:
case IRQ_OFFSET + IRQ_IDE2:
/* do nothing */
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例3: trap_dispatch
/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
char c;
switch (tf->tf_trapno) {
case IRQ_OFFSET + IRQ_TIMER:
/* LAB1 2012012139 : STEP 3 */
/* handle the timer interrupt */
/* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
* (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
* (3) Too Simple? Yes, I think so!
*/
++ticks;
if (ticks == TICK_NUM) {
print_ticks();
ticks = 0;
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
cprintf("serial [%03d] %c\n", c, c);
break;
case IRQ_OFFSET + IRQ_KBD:
c = cons_getc();
cprintf("kbd [%03d] %c\n", c, c);
break;
//LAB1 CHALLENGE 1 : 2012012139 you should modify below codes.
case T_SWITCH_TOU:
tf->tf_cs = USER_CS;
tf->tf_ds = USER_DS;
tf->tf_es = USER_DS;
tf->tf_ss = USER_DS;
// 改变IO输出所需要的权限,使得用户可以写
tf->tf_eflags |= 0x3000;
break;
case T_SWITCH_TOK:
tf->tf_cs = KERNEL_CS;
tf->tf_ds = KERNEL_DS;
tf->tf_es = KERNEL_DS;
// tf->tf_ss = KERNEL_DS;
// panic("T_SWITCH_** ??\n");
break;
case IRQ_OFFSET + IRQ_IDE1:
case IRQ_OFFSET + IRQ_IDE2:
/* do nothing */
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例4: getchar
/* getchar - reads a single non-zero character from stdin */
int
getchar(void) {
int c;
while ((c = cons_getc()) == 0)
/* do nothing */;
return c;
}
示例5: serial_int_handler
static int serial_int_handler(int irq, void * data)
{
extern void dev_stdin_write(char c);
char c = cons_getc();
dev_stdin_write(c);
return 0;
}
示例6: trap_dispatch
/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
char c;
switch (tf->tf_trapno) {
case T_DEBUG:
case T_BRKPT:
debug_monitor(tf);
break;
case IRQ_OFFSET + IRQ_TIMER:
ticks ++;
if (ticks % TICK_NUM == 0) {
cprintf("%d ticks\n",TICK_NUM);
}
break;
case IRQ_OFFSET + IRQ_COM1:
case IRQ_OFFSET + IRQ_KBD:
if ((c = cons_getc()) == 13) {
debug_monitor(tf);
}
else {
cprintf("%s [%03d] %c\n",
(tf->tf_trapno != IRQ_OFFSET + IRQ_KBD) ? "serial" : "kbd", c, c);
}
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例7: cons_io
// Synchronize the root process's console special files
// with the actual console I/O device.
bool
cons_io(void)
{
int num_io = 0;
// Get output file
fileinode *fi = &files->fi[FILEINO_CONSOUT];
int c;
// spinlock_acquire(&cons_lock);
while(cons_out_pos < fi->size) {
c = ((char*)FILEDATA(FILEINO_CONSOUT))[cons_out_pos];
cons_putc(c);
num_io++;
cons_out_pos++;
}
// spinlock_release(&cons_lock);
// Input file
fi = &files->fi[FILEINO_CONSIN];
// Read from console
while(fi->size <= FILE_MAXSIZE && (c = cons_getc())) {
// And appened to CONSIN
((char*)FILEDATA(FILEINO_CONSIN))[fi->size++] = c;
num_io++;
}
return num_io;
}
示例8: irq_handler
void irq_handler(){
uint32_t pending = inw(VIC_VBASE+INTERRUPT_STATUS);
uint32_t irq = 0;
while(pending > 0){
irq = inw(VIC_VBASE+INTERRUPT_NUMBER);
if(actions[irq].handler){
(*actions[irq].handler)(irq, actions[irq].opaque);
}else{
pic_disable(irq);
}
pending = inw(VIC_VBASE+INTERRUPT_STATUS);
}
#if 0
if(status & (1<<TIMER0_IRQ)){
//kprintf("@");
ticks++;
//assert(pls_read(current) != NULL);
run_timer_list();
clock_clear();
}
if( status & (1<<UART_IRQ) ){
//if ((c = cons_getc()) == 13) {
// debug_monitor(tf);
//}
//else {
extern void dev_stdin_write(char c);
char c = cons_getc();
dev_stdin_write(c);
//}
//kprintf("#");
serial_clear();
}
#endif
}
示例9: trap_dispatch
/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
char c;
switch (tf->tf_trapno) {
case IRQ_OFFSET + IRQ_TIMER:
ticks ++;
if (ticks % TICK_NUM == 0) {
print_ticks();
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
cprintf("serial [%03d] %c\n", c, c);
break;
case IRQ_OFFSET + IRQ_KBD:
c = cons_getc();
cprintf("kbd [%03d] %c\n", c, c);
break;
case T_SWITCH_TOU:
if (tf->tf_cs != USER_CS) {
tf->tf_cs = USER_CS;
tf->tf_ds = tf->tf_es = USER_DS;
tf->tf_ss = USER_DS;
// set eflags, make sure ucore can use io under user mode.
// if CPL > IOPL, then cpu will generate a general protection.
tf->tf_rflags |= FL_IOPL_MASK;
}
break;
case T_SWITCH_TOK:
if (tf->tf_cs != KERNEL_CS) {
tf->tf_cs = KERNEL_CS;
tf->tf_ds = tf->tf_es = KERNEL_DS;
tf->tf_ss = KERNEL_DS;
tf->tf_rflags &= ~FL_IOPL_MASK;
}
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例10: trap_dispatch
static void
trap_dispatch(struct trapframe *tf) {
char c;
int ret;
switch (tf->tf_trapno) {
case T_DEBUG:
case T_BRKPT:
debug_monitor(tf);
break;
case T_PGFLT:
if ((ret = pgfault_handler(tf)) != 0) {
print_trapframe(tf);
if (current == NULL) {
panic("handle pgfault failed. %e\n", ret);
}
else {
if (trap_in_kernel(tf)) {
panic("handle pgfault failed in kernel mode. %e\n", ret);
}
cprintf("killed by kernel.\n");
do_exit(-E_KILLED);
}
}
break;
case T_SYSCALL:
syscall();
break;
case IRQ_OFFSET + IRQ_TIMER:
ticks ++;
assert(current != NULL);
run_timer_list();
break;
case IRQ_OFFSET + IRQ_COM1:
case IRQ_OFFSET + IRQ_KBD:
if ((c = cons_getc()) == 13) {
debug_monitor(tf);
}
else {
cprintf("%s [%03d] %c\n",
(tf->tf_trapno != IRQ_OFFSET + IRQ_KBD) ? "serial" : "kbd", c, c);
}
break;
case IRQ_OFFSET + IRQ_IDE1:
case IRQ_OFFSET + IRQ_IDE2:
/* do nothing */
break;
default:
print_trapframe(tf);
if (current != NULL) {
cprintf("unhandled trap.\n");
do_exit(-E_KILLED);
}
panic("unexpected trap in kernel.\n");
}
}
示例11: trap_dispatch
/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
char c;
switch (tf->tf_trapno) {
case IRQ_OFFSET + IRQ_TIMER:
/* LAB1 YOUR CODE : STEP 3 */
/* handle the timer interrupt */
/* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
* (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
* (3) Too Simple? Yes, I think so!
*/
ticks++;
if (ticks % TICK_NUM == 0)
{
print_ticks();
}
break;
case IRQ_OFFSET + IRQ_COM1:
c = cons_getc();
cprintf("serial [%03d] %c\n", c, c);
break;
case IRQ_OFFSET + IRQ_KBD:
c = cons_getc();
cprintf("kbd [%03d] %c\n", c, c);
break;
//LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
case T_SWITCH_TOU:
case T_SWITCH_TOK:
panic("T_SWITCH_** ??\n");
break;
case IRQ_OFFSET + IRQ_IDE1:
case IRQ_OFFSET + IRQ_IDE2:
/* do nothing */
break;
default:
// in kernel, it must be a mistake
if ((tf->tf_cs & 3) == 0) {
print_trapframe(tf);
panic("unexpected trap in kernel.\n");
}
}
}
示例12: serial_int_handler
void serial_int_handler(void *opaque)
{
unsigned char id = inb(COM1+COM_IIR);
if(id & 0x01)
return ;
//int c = serial_proc_data();
int c = cons_getc(c);
extern void dev_stdin_write(char c);
dev_stdin_write(c);
}
示例13: arch_init
void arch_init()
{
pci_init();
#ifdef __CONFIG_ENABLE_MPTABLES__
mptables_parse();
ioapic_init(); // MUST BE AFTER PCI/ISA INIT!
// TODO: move these back to regular init. requires fixing the
// __CONFIG_NETWORKING__ inits to not need multiple cores running.
#endif
// this returns when all other cores are done and ready to receive IPIs
#ifdef __CONFIG_SINGLE_CORE__
smp_percpu_init();
#else
smp_boot();
#endif
proc_init();
/* EXPERIMENTAL NETWORK FUNCTIONALITY
* To enable, define __CONFIG_NETWORKING__ in your Makelocal
* If enabled, will load the rl8168 driver (if device exists)
* and will a boot into userland matrix, so remote syscalls can be performed.
* If in simulation, will do some debugging information with the ne2k device
*
* Note: If you use this, you should also define the mac address of the
* teathered machine via USER_MAC_ADDRESS in Makelocal.
*
* Additionally, you should have a look at the syscall server in the tools directory
*/
#ifdef __CONFIG_NETWORKING__
#ifdef __CONFIG_SINGLE_CORE__
warn("You currently can't have networking if you boot into single core mode!!\n");
#else
rl8168_init();
ne2k_init();
e1000_init();
#endif // __CONFIG_SINGLE_CORE__
#endif // __CONFIG_NETWORKING__
perfmon_init();
#ifdef __CONFIG_MONITOR_ON_INT__
/* Handler to read a char from the interrupt source and call the monitor.
* Need to read the character so the device will send another interrupt.
* Note this will read from both the serial and the keyboard, and throw away
* the result. We condition, since we don't want to trigger on a keyboard
* up interrupt */
void mon_int(struct trapframe *tf, void *data)
{
// Enable interrupts here so that we can receive
// other interrupts (e.g. from the NIC)
enable_irq();
if (cons_getc())
monitor(0);
}
示例14: sys_cgetc
// Read a character from the system console.
// Returns the character.
static int
sys_cgetc(void)
{
int c;
// The cons_getc() primitive doesn't wait for a character,
// but the sys_cgetc() system call does.
while ((c = cons_getc()) == 0)
/* do nothing */;
return c;
}
示例15: sys_cgetc
// Read a character from the system console.
// Returns the character.
static int
sys_cgetc(void)
{
int c;
/* The cons_getc() primitive doesn't wait for a character, But we do.
* TODO: Make kernel interruptable later
* Now just a makeshift, without kernel being interruptable, Ether
* device refuses to function properly.
*/
while ((c = cons_getc()) == 0);
/* { */
/* assert(curenv->env_status == ENV_RUNNING); */
/* spin_lock(&curenv->env_lock); */
/* curenv->env_status = ENV_RUNNABLE; */
/* spin_unlock(&curenv->env_lock); */
/* sched_yield();/\* This enables daemons to get CPU cycles when */
/* * sh is running. */
/* *\/ */
/* } */
return c;
}