OSDev.org
https://forum.osdev.org/

Char[] only works inside function.
https://forum.osdev.org/viewtopic.php?f=1&t=22971
Page 1 of 1

Author:  binsky3333 [ Sat Jan 08, 2011 1:59 pm ]
Post subject:  Char[] only works inside function.

Hi guys, im trying to get keyboard inout working. The IRQ works and everything my problem is that...

Code:
unsigned char kbdus[128] =
{
    0,  0, '1', '2', '3', '4', '5', '6', '7', '8',   /* 9 */
  '9', '0', '-', '=', '\b',   /* Backspace */
  '\t',         /* Tab */
  'q', 'w', 'e', 'r',   /* 19 */
  't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',   /* Enter key */
    0,         /* 29   - Control */
  'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',   /* 39 */
'\'', '`',   0,      /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n',         /* 49 */
  'm', ',', '.', '/',   0,            /* Right shift */
  '*',
    0,   /* Alt */
  ' ',   /* Space bar */
    0,   /* Caps lock */
    0,   /* 59 - F1 key ... > */
    0,   0,   0,   0,   0,   0,   0,   0,
    0,   /* < ... F10 */
    0,   /* 69 - Num lock*/
    0,   /* Scroll Lock */
    0,   /* Home key */
    0,   /* Up Arrow */
    0,   /* Page Up */
  '-',
    0,   /* Left Arrow */
    0,
    0,   /* Right Arrow */
  '+',
    0,   /* 79 - End key*/
    0,   /* Down Arrow */
    0,   /* Page Down */
    0,   /* Insert Key */
    0,   /* Delete Key */
    0,   0,   0,
    0,   /* F11 Key */
    0,   /* F12 Key */
    0,   /* All other keys are undefined */
};


Only works when it is inside the function:

Code:
void keyboard_handler(struct regs *r)
{
    unsigned char scancode;

    /* Read from the keyboard's data buffer */
    scancode = inportb(0x60);

    /* If the top bit of the byte we read from the keyboard is
    *  set, that means that a key has just been released */
    if (scancode & 0x80)
    {
        /* You can use this one to see if the user released the
        *  shift, alt, or control keys... */
    }
    else
    {
        print_character(kbdus[scancode]);
    }
}

Author:  XenOS [ Sat Jan 08, 2011 3:24 pm ]
Post subject:  Re: Char[] only works inside function.

Sounds like a linker problem. Could you post your linker script?

Author:  binsky3333 [ Sat Jan 08, 2011 3:57 pm ]
Post subject:  Re: Char[] only works inside function.

Code:
ENTRY (loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

Author:  Tosi [ Sat Jan 08, 2011 4:28 pm ]
Post subject:  Re: Char[] only works inside function.

What do you mean that it "only works" inside the function?
What compiler/linker errors does it give you if it's outside of that?
If it compiles fine, what happens when you try to run it?

Author:  binsky3333 [ Sat Jan 08, 2011 4:40 pm ]
Post subject:  Re: Char[] only works inside function.

It compiles, no errors or warnings. If its outside, the text doesn't display.

Author:  neon [ Sat Jan 08, 2011 5:32 pm ]
Post subject:  Re: Char[] only works inside function.

Hello,

What bootloader are you using? What debugging steps have you already performed? Have you verified that your .bss section is where its expected to be?

Author:  Chandra [ Sun Jan 09, 2011 7:53 am ]
Post subject:  Re: Char[] only works inside function.

Can you give an example of outside one(which doesnt work) to make things more clear?

Author:  prasadjvv [ Tue Jan 11, 2011 8:15 am ]
Post subject:  Re: Char[] only works inside function.

There are chances for the interrupt service routine to change the DS (data segment) register.
if you keep kbdus[] as global variable, contents of DS register might be different in your interrupt handler compared to the original so that it accesses wrong address (because of segment address) for your variable kbdus.

If you are sure that the DS register contains the same contents as the original in your interrupt handler, no need to bother about this.

Author:  jadam [ Wed Jan 12, 2011 1:19 pm ]
Post subject:  Re: Char[] only works inside function.

binsky3333 wrote:
It compiles, no errors or warnings. If its outside, the text doesn't display.

Just a guess, but it can't be that you load too few sectors to memory and the end of your binary image is not present? I had similar issue around the keyboard handler and I had to increase the number of sectors loaded by the bootloader... Maybe if you reposition your kbdus[] into a function something else is not loaded if it is really the problem what I think of...

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/