boot loader 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
0xBADC0DE

boot loader problem

Post by 0xBADC0DE »

anyone know why this code doesn't print to the screen?

Code: Select all

[bits 16]
[org 0x7c00]

jmp 0x0:stage1

stage1:
mov ax, 0x7c0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

stage2:
mov ax, 0xb800
mov es, ax
mov di, 0x0
mov byte [es:di], 'j'
inc di
mov byte [es:di], 0x07

end:
jmp end

times 510-($-$$) db 0
bootsig dw 0xAA55
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:boot loader problem

Post by Neo »

stage2:
mov ax, 0xb800
mov es, ax
mov di, 0x0
mov byte [es:di], 'j'
inc di
mov byte [es:di], 0x07
it seems like you want to move a char to video mem. Video mem has address 0xB8000 not b800 so to use this you have to use a segment:offset combi. the above code may then be re-written as

Code: Select all

stage2:
mov ax, 0xb000
mov es, ax
mov di, 0x8000
mov byte [es:di], 'j'
inc di
mov byte [es:di], 0x07
HTH
Only Human
0xBADC0DE

Re:boot loader problem

Post by 0xBADC0DE »

that does not work either
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:boot loader problem

Post by Candy »

osdever wrote: that does not work either
Since your code is doing what it's supposed to be doing, and Neo's change does exactly the same (sorry neo), you probably test on a computer that doesn't fit your expectation. That is, the text area of the video memory is not at 0xb8000

Think about the possibility, and then think what can then be different. Test on different computers, try it on bochs, do things like that. Be bold and try anything you can think of. In any case, your code is correct..

Just one sidenote though, you use the word stage for every jump at this point. Stages are usually used as separate files, and one only adds a stage if it's not possible to leave it out without changing the design. Either change your words, make them fit the common definition or live with most people taking the wrong idea.
Not Logged In

Re:boot loader problem

Post by Not Logged In »

osdever wrote:
[org 0x7c00]

mov ax, 0x7c0
mov ds, ax
Your Problem is that you're telling the program that it is located @ 7C0:7C00

Correct code would be:

Code: Select all


[org 0x7c00]

mov ax, 0x0
mov ds, ax
or

Code: Select all


[org 0x0]

mov ax, 0x7c0
mov ds, ax
TB

Re:boot loader problem

Post by TB »

Well I've tested your code under VMWare and it did work without any problems. Here's what I've done to compile and write to disk:
nasmw boot.asm -o boot.bin
partcopy boot.bin 0 200 -f0 0
Curufir

Re:boot loader problem

Post by Curufir »

Works fine on my comp so I'm just gonna ignore the print problem and get you to fix something else right away.

Code: Select all

[org 0x7c00]

jmp 0x0:stage1

stage1:
Now to the assembler (NASM, since you are using the times directive) the label stage1 is simply an offset into the binary file. The org 0x7c00 directive tells the assembler to add 0x7c00 to that offset to produce the final address associated with that label.

This behaviour menas the far jump executes fine (Note that near jumps use a relative offset, so they aren't affected by the org statement), because you are setting cs to 0x0 in the process.

Now comes the problem.

Code: Select all

mov ax, 0x7c0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
You set every other segment to be 0x7c0. This means that any time you address memory you are going to be looking in the wrong place.

If, for example, I wanted to put the contents of bootsig into memory I'd normally do something like:

Code: Select all

mov ax, word [bootsig]
With the environment you've set up this will NOT work.

Because you are using both the org directive AND have set the base of the segments then what that instruction actually reads as (It implicitly uses ds) is:

Code: Select all

move into ax the word at (0x7c0:0x7c00 + offset of bootsig)
Which is obviously not the correct address of bootsig.

Either use the org directive to make the labels correct, and set the segments to 0x0, or set the segments to 0x7c0 and the org directive to 0x0. The two mechanisms are mutually exclusive.

Sorry if that sounds patronising, but I'd rather risk that than have you come back in a couple of days with this problem.

***

As for the print problem. I know this is gonna sound seriously dumb, but are you sure it isn't printing? I only say this because if I hadn't known that char was going to come out in the top left corner of the screen I would probably not have noticed the change from the BIOS splash text.
Post Reply