Getting user input from meaty Skeleton

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Getting user input from meaty Skeleton

Post by JulienDarc »

Hello,

I may ask some stupid question, but please bear with me, I am just beginning.

Under Linux, when I have to deal with old assembly to wait for user input (which doesn't happen that much), I do :

Code: Select all

    __asm__("loop:\n\t"
            "movl $3, %%eax\n\t"
            "movl $1, %%ebx\n\t"
            "movl (%[buffer]), %%edx\n\t"
            "int $0x80"
            :
            : [buffer]"g"(buffer)
            : "rax","rbx","rcx","memory"
    );
Now, I started with the meaty skeleton scripts. I compiled and used qemu-system-i386 -kernel myos.bin.

It starts correctly. Fine.

I tried to put some user interaction, but the screen keeps flickering with the bios inscriptions (booting from rom.. ).
I am doing it wrong.
I used the code I found in the keyboard interrupt wiki section, translated it to at&t syntax and put it in the kernel_main like so:

Code: Select all

void kernel_main( void ) {

        printf( "Hello, kernel World!\n" );
        printf( "prompt\n" );

        __asm__("push %%eax\n\t"
                         "in $0x60 ,%%al\n\t"
                         "mov $0x20, %%al\n\t"
                         "out %%al, $0x20 \n\t"
                         "pop %%eax\n\t"
                         "iret"
                    :
                    :
                    : "al"
            );
}
But :
1) I am sure that at that point, I am still in real mode (I didn't set any gdt or family up yet). The Bios should catch the keyboard input.
2) If I take "iret" out (not returning from the interrupt properly), the code doesn't care and finish as if this section was non existent.
3) Maybe I set the wrong interrupts or cannot put that in kernel_main or worst, my asm code is nonsense in this context..

Could you please give me a hint ?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Getting user input from meaty Skeleton

Post by sortie »

I'm really tired right now, but some quick comments: You don't seem to know what you're doing. That's a bad sign. You need to truly know your tools, code and the hardware - everything - to succeed at osdev. Don't randomly combine tutorials without true comprehension. That's just quick observations that might not be the true case here, only a quick look.

A more serious remark, inline assembly is useful but it must be used with precision. Your use here doesn't show the proper levels of caution that you must use to use it well. It's surprisingly hard to use correct. I very much suggest you only use inline assembly written by experts that has been community verified, at least until you are established and read the proper documentation about it and understand the dangers. I truly recommend you just do regular assembly files with functions instead of inline assembly. There's no optimizer that you can lie to inadvertently, so the assembly actually does what you intend and don't corrupt the surrounding code if you follow the calling conventions.

I have no idea why you iret. This is not an interrupt handler. It's a kernel main function. This doesn't make sense.

You forgot to read my post in the other thread and the bare bones tutorial. Multiboot loads you into 32-bit protected mode with paging disabled.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Getting user input from meaty Skeleton

Post by iansjack »

As Sortie says, you are in protected mode, so can't use BIOS calls. In any case, the code that you used from Linux doesn't use the BIOS, it makes a Linux system call. You're not in Linux, so you can't use system calls (until you have written your own). And you can't just randomly take code from an interrupt routine and stick it into a normal function then expect it to work.

I think you need to do a lot more reading before trying to progress further, particularly the Intel Programmer's Manuals. I'm not convinced that you understand how the processor works, how interrupts work, etc. If you really want to see how an OS works you could study the code in the course I linked to in another post. It presents an OS that is simple enough to understand, but complete enough to show most of the essentials. You won't understand any of it at first, but the more you read the more you will get it.

I'm afraid this just demonstrates the problems with online tutorials; they are always going to be too limited to be of much value but they tempt people to cut and paste code without understanding it. OS development is not easy and there's no substitute for reading.
User avatar
bace
Member
Member
Posts: 34
Joined: Fri Jan 16, 2015 10:41 am
Location: United Kingdom

Re: Getting user input from meaty Skeleton

Post by bace »

If you're trying to wait for the user to press a key, you can't just read from this IO port. This returns the value in the keyboard's buffer, not waits until the user presses a key and then returns it (AFAIK). You can get and interrupt when a key is pressed/released, but you'll probably want to write a memory manager, an (A)PIC driver, and setup an IDT first.

And, as the others have said, it really does not look like you have any idea what you're doing. :(
"for example, turning off the system’s power through the movement of a large red switch" - the Advanced Configuration and Power Interface Specification
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Getting user input from meaty Skeleton

Post by JulienDarc »

:cry: You are all right, i fear.

I am sorry mates. I missed the disabled paging protected mode.
The inline asm works fine, but I agree, it is hacky. i actually don't write the registers %% but let gcc decide with input/output operands, but i wanted to show about the logic.

Will do some reading.

See you soon :)

And thanks for your time
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Getting user input from meaty Skeleton

Post by JulienDarc »

The Mit course about the xv6 is very helping.

I need to start over. That is the first key.

Thanks for your good advices, you helped a lot. A lot. :wink:
ExeTwezz
Member
Member
Posts: 104
Joined: Sun Sep 21, 2014 7:16 am
Libera.chat IRC: exetwezz

Re: Getting user input from meaty Skeleton

Post by ExeTwezz »

Hello,

You can try reading Andrew Tanenbaum's books:
  • Modern Operating Systems
  • Operating Systems. Design and Implementation
The first one is only theory about how operating systems work, what they use and what they do.
The second one is similar to the first one, but includes practice (explains how does MINIX 3 work and its source code).
Last edited by Combuster on Wed Mar 11, 2015 9:28 am, edited 1 time in total.
Reason: illegal content removed
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Getting user input from meaty Skeleton

Post by Roman »

Combuster wrote:illegal content removed
Unfortunately, a lot of people in Russia don't care about copyrights.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Getting user input from meaty Skeleton

Post by Candy »

Roman wrote:
Combuster wrote:illegal content removed
Unfortunately, a lot of people in Russia don't care about copyrights.
This forum is not in Russia.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Getting user input from meaty Skeleton

Post by Roman »

Candy wrote:
Roman wrote:
Combuster wrote:illegal content removed
Unfortunately, a lot of people in Russia don't care about copyrights.
This forum is not in Russia.
I was talking about ExeTwezz.
ExeTwezz's GitHub page wrote:Syktyvkar, Russia
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Getting user input from meaty Skeleton

Post by JulienDarc »

Thanks for the new pointers.
I read it a bit and it seems very well explained !

Thanks a lot !
Post Reply