Last time I checked.. It's open source.. Can't hurt to review the code lol..frank wrote:I would use GRUB, but I'm picky. I have to know everything that is going on all the time. I don't want some magic bootloader loading my kernel.
This might change however if I ever implement any other filesystems.
Who Uses GRUB?
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
In case you're trying to build GRUB on Cygwin, that doesn't work. However, there are pre-build binaries available at ftp://alpha.gnu.org/gnu/grub which work allright. Or, if you don't trust 'em, you can build the binaries on a Unix box.pcmattman wrote:I don't use GRUB for one simple reason: it doesn't work. I try to compile (using Cygwin) and I just get heaps of errors.
Every good solution is obvious once you've found it.
Looks like it's mixed: source and binaries. The ones ending in "-ext2fs" seem to be images (presumably formatted as ext2).pcmattman wrote:Ummm... ok... the FTP server you gave me has a whole lot of archives. That's good. Problem is, these archives are the same I am using now - no binary. Which archive has the binaries in it?
So grub-0.97-i386-pc.ext2fs would seem to be the latest binary.
Note: I haven't tried to run it, but I've hex-dumped it and it definitely looked like a dump of a GRUB install.
Thanks,Brynet-Inc wrote:Last time I checked.. It's open source.. Can't hurt to review the code lol..frank wrote:I would use GRUB, but I'm picky. I have to know everything that is going on all the time. I don't want some magic bootloader loading my kernel.
This might change however if I ever implement any other filesystems.
I might do that, if I ever get some free time. lol
Should I use GRUB 2 or Grub legacy? GRUB 2 is stable right?
grub-0.97-i386-pc.ext2fs
What does the ext2 mean?
I believe I already answered that in my post. You may have missed it though, it was right before yours.frank wrote:grub-0.97-i386-pc.ext2fs
What does the ext2 mean?
(They're presumably formatted using the ext2 filesystem. Google it if you want to know more, or read the wiki entry)
No, I know what ext 2 is, I was just wondering if that means that it only works on ext 2 or if I could use it on another filesystem, such as faturxae wrote:I believe I already answered that in my post. You may have missed it though, it was right before yours.frank wrote:grub-0.97-i386-pc.ext2fs
What does the ext2 mean?
(They're presumably formatted using the ext2 filesystem. Google it if you want to know more, or read the wiki entry)
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Thanks, finally a straight answer.Brynet-Inc wrote:It's simply stating it's a compiled version of GRUB.. And it includes a floppy image with an ext2fs file system.
GRUB 2 is not stable btw, The one most often used is called "Grub Legacy" these days.
Sorry to be a pain, but one more question, you can install grub from that floppy image on say a fat filesystem right.
EDIT: Never mind, I figured it out
I use GRUB exclusively at the moment - for my kernel, Linux machine and my Windows machine. The only reason I'd write my own bootloader is for other architectures, and I'd still try to make it Multiboot compliant.
Code: Select all
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M/MU d- s:- a--- C++++ UL P L++ E--- W+++ N+ w++ M- V+ PS+ Y+ PE- PGP t-- 5- X R- tv b DI-- D+ G e h! r++ y+
------END GEEK CODE BLOCK------
code
The code visible here is my "ugly" Multi Booting MBR (I like the way Ready4dis thinks! ). I have it running on a machine with Windoze as the OS on the Primary Master, and my OS on the Secondary Master, currently. My "pretty" MBR is about 30 bytes over the limit, and I'm tired of messing with it.
My MBR is strongly influenced by my insistence that all bootloaders should be loaded at 0x500 (physical), and that all MBRs should load at least 8K to give the bootloaders some space. Of course, I also have to support bootloaders that expect to load at 0x7c00.
The attached code is my bootloader. It currently does everything my kernel needs, and more -- but it is incomplete, anyway. I haven't gone back to finish polishing it up. It compiles to about 2.5K currently (both are NASM code).
Both are public domain -- you can do anything you want with 'em.
My MBR is strongly influenced by my insistence that all bootloaders should be loaded at 0x500 (physical), and that all MBRs should load at least 8K to give the bootloaders some space. Of course, I also have to support bootloaders that expect to load at 0x7c00.
The attached code is my bootloader. It currently does everything my kernel needs, and more -- but it is incomplete, anyway. I haven't gone back to finish polishing it up. It compiles to about 2.5K currently (both are NASM code).
Code: Select all
; Let's call this the lobotomized version of the Dual Booting Master Boot program.
; It allows alternate physical drives to be booted, if they contain a compatible MBR.
; Also, one Bang! partition on the current drive, besides the active partition.
; The 0xAA55 signature is NOT verified on chainloaded MBRs or Boot Sectors.
; It loads 8K of any chainloaded bootloader and passes a pointer to the boot
; partition in SI and BX. A chainloaded MBR is passed the new disk "number" in DL.
; (If this MBR needs to be modified, start shortening messages, if you must.)
; struc PT_ENT ;Partition table entry, 16 bytes long
;BootFlag resb 1
;BeginHead resb 1
;BeginSector resb 1
;BeginCyl resb 1
;SystemID resb 1
;EndHead resb 1
;EndSector resb 1
;EndCyl resb 1
;RelSectorLow resw 1
;RelSectorHigh resw 1
;NumSectorsLow resw 1
;NumSectorsHigh resw 1
; endstruc
extern ld_pt ; also = 0x500 -- entrypoint to my bootloader, defined by linker
extern self_reloc ; 0x7800 -- self-relocation point, to get out of 0x7c00
ld_point equ 0x500 ; initial load point for all disk reads
DAPACK equ 0x7bf0
SEGMENT START USE16 ; address = 0x7C00
start:
mov di, 0xb000
mov fs, di ; prepare to use fs:di for text video output
xor cx, cx ; Set segment registers to 0
mov ds, cx
mov es, cx
mov ss, cx
cld ; clear direction bit -- always copy going UP
mov si, start
mov sp, si
;Format of disk address packet:
;Offset Size Description
; 00h BYTE size of packet (0x10)
; 01h BYTE reserved (0)
; 02h WORD number of blocks to transfer (8K worth)
; 04h DWORD -> transfer buffer (0x500)
; 08h DWORD starting LBA
; 0ch DWORD reserved for 48 or 64 bit LBAs (0)
; push the structure in reverse order, of course
push cx
push cx ; first 64bits of LBA all 0 for now
push cx
push cx
push cx ; then 32 bits of memory address load point = 0x500
push ld_point
mov cl, 0x10 ; put a 16 in cx for sectors to read, and len of DAPACK
push cx
push cx
; clear my memory copy of the screen at 0:0xb000
mov ch, 0x10 ; copy a little more than 4000 chars -- more than enough
mov al, 0x20 ; clear to spaces (not zero)
rep stosb
; Sadly, for DOS/Win, and probably most foreign bootloaders, I need to relocate. :(
mov ch, 1 ; copy 256 shorts
mov di, 0x7800 ; should use self_reloc, but I don't feel like it.
rep movsw
jmp continue
; don't preload MBRs -- just accept the BIOS drive count.
; display all other drives as Alternate drive #x from 1 to y
; load 16 sectors at 0x500 -- that's safe, even if it's a CD
; if anything other than a Bang! partition load, copy to 0x7c00 -- 8K
; examine partition table for the active partition, and alternate bootable Bang! partition
; (only one of each is "allowed" -- the logic selects the last of each found)
SEGMENT MAIN USE16 ; address = 0x7800
continue:
mov bx, parttbl ; bx = 0x79be, 0x79ce, 0x79de, 0x79ee
; initialize the 2 default partition "pointer" registers -- ah, dh
mov ax, 0xae04 ; al=4, ah = "nonexistent partition" -- active partition
mov dh, ah ; also "nonexistent" -- dh = alt Bang! partition
xploop:
mov cl, [bx]
jcxz xnonact ; is it an active partition?
mov ah, bl ; save the "offset" of this active partition
jmp short xpdon
xnonact:
mov cl, [bx+4]
cmp cl, 0x1d ; is it a bootable Bang! partition?
jne short xpdon
mov dh, bl ; save the offset of this Bang! partition
xpdon:
add bl, 16 ; move to the next partition entry
dec al
jg short xploop
mov bp, dx ; save the current vals in dx forever
; now get the total drive count
mov si, 0x475
mov al, [si] ; bios found this many drives, total
cmp al, 8
jbe short abchk
mov al, 8 ; what else is there to do, if it was more than 8?
abchk:
; only one drive, with no alternate Bang! partition? if so, autoboot!
dec al
jg short makdsp ; if >1 drive, do a display
cmp dh, 0xae
jne short makdsp ; if alt Bang! partition exists, do a display
; Autoboot!
mov bl, ah ; set partition # to active (default)
push ax ; in case of read fail
jmp near b_part ; load and boot active partition
; Create as pretty a menu display as possible, and let the user choose
makdsp:
mov di, 0xb0a0 ; down a couple lines from top
add al, 0x30 ; convert disk count to ascii
mov cl, 0x30
; display 1st line -- active partition info -- if one exists
; 'Entr translated sys ID (current drive)'
cmp ah, 0xae
je short daltbng
mov [di], dword 0x72746e45 ; 'Entr' reversed
mov bh, 0x7d ; point bx at the active partition entry
; Note: the MBR at 0x7c00 is valid until the last instant before a successful chainload,
; so either 0x7dxx or 0x79xx both work just fine for partition table pointers
mov bl, ah ; set the partition table entry offset
mov bl, [bx+4] ; grab the system ID byte from entry
call mkdspl ; build a single display line for screen
daltbng:
; display 2nd line, of alterante Bang! partition info -- if one exists
; 'e Bang! (current drive)'
cmp dh, 0xae
je short ad_jin2 ; if no alt Bang! partition found, skip the line
mov [di], byte 0x65 ; 'e' for booting "non-active" Bang! partition
mov bl, 0x1d
jmp short ad_jin1 ; jump to doing a mkdspl call
daltdlp:
xor bl, bl
inc cx
mov [di], cl ; '1' to last drive (numeric)
ad_jin1:
call mkdspl
ad_jin2:
cmp cl, al
jne short daltdlp
; display 'Choice:'
mov si, chmsg
movsw
movsw
movsw
movsb
push ax ; preserve drive count & active partition
dosdsp:
; display different drives in different colors, to make the switch clear to users!
mov ah, dl
and ah, 7
inc ah ; color 1 to 8 on black text
mov cx, 2000 ; repaint the entire screen
; 0 is black
; 1 is dark blue
; 2 is dark green
; 3 is medium blue
; 4 is red
; 5 is dark pink
; 6 is dark orange / brown
; 7 is medium gray
; 8 is dark gray
; 9 is purple
; 'a' is light green
; 'b' is light blue
; 'c' is light orange
; 'd' is light pink
; 'e' is yellow
; 'f' is white
; dump the memory copy of the screen to video text mem, with attrib byte in ah
scndsp:
mov si, fs ; source buffer = 0xb000
mov es, si ; destination segment = 0xb000
mov di, 0x8000
scnlp:
lodsb ; mov ds:[si] to al, inc si
stosw ; mov ax to es:[di], add 2 to di
loop scnlp
mov es, cx ; reset es to 0
; get user input
waitusr:
xor ax, ax
int 16h ; int 16h, ah=0 hang on user input -- ascii key in al
pop bx ; recover drive count & active partition -- "without pop"
push bx
cmp al, 'e' ; did user select Alt Bang! boot partition?
je short altewbp
cmp al, bl ; was numeric input higher than the highest drive #?
ja short waitusr
cmp al, 0xd ; enter to select default (active) partition
je short def_part
sub al, 0x30 ; only digits 1 thru bl allowed
jbe short waitusr ; convert from ascii to numeric 1-7
; user selected a drive: must set dl = 0x80 + "al" ( - 1 if <= current dl )
mov cl, al ; what drive number did the user select?
or cl, 0x80 ; turn on the 0x80 bit
cmp cl, dl
jg short drvcp
dec cx
drvcp:
mov dl, cl
jmp short doread
def_part:
mov bl, bh ; active partition value is in bh now
jmp short b_part
altewbp:
mov bl, dh ; alternate Bang! boot partition
; load at 0x500, bl is partition offset from 0x7900 / 0x7d00
b_part:
; get LBA from partition table
cmp bl, 0xae ; did user hit an inactive key? (Ret, e)
je short waitusr ; If so, make 'em do it over
mov bh, 0x79 ; bx is now a partition table entry pointer
mov cl, [bx+4] ; System ID in cl
add bl, 8 ; increment bx pointer to point at StartLBA entry
mov si, bx
mov di, DAPACK+8 ; LBA to read, currently set to 0
movsw
movsw ; store the LBA from partition table
doread:
; load 8K of partition or drive into addy 0x500
mov SI, DAPACK ; address of "disk address packet"
mov AH, 42h
int 13h ; int 13h destroys upper words of many registers!
; None are used here, but if this code is modded, be careful!
mov al, [si+2] ; grab the actual # of sectors loaded
jc short badrd ; die on any failure
cmp al, 16 ; it must be 16!
jne short badrd
cmp cl, 0x1d ; booting a Bang! partition?
; if booting a drive, cl is never 0x1d
; if booting a Bang! partition, just jmp to the ld_pt -- otherwise do a std relocation
je ld_pt
mov cx, 0x1000 ; copy 8K => cx= 4096
mov si, ld_point ; Source (where data is located now) = 0x500
mov di, start ; next loader expects to be run at 0x7c00
rep movsw
sub bl, 8 ; for DOS/Win, MBR needs to
mov si, bx ; set si pointer back to partition entry *sigh*
jmp near start ; run new loader!
badrd:
; print a "Drive not ready" message boldly at TOS, jump back to accepting user input
mov dx, bp ; recover old drive number
mov [si+2], byte 16 ; set read sector qty back to 16
mov si, drvnr ; error message in SI
mov di, fs ; point di at "text screen"
mov cl, 15
rep movsb
mov cl, 0xa0 ; display 2 lines to change the background
mov ah, 0xc1 ; dark blue on light orange ;-)
jmp near scndsp ; copy text screen to real display
mkdspl:
pusha
mov [di+24], cl
mov cl, 8 ; ch is always 0
add di, cx ; "tab" di over to 8th columm
test bl, bl
jne short mkprtl
mov si, dline
jmp short mkdon
mkprtl:
; translate bl to a sysID -- 12, 0x1d, or other (WinF32, Bang!, Unk OS)
mov si, pline
cmp bl, 12
jne short bangtst
mov ax, 0x6957 ; WinF32
stosw
mov ax, 0x466e
stosw
mov ax, 0x3233
stosw
jmp short mkdon
bangtst:
cmp bl, 0x1d
jne short othros
mov ax, 0x6142 ; Bang!
stosw
mov ax, 0x676e
stosw
mov ax, 0x2021
stosw
jmp short mkdon
othros:
mov ax, 0x6e55 ; Unk OS
stosw
mov ax, 0x206b
stosw
mov ax, 0x534f
stosw
mkdon:
rep movsw ; copy the 16 byte generic message
popa
add di, 80
ret
SEGMENT FINAL USE16 ; linker aligns this to end of sector
; display messages
pline:
db ' (current drive)'
dline:
db 'Boot from '
drvnr:
db 'Drive not ready'
chmsg:
db 'Choice:'
dskser:
resb 2 ; "disk serial number" -- only 2 bytes, but that's enough
parttbl:
; 1st partition
db 0x80 ; active
db 0 ; Begin CHS = 0 for now
dw 0
db 0x1d ; OS type -- WinF, Othr, Bang!, non-bootable Bang!
db 0 ; End CHS = 0 for now
dw 0
dd 1 ; LBAstart
dd 12594897 ; partition length (blocks)
; 2nd partition
dd 0
dd 0
dd 0
dd 0
; 3rd partition
dd 0
dd 0
dd 0
dd 0
; 4th partition
dd 0
dd 0
dd 0
dd 0
dw 0AA55h
- Attachments
-
- bl3.txt
- (40.65 KiB) Downloaded 90 times