how to load the BS loader in the floppy

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
adeelmahmood1

how to load the BS loader in the floppy

Post by adeelmahmood1 »

hi
i need to know how to load the boot strap loader in the first sector of my floppy and i m using windows for that...
plz explain this in detail ..
thanx for ur help
adeelmahmood1

Re:how to load the BS loader in the floppy

Post by adeelmahmood1 »

and also tell me how u guys do it in linux .. i know how to use Partcopy but i was thinking may be there 's some other way ...
and also if some one can help me in this boot loader .. its code is

[bits 32]
jmp entry_point

entry_point:
mov ax,0xb800
   mov es,ax
   
   mov bx,letter
mov ah,BYTE [bx]

   mov byte [es:0x0f9c], ah
   
jc entry_point
jmp $

letter db 'H'
times 510- ($-$$) db 0
dw 0AA55h
...
i m trying to run this with partcopy but its not showing anything on the screen .. i dont know wats wrong with it .. can somebody plz check this
thanx
Tom

Re:how to load the BS loader in the floppy

Post by Tom »

I'm a linux OS programmer so here:

if using my FritzOS:
Download my FritzOS 6 and put in a empy floppy in /dev/fd0 ( your first floppy drive )
extract FritzOS.
change dirs to the FritzOS dir
type sh install.sh
reboot with the floppy in and there you go!
Schol-R-LEA

Re:how to load the BS loader in the floppy

Post by Schol-R-LEA »

adeelmahmood1 wrote: and also tell me how u guys do it in linux .. i know how to use Partcopy but i was thinking may be there 's some other way ...
The standard Unix/Linux utility for raw-writing and raw-reading disks is dd(1). Assuming you are writing to fd0, then the syntax should be:
[tt]
dd if=<filename> of=/dev/fd0 bs=512 count=1
[/tt]
Check the man and texinfo pages for more details.
and also if some one can help me in this boot loader .. its code is

Code: Select all

[bits 32]
jmp entry_point

entry_point:
                mov ax,0xb800
???mov es,ax
???
???mov bx,letter
                mov ah,BYTE [bx]

???mov byte [es:0x0f9c], ah
???
jc entry_point
jmp $

letter db 'H'
times 510- ($-$$) db 0
dw 0AA55h
i m trying to run this with partcopy but its not showing anything on the screen .. i dont know wats wrong with it .. can somebody plz check this
thanx
OK, here are a few things
  • PCs always boot up in real mode; thus, the BITS directive should be set to 16, not 32.
  • you're missing an ORG directive. Given the code above, the easiest solution is to put "[ORG 0x7C00]" on the line after the BITS directive. This assumes that the code segment register is set to 0000, which is usually the case (but see below).
  • Since there's no BIOS Parameter Block (needed only when using a FAT type file system) you don't need to have that starting 'JMP entry_point' to jump past it. However, it is a good idea to start your code with a FAR jump to the entrypoint, to make synch you code segment (that is, to make sure that the code segment register is set to 0000, as the ORG directive requires it to be). In that case, the code should be

    Code: Select all

    jmp far 0000:entry_point
    
  • You will want to make sure that the data segment register (DS) is set correctly for where you have you data; in this case, it should be equal to the code segment.

    Code: Select all

    mov ax, cs
    mov ds, ax
    
  • While it doesn't hurt anything, it is redundant to move the address of 'letter' into bx first, and then dereference it into ax. you could save a few bytes by just using "mov ax, [letter]".
  • I'm not sure why yoyu are using the constant '0x0f9c', offhand, but it is doesn't appear to point to a location on text page 0. If you want the character to appear in the middle of the screen, a closer approximation would be 0x0900.
  • Why do you have the jump on carry back to entry_point? It should never be true, and it serves no purpose as far as I can tell. What is it for?
That looks like everything. I've attached a version with these changes made to it, which I've assembled and run successfully under Bochs v.4.1; HTH.
adeelmahmood1

Re:how to load the BS loader in the floppy

Post by adeelmahmood1 »

ok i understood quite much of u ..
-
ok so it means that the bits directive must always be 16. coz pc always boots up in real mode .. but i have seen BS loaders with [bits 32] in them ... can u also explain to me why they use that ..?

-
i didnt completely understood why to use a far jmp to entry_point .. and also it didnt compiled when i tried that ???

-ok and after that the MOST IMP THING THAT AFTER THAT CHANGES U ASKED ME TO DO >> STILL ITS NOT WORKING.....
here 's the new code

[bits 16]
[ORG 0X7C00]
jmp 0000:entry_point

entry_point:
   mov ax,cs
   mov ds,ax

mov ax,0xb800
      mov es,ax

      mov bx,letter
mov ah,BYTE [bx]

      mov byte [es:0x0900], ah


jmp $

letter db 'H'
times 510- ($-$$) db 0
dw 0AA55h

.....
i didnt put the jmp far thing coz it was not compiling with that . it was saying "operand size doesnt match" so i changed that to "jmp 0000:entry_point"
so plz help
thanx for ur help
Schol-R-LEA

Re:how to load the BS loader in the floppy

Post by Schol-R-LEA »

Oops, the FAR part was a mistake... I thought I'd edited that out. Sorry.

I just tried the newer code you've posted, and it runs fine under Bochs. I'll try booting it from a real floppy now and see how it works.

Could you show us the command line or batch file you use to run partcopy with? This is one whic I've used:

c:\bin\partcopy boot.sec 0 200 -f0

Try putting this (changing the filename from 'boot.sec' to what ever file you are assembling it to, as appropriate, of course) in a file makedisk.bat, and see if it works.

Also, what command line are you using with NASM?
adeelmahmood1

Re:how to load the BS loader in the floppy

Post by adeelmahmood1 »

yuppp it worked ..
before this i was using

partcopy boot.bin 0 3 -f0 0

and now i used ur thing

partcopy boot.bin 0 200 -f0

and it worked .. but can u explain this to me what are these parameters for partcopy ...
and thanx alot for ur help
Schol-R-LEA

Re:how to load the BS loader in the floppy

Post by Schol-R-LEA »

[attachment deleted by admin]
Post Reply