Page 1 of 1
segment problem
Posted: Tue Mar 13, 2012 1:17 pm
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.
Re: segment problem
Posted: Tue Mar 13, 2012 1:28 pm
by Yoda
Why org 0?
BIOS loads boot sector to 7C00h.
Also, moving 0FFFFh into SP makes stack not word-aligned.
Re: segment problem
Posted: Tue Mar 13, 2012 1:45 pm
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.
Re: segment problem
Posted: Tue Mar 13, 2012 2:38 pm
by Yoda
How bootloader jumps to kernel? I.e. what is in CS register?
Re: segment problem
Posted: Thu Mar 15, 2012 9:29 am
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.
Re: segment problem
Posted: Thu Mar 15, 2012 9:59 am
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.
Re: segment problem
Posted: Thu Mar 15, 2012 10:36 am
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.
Re: segment problem
Posted: Thu Mar 15, 2012 10:41 am
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.
Re: segment problem
Posted: Thu Mar 15, 2012 10:47 am
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.
Re: segment problem
Posted: Thu Mar 15, 2012 1:23 pm
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.
Re: segment problem
Posted: Fri Mar 16, 2012 6:01 am
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.
Hey, guys, topicstarter probably solved his problem and left this topic. What is the reason to plow the sand after him?
Re: segment problem
Posted: Fri Mar 16, 2012 6:14 am
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.