vt.c 90 KB

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