Page 2 of 2

Re: Writing a boot menu

Posted: Fri Feb 27, 2009 5:21 am
by mangaluve
Thanks for the explanation!

Just a short one.. I dont want to move the stuff I load to "buffer", but instead to the memory location 08h:01000h. I replace "offset buffer" with 01000h but it doesnt seem to work. Am I doing something wrong? It seems like I never get pass this code

still_going:
in al,dx
test al,8
jz still_going

Re: Writing a boot menu

Posted: Fri Feb 27, 2009 11:05 am
by Dex
Try this (untested)

Code: Select all

;************************************
; By Dex
; Assemble with fasm 
; c:\fasm Hdd.asm Hdd.bin
;
;************************************
org 0x7C00 
use16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00 
;*****************************
; Setting up, to enter pmode.
;*****************************
        cli 
        lgdt  [gdtr]
        mov   eax, cr0
        or    al,0x1 
        mov   cr0,eax
        jmp   0x10: protected
;*****************************
; Pmode. ;-)
;*****************************
use32
protected:
        mov   ax,0x8 
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00
;*****************************
; Turn floppy off (if space).
;*****************************
        mov   dx,3F2h
        mov   al,0
        out   dx,al
;*********************************
; Print T in the right hand corner
;*********************************
        mov   byte [es:0xB809E], "1"

        mov   dx,1f6h         ;Drive and head port
        mov   al,0a0h         ;Drive 0, head 0
        out   dx,al

        mov   dx,1f2h         ;Sector count port
        mov   al,1            ;Read one sector
        out   dx,al

        mov   dx,1f3h         ;Sector number port
        mov   al,1            ;Read sector one
        out   dx,al

        mov   dx,1f4h         ;Cylinder low port
        mov   al,0            ;Cylinder 0
        out   dx,al

        mov   dx,1f5h         ;Cylinder high port
        mov   al,0            ;The rest of the cylinder 0
        out   dx,al

        mov   dx,1f7h         ;Command port
        mov   al,20h          ;Read with retry.
        out   dx,al
        mov   byte [es:0xB809E], "2"
still_going:
        in    al,dx
        test  al,8            ;This means the sector buffer requires
            ;servicing.
        jz      still_going     ;Don't continue until the sector buffer
            ;is ready.
        mov   byte [es:0xB809E], "3"

        mov   ecx,512/2        ;One sector /2
        mov   edi,0x1000
        mov   dx,1f0h         ;Data port - data comes in and out of here.
        rep   insw

        mov   byte [es:0xB809E], "4"

        mov   esi,0x1000        ; dump it to screen
        mov   edi,0xB8000
        mov   ecx,512
        mov   ah,' '
ScreenDump:
        lodsb
        stosw
        loop  ScreenDump

        mov   byte [es:0xB809E], "5"
        jmp   $                ; Just loop for now
;*************************************
; GDT. 
;*************************************
gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:       dw gdt_end - gdt - 1
            dd gdt
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start)  db 0
dw 0xaa55
The above code will dump mostlly unreadable words, but there should be some ASCII in there you can read.
Note: also the above code gesses your hdd address, is your's the first drive ?
Also is your base zero based (GDT) and are you tranlating the 0x1000 from realmode ?, as if so it will be 0x10000 for pmode.

Re: Writing a boot menu

Posted: Fri Feb 27, 2009 1:30 pm
by mangaluve
Thanks man! I'm still stuck after 2 has been printed, by I think that maybe I've configured Bochs wrong (only been using it for floppys before). I'ma give your code a real try :) Exactly how do I tell Bochs that my first harddrive should be a certain file, like
floppya: 1_44=booting.bin, status=inserted
but for a hard drive

edit: never mind, it works now.. I think the problem was the following lines:
mov ecx,512/2 ;One sector /2
mov edi, 01000h

I used cx and di instead of ecx and edi before...

Re: Writing a boot menu

Posted: Wed Mar 04, 2009 2:27 pm
by Sly
uh... Dex, a little off-topic, but I didn't see anything for enabling the A20 gate.

Re: Writing a boot menu

Posted: Wed Mar 04, 2009 8:36 pm
by Dex
Sly wrote:uh... Dex, a little off-topic, but I didn't see anything for enabling the A20 gate.
Why would we need to do that for this little demo ?, we are not going over 1MB, Unless your coding a full OS, you only put what is need for the demo, you need to keep things simple, to help beginners understand whats going on.

Re: Writing a boot menu

Posted: Mon Mar 09, 2009 3:33 am
by ScorchOS
That's a good way of doing it, but there is an easier way if you don't want to create your own bootloader from scratch. If you're using grub, you just need to edit the boot/grub/menu.lst file.