So simple, yet freaking

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
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

So simple, yet freaking

Post by joke »

Hi all,
i'm just trying to print a string in real mode. Everythings fine when my kernel is only one sector. Now, i tried to do the same thing by loading a sector of disk into memory. Well, nothing happens, the string does not appear , only a flashing cursor

here's my code
kernelt.asm

Code: Select all

[BITS 16]


%include 'proto2.inc'

Main:
  
mov si,welcome ;print message
call print


halt:
hlt
proto2.inc

Code: Select all

welcome db 'Welcome to my OS!',0 ;welcome message
print:
lodsb ;load from si
cmp al,0 ;see if string has ended
je printend ;if yes?
mov ah,0Eh  ;function params
mov bh, 0Fh
mov bl, 0
int 10h ;print!
jmp print

printend:
ret
the bootloader, boot.asm

Code: Select all

; I used Daniel's tutor at os resources as a template 

[ORG 0]
start:
mov ax,0x7C00
mov ds,ax
mov ax,0x0000
mov ss,ax ; setting my stack
mov sp,0xFFFF
reset_drive:                    
mov ax, 0          
mov dl, 0          
int 13h             
jc reset            

read:
mov ax,1000h ; ES:BX = 1000:0000
mov es,ax          
mov bx,0           ;
mov ah,2           ; Load disk data to ES:BX
mov al,5           ; Load 5 sectors
mov ch,0           ; Cylinder=0
mov cl,2           ; Sector=2
mov dh,0           ; Head=0
mov dl,0           ; Drive=0
int 13h             ; Read!
jc read             ; ERROR => Try again
mov ax,es
mov cs,ax ; i added this later, but it didn't solve my problem
jmp 1000h:0000  ; Jump to the program


times 510-($-$$) db 0
dw 0AA55h




and i use and image file to combine these files, image02.asm

Code: Select all

%include 'boot.asm'
%include 'kernelt2.asm'
i compile
nasm -f bin image02.asm -o image.bin
and
dd if=image.bin of=/dev/fd0

I'd really appreciate any help cause it's so simple and it's not working :(
Thank you
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

first, the most obvious problems:
1) you should specify 'bits 16' (though i dont remember -- it might be default for binary)


2) your loading the wrong DS:
start:
mov ax,0x7C00
mov ds,ax
the sector is loaded to absolute 0x7C00 -- which is 0x07C0:0

this should be:

Code: Select all

start:
mov ax,0x7C0
mov ds,ax


3) this is not valid code (should give an error, but might not):
mov ax,es
mov cs,ax ; i added this later, but it didn't solve my problem
you cannot manually alter the CS register -- only a JMP, CALL, or RET/IRET can alter CS -- and you do that with your FAR CALL


last comment:
i would recommend not combining the files together -- assemble them separately, and then write them to the disk separately (not familiar enough with dd to say how you would do that using that tool)
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

I've changed my code, but still no results. Here's my new code
kernelt2.asm

Code: Select all

[BITS 16]
;i've merged proto and kernelt
Main:
mov si,welcome
call print
;call unixpromt
;jmp Main
halt:
hlt
welcome db 'Welcome to my OS!',0
print:
lodsb
cmp al,0
je printend
mov ah,0Eh
mov bh, 0Fh
mov bl, 0
int 10h
jmp print

printend:
ret
boot.asm

Code: Select all

; I used Daniel's tutor at os resources as a template 
[BITS 16]
[ORG 0]
start:
mov ax,0x7C0
mov ds,ax
mov ax,0x0000
mov ss,ax
mov sp,0xFFFF
reset_drive:                    
mov ax, 0          
mov dl, 0          
int 13h             
jc reset_drive            

read:
mov ax,1000h ; ES:BX = 1000:0000
mov es,ax          
mov bx,0           ;
mov ah,2           ; Load disk data to ES:BX
mov al,5           ; Load 5 sectors
mov ch,0           ; Cylinder=0
mov cl,2           ; Sector=2
mov dh,0           ; Head=0
mov dl,0           ; Drive=0
int 13h             ; Read!
jc read             ; ERROR => Try again

jmp 1000h:0000  ; Jump to the program


times 510-($-$$) db 0
dw 0AA55h
i assembled
nasm -f bin kernelt2.bin -o kernel.bin
nasm -f bin boot.asm -o boot.bin

and
dd if=boot.bin of=/dev/fd0
dd if=kernel.bin of=/dev/fd0 obs=512 seek=1 ( i retried with seek=2 but didn't work either)
Any opinions on how to make it work are welcome
best regards
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

I think, that you have to reload segment register DS to value 0x100 before jump to loaded kernel, or use [org 0x1000] directive in your kernel code and load 0x0 to DS.

Also, I'm not sure, but I think that BIOS remains unchanged values of registers ax and bx after call -- consult with docs :) -- so, may be, you don't need to load this registers everytime in cycle.
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

The thing is that the intel manuals don't zoom too much on real mode operations , sadly :( (i mean like loading your kernel with interrupts, cause the describe everything else, like FLAGS,cr0-4,ther regs etc). I'll try to load the ds with 0x100 and post the results. Btw, if anyone knows dd , is my seek synax correct(obs=512,seek=1 is to correct)? I mean i want to write in sector 2, not overwrite my bootsector :D
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

i added a

mov ax,0x100
mov ds,ax

before the
jmp 1000h:0000

but still no success
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

Well, this is very strange. Did you try seek=2? If yes -- I have no ideas for now... You can send me your binary code, I'll try to test it.

mail: -=mika0x65=--=gmail=--=com=- (without '-=' and '=-')
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

i sent the bins as specified. Let's hope this brings something...
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

Check your mail, I've sent you an answer already :).
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

Hell , it worked !!!!!!! Yeah, it was that ds reg that made me troubles. A thousand thank yous Mikae. (and JaaMan). You saved me!
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
Post Reply