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.
Printing to the screen in protected mode
Re: Printing to the screen in protected mode
Is your linker script okay?
If a trainstation is where trains stop, what is a workstation ?
Re: Printing to the screen in protected mode
Also you should probably use volatile qualified pointers.
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Printing to the screen in protected mode
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).
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
linker script
for the stack I did this (as in the barebones)
does the gui debugger for bochs work in windows or is that feature linux only? would it work in cygwin?
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. */
}
}
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
Re: Printing to the screen in protected mode
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..
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.
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
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
Works now, thanks.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..
Remember, the stack grows downwards..Code: Select all
loader: ;entry point mov esp, stack+STACKSIZE ;setup a stack
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.
edit: to be clear, it was the stack issue.
one typo causes massive issues.