v86 0.4.0 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/Readme.md +56 -111
  2. package/build/libv86-debug.js +12677 -0
  3. package/build/libv86-debug.mjs +732 -0
  4. package/build/libv86.js +710 -0
  5. package/build/libv86.mjs +636 -0
  6. package/build/v86-debug.wasm +0 -0
  7. package/build/v86-fallback.wasm +0 -0
  8. package/build/v86.wasm +0 -0
  9. package/package.json +12 -35
  10. package/bios/.gitignore +0 -1
  11. package/bios/COPYING.LESSER +0 -165
  12. package/bios/bochs-bios.bin +0 -0
  13. package/bios/bochs-vgabios.bin +0 -0
  14. package/bios/fetch-and-build-seabios.sh +0 -13
  15. package/bios/seabios/.config +0 -113
  16. package/bios/seabios/.config.old +0 -114
  17. package/bios/seabios/.gitignore +0 -4
  18. package/bios/seabios/COPYING +0 -674
  19. package/bios/seabios/COPYING.LESSER +0 -165
  20. package/bios/seabios/Makefile +0 -286
  21. package/bios/seabios/README +0 -17
  22. package/bios/seabios/docs/Build_overview.md +0 -104
  23. package/bios/seabios/docs/Contributing.md +0 -20
  24. package/bios/seabios/docs/Debugging.md +0 -111
  25. package/bios/seabios/docs/Developer_Documentation.md +0 -25
  26. package/bios/seabios/docs/Developer_links.md +0 -86
  27. package/bios/seabios/docs/Download.md +0 -27
  28. package/bios/seabios/docs/Execution_and_code_flow.md +0 -178
  29. package/bios/seabios/docs/Linking_overview.md +0 -160
  30. package/bios/seabios/docs/Mailinglist.md +0 -8
  31. package/bios/seabios/docs/Memory_Model.md +0 -253
  32. package/bios/seabios/docs/README +0 -5
  33. package/bios/seabios/docs/Releases.md +0 -482
  34. package/bios/seabios/docs/Runtime_config.md +0 -193
  35. package/bios/seabios/docs/SeaBIOS.md +0 -17
  36. package/bios/seabios/docs/SeaVGABIOS.md +0 -39
  37. package/bios/seabios/out/autoconf.h +0 -117
  38. package/bios/seabios/out/include/config/acpi/dsdt.h +0 -0
  39. package/bios/seabios/out/include/config/acpi.h +0 -0
  40. package/bios/seabios/out/include/config/ahci.h +0 -0
  41. package/bios/seabios/out/include/config/apmbios.h +0 -0
  42. package/bios/seabios/out/include/config/ata/dma.h +0 -0
  43. package/bios/seabios/out/include/config/ata/pio32.h +0 -0
  44. package/bios/seabios/out/include/config/ata.h +0 -0
  45. package/bios/seabios/out/include/config/auto.conf +0 -69
  46. package/bios/seabios/out/include/config/auto.conf.cmd +0 -9
  47. package/bios/seabios/out/include/config/boot.h +0 -0
  48. package/bios/seabios/out/include/config/bootorder.h +0 -0
  49. package/bios/seabios/out/include/config/build/vgabios.h +0 -0
  50. package/bios/seabios/out/include/config/call32/smm.h +0 -0
  51. package/bios/seabios/out/include/config/cdrom/boot.h +0 -0
  52. package/bios/seabios/out/include/config/cdrom/emu.h +0 -0
  53. package/bios/seabios/out/include/config/debug/level.h +0 -0
  54. package/bios/seabios/out/include/config/drives.h +0 -0
  55. package/bios/seabios/out/include/config/entry/extrastack.h +0 -0
  56. package/bios/seabios/out/include/config/esp/scsi.h +0 -0
  57. package/bios/seabios/out/include/config/flash/floppy.h +0 -0
  58. package/bios/seabios/out/include/config/floppy.h +0 -0
  59. package/bios/seabios/out/include/config/fw/romfile/load.h +0 -0
  60. package/bios/seabios/out/include/config/hardware/irq.h +0 -0
  61. package/bios/seabios/out/include/config/kbd/call/int15/4f.h +0 -0
  62. package/bios/seabios/out/include/config/keyboard.h +0 -0
  63. package/bios/seabios/out/include/config/lpt.h +0 -0
  64. package/bios/seabios/out/include/config/lsi/scsi.h +0 -0
  65. package/bios/seabios/out/include/config/malloc/uppermemory.h +0 -0
  66. package/bios/seabios/out/include/config/megasas.h +0 -0
  67. package/bios/seabios/out/include/config/mouse.h +0 -0
  68. package/bios/seabios/out/include/config/mpt/scsi.h +0 -0
  69. package/bios/seabios/out/include/config/mptable.h +0 -0
  70. package/bios/seabios/out/include/config/mtrr/init.h +0 -0
  71. package/bios/seabios/out/include/config/optionroms.h +0 -0
  72. package/bios/seabios/out/include/config/override/pci/id.h +0 -0
  73. package/bios/seabios/out/include/config/pcibios.h +0 -0
  74. package/bios/seabios/out/include/config/pirtable.h +0 -0
  75. package/bios/seabios/out/include/config/pmm.h +0 -0
  76. package/bios/seabios/out/include/config/pmtimer.h +0 -0
  77. package/bios/seabios/out/include/config/pnpbios.h +0 -0
  78. package/bios/seabios/out/include/config/ps2port.h +0 -0
  79. package/bios/seabios/out/include/config/pvscsi.h +0 -0
  80. package/bios/seabios/out/include/config/qemu/hardware.h +0 -0
  81. package/bios/seabios/out/include/config/qemu.h +0 -0
  82. package/bios/seabios/out/include/config/rom/size.h +0 -0
  83. package/bios/seabios/out/include/config/rtc/timer.h +0 -0
  84. package/bios/seabios/out/include/config/s3/resume.h +0 -0
  85. package/bios/seabios/out/include/config/sdcard.h +0 -0
  86. package/bios/seabios/out/include/config/serial.h +0 -0
  87. package/bios/seabios/out/include/config/tcgbios.h +0 -0
  88. package/bios/seabios/out/include/config/threads.h +0 -0
  89. package/bios/seabios/out/include/config/tristate.conf +0 -4
  90. package/bios/seabios/out/include/config/tsc/timer.h +0 -0
  91. package/bios/seabios/out/include/config/use/smm.h +0 -0
  92. package/bios/seabios/out/include/config/vga/allocate/extra/stack.h +0 -0
  93. package/bios/seabios/out/include/config/vga/bochs/stdvga.h +0 -0
  94. package/bios/seabios/out/include/config/vga/bochs.h +0 -0
  95. package/bios/seabios/out/include/config/vga/did.h +0 -0
  96. package/bios/seabios/out/include/config/vga/extra/stack/size.h +0 -0
  97. package/bios/seabios/out/include/config/vga/fixup/asm.h +0 -0
  98. package/bios/seabios/out/include/config/vga/pci.h +0 -0
  99. package/bios/seabios/out/include/config/vga/stdvga/ports.h +0 -0
  100. package/bios/seabios/out/include/config/vga/vbe.h +0 -0
  101. package/bios/seabios/out/include/config/vga/vid.h +0 -0
  102. package/bios/seabios/out/include/config/vgahooks.h +0 -0
  103. package/bios/seabios/out/include/config/virtio/blk.h +0 -0
  104. package/bios/seabios/out/include/config/virtio/scsi.h +0 -0
  105. package/bios/seabios/out/include/config/xen.h +0 -0
  106. package/bios/seabios/out/scripts/kconfig/conf +0 -0
  107. package/bios/seabios/out/scripts/kconfig/conf.o +0 -0
  108. package/bios/seabios/out/scripts/kconfig/zconf.hash.c +0 -289
  109. package/bios/seabios/out/scripts/kconfig/zconf.lex.c +0 -2420
  110. package/bios/seabios/out/scripts/kconfig/zconf.tab.c +0 -2538
  111. package/bios/seabios/out/scripts/kconfig/zconf.tab.o +0 -0
  112. package/bios/seabios/scripts/acpi_extract.py +0 -366
  113. package/bios/seabios/scripts/acpi_extract_preprocess.py +0 -41
  114. package/bios/seabios/scripts/buildrom.py +0 -56
  115. package/bios/seabios/scripts/buildversion.py +0 -134
  116. package/bios/seabios/scripts/checkrom.py +0 -95
  117. package/bios/seabios/scripts/checkstack.py +0 -226
  118. package/bios/seabios/scripts/checksum.py +0 -16
  119. package/bios/seabios/scripts/encodeint.py +0 -21
  120. package/bios/seabios/scripts/gen-offsets.sh +0 -17
  121. package/bios/seabios/scripts/kconfig/.gitignore +0 -22
  122. package/bios/seabios/scripts/kconfig/Makefile +0 -331
  123. package/bios/seabios/scripts/kconfig/POTFILES.in +0 -12
  124. package/bios/seabios/scripts/kconfig/check.sh +0 -13
  125. package/bios/seabios/scripts/kconfig/conf.c +0 -718
  126. package/bios/seabios/scripts/kconfig/confdata.c +0 -1250
  127. package/bios/seabios/scripts/kconfig/expr.c +0 -1168
  128. package/bios/seabios/scripts/kconfig/expr.h +0 -241
  129. package/bios/seabios/scripts/kconfig/gconf.c +0 -1542
  130. package/bios/seabios/scripts/kconfig/gconf.glade +0 -661
  131. package/bios/seabios/scripts/kconfig/images.c +0 -326
  132. package/bios/seabios/scripts/kconfig/kxgettext.c +0 -235
  133. package/bios/seabios/scripts/kconfig/lex.zconf.c +0 -2430
  134. package/bios/seabios/scripts/kconfig/list.h +0 -131
  135. package/bios/seabios/scripts/kconfig/lkc.h +0 -200
  136. package/bios/seabios/scripts/kconfig/lkc_proto.h +0 -57
  137. package/bios/seabios/scripts/kconfig/lxdialog/.gitignore +0 -4
  138. package/bios/seabios/scripts/kconfig/lxdialog/BIG.FAT.WARNING +0 -4
  139. package/bios/seabios/scripts/kconfig/lxdialog/check-lxdialog.sh +0 -87
  140. package/bios/seabios/scripts/kconfig/lxdialog/checklist.c +0 -332
  141. package/bios/seabios/scripts/kconfig/lxdialog/dialog.h +0 -257
  142. package/bios/seabios/scripts/kconfig/lxdialog/inputbox.c +0 -301
  143. package/bios/seabios/scripts/kconfig/lxdialog/menubox.c +0 -437
  144. package/bios/seabios/scripts/kconfig/lxdialog/textbox.c +0 -408
  145. package/bios/seabios/scripts/kconfig/lxdialog/util.c +0 -713
  146. package/bios/seabios/scripts/kconfig/lxdialog/yesno.c +0 -114
  147. package/bios/seabios/scripts/kconfig/mconf.c +0 -1036
  148. package/bios/seabios/scripts/kconfig/menu.c +0 -697
  149. package/bios/seabios/scripts/kconfig/merge_config.sh +0 -150
  150. package/bios/seabios/scripts/kconfig/nconf.c +0 -1556
  151. package/bios/seabios/scripts/kconfig/nconf.gui.c +0 -656
  152. package/bios/seabios/scripts/kconfig/nconf.h +0 -96
  153. package/bios/seabios/scripts/kconfig/qconf.cc +0 -1795
  154. package/bios/seabios/scripts/kconfig/qconf.h +0 -338
  155. package/bios/seabios/scripts/kconfig/streamline_config.pl +0 -647
  156. package/bios/seabios/scripts/kconfig/symbol.c +0 -1373
  157. package/bios/seabios/scripts/kconfig/util.c +0 -157
  158. package/bios/seabios/scripts/kconfig/zconf.gperf +0 -48
  159. package/bios/seabios/scripts/kconfig/zconf.hash.c_shipped +0 -289
  160. package/bios/seabios/scripts/kconfig/zconf.l +0 -363
  161. package/bios/seabios/scripts/kconfig/zconf.lex.c_shipped +0 -2420
  162. package/bios/seabios/scripts/kconfig/zconf.tab.c_shipped +0 -2538
  163. package/bios/seabios/scripts/kconfig/zconf.y +0 -733
  164. package/bios/seabios/scripts/layoutrom.py +0 -705
  165. package/bios/seabios/scripts/python23compat.py +0 -14
  166. package/bios/seabios/scripts/readserial.py +0 -190
  167. package/bios/seabios/scripts/tarball.sh +0 -36
  168. package/bios/seabios/scripts/test-build.sh +0 -90
  169. package/bios/seabios/scripts/transdump.py +0 -53
  170. package/bios/seabios/scripts/vgafixup.py +0 -96
  171. package/bios/seabios/src/Kconfig +0 -579
  172. package/bios/seabios/src/apm.c +0 -215
  173. package/bios/seabios/src/asm-offsets.c +0 -23
  174. package/bios/seabios/src/biosvar.h +0 -130
  175. package/bios/seabios/src/block.c +0 -623
  176. package/bios/seabios/src/block.h +0 -121
  177. package/bios/seabios/src/bmp.c +0 -117
  178. package/bios/seabios/src/boot.c +0 -793
  179. package/bios/seabios/src/bootsplash.c +0 -255
  180. package/bios/seabios/src/bregs.h +0 -80
  181. package/bios/seabios/src/byteorder.h +0 -71
  182. package/bios/seabios/src/cdrom.c +0 -322
  183. package/bios/seabios/src/clock.c +0 -506
  184. package/bios/seabios/src/code16gcc.s +0 -1
  185. package/bios/seabios/src/config.h +0 -108
  186. package/bios/seabios/src/cp437.c +0 -275
  187. package/bios/seabios/src/cp437.h +0 -1
  188. package/bios/seabios/src/disk.c +0 -779
  189. package/bios/seabios/src/e820map.c +0 -152
  190. package/bios/seabios/src/e820map.h +0 -26
  191. package/bios/seabios/src/entryfuncs.S +0 -165
  192. package/bios/seabios/src/farptr.h +0 -208
  193. package/bios/seabios/src/font.c +0 -139
  194. package/bios/seabios/src/fw/acpi-dsdt-cpu-hotplug.dsl +0 -78
  195. package/bios/seabios/src/fw/acpi-dsdt-dbug.dsl +0 -26
  196. package/bios/seabios/src/fw/acpi-dsdt-hpet.dsl +0 -36
  197. package/bios/seabios/src/fw/acpi-dsdt-isa.dsl +0 -102
  198. package/bios/seabios/src/fw/acpi-dsdt-pci-crs.dsl +0 -90
  199. package/bios/seabios/src/fw/acpi-dsdt.dsl +0 -342
  200. package/bios/seabios/src/fw/acpi-dsdt.hex +0 -554
  201. package/bios/seabios/src/fw/acpi.c +0 -685
  202. package/bios/seabios/src/fw/biostables.c +0 -491
  203. package/bios/seabios/src/fw/coreboot.c +0 -569
  204. package/bios/seabios/src/fw/csm.c +0 -347
  205. package/bios/seabios/src/fw/dev-pci.h +0 -52
  206. package/bios/seabios/src/fw/dev-piix.h +0 -29
  207. package/bios/seabios/src/fw/dev-q35.h +0 -52
  208. package/bios/seabios/src/fw/lzmadecode.c +0 -398
  209. package/bios/seabios/src/fw/lzmadecode.h +0 -67
  210. package/bios/seabios/src/fw/mptable.c +0 -197
  211. package/bios/seabios/src/fw/mtrr.c +0 -105
  212. package/bios/seabios/src/fw/multiboot.c +0 -111
  213. package/bios/seabios/src/fw/paravirt.c +0 -624
  214. package/bios/seabios/src/fw/paravirt.h +0 -63
  215. package/bios/seabios/src/fw/pciinit.c +0 -1187
  216. package/bios/seabios/src/fw/pirtable.c +0 -103
  217. package/bios/seabios/src/fw/q35-acpi-dsdt.dsl +0 -450
  218. package/bios/seabios/src/fw/romfile_loader.c +0 -259
  219. package/bios/seabios/src/fw/romfile_loader.h +0 -91
  220. package/bios/seabios/src/fw/shadow.c +0 -208
  221. package/bios/seabios/src/fw/smbios.c +0 -585
  222. package/bios/seabios/src/fw/smm.c +0 -269
  223. package/bios/seabios/src/fw/smp.c +0 -194
  224. package/bios/seabios/src/fw/ssdt-misc.dsl +0 -104
  225. package/bios/seabios/src/fw/ssdt-misc.hex +0 -88
  226. package/bios/seabios/src/fw/ssdt-pcihp.dsl +0 -36
  227. package/bios/seabios/src/fw/ssdt-pcihp.hex +0 -38
  228. package/bios/seabios/src/fw/ssdt-proc.dsl +0 -48
  229. package/bios/seabios/src/fw/ssdt-proc.hex +0 -35
  230. package/bios/seabios/src/fw/xen.c +0 -149
  231. package/bios/seabios/src/fw/xen.h +0 -125
  232. package/bios/seabios/src/gen-defs.h +0 -19
  233. package/bios/seabios/src/hw/ahci.c +0 -697
  234. package/bios/seabios/src/hw/ahci.h +0 -201
  235. package/bios/seabios/src/hw/ata.c +0 -1046
  236. package/bios/seabios/src/hw/ata.h +0 -163
  237. package/bios/seabios/src/hw/blockcmd.c +0 -372
  238. package/bios/seabios/src/hw/blockcmd.h +0 -114
  239. package/bios/seabios/src/hw/dma.c +0 -67
  240. package/bios/seabios/src/hw/esp-scsi.c +0 -241
  241. package/bios/seabios/src/hw/esp-scsi.h +0 -8
  242. package/bios/seabios/src/hw/floppy.c +0 -741
  243. package/bios/seabios/src/hw/lsi-scsi.c +0 -221
  244. package/bios/seabios/src/hw/lsi-scsi.h +0 -8
  245. package/bios/seabios/src/hw/megasas.c +0 -405
  246. package/bios/seabios/src/hw/megasas.h +0 -8
  247. package/bios/seabios/src/hw/mpt-scsi.c +0 -319
  248. package/bios/seabios/src/hw/mpt-scsi.h +0 -8
  249. package/bios/seabios/src/hw/nvme-int.h +0 -199
  250. package/bios/seabios/src/hw/nvme.c +0 -708
  251. package/bios/seabios/src/hw/nvme.h +0 -17
  252. package/bios/seabios/src/hw/pci.c +0 -133
  253. package/bios/seabios/src/hw/pci.h +0 -47
  254. package/bios/seabios/src/hw/pci_ids.h +0 -2632
  255. package/bios/seabios/src/hw/pci_regs.h +0 -556
  256. package/bios/seabios/src/hw/pcidevice.c +0 -192
  257. package/bios/seabios/src/hw/pcidevice.h +0 -76
  258. package/bios/seabios/src/hw/pic.c +0 -115
  259. package/bios/seabios/src/hw/pic.h +0 -60
  260. package/bios/seabios/src/hw/ps2port.c +0 -543
  261. package/bios/seabios/src/hw/ps2port.h +0 -67
  262. package/bios/seabios/src/hw/pvscsi.c +0 -333
  263. package/bios/seabios/src/hw/pvscsi.h +0 -8
  264. package/bios/seabios/src/hw/ramdisk.c +0 -108
  265. package/bios/seabios/src/hw/rtc.c +0 -100
  266. package/bios/seabios/src/hw/rtc.h +0 -75
  267. package/bios/seabios/src/hw/sdcard.c +0 -572
  268. package/bios/seabios/src/hw/serialio.c +0 -113
  269. package/bios/seabios/src/hw/serialio.h +0 -29
  270. package/bios/seabios/src/hw/timer.c +0 -259
  271. package/bios/seabios/src/hw/tpm_drivers.c +0 -636
  272. package/bios/seabios/src/hw/tpm_drivers.h +0 -127
  273. package/bios/seabios/src/hw/usb-ehci.c +0 -650
  274. package/bios/seabios/src/hw/usb-ehci.h +0 -177
  275. package/bios/seabios/src/hw/usb-hid.c +0 -442
  276. package/bios/seabios/src/hw/usb-hid.h +0 -29
  277. package/bios/seabios/src/hw/usb-hub.c +0 -205
  278. package/bios/seabios/src/hw/usb-hub.h +0 -64
  279. package/bios/seabios/src/hw/usb-msc.c +0 -222
  280. package/bios/seabios/src/hw/usb-msc.h +0 -10
  281. package/bios/seabios/src/hw/usb-ohci.c +0 -568
  282. package/bios/seabios/src/hw/usb-ohci.h +0 -144
  283. package/bios/seabios/src/hw/usb-uas.c +0 -289
  284. package/bios/seabios/src/hw/usb-uas.h +0 -9
  285. package/bios/seabios/src/hw/usb-uhci.c +0 -571
  286. package/bios/seabios/src/hw/usb-uhci.h +0 -128
  287. package/bios/seabios/src/hw/usb-xhci.c +0 -1161
  288. package/bios/seabios/src/hw/usb-xhci.h +0 -133
  289. package/bios/seabios/src/hw/usb.c +0 -499
  290. package/bios/seabios/src/hw/usb.h +0 -254
  291. package/bios/seabios/src/hw/virtio-blk.c +0 -211
  292. package/bios/seabios/src/hw/virtio-blk.h +0 -43
  293. package/bios/seabios/src/hw/virtio-pci.c +0 -501
  294. package/bios/seabios/src/hw/virtio-pci.h +0 -151
  295. package/bios/seabios/src/hw/virtio-ring.c +0 -147
  296. package/bios/seabios/src/hw/virtio-ring.h +0 -121
  297. package/bios/seabios/src/hw/virtio-scsi.c +0 -220
  298. package/bios/seabios/src/hw/virtio-scsi.h +0 -47
  299. package/bios/seabios/src/jpeg.c +0 -1055
  300. package/bios/seabios/src/kbd.c +0 -599
  301. package/bios/seabios/src/list.h +0 -91
  302. package/bios/seabios/src/malloc.c +0 -561
  303. package/bios/seabios/src/malloc.h +0 -70
  304. package/bios/seabios/src/memmap.h +0 -21
  305. package/bios/seabios/src/misc.c +0 -195
  306. package/bios/seabios/src/mouse.c +0 -342
  307. package/bios/seabios/src/optionroms.c +0 -475
  308. package/bios/seabios/src/output.c +0 -584
  309. package/bios/seabios/src/output.h +0 -68
  310. package/bios/seabios/src/pcibios.c +0 -241
  311. package/bios/seabios/src/pmm.c +0 -176
  312. package/bios/seabios/src/pnpbios.c +0 -88
  313. package/bios/seabios/src/post.c +0 -337
  314. package/bios/seabios/src/resume.c +0 -157
  315. package/bios/seabios/src/romfile.c +0 -146
  316. package/bios/seabios/src/romfile.h +0 -21
  317. package/bios/seabios/src/romlayout.S +0 -698
  318. package/bios/seabios/src/sercon.c +0 -677
  319. package/bios/seabios/src/serial.c +0 -317
  320. package/bios/seabios/src/sha1.c +0 -147
  321. package/bios/seabios/src/sha1.h +0 -8
  322. package/bios/seabios/src/stacks.c +0 -771
  323. package/bios/seabios/src/stacks.h +0 -68
  324. package/bios/seabios/src/std/LegacyBios.h +0 -985
  325. package/bios/seabios/src/std/acpi.h +0 -323
  326. package/bios/seabios/src/std/bda.h +0 -174
  327. package/bios/seabios/src/std/disk.h +0 -175
  328. package/bios/seabios/src/std/mptable.h +0 -77
  329. package/bios/seabios/src/std/multiboot.h +0 -260
  330. package/bios/seabios/src/std/optionrom.h +0 -59
  331. package/bios/seabios/src/std/pirtable.h +0 -35
  332. package/bios/seabios/src/std/pmm.h +0 -19
  333. package/bios/seabios/src/std/pnpbios.h +0 -24
  334. package/bios/seabios/src/std/smbios.h +0 -167
  335. package/bios/seabios/src/std/tcg.h +0 -554
  336. package/bios/seabios/src/std/vbe.h +0 -156
  337. package/bios/seabios/src/std/vga.h +0 -63
  338. package/bios/seabios/src/string.c +0 -251
  339. package/bios/seabios/src/string.h +0 -31
  340. package/bios/seabios/src/system.c +0 -357
  341. package/bios/seabios/src/tcgbios.c +0 -2014
  342. package/bios/seabios/src/tcgbios.h +0 -19
  343. package/bios/seabios/src/types.h +0 -156
  344. package/bios/seabios/src/util.h +0 -251
  345. package/bios/seabios/src/version.c +0 -5
  346. package/bios/seabios/src/vgahooks.c +0 -355
  347. package/bios/seabios/src/x86.c +0 -23
  348. package/bios/seabios/src/x86.h +0 -277
  349. package/bios/seabios/vgasrc/Kconfig +0 -211
  350. package/bios/seabios/vgasrc/bochsdisplay.c +0 -59
  351. package/bios/seabios/vgasrc/bochsvga.c +0 -447
  352. package/bios/seabios/vgasrc/bochsvga.h +0 -57
  353. package/bios/seabios/vgasrc/cbvga.c +0 -337
  354. package/bios/seabios/vgasrc/clext.c +0 -627
  355. package/bios/seabios/vgasrc/geodevga.c +0 -434
  356. package/bios/seabios/vgasrc/geodevga.h +0 -89
  357. package/bios/seabios/vgasrc/ramfb.c +0 -163
  358. package/bios/seabios/vgasrc/stdvga.c +0 -485
  359. package/bios/seabios/vgasrc/stdvga.h +0 -81
  360. package/bios/seabios/vgasrc/stdvgaio.c +0 -186
  361. package/bios/seabios/vgasrc/stdvgamodes.c +0 -534
  362. package/bios/seabios/vgasrc/swcursor.c +0 -96
  363. package/bios/seabios/vgasrc/vbe.c +0 -432
  364. package/bios/seabios/vgasrc/vgabios.c +0 -1131
  365. package/bios/seabios/vgasrc/vgabios.h +0 -88
  366. package/bios/seabios/vgasrc/vgaentry.S +0 -161
  367. package/bios/seabios/vgasrc/vgafb.c +0 -661
  368. package/bios/seabios/vgasrc/vgafb.h +0 -42
  369. package/bios/seabios/vgasrc/vgafonts.c +0 -785
  370. package/bios/seabios/vgasrc/vgahw.h +0 -152
  371. package/bios/seabios/vgasrc/vgainit.c +0 -202
  372. package/bios/seabios/vgasrc/vgalayout.lds.S +0 -23
  373. package/bios/seabios/vgasrc/vgautil.h +0 -103
  374. package/bios/seabios/vgasrc/vgaversion.c +0 -6
  375. package/bios/seabios-debug.bin +0 -0
  376. package/bios/seabios-debug.config +0 -117
  377. package/bios/seabios.bin +0 -0
  378. package/bios/seabios.config +0 -114
  379. package/bios/vgabios-debug.bin +0 -0
  380. package/bios/vgabios.bin +0 -0
  381. package/build/binaries.js +0 -1
  382. package/build/index-debug.cjs +0 -1
  383. package/build/index-debug.js +0 -1
  384. package/build/index.cjs +0 -1
  385. package/build/index.js +0 -1
  386. package/v86.css +0 -259
@@ -1,1046 +0,0 @@
1
- // Low level ATA disk access
2
- //
3
- // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
4
- // Copyright (C) 2002 MandrakeSoft S.A.
5
- //
6
- // This file may be distributed under the terms of the GNU LGPLv3 license.
7
-
8
- #include "ata.h" // ATA_CB_STAT
9
- #include "biosvar.h" // GET_GLOBALFLAT
10
- #include "block.h" // struct drive_s
11
- #include "blockcmd.h" // CDB_CMD_READ_10
12
- #include "byteorder.h" // be16_to_cpu
13
- #include "malloc.h" // malloc_fseg
14
- #include "output.h" // dprintf
15
- #include "pci.h" // pci_config_readb
16
- #include "pcidevice.h" // foreachpci
17
- #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER
18
- #include "pci_regs.h" // PCI_INTERRUPT_LINE
19
- #include "pic.h" // enable_hwirq
20
- #include "stacks.h" // yield
21
- #include "std/disk.h" // DISK_RET_SUCCESS
22
- #include "string.h" // memset
23
- #include "util.h" // timer_calc
24
- #include "x86.h" // inb
25
-
26
- #define IDE_TIMEOUT 32000 //32 seconds max for IDE ops
27
-
28
-
29
- /****************************************************************
30
- * Helper functions
31
- ****************************************************************/
32
-
33
- // Wait for the specified ide state
34
- static inline int
35
- await_ide(u8 mask, u8 flags, u16 base, u16 timeout)
36
- {
37
- u32 end = timer_calc(timeout);
38
- for (;;) {
39
- u8 status = inb(base+ATA_CB_STAT);
40
- if ((status & mask) == flags)
41
- return status;
42
- if (timer_check(end)) {
43
- warn_timeout();
44
- return -1;
45
- }
46
- yield();
47
- }
48
- }
49
-
50
- // Wait for the device to be not-busy.
51
- static int
52
- await_not_bsy(u16 base)
53
- {
54
- return await_ide(ATA_CB_STAT_BSY, 0, base, IDE_TIMEOUT);
55
- }
56
-
57
- // Wait for the device to be ready.
58
- static int
59
- await_rdy(u16 base)
60
- {
61
- return await_ide(ATA_CB_STAT_RDY, ATA_CB_STAT_RDY, base, IDE_TIMEOUT);
62
- }
63
-
64
- // Wait for ide state - pauses for one ata cycle first.
65
- static inline int
66
- pause_await_not_bsy(u16 iobase1, u16 iobase2)
67
- {
68
- // Wait one PIO transfer cycle.
69
- inb(iobase2 + ATA_CB_ASTAT);
70
-
71
- return await_not_bsy(iobase1);
72
- }
73
-
74
- // Wait for ide state - pause for 400ns first.
75
- static inline int
76
- ndelay_await_not_bsy(u16 iobase1)
77
- {
78
- ndelay(400);
79
- return await_not_bsy(iobase1);
80
- }
81
-
82
- // Reset a drive
83
- static void
84
- ata_reset(struct atadrive_s *adrive_gf)
85
- {
86
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
87
- u8 slave = GET_GLOBALFLAT(adrive_gf->slave);
88
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
89
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
90
-
91
- dprintf(6, "ata_reset drive=%p\n", &adrive_gf->drive);
92
- // Pulse SRST
93
- outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN | ATA_CB_DC_SRST, iobase2+ATA_CB_DC);
94
- udelay(5);
95
- outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2+ATA_CB_DC);
96
- msleep(2);
97
-
98
- // wait for device to become not busy.
99
- int status = await_not_bsy(iobase1);
100
- if (status < 0)
101
- goto done;
102
- if (slave) {
103
- // Change device.
104
- u32 end = timer_calc(IDE_TIMEOUT);
105
- for (;;) {
106
- outb(ATA_CB_DH_DEV1, iobase1 + ATA_CB_DH);
107
- status = ndelay_await_not_bsy(iobase1);
108
- if (status < 0)
109
- goto done;
110
- if (inb(iobase1 + ATA_CB_DH) == ATA_CB_DH_DEV1)
111
- break;
112
- // Change drive request failed to take effect - retry.
113
- if (timer_check(end)) {
114
- warn_timeout();
115
- goto done;
116
- }
117
- }
118
- } else {
119
- // QEMU doesn't reset dh on reset, so set it explicitly.
120
- outb(ATA_CB_DH_DEV0, iobase1 + ATA_CB_DH);
121
- }
122
-
123
- // On a user-reset request, wait for RDY if it is an ATA device.
124
- u8 type=GET_GLOBALFLAT(adrive_gf->drive.type);
125
- if (type == DTYPE_ATA)
126
- status = await_rdy(iobase1);
127
-
128
- done:
129
- // Enable interrupts
130
- outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
131
-
132
- dprintf(6, "ata_reset exit status=%x\n", status);
133
- }
134
-
135
- // Check for drive RDY for 16bit interface command.
136
- static int
137
- isready(struct atadrive_s *adrive_gf)
138
- {
139
- // Read the status from controller
140
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
141
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
142
- u8 status = inb(iobase1 + ATA_CB_STAT);
143
- if ((status & (ATA_CB_STAT_BSY|ATA_CB_STAT_RDY)) == ATA_CB_STAT_RDY)
144
- return DISK_RET_SUCCESS;
145
- return DISK_RET_ENOTREADY;
146
- }
147
-
148
-
149
- /****************************************************************
150
- * ATA send command
151
- ****************************************************************/
152
-
153
- struct ata_pio_command {
154
- u8 feature;
155
- u8 sector_count;
156
- u8 lba_low;
157
- u8 lba_mid;
158
- u8 lba_high;
159
- u8 device;
160
- u8 command;
161
-
162
- u8 feature2;
163
- u8 sector_count2;
164
- u8 lba_low2;
165
- u8 lba_mid2;
166
- u8 lba_high2;
167
- };
168
-
169
- // Send an ata command to the drive.
170
- static int
171
- send_cmd(struct atadrive_s *adrive_gf, struct ata_pio_command *cmd)
172
- {
173
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
174
- u8 slave = GET_GLOBALFLAT(adrive_gf->slave);
175
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
176
-
177
- // Select device
178
- int status = await_not_bsy(iobase1);
179
- if (status < 0)
180
- return status;
181
- u8 newdh = ((cmd->device & ~ATA_CB_DH_DEV1)
182
- | (slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0));
183
- u8 olddh = inb(iobase1 + ATA_CB_DH);
184
- outb(newdh, iobase1 + ATA_CB_DH);
185
- if ((olddh ^ newdh) & (1<<4)) {
186
- // Was a device change - wait for device to become not busy.
187
- status = ndelay_await_not_bsy(iobase1);
188
- if (status < 0)
189
- return status;
190
- }
191
-
192
- // Check for ATA_CMD_(READ|WRITE)_(SECTORS|DMA)_EXT commands.
193
- if ((cmd->command & ~0x11) == ATA_CMD_READ_SECTORS_EXT) {
194
- outb(cmd->feature2, iobase1 + ATA_CB_FR);
195
- outb(cmd->sector_count2, iobase1 + ATA_CB_SC);
196
- outb(cmd->lba_low2, iobase1 + ATA_CB_SN);
197
- outb(cmd->lba_mid2, iobase1 + ATA_CB_CL);
198
- outb(cmd->lba_high2, iobase1 + ATA_CB_CH);
199
- }
200
- outb(cmd->feature, iobase1 + ATA_CB_FR);
201
- outb(cmd->sector_count, iobase1 + ATA_CB_SC);
202
- outb(cmd->lba_low, iobase1 + ATA_CB_SN);
203
- outb(cmd->lba_mid, iobase1 + ATA_CB_CL);
204
- outb(cmd->lba_high, iobase1 + ATA_CB_CH);
205
- outb(cmd->command, iobase1 + ATA_CB_CMD);
206
-
207
- return 0;
208
- }
209
-
210
- // Wait for data after calling 'send_cmd'.
211
- static int
212
- ata_wait_data(u16 iobase1)
213
- {
214
- int status = ndelay_await_not_bsy(iobase1);
215
- if (status < 0)
216
- return status;
217
-
218
- if (status & ATA_CB_STAT_ERR) {
219
- dprintf(6, "send_cmd : read error (status=%02x err=%02x)\n"
220
- , status, inb(iobase1 + ATA_CB_ERR));
221
- return -4;
222
- }
223
- if (!(status & ATA_CB_STAT_DRQ)) {
224
- dprintf(6, "send_cmd : DRQ not set (status %02x)\n", status);
225
- return -5;
226
- }
227
-
228
- return 0;
229
- }
230
-
231
- // Send an ata command that does not transfer any further data.
232
- int
233
- ata_cmd_nondata(struct atadrive_s *adrive_gf, struct ata_pio_command *cmd)
234
- {
235
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
236
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
237
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
238
-
239
- // Disable interrupts
240
- outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
241
-
242
- int ret = send_cmd(adrive_gf, cmd);
243
- if (ret)
244
- goto fail;
245
- ret = ndelay_await_not_bsy(iobase1);
246
- if (ret < 0)
247
- goto fail;
248
-
249
- if (ret & ATA_CB_STAT_ERR) {
250
- dprintf(6, "nondata cmd : read error (status=%02x err=%02x)\n"
251
- , ret, inb(iobase1 + ATA_CB_ERR));
252
- ret = -4;
253
- goto fail;
254
- }
255
- if (ret & ATA_CB_STAT_DRQ) {
256
- dprintf(6, "nondata cmd : DRQ set (status %02x)\n", ret);
257
- ret = -5;
258
- goto fail;
259
- }
260
-
261
- fail:
262
- // Enable interrupts
263
- outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
264
-
265
- return ret;
266
- }
267
-
268
-
269
- /****************************************************************
270
- * ATA PIO transfers
271
- ****************************************************************/
272
-
273
- // Transfer 'op->count' blocks (of 'blocksize' bytes) to/from drive
274
- // 'op->drive_fl'.
275
- static int
276
- ata_pio_transfer(struct disk_op_s *op, int iswrite, int blocksize)
277
- {
278
- dprintf(16, "ata_pio_transfer id=%p write=%d count=%d bs=%d buf=%p\n"
279
- , op->drive_fl, iswrite, op->count, blocksize, op->buf_fl);
280
-
281
- struct atadrive_s *adrive_gf = container_of(
282
- op->drive_fl, struct atadrive_s, drive);
283
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
284
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
285
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
286
- int count = op->count;
287
- void *buf_fl = op->buf_fl;
288
- int status;
289
- for (;;) {
290
- if (iswrite) {
291
- // Write data to controller
292
- dprintf(16, "Write sector id=%p dest=%p\n", op->drive_fl, buf_fl);
293
- if (CONFIG_ATA_PIO32)
294
- outsl_fl(iobase1, buf_fl, blocksize / 4);
295
- else
296
- outsw_fl(iobase1, buf_fl, blocksize / 2);
297
- } else {
298
- // Read data from controller
299
- dprintf(16, "Read sector id=%p dest=%p\n", op->drive_fl, buf_fl);
300
- if (CONFIG_ATA_PIO32)
301
- insl_fl(iobase1, buf_fl, blocksize / 4);
302
- else
303
- insw_fl(iobase1, buf_fl, blocksize / 2);
304
- }
305
- buf_fl += blocksize;
306
-
307
- status = pause_await_not_bsy(iobase1, iobase2);
308
- if (status < 0) {
309
- // Error
310
- op->count -= count;
311
- return status;
312
- }
313
-
314
- count--;
315
- if (!count)
316
- break;
317
- status &= (ATA_CB_STAT_BSY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR);
318
- if (status != ATA_CB_STAT_DRQ) {
319
- dprintf(6, "ata_pio_transfer : more sectors left (status %02x)\n"
320
- , status);
321
- op->count -= count;
322
- return -6;
323
- }
324
- }
325
-
326
- status &= (ATA_CB_STAT_BSY | ATA_CB_STAT_DF | ATA_CB_STAT_DRQ
327
- | ATA_CB_STAT_ERR);
328
- if (!iswrite)
329
- status &= ~ATA_CB_STAT_DF;
330
- if (status != 0) {
331
- dprintf(6, "ata_pio_transfer : no sectors left (status %02x)\n", status);
332
- return -7;
333
- }
334
-
335
- return 0;
336
- }
337
-
338
-
339
- /****************************************************************
340
- * ATA DMA transfers
341
- ****************************************************************/
342
-
343
- #define BM_CMD 0
344
- #define BM_CMD_MEMWRITE 0x08
345
- #define BM_CMD_START 0x01
346
- #define BM_STATUS 2
347
- #define BM_STATUS_IRQ 0x04
348
- #define BM_STATUS_ERROR 0x02
349
- #define BM_STATUS_ACTIVE 0x01
350
- #define BM_TABLE 4
351
-
352
- struct sff_dma_prd {
353
- u32 buf_fl;
354
- u32 count;
355
- };
356
-
357
- // Check if DMA available and setup transfer if so.
358
- static int
359
- ata_try_dma(struct disk_op_s *op, int iswrite, int blocksize)
360
- {
361
- ASSERT16();
362
- if (! CONFIG_ATA_DMA)
363
- return -1;
364
- u32 dest = (u32)op->buf_fl;
365
- if (dest & 1)
366
- // Need minimum alignment of 1.
367
- return -1;
368
- struct atadrive_s *adrive_gf = container_of(
369
- op->drive_fl, struct atadrive_s, drive);
370
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
371
- u16 iomaster = GET_GLOBALFLAT(chan_gf->iomaster);
372
- if (! iomaster)
373
- return -1;
374
- u32 bytes = op->count * blocksize;
375
- if (! bytes)
376
- return -1;
377
-
378
- // Build PRD dma structure.
379
- struct sff_dma_prd *dma = MAKE_FLATPTR(SEG_LOW, ExtraStack);
380
- struct sff_dma_prd *origdma = dma;
381
- while (bytes) {
382
- if (dma >= &origdma[16])
383
- // Too many descriptors..
384
- return -1;
385
- u32 count = bytes;
386
- u32 max = 0x10000 - (dest & 0xffff);
387
- if (count > max)
388
- count = max;
389
-
390
- SET_LOWFLAT(dma->buf_fl, dest);
391
- bytes -= count;
392
- if (!bytes)
393
- // Last descriptor.
394
- count |= 1<<31;
395
- dprintf(16, "dma@%p: %08x %08x\n", dma, dest, count);
396
- dest += count;
397
- SET_LOWFLAT(dma->count, count);
398
- dma++;
399
- }
400
-
401
- // Program bus-master controller.
402
- outl((u32)origdma, iomaster + BM_TABLE);
403
- u8 oldcmd = inb(iomaster + BM_CMD) & ~(BM_CMD_MEMWRITE|BM_CMD_START);
404
- outb(oldcmd | (iswrite ? 0x00 : BM_CMD_MEMWRITE), iomaster + BM_CMD);
405
- outb(BM_STATUS_ERROR|BM_STATUS_IRQ, iomaster + BM_STATUS);
406
-
407
- return 0;
408
- }
409
-
410
- // Transfer data using DMA.
411
- static int
412
- ata_dma_transfer(struct disk_op_s *op)
413
- {
414
- if (! CONFIG_ATA_DMA)
415
- return -1;
416
- dprintf(16, "ata_dma_transfer id=%p buf=%p\n", op->drive_fl, op->buf_fl);
417
-
418
- struct atadrive_s *adrive_gf = container_of(
419
- op->drive_fl, struct atadrive_s, drive);
420
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
421
- u16 iomaster = GET_GLOBALFLAT(chan_gf->iomaster);
422
-
423
- // Start bus-master controller.
424
- u8 oldcmd = inb(iomaster + BM_CMD);
425
- outb(oldcmd | BM_CMD_START, iomaster + BM_CMD);
426
-
427
- u32 end = timer_calc(IDE_TIMEOUT);
428
- u8 status;
429
- for (;;) {
430
- status = inb(iomaster + BM_STATUS);
431
- if (status & BM_STATUS_IRQ)
432
- break;
433
- // Transfer in progress
434
- if (timer_check(end)) {
435
- // Timeout.
436
- warn_timeout();
437
- break;
438
- }
439
- yield();
440
- }
441
- outb(oldcmd & ~BM_CMD_START, iomaster + BM_CMD);
442
-
443
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
444
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
445
- int idestatus = pause_await_not_bsy(iobase1, iobase2);
446
-
447
- if ((status & (BM_STATUS_IRQ|BM_STATUS_ACTIVE)) == BM_STATUS_IRQ
448
- && idestatus >= 0x00
449
- && (idestatus & (ATA_CB_STAT_BSY | ATA_CB_STAT_DF | ATA_CB_STAT_DRQ
450
- | ATA_CB_STAT_ERR)) == 0x00)
451
- // Success.
452
- return 0;
453
-
454
- dprintf(6, "IDE DMA error (dma=%x ide=%x/%x/%x)\n", status, idestatus
455
- , inb(iobase2 + ATA_CB_ASTAT), inb(iobase1 + ATA_CB_ERR));
456
- return -1;
457
- }
458
-
459
-
460
- /****************************************************************
461
- * ATA hard drive functions
462
- ****************************************************************/
463
-
464
- // Transfer data to harddrive using PIO protocol.
465
- static int
466
- ata_pio_cmd_data(struct disk_op_s *op, int iswrite, struct ata_pio_command *cmd)
467
- {
468
- struct atadrive_s *adrive_gf = container_of(
469
- op->drive_fl, struct atadrive_s, drive);
470
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
471
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
472
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
473
-
474
- // Disable interrupts
475
- outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
476
-
477
- int ret = send_cmd(adrive_gf, cmd);
478
- if (ret)
479
- goto fail;
480
- ret = ata_wait_data(iobase1);
481
- if (ret)
482
- goto fail;
483
- ret = ata_pio_transfer(op, iswrite, DISK_SECTOR_SIZE);
484
-
485
- fail:
486
- // Enable interrupts
487
- outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
488
- return ret;
489
- }
490
-
491
- // Transfer data to harddrive using DMA protocol.
492
- static int
493
- ata_dma_cmd_data(struct disk_op_s *op, struct ata_pio_command *cmd)
494
- {
495
- if (! CONFIG_ATA_DMA)
496
- return -1;
497
- struct atadrive_s *adrive_gf = container_of(
498
- op->drive_fl, struct atadrive_s, drive);
499
- int ret = send_cmd(adrive_gf, cmd);
500
- if (ret)
501
- return ret;
502
- return ata_dma_transfer(op);
503
- }
504
-
505
- // Read/write count blocks from a harddrive.
506
- static int
507
- ata_readwrite(struct disk_op_s *op, int iswrite)
508
- {
509
- u64 lba = op->lba;
510
-
511
- int usepio = ata_try_dma(op, iswrite, DISK_SECTOR_SIZE);
512
-
513
- struct ata_pio_command cmd;
514
- memset(&cmd, 0, sizeof(cmd));
515
-
516
- if (op->count >= (1<<8) || lba + op->count >= (1<<28)) {
517
- cmd.sector_count2 = op->count >> 8;
518
- cmd.lba_low2 = lba >> 24;
519
- cmd.lba_mid2 = lba >> 32;
520
- cmd.lba_high2 = lba >> 40;
521
- lba &= 0xffffff;
522
-
523
- if (usepio)
524
- cmd.command = (iswrite ? ATA_CMD_WRITE_SECTORS_EXT
525
- : ATA_CMD_READ_SECTORS_EXT);
526
- else
527
- cmd.command = (iswrite ? ATA_CMD_WRITE_DMA_EXT
528
- : ATA_CMD_READ_DMA_EXT);
529
- } else {
530
- if (usepio)
531
- cmd.command = (iswrite ? ATA_CMD_WRITE_SECTORS
532
- : ATA_CMD_READ_SECTORS);
533
- else
534
- cmd.command = (iswrite ? ATA_CMD_WRITE_DMA
535
- : ATA_CMD_READ_DMA);
536
- }
537
-
538
- cmd.sector_count = op->count;
539
- cmd.lba_low = lba;
540
- cmd.lba_mid = lba >> 8;
541
- cmd.lba_high = lba >> 16;
542
- cmd.device = ((lba >> 24) & 0xf) | ATA_CB_DH_LBA;
543
-
544
- int ret;
545
- if (usepio)
546
- ret = ata_pio_cmd_data(op, iswrite, &cmd);
547
- else
548
- ret = ata_dma_cmd_data(op, &cmd);
549
- if (ret)
550
- return DISK_RET_EBADTRACK;
551
- return DISK_RET_SUCCESS;
552
- }
553
-
554
- // 16bit command demuxer for ATA harddrives.
555
- int
556
- ata_process_op(struct disk_op_s *op)
557
- {
558
- if (!CONFIG_ATA)
559
- return 0;
560
-
561
- struct atadrive_s *adrive_gf = container_of(
562
- op->drive_fl, struct atadrive_s, drive);
563
- switch (op->command) {
564
- case CMD_READ:
565
- return ata_readwrite(op, 0);
566
- case CMD_WRITE:
567
- return ata_readwrite(op, 1);
568
- case CMD_RESET:
569
- ata_reset(adrive_gf);
570
- return DISK_RET_SUCCESS;
571
- case CMD_ISREADY:
572
- return isready(adrive_gf);
573
- default:
574
- return default_process_op(op);
575
- }
576
- }
577
-
578
-
579
- /****************************************************************
580
- * ATAPI functions
581
- ****************************************************************/
582
-
583
- #define CDROM_CDB_SIZE 12
584
-
585
- // Low-level atapi command transmit function.
586
- int
587
- ata_atapi_process_op(struct disk_op_s *op)
588
- {
589
- if (! CONFIG_ATA)
590
- return 0;
591
-
592
- if (op->command == CMD_WRITE || op->command == CMD_FORMAT)
593
- return DISK_RET_EWRITEPROTECT;
594
- u8 cdbcmd[CDROM_CDB_SIZE];
595
- int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd));
596
- if (blocksize < 0)
597
- return default_process_op(op);
598
-
599
- struct atadrive_s *adrive_gf = container_of(
600
- op->drive_fl, struct atadrive_s, drive);
601
- struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
602
- u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
603
- u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
604
-
605
- struct ata_pio_command cmd;
606
- memset(&cmd, 0, sizeof(cmd));
607
- cmd.lba_mid = blocksize;
608
- cmd.lba_high = blocksize >> 8;
609
- cmd.command = ATA_CMD_PACKET;
610
-
611
- // Disable interrupts
612
- outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
613
-
614
- int ret = send_cmd(adrive_gf, &cmd);
615
- if (ret)
616
- goto fail;
617
- ret = ata_wait_data(iobase1);
618
- if (ret)
619
- goto fail;
620
-
621
- // Send command to device
622
- outsw_fl(iobase1, MAKE_FLATPTR(GET_SEG(SS), cdbcmd), CDROM_CDB_SIZE / 2);
623
-
624
- int status = pause_await_not_bsy(iobase1, iobase2);
625
- if (status < 0) {
626
- ret = status;
627
- goto fail;
628
- }
629
-
630
- if (status & ATA_CB_STAT_ERR) {
631
- u8 err = inb(iobase1 + ATA_CB_ERR);
632
- // skip "Not Ready"
633
- if (err != 0x20)
634
- dprintf(6, "send_atapi_cmd : read error (status=%02x err=%02x)\n"
635
- , status, err);
636
- ret = -2;
637
- goto fail;
638
- }
639
- if (blocksize) {
640
- if (!(status & ATA_CB_STAT_DRQ)) {
641
- dprintf(6, "send_atapi_cmd : DRQ not set (status %02x)\n", status);
642
- ret = -3;
643
- goto fail;
644
- }
645
-
646
- ret = ata_pio_transfer(op, 0, blocksize);
647
- }
648
-
649
- fail:
650
- // Enable interrupts
651
- outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
652
- if (ret)
653
- return DISK_RET_EBADTRACK;
654
- return DISK_RET_SUCCESS;
655
- }
656
-
657
-
658
- /****************************************************************
659
- * ATA detect and init
660
- ****************************************************************/
661
-
662
- // Send an identify device or identify device packet command.
663
- static int
664
- send_ata_identity(struct atadrive_s *adrive, u16 *buffer, int command)
665
- {
666
- memset(buffer, 0, DISK_SECTOR_SIZE);
667
-
668
- struct disk_op_s dop;
669
- memset(&dop, 0, sizeof(dop));
670
- dop.drive_fl = &adrive->drive;
671
- dop.count = 1;
672
- dop.lba = 1;
673
- dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
674
-
675
- struct ata_pio_command cmd;
676
- memset(&cmd, 0, sizeof(cmd));
677
- cmd.command = command;
678
-
679
- return ata_pio_cmd_data(&dop, 0, &cmd);
680
- }
681
-
682
- // Extract the ATA/ATAPI version info.
683
- int
684
- ata_extract_version(u16 *buffer)
685
- {
686
- // Extract ATA/ATAPI version.
687
- u16 ataversion = buffer[80];
688
- u8 version;
689
- for (version=15; version>0; version--)
690
- if (ataversion & (1<<version))
691
- break;
692
- return version;
693
- }
694
-
695
- #define MAXMODEL 40
696
-
697
- // Extract the ATA/ATAPI model info.
698
- char *
699
- ata_extract_model(char *model, u32 size, u16 *buffer)
700
- {
701
- // Read model name
702
- int i;
703
- for (i=0; i<size/2; i++)
704
- *(u16*)&model[i*2] = be16_to_cpu(buffer[27+i]);
705
- model[size] = 0x00;
706
- nullTrailingSpace(model);
707
- return model;
708
- }
709
-
710
- // Common init code between ata and atapi
711
- static struct atadrive_s *
712
- init_atadrive(struct atadrive_s *dummy, u16 *buffer)
713
- {
714
- struct atadrive_s *adrive = malloc_fseg(sizeof(*adrive));
715
- if (!adrive) {
716
- warn_noalloc();
717
- return NULL;
718
- }
719
- memset(adrive, 0, sizeof(*adrive));
720
- adrive->chan_gf = dummy->chan_gf;
721
- adrive->slave = dummy->slave;
722
- adrive->drive.cntl_id = adrive->chan_gf->ataid * 2 + dummy->slave;
723
- adrive->drive.removable = (buffer[0] & 0x80) ? 1 : 0;
724
- return adrive;
725
- }
726
-
727
- // Detect if the given drive is an atapi - initialize it if so.
728
- static struct atadrive_s *
729
- init_drive_atapi(struct atadrive_s *dummy, u16 *buffer)
730
- {
731
- // Send an IDENTIFY_DEVICE_PACKET command to device
732
- int ret = send_ata_identity(dummy, buffer, ATA_CMD_IDENTIFY_PACKET_DEVICE);
733
- if (ret)
734
- return NULL;
735
-
736
- // Success - setup as ATAPI.
737
- struct atadrive_s *adrive = init_atadrive(dummy, buffer);
738
- if (!adrive)
739
- return NULL;
740
- adrive->drive.type = DTYPE_ATA_ATAPI;
741
- adrive->drive.blksize = CDROM_SECTOR_SIZE;
742
- adrive->drive.sectors = (u64)-1;
743
- u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
744
- char model[MAXMODEL+1];
745
- char *desc = znprintf(MAXDESCSIZE
746
- , "DVD/CD [ata%d-%d: %s ATAPI-%d %s]"
747
- , adrive->chan_gf->ataid, adrive->slave
748
- , ata_extract_model(model, MAXMODEL, buffer)
749
- , ata_extract_version(buffer)
750
- , (iscd ? "DVD/CD" : "Device"));
751
- dprintf(1, "%s\n", desc);
752
-
753
- // fill cdidmap
754
- if (iscd) {
755
- int prio = bootprio_find_ata_device(adrive->chan_gf->pci_tmp,
756
- adrive->chan_gf->chanid,
757
- adrive->slave);
758
- boot_add_cd(&adrive->drive, desc, prio);
759
- }
760
-
761
- return adrive;
762
- }
763
-
764
- // Detect if the given drive is a regular ata drive - initialize it if so.
765
- static struct atadrive_s *
766
- init_drive_ata(struct atadrive_s *dummy, u16 *buffer)
767
- {
768
- // Send an IDENTIFY_DEVICE command to device
769
- int ret = send_ata_identity(dummy, buffer, ATA_CMD_IDENTIFY_DEVICE);
770
- if (ret)
771
- return NULL;
772
-
773
- // Success - setup as ATA.
774
- struct atadrive_s *adrive = init_atadrive(dummy, buffer);
775
- if (!adrive)
776
- return NULL;
777
- adrive->drive.type = DTYPE_ATA;
778
- adrive->drive.blksize = DISK_SECTOR_SIZE;
779
-
780
- adrive->drive.pchs.cylinder = buffer[1];
781
- adrive->drive.pchs.head = buffer[3];
782
- adrive->drive.pchs.sector = buffer[6];
783
-
784
- u64 sectors;
785
- if (buffer[83] & (1 << 10)) // word 83 - lba48 support
786
- sectors = *(u64*)&buffer[100]; // word 100-103
787
- else
788
- sectors = *(u32*)&buffer[60]; // word 60 and word 61
789
- adrive->drive.sectors = sectors;
790
- u64 adjsize = sectors >> 11;
791
- char adjprefix = 'M';
792
- if (adjsize >= (1 << 16)) {
793
- adjsize >>= 10;
794
- adjprefix = 'G';
795
- }
796
- char model[MAXMODEL+1];
797
- char *desc = znprintf(MAXDESCSIZE
798
- , "ata%d-%d: %s ATA-%d Hard-Disk (%u %ciBytes)"
799
- , adrive->chan_gf->ataid, adrive->slave
800
- , ata_extract_model(model, MAXMODEL, buffer)
801
- , ata_extract_version(buffer)
802
- , (u32)adjsize, adjprefix);
803
- dprintf(1, "%s\n", desc);
804
-
805
- int prio = bootprio_find_ata_device(adrive->chan_gf->pci_tmp,
806
- adrive->chan_gf->chanid,
807
- adrive->slave);
808
- // Register with bcv system.
809
- boot_add_hd(&adrive->drive, desc, prio);
810
-
811
- return adrive;
812
- }
813
-
814
- static u32 SpinupEnd;
815
-
816
- // Wait for non-busy status and check for "floating bus" condition.
817
- static int
818
- powerup_await_non_bsy(u16 base)
819
- {
820
- u8 orstatus = 0;
821
- u8 status;
822
- for (;;) {
823
- status = inb(base+ATA_CB_STAT);
824
- if (!(status & ATA_CB_STAT_BSY))
825
- break;
826
- orstatus |= status;
827
- if (orstatus == 0xff) {
828
- dprintf(4, "powerup IDE floating\n");
829
- return orstatus;
830
- }
831
- if (timer_check(SpinupEnd)) {
832
- warn_timeout();
833
- return -1;
834
- }
835
- yield();
836
- }
837
- dprintf(6, "powerup iobase=%x st=%x\n", base, status);
838
- return status;
839
- }
840
-
841
- // Detect any drives attached to a given controller.
842
- static void
843
- ata_detect(void *data)
844
- {
845
- struct ata_channel_s *chan_gf = data;
846
- struct atadrive_s dummy;
847
- memset(&dummy, 0, sizeof(dummy));
848
- dummy.chan_gf = chan_gf;
849
- // Device detection
850
- int didreset = 0;
851
- u8 slave;
852
- for (slave=0; slave<=1; slave++) {
853
- // Wait for not-bsy.
854
- u16 iobase1 = chan_gf->iobase1;
855
- int status = powerup_await_non_bsy(iobase1);
856
- if (status < 0)
857
- continue;
858
- u8 newdh = slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0;
859
- outb(newdh, iobase1+ATA_CB_DH);
860
- ndelay(400);
861
- status = powerup_await_non_bsy(iobase1);
862
- if (status < 0)
863
- continue;
864
-
865
- // Check if ioport registers look valid.
866
- outb(newdh, iobase1+ATA_CB_DH);
867
- u8 dh = inb(iobase1+ATA_CB_DH);
868
- outb(0x55, iobase1+ATA_CB_SC);
869
- outb(0xaa, iobase1+ATA_CB_SN);
870
- u8 sc = inb(iobase1+ATA_CB_SC);
871
- u8 sn = inb(iobase1+ATA_CB_SN);
872
- dprintf(6, "ata_detect ata%d-%d: sc=%x sn=%x dh=%x\n"
873
- , chan_gf->ataid, slave, sc, sn, dh);
874
- if (sc != 0x55 || sn != 0xaa || dh != newdh)
875
- continue;
876
-
877
- // Prepare new drive.
878
- dummy.slave = slave;
879
-
880
- // reset the channel
881
- if (!didreset) {
882
- ata_reset(&dummy);
883
- didreset = 1;
884
- }
885
-
886
- // check for ATAPI
887
- u16 buffer[256];
888
- struct atadrive_s *adrive = init_drive_atapi(&dummy, buffer);
889
- if (!adrive) {
890
- // Didn't find an ATAPI drive - look for ATA drive.
891
- u8 st = inb(iobase1+ATA_CB_STAT);
892
- if (!st)
893
- // Status not set - can't be a valid drive.
894
- continue;
895
-
896
- // Wait for RDY.
897
- int ret = await_rdy(iobase1);
898
- if (ret < 0)
899
- continue;
900
-
901
- // check for ATA.
902
- adrive = init_drive_ata(&dummy, buffer);
903
- if (!adrive)
904
- // No ATA drive found
905
- continue;
906
- }
907
-
908
- u16 resetresult = buffer[93];
909
- dprintf(6, "ata_detect resetresult=%04x\n", resetresult);
910
- if (!slave && (resetresult & 0xdf61) == 0x4041)
911
- // resetresult looks valid and device 0 is responding to
912
- // device 1 requests - device 1 must not be present - skip
913
- // detection.
914
- break;
915
- }
916
- }
917
-
918
- // Initialize an ata controller and detect its drives.
919
- static void
920
- init_controller(struct pci_device *pci, int chanid, int irq
921
- , u32 port1, u32 port2, u32 master)
922
- {
923
- static int ataid = 0;
924
- struct ata_channel_s *chan_gf = malloc_fseg(sizeof(*chan_gf));
925
- if (!chan_gf) {
926
- warn_noalloc();
927
- return;
928
- }
929
- chan_gf->ataid = ataid++;
930
- chan_gf->chanid = chanid;
931
- chan_gf->irq = irq;
932
- chan_gf->pci_bdf = pci ? pci->bdf : -1;
933
- chan_gf->pci_tmp = pci;
934
- chan_gf->iobase1 = port1;
935
- chan_gf->iobase2 = port2;
936
- chan_gf->iomaster = master;
937
- dprintf(1, "ATA controller %d at %x/%x/%x (irq %d dev %x)\n"
938
- , ataid, port1, port2, master, irq, chan_gf->pci_bdf);
939
- run_thread(ata_detect, chan_gf);
940
- }
941
-
942
- #define IRQ_ATA1 14
943
- #define IRQ_ATA2 15
944
-
945
- // Handle controllers on an ATA PCI device.
946
- static void
947
- init_pciata(struct pci_device *pci, u8 prog_if)
948
- {
949
- u8 pciirq = pci_config_readb(pci->bdf, PCI_INTERRUPT_LINE);
950
- int master = 0;
951
- if (CONFIG_ATA_DMA && prog_if & 0x80) {
952
- // Check for bus-mastering.
953
- u32 bar = pci_config_readl(pci->bdf, PCI_BASE_ADDRESS_4);
954
- if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
955
- master = pci_enable_iobar(pci, PCI_BASE_ADDRESS_4);
956
- pci_enable_busmaster(pci);
957
- }
958
- }
959
-
960
- u32 port1, port2, irq;
961
- if (prog_if & 1) {
962
- port1 = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0);
963
- port2 = pci_enable_iobar(pci, PCI_BASE_ADDRESS_1);
964
- if (!port1 || !port2)
965
- return;
966
- irq = pciirq;
967
- } else {
968
- port1 = PORT_ATA1_CMD_BASE;
969
- port2 = PORT_ATA1_CTRL_BASE;
970
- irq = IRQ_ATA1;
971
- }
972
- init_controller(pci, 0, irq, port1, port2, master);
973
-
974
- if (prog_if & 4) {
975
- port1 = pci_enable_iobar(pci, PCI_BASE_ADDRESS_2);
976
- port2 = pci_enable_iobar(pci, PCI_BASE_ADDRESS_3);
977
- if (!port1 || !port2)
978
- return;
979
- irq = pciirq;
980
- } else {
981
- port1 = PORT_ATA2_CMD_BASE;
982
- port2 = PORT_ATA2_CTRL_BASE;
983
- irq = IRQ_ATA2;
984
- }
985
- init_controller(pci, 1, irq, port1, port2, master ? master + 8 : 0);
986
- }
987
-
988
- static void
989
- found_genericata(struct pci_device *pci, void *arg)
990
- {
991
- init_pciata(pci, pci->prog_if);
992
- }
993
-
994
- static void
995
- found_compatibleahci(struct pci_device *pci, void *arg)
996
- {
997
- if (CONFIG_AHCI)
998
- // Already handled directly via native ahci interface.
999
- return;
1000
- init_pciata(pci, 0x8f);
1001
- }
1002
-
1003
- static const struct pci_device_id pci_ata_tbl[] = {
1004
- PCI_DEVICE_CLASS(PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE
1005
- , found_genericata),
1006
- PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4391, found_compatibleahci),
1007
- PCI_DEVICE_END,
1008
- };
1009
-
1010
- // Locate and init ata controllers.
1011
- static void
1012
- ata_scan(void)
1013
- {
1014
- if (CONFIG_QEMU && hlist_empty(&PCIDevices)) {
1015
- // No PCI devices found - probably a QEMU "-M isapc" machine.
1016
- // Try using ISA ports for ATA controllers.
1017
- init_controller(NULL, 0, IRQ_ATA1
1018
- , PORT_ATA1_CMD_BASE, PORT_ATA1_CTRL_BASE, 0);
1019
- init_controller(NULL, 1, IRQ_ATA2
1020
- , PORT_ATA2_CMD_BASE, PORT_ATA2_CTRL_BASE, 0);
1021
- return;
1022
- }
1023
-
1024
- // Scan PCI bus for ATA adapters
1025
- struct pci_device *pci;
1026
- foreachpci(pci) {
1027
- pci_init_device(pci_ata_tbl, pci, NULL);
1028
- }
1029
- }
1030
-
1031
- void
1032
- ata_setup(void)
1033
- {
1034
- ASSERT32FLAT();
1035
- if (!CONFIG_ATA)
1036
- return;
1037
-
1038
- dprintf(3, "init hard drives\n");
1039
-
1040
- SpinupEnd = timer_calc(IDE_TIMEOUT);
1041
- ata_scan();
1042
-
1043
- SET_BDA(disk_control_byte, 0xc0);
1044
-
1045
- enable_hwirq(14, FUNC16(entry_76));
1046
- }