I had a really really strange something today. I wrote my keyboard-read-key code about 2 weeks ago and today I used it again. It was working, but it is not working now.
The only modification was I did recompiling gcc with --with-newlib because I forgot it before. I returned back to old compiler, but problem is still persist.
It should work, but it is not working now.
Code: Select all
char keyboard_getchar()
{
while (!(inb(0x64) & 0x1));
unsigned char scancode = inb(0x60);
if (scancode & 0x80) keyboard_getchar();
char chr = key_list[scancode];
terminal_putchar(chr);
return chr;
}
Surprisingly, it works if I make it:
Code: Select all
char keyboard_getchar()
{
X:
while (!(inb(0x64) & 0x1));
unsigned char scancode = inb(0x60);
if (scancode & 0x80) goto X;
char chr = key_list[scancode];
terminal_putchar(chr);
return chr;
}
That problem is really strange for me. Also I have another now-not-working code, too.
Newlib was handling backspace itself great, but now it is not handling it, too.
Code: Select all
void rw_test()
{
char *str = malloc(50);
printf("Enter some string: ");
gets(str);
printf("The string you entered: %s\n", str);
if (!strncmp("abcdef", str, 6))
{
printf("You entered abcdef, yay!");
}
}
In that code if I send an output to newlib like xyz\b\b\babcdef;
It results with str[0] is x, str[1] is y, str[2] is z, str[3] is \b, str[4] is \b, str[5] is \b, str[6] is a, str[7] is b, str[8] is c, ...
printf prints the correct text, abcdef (surprisingly), but strncmp or strcmp says strings are not same. I'm sure it was working before.
That is my read syscall:
Code: Select all
int read(int file, char *ptr, int len) {
if (file == 1) {
*ptr = keyboard_getchar();
return 1;
}
else
{
return -1; //Until fixing that problem I won't add VFS read code
}
}
Help please
GCC version 6.2.0, Binutils version 2.27, Newlib version 2.2.0-1
Why it is happening?