kernel printing trash

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.
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

kernel printing trash

Post 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
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: kernel printing trash

Post 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?
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

Re: kernel printing trash

Post by A32 »

I changed it a little, its still printing trash, but atleast its printing different kind of trash.
User avatar
mnovotny
Member
Member
Posts: 27
Joined: Mon Aug 10, 2009 2:54 am
Location: Slovakia

Re: kernel printing trash

Post by mnovotny »

Hi,

Are you sure you have your segment registers set up properly? Or use [ORG 0xXXXX] stuff.
Keep the world with all its sin
It's not fit for livin' in
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

Re: kernel printing trash

Post 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.
User avatar
ahmedhalawa
Member
Member
Posts: 28
Joined: Wed Jul 02, 2008 9:28 am

Re: kernel printing trash

Post by ahmedhalawa »

i think the problem in

Code: Select all

mov si,msgHello
call Print_string
to which where si point
in my opinion if wants to use this code with out any changes in it
try to add

Code: Select all

[org 0x07c0]
in your code
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

Re: kernel printing trash

Post by A32 »

ahmedhalawa wrote:i think the problem in

Code: Select all

mov si,msgHello
call Print_string
to which where si point
in my opinion if wants to use this code with out any changes in it
try to add

Code: Select all

[org 0x07c0]
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
User avatar
mnovotny
Member
Member
Posts: 27
Joined: Mon Aug 10, 2009 2:54 am
Location: Slovakia

Re: kernel printing trash

Post 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.
Keep the world with all its sin
It's not fit for livin' in
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: kernel printing trash

Post by Combuster »

The bug:
hlt
"temporarily suspend execution" temporarily being until an (timer) interrupt happens.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

Re: kernel printing trash

Post 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. :roll: Just learning.

Edit:
"temporarily suspend execution" temporarily being until an (timer) interrupt happens.
whats a timer interrupt? :D
User avatar
mnovotny
Member
Member
Posts: 27
Joined: Mon Aug 10, 2009 2:54 am
Location: Slovakia

Re: kernel printing trash

Post 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.
Keep the world with all its sin
It's not fit for livin' in
A32
Posts: 6
Joined: Fri Aug 14, 2009 8:45 am

Re: kernel printing trash

Post 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?
User avatar
mnovotny
Member
Member
Posts: 27
Joined: Mon Aug 10, 2009 2:54 am
Location: Slovakia

Re: kernel printing trash

Post 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.
Keep the world with all its sin
It's not fit for livin' in
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: kernel printing trash

Post 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.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: kernel printing trash

Post by Troy Martin »

A32 wrote:whats a timer interrupt? :D
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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Locked