Second stage bootlaoder
Second stage bootlaoder
I am tryingot figure out how to laod a second stage boot loader form a first stage bootlaoder i think i have a good idea on how i want to load it but i am not sure on how to go about loading it from the first stage and wha ti need o put in the second stage loader, should i go ahead and make the first stage load pmod and a temp gdt table or should i inlcude them in the second stage loader, and where should i load the second stage loader from what address i mean. here is the code i have so far:
;Bios loads this at 7C00h. Tell NASM that is where it is loaded
ORG 7c00h
; nasm knows where it is loaded, we jump to the main bootsector code
jmp Start ;goto start
;start
Start:
mov [ drive ], dl ; get the floppy 3dimenOS booted from
;update the segment registers
xor ax,ax ;xor ax
mov ds,ax ;mov AX into DS
jmp Running ; goto the running part of the bootsector
;This is where the boot program runs.
Running:
;Clear text mode screen
mov ax,3 ;Set text mode3
int 10h ;text-mode 3 set. the screen is cleared
;Load second stage bootloader
;Reset the floppy drive.
ResetFloppy:
mov ax,0x00 ;select floppy rest BIOS function
mov dl,[ drive ] ;select the floppy drive booted from
int 13h ;rest floppy;
jc ResetFloppy ;if there was an error retry
;read the floppy drive for loadig the second stage bootlaoder
ReadFloppy:
mov bx, ???? ;load second stage boot laoder at ????? i need help here
mov ah,0x02 ;load disk data to ES:BX
mov al,17 ;load two heads full of worth of data
mov ch,0 ;first clyinder
mov cl,2 ;start at the 2nd secotr, so you don't load the bootsector, you load the second stage boot loader
mov dh,0 ;use first floppy head
mov dl,[ drive ] ;load from the drive booted from
int 13h ;read the floppy disk
jc ReadFloppy ;error try again
;this part makes sure the bootsector is 5512 bytes
times 509-($-$$) db 0
;we need this tells the bios that is a bootable disk
dw 0xA55
;for storing which floppy drive was booted from
drive db 0
Thanks for any help
;Bios loads this at 7C00h. Tell NASM that is where it is loaded
ORG 7c00h
; nasm knows where it is loaded, we jump to the main bootsector code
jmp Start ;goto start
;start
Start:
mov [ drive ], dl ; get the floppy 3dimenOS booted from
;update the segment registers
xor ax,ax ;xor ax
mov ds,ax ;mov AX into DS
jmp Running ; goto the running part of the bootsector
;This is where the boot program runs.
Running:
;Clear text mode screen
mov ax,3 ;Set text mode3
int 10h ;text-mode 3 set. the screen is cleared
;Load second stage bootloader
;Reset the floppy drive.
ResetFloppy:
mov ax,0x00 ;select floppy rest BIOS function
mov dl,[ drive ] ;select the floppy drive booted from
int 13h ;rest floppy;
jc ResetFloppy ;if there was an error retry
;read the floppy drive for loadig the second stage bootlaoder
ReadFloppy:
mov bx, ???? ;load second stage boot laoder at ????? i need help here
mov ah,0x02 ;load disk data to ES:BX
mov al,17 ;load two heads full of worth of data
mov ch,0 ;first clyinder
mov cl,2 ;start at the 2nd secotr, so you don't load the bootsector, you load the second stage boot loader
mov dh,0 ;use first floppy head
mov dl,[ drive ] ;load from the drive booted from
int 13h ;read the floppy disk
jc ReadFloppy ;error try again
;this part makes sure the bootsector is 5512 bytes
times 509-($-$$) db 0
;we need this tells the bios that is a bootable disk
dw 0xA55
;for storing which floppy drive was booted from
drive db 0
Thanks for any help
Re:Second stage bootlaoder
Yep...first stage loader->PM->GDT->2nd stage loader. I have source if you would like it...go ahead and make the first stage load pmod and a temp gdt table or should i inlcude them in the second stage loader
Re:Second stage bootlaoder
..
Last edited by Perica on Sun Dec 03, 2006 8:28 pm, edited 1 time in total.
Re:Second stage bootlaoder
my 2 stage loader operates somethign like this:
set Rmode segments and stack -> dsplay message -> enable a20 -> load second stage into memory -> start execution of second stage -> locate kernel on file system and load it into memory -> load GDT -> switch to Pmode -> set selectors -> create Pmode stack -> jump to kernel
set Rmode segments and stack -> dsplay message -> enable a20 -> load second stage into memory -> start execution of second stage -> locate kernel on file system and load it into memory -> load GDT -> switch to Pmode -> set selectors -> create Pmode stack -> jump to kernel
Re:Second stage bootlaoder
Here is what i'm working in:
1st stage loader-> set stack -> load 2nd stage loader-> get amount of memory, HDs, Floppys, and everything you want, -> load kernel -> set Pmode-> jump to kernel
1st stage loader-> set stack -> load 2nd stage loader-> get amount of memory, HDs, Floppys, and everything you want, -> load kernel -> set Pmode-> jump to kernel
Re:Second stage bootlaoder
I recommend GRUB now...since of BIOS portability.
I've noticed you've used my bootsector...and i've found it to be faulty.
Get GRUB.
I've noticed you've used my bootsector...and i've found it to be faulty.
Get GRUB.
Re:Second stage bootlaoder
Well Tiom Yes i did use part of your code I want the second stage to laod up in a menu style with graphics somthing like XOSL but i want to write it myself and learn alittle bit on my own i learn mfrom my mistakes and such and others and try to figure out a solution myself this time i could not. I would also like to look at some other source code to get a general idea of how to go about laoding to the second stage any help would be appreciated.
Thanks for the help the most i have gotten anywhere
Thanks for the help the most i have gotten anywhere
Re:Second stage bootlaoder
The reason why i am tryingot make my own bootlaoder is beacuse of the design idea i have for my os. I tried grub but i did not like the way it loaded and such. I use it on my linux systems and i like it there but for what i am trying to achive is the laerning experiance right now to get myslef on my feet again with OS deisgn.
Re:Second stage bootlaoder
I like writing my own bootsector for learning...too...but I had to go with GRUB since the kernel is easier to learn to program first...then the bootsector...
But...I can't help too much after this...since I stopped my bootsector writing since everyone won't help and just tells me to get GRUB...
But...I can't help too much after this...since I stopped my bootsector writing since everyone won't help and just tells me to get GRUB...
Re:Second stage bootlaoder
Ok now in the second stage loader i would set ORG to 7e00h and then laod pmode, GDT and the kernel and that is it for now as a start
Re:Second stage bootlaoder
but that would only give you a small amount of room for your second stage loader...too small...I suggest something like 0x1000...so you don't overwrite the BIOS.
Re:Second stage bootlaoder
Thanks Tom fopr the suggestion i will change it to 0x1000. wheni compile it with nasm how should i compile them first the first stage and then the second stage laoder how would i compile it just like normal with nasm.
Re:Second stage bootlaoder
You would compile the first stage loader just like normal...(you load the kernel's 2nd stage loader over the BIOS so you can have your os use v86 mode later on...so you don't have the bios gone)
and in the 2nd stage loader have a
org 0x1000
but if the 2nd stage loader will have C code, you will need to link differently.
and in the 2nd stage loader have a
org 0x1000
but if the 2nd stage loader will have C code, you will need to link differently.
Re:Second stage bootlaoder
its not that I wont help, I told you whats wrong with it. your sector reading code is all wrong. A simple bootsector like that, i think you should be able to knock it out inside of about 2 hours, fully working, since all it does is read in a block of sectors, move it to 1mb and jump to it. thats basic stuff.Tom wrote: I like writing my own bootsector for learning...too...but I had to go with GRUB since the kernel is easier to learn to program first...then the bootsector...
But...I can't help too much after this...since I stopped my bootsector writing since everyone won't help and just tells me to get GRUB...
if you want to make it more complex, parse a FAT12/FAT16 table and read a named kernel file from it, still inside of 512 bytes and jump to pmode!
nobody said you had to give up, but if all your efforts at making pk08 are being hampered by a bootsector that doesnt work. get a work around (grub) and go back to it later on, etc.
want to know what I'm doing right now? I'm writing a bootsector! I have 1kb, and I'm reading in a filesystem I created (DF_SFS, df's small file system). ist very minix/v5/ext2 style. single/double/triple indirect blocks. security blocks, inode blocks, data blocks, with bitmapping. (no zoning or block bins or fragments.)
i'm kinda proud of my sfs, its not a bastardisation of a dos FAT, its very workable, sturdy, not prone to breakage like FAT style systems, can have freeform ACL based security of unfixed size, no fixed size of filenames, etc.
and I have to handle all this and boot into pmode inside of 1kb!
i think it will take me a weekend to get it properly sorted maybe more...
-- Stu --