Page 1 of 1

Boot script not working

Posted: Sun Aug 13, 2006 10:30 am
by James
My friend and I were working on a new boot script:

Code: Select all

                          
#fasm#         ; use flat assembler syntax

#make_boot#

org 7c00h      ; set location counter.



;Trip OS bootload

mbr_ch_loop:
        lodsb
        cmp al,0
        jz tripos_load
        mov ah,0x0E
        int 0x10
        jmp mbr_ch_loop

tripsos_load:
        mov ah,0x32
        mov al,0x32
        xor bx,bx
        mov es,bx
        mov bx,0x7E00
        mov cx,0x0002
        mov dx,0
        int 0x13

        jmp 0x7E00

        mbr_msg db 13, 10, 'TripOS bootloader running'

        times 510-($-$$) db 0

        db 0x55
        db 0xAA



INT 19h        ; reboot

Again our compiling team had a virus attack. So, if someone could compile this for me, I would be very happy!

Thanks

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:27 pm
by DruG5t0r3
so how did you post this if you had a "virus attack"?...

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:33 pm
by Kemp
The first rule of OS dev is you do not talk about OS dev ;D Sorry, actually the first rule is that other people won't compile things for you. Getting it working yourself is absolutely necessary, especially at the beginning where you can be putting out a new version with bug fixes every 5 mins or so. It's next to impossible to dev via someone else.

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:33 pm
by James
My friend has a couple of comps, they do all the compiling etc.. They gave me the script to see if we could get it compiled.. I dont like using the compiler.. It never works for me!

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:42 pm
by Candy
James wrote: My friend has a couple of comps, they do all the compiling etc.. They gave me the script to see if we could get it compiled.. I dont like using the compiler.. It never works for me!
If you're still in the stage of fighting with your compiler, you need a few more months or decades of experience developing software before starting OS dev.

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:42 pm
by DruG5t0r3
if it doesn't work...fix it!...thats the whole point of deving

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:44 pm
by James
I thought this was a supprt forum..

Can you not just compile it with Nasm?

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:45 pm
by Kemp
Support != doing things for you. You need to know how to do these things for yourself in order to get anywhere. I suggest looking through the OSFAQ, especially the pages about getting a dev environment set up and the various things not to do.

Re:Boot script not working

Posted: Sun Aug 13, 2006 12:46 pm
by James
OK it doesnt matter..

Re:Boot script not working

Posted: Sun Aug 13, 2006 4:21 pm
by Schol-R-LEA
We can't help much without more information about how it is failing, in any case. I can give a few pieces of advice though (pardon any mistakes I may make, I haven't been doing this for a while):

[*] I don't know much about Flat Assembler, but as far as I know, it takes a syntax that is almost the same as Netwide Assembler. If you can't get FASM to work, you might want to try NASM. If you do, you may want to get NASM-IDE or NASMEdit (also on the same web page, though I don't think it works with the current version of JVM) to make working with it easier. Yasm is also another option to consider using.

[*] There's a typo on either line 3 or line 8 (counting only actual lines of code): on the former, a label is given as [tt]tripos[/tt], while on the latter, it is given as [tt]tripsos[/tt]. One of the two must be changed; as it is, it probably won't assemble at all. (BTW, there's has already been at least one other operating system called Tripos - in fact, it was the basis for AmigaExec back in the 1980s. While you don't have to change the name, you should be aware of the fact in case there's any confusion. I ran into the same problem when I was calling mine 'Janos'.)

[*] The code never sets the segment registers. You never use the stack in this part of the code, but you do use a data offset, which could be a problem; while most BIOSes do set the code and data segments to 0000, you cannot rely on it. I would add some code just before [tt]mbr_ch_loop[/tt] to the effect of:

Code: Select all

start:
  mov ax, 0x9000   ;  select some arbitrarily high point in memory
  cli
  mov ss, ax          ; and set the stack segment to it
  mov sp,  0xFFFF  ; put the stack pointer to the top of SS
  sti                  ; reset interrupts so BIOS calls can be used
  mov ax, cs
  mov ds, ax          ; set DS == CS
Even if this is not the cause of the current problem, it will help you avoid others in the future.

[*] In the existing code, the very first instruction given is 'lodsb', which is supposed to load the first byte of a string which is pointed to by the SI register in the AH register. The problem is, the SI register hasn't been set yet. you need something like

Code: Select all

lea si, mbr_msg
before that in order to make it work.

[*] You need to issue a disk reset interrupt call (int 0x13, AH=0x00) before you try reading from the disk.

[*] The BIOS interrupt for reading a sector from a disk is Int 0x13, AH=0x02, not int 0x13, AH=0x32 (which isn't even a standard BIOS call). I'm guessing that this was another typo.

BTW, I'm attaching a copy of my own boot loader, which may be helpful. It's for NASM (which as I said is similar but not quite the same as FASM), and uses several macros and a lot of defined constants, but it's well commented and may prove useful to you as a reference point. The OS-DEV Wiki has several links to other example boot loaders to look at as well, and a detailed explanation of the boot-up sequence and how to design a boot loader.

Re:Boot script not working

Posted: Mon Aug 14, 2006 1:38 pm
by Schol-R-LEA
Oh, I hadn't even noticed this until now: the [tt]int 0x019[/tt] operation is in the wrong place. Putting it after the boot signature means that it will actually be past the end of the boot sector, and won't get added to the boot code at all; it might even cause a problem with raw-writing to the disk, depending on how you do it.

Re:Boot script not working

Posted: Tue Aug 15, 2006 3:30 am
by James
Yeah, that was one of the bugs we fixed! Well, it now works any hoo thanks for all the help!