OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:07 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 1:59 pm 
Offline

Joined: Sat Jan 01, 2011 12:34 am
Posts: 14
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]);
    }
}


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 3:24 pm 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
Sounds like a linker problem. Could you post your linker script?

_________________
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 3:57 pm 
Offline

Joined: Sat Jan 01, 2011 12:34 am
Posts: 14
Code:
ENTRY (loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

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

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

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


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 4:28 pm 
Offline
Member
Member

Joined: Tue Jun 15, 2010 9:27 am
Posts: 255
Location: Flyover State, United States
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?

_________________
Getting_Started on the wiki
x86 technical information
Interrupt Jump Table
Real Programmers Don't Use Pascal
My open-source projects


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 4:40 pm 
Offline

Joined: Sat Jan 01, 2011 12:34 am
Posts: 14
It compiles, no errors or warnings. If its outside, the text doesn't display.


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sat Jan 08, 2011 5:32 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
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?

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Sun Jan 09, 2011 7:53 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
Can you give an example of outside one(which doesnt work) to make things more clear?

_________________
Programming is not about using a language to solve a problem, it's about using logic to find a solution !


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Tue Jan 11, 2011 8:15 am 
Offline

Joined: Thu Jan 06, 2011 9:48 am
Posts: 5
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.


Top
 Profile  
 
 Post subject: Re: Char[] only works inside function.
PostPosted: Wed Jan 12, 2011 1:19 pm 
Offline

Joined: Mon Dec 27, 2010 3:41 am
Posts: 4
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Amazonbot [bot], Bing [Bot], DotBot [Bot], mrjbom and 79 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group