Guest User

MachinimaOS kernel pre-boot IDE driver

a guest
Oct 18th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;MachinimaOS kernel pre-boot IDE driver
  2. ;    Copyright (C) 2013 Jonathan Strobl ([email protected])
  3.  
  4. ;This program is free software; you can redistribute it and/or modify
  5. ;    it under the terms of the GNU General Public License as published by
  6. ;    the Free Software Foundation; either version 2 of the License, or
  7. ;    (at your option) any later version.
  8. ;
  9. ;    This program is distributed in the hope that it will be useful,
  10. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;    GNU General Public License for more details.
  13. ;
  14. ;    You should have received a copy of the GNU General Public License along
  15. ;    with this program; if not, write to the Free Software Foundation, Inc.,
  16. ;    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  
  18.  
  19.  
  20. ;ASM-Merkmal für IDE, auskommentiert
  21. {
  22. option casemap:none        ;Assembler Merkmal
  23. }
  24.  
  25.  
  26.  
  27. BOOTMEDIUM_KERNEL_DRIVER:
  28.  
  29. ;CONSTANTS
  30.  
  31. ;Supported card type
  32. .CARD_TYPE: EQU 2
  33.  
  34. ;Register addresses
  35. .ALTERNATE_STATUS_REG: EQU 140
  36. .DEVICE_CTRL_REG: EQU 140
  37. .DATA_REG_LOW: EQU 144
  38. .DATA_REG_HIGH: EQU 145
  39. .ERROR_REG: EQU 146
  40. .FEATURES_REG: EQU 146
  41. .SECTOR_COUNT_REG: EQU 148
  42. .SECTOR_NUMBER_REG: EQU 150
  43. .LBA_BITS_0_7_REG: EQU 150
  44. .CYLINDER_LOW_REG: EQU 152
  45. .LBA_BITS_8_15_REG: EQU 152
  46. .CYLINDER_HIGH_REG: EQU 154
  47. .LBA_BITS_16_23_REG: EQU 154
  48. .DEVICE_REG: EQU 156
  49. .LBA_BITS_24_27_REG: EQU 156
  50. .STATUS_REG: EQU 158
  51. .COMMAND_REG: EQU 158
  52.  
  53. ;Bit masks
  54. .BMASK_BUSY: EQU 1000 0000b
  55. .BMASK_DRDY: EQU 0100 0000b
  56. .BMASK_DF: EQU 0010 0000b
  57. .BMASK_DSC: EQU 0001 0000b
  58. .BMASK_DRQ: EQU 0000 1000b
  59. .BMASK_CORR: EQU 0000 0100b
  60. .BMASK_IDX: EQU 0000 0010b
  61. .BMASK_ERR: EQU 0000 0001b
  62.  
  63.  
  64. ;CODE
  65.  
  66. .INIT:
  67.   ;In: C (Slot)
  68.  
  69.   PUSH AF
  70.   PUSH BC
  71.  
  72.   LD A, C
  73.   LD (.drvprop_deviceslot), A
  74.   PUSH BC
  75.     LD IY, _KRNL_get_device_type
  76.     RST 10h
  77.     LD A, C
  78.     CP A, .CARD_TYPE
  79.     JP Z, .INIT_type_correct
  80.       LD A, 0
  81.       LD (.drvprop_deviceslot), A
  82.     .INIT_type_correct:
  83.   POP BC
  84.  
  85.   POP BC
  86.   POP AF
  87. RET
  88.  
  89. .READ_REGISTER:
  90.   ;In: C (Adr)
  91.   ;Out: D (Data)
  92.  
  93.   PUSH AF
  94.   PUSH BC
  95.  
  96.   LD B, C
  97.   LD A, (.drvprop_deviceslot)
  98.   LD C, A
  99.   IN D, (C)
  100.  
  101.   POP BC
  102.   POP AF
  103. RET
  104.  
  105. .WRITE_REGISTER:
  106.   ;In: C (Adr), D (Data)
  107.  
  108.   PUSH AF
  109.   PUSH BC
  110.  
  111.   LD B, C
  112.   LD A, (.drvprop_deviceslot)
  113.   LD C, A
  114.   OUT (C), D
  115.  
  116.   POP BC
  117.   POP AF
  118. RET
  119.  
  120. .READDATA:
  121.   ;In: HL (dest adr)
  122.   ;Out: HL (ptr to end of data)
  123.  
  124.   PUSH AF
  125.   PUSH BC
  126.   PUSH DE
  127.  
  128.   .READDATA_readloop:
  129.     ;Auf weitere Daten prüfen
  130.     .READDATA_check_for_data_loop:
  131.       LD C, .STATUS_REG
  132.       CALL .READ_REGISTER
  133.       LD A, .BMASK_BUSY
  134.       AND A, D
  135.       JP NZ, .READDATA_check_for_data_loop
  136.       LD A, .BMASK_ERR
  137.       AND A, D
  138.       JP NZ, .READDATA_finish
  139.       LD A, .BMASK_DRQ
  140.       AND A, D
  141.       JP Z, .READDATA_finish
  142.    
  143.     ;Daten lesen
  144.    
  145.     ;Lesen vom Low-Register triggert 16-Byte-Read des Controllers,
  146.     ;High-Byte bleibt im Puffer des Controllers
  147.     LD C, .DATA_REG_LOW
  148.     CALL .READ_REGISTER
  149.     LD (HL), D
  150.     INC HL
  151.    
  152.     ;High-Byte aus dem Controller-Puffer lesen
  153.     LD C, .DATA_REG_HIGH
  154.     CALL .READ_REGISTER
  155.     LD (HL), D
  156.     INC HL
  157.   JP .READDATA_readloop
  158.   .READDATA_finish:
  159.  
  160.   POP DE
  161.   POP BC
  162.   POP AF
  163. RET
  164.  
  165.  
  166. ;DATA
  167.  
  168. .drvprop_deviceslot: DB 0
Advertisement
Add Comment
Please, Sign In to add comment