资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
(VR虚拟现实)切换虚拟终端切换虚拟终端概述linux使用虚拟终端,这些虚拟终端对应/dev/tty1/dev/tty8,它们由系统初始化时打开。这个过程也在键盘的中断服务程序中完成。用户用ALT+1.8或ALT+箭头来切换终端。每个虚拟终端对应一个tty_struct和一个termios结构。Termios结构存储输入输出及控制模式,一些底层参数。Tty_struct和终端的关系如同task_struct和进程的关系。一个tty被打开,就对应一个tty_stract,对终端的一切处理都围绕tty_strct进行。Termios也被tty_struct的一个指针指向。当然,tty_struct和termios结构相对独立,tty被完全关闭时,tty_struct也就不在存在,而termios依然存在。另:1与虚拟终端相对的是实终端。它对应/dev/tty0或/dev/console二者设备号均为4,0(2035)系统初始时tty的初始化分早期和晚期。早期初始化支持实终端,晚期初始化支持虚拟终端。此时/dev/tty0或/dev/console对应当前终端。2伪终端正如其名,与控制台终端除了最高层的输入输出功能类似外,底层的实现大相径庭。终端切换的流程:Key_handler(do_cons)want_console=nr;mark_bh(CONSOLE_BH);Console_bhcomplete_change_consoleUpdate_screenstaticvoidkeyboard_interrupt(intirq,void*dev_id,structpt_regs*regs)handle_scancode(scancode);(*key_handlertype)(keysym&0xff,up_flag);k_handkey_handlerkeyboard.c键盘特殊输入的特殊处理函数数组。statick_handkey_handler16=do_self,do_fn,do_spec,do_pad,do_dead,do_cons,do_cur,do_shift,do_meta,do_ascii,do_lock,do_lowercase,do_slock,do_ignore,do_ignore,do_ignore;do_cons()改变终端的最上层函数keyboard.cstaticvoiddo_cons(unsignedcharvalue,charup_flag)if(up_flag)return;set_console(value);set_console()设置want_console为欲切换到的终端。设置console的bottomhalf标志。kbd_kern.hexterninlinevoidset_console(intnr)want_console=nr;mark_bh(CONSOLE_BH);console_bh()console.cstaticvoidconsole_bh(void)是否要切换consoleif(want_console=0)if(want_console!=fg_console)change_console(want_console);/*weonlychangedwhentheconsolehadalreadybeenallocated-anewconsoleisnotcreatedinaninterruptroutine*/want_console=-1;if(do_poke_blanked_console)/*donotunblankforaLEDchange*/do_poke_blanked_console=0;poke_blanked_console();change_console()tty_io.c切换终端的实际动作。voidchange_console(unsignedintnew_console)if(new_console=fg_console)|(vt_dont_switch)return;if(!vc_cons_allocated(new_console)return;/*Ifthisvtisinprocessmode,thenweneedtohandshakewith什么模式?在此模式下,不能直接切换,要等待!*thatprocessbeforeswitching.Essentially,westorewherethat*vtwantstoswitchtoandwaitforittotelluswhenitsdone*(viaVT_RELDISPioctl).*Wealsochecktoseeifthecontrollingprocessstillexists.控制进程*Ifitdoesnt,weresetthisvttoautomodeandcontinue.什么模式?*Thisisacheapwaytotrackprocesscontrol.Theworstthing*thatcanhappenis:wesendasignaltoaprocess,itdies,and*theswitchgetslostwaitingforaresponse;hopefully,the*userwilltryagain,welldetecttheprocessisgone(unless*theuserwaitsjusttherightamountoftime:-)andrevertthe*vttoautocontrol.*/VT_PROCESS模式的处理。在此模式下,不能直接切换,要等待!if(vt_consfg_console-vt_mode.mode=VT_PROCESS)/*Sendthesignalasprivileged-kill_proc()will*tellusiftheprocesshasgoneorsomethingelse*isawry*/if(kill_proc(vt_consfg_console-vt_pid,vt_consfg_console-vt_mode.relsig,1)=0)/*Itworked.Markthevttoswitchtoand*return.Theprocessneedstosendusa*VT_RELDISPioctltocompletetheswitch.*/vt_consfg_console-vt_newvt=new_console;return;/*Thecontrollingprocesshasdied,sowerevertbackto*normaloperation.Inthiscase,wellalsochangeback*toKD_TEXTmode.Imnotsureifthisisstrictlycorrect*butitsavestheagonywhentheXserverdiesandthescreen*remainsblankedduetoKD_GRAPHICS!Itwouldbenicetodo*thisoutsideofVT_PROCESSbutthereisnosingleprocess*toaccountforandtrackingttycountmaybeundesirable.*/reset_vc(fg_console);/*Fallthroughtonormal(VT_AUTO)handlingoftheswitch.*/在KD_GRAPHICS+VT_AUTO模式下忽略所有终端切换。if(vt_consfg_console-vc_mode=KD_GRAPHICS)return;complete_change_console(new_console);相关函数与变量判断新的虚拟终端是否存在。intvc_cons_allocated(unsignedinti)/console.creturn(ivc_mode=KD_TEXT;kbd_tablenew_console.kbdmode=VC_XLATE;vt_consnew_console-vt_mode.mode=VT_AUTO;vt_consnew_console-vt_mode.waitv=0;vt_consnew_console-vt_mode.relsig=0;vt_consnew_console-vt_mode.acqsig=0;vt_consnew_console-vt_mode.frsig=0;vt_consnew_console-vt_pid=-1;vt_consnew_console-vt_newvt=-1;reset_palette(new_console);complete_change_console()切换终端的实际动作。tty_io.cvoidcomplete_change_console(unsignedintnew_console)unsignedcharold_vc_mode;if(new_console=fg_console)|(vt_dont_switch)return;if(!vc_cons_allocated(new_console)return;last_console=fg_console;/*Ifwereswitching,wecouldbegoingfromKD_GRAPHICSto*KD_TEXTmodeorviceversa,whichmeansweneedtoblankor*unblankthescreenlater.*/old_vc_mode=vt_consfg_console-vc_mode;根据new_console重设显示器。update_screen(new_console);/*Ifthisnewconsoleisunderprocesscontrol,senditasignal*tellingitthatithasacquired.Alsocheckifithasdiedand*cleanup(similartologicemployedinchange_console()*/if(vt_consnew_console-vt_mode.mode=VT_PROCESS)/*Sendthesignalasprivileged-kill_proc()will*tellusiftheprocesshasgoneorsometh
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号