vt.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819
  1. /*
  2. * linux/drivers/char/vt.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * Hopefully this will be a rather complete VT102 implementation.
  8. *
  9. * Beeping thanks to John T Kohl.
  10. *
  11. * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics
  12. * Chars, and VT100 enhancements by Peter MacDonald.
  13. *
  14. * Copy and paste function by Andrew Haylett,
  15. * some enhancements by Alessandro Rubini.
  16. *
  17. * Code to check for different video-cards mostly by Galen Hunt,
  18. * <g-hunt@ee.utah.edu>
  19. *
  20. * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
  21. * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
  22. *
  23. * Dynamic allocation of consoles, aeb@cwi.nl, May 1994
  24. * Resizing of consoles, aeb, 940926
  25. *
  26. * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
  27. * <poe@daimi.aau.dk>
  28. *
  29. * User-defined bell sound, new setterm control sequences and printk
  30. * redirection by Martin Mares <mj@k332.feld.cvut.cz> 19-Nov-95
  31. *
  32. * APM screenblank bug fixed Takashi Manabe <manabe@roy.dsl.tutics.tut.jp>
  33. *
  34. * Merge with the abstract console driver by Geert Uytterhoeven
  35. * <geert@linux-m68k.org>, Jan 1997.
  36. *
  37. * Original m68k console driver modifications by
  38. *
  39. * - Arno Griffioen <arno@usn.nl>
  40. * - David Carter <carter@cs.bris.ac.uk>
  41. *
  42. * The abstract console driver provides a generic interface for a text
  43. * console. It supports VGA text mode, frame buffer based graphical consoles
  44. * and special graphics processors that are only accessible through some
  45. * registers (e.g. a TMS340x0 GSP).
  46. *
  47. * The interface to the hardware is specified using a special structure
  48. * (struct consw) which contains function pointers to console operations
  49. * (see <linux/console.h> for more information).
  50. *
  51. * Support for changeable cursor shape
  52. * by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>, August 1997
  53. *
  54. * Ported to i386 and con_scrolldelta fixed
  55. * by Emmanuel Marty <core@ggi-project.org>, April 1998
  56. *
  57. * Resurrected character buffers in videoram plus lots of other trickery
  58. * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
  59. *
  60. * Removed old-style timers, introduced console_timer, made timer
  61. * deletion SMP-safe. 17Jun00, Andrew Morton <andrewm@uow.edu.au>
  62. *
  63. * Removed console_lock, enabled interrupts across all console operations
  64. * 13 March 2001, Andrew Morton
  65. *
  66. * Fixed UTF-8 mode so alternate charset modes always work according
  67. * to control sequences interpreted in do_con_trol function
  68. * preserving backward VT100 semigraphics compatibility,
  69. * malformed UTF sequences represented as sequences of replacement glyphs,
  70. * original codes or '?' as a last resort if replacement glyph is undefined
  71. * by Adam Tla/lka <atlka@pg.gda.pl>, Aug 2006
  72. */
  73. #include <linux/module.h>
  74. #include <linux/types.h>
  75. #include <linux/sched.h>
  76. #include <linux/tty.h>
  77. #include <linux/tty_flip.h>
  78. #include <linux/kernel.h>
  79. #include <linux/string.h>
  80. #include <linux/errno.h>
  81. #include <linux/kd.h>
  82. #include <linux/slab.h>
  83. #include <linux/major.h>
  84. #include <linux/mm.h>
  85. #include <linux/console.h>
  86. #include <linux/init.h>
  87. #include <linux/vt_kern.h>
  88. #include <linux/selection.h>
  89. #include <linux/tiocl.h>
  90. #include <linux/kbd_kern.h>
  91. #include <linux/consolemap.h>
  92. #include <linux/timer.h>
  93. #include <linux/interrupt.h>
  94. #include <linux/workqueue.h>
  95. #include <linux/bootmem.h>
  96. #include <linux/pm.h>
  97. #include <linux/font.h>
  98. #include <linux/bitops.h>
  99. #include <asm/io.h>
  100. #include <asm/system.h>
  101. #include <asm/uaccess.h>
  102. #define MAX_NR_CON_DRIVER 16
  103. #define CON_DRIVER_FLAG_MODULE 1
  104. #define CON_DRIVER_FLAG_INIT 2
  105. #define CON_DRIVER_FLAG_ATTR 4
  106. struct con_driver {
  107. const struct consw *con;
  108. const char *desc;
  109. struct device *dev;
  110. int node;
  111. int first;
  112. int last;
  113. int flag;
  114. };
  115. static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER];
  116. const struct consw *conswitchp;
  117. /* A bitmap for codes <32. A bit of 1 indicates that the code
  118. * corresponding to that bit number invokes some special action
  119. * (such as cursor movement) and should not be displayed as a
  120. * glyph unless the disp_ctrl mode is explicitly enabled.
  121. */
  122. #define CTRL_ACTION 0x0d00ff81
  123. #define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */
  124. /*
  125. * Here is the default bell parameters: 750HZ, 1/8th of a second
  126. */
  127. #define DEFAULT_BELL_PITCH 750
  128. #define DEFAULT_BELL_DURATION (HZ/8)
  129. struct vc vc_cons [MAX_NR_CONSOLES];
  130. #ifndef VT_SINGLE_DRIVER
  131. static const struct consw *con_driver_map[MAX_NR_CONSOLES];
  132. #endif
  133. static int con_open(struct tty_struct *, struct file *);
  134. static void vc_init(struct vc_data *vc, unsigned int rows,
  135. unsigned int cols, int do_clear);
  136. static void gotoxy(struct vc_data *vc, int new_x, int new_y);
  137. static void save_cur(struct vc_data *vc);
  138. static void reset_terminal(struct vc_data *vc, int do_clear);
  139. static void con_flush_chars(struct tty_struct *tty);
  140. static int set_vesa_blanking(char __user *p);
  141. static void set_cursor(struct vc_data *vc);
  142. static void hide_cursor(struct vc_data *vc);
  143. static void console_callback(struct work_struct *ignored);
  144. static void blank_screen_t(unsigned long dummy);
  145. static void set_palette(struct vc_data *vc);
  146. static int printable; /* Is console ready for printing? */
  147. /*
  148. * ignore_poke: don't unblank the screen when things are typed. This is
  149. * mainly for the privacy of braille terminal users.
  150. */
  151. static int ignore_poke;
  152. int do_poke_blanked_console;
  153. int console_blanked;
  154. static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
  155. static int blankinterval = 10*60*HZ;
  156. static int vesa_off_interval;
  157. static DECLARE_WORK(console_work, console_callback);
  158. /*
  159. * fg_console is the current virtual console,
  160. * last_console is the last used one,
  161. * want_console is the console we want to switch to,
  162. * kmsg_redirect is the console for kernel messages,
  163. */
  164. int fg_console;
  165. int last_console;
  166. int want_console = -1;
  167. int kmsg_redirect;
  168. /*
  169. * For each existing display, we have a pointer to console currently visible
  170. * on that display, allowing consoles other than fg_console to be refreshed
  171. * appropriately. Unless the low-level driver supplies its own display_fg
  172. * variable, we use this one for the "master display".
  173. */
  174. static struct vc_data *master_display_fg;
  175. /*
  176. * Unfortunately, we need to delay tty echo when we're currently writing to the
  177. * console since the code is (and always was) not re-entrant, so we schedule
  178. * all flip requests to process context with schedule-task() and run it from
  179. * console_callback().
  180. */
  181. /*
  182. * For the same reason, we defer scrollback to the console callback.
  183. */
  184. static int scrollback_delta;
  185. /*
  186. * Hook so that the power management routines can (un)blank
  187. * the console on our behalf.
  188. */
  189. int (*console_blank_hook)(int);
  190. static struct timer_list console_timer;
  191. static int blank_state;
  192. static int blank_timer_expired;
  193. enum {
  194. blank_off = 0,
  195. blank_normal_wait,
  196. blank_vesa_wait,
  197. };
  198. /*
  199. * Low-Level Functions
  200. */
  201. #define IS_FG(vc) ((vc)->vc_num == fg_console)
  202. #ifdef VT_BUF_VRAM_ONLY
  203. #define DO_UPDATE(vc) 0
  204. #else
  205. #define DO_UPDATE(vc) CON_IS_VISIBLE(vc)
  206. #endif
  207. static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed)
  208. {
  209. unsigned short *p;
  210. if (!viewed)
  211. p = (unsigned short *)(vc->vc_origin + offset);
  212. else if (!vc->vc_sw->con_screen_pos)
  213. p = (unsigned short *)(vc->vc_visible_origin + offset);
  214. else
  215. p = vc->vc_sw->con_screen_pos(vc, offset);
  216. return p;
  217. }
  218. static inline void scrolldelta(int lines)
  219. {
  220. scrollback_delta += lines;
  221. schedule_console_callback();
  222. }
  223. void schedule_console_callback(void)
  224. {
  225. schedule_work(&console_work);
  226. }
  227. static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
  228. {
  229. unsigned short *d, *s;
  230. if (t+nr >= b)
  231. nr = b - t - 1;
  232. if (b > vc->vc_rows || t >= b || nr < 1)
  233. return;
  234. if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr))
  235. return;
  236. d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
  237. s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
  238. scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
  239. scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char,
  240. vc->vc_size_row * nr);
  241. }
  242. static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
  243. {
  244. unsigned short *s;
  245. unsigned int step;
  246. if (t+nr >= b)
  247. nr = b - t - 1;
  248. if (b > vc->vc_rows || t >= b || nr < 1)
  249. return;
  250. if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr))
  251. return;
  252. s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
  253. step = vc->vc_cols * nr;
  254. scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row);
  255. scr_memsetw(s, vc->vc_video_erase_char, 2 * step);
  256. }
  257. static void do_update_region(struct vc_data *vc, unsigned long start, int count)
  258. {
  259. #ifndef VT_BUF_VRAM_ONLY
  260. unsigned int xx, yy, offset;
  261. u16 *p;
  262. p = (u16 *) start;
  263. if (!vc->vc_sw->con_getxy) {
  264. offset = (start - vc->vc_origin) / 2;
  265. xx = offset % vc->vc_cols;
  266. yy = offset / vc->vc_cols;
  267. } else {
  268. int nxx, nyy;
  269. start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy);
  270. xx = nxx; yy = nyy;
  271. }
  272. for(;;) {
  273. u16 attrib = scr_readw(p) & 0xff00;
  274. int startx = xx;
  275. u16 *q = p;
  276. while (xx < vc->vc_cols && count) {
  277. if (attrib != (scr_readw(p) & 0xff00)) {
  278. if (p > q)
  279. vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
  280. startx = xx;
  281. q = p;
  282. attrib = scr_readw(p) & 0xff00;
  283. }
  284. p++;
  285. xx++;
  286. count--;
  287. }
  288. if (p > q)
  289. vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
  290. if (!count)
  291. break;
  292. xx = 0;
  293. yy++;
  294. if (vc->vc_sw->con_getxy) {
  295. p = (u16 *)start;
  296. start = vc->vc_sw->con_getxy(vc, start, NULL, NULL);
  297. }
  298. }
  299. #endif
  300. }
  301. void update_region(struct vc_data *vc, unsigned long start, int count)
  302. {
  303. WARN_CONSOLE_UNLOCKED();
  304. if (DO_UPDATE(vc)) {
  305. hide_cursor(vc);
  306. do_update_region(vc, start, count);
  307. set_cursor(vc);
  308. }
  309. }
  310. /* Structure of attributes is hardware-dependent */
  311. static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, u8 _underline, u8 _reverse)
  312. {
  313. if (vc->vc_sw->con_build_attr)
  314. return vc->vc_sw->con_build_attr(vc, _color, _intensity, _blink, _underline, _reverse);
  315. #ifndef VT_BUF_VRAM_ONLY
  316. /*
  317. * ++roman: I completely changed the attribute format for monochrome
  318. * mode (!can_do_color). The formerly used MDA (monochrome display
  319. * adapter) format didn't allow the combination of certain effects.
  320. * Now the attribute is just a bit vector:
  321. * Bit 0..1: intensity (0..2)
  322. * Bit 2 : underline
  323. * Bit 3 : reverse
  324. * Bit 7 : blink
  325. */
  326. {
  327. u8 a = vc->vc_color;
  328. if (!vc->vc_can_do_color)
  329. return _intensity |
  330. (_underline ? 4 : 0) |
  331. (_reverse ? 8 : 0) |
  332. (_blink ? 0x80 : 0);
  333. if (_underline)
  334. a = (a & 0xf0) | vc->vc_ulcolor;
  335. else if (_intensity == 0)
  336. a = (a & 0xf0) | vc->vc_ulcolor;
  337. if (_reverse)
  338. a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
  339. if (_blink)
  340. a ^= 0x80;
  341. if (_intensity == 2)
  342. a ^= 0x08;
  343. if (vc->vc_hi_font_mask == 0x100)
  344. a <<= 1;
  345. return a;
  346. }
  347. #else
  348. return 0;
  349. #endif
  350. }
  351. static void update_attr(struct vc_data *vc)
  352. {
  353. vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity, vc->vc_blink, vc->vc_underline, vc->vc_reverse ^ vc->vc_decscnm);
  354. vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm) << 8) | ' ';
  355. }
  356. /* Note: inverting the screen twice should revert to the original state */
  357. void invert_screen(struct vc_data *vc, int offset, int count, int viewed)
  358. {
  359. unsigned short *p;
  360. WARN_CONSOLE_UNLOCKED();
  361. count /= 2;
  362. p = screenpos(vc, offset, viewed);
  363. if (vc->vc_sw->con_invert_region)
  364. vc->vc_sw->con_invert_region(vc, p, count);
  365. #ifndef VT_BUF_VRAM_ONLY
  366. else {
  367. u16 *q = p;
  368. int cnt = count;
  369. u16 a;
  370. if (!vc->vc_can_do_color) {
  371. while (cnt--) {
  372. a = scr_readw(q);
  373. a ^= 0x0800;
  374. scr_writew(a, q);
  375. q++;
  376. }
  377. } else if (vc->vc_hi_font_mask == 0x100) {
  378. while (cnt--) {
  379. a = scr_readw(q);
  380. a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
  381. scr_writew(a, q);
  382. q++;
  383. }
  384. } else {
  385. while (cnt--) {
  386. a = scr_readw(q);
  387. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
  388. scr_writew(a, q);
  389. q++;
  390. }
  391. }
  392. }
  393. #endif
  394. if (DO_UPDATE(vc))
  395. do_update_region(vc, (unsigned long) p, count);
  396. }
  397. /* used by selection: complement pointer position */
  398. void complement_pos(struct vc_data *vc, int offset)
  399. {
  400. static int old_offset = -1;
  401. static unsigned short old;
  402. static unsigned short oldx, oldy;
  403. WARN_CONSOLE_UNLOCKED();
  404. if (old_offset != -1 && old_offset >= 0 &&
  405. old_offset < vc->vc_screenbuf_size) {
  406. scr_writew(old, screenpos(vc, old_offset, 1));
  407. if (DO_UPDATE(vc))
  408. vc->vc_sw->con_putc(vc, old, oldy, oldx);
  409. }
  410. old_offset = offset;
  411. if (offset != -1 && offset >= 0 &&
  412. offset < vc->vc_screenbuf_size) {
  413. unsigned short new;
  414. unsigned short *p;
  415. p = screenpos(vc, offset, 1);
  416. old = scr_readw(p);
  417. new = old ^ vc->vc_complement_mask;
  418. scr_writew(new, p);
  419. if (DO_UPDATE(vc)) {
  420. oldx = (offset >> 1) % vc->vc_cols;
  421. oldy = (offset >> 1) / vc->vc_cols;
  422. vc->vc_sw->con_putc(vc, new, oldy, oldx);
  423. }
  424. }
  425. }
  426. static void insert_char(struct vc_data *vc, unsigned int nr)
  427. {
  428. unsigned short *p, *q = (unsigned short *)vc->vc_pos;
  429. p = q + vc->vc_cols - nr - vc->vc_x;
  430. while (--p >= q)
  431. scr_writew(scr_readw(p), p + nr);
  432. scr_memsetw(q, vc->vc_video_erase_char, nr * 2);
  433. vc->vc_need_wrap = 0;
  434. if (DO_UPDATE(vc)) {
  435. unsigned short oldattr = vc->vc_attr;
  436. vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x, vc->vc_y, vc->vc_x + nr, 1,
  437. vc->vc_cols - vc->vc_x - nr);
  438. vc->vc_attr = vc->vc_video_erase_char >> 8;
  439. while (nr--)
  440. vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y, vc->vc_x + nr);
  441. vc->vc_attr = oldattr;
  442. }
  443. }
  444. static void delete_char(struct vc_data *vc, unsigned int nr)
  445. {
  446. unsigned int i = vc->vc_x;
  447. unsigned short *p = (unsigned short *)vc->vc_pos;
  448. while (++i <= vc->vc_cols - nr) {
  449. scr_writew(scr_readw(p+nr), p);
  450. p++;
  451. }
  452. scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
  453. vc->vc_need_wrap = 0;
  454. if (DO_UPDATE(vc)) {
  455. unsigned short oldattr = vc->vc_attr;
  456. vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x + nr, vc->vc_y, vc->vc_x, 1,
  457. vc->vc_cols - vc->vc_x - nr);
  458. vc->vc_attr = vc->vc_video_erase_char >> 8;
  459. while (nr--)
  460. vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y,
  461. vc->vc_cols - 1 - nr);
  462. vc->vc_attr = oldattr;
  463. }
  464. }
  465. static int softcursor_original;
  466. static void add_softcursor(struct vc_data *vc)
  467. {
  468. int i = scr_readw((u16 *) vc->vc_pos);
  469. u32 type = vc->vc_cursor_type;
  470. if (! (type & 0x10)) return;
  471. if (softcursor_original != -1) return;
  472. softcursor_original = i;
  473. i |= ((type >> 8) & 0xff00 );
  474. i ^= ((type) & 0xff00 );
  475. if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000;
  476. if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700;
  477. scr_writew(i, (u16 *) vc->vc_pos);
  478. if (DO_UPDATE(vc))
  479. vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x);
  480. }
  481. static void hide_softcursor(struct vc_data *vc)
  482. {
  483. if (softcursor_original != -1) {
  484. scr_writew(softcursor_original, (u16 *)vc->vc_pos);
  485. if (DO_UPDATE(vc))
  486. vc->vc_sw->con_putc(vc, softcursor_original,
  487. vc->vc_y, vc->vc_x);
  488. softcursor_original = -1;
  489. }
  490. }
  491. static void hide_cursor(struct vc_data *vc)
  492. {
  493. if (vc == sel_cons)
  494. clear_selection();
  495. vc->vc_sw->con_cursor(vc, CM_ERASE);
  496. hide_softcursor(vc);
  497. }
  498. static void set_cursor(struct vc_data *vc)
  499. {
  500. if (!IS_FG(vc) || console_blanked ||
  501. vc->vc_mode == KD_GRAPHICS)
  502. return;
  503. if (vc->vc_deccm) {
  504. if (vc == sel_cons)
  505. clear_selection();
  506. add_softcursor(vc);
  507. if ((vc->vc_cursor_type & 0x0f) != 1)
  508. vc->vc_sw->con_cursor(vc, CM_DRAW);
  509. } else
  510. hide_cursor(vc);
  511. }
  512. static void set_origin(struct vc_data *vc)
  513. {
  514. WARN_CONSOLE_UNLOCKED();
  515. if (!CON_IS_VISIBLE(vc) ||
  516. !vc->vc_sw->con_set_origin ||
  517. !vc->vc_sw->con_set_origin(vc))
  518. vc->vc_origin = (unsigned long)vc->vc_screenbuf;
  519. vc->vc_visible_origin = vc->vc_origin;
  520. vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size;
  521. vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->vc_y + 2 * vc->vc_x;
  522. }
  523. static inline void save_screen(struct vc_data *vc)
  524. {
  525. WARN_CONSOLE_UNLOCKED();
  526. if (vc->vc_sw->con_save_screen)
  527. vc->vc_sw->con_save_screen(vc);
  528. }
  529. /*
  530. * Redrawing of screen
  531. */
  532. static void clear_buffer_attributes(struct vc_data *vc)
  533. {
  534. unsigned short *p = (unsigned short *)vc->vc_origin;
  535. int count = vc->vc_screenbuf_size / 2;
  536. int mask = vc->vc_hi_font_mask | 0xff;
  537. for (; count > 0; count--, p++) {
  538. scr_writew((scr_readw(p)&mask) | (vc->vc_video_erase_char & ~mask), p);
  539. }
  540. }
  541. void redraw_screen(struct vc_data *vc, int is_switch)
  542. {
  543. int redraw = 0;
  544. WARN_CONSOLE_UNLOCKED();
  545. if (!vc) {
  546. /* strange ... */
  547. /* printk("redraw_screen: tty %d not allocated ??\n", new_console+1); */
  548. return;
  549. }
  550. if (is_switch) {
  551. struct vc_data *old_vc = vc_cons[fg_console].d;
  552. if (old_vc == vc)
  553. return;
  554. if (!CON_IS_VISIBLE(vc))
  555. redraw = 1;
  556. *vc->vc_display_fg = vc;
  557. fg_console = vc->vc_num;
  558. hide_cursor(old_vc);
  559. if (!CON_IS_VISIBLE(old_vc)) {
  560. save_screen(old_vc);
  561. set_origin(old_vc);
  562. }
  563. } else {
  564. hide_cursor(vc);
  565. redraw = 1;
  566. }
  567. if (redraw) {
  568. int update;
  569. int old_was_color = vc->vc_can_do_color;
  570. set_origin(vc);
  571. update = vc->vc_sw->con_switch(vc);
  572. set_palette(vc);
  573. /*
  574. * If console changed from mono<->color, the best we can do
  575. * is to clear the buffer attributes. As it currently stands,
  576. * rebuilding new attributes from the old buffer is not doable
  577. * without overly complex code.
  578. */
  579. if (old_was_color != vc->vc_can_do_color) {
  580. update_attr(vc);
  581. clear_buffer_attributes(vc);
  582. }
  583. if (update && vc->vc_mode != KD_GRAPHICS)
  584. do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
  585. }
  586. set_cursor(vc);
  587. if (is_switch) {
  588. set_leds();
  589. compute_shiftstate();
  590. }
  591. }
  592. /*
  593. * Allocation, freeing and resizing of VTs.
  594. */
  595. int vc_cons_allocated(unsigned int i)
  596. {
  597. return (i < MAX_NR_CONSOLES && vc_cons[i].d);
  598. }
  599. static void visual_init(struct vc_data *vc, int num, int init)
  600. {
  601. /* ++Geert: vc->vc_sw->con_init determines console size */
  602. if (vc->vc_sw)
  603. module_put(vc->vc_sw->owner);
  604. vc->vc_sw = conswitchp;
  605. #ifndef VT_SINGLE_DRIVER
  606. if (con_driver_map[num])
  607. vc->vc_sw = con_driver_map[num];
  608. #endif
  609. __module_get(vc->vc_sw->owner);
  610. vc->vc_num = num;
  611. vc->vc_display_fg = &master_display_fg;
  612. vc->vc_uni_pagedir_loc = &vc->vc_uni_pagedir;
  613. vc->vc_uni_pagedir = 0;
  614. vc->vc_hi_font_mask = 0;
  615. vc->vc_complement_mask = 0;
  616. vc->vc_can_do_color = 0;
  617. vc->vc_sw->con_init(vc, init);
  618. if (!vc->vc_complement_mask)
  619. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  620. vc->vc_s_complement_mask = vc->vc_complement_mask;
  621. vc->vc_size_row = vc->vc_cols << 1;
  622. vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
  623. }
  624. int vc_allocate(unsigned int currcons) /* return 0 on success */
  625. {
  626. WARN_CONSOLE_UNLOCKED();
  627. if (currcons >= MAX_NR_CONSOLES)
  628. return -ENXIO;
  629. if (!vc_cons[currcons].d) {
  630. struct vc_data *vc;
  631. /* prevent users from taking too much memory */
  632. if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE))
  633. return -EPERM;
  634. /* due to the granularity of kmalloc, we waste some memory here */
  635. /* the alloc is done in two steps, to optimize the common situation
  636. of a 25x80 console (structsize=216, screenbuf_size=4000) */
  637. /* although the numbers above are not valid since long ago, the
  638. point is still up-to-date and the comment still has its value
  639. even if only as a historical artifact. --mj, July 1998 */
  640. vc = kmalloc(sizeof(struct vc_data), GFP_KERNEL);
  641. if (!vc)
  642. return -ENOMEM;
  643. memset(vc, 0, sizeof(*vc));
  644. vc_cons[currcons].d = vc;
  645. visual_init(vc, currcons, 1);
  646. if (!*vc->vc_uni_pagedir_loc)
  647. con_set_default_unimap(vc);
  648. if (!vc->vc_kmalloced)
  649. vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
  650. if (!vc->vc_screenbuf) {
  651. kfree(vc);
  652. vc_cons[currcons].d = NULL;
  653. return -ENOMEM;
  654. }
  655. vc->vc_kmalloced = 1;
  656. vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
  657. }
  658. return 0;
  659. }
  660. static inline int resize_screen(struct vc_data *vc, int width, int height)
  661. {
  662. /* Resizes the resolution of the display adapater */
  663. int err = 0;
  664. if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_resize)
  665. err = vc->vc_sw->con_resize(vc, width, height);
  666. return err;
  667. }
  668. /*
  669. * Change # of rows and columns (0 means unchanged/the size of fg_console)
  670. * [this is to be used together with some user program
  671. * like resize that changes the hardware videomode]
  672. */
  673. #define VC_RESIZE_MAXCOL (32767)
  674. #define VC_RESIZE_MAXROW (32767)
  675. int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
  676. {
  677. unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
  678. unsigned int old_cols, old_rows, old_row_size, old_screen_size;
  679. unsigned int new_cols, new_rows, new_row_size, new_screen_size;
  680. unsigned int end;
  681. unsigned short *newscreen;
  682. WARN_CONSOLE_UNLOCKED();
  683. if (!vc)
  684. return -ENXIO;
  685. if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW)
  686. return -EINVAL;
  687. new_cols = (cols ? cols : vc->vc_cols);
  688. new_rows = (lines ? lines : vc->vc_rows);
  689. new_row_size = new_cols << 1;
  690. new_screen_size = new_row_size * new_rows;
  691. if (new_cols == vc->vc_cols && new_rows == vc->vc_rows)
  692. return 0;
  693. newscreen = kmalloc(new_screen_size, GFP_USER);
  694. if (!newscreen)
  695. return -ENOMEM;
  696. old_rows = vc->vc_rows;
  697. old_cols = vc->vc_cols;
  698. old_row_size = vc->vc_size_row;
  699. old_screen_size = vc->vc_screenbuf_size;
  700. err = resize_screen(vc, new_cols, new_rows);
  701. if (err) {
  702. kfree(newscreen);
  703. return err;
  704. }
  705. vc->vc_rows = new_rows;
  706. vc->vc_cols = new_cols;
  707. vc->vc_size_row = new_row_size;
  708. vc->vc_screenbuf_size = new_screen_size;
  709. rlth = min(old_row_size, new_row_size);
  710. rrem = new_row_size - rlth;
  711. old_origin = vc->vc_origin;
  712. new_origin = (long) newscreen;
  713. new_scr_end = new_origin + new_screen_size;
  714. if (vc->vc_y > new_rows) {
  715. if (old_rows - vc->vc_y < new_rows) {
  716. /*
  717. * Cursor near the bottom, copy contents from the
  718. * bottom of buffer
  719. */
  720. old_origin += (old_rows - new_rows) * old_row_size;
  721. end = vc->vc_scr_end;
  722. } else {
  723. /*
  724. * Cursor is in no man's land, copy 1/2 screenful
  725. * from the top and bottom of cursor position
  726. */
  727. old_origin += (vc->vc_y - new_rows/2) * old_row_size;
  728. end = old_origin + (old_row_size * new_rows);
  729. }
  730. } else
  731. /*
  732. * Cursor near the top, copy contents from the top of buffer
  733. */
  734. end = (old_rows > new_rows) ? old_origin +
  735. (old_row_size * new_rows) :
  736. vc->vc_scr_end;
  737. update_attr(vc);
  738. while (old_origin < end) {
  739. scr_memcpyw((unsigned short *) new_origin,
  740. (unsigned short *) old_origin, rlth);
  741. if (rrem)
  742. scr_memsetw((void *)(new_origin + rlth),
  743. vc->vc_video_erase_char, rrem);
  744. old_origin += old_row_size;
  745. new_origin += new_row_size;
  746. }
  747. if (new_scr_end > new_origin)
  748. scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
  749. new_scr_end - new_origin);
  750. if (vc->vc_kmalloced)
  751. kfree(vc->vc_screenbuf);
  752. vc->vc_screenbuf = newscreen;
  753. vc->vc_kmalloced = 1;
  754. vc->vc_screenbuf_size = new_screen_size;
  755. set_origin(vc);
  756. /* do part of a reset_terminal() */
  757. vc->vc_top = 0;
  758. vc->vc_bottom = vc->vc_rows;
  759. gotoxy(vc, vc->vc_x, vc->vc_y);
  760. save_cur(vc);
  761. if (vc->vc_tty) {
  762. struct winsize ws, *cws = &vc->vc_tty->winsize;
  763. memset(&ws, 0, sizeof(ws));
  764. ws.ws_row = vc->vc_rows;
  765. ws.ws_col = vc->vc_cols;
  766. ws.ws_ypixel = vc->vc_scan_lines;
  767. if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
  768. vc->vc_tty->pgrp > 0)
  769. kill_pg(vc->vc_tty->pgrp, SIGWINCH, 1);
  770. *cws = ws;
  771. }
  772. if (CON_IS_VISIBLE(vc))
  773. update_screen(vc);
  774. return err;
  775. }
  776. int vc_lock_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
  777. {
  778. int rc;
  779. acquire_console_sem();
  780. rc = vc_resize(vc, cols, lines);
  781. release_console_sem();
  782. return rc;
  783. }
  784. void vc_deallocate(unsigned int currcons)
  785. {
  786. WARN_CONSOLE_UNLOCKED();
  787. if (vc_cons_allocated(currcons)) {
  788. struct vc_data *vc = vc_cons[currcons].d;
  789. vc->vc_sw->con_deinit(vc);
  790. put_pid(vc->vt_pid);
  791. module_put(vc->vc_sw->owner);
  792. if (vc->vc_kmalloced)
  793. kfree(vc->vc_screenbuf);
  794. if (currcons >= MIN_NR_CONSOLES)
  795. kfree(vc);
  796. vc_cons[currcons].d = NULL;
  797. }
  798. }
  799. /*
  800. * VT102 emulator
  801. */
  802. #define set_kbd(vc, x) set_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  803. #define clr_kbd(vc, x) clr_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  804. #define is_kbd(vc, x) vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  805. #define decarm VC_REPEAT
  806. #define decckm VC_CKMODE
  807. #define kbdapplic VC_APPLIC
  808. #define lnm VC_CRLF
  809. /*
  810. * this is what the terminal answers to a ESC-Z or csi0c query.
  811. */
  812. #define VT100ID "\033[?1;2c"
  813. #define VT102ID "\033[?6c"
  814. unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
  815. 8,12,10,14, 9,13,11,15 };
  816. /* the default colour table, for VGA+ colour systems */
  817. int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
  818. 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
  819. int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
  820. 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
  821. int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
  822. 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
  823. /*
  824. * gotoxy() must verify all boundaries, because the arguments
  825. * might also be negative. If the given position is out of
  826. * bounds, the cursor is placed at the nearest margin.
  827. */
  828. static void gotoxy(struct vc_data *vc, int new_x, int new_y)
  829. {
  830. int min_y, max_y;
  831. if (new_x < 0)
  832. vc->vc_x = 0;
  833. else {
  834. if (new_x >= vc->vc_cols)
  835. vc->vc_x = vc->vc_cols - 1;
  836. else
  837. vc->vc_x = new_x;
  838. }
  839. if (vc->vc_decom) {
  840. min_y = vc->vc_top;
  841. max_y = vc->vc_bottom;
  842. } else {
  843. min_y = 0;
  844. max_y = vc->vc_rows;
  845. }
  846. if (new_y < min_y)
  847. vc->vc_y = min_y;
  848. else if (new_y >= max_y)
  849. vc->vc_y = max_y - 1;
  850. else
  851. vc->vc_y = new_y;
  852. vc->vc_pos = vc->vc_origin + vc->vc_y * vc->vc_size_row + (vc->vc_x<<1);
  853. vc->vc_need_wrap = 0;
  854. }
  855. /* for absolute user moves, when decom is set */
  856. static void gotoxay(struct vc_data *vc, int new_x, int new_y)
  857. {
  858. gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y);
  859. }
  860. void scrollback(struct vc_data *vc, int lines)
  861. {
  862. if (!lines)
  863. lines = vc->vc_rows / 2;
  864. scrolldelta(-lines);
  865. }
  866. void scrollfront(struct vc_data *vc, int lines)
  867. {
  868. if (!lines)
  869. lines = vc->vc_rows / 2;
  870. scrolldelta(lines);
  871. }
  872. static void lf(struct vc_data *vc)
  873. {
  874. /* don't scroll if above bottom of scrolling region, or
  875. * if below scrolling region
  876. */
  877. if (vc->vc_y + 1 == vc->vc_bottom)
  878. scrup(vc, vc->vc_top, vc->vc_bottom, 1);
  879. else if (vc->vc_y < vc->vc_rows - 1) {
  880. vc->vc_y++;
  881. vc->vc_pos += vc->vc_size_row;
  882. }
  883. vc->vc_need_wrap = 0;
  884. }
  885. static void ri(struct vc_data *vc)
  886. {
  887. /* don't scroll if below top of scrolling region, or
  888. * if above scrolling region
  889. */
  890. if (vc->vc_y == vc->vc_top)
  891. scrdown(vc, vc->vc_top, vc->vc_bottom, 1);
  892. else if (vc->vc_y > 0) {
  893. vc->vc_y--;
  894. vc->vc_pos -= vc->vc_size_row;
  895. }
  896. vc->vc_need_wrap = 0;
  897. }
  898. static inline void cr(struct vc_data *vc)
  899. {
  900. vc->vc_pos -= vc->vc_x << 1;
  901. vc->vc_need_wrap = vc->vc_x = 0;
  902. }
  903. static inline void bs(struct vc_data *vc)
  904. {
  905. if (vc->vc_x) {
  906. vc->vc_pos -= 2;
  907. vc->vc_x--;
  908. vc->vc_need_wrap = 0;
  909. }
  910. }
  911. static inline void del(struct vc_data *vc)
  912. {
  913. /* ignored */
  914. }
  915. static void csi_J(struct vc_data *vc, int vpar)
  916. {
  917. unsigned int count;
  918. unsigned short * start;
  919. switch (vpar) {
  920. case 0: /* erase from cursor to end of display */
  921. count = (vc->vc_scr_end - vc->vc_pos) >> 1;
  922. start = (unsigned short *)vc->vc_pos;
  923. if (DO_UPDATE(vc)) {
  924. /* do in two stages */
  925. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
  926. vc->vc_cols - vc->vc_x);
  927. vc->vc_sw->con_clear(vc, vc->vc_y + 1, 0,
  928. vc->vc_rows - vc->vc_y - 1,
  929. vc->vc_cols);
  930. }
  931. break;
  932. case 1: /* erase from start to cursor */
  933. count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
  934. start = (unsigned short *)vc->vc_origin;
  935. if (DO_UPDATE(vc)) {
  936. /* do in two stages */
  937. vc->vc_sw->con_clear(vc, 0, 0, vc->vc_y,
  938. vc->vc_cols);
  939. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  940. vc->vc_x + 1);
  941. }
  942. break;
  943. case 2: /* erase whole display */
  944. count = vc->vc_cols * vc->vc_rows;
  945. start = (unsigned short *)vc->vc_origin;
  946. if (DO_UPDATE(vc))
  947. vc->vc_sw->con_clear(vc, 0, 0,
  948. vc->vc_rows,
  949. vc->vc_cols);
  950. break;
  951. default:
  952. return;
  953. }
  954. scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
  955. vc->vc_need_wrap = 0;
  956. }
  957. static void csi_K(struct vc_data *vc, int vpar)
  958. {
  959. unsigned int count;
  960. unsigned short * start;
  961. switch (vpar) {
  962. case 0: /* erase from cursor to end of line */
  963. count = vc->vc_cols - vc->vc_x;
  964. start = (unsigned short *)vc->vc_pos;
  965. if (DO_UPDATE(vc))
  966. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
  967. vc->vc_cols - vc->vc_x);
  968. break;
  969. case 1: /* erase from start of line to cursor */
  970. start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
  971. count = vc->vc_x + 1;
  972. if (DO_UPDATE(vc))
  973. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  974. vc->vc_x + 1);
  975. break;
  976. case 2: /* erase whole line */
  977. start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
  978. count = vc->vc_cols;
  979. if (DO_UPDATE(vc))
  980. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  981. vc->vc_cols);
  982. break;
  983. default:
  984. return;
  985. }
  986. scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
  987. vc->vc_need_wrap = 0;
  988. }
  989. static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */
  990. { /* not vt100? */
  991. int count;
  992. if (!vpar)
  993. vpar++;
  994. count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar;
  995. scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
  996. if (DO_UPDATE(vc))
  997. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count);
  998. vc->vc_need_wrap = 0;
  999. }
  1000. static void default_attr(struct vc_data *vc)
  1001. {
  1002. vc->vc_intensity = 1;
  1003. vc->vc_underline = 0;
  1004. vc->vc_reverse = 0;
  1005. vc->vc_blink = 0;
  1006. vc->vc_color = vc->vc_def_color;
  1007. }
  1008. /* console_sem is held */
  1009. static void csi_m(struct vc_data *vc)
  1010. {
  1011. int i;
  1012. for (i = 0; i <= vc->vc_npar; i++)
  1013. switch (vc->vc_par[i]) {
  1014. case 0: /* all attributes off */
  1015. default_attr(vc);
  1016. break;
  1017. case 1:
  1018. vc->vc_intensity = 2;
  1019. break;
  1020. case 2:
  1021. vc->vc_intensity = 0;
  1022. break;
  1023. case 4:
  1024. vc->vc_underline = 1;
  1025. break;
  1026. case 5:
  1027. vc->vc_blink = 1;
  1028. break;
  1029. case 7:
  1030. vc->vc_reverse = 1;
  1031. break;
  1032. case 10: /* ANSI X3.64-1979 (SCO-ish?)
  1033. * Select primary font, don't display
  1034. * control chars if defined, don't set
  1035. * bit 8 on output.
  1036. */
  1037. vc->vc_translate = set_translate(vc->vc_charset == 0
  1038. ? vc->vc_G0_charset
  1039. : vc->vc_G1_charset, vc);
  1040. vc->vc_disp_ctrl = 0;
  1041. vc->vc_toggle_meta = 0;
  1042. break;
  1043. case 11: /* ANSI X3.64-1979 (SCO-ish?)
  1044. * Select first alternate font, lets
  1045. * chars < 32 be displayed as ROM chars.
  1046. */
  1047. vc->vc_translate = set_translate(IBMPC_MAP, vc);
  1048. vc->vc_disp_ctrl = 1;
  1049. vc->vc_toggle_meta = 0;
  1050. break;
  1051. case 12: /* ANSI X3.64-1979 (SCO-ish?)
  1052. * Select second alternate font, toggle
  1053. * high bit before displaying as ROM char.
  1054. */
  1055. vc->vc_translate = set_translate(IBMPC_MAP, vc);
  1056. vc->vc_disp_ctrl = 1;
  1057. vc->vc_toggle_meta = 1;
  1058. break;
  1059. case 21:
  1060. case 22:
  1061. vc->vc_intensity = 1;
  1062. break;
  1063. case 24:
  1064. vc->vc_underline = 0;
  1065. break;
  1066. case 25:
  1067. vc->vc_blink = 0;
  1068. break;
  1069. case 27:
  1070. vc->vc_reverse = 0;
  1071. break;
  1072. case 38: /* ANSI X3.64-1979 (SCO-ish?)
  1073. * Enables underscore, white foreground
  1074. * with white underscore (Linux - use
  1075. * default foreground).
  1076. */
  1077. vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);
  1078. vc->vc_underline = 1;
  1079. break;
  1080. case 39: /* ANSI X3.64-1979 (SCO-ish?)
  1081. * Disable underline option.
  1082. * Reset colour to default? It did this
  1083. * before...
  1084. */
  1085. vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);
  1086. vc->vc_underline = 0;
  1087. break;
  1088. case 49:
  1089. vc->vc_color = (vc->vc_def_color & 0xf0) | (vc->vc_color & 0x0f);
  1090. break;
  1091. default:
  1092. if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
  1093. vc->vc_color = color_table[vc->vc_par[i] - 30]
  1094. | (vc->vc_color & 0xf0);
  1095. else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47)
  1096. vc->vc_color = (color_table[vc->vc_par[i] - 40] << 4)
  1097. | (vc->vc_color & 0x0f);
  1098. break;
  1099. }
  1100. update_attr(vc);
  1101. }
  1102. static void respond_string(const char *p, struct tty_struct *tty)
  1103. {
  1104. while (*p) {
  1105. tty_insert_flip_char(tty, *p, 0);
  1106. p++;
  1107. }
  1108. con_schedule_flip(tty);
  1109. }
  1110. static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
  1111. {
  1112. char buf[40];
  1113. sprintf(buf, "\033[%d;%dR", vc->vc_y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->vc_x + 1);
  1114. respond_string(buf, tty);
  1115. }
  1116. static inline void status_report(struct tty_struct *tty)
  1117. {
  1118. respond_string("\033[0n", tty); /* Terminal ok */
  1119. }
  1120. static inline void respond_ID(struct tty_struct * tty)
  1121. {
  1122. respond_string(VT102ID, tty);
  1123. }
  1124. void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry)
  1125. {
  1126. char buf[8];
  1127. sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
  1128. (char)('!' + mry));
  1129. respond_string(buf, tty);
  1130. }
  1131. /* invoked via ioctl(TIOCLINUX) and through set_selection */
  1132. int mouse_reporting(void)
  1133. {
  1134. return vc_cons[fg_console].d->vc_report_mouse;
  1135. }
  1136. /* console_sem is held */
  1137. static void set_mode(struct vc_data *vc, int on_off)
  1138. {
  1139. int i;
  1140. for (i = 0; i <= vc->vc_npar; i++)
  1141. if (vc->vc_ques) {
  1142. switch(vc->vc_par[i]) { /* DEC private modes set/reset */
  1143. case 1: /* Cursor keys send ^[Ox/^[[x */
  1144. if (on_off)
  1145. set_kbd(vc, decckm);
  1146. else
  1147. clr_kbd(vc, decckm);
  1148. break;
  1149. case 3: /* 80/132 mode switch unimplemented */
  1150. vc->vc_deccolm = on_off;
  1151. #if 0
  1152. vc_resize(deccolm ? 132 : 80, vc->vc_rows);
  1153. /* this alone does not suffice; some user mode
  1154. utility has to change the hardware regs */
  1155. #endif
  1156. break;
  1157. case 5: /* Inverted screen on/off */
  1158. if (vc->vc_decscnm != on_off) {
  1159. vc->vc_decscnm = on_off;
  1160. invert_screen(vc, 0, vc->vc_screenbuf_size, 0);
  1161. update_attr(vc);
  1162. }
  1163. break;
  1164. case 6: /* Origin relative/absolute */
  1165. vc->vc_decom = on_off;
  1166. gotoxay(vc, 0, 0);
  1167. break;
  1168. case 7: /* Autowrap on/off */
  1169. vc->vc_decawm = on_off;
  1170. break;
  1171. case 8: /* Autorepeat on/off */
  1172. if (on_off)
  1173. set_kbd(vc, decarm);
  1174. else
  1175. clr_kbd(vc, decarm);
  1176. break;
  1177. case 9:
  1178. vc->vc_report_mouse = on_off ? 1 : 0;
  1179. break;
  1180. case 25: /* Cursor on/off */
  1181. vc->vc_deccm = on_off;
  1182. break;
  1183. case 1000:
  1184. vc->vc_report_mouse = on_off ? 2 : 0;
  1185. break;
  1186. }
  1187. } else {
  1188. switch(vc->vc_par[i]) { /* ANSI modes set/reset */
  1189. case 3: /* Monitor (display ctrls) */
  1190. vc->vc_disp_ctrl = on_off;
  1191. break;
  1192. case 4: /* Insert Mode on/off */
  1193. vc->vc_decim = on_off;
  1194. break;
  1195. case 20: /* Lf, Enter == CrLf/Lf */
  1196. if (on_off)
  1197. set_kbd(vc, lnm);
  1198. else
  1199. clr_kbd(vc, lnm);
  1200. break;
  1201. }
  1202. }
  1203. }
  1204. /* console_sem is held */
  1205. static void setterm_command(struct vc_data *vc)
  1206. {
  1207. switch(vc->vc_par[0]) {
  1208. case 1: /* set color for underline mode */
  1209. if (vc->vc_can_do_color &&
  1210. vc->vc_par[1] < 16) {
  1211. vc->vc_ulcolor = color_table[vc->vc_par[1]];
  1212. if (vc->vc_underline)
  1213. update_attr(vc);
  1214. }
  1215. break;
  1216. case 2: /* set color for half intensity mode */
  1217. if (vc->vc_can_do_color &&
  1218. vc->vc_par[1] < 16) {
  1219. vc->vc_halfcolor = color_table[vc->vc_par[1]];
  1220. if (vc->vc_intensity == 0)
  1221. update_attr(vc);
  1222. }
  1223. break;
  1224. case 8: /* store colors as defaults */
  1225. vc->vc_def_color = vc->vc_attr;
  1226. if (vc->vc_hi_font_mask == 0x100)
  1227. vc->vc_def_color >>= 1;
  1228. default_attr(vc);
  1229. update_attr(vc);
  1230. break;
  1231. case 9: /* set blanking interval */
  1232. blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;
  1233. poke_blanked_console();
  1234. break;
  1235. case 10: /* set bell frequency in Hz */
  1236. if (vc->vc_npar >= 1)
  1237. vc->vc_bell_pitch = vc->vc_par[1];
  1238. else
  1239. vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
  1240. break;
  1241. case 11: /* set bell duration in msec */
  1242. if (vc->vc_npar >= 1)
  1243. vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?
  1244. vc->vc_par[1] * HZ / 1000 : 0;
  1245. else
  1246. vc->vc_bell_duration = DEFAULT_BELL_DURATION;
  1247. break;
  1248. case 12: /* bring specified console to the front */
  1249. if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))
  1250. set_console(vc->vc_par[1] - 1);
  1251. break;
  1252. case 13: /* unblank the screen */
  1253. poke_blanked_console();
  1254. break;
  1255. case 14: /* set vesa powerdown interval */
  1256. vesa_off_interval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;
  1257. break;
  1258. case 15: /* activate the previous console */
  1259. set_console(last_console);
  1260. break;
  1261. }
  1262. }
  1263. /* console_sem is held */
  1264. static void csi_at(struct vc_data *vc, unsigned int nr)
  1265. {
  1266. if (nr > vc->vc_cols - vc->vc_x)
  1267. nr = vc->vc_cols - vc->vc_x;
  1268. else if (!nr)
  1269. nr = 1;
  1270. insert_char(vc, nr);
  1271. }
  1272. /* console_sem is held */
  1273. static void csi_L(struct vc_data *vc, unsigned int nr)
  1274. {
  1275. if (nr > vc->vc_rows - vc->vc_y)
  1276. nr = vc->vc_rows - vc->vc_y;
  1277. else if (!nr)
  1278. nr = 1;
  1279. scrdown(vc, vc->vc_y, vc->vc_bottom, nr);
  1280. vc->vc_need_wrap = 0;
  1281. }
  1282. /* console_sem is held */
  1283. static void csi_P(struct vc_data *vc, unsigned int nr)
  1284. {
  1285. if (nr > vc->vc_cols - vc->vc_x)
  1286. nr = vc->vc_cols - vc->vc_x;
  1287. else if (!nr)
  1288. nr = 1;
  1289. delete_char(vc, nr);
  1290. }
  1291. /* console_sem is held */
  1292. static void csi_M(struct vc_data *vc, unsigned int nr)
  1293. {
  1294. if (nr > vc->vc_rows - vc->vc_y)
  1295. nr = vc->vc_rows - vc->vc_y;
  1296. else if (!nr)
  1297. nr=1;
  1298. scrup(vc, vc->vc_y, vc->vc_bottom, nr);
  1299. vc->vc_need_wrap = 0;
  1300. }
  1301. /* console_sem is held (except via vc_init->reset_terminal */
  1302. static void save_cur(struct vc_data *vc)
  1303. {
  1304. vc->vc_saved_x = vc->vc_x;
  1305. vc->vc_saved_y = vc->vc_y;
  1306. vc->vc_s_intensity = vc->vc_intensity;
  1307. vc->vc_s_underline = vc->vc_underline;
  1308. vc->vc_s_blink = vc->vc_blink;
  1309. vc->vc_s_reverse = vc->vc_reverse;
  1310. vc->vc_s_charset = vc->vc_charset;
  1311. vc->vc_s_color = vc->vc_color;
  1312. vc->vc_saved_G0 = vc->vc_G0_charset;
  1313. vc->vc_saved_G1 = vc->vc_G1_charset;
  1314. }
  1315. /* console_sem is held */
  1316. static void restore_cur(struct vc_data *vc)
  1317. {
  1318. gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y);
  1319. vc->vc_intensity = vc->vc_s_intensity;
  1320. vc->vc_underline = vc->vc_s_underline;
  1321. vc->vc_blink = vc->vc_s_blink;
  1322. vc->vc_reverse = vc->vc_s_reverse;
  1323. vc->vc_charset = vc->vc_s_charset;
  1324. vc->vc_color = vc->vc_s_color;
  1325. vc->vc_G0_charset = vc->vc_saved_G0;
  1326. vc->vc_G1_charset = vc->vc_saved_G1;
  1327. vc->vc_translate = set_translate(vc->vc_charset ? vc->vc_G1_charset : vc->vc_G0_charset, vc);
  1328. update_attr(vc);
  1329. vc->vc_need_wrap = 0;
  1330. }
  1331. enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
  1332. EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
  1333. ESpalette };
  1334. /* console_sem is held (except via vc_init()) */
  1335. static void reset_terminal(struct vc_data *vc, int do_clear)
  1336. {
  1337. vc->vc_top = 0;
  1338. vc->vc_bottom = vc->vc_rows;
  1339. vc->vc_state = ESnormal;
  1340. vc->vc_ques = 0;
  1341. vc->vc_translate = set_translate(LAT1_MAP, vc);
  1342. vc->vc_G0_charset = LAT1_MAP;
  1343. vc->vc_G1_charset = GRAF_MAP;
  1344. vc->vc_charset = 0;
  1345. vc->vc_need_wrap = 0;
  1346. vc->vc_report_mouse = 0;
  1347. vc->vc_utf = 0;
  1348. vc->vc_utf_count = 0;
  1349. vc->vc_disp_ctrl = 0;
  1350. vc->vc_toggle_meta = 0;
  1351. vc->vc_decscnm = 0;
  1352. vc->vc_decom = 0;
  1353. vc->vc_decawm = 1;
  1354. vc->vc_deccm = 1;
  1355. vc->vc_decim = 0;
  1356. set_kbd(vc, decarm);
  1357. clr_kbd(vc, decckm);
  1358. clr_kbd(vc, kbdapplic);
  1359. clr_kbd(vc, lnm);
  1360. kbd_table[vc->vc_num].lockstate = 0;
  1361. kbd_table[vc->vc_num].slockstate = 0;
  1362. kbd_table[vc->vc_num].ledmode = LED_SHOW_FLAGS;
  1363. kbd_table[vc->vc_num].ledflagstate = kbd_table[vc->vc_num].default_ledflagstate;
  1364. /* do not do set_leds here because this causes an endless tasklet loop
  1365. when the keyboard hasn't been initialized yet */
  1366. vc->vc_cursor_type = CUR_DEFAULT;
  1367. vc->vc_complement_mask = vc->vc_s_complement_mask;
  1368. default_attr(vc);
  1369. update_attr(vc);
  1370. vc->vc_tab_stop[0] = 0x01010100;
  1371. vc->vc_tab_stop[1] =
  1372. vc->vc_tab_stop[2] =
  1373. vc->vc_tab_stop[3] =
  1374. vc->vc_tab_stop[4] = 0x01010101;
  1375. vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
  1376. vc->vc_bell_duration = DEFAULT_BELL_DURATION;
  1377. gotoxy(vc, 0, 0);
  1378. save_cur(vc);
  1379. if (do_clear)
  1380. csi_J(vc, 2);
  1381. }
  1382. /* console_sem is held */
  1383. static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
  1384. {
  1385. /*
  1386. * Control characters can be used in the _middle_
  1387. * of an escape sequence.
  1388. */
  1389. switch (c) {
  1390. case 0:
  1391. return;
  1392. case 7:
  1393. if (vc->vc_bell_duration)
  1394. kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
  1395. return;
  1396. case 8:
  1397. bs(vc);
  1398. return;
  1399. case 9:
  1400. vc->vc_pos -= (vc->vc_x << 1);
  1401. while (vc->vc_x < vc->vc_cols - 1) {
  1402. vc->vc_x++;
  1403. if (vc->vc_tab_stop[vc->vc_x >> 5] & (1 << (vc->vc_x & 31)))
  1404. break;
  1405. }
  1406. vc->vc_pos += (vc->vc_x << 1);
  1407. return;
  1408. case 10: case 11: case 12:
  1409. lf(vc);
  1410. if (!is_kbd(vc, lnm))
  1411. return;
  1412. case 13:
  1413. cr(vc);
  1414. return;
  1415. case 14:
  1416. vc->vc_charset = 1;
  1417. vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
  1418. vc->vc_disp_ctrl = 1;
  1419. return;
  1420. case 15:
  1421. vc->vc_charset = 0;
  1422. vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
  1423. vc->vc_disp_ctrl = 0;
  1424. return;
  1425. case 24: case 26:
  1426. vc->vc_state = ESnormal;
  1427. return;
  1428. case 27:
  1429. vc->vc_state = ESesc;
  1430. return;
  1431. case 127:
  1432. del(vc);
  1433. return;
  1434. case 128+27:
  1435. vc->vc_state = ESsquare;
  1436. return;
  1437. }
  1438. switch(vc->vc_state) {
  1439. case ESesc:
  1440. vc->vc_state = ESnormal;
  1441. switch (c) {
  1442. case '[':
  1443. vc->vc_state = ESsquare;
  1444. return;
  1445. case ']':
  1446. vc->vc_state = ESnonstd;
  1447. return;
  1448. case '%':
  1449. vc->vc_state = ESpercent;
  1450. return;
  1451. case 'E':
  1452. cr(vc);
  1453. lf(vc);
  1454. return;
  1455. case 'M':
  1456. ri(vc);
  1457. return;
  1458. case 'D':
  1459. lf(vc);
  1460. return;
  1461. case 'H':
  1462. vc->vc_tab_stop[vc->vc_x >> 5] |= (1 << (vc->vc_x & 31));
  1463. return;
  1464. case 'Z':
  1465. respond_ID(tty);
  1466. return;
  1467. case '7':
  1468. save_cur(vc);
  1469. return;
  1470. case '8':
  1471. restore_cur(vc);
  1472. return;
  1473. case '(':
  1474. vc->vc_state = ESsetG0;
  1475. return;
  1476. case ')':
  1477. vc->vc_state = ESsetG1;
  1478. return;
  1479. case '#':
  1480. vc->vc_state = EShash;
  1481. return;
  1482. case 'c':
  1483. reset_terminal(vc, 1);
  1484. return;
  1485. case '>': /* Numeric keypad */
  1486. clr_kbd(vc, kbdapplic);
  1487. return;
  1488. case '=': /* Appl. keypad */
  1489. set_kbd(vc, kbdapplic);
  1490. return;
  1491. }
  1492. return;
  1493. case ESnonstd:
  1494. if (c=='P') { /* palette escape sequence */
  1495. for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
  1496. vc->vc_par[vc->vc_npar] = 0;
  1497. vc->vc_npar = 0;
  1498. vc->vc_state = ESpalette;
  1499. return;
  1500. } else if (c=='R') { /* reset palette */
  1501. reset_palette(vc);
  1502. vc->vc_state = ESnormal;
  1503. } else
  1504. vc->vc_state = ESnormal;
  1505. return;
  1506. case ESpalette:
  1507. if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
  1508. vc->vc_par[vc->vc_npar++] = (c > '9' ? (c & 0xDF) - 'A' + 10 : c - '0');
  1509. if (vc->vc_npar == 7) {
  1510. int i = vc->vc_par[0] * 3, j = 1;
  1511. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1512. vc->vc_palette[i++] += vc->vc_par[j++];
  1513. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1514. vc->vc_palette[i++] += vc->vc_par[j++];
  1515. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1516. vc->vc_palette[i] += vc->vc_par[j];
  1517. set_palette(vc);
  1518. vc->vc_state = ESnormal;
  1519. }
  1520. } else
  1521. vc->vc_state = ESnormal;
  1522. return;
  1523. case ESsquare:
  1524. for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
  1525. vc->vc_par[vc->vc_npar] = 0;
  1526. vc->vc_npar = 0;
  1527. vc->vc_state = ESgetpars;
  1528. if (c == '[') { /* Function key */
  1529. vc->vc_state=ESfunckey;
  1530. return;
  1531. }
  1532. vc->vc_ques = (c == '?');
  1533. if (vc->vc_ques)
  1534. return;
  1535. case ESgetpars:
  1536. if (c == ';' && vc->vc_npar < NPAR - 1) {
  1537. vc->vc_npar++;
  1538. return;
  1539. } else if (c>='0' && c<='9') {
  1540. vc->vc_par[vc->vc_npar] *= 10;
  1541. vc->vc_par[vc->vc_npar] += c - '0';
  1542. return;
  1543. } else
  1544. vc->vc_state = ESgotpars;
  1545. case ESgotpars:
  1546. vc->vc_state = ESnormal;
  1547. switch(c) {
  1548. case 'h':
  1549. set_mode(vc, 1);
  1550. return;
  1551. case 'l':
  1552. set_mode(vc, 0);
  1553. return;
  1554. case 'c':
  1555. if (vc->vc_ques) {
  1556. if (vc->vc_par[0])
  1557. vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16);
  1558. else
  1559. vc->vc_cursor_type = CUR_DEFAULT;
  1560. return;
  1561. }
  1562. break;
  1563. case 'm':
  1564. if (vc->vc_ques) {
  1565. clear_selection();
  1566. if (vc->vc_par[0])
  1567. vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
  1568. else
  1569. vc->vc_complement_mask = vc->vc_s_complement_mask;
  1570. return;
  1571. }
  1572. break;
  1573. case 'n':
  1574. if (!vc->vc_ques) {
  1575. if (vc->vc_par[0] == 5)
  1576. status_report(tty);
  1577. else if (vc->vc_par[0] == 6)
  1578. cursor_report(vc, tty);
  1579. }
  1580. return;
  1581. }
  1582. if (vc->vc_ques) {
  1583. vc->vc_ques = 0;
  1584. return;
  1585. }
  1586. switch(c) {
  1587. case 'G': case '`':
  1588. if (vc->vc_par[0])
  1589. vc->vc_par[0]--;
  1590. gotoxy(vc, vc->vc_par[0], vc->vc_y);
  1591. return;
  1592. case 'A':
  1593. if (!vc->vc_par[0])
  1594. vc->vc_par[0]++;
  1595. gotoxy(vc, vc->vc_x, vc->vc_y - vc->vc_par[0]);
  1596. return;
  1597. case 'B': case 'e':
  1598. if (!vc->vc_par[0])
  1599. vc->vc_par[0]++;
  1600. gotoxy(vc, vc->vc_x, vc->vc_y + vc->vc_par[0]);
  1601. return;
  1602. case 'C': case 'a':
  1603. if (!vc->vc_par[0])
  1604. vc->vc_par[0]++;
  1605. gotoxy(vc, vc->vc_x + vc->vc_par[0], vc->vc_y);
  1606. return;
  1607. case 'D':
  1608. if (!vc->vc_par[0])
  1609. vc->vc_par[0]++;
  1610. gotoxy(vc, vc->vc_x - vc->vc_par[0], vc->vc_y);
  1611. return;
  1612. case 'E':
  1613. if (!vc->vc_par[0])
  1614. vc->vc_par[0]++;
  1615. gotoxy(vc, 0, vc->vc_y + vc->vc_par[0]);
  1616. return;
  1617. case 'F':
  1618. if (!vc->vc_par[0])
  1619. vc->vc_par[0]++;
  1620. gotoxy(vc, 0, vc->vc_y - vc->vc_par[0]);
  1621. return;
  1622. case 'd':
  1623. if (vc->vc_par[0])
  1624. vc->vc_par[0]--;
  1625. gotoxay(vc, vc->vc_x ,vc->vc_par[0]);
  1626. return;
  1627. case 'H': case 'f':
  1628. if (vc->vc_par[0])
  1629. vc->vc_par[0]--;
  1630. if (vc->vc_par[1])
  1631. vc->vc_par[1]--;
  1632. gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
  1633. return;
  1634. case 'J':
  1635. csi_J(vc, vc->vc_par[0]);
  1636. return;
  1637. case 'K':
  1638. csi_K(vc, vc->vc_par[0]);
  1639. return;
  1640. case 'L':
  1641. csi_L(vc, vc->vc_par[0]);
  1642. return;
  1643. case 'M':
  1644. csi_M(vc, vc->vc_par[0]);
  1645. return;
  1646. case 'P':
  1647. csi_P(vc, vc->vc_par[0]);
  1648. return;
  1649. case 'c':
  1650. if (!vc->vc_par[0])
  1651. respond_ID(tty);
  1652. return;
  1653. case 'g':
  1654. if (!vc->vc_par[0])
  1655. vc->vc_tab_stop[vc->vc_x >> 5] &= ~(1 << (vc->vc_x & 31));
  1656. else if (vc->vc_par[0] == 3) {
  1657. vc->vc_tab_stop[0] =
  1658. vc->vc_tab_stop[1] =
  1659. vc->vc_tab_stop[2] =
  1660. vc->vc_tab_stop[3] =
  1661. vc->vc_tab_stop[4] = 0;
  1662. }
  1663. return;
  1664. case 'm':
  1665. csi_m(vc);
  1666. return;
  1667. case 'q': /* DECLL - but only 3 leds */
  1668. /* map 0,1,2,3 to 0,1,2,4 */
  1669. if (vc->vc_par[0] < 4)
  1670. setledstate(kbd_table + vc->vc_num,
  1671. (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
  1672. return;
  1673. case 'r':
  1674. if (!vc->vc_par[0])
  1675. vc->vc_par[0]++;
  1676. if (!vc->vc_par[1])
  1677. vc->vc_par[1] = vc->vc_rows;
  1678. /* Minimum allowed region is 2 lines */
  1679. if (vc->vc_par[0] < vc->vc_par[1] &&
  1680. vc->vc_par[1] <= vc->vc_rows) {
  1681. vc->vc_top = vc->vc_par[0] - 1;
  1682. vc->vc_bottom = vc->vc_par[1];
  1683. gotoxay(vc, 0, 0);
  1684. }
  1685. return;
  1686. case 's':
  1687. save_cur(vc);
  1688. return;
  1689. case 'u':
  1690. restore_cur(vc);
  1691. return;
  1692. case 'X':
  1693. csi_X(vc, vc->vc_par[0]);
  1694. return;
  1695. case '@':
  1696. csi_at(vc, vc->vc_par[0]);
  1697. return;
  1698. case ']': /* setterm functions */
  1699. setterm_command(vc);
  1700. return;
  1701. }
  1702. return;
  1703. case ESpercent:
  1704. vc->vc_state = ESnormal;
  1705. switch (c) {
  1706. case '@': /* defined in ISO 2022 */
  1707. vc->vc_utf = 0;
  1708. return;
  1709. case 'G': /* prelim official escape code */
  1710. case '8': /* retained for compatibility */
  1711. vc->vc_utf = 1;
  1712. return;
  1713. }
  1714. return;
  1715. case ESfunckey:
  1716. vc->vc_state = ESnormal;
  1717. return;
  1718. case EShash:
  1719. vc->vc_state = ESnormal;
  1720. if (c == '8') {
  1721. /* DEC screen alignment test. kludge :-) */
  1722. vc->vc_video_erase_char =
  1723. (vc->vc_video_erase_char & 0xff00) | 'E';
  1724. csi_J(vc, 2);
  1725. vc->vc_video_erase_char =
  1726. (vc->vc_video_erase_char & 0xff00) | ' ';
  1727. do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
  1728. }
  1729. return;
  1730. case ESsetG0:
  1731. if (c == '0')
  1732. vc->vc_G0_charset = GRAF_MAP;
  1733. else if (c == 'B')
  1734. vc->vc_G0_charset = LAT1_MAP;
  1735. else if (c == 'U')
  1736. vc->vc_G0_charset = IBMPC_MAP;
  1737. else if (c == 'K')
  1738. vc->vc_G0_charset = USER_MAP;
  1739. if (vc->vc_charset == 0)
  1740. vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
  1741. vc->vc_state = ESnormal;
  1742. return;
  1743. case ESsetG1:
  1744. if (c == '0')
  1745. vc->vc_G1_charset = GRAF_MAP;
  1746. else if (c == 'B')
  1747. vc->vc_G1_charset = LAT1_MAP;
  1748. else if (c == 'U')
  1749. vc->vc_G1_charset = IBMPC_MAP;
  1750. else if (c == 'K')
  1751. vc->vc_G1_charset = USER_MAP;
  1752. if (vc->vc_charset == 1)
  1753. vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
  1754. vc->vc_state = ESnormal;
  1755. return;
  1756. default:
  1757. vc->vc_state = ESnormal;
  1758. }
  1759. }
  1760. /* This is a temporary buffer used to prepare a tty console write
  1761. * so that we can easily avoid touching user space while holding the
  1762. * console spinlock. It is allocated in con_init and is shared by
  1763. * this code and the vc_screen read/write tty calls.
  1764. *
  1765. * We have to allocate this statically in the kernel data section
  1766. * since console_init (and thus con_init) are called before any
  1767. * kernel memory allocation is available.
  1768. */
  1769. char con_buf[CON_BUF_SIZE];
  1770. DECLARE_MUTEX(con_buf_sem);
  1771. /* acquires console_sem */
  1772. static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1773. {
  1774. #ifdef VT_BUF_VRAM_ONLY
  1775. #define FLUSH do { } while(0);
  1776. #else
  1777. #define FLUSH if (draw_x >= 0) { \
  1778. vc->vc_sw->con_putcs(vc, (u16 *)draw_from, (u16 *)draw_to - (u16 *)draw_from, vc->vc_y, draw_x); \
  1779. draw_x = -1; \
  1780. }
  1781. #endif
  1782. int c, tc, ok, n = 0, draw_x = -1;
  1783. unsigned int currcons;
  1784. unsigned long draw_from = 0, draw_to = 0;
  1785. struct vc_data *vc;
  1786. u16 himask, charmask;
  1787. const unsigned char *orig_buf = NULL;
  1788. int orig_count;
  1789. if (in_interrupt())
  1790. return count;
  1791. might_sleep();
  1792. acquire_console_sem();
  1793. vc = tty->driver_data;
  1794. if (vc == NULL) {
  1795. printk(KERN_ERR "vt: argh, driver_data is NULL !\n");
  1796. release_console_sem();
  1797. return 0;
  1798. }
  1799. currcons = vc->vc_num;
  1800. if (!vc_cons_allocated(currcons)) {
  1801. /* could this happen? */
  1802. static int error = 0;
  1803. if (!error) {
  1804. error = 1;
  1805. printk("con_write: tty %d not allocated\n", currcons+1);
  1806. }
  1807. release_console_sem();
  1808. return 0;
  1809. }
  1810. release_console_sem();
  1811. orig_buf = buf;
  1812. orig_count = count;
  1813. /* At this point 'buf' is guaranteed to be a kernel buffer
  1814. * and therefore no access to userspace (and therefore sleeping)
  1815. * will be needed. The con_buf_sem serializes all tty based
  1816. * console rendering and vcs write/read operations. We hold
  1817. * the console spinlock during the entire write.
  1818. */
  1819. acquire_console_sem();
  1820. vc = tty->driver_data;
  1821. if (vc == NULL) {
  1822. printk(KERN_ERR "vt: argh, driver_data _became_ NULL !\n");
  1823. release_console_sem();
  1824. goto out;
  1825. }
  1826. himask = vc->vc_hi_font_mask;
  1827. charmask = himask ? 0x1ff : 0xff;
  1828. /* undraw cursor first */
  1829. if (IS_FG(vc))
  1830. hide_cursor(vc);
  1831. while (!tty->stopped && count) {
  1832. int orig = *buf;
  1833. c = orig;
  1834. buf++;
  1835. n++;
  1836. count--;
  1837. /* Do no translation at all in control states */
  1838. if (vc->vc_state != ESnormal) {
  1839. tc = c;
  1840. } else if (vc->vc_utf && !vc->vc_disp_ctrl) {
  1841. /* Combine UTF-8 into Unicode */
  1842. /* Malformed sequences as sequences of replacement glyphs */
  1843. rescan_last_byte:
  1844. if(c > 0x7f) {
  1845. if (vc->vc_utf_count) {
  1846. if ((c & 0xc0) == 0x80) {
  1847. vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
  1848. if (--vc->vc_utf_count) {
  1849. vc->vc_npar++;
  1850. continue;
  1851. }
  1852. tc = c = vc->vc_utf_char;
  1853. } else
  1854. goto replacement_glyph;
  1855. } else {
  1856. vc->vc_npar = 0;
  1857. if ((c & 0xe0) == 0xc0) {
  1858. vc->vc_utf_count = 1;
  1859. vc->vc_utf_char = (c & 0x1f);
  1860. } else if ((c & 0xf0) == 0xe0) {
  1861. vc->vc_utf_count = 2;
  1862. vc->vc_utf_char = (c & 0x0f);
  1863. } else if ((c & 0xf8) == 0xf0) {
  1864. vc->vc_utf_count = 3;
  1865. vc->vc_utf_char = (c & 0x07);
  1866. } else if ((c & 0xfc) == 0xf8) {
  1867. vc->vc_utf_count = 4;
  1868. vc->vc_utf_char = (c & 0x03);
  1869. } else if ((c & 0xfe) == 0xfc) {
  1870. vc->vc_utf_count = 5;
  1871. vc->vc_utf_char = (c & 0x01);
  1872. } else
  1873. goto replacement_glyph;
  1874. continue;
  1875. }
  1876. } else {
  1877. if (vc->vc_utf_count)
  1878. goto replacement_glyph;
  1879. tc = c;
  1880. }
  1881. } else { /* no utf or alternate charset mode */
  1882. tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c];
  1883. }
  1884. /* If the original code was a control character we
  1885. * only allow a glyph to be displayed if the code is
  1886. * not normally used (such as for cursor movement) or
  1887. * if the disp_ctrl mode has been explicitly enabled.
  1888. * Certain characters (as given by the CTRL_ALWAYS
  1889. * bitmap) are always displayed as control characters,
  1890. * as the console would be pretty useless without
  1891. * them; to display an arbitrary font position use the
  1892. * direct-to-font zone in UTF-8 mode.
  1893. */
  1894. ok = tc && (c >= 32 ||
  1895. !(vc->vc_disp_ctrl ? (CTRL_ALWAYS >> c) & 1 :
  1896. vc->vc_utf || ((CTRL_ACTION >> c) & 1)))
  1897. && (c != 127 || vc->vc_disp_ctrl)
  1898. && (c != 128+27);
  1899. if (vc->vc_state == ESnormal && ok) {
  1900. /* Now try to find out how to display it */
  1901. tc = conv_uni_to_pc(vc, tc);
  1902. if (tc & ~charmask) {
  1903. if ( tc == -4 ) {
  1904. /* If we got -4 (not found) then see if we have
  1905. defined a replacement character (U+FFFD) */
  1906. replacement_glyph:
  1907. tc = conv_uni_to_pc(vc, 0xfffd);
  1908. if (!(tc & ~charmask))
  1909. goto display_glyph;
  1910. } else if ( tc != -3 )
  1911. continue; /* nothing to display */
  1912. /* no hash table or no replacement --
  1913. * hope for the best */
  1914. if ( c & ~charmask )
  1915. tc = '?';
  1916. else
  1917. tc = c;
  1918. }
  1919. display_glyph:
  1920. if (vc->vc_need_wrap || vc->vc_decim)
  1921. FLUSH
  1922. if (vc->vc_need_wrap) {
  1923. cr(vc);
  1924. lf(vc);
  1925. }
  1926. if (vc->vc_decim)
  1927. insert_char(vc, 1);
  1928. scr_writew(himask ?
  1929. ((vc->vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
  1930. (vc->vc_attr << 8) + tc,
  1931. (u16 *) vc->vc_pos);
  1932. if (DO_UPDATE(vc) && draw_x < 0) {
  1933. draw_x = vc->vc_x;
  1934. draw_from = vc->vc_pos;
  1935. }
  1936. if (vc->vc_x == vc->vc_cols - 1) {
  1937. vc->vc_need_wrap = vc->vc_decawm;
  1938. draw_to = vc->vc_pos + 2;
  1939. } else {
  1940. vc->vc_x++;
  1941. draw_to = (vc->vc_pos += 2);
  1942. }
  1943. if (vc->vc_utf_count) {
  1944. if (vc->vc_npar) {
  1945. vc->vc_npar--;
  1946. goto display_glyph;
  1947. }
  1948. vc->vc_utf_count = 0;
  1949. c = orig;
  1950. goto rescan_last_byte;
  1951. }
  1952. continue;
  1953. }
  1954. FLUSH
  1955. do_con_trol(tty, vc, orig);
  1956. }
  1957. FLUSH
  1958. console_conditional_schedule();
  1959. release_console_sem();
  1960. out:
  1961. return n;
  1962. #undef FLUSH
  1963. }
  1964. /*
  1965. * This is the console switching callback.
  1966. *
  1967. * Doing console switching in a process context allows
  1968. * us to do the switches asynchronously (needed when we want
  1969. * to switch due to a keyboard interrupt). Synchronization
  1970. * with other console code and prevention of re-entrancy is
  1971. * ensured with console_sem.
  1972. */
  1973. static void console_callback(struct work_struct *ignored)
  1974. {
  1975. acquire_console_sem();
  1976. if (want_console >= 0) {
  1977. if (want_console != fg_console &&
  1978. vc_cons_allocated(want_console)) {
  1979. hide_cursor(vc_cons[fg_console].d);
  1980. change_console(vc_cons[want_console].d);
  1981. /* we only changed when the console had already
  1982. been allocated - a new console is not created
  1983. in an interrupt routine */
  1984. }
  1985. want_console = -1;
  1986. }
  1987. if (do_poke_blanked_console) { /* do not unblank for a LED change */
  1988. do_poke_blanked_console = 0;
  1989. poke_blanked_console();
  1990. }
  1991. if (scrollback_delta) {
  1992. struct vc_data *vc = vc_cons[fg_console].d;
  1993. clear_selection();
  1994. if (vc->vc_mode == KD_TEXT)
  1995. vc->vc_sw->con_scrolldelta(vc, scrollback_delta);
  1996. scrollback_delta = 0;
  1997. }
  1998. if (blank_timer_expired) {
  1999. do_blank_screen(0);
  2000. blank_timer_expired = 0;
  2001. }
  2002. release_console_sem();
  2003. }
  2004. void set_console(int nr)
  2005. {
  2006. want_console = nr;
  2007. schedule_console_callback();
  2008. }
  2009. struct tty_driver *console_driver;
  2010. #ifdef CONFIG_VT_CONSOLE
  2011. /*
  2012. * Console on virtual terminal
  2013. *
  2014. * The console must be locked when we get here.
  2015. */
  2016. static void vt_console_print(struct console *co, const char *b, unsigned count)
  2017. {
  2018. struct vc_data *vc = vc_cons[fg_console].d;
  2019. unsigned char c;
  2020. static unsigned long printing;
  2021. const ushort *start;
  2022. ushort cnt = 0;
  2023. ushort myx;
  2024. /* console busy or not yet initialized */
  2025. if (!printable || test_and_set_bit(0, &printing))
  2026. return;
  2027. if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
  2028. vc = vc_cons[kmsg_redirect - 1].d;
  2029. /* read `x' only after setting currcons properly (otherwise
  2030. the `x' macro will read the x of the foreground console). */
  2031. myx = vc->vc_x;
  2032. if (!vc_cons_allocated(fg_console)) {
  2033. /* impossible */
  2034. /* printk("vt_console_print: tty %d not allocated ??\n", currcons+1); */
  2035. goto quit;
  2036. }
  2037. if (vc->vc_mode != KD_TEXT)
  2038. goto quit;
  2039. /* undraw cursor first */
  2040. if (IS_FG(vc))
  2041. hide_cursor(vc);
  2042. start = (ushort *)vc->vc_pos;
  2043. /* Contrived structure to try to emulate original need_wrap behaviour
  2044. * Problems caused when we have need_wrap set on '\n' character */
  2045. while (count--) {
  2046. c = *b++;
  2047. if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
  2048. if (cnt > 0) {
  2049. if (CON_IS_VISIBLE(vc))
  2050. vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
  2051. vc->vc_x += cnt;
  2052. if (vc->vc_need_wrap)
  2053. vc->vc_x--;
  2054. cnt = 0;
  2055. }
  2056. if (c == 8) { /* backspace */
  2057. bs(vc);
  2058. start = (ushort *)vc->vc_pos;
  2059. myx = vc->vc_x;
  2060. continue;
  2061. }
  2062. if (c != 13)
  2063. lf(vc);
  2064. cr(vc);
  2065. start = (ushort *)vc->vc_pos;
  2066. myx = vc->vc_x;
  2067. if (c == 10 || c == 13)
  2068. continue;
  2069. }
  2070. scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos);
  2071. cnt++;
  2072. if (myx == vc->vc_cols - 1) {
  2073. vc->vc_need_wrap = 1;
  2074. continue;
  2075. }
  2076. vc->vc_pos += 2;
  2077. myx++;
  2078. }
  2079. if (cnt > 0) {
  2080. if (CON_IS_VISIBLE(vc))
  2081. vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
  2082. vc->vc_x += cnt;
  2083. if (vc->vc_x == vc->vc_cols) {
  2084. vc->vc_x--;
  2085. vc->vc_need_wrap = 1;
  2086. }
  2087. }
  2088. set_cursor(vc);
  2089. quit:
  2090. clear_bit(0, &printing);
  2091. }
  2092. static struct tty_driver *vt_console_device(struct console *c, int *index)
  2093. {
  2094. *index = c->index ? c->index-1 : fg_console;
  2095. return console_driver;
  2096. }
  2097. static struct console vt_console_driver = {
  2098. .name = "tty",
  2099. .write = vt_console_print,
  2100. .device = vt_console_device,
  2101. .unblank = unblank_screen,
  2102. .flags = CON_PRINTBUFFER,
  2103. .index = -1,
  2104. };
  2105. #endif
  2106. /*
  2107. * Handling of Linux-specific VC ioctls
  2108. */
  2109. /*
  2110. * Generally a bit racy with respect to console_sem().
  2111. *
  2112. * There are some functions which don't need it.
  2113. *
  2114. * There are some functions which can sleep for arbitrary periods
  2115. * (paste_selection) but we don't need the lock there anyway.
  2116. *
  2117. * set_selection has locking, and definitely needs it
  2118. */
  2119. int tioclinux(struct tty_struct *tty, unsigned long arg)
  2120. {
  2121. char type, data;
  2122. char __user *p = (char __user *)arg;
  2123. int lines;
  2124. int ret;
  2125. if (tty->driver->type != TTY_DRIVER_TYPE_CONSOLE)
  2126. return -EINVAL;
  2127. if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN))
  2128. return -EPERM;
  2129. if (get_user(type, p))
  2130. return -EFAULT;
  2131. ret = 0;
  2132. switch (type)
  2133. {
  2134. case TIOCL_SETSEL:
  2135. acquire_console_sem();
  2136. ret = set_selection((struct tiocl_selection __user *)(p+1), tty);
  2137. release_console_sem();
  2138. break;
  2139. case TIOCL_PASTESEL:
  2140. ret = paste_selection(tty);
  2141. break;
  2142. case TIOCL_UNBLANKSCREEN:
  2143. acquire_console_sem();
  2144. unblank_screen();
  2145. release_console_sem();
  2146. break;
  2147. case TIOCL_SELLOADLUT:
  2148. ret = sel_loadlut(p);
  2149. break;
  2150. case TIOCL_GETSHIFTSTATE:
  2151. /*
  2152. * Make it possible to react to Shift+Mousebutton.
  2153. * Note that 'shift_state' is an undocumented
  2154. * kernel-internal variable; programs not closely
  2155. * related to the kernel should not use this.
  2156. */
  2157. data = shift_state;
  2158. ret = __put_user(data, p);
  2159. break;
  2160. case TIOCL_GETMOUSEREPORTING:
  2161. data = mouse_reporting();
  2162. ret = __put_user(data, p);
  2163. break;
  2164. case TIOCL_SETVESABLANK:
  2165. ret = set_vesa_blanking(p);
  2166. break;
  2167. case TIOCL_GETKMSGREDIRECT:
  2168. data = kmsg_redirect;
  2169. ret = __put_user(data, p);
  2170. break;
  2171. case TIOCL_SETKMSGREDIRECT:
  2172. if (!capable(CAP_SYS_ADMIN)) {
  2173. ret = -EPERM;
  2174. } else {
  2175. if (get_user(data, p+1))
  2176. ret = -EFAULT;
  2177. else
  2178. kmsg_redirect = data;
  2179. }
  2180. break;
  2181. case TIOCL_GETFGCONSOLE:
  2182. ret = fg_console;
  2183. break;
  2184. case TIOCL_SCROLLCONSOLE:
  2185. if (get_user(lines, (s32 __user *)(p+4))) {
  2186. ret = -EFAULT;
  2187. } else {
  2188. scrollfront(vc_cons[fg_console].d, lines);
  2189. ret = 0;
  2190. }
  2191. break;
  2192. case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */
  2193. acquire_console_sem();
  2194. ignore_poke = 1;
  2195. do_blank_screen(0);
  2196. release_console_sem();
  2197. break;
  2198. case TIOCL_BLANKEDSCREEN:
  2199. ret = console_blanked;
  2200. break;
  2201. default:
  2202. ret = -EINVAL;
  2203. break;
  2204. }
  2205. return ret;
  2206. }
  2207. /*
  2208. * /dev/ttyN handling
  2209. */
  2210. static int con_write(struct tty_struct *tty, const unsigned char *buf, int count)
  2211. {
  2212. int retval;
  2213. retval = do_con_write(tty, buf, count);
  2214. con_flush_chars(tty);
  2215. return retval;
  2216. }
  2217. static void con_put_char(struct tty_struct *tty, unsigned char ch)
  2218. {
  2219. if (in_interrupt())
  2220. return; /* n_r3964 calls put_char() from interrupt context */
  2221. do_con_write(tty, &ch, 1);
  2222. }
  2223. static int con_write_room(struct tty_struct *tty)
  2224. {
  2225. if (tty->stopped)
  2226. return 0;
  2227. return 4096; /* No limit, really; we're not buffering */
  2228. }
  2229. static int con_chars_in_buffer(struct tty_struct *tty)
  2230. {
  2231. return 0; /* we're not buffering */
  2232. }
  2233. /*
  2234. * con_throttle and con_unthrottle are only used for
  2235. * paste_selection(), which has to stuff in a large number of
  2236. * characters...
  2237. */
  2238. static void con_throttle(struct tty_struct *tty)
  2239. {
  2240. }
  2241. static void con_unthrottle(struct tty_struct *tty)
  2242. {
  2243. struct vc_data *vc = tty->driver_data;
  2244. wake_up_interruptible(&vc->paste_wait);
  2245. }
  2246. /*
  2247. * Turn the Scroll-Lock LED on when the tty is stopped
  2248. */
  2249. static void con_stop(struct tty_struct *tty)
  2250. {
  2251. int console_num;
  2252. if (!tty)
  2253. return;
  2254. console_num = tty->index;
  2255. if (!vc_cons_allocated(console_num))
  2256. return;
  2257. set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
  2258. set_leds();
  2259. }
  2260. /*
  2261. * Turn the Scroll-Lock LED off when the console is started
  2262. */
  2263. static void con_start(struct tty_struct *tty)
  2264. {
  2265. int console_num;
  2266. if (!tty)
  2267. return;
  2268. console_num = tty->index;
  2269. if (!vc_cons_allocated(console_num))
  2270. return;
  2271. clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
  2272. set_leds();
  2273. }
  2274. static void con_flush_chars(struct tty_struct *tty)
  2275. {
  2276. struct vc_data *vc;
  2277. if (in_interrupt()) /* from flush_to_ldisc */
  2278. return;
  2279. /* if we race with con_close(), vt may be null */
  2280. acquire_console_sem();
  2281. vc = tty->driver_data;
  2282. if (vc)
  2283. set_cursor(vc);
  2284. release_console_sem();
  2285. }
  2286. /*
  2287. * Allocate the console screen memory.
  2288. */
  2289. static int con_open(struct tty_struct *tty, struct file *filp)
  2290. {
  2291. unsigned int currcons = tty->index;
  2292. int ret = 0;
  2293. acquire_console_sem();
  2294. if (tty->driver_data == NULL) {
  2295. ret = vc_allocate(currcons);
  2296. if (ret == 0) {
  2297. struct vc_data *vc = vc_cons[currcons].d;
  2298. tty->driver_data = vc;
  2299. vc->vc_tty = tty;
  2300. if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
  2301. tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
  2302. tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
  2303. }
  2304. release_console_sem();
  2305. vcs_make_sysfs(tty);
  2306. return ret;
  2307. }
  2308. }
  2309. release_console_sem();
  2310. return ret;
  2311. }
  2312. /*
  2313. * We take tty_mutex in here to prevent another thread from coming in via init_dev
  2314. * and taking a ref against the tty while we're in the process of forgetting
  2315. * about it and cleaning things up.
  2316. *
  2317. * This is because vcs_remove_sysfs() can sleep and will drop the BKL.
  2318. */
  2319. static void con_close(struct tty_struct *tty, struct file *filp)
  2320. {
  2321. mutex_lock(&tty_mutex);
  2322. acquire_console_sem();
  2323. if (tty && tty->count == 1) {
  2324. struct vc_data *vc = tty->driver_data;
  2325. if (vc)
  2326. vc->vc_tty = NULL;
  2327. tty->driver_data = NULL;
  2328. release_console_sem();
  2329. vcs_remove_sysfs(tty);
  2330. mutex_unlock(&tty_mutex);
  2331. /*
  2332. * tty_mutex is released, but we still hold BKL, so there is
  2333. * still exclusion against init_dev()
  2334. */
  2335. return;
  2336. }
  2337. release_console_sem();
  2338. mutex_unlock(&tty_mutex);
  2339. }
  2340. static void vc_init(struct vc_data *vc, unsigned int rows,
  2341. unsigned int cols, int do_clear)
  2342. {
  2343. int j, k ;
  2344. vc->vc_cols = cols;
  2345. vc->vc_rows = rows;
  2346. vc->vc_size_row = cols << 1;
  2347. vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
  2348. set_origin(vc);
  2349. vc->vc_pos = vc->vc_origin;
  2350. reset_vc(vc);
  2351. for (j=k=0; j<16; j++) {
  2352. vc->vc_palette[k++] = default_red[j] ;
  2353. vc->vc_palette[k++] = default_grn[j] ;
  2354. vc->vc_palette[k++] = default_blu[j] ;
  2355. }
  2356. vc->vc_def_color = 0x07; /* white */
  2357. vc->vc_ulcolor = 0x0f; /* bold white */
  2358. vc->vc_halfcolor = 0x08; /* grey */
  2359. init_waitqueue_head(&vc->paste_wait);
  2360. reset_terminal(vc, do_clear);
  2361. }
  2362. /*
  2363. * This routine initializes console interrupts, and does nothing
  2364. * else. If you want the screen to clear, call tty_write with
  2365. * the appropriate escape-sequence.
  2366. */
  2367. static int __init con_init(void)
  2368. {
  2369. const char *display_desc = NULL;
  2370. struct vc_data *vc;
  2371. unsigned int currcons = 0, i;
  2372. acquire_console_sem();
  2373. if (conswitchp)
  2374. display_desc = conswitchp->con_startup();
  2375. if (!display_desc) {
  2376. fg_console = 0;
  2377. release_console_sem();
  2378. return 0;
  2379. }
  2380. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2381. struct con_driver *con_driver = &registered_con_driver[i];
  2382. if (con_driver->con == NULL) {
  2383. con_driver->con = conswitchp;
  2384. con_driver->desc = display_desc;
  2385. con_driver->flag = CON_DRIVER_FLAG_INIT;
  2386. con_driver->first = 0;
  2387. con_driver->last = MAX_NR_CONSOLES - 1;
  2388. break;
  2389. }
  2390. }
  2391. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2392. con_driver_map[i] = conswitchp;
  2393. init_timer(&console_timer);
  2394. console_timer.function = blank_screen_t;
  2395. if (blankinterval) {
  2396. blank_state = blank_normal_wait;
  2397. mod_timer(&console_timer, jiffies + blankinterval);
  2398. }
  2399. /*
  2400. * kmalloc is not running yet - we use the bootmem allocator.
  2401. */
  2402. for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
  2403. vc_cons[currcons].d = vc = alloc_bootmem(sizeof(struct vc_data));
  2404. visual_init(vc, currcons, 1);
  2405. vc->vc_screenbuf = (unsigned short *)alloc_bootmem(vc->vc_screenbuf_size);
  2406. vc->vc_kmalloced = 0;
  2407. vc_init(vc, vc->vc_rows, vc->vc_cols,
  2408. currcons || !vc->vc_sw->con_save_screen);
  2409. }
  2410. currcons = fg_console = 0;
  2411. master_display_fg = vc = vc_cons[currcons].d;
  2412. set_origin(vc);
  2413. save_screen(vc);
  2414. gotoxy(vc, vc->vc_x, vc->vc_y);
  2415. csi_J(vc, 0);
  2416. update_screen(vc);
  2417. printk("Console: %s %s %dx%d",
  2418. vc->vc_can_do_color ? "colour" : "mono",
  2419. display_desc, vc->vc_cols, vc->vc_rows);
  2420. printable = 1;
  2421. printk("\n");
  2422. release_console_sem();
  2423. #ifdef CONFIG_VT_CONSOLE
  2424. register_console(&vt_console_driver);
  2425. #endif
  2426. return 0;
  2427. }
  2428. console_initcall(con_init);
  2429. static const struct tty_operations con_ops = {
  2430. .open = con_open,
  2431. .close = con_close,
  2432. .write = con_write,
  2433. .write_room = con_write_room,
  2434. .put_char = con_put_char,
  2435. .flush_chars = con_flush_chars,
  2436. .chars_in_buffer = con_chars_in_buffer,
  2437. .ioctl = vt_ioctl,
  2438. .stop = con_stop,
  2439. .start = con_start,
  2440. .throttle = con_throttle,
  2441. .unthrottle = con_unthrottle,
  2442. };
  2443. int __init vty_init(void)
  2444. {
  2445. vcs_init();
  2446. console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
  2447. if (!console_driver)
  2448. panic("Couldn't allocate console driver\n");
  2449. console_driver->owner = THIS_MODULE;
  2450. console_driver->name = "tty";
  2451. console_driver->name_base = 1;
  2452. console_driver->major = TTY_MAJOR;
  2453. console_driver->minor_start = 1;
  2454. console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
  2455. console_driver->init_termios = tty_std_termios;
  2456. console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
  2457. tty_set_operations(console_driver, &con_ops);
  2458. if (tty_register_driver(console_driver))
  2459. panic("Couldn't register console driver\n");
  2460. kbd_init();
  2461. console_map_init();
  2462. #ifdef CONFIG_PROM_CONSOLE
  2463. prom_con_init();
  2464. #endif
  2465. #ifdef CONFIG_MDA_CONSOLE
  2466. mda_console_init();
  2467. #endif
  2468. return 0;
  2469. }
  2470. #ifndef VT_SINGLE_DRIVER
  2471. #include <linux/device.h>
  2472. static struct class *vtconsole_class;
  2473. static int bind_con_driver(const struct consw *csw, int first, int last,
  2474. int deflt)
  2475. {
  2476. struct module *owner = csw->owner;
  2477. const char *desc = NULL;
  2478. struct con_driver *con_driver;
  2479. int i, j = -1, k = -1, retval = -ENODEV;
  2480. if (!try_module_get(owner))
  2481. return -ENODEV;
  2482. acquire_console_sem();
  2483. /* check if driver is registered */
  2484. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2485. con_driver = &registered_con_driver[i];
  2486. if (con_driver->con == csw) {
  2487. desc = con_driver->desc;
  2488. retval = 0;
  2489. break;
  2490. }
  2491. }
  2492. if (retval)
  2493. goto err;
  2494. if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
  2495. csw->con_startup();
  2496. con_driver->flag |= CON_DRIVER_FLAG_INIT;
  2497. }
  2498. if (deflt) {
  2499. if (conswitchp)
  2500. module_put(conswitchp->owner);
  2501. __module_get(owner);
  2502. conswitchp = csw;
  2503. }
  2504. first = max(first, con_driver->first);
  2505. last = min(last, con_driver->last);
  2506. for (i = first; i <= last; i++) {
  2507. int old_was_color;
  2508. struct vc_data *vc = vc_cons[i].d;
  2509. if (con_driver_map[i])
  2510. module_put(con_driver_map[i]->owner);
  2511. __module_get(owner);
  2512. con_driver_map[i] = csw;
  2513. if (!vc || !vc->vc_sw)
  2514. continue;
  2515. j = i;
  2516. if (CON_IS_VISIBLE(vc)) {
  2517. k = i;
  2518. save_screen(vc);
  2519. }
  2520. old_was_color = vc->vc_can_do_color;
  2521. vc->vc_sw->con_deinit(vc);
  2522. vc->vc_origin = (unsigned long)vc->vc_screenbuf;
  2523. visual_init(vc, i, 0);
  2524. set_origin(vc);
  2525. update_attr(vc);
  2526. /* If the console changed between mono <-> color, then
  2527. * the attributes in the screenbuf will be wrong. The
  2528. * following resets all attributes to something sane.
  2529. */
  2530. if (old_was_color != vc->vc_can_do_color)
  2531. clear_buffer_attributes(vc);
  2532. }
  2533. printk("Console: switching ");
  2534. if (!deflt)
  2535. printk("consoles %d-%d ", first+1, last+1);
  2536. if (j >= 0) {
  2537. struct vc_data *vc = vc_cons[j].d;
  2538. printk("to %s %s %dx%d\n",
  2539. vc->vc_can_do_color ? "colour" : "mono",
  2540. desc, vc->vc_cols, vc->vc_rows);
  2541. if (k >= 0) {
  2542. vc = vc_cons[k].d;
  2543. update_screen(vc);
  2544. }
  2545. } else
  2546. printk("to %s\n", desc);
  2547. retval = 0;
  2548. err:
  2549. release_console_sem();
  2550. module_put(owner);
  2551. return retval;
  2552. };
  2553. #ifdef CONFIG_VT_HW_CONSOLE_BINDING
  2554. static int con_is_graphics(const struct consw *csw, int first, int last)
  2555. {
  2556. int i, retval = 0;
  2557. for (i = first; i <= last; i++) {
  2558. struct vc_data *vc = vc_cons[i].d;
  2559. if (vc && vc->vc_mode == KD_GRAPHICS) {
  2560. retval = 1;
  2561. break;
  2562. }
  2563. }
  2564. return retval;
  2565. }
  2566. static int unbind_con_driver(const struct consw *csw, int first, int last,
  2567. int deflt)
  2568. {
  2569. struct module *owner = csw->owner;
  2570. const struct consw *defcsw = NULL;
  2571. struct con_driver *con_driver = NULL, *con_back = NULL;
  2572. int i, retval = -ENODEV;
  2573. if (!try_module_get(owner))
  2574. return -ENODEV;
  2575. acquire_console_sem();
  2576. /* check if driver is registered and if it is unbindable */
  2577. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2578. con_driver = &registered_con_driver[i];
  2579. if (con_driver->con == csw &&
  2580. con_driver->flag & CON_DRIVER_FLAG_MODULE) {
  2581. retval = 0;
  2582. break;
  2583. }
  2584. }
  2585. if (retval) {
  2586. release_console_sem();
  2587. goto err;
  2588. }
  2589. retval = -ENODEV;
  2590. /* check if backup driver exists */
  2591. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2592. con_back = &registered_con_driver[i];
  2593. if (con_back->con &&
  2594. !(con_back->flag & CON_DRIVER_FLAG_MODULE)) {
  2595. defcsw = con_back->con;
  2596. retval = 0;
  2597. break;
  2598. }
  2599. }
  2600. if (retval) {
  2601. release_console_sem();
  2602. goto err;
  2603. }
  2604. if (!con_is_bound(csw)) {
  2605. release_console_sem();
  2606. goto err;
  2607. }
  2608. first = max(first, con_driver->first);
  2609. last = min(last, con_driver->last);
  2610. for (i = first; i <= last; i++) {
  2611. if (con_driver_map[i] == csw) {
  2612. module_put(csw->owner);
  2613. con_driver_map[i] = NULL;
  2614. }
  2615. }
  2616. if (!con_is_bound(defcsw)) {
  2617. const struct consw *defconsw = conswitchp;
  2618. defcsw->con_startup();
  2619. con_back->flag |= CON_DRIVER_FLAG_INIT;
  2620. /*
  2621. * vgacon may change the default driver to point
  2622. * to dummycon, we restore it here...
  2623. */
  2624. conswitchp = defconsw;
  2625. }
  2626. if (!con_is_bound(csw))
  2627. con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
  2628. release_console_sem();
  2629. /* ignore return value, binding should not fail */
  2630. bind_con_driver(defcsw, first, last, deflt);
  2631. err:
  2632. module_put(owner);
  2633. return retval;
  2634. }
  2635. static int vt_bind(struct con_driver *con)
  2636. {
  2637. const struct consw *defcsw = NULL, *csw = NULL;
  2638. int i, more = 1, first = -1, last = -1, deflt = 0;
  2639. if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) ||
  2640. con_is_graphics(con->con, con->first, con->last))
  2641. goto err;
  2642. csw = con->con;
  2643. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2644. struct con_driver *con = &registered_con_driver[i];
  2645. if (con->con && !(con->flag & CON_DRIVER_FLAG_MODULE)) {
  2646. defcsw = con->con;
  2647. break;
  2648. }
  2649. }
  2650. if (!defcsw)
  2651. goto err;
  2652. while (more) {
  2653. more = 0;
  2654. for (i = con->first; i <= con->last; i++) {
  2655. if (con_driver_map[i] == defcsw) {
  2656. if (first == -1)
  2657. first = i;
  2658. last = i;
  2659. more = 1;
  2660. } else if (first != -1)
  2661. break;
  2662. }
  2663. if (first == 0 && last == MAX_NR_CONSOLES -1)
  2664. deflt = 1;
  2665. if (first != -1)
  2666. bind_con_driver(csw, first, last, deflt);
  2667. first = -1;
  2668. last = -1;
  2669. deflt = 0;
  2670. }
  2671. err:
  2672. return 0;
  2673. }
  2674. static int vt_unbind(struct con_driver *con)
  2675. {
  2676. const struct consw *csw = NULL;
  2677. int i, more = 1, first = -1, last = -1, deflt = 0;
  2678. if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) ||
  2679. con_is_graphics(con->con, con->first, con->last))
  2680. goto err;
  2681. csw = con->con;
  2682. while (more) {
  2683. more = 0;
  2684. for (i = con->first; i <= con->last; i++) {
  2685. if (con_driver_map[i] == csw) {
  2686. if (first == -1)
  2687. first = i;
  2688. last = i;
  2689. more = 1;
  2690. } else if (first != -1)
  2691. break;
  2692. }
  2693. if (first == 0 && last == MAX_NR_CONSOLES -1)
  2694. deflt = 1;
  2695. if (first != -1)
  2696. unbind_con_driver(csw, first, last, deflt);
  2697. first = -1;
  2698. last = -1;
  2699. deflt = 0;
  2700. }
  2701. err:
  2702. return 0;
  2703. }
  2704. #else
  2705. static inline int vt_bind(struct con_driver *con)
  2706. {
  2707. return 0;
  2708. }
  2709. static inline int vt_unbind(struct con_driver *con)
  2710. {
  2711. return 0;
  2712. }
  2713. #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
  2714. static ssize_t store_bind(struct device *dev, struct device_attribute *attr,
  2715. const char *buf, size_t count)
  2716. {
  2717. struct con_driver *con = dev_get_drvdata(dev);
  2718. int bind = simple_strtoul(buf, NULL, 0);
  2719. if (bind)
  2720. vt_bind(con);
  2721. else
  2722. vt_unbind(con);
  2723. return count;
  2724. }
  2725. static ssize_t show_bind(struct device *dev, struct device_attribute *attr,
  2726. char *buf)
  2727. {
  2728. struct con_driver *con = dev_get_drvdata(dev);
  2729. int bind = con_is_bound(con->con);
  2730. return snprintf(buf, PAGE_SIZE, "%i\n", bind);
  2731. }
  2732. static ssize_t show_name(struct device *dev, struct device_attribute *attr,
  2733. char *buf)
  2734. {
  2735. struct con_driver *con = dev_get_drvdata(dev);
  2736. return snprintf(buf, PAGE_SIZE, "%s %s\n",
  2737. (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)",
  2738. con->desc);
  2739. }
  2740. static struct device_attribute device_attrs[] = {
  2741. __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind),
  2742. __ATTR(name, S_IRUGO, show_name, NULL),
  2743. };
  2744. static int vtconsole_init_device(struct con_driver *con)
  2745. {
  2746. int i;
  2747. int error = 0;
  2748. con->flag |= CON_DRIVER_FLAG_ATTR;
  2749. dev_set_drvdata(con->dev, con);
  2750. for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
  2751. error = device_create_file(con->dev, &device_attrs[i]);
  2752. if (error)
  2753. break;
  2754. }
  2755. if (error) {
  2756. while (--i >= 0)
  2757. device_remove_file(con->dev, &device_attrs[i]);
  2758. con->flag &= ~CON_DRIVER_FLAG_ATTR;
  2759. }
  2760. return error;
  2761. }
  2762. static void vtconsole_deinit_device(struct con_driver *con)
  2763. {
  2764. int i;
  2765. if (con->flag & CON_DRIVER_FLAG_ATTR) {
  2766. for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
  2767. device_remove_file(con->dev, &device_attrs[i]);
  2768. con->flag &= ~CON_DRIVER_FLAG_ATTR;
  2769. }
  2770. }
  2771. /**
  2772. * con_is_bound - checks if driver is bound to the console
  2773. * @csw: console driver
  2774. *
  2775. * RETURNS: zero if unbound, nonzero if bound
  2776. *
  2777. * Drivers can call this and if zero, they should release
  2778. * all resources allocated on con_startup()
  2779. */
  2780. int con_is_bound(const struct consw *csw)
  2781. {
  2782. int i, bound = 0;
  2783. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  2784. if (con_driver_map[i] == csw) {
  2785. bound = 1;
  2786. break;
  2787. }
  2788. }
  2789. return bound;
  2790. }
  2791. EXPORT_SYMBOL(con_is_bound);
  2792. /**
  2793. * register_con_driver - register console driver to console layer
  2794. * @csw: console driver
  2795. * @first: the first console to take over, minimum value is 0
  2796. * @last: the last console to take over, maximum value is MAX_NR_CONSOLES -1
  2797. *
  2798. * DESCRIPTION: This function registers a console driver which can later
  2799. * bind to a range of consoles specified by @first and @last. It will
  2800. * also initialize the console driver by calling con_startup().
  2801. */
  2802. int register_con_driver(const struct consw *csw, int first, int last)
  2803. {
  2804. struct module *owner = csw->owner;
  2805. struct con_driver *con_driver;
  2806. const char *desc;
  2807. int i, retval = 0;
  2808. if (!try_module_get(owner))
  2809. return -ENODEV;
  2810. acquire_console_sem();
  2811. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2812. con_driver = &registered_con_driver[i];
  2813. /* already registered */
  2814. if (con_driver->con == csw)
  2815. retval = -EINVAL;
  2816. }
  2817. if (retval)
  2818. goto err;
  2819. desc = csw->con_startup();
  2820. if (!desc)
  2821. goto err;
  2822. retval = -EINVAL;
  2823. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2824. con_driver = &registered_con_driver[i];
  2825. if (con_driver->con == NULL) {
  2826. con_driver->con = csw;
  2827. con_driver->desc = desc;
  2828. con_driver->node = i;
  2829. con_driver->flag = CON_DRIVER_FLAG_MODULE |
  2830. CON_DRIVER_FLAG_INIT;
  2831. con_driver->first = first;
  2832. con_driver->last = last;
  2833. retval = 0;
  2834. break;
  2835. }
  2836. }
  2837. if (retval)
  2838. goto err;
  2839. con_driver->dev = device_create(vtconsole_class, NULL,
  2840. MKDEV(0, con_driver->node),
  2841. "vtcon%i", con_driver->node);
  2842. if (IS_ERR(con_driver->dev)) {
  2843. printk(KERN_WARNING "Unable to create device for %s; "
  2844. "errno = %ld\n", con_driver->desc,
  2845. PTR_ERR(con_driver->dev));
  2846. con_driver->dev = NULL;
  2847. } else {
  2848. vtconsole_init_device(con_driver);
  2849. }
  2850. err:
  2851. release_console_sem();
  2852. module_put(owner);
  2853. return retval;
  2854. }
  2855. EXPORT_SYMBOL(register_con_driver);
  2856. /**
  2857. * unregister_con_driver - unregister console driver from console layer
  2858. * @csw: console driver
  2859. *
  2860. * DESCRIPTION: All drivers that registers to the console layer must
  2861. * call this function upon exit, or if the console driver is in a state
  2862. * where it won't be able to handle console services, such as the
  2863. * framebuffer console without loaded framebuffer drivers.
  2864. *
  2865. * The driver must unbind first prior to unregistration.
  2866. */
  2867. int unregister_con_driver(const struct consw *csw)
  2868. {
  2869. int i, retval = -ENODEV;
  2870. acquire_console_sem();
  2871. /* cannot unregister a bound driver */
  2872. if (con_is_bound(csw))
  2873. goto err;
  2874. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2875. struct con_driver *con_driver = &registered_con_driver[i];
  2876. if (con_driver->con == csw &&
  2877. con_driver->flag & CON_DRIVER_FLAG_MODULE) {
  2878. vtconsole_deinit_device(con_driver);
  2879. device_destroy(vtconsole_class,
  2880. MKDEV(0, con_driver->node));
  2881. con_driver->con = NULL;
  2882. con_driver->desc = NULL;
  2883. con_driver->dev = NULL;
  2884. con_driver->node = 0;
  2885. con_driver->flag = 0;
  2886. con_driver->first = 0;
  2887. con_driver->last = 0;
  2888. retval = 0;
  2889. break;
  2890. }
  2891. }
  2892. err:
  2893. release_console_sem();
  2894. return retval;
  2895. }
  2896. EXPORT_SYMBOL(unregister_con_driver);
  2897. /*
  2898. * If we support more console drivers, this function is used
  2899. * when a driver wants to take over some existing consoles
  2900. * and become default driver for newly opened ones.
  2901. *
  2902. * take_over_console is basically a register followed by unbind
  2903. */
  2904. int take_over_console(const struct consw *csw, int first, int last, int deflt)
  2905. {
  2906. int err;
  2907. err = register_con_driver(csw, first, last);
  2908. if (!err)
  2909. bind_con_driver(csw, first, last, deflt);
  2910. return err;
  2911. }
  2912. /*
  2913. * give_up_console is a wrapper to unregister_con_driver. It will only
  2914. * work if driver is fully unbound.
  2915. */
  2916. void give_up_console(const struct consw *csw)
  2917. {
  2918. unregister_con_driver(csw);
  2919. }
  2920. static int __init vtconsole_class_init(void)
  2921. {
  2922. int i;
  2923. vtconsole_class = class_create(THIS_MODULE, "vtconsole");
  2924. if (IS_ERR(vtconsole_class)) {
  2925. printk(KERN_WARNING "Unable to create vt console class; "
  2926. "errno = %ld\n", PTR_ERR(vtconsole_class));
  2927. vtconsole_class = NULL;
  2928. }
  2929. /* Add system drivers to sysfs */
  2930. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2931. struct con_driver *con = &registered_con_driver[i];
  2932. if (con->con && !con->dev) {
  2933. con->dev = device_create(vtconsole_class, NULL,
  2934. MKDEV(0, con->node),
  2935. "vtcon%i", con->node);
  2936. if (IS_ERR(con->dev)) {
  2937. printk(KERN_WARNING "Unable to create "
  2938. "device for %s; errno = %ld\n",
  2939. con->desc, PTR_ERR(con->dev));
  2940. con->dev = NULL;
  2941. } else {
  2942. vtconsole_init_device(con);
  2943. }
  2944. }
  2945. }
  2946. return 0;
  2947. }
  2948. postcore_initcall(vtconsole_class_init);
  2949. #endif
  2950. /*
  2951. * Screen blanking
  2952. */
  2953. static int set_vesa_blanking(char __user *p)
  2954. {
  2955. unsigned int mode;
  2956. if (get_user(mode, p + 1))
  2957. return -EFAULT;
  2958. vesa_blank_mode = (mode < 4) ? mode : 0;
  2959. return 0;
  2960. }
  2961. void do_blank_screen(int entering_gfx)
  2962. {
  2963. struct vc_data *vc = vc_cons[fg_console].d;
  2964. int i;
  2965. WARN_CONSOLE_UNLOCKED();
  2966. if (console_blanked) {
  2967. if (blank_state == blank_vesa_wait) {
  2968. blank_state = blank_off;
  2969. vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
  2970. }
  2971. return;
  2972. }
  2973. if (blank_state != blank_normal_wait)
  2974. return;
  2975. blank_state = blank_off;
  2976. /* entering graphics mode? */
  2977. if (entering_gfx) {
  2978. hide_cursor(vc);
  2979. save_screen(vc);
  2980. vc->vc_sw->con_blank(vc, -1, 1);
  2981. console_blanked = fg_console + 1;
  2982. set_origin(vc);
  2983. return;
  2984. }
  2985. /* don't blank graphics */
  2986. if (vc->vc_mode != KD_TEXT) {
  2987. console_blanked = fg_console + 1;
  2988. return;
  2989. }
  2990. hide_cursor(vc);
  2991. del_timer_sync(&console_timer);
  2992. blank_timer_expired = 0;
  2993. save_screen(vc);
  2994. /* In case we need to reset origin, blanking hook returns 1 */
  2995. i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0);
  2996. console_blanked = fg_console + 1;
  2997. if (i)
  2998. set_origin(vc);
  2999. if (console_blank_hook && console_blank_hook(1))
  3000. return;
  3001. if (vesa_off_interval && vesa_blank_mode) {
  3002. blank_state = blank_vesa_wait;
  3003. mod_timer(&console_timer, jiffies + vesa_off_interval);
  3004. }
  3005. }
  3006. EXPORT_SYMBOL(do_blank_screen);
  3007. /*
  3008. * Called by timer as well as from vt_console_driver
  3009. */
  3010. void do_unblank_screen(int leaving_gfx)
  3011. {
  3012. struct vc_data *vc;
  3013. /* This should now always be called from a "sane" (read: can schedule)
  3014. * context for the sake of the low level drivers, except in the special
  3015. * case of oops_in_progress
  3016. */
  3017. if (!oops_in_progress)
  3018. might_sleep();
  3019. WARN_CONSOLE_UNLOCKED();
  3020. ignore_poke = 0;
  3021. if (!console_blanked)
  3022. return;
  3023. if (!vc_cons_allocated(fg_console)) {
  3024. /* impossible */
  3025. printk("unblank_screen: tty %d not allocated ??\n", fg_console+1);
  3026. return;
  3027. }
  3028. vc = vc_cons[fg_console].d;
  3029. if (vc->vc_mode != KD_TEXT)
  3030. return; /* but leave console_blanked != 0 */
  3031. if (blankinterval) {
  3032. mod_timer(&console_timer, jiffies + blankinterval);
  3033. blank_state = blank_normal_wait;
  3034. }
  3035. console_blanked = 0;
  3036. if (vc->vc_sw->con_blank(vc, 0, leaving_gfx))
  3037. /* Low-level driver cannot restore -> do it ourselves */
  3038. update_screen(vc);
  3039. if (console_blank_hook)
  3040. console_blank_hook(0);
  3041. set_palette(vc);
  3042. set_cursor(vc);
  3043. }
  3044. EXPORT_SYMBOL(do_unblank_screen);
  3045. /*
  3046. * This is called by the outside world to cause a forced unblank, mostly for
  3047. * oopses. Currently, I just call do_unblank_screen(0), but we could eventually
  3048. * call it with 1 as an argument and so force a mode restore... that may kill
  3049. * X or at least garbage the screen but would also make the Oops visible...
  3050. */
  3051. void unblank_screen(void)
  3052. {
  3053. do_unblank_screen(0);
  3054. }
  3055. /*
  3056. * We defer the timer blanking to work queue so it can take the console mutex
  3057. * (console operations can still happen at irq time, but only from printk which
  3058. * has the console mutex. Not perfect yet, but better than no locking
  3059. */
  3060. static void blank_screen_t(unsigned long dummy)
  3061. {
  3062. if (unlikely(!keventd_up())) {
  3063. mod_timer(&console_timer, jiffies + blankinterval);
  3064. return;
  3065. }
  3066. blank_timer_expired = 1;
  3067. schedule_work(&console_work);
  3068. }
  3069. void poke_blanked_console(void)
  3070. {
  3071. WARN_CONSOLE_UNLOCKED();
  3072. /* Add this so we quickly catch whoever might call us in a non
  3073. * safe context. Nowadays, unblank_screen() isn't to be called in
  3074. * atomic contexts and is allowed to schedule (with the special case
  3075. * of oops_in_progress, but that isn't of any concern for this
  3076. * function. --BenH.
  3077. */
  3078. might_sleep();
  3079. /* This isn't perfectly race free, but a race here would be mostly harmless,
  3080. * at worse, we'll do a spurrious blank and it's unlikely
  3081. */
  3082. del_timer(&console_timer);
  3083. blank_timer_expired = 0;
  3084. if (ignore_poke || !vc_cons[fg_console].d || vc_cons[fg_console].d->vc_mode == KD_GRAPHICS)
  3085. return;
  3086. if (console_blanked)
  3087. unblank_screen();
  3088. else if (blankinterval) {
  3089. mod_timer(&console_timer, jiffies + blankinterval);
  3090. blank_state = blank_normal_wait;
  3091. }
  3092. }
  3093. /*
  3094. * Palettes
  3095. */
  3096. static void set_palette(struct vc_data *vc)
  3097. {
  3098. WARN_CONSOLE_UNLOCKED();
  3099. if (vc->vc_mode != KD_GRAPHICS)
  3100. vc->vc_sw->con_set_palette(vc, color_table);
  3101. }
  3102. static int set_get_cmap(unsigned char __user *arg, int set)
  3103. {
  3104. int i, j, k;
  3105. WARN_CONSOLE_UNLOCKED();
  3106. for (i = 0; i < 16; i++)
  3107. if (set) {
  3108. get_user(default_red[i], arg++);
  3109. get_user(default_grn[i], arg++);
  3110. get_user(default_blu[i], arg++);
  3111. } else {
  3112. put_user(default_red[i], arg++);
  3113. put_user(default_grn[i], arg++);
  3114. put_user(default_blu[i], arg++);
  3115. }
  3116. if (set) {
  3117. for (i = 0; i < MAX_NR_CONSOLES; i++)
  3118. if (vc_cons_allocated(i)) {
  3119. for (j = k = 0; j < 16; j++) {
  3120. vc_cons[i].d->vc_palette[k++] = default_red[j];
  3121. vc_cons[i].d->vc_palette[k++] = default_grn[j];
  3122. vc_cons[i].d->vc_palette[k++] = default_blu[j];
  3123. }
  3124. set_palette(vc_cons[i].d);
  3125. }
  3126. }
  3127. return 0;
  3128. }
  3129. /*
  3130. * Load palette into the DAC registers. arg points to a colour
  3131. * map, 3 bytes per colour, 16 colours, range from 0 to 255.
  3132. */
  3133. int con_set_cmap(unsigned char __user *arg)
  3134. {
  3135. int rc;
  3136. acquire_console_sem();
  3137. rc = set_get_cmap (arg,1);
  3138. release_console_sem();
  3139. return rc;
  3140. }
  3141. int con_get_cmap(unsigned char __user *arg)
  3142. {
  3143. int rc;
  3144. acquire_console_sem();
  3145. rc = set_get_cmap (arg,0);
  3146. release_console_sem();
  3147. return rc;
  3148. }
  3149. void reset_palette(struct vc_data *vc)
  3150. {
  3151. int j, k;
  3152. for (j=k=0; j<16; j++) {
  3153. vc->vc_palette[k++] = default_red[j];
  3154. vc->vc_palette[k++] = default_grn[j];
  3155. vc->vc_palette[k++] = default_blu[j];
  3156. }
  3157. set_palette(vc);
  3158. }
  3159. /*
  3160. * Font switching
  3161. *
  3162. * Currently we only support fonts up to 32 pixels wide, at a maximum height
  3163. * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,
  3164. * depending on width) reserved for each character which is kinda wasty, but
  3165. * this is done in order to maintain compatibility with the EGA/VGA fonts. It
  3166. * is upto the actual low-level console-driver convert data into its favorite
  3167. * format (maybe we should add a `fontoffset' field to the `display'
  3168. * structure so we won't have to convert the fontdata all the time.
  3169. * /Jes
  3170. */
  3171. #define max_font_size 65536
  3172. static int con_font_get(struct vc_data *vc, struct console_font_op *op)
  3173. {
  3174. struct console_font font;
  3175. int rc = -EINVAL;
  3176. int c;
  3177. if (vc->vc_mode != KD_TEXT)
  3178. return -EINVAL;
  3179. if (op->data) {
  3180. font.data = kmalloc(max_font_size, GFP_KERNEL);
  3181. if (!font.data)
  3182. return -ENOMEM;
  3183. } else
  3184. font.data = NULL;
  3185. acquire_console_sem();
  3186. if (vc->vc_sw->con_font_get)
  3187. rc = vc->vc_sw->con_font_get(vc, &font);
  3188. else
  3189. rc = -ENOSYS;
  3190. release_console_sem();
  3191. if (rc)
  3192. goto out;
  3193. c = (font.width+7)/8 * 32 * font.charcount;
  3194. if (op->data && font.charcount > op->charcount)
  3195. rc = -ENOSPC;
  3196. if (!(op->flags & KD_FONT_FLAG_OLD)) {
  3197. if (font.width > op->width || font.height > op->height)
  3198. rc = -ENOSPC;
  3199. } else {
  3200. if (font.width != 8)
  3201. rc = -EIO;
  3202. else if ((op->height && font.height > op->height) ||
  3203. font.height > 32)
  3204. rc = -ENOSPC;
  3205. }
  3206. if (rc)
  3207. goto out;
  3208. op->height = font.height;
  3209. op->width = font.width;
  3210. op->charcount = font.charcount;
  3211. if (op->data && copy_to_user(op->data, font.data, c))
  3212. rc = -EFAULT;
  3213. out:
  3214. kfree(font.data);
  3215. return rc;
  3216. }
  3217. static int con_font_set(struct vc_data *vc, struct console_font_op *op)
  3218. {
  3219. struct console_font font;
  3220. int rc = -EINVAL;
  3221. int size;
  3222. if (vc->vc_mode != KD_TEXT)
  3223. return -EINVAL;
  3224. if (!op->data)
  3225. return -EINVAL;
  3226. if (op->charcount > 512)
  3227. return -EINVAL;
  3228. if (!op->height) { /* Need to guess font height [compat] */
  3229. int h, i;
  3230. u8 __user *charmap = op->data;
  3231. u8 tmp;
  3232. /* If from KDFONTOP ioctl, don't allow things which can be done in userland,
  3233. so that we can get rid of this soon */
  3234. if (!(op->flags & KD_FONT_FLAG_OLD))
  3235. return -EINVAL;
  3236. for (h = 32; h > 0; h--)
  3237. for (i = 0; i < op->charcount; i++) {
  3238. if (get_user(tmp, &charmap[32*i+h-1]))
  3239. return -EFAULT;
  3240. if (tmp)
  3241. goto nonzero;
  3242. }
  3243. return -EINVAL;
  3244. nonzero:
  3245. op->height = h;
  3246. }
  3247. if (op->width <= 0 || op->width > 32 || op->height > 32)
  3248. return -EINVAL;
  3249. size = (op->width+7)/8 * 32 * op->charcount;
  3250. if (size > max_font_size)
  3251. return -ENOSPC;
  3252. font.charcount = op->charcount;
  3253. font.height = op->height;
  3254. font.width = op->width;
  3255. font.data = kmalloc(size, GFP_KERNEL);
  3256. if (!font.data)
  3257. return -ENOMEM;
  3258. if (copy_from_user(font.data, op->data, size)) {
  3259. kfree(font.data);
  3260. return -EFAULT;
  3261. }
  3262. acquire_console_sem();
  3263. if (vc->vc_sw->con_font_set)
  3264. rc = vc->vc_sw->con_font_set(vc, &font, op->flags);
  3265. else
  3266. rc = -ENOSYS;
  3267. release_console_sem();
  3268. kfree(font.data);
  3269. return rc;
  3270. }
  3271. static int con_font_default(struct vc_data *vc, struct console_font_op *op)
  3272. {
  3273. struct console_font font = {.width = op->width, .height = op->height};
  3274. char name[MAX_FONT_NAME];
  3275. char *s = name;
  3276. int rc;
  3277. if (vc->vc_mode != KD_TEXT)
  3278. return -EINVAL;
  3279. if (!op->data)
  3280. s = NULL;
  3281. else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0)
  3282. return -EFAULT;
  3283. else
  3284. name[MAX_FONT_NAME - 1] = 0;
  3285. acquire_console_sem();
  3286. if (vc->vc_sw->con_font_default)
  3287. rc = vc->vc_sw->con_font_default(vc, &font, s);
  3288. else
  3289. rc = -ENOSYS;
  3290. release_console_sem();
  3291. if (!rc) {
  3292. op->width = font.width;
  3293. op->height = font.height;
  3294. }
  3295. return rc;
  3296. }
  3297. static int con_font_copy(struct vc_data *vc, struct console_font_op *op)
  3298. {
  3299. int con = op->height;
  3300. int rc;
  3301. if (vc->vc_mode != KD_TEXT)
  3302. return -EINVAL;
  3303. acquire_console_sem();
  3304. if (!vc->vc_sw->con_font_copy)
  3305. rc = -ENOSYS;
  3306. else if (con < 0 || !vc_cons_allocated(con))
  3307. rc = -ENOTTY;
  3308. else if (con == vc->vc_num) /* nothing to do */
  3309. rc = 0;
  3310. else
  3311. rc = vc->vc_sw->con_font_copy(vc, con);
  3312. release_console_sem();
  3313. return rc;
  3314. }
  3315. int con_font_op(struct vc_data *vc, struct console_font_op *op)
  3316. {
  3317. switch (op->op) {
  3318. case KD_FONT_OP_SET:
  3319. return con_font_set(vc, op);
  3320. case KD_FONT_OP_GET:
  3321. return con_font_get(vc, op);
  3322. case KD_FONT_OP_SET_DEFAULT:
  3323. return con_font_default(vc, op);
  3324. case KD_FONT_OP_COPY:
  3325. return con_font_copy(vc, op);
  3326. }
  3327. return -ENOSYS;
  3328. }
  3329. /*
  3330. * Interface exported to selection and vcs.
  3331. */
  3332. /* used by selection */
  3333. u16 screen_glyph(struct vc_data *vc, int offset)
  3334. {
  3335. u16 w = scr_readw(screenpos(vc, offset, 1));
  3336. u16 c = w & 0xff;
  3337. if (w & vc->vc_hi_font_mask)
  3338. c |= 0x100;
  3339. return c;
  3340. }
  3341. /* used by vcs - note the word offset */
  3342. unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
  3343. {
  3344. return screenpos(vc, 2 * w_offset, viewed);
  3345. }
  3346. void getconsxy(struct vc_data *vc, unsigned char *p)
  3347. {
  3348. p[0] = vc->vc_x;
  3349. p[1] = vc->vc_y;
  3350. }
  3351. void putconsxy(struct vc_data *vc, unsigned char *p)
  3352. {
  3353. hide_cursor(vc);
  3354. gotoxy(vc, p[0], p[1]);
  3355. set_cursor(vc);
  3356. }
  3357. u16 vcs_scr_readw(struct vc_data *vc, const u16 *org)
  3358. {
  3359. if ((unsigned long)org == vc->vc_pos && softcursor_original != -1)
  3360. return softcursor_original;
  3361. return scr_readw(org);
  3362. }
  3363. void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
  3364. {
  3365. scr_writew(val, org);
  3366. if ((unsigned long)org == vc->vc_pos) {
  3367. softcursor_original = -1;
  3368. add_softcursor(vc);
  3369. }
  3370. }
  3371. /*
  3372. * Visible symbols for modules
  3373. */
  3374. EXPORT_SYMBOL(color_table);
  3375. EXPORT_SYMBOL(default_red);
  3376. EXPORT_SYMBOL(default_grn);
  3377. EXPORT_SYMBOL(default_blu);
  3378. EXPORT_SYMBOL(update_region);
  3379. EXPORT_SYMBOL(redraw_screen);
  3380. EXPORT_SYMBOL(vc_resize);
  3381. EXPORT_SYMBOL(vc_lock_resize);
  3382. EXPORT_SYMBOL(fg_console);
  3383. EXPORT_SYMBOL(console_blank_hook);
  3384. EXPORT_SYMBOL(console_blanked);
  3385. EXPORT_SYMBOL(vc_cons);
  3386. #ifndef VT_SINGLE_DRIVER
  3387. EXPORT_SYMBOL(take_over_console);
  3388. EXPORT_SYMBOL(give_up_console);
  3389. #endif