Page 1 of 1

int 0x10 not working and mkisofs problem

Posted: Mon Aug 30, 2010 3:14 pm
by MDM
Hey, sorry for another noobish question, but I'm having some problems getting my bootsector working correctly, as well as a problem with mkisofs. So I have the code

Code: Select all

;**********************bootstart.s**********************;
; The bootsector
[ORG 0x7c00]
[BITS 16]

jmp 0x0000:bootstart ; jump to set up CS:IP

bootstart:
	; Clear interrupts
;	cli
	; Set our data segment
	xor ax, ax
	mov ds, ax
	mov ah, 0xa
	mov al, bootsectorload
	mov bl, 0xf
	int 0x10
	
;	mov si, greeting
;	call printString
;	mov si, error
;	call printString
;	mov si, load
;	call printString
	hlt
printString:
	lodsb ; Load character of string
	or al, al ; Check to see if al is zero
	mov bl, 0xf
	jz psreturn
	mov ah, 0x13
	int 0x10
	jmp printString
psreturn:
	ret
	
data:
	bootsectorload  db 'A'

times 510-($-$$) db 0
dw 0x55AA
Which I compile with nasm -f bin and then do mkisofs -no-emul-boot -o /Volumes/Macintosh\ HD\ 2/Users/daniel/Desktop/Cube/source/build/CUBE.iso -A CUBE -b cube.img /Volumes/Macintosh\ HD\ 2/Users/daniel/Desktop/Cube/source/build/bin

This works fine, however, when I load this into qemu or virtualbox, the top of the screen glitches. It doesn't complain about booting though. When I inspected the iso file produced by mkisofs, I noticed it had the file in it _DS_STOR, and when I change the directories I use in my iso creation script to mkisofs -no-emul-boot -o /Volumes/Macintosh\ HD\ 2/Users/daniel/Programming/Cube/source/build/CUBE.iso -A CUBE -b cube.img /Volumes/Macintosh\ HD\ 2/Users/daniel/Programming/Cube/source/build/bin
it no longer creates the _DS_STOR file.
Also as you can see from the screenshot, the interrupt isn't producing a character on screen.

Re: int 0x10 not working and mkisofs problem

Posted: Mon Aug 30, 2010 6:00 pm
by robos
some thoughts

1) you're not setting up your own stack, so you have no idea where it is or how big it is

2) int 0x10 function 0xa (see http://www.ctyme.com/intr/rb-0100.htm) writes character at cursor position, but you do not specify the page number (bh) or the number of times the character needs to be written (cx)

3) you do not actually load the 'A' from bootsectorload with "mov al, bootsectorload", you need to write "mov al, [bootsectorload]" or you could just simply write "mov al, 'A'". So with this and the above it's very likely it is indeed not putting a character on the screen.

4) hlt without interrupts disabled will just pause for a moment and then continue executing code, going straight into your printString function. You should write something like "hlt" followed by "jmp $" or better yet something like this:

Code: Select all

hang:
hlt
jmp hang
5) in your printString function you're using int 0x10 function 0x13 which is the print string function (see http://www.ctyme.com/intr/rb-0210.htm), but you're not setting write mode (al), page number (bh), number of characters (cx), offset (dh & dl) or the string to write (es:bp, BOTH of which are not even set in your commented out code above printString). In other words, it's doing completely random things, quite possible overwriting your character (if it was even there to begin with, see above). It generates all the garbage in your screenshot.

6) it makes no sense that you're going through the string yourself while also having the BIOS do that. Either do it yourself or have the BIOS do it for you. I'm guessing you wanted to use int 0x10 function 0x0e (teletype out, see http://www.ctyme.com/intr/rb-0106.htm). In that case you still need to set the page number (bh) but at least the printString function would work. I'm assuming you also wanted to use this to print the character.

7) finally "ret" at the end of your printString will return nowhere in your current code since you did not call it at all, you simply fell through into that function

I suggest you read up on nasm syntax (http://www.nasm.us/doc/), assembly in general (tutorials as well as the Intel/AMD instruction set references) as well as the BIOS functions and the parameters they require

Keep in mind that first boot is a hostile environment. You have no idea what is set up for you or not and no idea what is or is not enabled. Tread carefully!

p.s.: a ._DS_STORE file is generate by Mac OS X. It's harmless, but not needed. It's a hidden file (OS X generates many of these)

Re: int 0x10 not working and mkisofs problem

Posted: Mon Aug 30, 2010 7:01 pm
by MDM
Ah, now its working, set page number and cx, as well as enclosed the bootsectorload in brackets. Thank you for the help!