bios.S 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. #include "bios.h"
  32. /*
  33. * During it's initialization phase, before switching to protected
  34. * mode, the Linux Kernel makes a few BIOS calls. This won't work
  35. * if the board does not have a BIOS.
  36. *
  37. * This is a very minimalisic BIOS that supplies just enough
  38. * functionality to keep the Linux Kernel happy. It is NOT
  39. * a general purpose replacement for a real BIOS !!
  40. */
  41. .section .bios, "ax"
  42. .code16
  43. .org 0
  44. /* a call to f000:0 should warmboot */
  45. jmp realmode_reset
  46. .globl rm_int00
  47. rm_int00:
  48. pushw $0
  49. jmp any_interrupt16
  50. .globl rm_int01
  51. rm_int01:
  52. pushw $1
  53. jmp any_interrupt16
  54. .globl rm_int02
  55. rm_int02:
  56. pushw $2
  57. jmp any_interrupt16
  58. .globl rm_int03
  59. rm_int03:
  60. pushw $3
  61. jmp any_interrupt16
  62. .globl rm_int04
  63. rm_int04:
  64. pushw $4
  65. jmp any_interrupt16
  66. .globl rm_int05
  67. rm_int05:
  68. pushw $5
  69. jmp any_interrupt16
  70. .globl rm_int06
  71. rm_int06:
  72. pushw $6
  73. jmp any_interrupt16
  74. .globl rm_int07
  75. rm_int07:
  76. pushw $7
  77. jmp any_interrupt16
  78. .globl rm_int08
  79. rm_int08:
  80. pushw $8
  81. jmp any_interrupt16
  82. .globl rm_int09
  83. rm_int09:
  84. pushw $9
  85. jmp any_interrupt16
  86. .globl rm_int0a
  87. rm_int0a:
  88. pushw $10
  89. jmp any_interrupt16
  90. .globl rm_int0b
  91. rm_int0b:
  92. pushw $11
  93. jmp any_interrupt16
  94. .globl rm_int0c
  95. rm_int0c:
  96. pushw $12
  97. jmp any_interrupt16
  98. .globl rm_int0d
  99. rm_int0d:
  100. pushw $13
  101. jmp any_interrupt16
  102. .globl rm_int0e
  103. rm_int0e:
  104. pushw $14
  105. jmp any_interrupt16
  106. .globl rm_int0f
  107. rm_int0f:
  108. pushw $15
  109. jmp any_interrupt16
  110. .globl rm_int10
  111. rm_int10:
  112. pushw $16
  113. jmp any_interrupt16
  114. .globl rm_int11
  115. rm_int11:
  116. pushw $17
  117. jmp any_interrupt16
  118. .globl rm_int12
  119. rm_int12:
  120. pushw $18
  121. jmp any_interrupt16
  122. .globl rm_int13
  123. rm_int13:
  124. pushw $19
  125. jmp any_interrupt16
  126. .globl rm_int14
  127. rm_int14:
  128. pushw $20
  129. jmp any_interrupt16
  130. .globl rm_int15
  131. rm_int15:
  132. pushw $21
  133. jmp any_interrupt16
  134. .globl rm_int16
  135. rm_int16:
  136. pushw $22
  137. jmp any_interrupt16
  138. .globl rm_int17
  139. rm_int17:
  140. pushw $23
  141. jmp any_interrupt16
  142. .globl rm_int18
  143. rm_int18:
  144. pushw $24
  145. jmp any_interrupt16
  146. .globl rm_int19
  147. rm_int19:
  148. pushw $25
  149. jmp any_interrupt16
  150. .globl rm_int1a
  151. rm_int1a:
  152. pushw $26
  153. jmp any_interrupt16
  154. .globl rm_int1b
  155. rm_int1b:
  156. pushw $27
  157. jmp any_interrupt16
  158. .globl rm_int1c
  159. rm_int1c:
  160. pushw $28
  161. jmp any_interrupt16
  162. .globl rm_int1d
  163. rm_int1d:
  164. pushw $29
  165. jmp any_interrupt16
  166. .globl rm_int1e
  167. rm_int1e:
  168. pushw $30
  169. jmp any_interrupt16
  170. .globl rm_int1f
  171. rm_int1f:
  172. pushw $31
  173. jmp any_interrupt16
  174. .globl rm_def_int
  175. rm_def_int:
  176. iret
  177. /*
  178. * All interrupt jumptable entries jump to here
  179. * after pushing the interrupt vector number onto the
  180. * stack.
  181. */
  182. any_interrupt16:
  183. MAKE_BIOS_STACK
  184. gs movw OFFS_VECTOR(%bp), %ax
  185. cmpw $0x10, %ax
  186. je Lint_10h
  187. cmpw $0x11, %ax
  188. je Lint_11h
  189. cmpw $0x12, %ax
  190. je Lint_12h
  191. cmpw $0x13, %ax
  192. je Lint_13h
  193. cmpw $0x15, %ax
  194. je Lint_15h
  195. cmpw $0x16, %ax
  196. je Lint_16h
  197. cmpw $0x1a, %ax
  198. je Lint_1ah
  199. movw $0xffff, %ax
  200. jmp Lout
  201. Lint_10h: /* VGA BIOS services */
  202. call bios_10h
  203. jmp Lout
  204. Lint_11h:
  205. call bios_11h
  206. jmp Lout
  207. Lint_12h:
  208. call bios_12h
  209. jmp Lout
  210. Lint_13h: /* BIOS disk services */
  211. call bios_13h
  212. jmp Lout
  213. Lint_15h: /* Misc. BIOS services */
  214. call bios_15h
  215. jmp Lout
  216. Lint_16h: /* keyboard services */
  217. call bios_16h
  218. jmp Lout
  219. Lint_1ah: /* PCI bios */
  220. call bios_1ah
  221. jmp Lout
  222. Lout:
  223. cmpw $0, %ax
  224. je Lhandeled
  225. /* Insert code for unhandeled INTs here.
  226. *
  227. * ROLO prints a message to the console
  228. * (we could do that but then we're in 16bit mode
  229. * so we'll have to get back into 32bit mode
  230. * to use the console I/O routines (if we do this
  231. * we shuls make int 0x10 and int 0x16 work as well))
  232. */
  233. Lhandeled:
  234. RESTORE_CALLERS_STACK
  235. addw $2,%sp /* dump vector number */
  236. iret /* return from interrupt */
  237. /*
  238. ************************************************************
  239. * BIOS interrupt 10h -- VGA services
  240. ************************************************************
  241. */
  242. bios_10h:
  243. gs movw OFFS_AX(%bp), %ax
  244. shrw $8, %ax
  245. cmpw $0x3, %ax
  246. je Lcur_pos
  247. cmpw $0xf, %ax
  248. je Lvid_state
  249. cmpw $0x12, %ax
  250. je Lvid_cfg
  251. movw $0xffff, %ax
  252. ret
  253. Lcur_pos: /* Read Cursor Position and Size */
  254. gs movw $0, OFFS_CX(%bp)
  255. gs movw $0, OFFS_DX(%bp)
  256. xorw %ax, %ax
  257. ret
  258. Lvid_state: /* Get Video State */
  259. gs movw $(80 << 8|0x03), OFFS_AX(%bp) /* 80 columns, 80x25, 16 colors */
  260. gs movw $0, OFFS_BX(%bp)
  261. xorw %ax, %ax
  262. ret
  263. Lvid_cfg: /* Video Subsystem Configuration (EGA/VGA) */
  264. gs movw $0x10, OFFS_BX(%bp) /* indicate CGA/MDA/HGA */
  265. xorw %ax, %ax
  266. ret
  267. /*
  268. ************************************************************
  269. * BIOS interrupt 11h -- Equipment determination
  270. ************************************************************
  271. */
  272. bios_11h:
  273. cs movw bios_equipment, %ax
  274. gs movw %ax, OFFS_AX(%bp)
  275. xorw %ax, %ax
  276. ret
  277. /*
  278. ************************************************************
  279. * BIOS interrupt 12h -- Get Memory Size
  280. ************************************************************
  281. */
  282. bios_12h:
  283. cs movw ram_in_64kb_chunks, %ax
  284. cmpw $0xa, %ax
  285. ja b12_more_than_640k
  286. shlw $6, %ax
  287. jmp b12_return
  288. b12_more_than_640k:
  289. movw $0x280, %ax
  290. b12_return:
  291. gs movw %ax, OFFS_AX(%bp) /* return number of kilobytes in ax */
  292. gs movw OFFS_FLAGS(%bp), %ax
  293. andw $0xfffe, %ax /* clear carry -- function succeeded */
  294. gs movw %ax, OFFS_FLAGS(%bp)
  295. xorw %ax, %ax
  296. ret
  297. /*
  298. ************************************************************
  299. * BIOS interrupt 13h -- Disk services
  300. ************************************************************
  301. */
  302. bios_13h:
  303. gs movw OFFS_AX(%bp), %ax
  304. shrw $8, %ax
  305. cmpw $0x15, %ax
  306. je Lfunc_15h
  307. movw $0xffff, %ax
  308. ret
  309. Lfunc_15h:
  310. gs movw OFFS_AX(%bp), %ax
  311. andw $0xff, %ax /* return AH=0->drive not present */
  312. gs movw %ax, OFFS_AX(%bp)
  313. xorw %ax, %ax
  314. ret
  315. /*
  316. ***********************************************************
  317. * BIOS interrupt 15h -- Miscellaneous services
  318. ***********************************************************
  319. */
  320. bios_15h:
  321. gs movw OFFS_AX(%bp), %ax
  322. shrw $8, %ax
  323. cmpw $0xc0, %ax
  324. je Lfunc_c0h
  325. cmpw $0xe8, %ax
  326. je Lfunc_e8h
  327. cmpw $0x88, %ax
  328. je Lfunc_88h
  329. movw $0xffff, %ax
  330. ret
  331. Lfunc_c0h: /* Return System Configuration Parameters (PS2 only) */
  332. gs movw OFFS_FLAGS(%bp), %ax
  333. orw $1, %ax /* return carry -- function not supported */
  334. gs movw %ax, OFFS_FLAGS(%bp)
  335. xorw %ax, %ax
  336. ret
  337. Lfunc_e8h:
  338. gs movw OFFS_AX(%bp), %ax
  339. andw $0xff, %ax
  340. cmpw $1, %ax
  341. je Lfunc_e801h
  342. gs movw OFFS_FLAGS(%bp), %ax
  343. orw $1, %ax /* return carry -- function not supported */
  344. gs movw %ax, OFFS_FLAGS(%bp)
  345. xorw %ax, %ax
  346. ret
  347. Lfunc_e801h: /* Get memory size for >64M Configurations */
  348. cs movw ram_in_64kb_chunks, %ax
  349. cmpw $0x100, %ax
  350. ja e801_more_than_16mb
  351. shlw $6, %ax /* multiply by 64 */
  352. subw $0x400, %ax /* 1st meg does not count */
  353. gs movw %ax, OFFS_AX(%bp) /* return memory size between 1M and 16M in 1kb chunks in AX and CX */
  354. gs movw %ax, OFFS_CX(%bp)
  355. gs movw $0, OFFS_BX(%bp) /* set BX and DX to 0*/
  356. gs movw $0, OFFS_DX(%bp)
  357. gs movw OFFS_FLAGS(%bp), %ax
  358. andw $0xfffe, %ax /* clear carry -- function succeeded */
  359. gs movw %ax, OFFS_FLAGS(%bp)
  360. xorw %ax, %ax
  361. ret
  362. e801_more_than_16mb:
  363. subw $0x100, %ax /* subtract 16MB */
  364. gs movw $0x3c00, OFFS_AX(%bp) /* return 0x3c00 (16MB-1MB) in AX and CX */
  365. gs movw $0x3c00, OFFS_CX(%bp)
  366. gs movw %ax, OFFS_BX(%bp) /* set BX and DX to number of 64kb chunks above 16MB */
  367. gs movw %ax, OFFS_DX(%bp)
  368. gs movw OFFS_FLAGS(%bp), %ax
  369. andw $0xfffe, %ax /* clear carry -- function succeeded */
  370. gs movw %ax, OFFS_FLAGS(%bp)
  371. xorw %ax, %ax
  372. ret
  373. Lfunc_88h:
  374. cs movw ram_in_64kb_chunks, %ax
  375. cmpw $0x100, %ax
  376. jna b88_not_more_than16
  377. movw $0x100, %ax
  378. b88_not_more_than16:
  379. shlw $6, %ax
  380. subw $0x400, %ax /* 1st meg does not count */
  381. gs movw %ax, OFFS_AX(%bp) /* return number of kilobytes between 16MB and 16MB in ax */
  382. gs movw OFFS_FLAGS(%bp), %ax
  383. andw $0xfffe, %ax /* clear carry -- function succeeded */
  384. gs movw %ax, OFFS_FLAGS(%bp)
  385. xorw %ax, %ax
  386. ret
  387. /*
  388. ************************************************************
  389. * BIOS interrupt 16h -- keyboard services
  390. ************************************************************
  391. */
  392. bios_16h:
  393. gs movw OFFS_AX(%bp), %ax
  394. shrw $8, %ax
  395. cmpw $0x03, %ax
  396. je Lfunc_03h
  397. movw $0xffff, %ax
  398. ret
  399. Lfunc_03h:
  400. xorw %ax, %ax /* do nothing -- function not supported */
  401. ret
  402. /*
  403. ************************************************************
  404. * BIOS interrupt 1ah -- PCI bios
  405. ************************************************************
  406. */
  407. bios_1ah:
  408. gs movw OFFS_AX(%bp), %ax
  409. cmpb $0xb1, %ah
  410. je Lfunc_b1h
  411. movw $0xffff, %ax
  412. ret
  413. Lfunc_b1h:
  414. call realmode_pci_bios
  415. xorw %ax, %ax /* do nothing -- function not supported */
  416. ret
  417. .globl ram_in_64kb_chunks
  418. ram_in_64kb_chunks:
  419. .word 0
  420. .globl bios_equipment
  421. bios_equipment:
  422. .word 0