_mon.s 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #
  2. ! $Source$
  3. ! $State$
  4. ! $Revision$
  5. ! Declare segments (the order is important).
  6. .sect .text
  7. .sect .rom
  8. .sect .data
  9. .sect .bss
  10. .sect .bss
  11. .define __sys_params_in
  12. .comm __sys_params_in, 6
  13. .define __sys_params_out
  14. .comm __sys_params_out, 2
  15. .comm opcode, 2
  16. .comm returnto, 2
  17. .sect .text
  18. ! Called on system call. This does *not* use the C calling convention:
  19. ! ax: syscall number
  20. ! stack: ( param3 param2 param1 - result )
  21. .define .mon
  22. .mon:
  23. mov (opcode), ax
  24. pop (returnto)
  25. cmp ax, 1
  26. je exit
  27. cmp ax, 3
  28. je read
  29. cmp ax, 4
  30. je write
  31. cmp ax, 5
  32. je open
  33. cmp ax, 6
  34. je nop_1 ! close
  35. cmp ax, 20
  36. je nop_0 ! getpid
  37. cmp ax, 35
  38. je nop_1 ! time
  39. cmp ax, 48
  40. je sigtrp
  41. cmp ax, 54
  42. je ioctl
  43. ! Syscall not supported --- write out an error message and halt.
  44. unsupported:
  45. mov si, msg
  46. 1:
  47. lodsb
  48. andb al, al
  49. jz 2f
  50. movb ah, 0xE ! service
  51. mov bx, 0x0007 ! page 0, white
  52. int 0x10
  53. jmp 1b
  54. 2:
  55. ! Write out the syscall number.
  56. mov dx, (opcode)
  57. mov cx, 4 ! 4 hex digits
  58. 1:
  59. rol dx, 1 ! rotate so that highest 4 bits are at the bottom
  60. rol dx, 1
  61. rol dx, 1
  62. rol dx, 1
  63. mov ax, 0xE0F ! ah = request, al = mask for nybble
  64. andb al, dl
  65. addb al, 0x90 ! convert al to ascii hex (four instructions)
  66. daa
  67. adcb al, 0x40
  68. daa
  69. int 0x10
  70. loop 1b
  71. ! Exit.
  72. jmp EXIT
  73. .sect .rom
  74. msg:
  75. .asciz 'NOSYS'
  76. .sect .text
  77. exit:
  78. jmp EXIT
  79. read:
  80. mov ax, __sys_read
  81. jmp in_3_out_1
  82. write:
  83. mov ax, __sys_write
  84. jmp in_3_out_1
  85. open:
  86. add sp, 2*2
  87. jmp unimplemented
  88. ioctl:
  89. mov ax, __sys_ioctl
  90. jmp in_3_out_0
  91. sigtrp:
  92. add sp, 4
  93. jmp unimplemented
  94. in_3_out_0:
  95. pop (__sys_params_in+0)
  96. pop (__sys_params_in+2)
  97. pop (__sys_params_in+4)
  98. call ax
  99. jmp out_0
  100. in_3_out_1:
  101. pop (__sys_params_in+0)
  102. pop (__sys_params_in+2)
  103. pop (__sys_params_in+4)
  104. call ax
  105. jmp out_1
  106. out_0:
  107. or ax, ax
  108. jnz failed
  109. push ax
  110. jmp return
  111. out_1:
  112. or ax, ax
  113. jnz failed
  114. push (__sys_params_out)
  115. push ax
  116. jmp return
  117. unimplemented:
  118. mov ax, EBADMON
  119. failed:
  120. push ax
  121. push ax
  122. jmp return
  123. nop_1:
  124. add sp, 1*2
  125. jmp nop_0
  126. nop_3:
  127. add sp, 3*2
  128. nop_0:
  129. mov ax, 0
  130. push ax
  131. jmp return
  132. return:
  133. jmp (returnto)