Page 1 of 1
Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 2:51 am
by serge2k
Hi
I'm trying to print in protected mode and it's behaving very strangely.
I just got my kernel to boot from grub, haven't done anything yet.
I'm following the C++ barebones, with the gaps filled in using the C barebones. SO I have the nasm loader.s on the C barebones with the loops for constructors added in.
This works:
mov [0xb8000], 0x07690748
in loader.s right before calling my kernel
*((int*)0xb8000)=0x07690748;
works in the kernel
this doesn't
unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[0] = 65; /* character 'A' */
videoram[1] = 0x07; /* forground, background color. */
this doesn't
for(int i = 0;i < 10; i++)
{
}
*((int*)0xb8000)=0x07690748;
this does
for(int i = 0;i < 10; i++)
{
*((int*)0xb8000)=0x07690748;
}
this prints high but then never prints the A
for(int i = 0;i < 10; i++)
{
*((int*)0xb8000)=0x07690748;
}
mov WORD [0xb8000], 0x0741
any ideas? is this normal, it seems like odd behaviour.
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 3:33 am
by gerryg400
Is your linker script okay?
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 4:00 am
by skyking
Also you should probably use volatile qualified pointers.
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 11:39 am
by xenos
Have you checked whether the compiler outputs what you expect?
Have you properly set up a stack? It seems that writing to the screen fails whenever you use stack variables (i, videoram).
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 12:27 pm
by serge2k
linker script
Code: Select all
ENTRY (loader)
SECTIONS
{
. = 0x100000;
.text ALIGN(4096) :
{
*(.text*)
*(.gnu.linkonce.t*)
}
.rodata ALIGN(4096) :
{
*(.rodata*)
*(.gnu.linkonce.r*)
}
.data ALIGN(4096) :
{
start_ctors = .;
*(.ctor*)
end_ctors = .;
start_dtors = .;
*(.dtor*)
end_dtors = .;
*(.data*)
*(.gnu.linkonce.d*)
}
.bss ALIGN(4096) :
{
*(.COMMON*)
*(.bss*)
*(.gnu.linkonce.b*)
}
/DISCARD/ :
{
*(.comment)
*(.eh_frame) /* You should discard this unless you're implementing runtime support for C++ exceptions. */
}
}
for the stack I did this (as in the barebones)
Code: Select all
; reserve initial kernel stack space
STACKSIZE equ 0x4000 ; that's 16k.
loader: ;entry point
mov esp, stack-STACKSIZE ;setup a stack
then at the bottom
section .bss
align 4
stack:
resb STACKSIZE ;reseve stack space
does the gui debugger for bochs work in windows or is that feature linux only? would it work in cygwin?
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 1:01 pm
by zity
First of all, you should take a look at the linker script here:
http://wiki.osdev.org/Bran%27s_Known_Bugs
Secondly, you have a bug in your stack code. You need to
add the stack size, not
subtract it..
Code: Select all
loader: ;entry point
mov esp, stack+STACKSIZE ;setup a stack
Remember, the stack grows downwards..
EDIT: I should probably be more specific about the linker script. You don't specify an output format and you don't specify any addresses in the linker script. These two things are shown in the script example I linked to. I'm not sure if that's whats coursing your problem, but your might look into it.
Re: Printing to the screen in protected mode
Posted: Fri Jul 30, 2010 1:24 pm
by serge2k
zity wrote:First of all, you should take a look at the linker script here:
http://wiki.osdev.org/Bran%27s_Known_Bugs
Secondly, you have a bug in your stack code. You need to
add the stack size, not
subtract it..
Code: Select all
loader: ;entry point
mov esp, stack+STACKSIZE ;setup a stack
Remember, the stack grows downwards..
EDIT: I should probably be more specific about the linker script. You don't specify an output format and you don't specify any addresses in the linker script. These two things are shown in the script example I linked to. I'm not sure if that's whats coursing your problem, but your might look into it.
Works now, thanks.
edit: to be clear, it was the stack issue.
one typo causes massive issues.