segment 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
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

segment problem

Post by assembler01 »

This is my 16 bit kernel code:

Code: Select all

section .text
bits 16
org 0x0
_start:
cli
mov ax, 0x0
mov ss, ax
mov sp, 0x0ffff
sti
cld
mov ax, 0x0200 ; the segment my bootloader loads my kernel
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
test: ; this tests to see if the bootloader has actually booted my kernel
mov ah, 0x0e
mov al, 'O'
xor bh, bh
int 0x10
main:
call clean_all ; clears the screen and registers
mov si, .msg
call print
jmp .halt
.msg: db 'Testing, testing ...', 0
.halt:
cli
hlt
jmp .halt
section .data
%include "screen.asm"
%include "clean.asm"
When I run it in qemu it boots up perfectly (it shows the 'O' char) but after that, nothing happends. I guess it is a segmentation problem but the setup is like in the mikeos kernel.
Talk is cheap, show me the code. - Linus Torvalds
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: segment problem

Post by Yoda »

Why org 0?
BIOS loads boot sector to 7C00h.
Also, moving 0FFFFh into SP makes stack not word-aligned.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: segment problem

Post by assembler01 »

This is not my bootloader, this is the (test) kernel. I have tested the bootloader loading the mikeos kernel and it worked perfectly.
Talk is cheap, show me the code. - Linus Torvalds
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: segment problem

Post by Yoda »

How bootloader jumps to kernel? I.e. what is in CS register?
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: segment problem

Post by qw »

assembler01 wrote:When I run it in qemu it boots up perfectly (it shows the 'O' char) but after that, nothing happends.
Perhaps it's because you disable interrupts before the HLT. I know this prevends Bochs from updating the screen, maybe the same counts for Qemu.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: segment problem

Post by Yoda »

The cli/hlt is his final sequence. That's ok.
I think, he found that didn't properly initialize CS by far jump, that's why he didn't respond to last my post.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: segment problem

Post by xenos »

Hobbes wrote:Perhaps it's because you disable interrupts before the HLT. I know this prevends Bochs from updating the screen, maybe the same counts for Qemu.
I'm not quite sure about Bochs, but I know for sure that it prevents updating the screen on Qemu.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: segment problem

Post by bubach »

Still, how is that relevant? By that point the message is already printed, and it's not exactly uncommon to end your code with cli, hlt.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: segment problem

Post by VolTeK »

Set your segments before your jump to your kernel code.

Yoda wrote:Why org 0?
Because as you can see, its his kernel code. Not his bootloader code.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: segment problem

Post by qw »

bubach wrote:Still, how is that relevant? By that point the message is already printed
No, it is not. It is printed when Bochs/Qemu refreshes the screen, which may be a long time (relatively speaking) after return from INT 10H.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: segment problem

Post by Yoda »

VolTeK wrote:Because as you can see, its his kernel code. Not his bootloader code.
Ask others to repeat it too. Did you read this topic? I did. :D

Hey, guys, topicstarter probably solved his problem and left this topic. What is the reason to plow the sand after him?
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: segment problem

Post by qw »

Yoda, a forum is a way to exchange ideas, not just solve some OP's problem. Bubach obviously was not aware of the effect of CLI/HLT on certain emulators, he is now.
Post Reply