vt.c 90 KB

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