I have written a builtin command for the NOS kernel, but it seems to only list the first file entry in the FSB before quitting. In this screenshot, I took a photo of the boot disk listing which only lists INT21, however the FSB has two listings. I can't seem to figure out what is wrong with this section of code.
Screenshot of listing:
;; This is a simple FSB (Filesystem block) for NOS on a 1.44MB floppy disk.
;; PERSONAL NOTE: there are 18 sectors per track, 2 tracks per cyl, and 80 cyl on a 1.44MB floppy
;; CHS for Kernel start
;; Length of kernel in blocks (0FFh here means no kernel on disk)
;; free blocks
;; total blocks
;; file fields go here
;; INT21 must be our first file here. Otherwise the kernel will not boot.
db80h; Start of field
db00h, 00h, 07h; CHS of INT21
db02h; INT21 will be 1024 bytes
db"INT21", 00h, " "; Filename and padding
db00h; EXE flag
db0FFh; End field
; Example text file for use with type command
db00h, 00h, 09h
db"text", 00h, " " db00h
DIR command code:
; pointing at "d"
cmpah, "i" jneexternal_command
cmpah, "r" jneexternal_command
; We have a dir command
; First thing is first: update the FSB.
movcl, 02d; CL=02 is the FSB
movdl, byte [boot_drv] movbx, 2000h; FSB segment
; Now we need to begin the process of listing out the files.
; Start by pointing ES:BX at the first file field.
list_files_loop: ; Now we loop until we find a null, indicating that we have entered empty space.
; Find the file fields
; Otherwise, check for null
; Increment until we find a file
get_file_name_dir: ; The file name is exactly 5 bytes from the 0x80, add that on
; Now print out the file name on its own
; Now go to the end of the field
; Continue the loop
done: ; We are done here.
The rest of the code, for context, is the repository, in KERNEL.ASM, under the label check_dir. Link is in my signature.
_________________ It may look hard, but it won't take long if you take it one byte at a time.
Right, sorry. Here is the INT21 code. I'm not going to be at my computer, so I can't change anything off the bat, but upon a quick visual scan I don't see anything wrong with INT21. I will try changing what is added to BX and check the result when I can get back to it.
;; This file contains the INT 21 API for the NOS kernel.
;; Table of functions follows:
;; AX=0123h, BX=4567h, CX=8910h, DX=FFFFh: This invokes a kernel panic routine. This is not available
;; to user apps (the NOS kernel will call the panic with CF set and a byte in RAM set to FFh). This
;; sends a message to the user and halts the machine.
;; AH=00h: Does nothing, returns AX=5555h
;; AH=01h: Write string to display (null terminated) from DS:DX, returns number of chars written
;; in BH.
;; AH=02h: Open a file. Opens file whose null-terminated name is in DS:DX, and loads the contents
;; of the file to ES:BX. Returns number of blocks read in AL, CF is set on an error, and
;; BH describes the error when CF is set.
;; AH=03h: Close a file. DS:DX points to the null-terminated file name, ES:BX points to the file
;; contents, and AH contains the number of blocks to be written. Returns nothing on no error,
;; if an error occurs then CF is set and BH describes the error.
;; AH=04h: Gets the NOS version and places two ASCII characters into CX. (e.g. CX="20", NOS 2.0)
;; Minor version number is placed in AL (e.g. Rev 3, AL="3")
;; AH=05h: No function is here yet, this will just IRET until something gets placed here.
;; AH=06h: Gets a string from the user until the user presses return. The string is placed into
;; RAM pointed to by DS:DX.
;; First we want to check if the kernel panic thing is being called.
pushf; For later functions
;; Now check for the RAM byte (0x9000:0xFFFF)
;; Check the carry flag
fraud_call: ;; At this point we can guarantee that this is a fraudulent panic call. Just do an IRET now
;; with the carry flag set.
orbyte [esp+4], 1
main_func_check: ;; Check for a non-panic call.
jeinstall_check; Our install check routine for boot time
jeprint_string; Our print string function
jeopen_file; Open file function
jeclose_file; Close file function
jenos_version; Returns tho NOS version
;; Skip 0x05 for now, created 0x06 with no 0x05! so I will have to think up a
;; function to fill this hole.
jeget_user_string; Our getstring function
;; If none of these match, pop our flags, set carry, and return
; Set carry
orbyte [esp+4], 1
install_check: ;; This is a simple install check function.
;; Doesn't take any args, and just returns AX=0x5555
popf; Required of all functions, to keep stack clean
; This code snippet is provided by SeproMan on the FASM board.
; Thanks Sepro!
pushax pushcx pushsi movah, 0Eh;BIOS teletype
movbh, 0;Display page 0, don't care about BL in video mode 3
movch, 0;Count characters
movsi, dx;DX can't be used to address memory!!!
print_loop: moval, [ds:si] incsi cmpal, 0 jeprint_done int10h incch;Printed a char
jmpprint_loop print_done: movbh, ch;BH is be the number of chars that we wrote
popsi popcx popax iret
; Load up the FSB
; Get the boot drive from the kernel (4th byte in kernel space)
; Read through DS:DX to find the filename
; AH is pointer to filename char
open_filename_loop: moval, byteptrds:si
; Check for null
; AH=pointer, AL=byte
movbx, filename; Address of filename, in data area below
; AX=00<ptr byte>h
done_open_filename_loop: ; Increment through the FSB starting at the file fields (8 bytes in)
; File field format:
; C,H,S of file (3 bytes)
; Number of blocks (1 byte)
; Filename with 0x00 padding (8 bytes)
; Executable flag (1 byte)
find_files_loop: ; Check for a file
; If there is a null here, then we are in empty spce of the FSB.
; Exit just in case.
disk_error: ; Otherwise we are done here, and have not found our file.
orbyte [esp+4], 1
found_field: ; inc through the field to the filename (pointing at 0x80)
; Compare the filenames
cmp_name_loop: movah, byteptres:bx
; If not equal then go to the end of the field and check for another one
; inc and check next char
check_end_filename: ; Looking at the end of the file name. If they are the same then we have the correct file and we need
; to load it up.
; We have a correct filename. Load it up, point at beginning of file field.
; Get CHS info
; Now the number of blocks
; Move the blocks into AL and quit
not_right_file: ; Somewhere in the filename. Go back to the beginning of the field
; Back to 0x80. Go to byte after 0xff
open_file_data: filenamedb00h,00h,00h,00h,00h,00h,00h,00h; 8 bytes for file name
blocksdb00h; For the number of blocks later
close_file: ; Empty for the sake of a test build
; DS:DX - address to save string at
get_char_loop: ; Start by getting a char
; Check to see if AL is a CR
; Otherwise copy the char and begin again
mov [ds:si], al
get_string_done: ; Place our NULL, print a return, and exit
movbyte [ds:si], 00h
movcx, "0B" iret
kernel_panic: ; Turn on all keylights and Halt
movdx, 60h moval, 0EDh outdx, al
movax, 00000111b outdx, al
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum