bios.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Based on msbios.c from rolo 1.6:
  25. *----------------------------------------------------------------------
  26. * (C) Copyright 2000
  27. * Sysgo Real-Time Solutions GmbH
  28. * Klein-Winternheim, Germany
  29. *----------------------------------------------------------------------
  30. */
  31. /*
  32. * During it's initialization phase, before switching to protected
  33. * mode, the Linux Kernel makes a few BIOS calls. This won't work
  34. * if the board does not have a BIOS.
  35. *
  36. * This is a very minimalisic BIOS that supplies just enough
  37. * functionality to keep the Linux Kernel happy. It is NOT
  38. * a general purpose replacement for a real BIOS !!
  39. */
  40. #define OFFS_ES 0
  41. #define OFFS_GS 2
  42. #define OFFS_DS 4
  43. #define OFFS_DI 6
  44. #define OFFS_SI 8
  45. #define OFFS_BP 10
  46. #define OFFS_SP 12
  47. #define OFFS_BX 14
  48. #define OFFS_DX 16
  49. #define OFFS_CX 18
  50. #define OFFS_AX 20
  51. #define OFFS_VECTOR 22
  52. #define OFFS_IP 24
  53. #define OFFS_CS 26
  54. #define OFFS_FLAGS 28
  55. #define SEGMENT 0x40
  56. #define STACK 0x800 /* stack at 0x40:0x800 -> 0x800 */
  57. .section .bios, "ax"
  58. .code16
  59. .org 0
  60. .globl rm_int00
  61. rm_int00:
  62. pushw $0
  63. jmp any_interrupt16
  64. .globl rm_int01
  65. rm_int01:
  66. pushw $1
  67. jmp any_interrupt16
  68. .globl rm_int02
  69. rm_int02:
  70. pushw $2
  71. jmp any_interrupt16
  72. .globl rm_int03
  73. rm_int03:
  74. pushw $3
  75. jmp any_interrupt16
  76. .globl rm_int04
  77. rm_int04:
  78. pushw $4
  79. jmp any_interrupt16
  80. .globl rm_int05
  81. rm_int05:
  82. pushw $5
  83. jmp any_interrupt16
  84. .globl rm_int06
  85. rm_int06:
  86. pushw $6
  87. jmp any_interrupt16
  88. .globl rm_int07
  89. rm_int07:
  90. pushw $7
  91. jmp any_interrupt16
  92. .globl rm_int08
  93. rm_int08:
  94. pushw $8
  95. jmp any_interrupt16
  96. .globl rm_int09
  97. rm_int09:
  98. pushw $9
  99. jmp any_interrupt16
  100. .globl rm_int0a
  101. rm_int0a:
  102. pushw $10
  103. jmp any_interrupt16
  104. .globl rm_int0b
  105. rm_int0b:
  106. pushw $11
  107. jmp any_interrupt16
  108. .globl rm_int0c
  109. rm_int0c:
  110. pushw $12
  111. jmp any_interrupt16
  112. .globl rm_int0d
  113. rm_int0d:
  114. pushw $13
  115. jmp any_interrupt16
  116. .globl rm_int0e
  117. rm_int0e:
  118. pushw $14
  119. jmp any_interrupt16
  120. .globl rm_int0f
  121. rm_int0f:
  122. pushw $15
  123. jmp any_interrupt16
  124. .globl rm_int10
  125. rm_int10:
  126. pushw $16
  127. jmp any_interrupt16
  128. .globl rm_int11
  129. rm_int11:
  130. pushw $17
  131. jmp any_interrupt16
  132. .globl rm_int12
  133. rm_int12:
  134. pushw $18
  135. jmp any_interrupt16
  136. .globl rm_int13
  137. rm_int13:
  138. pushw $19
  139. jmp any_interrupt16
  140. .globl rm_int14
  141. rm_int14:
  142. pushw $20
  143. jmp any_interrupt16
  144. .globl rm_int15
  145. rm_int15:
  146. pushw $21
  147. jmp any_interrupt16
  148. .globl rm_int16
  149. rm_int16:
  150. pushw $22
  151. jmp any_interrupt16
  152. .globl rm_int17
  153. rm_int17:
  154. pushw $23
  155. jmp any_interrupt16
  156. .globl rm_int18
  157. rm_int18:
  158. pushw $24
  159. jmp any_interrupt16
  160. .globl rm_int19
  161. rm_int19:
  162. pushw $25
  163. jmp any_interrupt16
  164. .globl rm_int1a
  165. rm_int1a:
  166. pushw $26
  167. jmp any_interrupt16
  168. .globl rm_int1b
  169. rm_int1b:
  170. pushw $27
  171. jmp any_interrupt16
  172. .globl rm_int1c
  173. rm_int1c:
  174. pushw $28
  175. jmp any_interrupt16
  176. .globl rm_int1d
  177. rm_int1d:
  178. pushw $29
  179. jmp any_interrupt16
  180. .globl rm_int1e
  181. rm_int1e:
  182. pushw $30
  183. jmp any_interrupt16
  184. .globl rm_int1f
  185. rm_int1f:
  186. pushw $31
  187. jmp any_interrupt16
  188. .globl rm_def_int
  189. rm_def_int:
  190. iret
  191. /*
  192. * All interrupt jumptable entries jump to here
  193. * after pushing the interrupt vector number onto the
  194. * stack.
  195. */
  196. any_interrupt16:
  197. pusha /* save general registers */
  198. pushw %ds /* save some segments */
  199. pushw %gs
  200. pushw %es
  201. pushw %ss /* save callers stack segment .. */
  202. popw %gs /* ... in gs */
  203. movw $SEGMENT,%ax /* setup my segments */
  204. movw %ax,%ds
  205. movw %ax,%es
  206. movw %ax,%ss
  207. movw %sp,%bp
  208. movw $STACK,%sp /* setup BIOS stackpointer */
  209. gs movw OFFS_VECTOR(%bp), %ax
  210. cmpw $0x10, %ax
  211. je Lint_10h
  212. cmpw $0x11, %ax
  213. je Lint_11h
  214. cmpw $0x13, %ax
  215. je Lint_13h
  216. cmpw $0x15, %ax
  217. je Lint_15h
  218. cmpw $0x16, %ax
  219. je Lint_16h
  220. movw $0xffff, %ax
  221. jmp Lout
  222. Lint_10h: /* VGA BIOS services */
  223. call bios_10h
  224. jmp Lout
  225. Lint_11h:
  226. call bios_11h
  227. jmp Lout
  228. Lint_13h: /* BIOS disk services */
  229. call bios_13h
  230. jmp Lout
  231. Lint_15h: /* Misc. BIOS services */
  232. call bios_15h
  233. jmp Lout
  234. Lint_16h: /* keyboard services */
  235. call bios_16h
  236. jmp Lout
  237. Lout:
  238. cmpw $0, %ax
  239. je Lhandeled
  240. /* Insert code for unhandeled INTs here.
  241. *
  242. * ROLO prints a message to the console
  243. * (we could do that but then we're in 16bit mode
  244. * so we'll have to get back into 32bit mode
  245. * to use the console I/O routines (if we do this
  246. * we shuls make int 0x10 and int 0x16 work as well))
  247. */
  248. Lhandeled:
  249. pushw %gs /* restore callers stack segment */
  250. popw %ss
  251. movw %bp,%sp /* restore stackpointer */
  252. popw %es /* restore segment selectors */
  253. popw %gs
  254. popw %ds
  255. popa /* restore GP registers */
  256. addw $2,%sp /* dump vector number */
  257. iret /* return from interrupt */
  258. /*
  259. ************************************************************
  260. * BIOS interrupt 10h -- VGA services
  261. ************************************************************
  262. */
  263. bios_10h:
  264. gs movw OFFS_AX(%bp), %ax
  265. shrw $8, %ax
  266. cmpw $0x3, %ax
  267. je Lcur_pos
  268. cmpw $0xf, %ax
  269. je Lvid_state
  270. cmpw $0x12, %ax
  271. je Lvid_cfg
  272. movw $0xffff, %ax
  273. ret
  274. Lcur_pos: /* Read Cursor Position and Size */
  275. gs movw $0, OFFS_CX(%bp)
  276. gs movw $0, OFFS_DX(%bp)
  277. xorw %ax, %ax
  278. ret
  279. Lvid_state: /* Get Video State */
  280. gs movw $(80 << 8|0x03), OFFS_AX(%bp) /* 80 columns, 80x25, 16 colors */
  281. gs movw $0, OFFS_BX(%bp)
  282. xorw %ax, %ax
  283. ret
  284. Lvid_cfg: /* Video Subsystem Configuration (EGA/VGA) */
  285. gs movw $0x10, OFFS_BX(%bp) /* indicate CGA/MDA/HGA */
  286. xorw %ax, %ax
  287. ret
  288. /*
  289. ************************************************************
  290. * BIOS interrupt 11h -- Equipment determination
  291. ************************************************************
  292. */
  293. bios_11h:
  294. movw bios_equipment, %ax
  295. gs movw %ax, OFFS_AX(%bp)
  296. xorw %ax, %ax
  297. ret
  298. /*
  299. ************************************************************
  300. * BIOS interrupt 13h -- Disk services
  301. ************************************************************
  302. */
  303. bios_13h:
  304. gs movw OFFS_AX(%bp), %ax
  305. shrw $8, %ax
  306. cmpw $0x15, %ax
  307. je Lfunc_15h
  308. movw $0xffff, %ax
  309. ret
  310. Lfunc_15h:
  311. gs movw OFFS_AX(%bp), %ax
  312. andw $0xff, %ax /* return AH=0->drive not present */
  313. gs movw %ax, OFFS_AX(%bp)
  314. xorw %ax, %ax
  315. ret
  316. /*
  317. ***********************************************************
  318. * BIOS interrupt 15h -- Miscellaneous services
  319. ***********************************************************
  320. */
  321. bios_15h:
  322. gs movw OFFS_AX(%bp), %ax
  323. shrw $8, %ax
  324. cmpw $0xc0, %ax
  325. je Lfunc_c0h
  326. cmpw $0xe8, %ax
  327. je Lfunc_e8h
  328. cmpw $0x88, %ax
  329. je Lfunc_88h
  330. movw $0xffff, %ax
  331. ret
  332. Lfunc_c0h: /* Return System Configuration Parameters (PS2 only) */
  333. gs movw OFFS_FLAGS(%bp), %ax
  334. orw $1, %ax /* return carry -- function not supported */
  335. gs movw %ax, OFFS_FLAGS(%bp)
  336. xorw %ax, %ax
  337. ret
  338. Lfunc_e8h:
  339. gs movw OFFS_AX(%bp), %ax
  340. andw $0xff, %ax
  341. cmpw $1, %ax
  342. je Lfunc_e801h
  343. gs movw OFFS_FLAGS(%bp), %ax
  344. orw $1, %ax /* return carry -- function not supported */
  345. gs movw %ax, OFFS_FLAGS(%bp)
  346. xorw %ax, %ax
  347. ret
  348. Lfunc_e801h: /* Get memory size for >64M Configurations */
  349. movw $ram_in_64kb_chunks, %ax
  350. cmpw $256, %ax
  351. ja Lmore_than_16mb
  352. shlw $6, %ax /* multiply by 64 */
  353. gs movw %ax, OFFS_AX(%bp) /* return memory size in 1kb chunks in AX and CX */
  354. gs movw %ax, OFFS_CX(%bp)
  355. xorw %ax, %ax
  356. gs movw %ax, OFFS_BX(%bp) /* set BX and DX to 0*/
  357. gs movw %ax, OFFS_DX(%bp)
  358. gs movw OFFS_FLAGS(%bp), %ax
  359. andw $0xfffe, %ax /* clear carry -- function succeeded */
  360. gs movw %ax, OFFS_FLAGS(%bp)
  361. xorw %ax, %ax
  362. ret
  363. Lmore_than_16mb:
  364. subw $0x100, %ax /* subtract 16MB */
  365. gs movw $0x3c00, OFFS_AX(%bp) /* return 0x3c00 (16MB-384k) in AX and CX */
  366. gs movw $0x3c00, OFFS_CX(%bp)
  367. gs movw %ax, OFFS_BX(%bp) /* set BX and DX to number of 64kb chunks - 256 */
  368. gs movw %ax, OFFS_DX(%bp)
  369. gs movw OFFS_FLAGS(%bp), %ax
  370. andw $0xfffe, %ax /* clear carry -- function succeeded */
  371. gs movw %ax, OFFS_FLAGS(%bp)
  372. xorw %ax, %ax
  373. ret
  374. Lfunc_88h:
  375. movw ram_in_64kb_chunks, %ax
  376. subw $16, %ax
  377. shlw $6, %ax
  378. gs movw %ax, OFFS_AX(%bp) /* return number of kilobytes in ax */
  379. gs movw OFFS_FLAGS(%bp), %ax
  380. andw $0xfffe, %ax /* clear carry -- function succeeded */
  381. gs movw %ax, OFFS_FLAGS(%bp)
  382. xorw %ax, %ax
  383. ret
  384. /*
  385. ************************************************************
  386. * BIOS interrupt 16h -- keyboard services
  387. ************************************************************
  388. */
  389. bios_16h:
  390. gs movw OFFS_AX(%bp), %ax
  391. shrw $8, %ax
  392. cmpw $0x03, %ax
  393. je Lfunc_03h
  394. movw $0xffff, %ax
  395. ret
  396. Lfunc_03h:
  397. xorw %ax, %ax /* do nothing -- function not supported */
  398. ret
  399. .globl ram_in_64kb_chunks
  400. ram_in_64kb_chunks:
  401. .word 0
  402. .globl bios_equipment
  403. bios_equipment:
  404. .word 0