Page 1 of 1

Char[] only works inside function.

Posted: Sat Jan 08, 2011 1:59 pm
by binsky3333
Hi guys, im trying to get keyboard inout working. The IRQ works and everything my problem is that...

Code: Select all

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: Select all

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]);
    }
}

Re: Char[] only works inside function.

Posted: Sat Jan 08, 2011 3:24 pm
by xenos
Sounds like a linker problem. Could you post your linker script?

Re: Char[] only works inside function.

Posted: Sat Jan 08, 2011 3:57 pm
by binsky3333

Code: Select all

ENTRY (loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

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

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

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

Re: Char[] only works inside function.

Posted: Sat Jan 08, 2011 4:28 pm
by Tosi
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?

Re: Char[] only works inside function.

Posted: Sat Jan 08, 2011 4:40 pm
by binsky3333
It compiles, no errors or warnings. If its outside, the text doesn't display.

Re: Char[] only works inside function.

Posted: Sat Jan 08, 2011 5:32 pm
by neon
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?

Re: Char[] only works inside function.

Posted: Sun Jan 09, 2011 7:53 am
by Chandra
Can you give an example of outside one(which doesnt work) to make things more clear?

Re: Char[] only works inside function.

Posted: Tue Jan 11, 2011 8:15 am
by prasadjvv
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.

Re: Char[] only works inside function.

Posted: Wed Jan 12, 2011 1:19 pm
by jadam
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...