vt.c 91 KB

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