Help debugging assembly code (Was: "Interesting 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
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Help debugging assembly code (Was: "Interesting problem")

Post by lkurusa »

Hello:)

In the following lines of code if I uncomment the lines, the program just hangs in bochs, no error message whatsoever....:/
The code is loaded via the bootloader to the address of 0x2000...
If the lines are commented, everything works fine as intended.
I just don't seem to understand why the emulator hangs when I uncomment any of those lines
Please help me, thanks in advance :)

Code: Select all

org 0x2000
entry:
mov si, msg
call putstr
mov byte [0x298], 0x01
jmp 0x1000
;mov bx, 0x0000    ; LINES FROM HERE 
;mov es, bx
;mov bx, 0x2300
;mov byte [0x0297], 4
;mov ax, 0 ; move code segment to ax
;mov ds, ax ; move ax to data segment
;mov es, ax ; move ax to extra segment
;mov		ah, 0					; reset floppy disk function
;mov		dl, 80h				; drive number
;int		0x13					; call BIOS
;jc		fail				

;mov byte cl, [0x297]

;mov		ah, 0x02				; read floppy sector function
;mov		al, 1					; read 1 sector
;mov		ch, 0					; track number
;;mov		cl, 2					; sector to read
;mov		dh, 0					; head number
;mov		dl, 80h					; drive number.
;int		0x13					; call BIOS - Read the sector
;;jc fail
hlt
putstr:
        lodsb           ; AL = [DS:SI]
        or al, al       ; Set zero flag if al=0
        jz putstrd      ; jump to putstrd if zero flag is set
        mov ah, 0x0e    ; video function 0Eh (print char)
        mov bx, 0x0007  ; color
        int 0x10
        jmp putstr
putstrd:
        retn
        
msg db 'Sector 3 loaded. Pure awesomenuzz!', 0
	
size    equ     $ - entry
%if size > 512
  %error "util > 512"
%endif
        times   (512 - size) db 0
Thanks again :)
Last edited by JamesM on Wed Aug 08, 2012 11:36 am, edited 1 time in total.
Reason: Your problem is not interesting.
Cheers,

Lev
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Interesting problem

Post by GAT »

It looks like you are messing with the segment registers without saving/restoring them. And possibly setting the wrong drive number. (Hint - first floppy is drive 0 IIRC)
Try uncommenting it a few lines at a tine til you hit a problem.
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: Interesting problem

Post by lkurusa »

I'm reading from the HDD so I assume that 80H is alright.
If I just uncomment a line it just hangs just like this would:

Code: Select all

hang:
 jmp hang
Cheers,

Lev
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Interesting problem

Post by GAT »

Try this:

Code: Select all

;mov bx, 0x0000    ; LINES FROM HERE
push es
push ds
;mov es, bx
;mov bx, 0x2300
;mov byte [0x0297], 4
;mov ax, 0 ; move code segment to ax
;mov ds, ax ; move ax to data segment
;mov es, ax ; move ax to extra segment
;mov      ah, 0               ; reset floppy disk function
;mov      dl, 80h            ; drive number
;int      0x13               ; call BIOS
pop ds
pop es
;jc      fail            

;mov byte cl, [0x297]

mov bx, 0x0000
push es
push ds
mov es, bx
mov bx, 0x2300
;mov      ah, 0x02            ; read floppy sector function
;mov      al, 1               ; read 1 sector
;mov      ch, 0               ; track number
;;mov      cl, 2               ; sector to read
;mov      dh, 0               ; head number
;mov      dl, 80h               ; drive number.
;int      0x13               ; call BIOS - Read the sector
pop ds
pop es
;;jc fail
Also, what is with the jmp 0x1000 near the top of the code?
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: Interesting problem

Post by lkurusa »

Still hangs, 0x1000 is an another sector which is properly loaded and executed.
I have absolutely no idea why from a single piece of code it just hangs, not even printing the strings...
Probably NASM optimizing too much..
Cheers,

Lev
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Interesting problem

Post by GAT »

no, nasm don't optimize.
Where is the fail that you jc to after int 13h?
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
Congdm
Member
Member
Posts: 48
Joined: Wed Aug 01, 2012 10:53 am

Re: Interesting problem

Post by Congdm »

You jump to 1000h but how did you know the exact address to return?
And what is the purpose of hlt before putstr?

How about using Bochs debugger if you can not find the bug?
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: Help debugging assembly code (Was: "Interesting problem"

Post by lkurusa »

Fail is just a simple call to putstr, so I know if the load sector sets an error.
This sector's job is to load a filesystem (later), and then pass control back to RAM adress 1000h, so I know the return adress.
Cheers,

Lev
Post Reply