Page 1 of 1

Filesystem concept

Posted: Fri Apr 03, 2015 3:34 pm
by LeChapelierFou
Hi osdev community, hope that you're doing well. I'm writting a very basic 16 bits OS with nasm and helping myself with appusajeev documentation , I've written the bootloader that jump to a very tiny shell which reads the user command, compare it with a filetable and run the file if exist.

But I'm stuck at the comparison step :
- How to creat a filetable ( I found an example but not clear :s ) {file1-sector,file2-sector,…,filen-sector,}
- Which format should be the file
- Since I've loaded the filetable at 0x2000 in the bootloader , how to put the file at this adress
- Is there a relation between a sector and a segment ? If yes, can someone explain it to me

Here is my code :

Bootloader.asm

Code: Select all

%define drive_number 0


[bits 16]
[org 0x7C00]

boot : jmp start

print_char:
	mov ah, 0x0E
	mov bh, 0x00 
	mov bl, 0x03
	int 0x10
	ret 

print_string:
	mov al, [si]
	inc si
	call print_char 
	or al, al
	jz done
	jmp print_string

	done:
		ret

reset_drive:
	mov si, reset_drive_start_msg
	call print_string
	mov ah, 00h
	mov dl, drive_number
	jc reset_drive_fail
	mov si, reset_drive_success_msg
	call print_string
	ret 

	reset_drive_fail:
		mov si, reset_drive_fail_msg
		call print_string
		jmp reset_drive





boot_kernel:
	mov si, load_kernel_msg
	call print_string
	mov si, 0x00

	;os load
	mov ax, 0x1000
	mov es, ax 
	xor bx, bx 
	mov ah, 0x02
	mov al, 1
	mov ch, 0
	mov cl, 2
	mov dh, 0
	mov dl, drive_number

	int 0x13

	mov ax, 0x2000
	mov es, ax 
	xor bx, bx 
	mov ah, 0x02 
	mov al, 1
	mov ch, 0
	mov cl, 2
	mov dh, 0
	mov dl, drive_number

	int 0x13
	jc boot_kernel
	push es 
	push bx 

	mov si, load_kernel_success_msg
	call print_string

	retf 

start:
	
	mov si, start_msg
	call print_string
	call reset_drive
	call boot_kernel


	jmp 1000:0x00
	

start_msg db ' [-] Bootloader has been started !', 0x0D, 0x0A, 0
reset_drive_start_msg db '[-] Trying to reset the disk drive...', 0x0D, 0x0A, 0
reset_drive_success_msg db '[-] Disk drive resetted...[OK]', 0x0D, 0x0A, 0
reset_drive_fail_msg db '[-] Disk drive not resetted...[!]', 0x0D, 0x0A, 0,'Retrying to reset the disk drive...', 0x0D, 0x0A, 0

load_kernel_msg db '[-] Trying to load the kernel...', 0x0D, 0x0A, 0
load_kernel_success_msg db '[-] Kernel loaded...[OK]', 0x0D, 0x0A, 0
load_kernel_fail_msg db '[-] Kernel not loaded...[!]', 0x0D, 0x0A, 0,'Retrying to load the kernel...', 0x0D, 0x0A, 0
TIMES 510 - ($-$$) db 0
dw 0xAA55

shell.asm

Code: Select all

kernel:
	jmp k_main


print_string:
	still_printing:
		lodsb
		or al, al 
		jz print_string_done
		mov ah, 0x0E
		int 0x10
		jmp still_printing

	print_string_done:
		ret 



shell_prompt:

	mov si, shellSym
	call print_string

	push command
	call read_command

	jmp shell_prompt


read_command:
	pusha
	mov bp, sp 
	cld
	mov byte [ccount], 0
	mov di, [bp+18]

	still_reading:
		mov ah, 0
		int 16h
		cmp al, 0dh
		jz done_read_command
		mov ah, 0x0E
		mov bx, 0
		int 10h
		stosb
		inc byte [ccount]
		jmp still_reading

	done_read_command:
		mov si, 0000000000000000
		mov si, lj
		call print_string
		mov sp, bp 
		popa 
		ret



k_main:
	push cs 
	pop ds 

	
	mov si, welcomeMsg
	call print_string
	
	call shell_prompt
	
	




welcomeMsg db "Welcome to B.S Operating System... Whats up ! ",10,13,10,13,0
shellSym db ">>",0
ccount dw 0
command times 30 db 0
lj db 10,13,0
TIMES 512 - ($-$$) db 0

Thanks for helping me :)

Re: Filesystem concept

Posted: Fri Apr 03, 2015 5:32 pm
by BrightLight
What do you mean by "file table?" What file system are you booting from? Your boot sector code has no BPB or MBR, your disk is raw, there is no file system.
A file system is actually just a structure on a disk that creates the concept of a file. Each file system is different. FAT is the simplest file system. Read about FAT in the Wiki.
Notice how you load your kernel from a raw sector. Most file systems won't allow this. Read on file systems before asking.

Re: Filesystem concept

Posted: Sun Apr 12, 2015 6:07 pm
by azblue
LeChapelierFou wrote:Hi osdev community, hope that you're doing well. I'm writting a very basic 16 bits OS with nasm and helping myself with appusajeev documentation , I've written the bootloader that jump to a very tiny shell which reads the user command, compare it with a filetable and run the file if exist.

But I'm stuck at the comparison step :
- How to creat a filetable ( I found an example but not clear :s ) {file1-sector,file2-sector,…,filen-sector,}
- Which format should be the file
- Since I've loaded the filetable at 0x2000 in the bootloader , how to put the file at this adress
- Is there a relation between a sector and a segment ? If yes, can someone explain it to me
There are several problems with your code that you'll probably want to address sooner rather than later (hard coding the drive number, not setting up segments and stack right away, kernel limited to 1 sector). Also, it looks like you load your kernel at 1000:0 and 2000:0?

Anyway, on to your questions:
- Which format should be the file
Whichever format your OS supports. ELF is probably the most popular format; it may be wise to stick with that since that's the one you'll find the most info for. However, if you're sticking entirely with 16-bit real mode, COM may be a good idea. It has its limitations (64K) but it's ridiculously simple.
- Since I've loaded the filetable at 0x2000 in the bootloader , how to put the file at this adress
Your going to have to write code to properly save files to a disk setup with your file system.
- Is there a relation between a sector and a segment ? If yes, can someone explain it to me
Nope. But one real-mode trick when loading multiple sectors is to add 32 to the segment after every sector load. (Don't do it until you understand why it works and what it's for).
- How to creat a filetable ( I found an example but not clear :s ) {file1-sector,file2-sector,…,filen-sector,}
Think about the absolute minimum a file system needs: You have to have names for your files. You have to know where they are. You have to know how many sectors they take. You should be able to come up with a file system on your own just by thinking it through.


I strongly recommend you try to figure something out without looking at my simple design here -- it's the sort of thing you need to do on your own when you're OS-deving.





But, if you really need some help, you could do something like this:

Starting at sector 3, you have file entries in the following format:

12 bytes - file name
2 bytes - starting sector (note: you'll need CHS conversions on a floppy)
2 bytes - -number of sectors

Note that you're limited to 32 files, you don't support directories, you don't know exactly how big any file is, or when it was created or modified, etc.

Re: Filesystem concept

Posted: Mon Apr 13, 2015 5:14 am
by SpyderTL
Segments and sectors are not directly related, but they are similar, in that sectors are used to break up a disk into readable chunks, and segments are used to break up system RAM into readable chunks.

Reading disks and/or memory in chunks is useful, because it increases the amount of data that you can "address" when using a 16-bit number. Instead of being limited to 65535 bytes (like the old Commodore 64), you can instead read 65535 chunks of data.

If each chunk is 16 bytes (like segments) or 512 bytes (like disk sectors), you can see how this greatly increases the amount of data that you can access using the exact same 16-bit value.