flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Boot from the Hard Disk |
Author |
|
f0dder 16 Dec 2012, 17:01
"The best file system" depends on your needs. FAT32 is supported pretty much everywhere, so if ubiquity is your goal, then it's probably "the best". It has a number of limitations, though, and it's not very resilient against errors. NTFS is a lot better in a lot of ways(TM), but if you head outside Windows, there's other alternatives that might be better - XFS, Ext3/Ext4, btrfs, ZFS are all pretty interesting! (and then there's ReiserFS - but it had problems even before it's author was convicted of murder :/).
For hobbyist osdev, you will probably want to focus on fat(32) - it's simple, there's a lot of material available, lots of tools, and it's easy to deal with. IMHO the filesystem is relatively irrelevant for hobbyist osdev - there's so many other parts that's more interesting to program for, so you should rather do a simple filesystem initially, once you have the other parts in place you can look at more interesting FS. |
|||
16 Dec 2012, 17:01 |
|
A$M 16 Dec 2012, 17:17
So, I will choose FAT32. And now: how to boot from a FAT32 HD? What errors FAT32 can present? And last, but not less important: how to access the HDD from the Protected Mode (32 bit)?
|
|||
16 Dec 2012, 17:17 |
|
cod3b453 16 Dec 2012, 19:30
At boot, the BIOS loads the first sector of the HDD and runs it (assuming it has the expected signature). This is the same for all disks and doesn't matter what file system your disk is formatted with - the file system tables begin somewhere after the boot sector, according to the specification.
Your boot sector will need to load the next stage boot loader and a driver for the disk you are booting from. You have the option of either starting to use the file system here or allocating a predefined region of disk; personally, I recommend the second option because it minimises the amount of work that needs to be done in 16bit and in very little space*. For drivers, the simplest is ATA PIO, which can be easily copied to make 16/32/64bit versions; this covers PATA and/or legacy mapped SATA drives (up to 4). There are two modes - LBA28 and LBA48 - which are almost the same, so it only matters how much disk space you want to address. With this up and running, you can use what ever FS you like - it'll probably be harder to make the disk image than to use it! FAT32 is fairly simple, most of the complexity is the cluster map and long file names, so these are the most likely places for errors. *HD boot sectors typically have the MBR at the end, which defines partitions (or EFI/GPT support) which leaves about 400 bytes for code. |
|||
16 Dec 2012, 19:30 |
|
egos 17 Dec 2012, 07:55
MBR is HD boot sector. The table at the end of MBR is named Partition Table (PT). It's possible to use current MBR boot loader and to write FAT32 boot loader for your OS. There're advanced MBR boot loaders. One of them I had written recently (it's experimental version). It allows to use dual booting, so you can keep booting your current OS and to boot your hobby OS as well. If your current OS uses traditional MBR boot loader, just replace it by the my one. You can use rescue CD to test it first.
To access to HDD in modern computers you should write PCI IDE-driver and probably AHCI-driver. |
|||
17 Dec 2012, 07:55 |
|
A$M 17 Dec 2012, 17:50
I had seen something about "ATA PIO" on page http://wiki.osdev.org/ATA_PIO_Mode . Can anybody explain it right or show me a tutorial or something?
Thank you! |
|||
17 Dec 2012, 17:50 |
|
cod3b453 21 Dec 2012, 18:49
That link has some explanation/examples already - what do you want to know more about?
|
|||
21 Dec 2012, 18:49 |
|
A$M 22 Dec 2012, 12:41
Is there anything that this page does not deal? If so, please explain. (That's the right question, sorry )
EDIT: I let the laziness aside and I read about ATA PIO Mode in OSDev. I managed to do this code: Code: format binary as 'img' use16 org 7c00h ;DATAPORT = 0x1F0 ;ERROR = 0x1F1 ;SECTORCNT = 0x1F2 ;LBA_LOW = 0x1F3 ;LBA_MED = 0x1F4 ;LBA_HIGH = 0x1F5 ;DRIVE = 0x1F6 ;COMMAND = 0x1F7 NULL = 0 INREG = "INREG" macro inb port { if port <> "INREG" mov dx, port end if in al, dx } macro outb port, value { if port <> "INREG" mov dx, port end if mov al, value out dx, al } boot: cli display "Este código foi feito por A$M." ;On Brazilian Portuguese push cs push cs pop ds pop es outb 0x1F1, NULL outb 0x1F2, 1 LBA = 0x000001 outb 0x1F3, LBA and 0xFF outb 0x1F4, (LBA shr 8) and 0xFF outb 0x1F5, (LBA shr 16) and 0xFF outb 0x1F6, 0xE0 outb 0x1F7, 0x20 ;READ! mov ecx, 4 .loop1: inb INREG test al, 10000000b ; Check BSY jnz short .retry test al, 00001000b ; Check DRQ jnz short .data_ready .retry: dec ecx jg short .loop1 .loop2: inb INREG test al, 10000000b ; Check BSY jnz short .loop2 test al, 00100001b ; Check ERR and DF jnz short .fail .data_ready: mov dx, 0x1F0 mov cx, 256 mov di, buffer rep insw ; Read data to ES:DI inb 1F7h inb INREG ; Waiting inb INREG ; 400ns inb INREG mov si, done mov cx, 7 mov dx, 0xE9 rep outsb ; 'Done!' message on BOCHS mov al, 1 mov bh, 0 mov bl, 2Fh mov cx, str_end - buffer mov dl, 0 mov dh, 1 mov bp, buffer mov ah, 13h int 10h hlt jmp $ .fail: mov al, 1 mov bh, 0 mov bl, 4Fh mov cx, error_end - error_str mov dl, 0 mov dh, 1 mov bp, error_str mov ah, 13h int 10h hlt jmp $ error_str db "ERROR!!!" error_end: done db "Done!",10,13 times 510-($-$$) db 0 dw 0aa55h buffer: db ' This is the proof that my code is absolutely right!!!!!!!!! \o/ ' str_end: times 512-($-buffer) db 0
|
|||||||||||
22 Dec 2012, 12:41 |
|
cod3b453 06 Jan 2013, 02:09
That covers basic read/write/identify, which is almost everything you'd normally need but the ATA specification has many more commands that cover power management, device status and reset/flushing. ATA also covers CD drives, so it has the abilty to check/lock/eject etc as well.
|
|||
06 Jan 2013, 02:09 |
|
A$M 11 Jan 2013, 13:06
cod3b453 wrote: That covers basic read/write/identify, which is almost everything you'd normally need but the ATA specification has many more commands that cover power management, device status and reset/flushing. ATA also covers CD drives, so it has the abilty to check/lock/eject etc as well. cod3b453, this is something very simple, but enough for a bootloader. |
|||
11 Jan 2013, 13:06 |
|
egos 11 Jan 2013, 18:33
Nobody uses this in boot loader
|
|||
11 Jan 2013, 18:33 |
|
baldr 11 Jan 2013, 22:08
egos,
Yep, bootloader can't be too generic. Hell, I often ask myself why they do use partitions' table/BPB/whatever to read the rest of bootstrap code while it can be hardcoded by FDISK/SYS/whatever. |
|||
11 Jan 2013, 22:08 |
|
egos 12 Jan 2013, 12:17
I prefer to use PT/BPB+/whatever
I even had modified GRUB for this purpose. |
|||
12 Jan 2013, 12:17 |
|
A$M 12 Jan 2013, 12:22
egos wrote: Nobody uses this in boot loader Whoa! Thank you! You made me realize my distraction. I can use the BIOS interrupts... lol |
|||
12 Jan 2013, 12:22 |
|
egos 14 Jan 2013, 13:30
Why not. Do you know about ATA native mode, about AHCI-mode? What about initialization, detection? Don't forget about USB pen/hard drives and so on.
|
|||
14 Jan 2013, 13:30 |
|
c.j.gowett 16 Jan 2014, 20:23
You could try to implement your own file system, but it won't be readable to windows or other operating systems but your own. This is what I am doing. If you want to put in the work, maybe I can help you on it. Something I would do if you are using BIOS interrupts before you switch into protected mode is to load your entire OS into memory with int 10h. I am still trying to figure out how to write to the disk in protected mode, but I can help you out with it when I do grasp it.
|
|||
16 Jan 2014, 20:23 |
|
sid123 17 Jan 2014, 07:09
Quote: You could try to implement your own file system, but it won't be readable to windows or other operating systems but your own Write a driver for your FS. That's how I access Ext4 partitions from Windows.(I didn't write the driver myself btw.) _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
17 Jan 2014, 07:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.