Page 1 of 2
kernel printing trash
Posted: Fri Aug 14, 2009 8:55 am
by A32
So, I am kinda new to this OS development, I got caught two months ago, and I was starting with the bare bones 1 kernel. I fitted in the boot sector fine. Then it grew and I needed a bootloader. I got none of the bootloader work, I got frustrated, and left OS dev behind. Now I am starting again, this I got a bootloader to work (MikeOS bootloder) but now my kernel is not working. I am simply tring to print "Hello world" to the screen, but instead, it prints some garbage ( looping over and over).
It is so frustrating. One possible theory is that MikeOS bootloader doesnt work with my kernel, but its the only working bootloader.
My kernel code:
Code: Select all
[BITS 16]
mov si,msgHello
call Print_string
hlt
Print_string:
lodsb
or al,al
jz .done
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
int 0x10
jmp Print_string
.done:
ret
msgHello db 0x0D, 0x0A, "Hello World", 0x0D, 0x0A, 0x00
TIMES 510-($-$$) DB 0
Re: kernel printing trash
Posted: Fri Aug 14, 2009 9:39 am
by gravaera
Or you could try GrUB. Here is the Wiki article:
http://wiki.osdev.org/GRUB
I don't use interrupts very much, and I've never used the BIOS printing interrupts before, but it seems like the problem is somewhere there. Maybe you could try checking that the right value are loaded into the registers?
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:08 am
by A32
I changed it a little, its still printing trash, but atleast its printing different kind of trash.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:36 am
by mnovotny
Hi,
Are you sure you have your segment registers set up properly? Or use [ORG 0xXXXX] stuff.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:39 am
by A32
mnovotny wrote:Hi,
Are you sure you have your segment registers set up properly? Or use [ORG 0xXXXX] stuff.
Oh yeah the segment registers. I fixed that, but... now it doesnt load... Maybe the bootloader has problems. But its the only working I have found, GRUB is too hard to configure.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:41 am
by ahmedhalawa
i think the problem in
to which where si point
in my opinion if wants to use this code with out any changes in it
try to add
in your code
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:45 am
by A32
ahmedhalawa wrote:i think the problem in
to which where si point
in my opinion if wants to use this code with out any changes in it
try to add
in your code
Done everything, it still doesnt load. The new code:
Code: Select all
[BITS 16]
[org 0x07c0]
prepare:
mov ax, 0x07C0
mov ds, ax
mov es, ax
mov si,msgHello
call Print_string
hlt
Print_string:
.loop:
lodsb
or al, al
jz .done
mov ah, 0x0E
int 0x10
jmp .loop
.done:
ret
msgHello db "Hello World", 0
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:47 am
by mnovotny
A32 wrote:[org 0x07c0]
A32 wrote:mov ax, 0x07C0
mov ds, ax
mov es, ax
I must ask: where does MikeOS bootloader load your kernel? Because that code is just nonsense from normal point of view.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:49 am
by Combuster
The bug:
hlt
"
temporarily suspend execution" temporarily being until an (timer) interrupt happens.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 10:56 am
by A32
I... I Dont understand what you are saying
MikeOS bootloader loads the kernel in RAM and jumps to position 2000h:0000h (whatever that is) in the loaded kernel. If the hello world program has errors, can you explain them to me with a OSdev-newbie language.
Just learning.
Edit:
"temporarily suspend execution" temporarily being until an (timer) interrupt happens.
whats a timer interrupt?
Re: kernel printing trash
Posted: Fri Aug 14, 2009 11:19 am
by mnovotny
Code: Select all
[BITS 16]
prepare:
mov ax, 0x2000 ; You said you're here
mov ds, ax
mov es, ax
mov si,msgHello
call Print_string
hang: jmp hang ; Use instead of hlt
Print_string:
.loop:
lodsb
or al, al
jz .done
mov ah, 0x0E
int 0x10
jmp .loop
.done:
ret
msgHello db "Hello World", 0
I'm in hurry and didn't test it, but try it.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 11:23 am
by A32
Thanks, that worked. I get that hang thingy but what really this
Code: Select all
mov ax, 0x2000
mov ds, ax
mov es, ax
does? I also get the mov parts but what is 0x2000?
Re: kernel printing trash
Posted: Fri Aug 14, 2009 11:27 am
by mnovotny
http://wiki.osdev.org/Segmentation#Real_mode
A32 wrote:MikeOS bootloader loads the kernel in RAM and jumps to position 2000h:0000h (whatever that is) in the loaded kernel.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 12:06 pm
by tantrikwizard
A32 wrote:I also get the mov parts but what is 0x2000?
You cannot expect to write an operating system if you lack the fundamental knowledge of the hardware you're trying to write an operating system for.
Re: kernel printing trash
Posted: Fri Aug 14, 2009 12:40 pm
by Troy Martin
A32 wrote:whats a timer interrupt?
Oh dear lord...
I'd suggest you read the Intel manuals. And about half a dozen 16-bit assembly tutorials. Then, if you understand even a bit of your copy/pasted code, this might not happen again.