Qbasicnews.com

Full Version: Vema
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
okay, now it's clarified. but i have to comment on that.

Code:
' Virtual console driver read
sub consoleRead(length as integer, buffer$)
   'Do the low level handling of key_up and key_down here
   'and then put the resulting string in the buffer.
   'The buffer could be returned to the user process by sending
   'another message, or putting the buffer somewhere in memory
   'and having a pointer returned (via a register or the stack in
   'the VM) to the user-process.
end sub

in this example, your "driver" is part of the os really, hardcoded. it's not a driver... it's just another sub in my "os", which can be addressed with a special message. but i can think of a vm equivilent:

Code:
; this is the "console driver".
; the owner-id is subsituted for THISAPP when app is loaded

GLOBAL chr

; trap that eats MSG_CONSOLE_READ
; info1 = length
; info2 = return buffer (created by caller)

Trap vddConsoleRead: MSG_VDD_CONSOLEREAD To THISAPP By NA (NA, NA, NA, NA)
    NEWINT c
    NEWSTR chr        ; create GLOBAL chr here

    SETINT c, 0
    SETSTR INFO2, ""

    ENABLE vddConsoleReadHelper

    redo:
        SUSPEND vddConsoleRead
        CMPSTR chr, "\n"
        BNE redo
        CONCAT INFO2, chr
        INCINT c
        CMPINT c, INFO1
        BL redo

    DISABLE vddConsoleReadHelper
    DELSTR chr
    LEAVE
End Trap



; hook that eats MSG_SYS_KEYPRESS (system message)
; info1 = scan code (sent by the keyboard handler)
; info2, 3, 4 = N/A

Hook vddConsoleReadHelper: MSG_SYS_KEYPRESS By SYSTEM To (NA, NA, NA, NA)
    CMPINT INFO1, 16
    BE L16

    CMPINT INFO1, 17
    BE L17

    CMPINT INFO1, 18
    BE L18

    ;...

    CMPINT INFO1, 28
    BE L28

    ; rest of scan codes
    ;--------------

    L16:
    SETCHR chr, "Q"
    GOTO endofhook

    L17:
    SETCHR chr, "W"
    GOTO endofhook

    L18:
    SETCHR chr, "E"
    GOTO endofhook

    ; ...
    L18:
    SETCHR chr, "\n"
    GOTO endofhook

    ; rest of ASCIIs
    ;--------------

    endofhook:
    RESUME vddConsoleRead
End Hook


now i'll explain the algorithm a little -- vddConsoleRead is the trap that accepts app-requests. of course we need some driver-initializer, but that's not important to show for this example. anyway, once vddConsoleRead is activated, it initializes itself, enables a dormant hook (vddConsoleReadHelper) and suspends itself. now that the hook is enabled, it will trap keypress messages, digest them and spew out the equivilent ASCII char. when it returns, it resumes vddConsoleRead. notice that the hook does not LEAVE. LEAVEing is required only to resume the suspended caller of a trap. since the hook is called by the system directly, and because it RESUMEs vddConsoleRead manually, we do no need a LEAVE here.

vddConsoleRead will now continue after the SUSPEND instruction. if the char read is newline, or if the buf-length is greater than the allowed, it will exit the loop; otherwise, it will reiterate. when the loop exits, vddConsoleRead will disable the helper hook, so that system messages are processed normally. it releases chr, because it is no longer used. on the other hand, it does not release buf, because it holds the returned string. the program that requested vddConsoleRead should release it.

i'm still not done designing this language. for example, RETURN-MESSAGES would be more efficient than traps. for example:

;; get username
NEWSTR txt1, "Enter username: "
NEWSTR txt2, "Welcome "
SEND MSG_SYS_DISPLAY To SYSTEM (txt1, NA, NA, NA)
SEND MSG_VDD_CONSOLEREAD To DRIVERAPP (txt1, NA, NA, NA)
SEND MSG_SYS_DISPLAY To SYSTEM (txt2, NA, NA, NA)
SEND MSG_SYS_DISPLAY To SYSTEM (txt1, NA, NA, NA)
DELSTR txt

since the read buffer is returned to txt1, we dont need any messages here. but mathematical functions, for instance, return a value. so instead of passing variables, a special RETURN instruction can be made to send a message, leave the trap, and store the message in local variables, rather than on the queue (for instance, RET_INFO1, RET_INFO2, RET_INFO3, and RET_INFO4 - just like INFO1, INFO2, INFO3, and INFO4 store the trapped message)

Quote:The exec system call is used to execute a new process
well, in my "os" there's a VMI_LOADAPP instruction, which loads an app from file. as for forking or spawning (the windows term), that is harder, because i'll need to duplicate all of the owner's traps (because traps trap messages sent to a specific owner usually).

Quote:Im currently doing a research/coding project for my University to make Solaris MINIX portable to other operating systems and architectures. Solaris MINIX is a real operating system that is hosted as a single process on top of Solaris. Each process is a real execuatable and runs directly on the CPU and the kernel swaps them in and out using ucontext structures. Signals are used to simulate interrupts and all of the device drivers have been replaced with virtual ones which make system calls to the host. Im not sure that system crashes would be impossible, you still need to interface with the host, so theoritically you could do something wrong and bring it down, of course it is a much more stable way to develop operating systems, which is why Hosted-Linux exists.

hosted linux sounds interesting... and since i have redhat on my other partition... were can i get hosted linux? although i'm guessing this method is good for development, but you couldnt make a bootup this way. anyway. what are you researching by it?

Quote:Your implementation is very accurate though.
nice to know. you see, i didnt take computers at school, i took chem... because i used to like chem, and because what they teach i hate (pascal as an intro, and then two years of prolog - yuch!!). so i havent learned all the things and terms, and how they are implemented. instead i read about it, and mostly reinvent it myself.






[Flexibal>
Quote:in this example, your "driver" is part of the os really, hardcoded. it's not a driver... it's just another sub in my "os", which can be addressed with a special message. but i can think of a vm equivilent:

This is the simplest case for drviers. MINIX for example has all its drivers as part of the kernel source, when the kernel starts up it sets up a kernel task for each of the drivers. The drivers all have a wait loop, which waits for a message to be sent and then calls the approiate functions.

Code:
...
while (TRUE) {
        /* Handle any events on any of the ttys. */
        for (tp = FIRST_TTY; tp < END_TTY; tp++) {
                if (tp->tty_events) handle_events(tp);
        }

        /* Receive a message */
        receive(ANY, &tty_mess);
...
/* Execute the requested function. */
        switch (tty_mess.m_type) {
            case DEV_READ:      do_read(tp, &tty_mess);         break;
            case DEV_WRITE:     do_write(tp, &tty_mess);        break;
            case DEV_IOCTL:     do_ioctl(tp, &tty_mess);        break;
            case DEV_OPEN:      do_open(tp, &tty_mess);         break;
            case DEV_CLOSE:     do_close(tp, &tty_mess);        break;
            case CANCEL:        do_cancel(tp, &tty_mess);       break;
            default:            tty_reply(TASK_REPLY, tty_mess.m_source,
                                                tty_mess.PROC_NR, EINVAL);
        }
...

If you are going to write your drivers to run on the VM you may want to have a protected/supervisor mode for kernel VM code. You dont want your user-mode programs to be able to intercept messages or perform functions that should be handled by the kernel.

Quote:hosted linux sounds interesting... and since i have redhat on my other partition... were can i get hosted linux? although i'm guessing this method is good for development, but you couldnt make a bootup this way. anyway. what are you researching by it?

User mode Linux is available hee: http://user-mode-linux.sourceforge.net/
I think it comes as a set of diffs to the kernel source, so you will need that installed, check /usr/src/linux.
Im doing research with Solaris MINIX(SMX) to make it portable to any conforming POSIX system. All of the current hosted operating systems use OS specific tricks.
Pages: 1 2