Guest User

Untitled

a guest
May 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. #include "port.h"
  2.  
  3. Port::Port(uint16_t portnumber)
  4. {
  5. this->portnumber = portnumber;
  6. }
  7.  
  8. Port::~Port()
  9. {
  10. }
  11.  
  12. Port8Bit::Port8Bit(uint8_t portnumber)
  13. : Port(portnumber)
  14. {
  15. }
  16.  
  17. Port8Bit::~Port8Bit()
  18. {
  19. }
  20.  
  21. void Port8Bit::Write(uint8_t data)
  22. {
  23. __asm__ volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber);
  24. }
  25.  
  26. uint8_t Port8Bit::Read()
  27. {
  28. uint8_t result;
  29. __asm__ volatile("inb %1, %0" : : "=a" (result) : "Nd" (portnumber);
  30. return result;
  31. }
  32.  
  33. Port8BitSlow::Port8BitSlow(uint8_t portnumber)
  34. : Port(portnumber)
  35. {
  36. }
  37.  
  38. Port8BitSlow::~Port8BitSlow()
  39. {
  40. }
  41.  
  42. void Port8BitSlow::Write(uint8_t data)
  43. {
  44. __asm__ volatile("outb %0, %1njmp 1fn1: jmp 1fn1:" : : "a" (data), "Nd" (portnumber);
  45. }
  46.  
  47. Port16Bit::Port16Bit(uint16_t portnumber)
  48. : Port(portnumber)
  49. {
  50. }
  51.  
  52. Port16Bit::~Port16Bit()
  53. {
  54. }
  55.  
  56. void Port16Bit::Write(uint16_t data)
  57. {
  58. __asm__ volatile("outw %0, %1" : : "a" (data), "Nd" (portnumber);
  59. }
  60.  
  61. uint16_t Port16Bit::Read()
  62. {
  63. uint16_t result;
  64. __asm__ volatile("inw %1, %0" : : "=a" (result) : "Nd" (portnumber);
  65. return result;
  66. }
  67.  
  68. Port32Bit::Port32Bit(uint16_t portnumber)
  69. : Port(portnumber)
  70. {
  71. }
  72.  
  73. Port32Bit::~Port32Bit()
  74. {
  75. }
  76.  
  77. void Port32BitWrite(uint32_t data)
  78. {
  79. __asm__ volatile("outl %0, %1" : : "a" (data), "Nd" (portnumber)));
  80. }
  81.  
  82. uint32_t Port16BitRead()
  83. {
  84. uint32_t result;
  85. __asm__ volatile("inl %1, %0" : "=a" (result) : "Nd" (portnumber)));
  86. return result;
  87. }
  88.  
  89. #ifndef __PORT_H
  90. #define __PORT_H
  91.  
  92.  
  93. #include "types.h"
  94.  
  95.  
  96. class Port
  97. {
  98. protected:
  99. uint16_t portnumber;
  100. Port(uint16_t portnumber);
  101. ~Port();
  102. };
  103.  
  104. class Port8Bit : public Port
  105. {
  106. public:
  107. Port8Bit(uint16_t portnumber);
  108. ~Port8Bit();
  109. virtual void Write(uint8_t data);
  110. virtual uint8_t Read();
  111. };
  112.  
  113. class Port8BitSlow : public Port8Bit
  114. {
  115. public:
  116. Port8BitSlow(uint16_t portnumber);
  117. ~Port8BitSlow();
  118. virtual void Write(uint8_t data);
  119. };
  120.  
  121. class Port16Bit : public Port
  122. {
  123. public:
  124. Port16Bit(uint16_t portnumber);
  125. ~Port16Bit();
  126. virtual void Write(uint16_t data);
  127. virtual uint16_t Read();
  128. };
  129.  
  130. class Port32Bit : public Port
  131. {
  132. public:
  133. Port32Bit(uint16_t portnumber);
  134. ~Port32Bit();
  135. virtual void Write(uint32_t data);
  136. virtual uint32_t Read();
  137. };
  138.  
  139.  
  140. #endif
  141.  
  142. sergey@COMPUTER:~/Рабочий стол/myOS5$ make clean
  143. rm -f loader.o gdt.o port.o kernel.o mykernel.bin mykernel.iso
  144. sergey@COMPUTER:~/Рабочий стол/myOS5$ make run
  145. as --32 -o loader.o loader.s
  146. g++ -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -o gdt.o -c gdt.cpp
  147. g++ -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -o port.o -c port.cpp
  148. port.cpp: In member function ‘virtual void Port8Bit::Write(uint8_t)’:
  149. port.cpp:27:35: error: expected ‘)’ before ‘:’ token
  150. __asm__volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber);
  151. ^
  152. port.cpp:27:67: error: expression cannot be used as a function
  153. __asm__volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber);
  154. ^
  155. port.cpp: In member function ‘virtual uint8_t Port8Bit::Read()’:
  156. port.cpp:33:34: error: expected ‘)’ before ‘:’ token
  157. __asm__volatile("inb %1, %0" : : "=a" (result) : "Nd" (portnumber);
  158. ^
  159. port.cpp: In constructor ‘Port8BitSlow::Port8BitSlow(uint16_t)’:
  160. port.cpp:40:3: error: type ‘Port’ is not a direct base of ‘Port8BitSlow’
  161. : Port(portnumber)
  162. ^
  163. port.cpp:40:18: error: no matching function for call to ‘Port8Bit::Port8Bit()’
  164. : Port(portnumber)
  165. ^
  166. port.cpp:16:1: note: candidate: Port8Bit::Port8Bit(uint16_t)
  167. Port8Bit::Port8Bit(uint16_t portnumber)
  168. ^
  169. port.cpp:16:1: note: candidate expects 1 argument, 0 provided
  170. In file included from port.cpp:2:0:
  171. port.h:17:11: note: candidate: Port8Bit::Port8Bit(const Port8Bit&)
  172. class Port8Bit : public Port
  173. ^
  174. port.h:17:11: note: candidate expects 1 argument, 0 provided
  175. port.cpp: In member function ‘virtual void Port8BitSlow::Write(uint8_t)’:
  176. port.cpp:50:58: error: expected ‘)’ before ‘:’ token
  177. __asm__volatile("outb %0, %1njmp 1fn1: jmp 1fn1:" : : "a" (data), "Nd" (
  178. ^
  179. port.cpp:50:90: error: expression cannot be used as a function
  180. olatile("outb %0, %1njmp 1fn1: jmp 1fn1:" : : "a" (data), "Nd" (portnumber);
  181. ^
  182. port.cpp: In member function ‘virtual void Port16Bit::Write(uint16_t)’:
  183. port.cpp:68:35: error: expected ‘)’ before ‘:’ token
  184. __asm__volatile("outw %0, %1" : : "a" (data), "Nd" (portnumber);
  185. ^
  186. port.cpp:68:67: error: expression cannot be used as a function
  187. __asm__volatile("outw %0, %1" : : "a" (data), "Nd" (portnumber);
  188. ^
  189. port.cpp: In member function ‘virtual uint16_t Port16Bit::Read()’:
  190. port.cpp:74:34: error: expected ‘)’ before ‘:’ token
  191. __asm__volatile("inw %1, %0" : : "=a" (result) : "Nd" (portnumber);
  192. ^
  193. port.cpp: In member function ‘virtual void Port32Bit::Write(uint32_t)’:
  194. port.cpp:94:35: error: expected ‘)’ before ‘:’ token
  195. __asm__volatile("outl %0, %1" : : "a" (data), "Nd" (portnumber)));
  196. ^
  197. port.cpp:94:67: error: expression cannot be used as a function
  198. __asm__volatile("outl %0, %1" : : "a" (data), "Nd" (portnumber)));
  199. ^
  200. port.cpp:94:68: error: ‘__asm__volatile’ was not declared in this scope
  201. __asm__volatile("outl %0, %1" : : "a" (data), "Nd" (portnumber)));
  202. ^
  203. port.cpp: At global scope:
  204. port.cpp:97:10: error: prototype for ‘uint32_t Port16Bit::Read()’ does not match any in class ‘Port16Bit’
  205. uint32_t Port16Bit::Read()
  206. ^
  207. port.cpp:71:10: error: candidate is: virtual uint16_t Port16Bit::Read()
  208. uint16_t Port16Bit::Read()
  209. ^
  210. Makefile:9: ошибка выполнения рецепта для цели «port.o»
  211. make: *** [port.o] Ошибка 1
  212. sergey@COMPUTER:~/Рабочий стол/myOS5$
Add Comment
Please, Sign In to add comment