boot sector loop problem

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
GLneo

boot sector loop problem

Post by GLneo »

hi all, when i test my boot sector in boch it says:

Code: Select all

00008243609i[CPU  ] LOCK prefix unallowed (op1=0x53, attr=0x0, mod=0x0, nnn=0)
a million times. does anyone know what that means ???, thx :)
Uncanny Dude

Re:boot sector loop problem

Post by Uncanny Dude »

Hi!

It seems you are jumping to bogus memory, it happened to me a zillion times. Try inserting a jmp $ in your code to see how far it goes without errors.

Maybe it is the place you had put your buffer.

Cheers.
AR

Re:boot sector loop problem

Post by AR »

Your problem is this:

Code: Select all

[BITS 16]

  >>>[ORG 0]<<<

    >>>jmp 0x00:start<<<

    printdash:
       push ax
       push bx
       push cx
       push dx
       mov ah, 0Eh
       mov al, 45
       xor bx, bx
       int 10h
       pop dx
       pop cx
       pop bx
       pop ax
       ret

    start:
       xor ax,ax
       mov ds,ax
       mov ss,ax
       mov esp,9000h
You are jumping to 0000:0020 or something along those lines. ORG is the offset from the start of the segment, your segment is at 0000, bootsectors are located at 0x7C00 so what you want is [ORG 0x7C00]
GLneo

Re:boot sector loop problem

Post by GLneo »

O.K. i tryed ar's suggsestion and it fixed the "LOCK prefix unallowed" error but it still didn't work so i tryed Uncanny Dude's suggsestion and found it is a div error but why ???
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:boot sector loop problem

Post by Brendan »

Hi,

It's a "divide by zero" error...


[edit: sorry - messed up the first division, corrected now]

Code: Select all

    mov ax, 02h
    mov cx, 18
LoadSectors:
    mov dl, 18h
    div dl               ;al = 0 (result), ah = 2 (remainder)
    inc ah              ;ah = 3
    mov cl, ah        ;cl = 3
    mov dh, al        ;dh = 0
    mov ax, 02h     ;ax = 2
    div dh             ;al = 2/0 = divide by zero error

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
GLneo

Re:boot sector loop problem

Post by GLneo »

hmmm... i dont know much about div in asm :-\ but heres my code:

Code: Select all

mov dl, 18h
div dl
inc ah
mov cl, ah
Sector = (LBA mod SectorsPerTrack)+1

Code: Select all

mov dh, al
mov ax, 02h
div dh
mov ch, ah
Cylinder = (LBA/SectorsPerTrack)/NumHeads

Code: Select all

mov dh, al
Head = (LBA/SectorsPerTrack) mod NumHeads
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:boot sector loop problem

Post by Brendan »

Hi,

It's your code (taken from your link) that I used for my last post, showing what would be in each register and why you're getting a "divide by zero" error. Posting the exact same (faulty) code won't change this...
GLneo wrote: hmmm... i dont know much about div in asm :-\ but heres my code:

Code: Select all

mov dl, 18h
div dl
inc ah
mov cl, ah
Sector = (LBA mod SectorsPerTrack)+1
At this point:
cl = LBA mod SectorsPerTrack+1
ah = LBA mod SectorsPerTrack+1
al = LBA / SectorsPerTrack
dl = 18h still

Code: Select all

mov dh, al
mov ax, 02h
At this point:
cl = LBA mod SectorsPerTrack+1
ax = 02h
dl = 18h still
dh = LBA / SectorsPerTrack

Also at this point, if LBA is less than SectorsPerTrack, then "LBA / SectorsPerTrack" will be zero, and therefore dh will be zero.

The next instruction is "div dh", or (if LBA is less than SectorsPerTrack), "divide by zero".

For the code in your boot sector (from your link), LBA is always equal to 02h as you do a "mov ax, 02h" immediately before this code. Therefore LBA is always less than SectorsPerTrack, and you'll always get a "divide by zero" error.

The problem with dividing by zero is that the answer is infinity. All pocket calculators and CPUs that I've ever seen have trouble with infinity. An 80x86 CPU will generate a "Divide Error Exception" (exception 0x00).

Often, what your code is meant to be doing and what it actually is doing is completely different. Using your mind (and the assistance of Intel's manuals if necessary), it's often possible to step though the code one instruction at a time (while keeping track of what each register or variable contains) until you find the bug.

I'd hope that if you realize that you "dont know much about div in asm", and if you're having trouble with bugs in code that mainly relies on "div in asm", then as a programmer you'd have the skills needed to find details of this instruction (in either Intel's reference material or elsewhere) and the sense to learn about "div in asm".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply