You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
12 KiB

пре 5 година
пре 3 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 3 година
пре 5 година
пре 5 година
пре 3 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 3 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 3 година
пре 5 година
пре 3 година
пре 3 година
  1. BITS 16
  2. start_sing:
  3. ; loading essentials for SingOS to run
  4. mov ax, 0x0150
  5. mov ds, ax
  6. mov es, ax
  7. ; Setup stack
  8. mov ax, 0x8fc0
  9. mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
  10. mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
  11. mov bp, sp
  12. mov [global_disk_FSCI_LBA_position], bx ; passed by the volume boot record.
  13. mov [global_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
  14. ; This number is set by the bios
  15. ;call lsfs_check_extended_support ; Check that the int 0x13 extended read and write is available
  16. ; setup file system information
  17. ; mov cx, [global_disk_FSCI_LBA_position]
  18. ; mov WORD [Parameter_Struct.buffer_segment], 0x50
  19. ; mov WORD [Parameter_Struct.buffer_address], 0x2000 ; Heap memory start adresses for the file system
  20. ; mov WORD [Parameter_Struct.buffer_size], 0x3000 ; End address for the heap
  21. ; mov WORD [Parameter_Struct.data_length], cx
  22. ;
  23. ; mov bx, ds
  24. ; mov cx, Parameter_Struct
  25. ; mov ax, 0x1
  26. ; push cx
  27. ; push bx
  28. ; push ax
  29. ; mov cx, 0x50
  30. ; mov ds, cx
  31. ; mov es, cx
  32. ; call 0x50:0x00
  33. ; add sp, 0x6 ; skip the paramerts
  34. ; mov cx, 0x0150
  35. ; mov ds, cx
  36. ; mov es, cx
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. ; SYSTEM CALL TABLE STARTING AT POSITION 0x0050:0x0000
  39. ; To already support 64-bit, the entries is 64-bit
  40. ; But in 16-bit, the adresses is only 16-bit
  41. ; These are stored in the first 16-bits
  42. ; There is reserved 2 sectors to the table witch means that we have room for
  43. ; 128 System Calls
  44. ; |----|----------------------------------------------------------------------------|
  45. ; | 1 | Master Table| call [0x0050:0x0000] Pointer to the Master File Table |
  46. ; |----|----------------------------------------------------------------------------|
  47. ; | 2 | FILE SYSTEM | call [0x0050:0x0008] for arguments see under the file system |
  48. ; |----|----------------------------------------------------------------------------|
  49. ; | 3 | OS_LIB | call [0x0050:0x0016] for arguments see under the file system |
  50. ; |----|----------------------------------------------------------------------------|
  51. ; | 1 | FILE SYSTEM | call [0x0050:0x0000] for arguments see under the file system |
  52. ; |----|----------------------------------------------------------------------------|
  53. ; | 2 | OS_LIB | call [0x0050:0x0008] for arguments see under the file system |
  54. ; |----|----------------------------------------------------------------------------|
  55. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  56. xor bx, bx
  57. mov al, 0x49
  58. mov ah, 0x0E
  59. int 0x10
  60. jmp 0x0150:sing_loaded
  61. ;%include "mem_lib/mem_lib.nasm"
  62. %include "lib/os_lib.nasm"
  63. %include "lib/string.nasm"
  64. %include "lib/debug_tools.nasm"
  65. %include "lib/std_power.nasm"
  66. %include "lib/svim.nasm"
  67. %include "lib/xex.nasm"
  68. %include "filesystems/lsfs/lsfs.nasm" ; old filesystem was ;%include "vsfs/vsfs.nasm"
  69. %include "CLI/CLI.nasm"
  70. sing_loaded: ; SingOS is ready for the user:
  71. xor bx, bx
  72. mov al, 0x49
  73. mov ah, 0x0E
  74. int 0x10
  75. ; mov ax, 0x8fc0
  76. ; mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
  77. ; mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
  78. ; mov bp, sp
  79. ;
  80. sing_ready: ; SingOS is ready for the user:
  81. %if 0
  82. call Go32Bit
  83. %endif
  84. call os_clear_screen
  85. mov si, welcome ; Put address of the null-terminated string to output into 'si'
  86. call print ; Call our string-printing routine
  87. print_format example_format_string, 0xdead, 0xbeef, 0xbabe, 420
  88. call printCRLF
  89. call dump_general_registers
  90. call printCRLF
  91. call dump_segment_registers
  92. call printCRLF
  93. call dump_stack_registers
  94. call printCRLF
  95. call dump_status_flags
  96. call printCRLF
  97. call print_help_message
  98. mov si, command_line
  99. call print
  100. jmp terminal
  101. terminal:
  102. call wait_for_key
  103. jmp terminal
  104. wait_for_key:
  105. pusha
  106. mov ax, 0
  107. mov ah, 0x10 ; BIOS call to wait for key
  108. int 0x16
  109. cmp ax, 0x11b; ESC key
  110. je near .end
  111. cmp ax, 0x3b00 ; f1 key
  112. je .change_one
  113. cmp ax, 0x3c00 ; f2 key
  114. je .change_two
  115. cmp ax, 0x1c0d ; enter key
  116. je .enter_hit
  117. mov [.tmp_buf], ax ; save the key pressed befor printing it
  118. mov cx, [.tmp_buf]
  119. cmp cx, 0x0e08 ; backspace key
  120. ;je .backspace_handler
  121. jne .dont_backspace
  122. call CLI_DELETE
  123. popa
  124. ret
  125. .dont_backspace:
  126. call CLI_ASCII_INPUT
  127. .return_enter:
  128. popa ; But restore all other regs
  129. ret
  130. .os_buffer_full:
  131. mov si, .os_str_full
  132. call print
  133. popa
  134. ret
  135. .backspace_handler:
  136. ; bx already set to the current buffer count
  137. mov bx, [.os_command_buffer_counter]
  138. cmp bx, 0x00
  139. je .backspace_stop
  140. sub bx, 0x01
  141. mov [.os_command_buffer_counter], bx
  142. add bx, .os_command_buffer
  143. mov ax, 0x00
  144. mov [bx], ax
  145. mov ax, [.tmp_buf] ; load the backpace
  146. mov ah, 0xE ; print the backspace
  147. int 0x10
  148. mov al, 0
  149. int 0x10
  150. mov al, 0x08
  151. int 0x10
  152. ;mov al, 0x20 ; now the curser is one back
  153. ;int 0x10 ; print null charecter
  154. .backspace_stop:
  155. popa ; But restore all other regs
  156. ret
  157. .change_one:
  158. mov al, 0x00 ; arg: index 0
  159. call os_change_screen
  160. jmp terminal
  161. .change_two:
  162. mov al, 0x01 ; arg: index 0
  163. call os_change_screen
  164. jmp terminal
  165. .enter_hit:
  166. call CLI_CONFIRM_INPUT
  167. jmp .command_interpreter
  168. .no_str:
  169. mov si, command_line
  170. call print
  171. jmp .return_enter
  172. .compare_with_LIST_searchindex dw 0
  173. .compare_with_LIST_NAMES dw .compare_with_dumpmem, .compare_with_keyprint, .compare_with_display, .compare_with_svim, .compare_with_clear, .compare_with_ls, 0
  174. .compare_with_LIST_POINTERS dw dumpmem, keyprint, .change_display, svim, .clearcommand, lsfs_list_files_command, 0
  175. .compare_with_dumpmem db 'dumpmem', 0
  176. .compare_with_keyprint db 'keyprint', 0
  177. .compare_with_display db 'display', 0 ; original this is the display command for better grapichs
  178. .compare_with_svim db 'svim', 0 ; SingOS vim edition 'svim'
  179. .compare_with_clear db 'clear', 0 ; Clear the screen
  180. .compare_with_ls db 'ls', 0 ; List file table
  181. .end:
  182. mov si, exit_message
  183. call print
  184. call power_off
  185. cli
  186. hlt
  187. .change_display:
  188. mov ax, 0x4F02 ; set VBE mode
  189. mov bx, 0x4118 ; VBE mode number; notice that bits 0-13 contain the mode number and bit 14 (LFB) is set and bit 15 (DM) is clear.
  190. ;xor bx, bx
  191. ;xor cx, cx
  192. ;xor dx, dx
  193. ;mov ah, 0x06
  194. ;mov al, 0xff
  195. int 0x10
  196. ret
  197. .clearcommand:
  198. xor bx, bx
  199. xor cx, cx ; Upper and left coordinate
  200. mov bh, 0x0f ; color for new screen 0 = black f = white
  201. mov dh, 0xff ; Select all screen
  202. mov dl, 0xff ; Select all screen
  203. mov ah, 0x07 ; scrool down
  204. mov al, 0x00 ; scrool 0 lines (means blank screen )
  205. int 0x10
  206. ; move curser back to the top of the screen
  207. mov ah, 0x02
  208. mov bh, 0x00 ; page number 0
  209. mov dh, 0x00 ; row zero
  210. mov dl, 0x00 ; coloumn zero
  211. int 0x10
  212. ret
  213. .tmp_buf dw 0
  214. .os_command_buffer times 255 dw 0
  215. .os_command_buffer_counter dw 0
  216. .os_str_full db 13, 10, 'Buffer is full', 13, 10, 0
  217. .command_interpreter:
  218. mov bx, [.os_command_buffer_counter]
  219. cmp bx, 0x00
  220. je near .no_str ; First byte is 0 => No command
  221. call printCRLF
  222. add bx, .os_command_buffer ; Note addition. Sets bx to the end of the string, which should be guaranteed to be 0
  223. mov ax, 0x00
  224. mov [bx], ax ; Ensure that the command is null-terminated
  225. xor bx, bx
  226. mov [.os_command_buffer_counter], bx
  227. mov si, .os_command_buffer
  228. call print ; Echo the command
  229. lea si, [.os_command_buffer]
  230. ;mov dword [.compare_with_LIST_searchindex], 0 ; Next time, start at 0
  231. mov cx, 0 ; Index
  232. .command_interpreter_searchloop:
  233. ;call printCRLF
  234. ;mov ax, cx
  235. ;call dumpax
  236. ;mov bx, [.compare_with_LIST_searchindex]
  237. mov bx, cx
  238. add bx, bx ; The pointers are 2 bytes long. Compensate here
  239. ;call printCRLF
  240. ;mov ax, cx
  241. ;call dumpax
  242. mov dx, [.compare_with_LIST_NAMES+bx] ; Here it HAS to be bx. Otherwise it is invalid for some reason
  243. mov bx, dx
  244. lea di, [bx]
  245. call stringcompare
  246. je .command_interpreter_foundcommand
  247. ; I don't assume here that the registers contain the same values they used to after the calls
  248. ;mov bx, [.compare_with_LIST_searchindex]
  249. ;inc bx
  250. ;mov [.compare_with_LIST_searchindex], bx
  251. inc cx
  252. mov bx, cx
  253. add bx, bx
  254. mov dx, [.compare_with_LIST_NAMES+bx]
  255. cmp dx, 0 ;Is it at the null terminator?
  256. jne .command_interpreter_searchloop ; There is another command to check
  257. jmp .no_str
  258. .command_interpreter_foundcommand:
  259. call printCRLF
  260. ;mov bx, [.compare_with_LIST_searchindex] ; Remember this thing
  261. mov bx, cx
  262. add bx, bx ;The pointers are 2 bytes long. Compensate here
  263. ;call printCRLF
  264. ;mov ax, cx
  265. ;call dumpax
  266. mov dx, [.compare_with_LIST_POINTERS+bx] ; This is where the program is.
  267. ;mov ax, dx
  268. ;call printCRLF
  269. ;call dumpax
  270. call dx
  271. jmp .no_str
  272. ;
  273. global_vars:
  274. global_lsfs_master_record dw 2064 ; this is the index of the start of the master table for the filesystem
  275. ; This should maby contain more information.
  276. ; and somehow be setted in a fix sector, which holds all the variabels for SingOS
  277. ; 2064 is currently the magic number where the file system starts on our disk.
  278. global_lsfs_next_index dw 0 ; This is the next index to the next file created.
  279. ; this var is set durling load of SingOS
  280. ; Changed my mind, the index is currently loaded and written back to disk under
  281. ; creation of a new file.
  282. global_disk_identifier db 0 ; set by the bios passed by the bootloader,
  283. ; this is the bios ID
  284. global_disk_FSCI_LBA_position db 0
  285. data:
  286. welcome db "###############################################################################", 13, 10, "# Welcome to SingOS - VERSION 0.0.6.1 #", 13, 10, "# #", 13, 10, "###############################################################################", 13, 10, 'Press ESC to halt.', 13, 10, 13, 10, 0
  287. exit_message db 13, 10, 'Goodbye from SingOS',13,10,'The system has halted.', 0
  288. command_line db 13, 10, 'groot@SingOS $ ', 0
  289. number_one_zstring db '71', 0
  290. example_format_string db "(%x-%x-%x){%d%%}",0
  291. Parameter_Struct:
  292. .path dw 0x00 ; char*
  293. .new_path dw 0x00 ; char*
  294. .buffer_segment dw 0x00 ; int
  295. .buffer_address dw 0x00 ; int
  296. .buffer_size dw 0x00 ; int
  297. .data_length dw 0x00 ; int
  298. .byte_offset_into_file dw 0x00 ; int
  299. .entry_kind dw 0x00 ; Table_Entry_Kind
  300. ;times 131072-($-$$) db 0 ; 256 sectos
  301. ;GLOBAL_VSFS_START db 'VSFS v0.1' ; sector 257 reserved for file system information
  302. %include "go32bit.nasm"