Page 2 of 2

Re:OS Syatem reqirements

Posted: Sat Aug 21, 2004 11:29 am
by srg
I think in the end, I will use candy's invalid opcode method as it's much cleaner than anything else.

I will try to optimise it for catching the INVLPG instruction.

BTW Would be be best to write this in asm for maximim speed. (I know it own't hurt portability).

srg

Re:OS Syatem reqirements

Posted: Sat Aug 21, 2004 2:04 pm
by Candy
Don't attribute the method to me, I only heard it from somebody else, probably here even

Re:OS Syatem reqirements

Posted: Sat Aug 21, 2004 2:16 pm
by srg
Candy wrote: Don't attribute the method to me, I only heard it from somebody else, probably here even
Well I didn't quite mean that.

Anyway, would C be enough or would asm be better?

srg

Re:OS System requirements

Posted: Sun Aug 22, 2004 12:27 am
by Dreamsmith
srg wrote:BTW Dreamsmith, the machines you're talking about are embedded computers and that's the sort of thing that my Uni course is all about. The chip my Uni loves is the PIC16F877 wihich has 14336bytes of program memory, 368 of RAM and 256byte Data EEPROM (a bit small for your OS but the ATtiny15 has 512 words of flash for program and just it's 32 registers for variable storage), surely this is mor ethe sort of thing that what you listed would be using (I am still very much a noob at this though)?
Something like that, although a bit beefier. The latest design one of my clients was looking at (I'm afraid I don't recall the chip number) had the ability to download up to 64K of code on bootup across USB, storing it in local RAM and executing it there. Sure beats having to burn an EPROM every time you change something in the software. ;)

My hobby OS executes on standard PC hardware, so I don't have to be quite as constrained, but I try to keep the requirements in that range as much as possible, as I do sometimes pull code from such projects into my professional work.

Re:OS Syatem reqirements

Posted: Sun Aug 22, 2004 3:21 am
by Brendan
Hi,
srg wrote: Anyway, would C be enough or would asm be better?
I'm an assembly programmer, but in this case I'd say the overhead of the exception (and the effect of wiping the CPU's TLB) is going to have the most effect on performance (regardless of which language you use).

That said, even if you do use C you'll need to have some inline assembly to reload CR3. I guess if INVLPG is the only thing you intend using the invalid opcode handler for, then there's little point using C as it isn't capable of generating much of the code anyway.

I think this should be close to correct (untested):

Code: Select all

invalidOpcodeHandler:
    push eax
    push ebx

%define .oldEIP      [esp+12]
%define .oldEFLAGS   [esp+8]
%define .oldEAX      [esp+4]
%define .oldEBX      [esp]

    mov eax,.oldEIP
    cmp word [eax],0x0F01       ;INVLPG
    je .gotINVLPG

    ;Test for any other emulated instructions here

.isInvalid:

    ;Start critical error handler here???

    pop ebx
    pop eax
    iretd


.gotINVLPG:
    mov bl,[eax+2]             ;bl = MOD R/M byte
    mov eax,cr3
    mov cr3,eax
    cmp bl,0xC0                ;Is the MOD R/M byte sane?
    jae .isInvalid             ; no, return to invalid opcode handler
    cmp bl,0xBC                ;Is there a 32 bit displacement and SIB?
    je .disp32SIB              ; yes
    cmp bl,0x80                ;Is there a 32 bit displacement?
    jae .disp32                ; yes
    cmp bl,0x7C                ;Is there an 8 bit displacement and SIB?
    je .disp8SIB               ; yes
    cmp bl,0x40                ;Is there an 8 bit displacement?
    jae .disp8SIB              ; yes
    cmp bl,0x3D                ;Is there a 32 bit displacement (with no register)?
    je .disp32                 ; yes
    cmp bl,0x3C                ;Is there a SIB without displacement?
    je .SIB                    ; yes

    pop ebx
    pop eax
    iretd

.disp32SIB:
    add dword .oldEIP,8
    pop ebx
    pop eax
    iretd

.disp32:
    add dword .oldEIP,7
    jmp .do

.disp8SIB:
    add dword .oldEIP,5
    pop ebx
    pop eax
    iretd

.SIB:
    add dword .oldEIP,3
    pop ebx
    pop eax
    iretd

Cheers,

Brendan

Re:OS Syatem reqirements

Posted: Sun Aug 22, 2004 10:54 pm
by crc
I don't like OS's where the user is expected to compile the kernel before using it for best performance. It makes it hard for normal users (as opposed to programmers, system administrators) to install the OS. Also one of my goals is to have a single floppy disk which can be used to boot any supported computer with the absolute minimum of configuration required (for demonstration and installation purposes).
I get lucky here: my OS is written in assembly and Forth, so most of the drivers and applications are compiled on demand. It would be easy enough for me to add a couple of routines that scanned for known hardware and automatically compiled the drivers at boot time. Or drivers could be compiled/removed as needed.

For me, this eliminates most of the need for multiple kernels with different compile-time options. There's only a few exceptions that I see, and those are mainly for single task/preemptive multitasking or single/multi processor. Other than that pretty much everything can be compiled as needed.

Oh, and compiliation at boot or runtime won't waste much time in my OS. My compiler can compile a 200k source file in just over 4 seconds. All of my drivers don't even come close to 200k in size.

Re:OS Syatem reqirements

Posted: Mon Aug 23, 2004 12:44 am
by Legend
I would say, if you have really a lot of compilation options that you will have to configure (like in Linux), then the project (the linux kernel) got too big in my humble opinion ..

Re:OS Syatem reqirements

Posted: Mon Aug 23, 2004 1:01 am
by Candy
crc wrote: I get lucky here: my OS is written in assembly and Forth, so most of the drivers and applications are compiled on demand. It would be easy enough for me to add a couple of routines that scanned for known hardware and automatically compiled the drivers at boot time. Or drivers could be compiled/removed as needed.
Now that is quite the sickest idea I've ever heard. It also applies to AtlantisOS as I think about it, but it's still sick. That's the more extreme form of plug&play. The most extreme would be that the OS looks for some driver sources online, downloads them, compiles them, links them in the kernel at runtime, and gives you a note: your hardware is ready to be used.

Damn, good idea :)... Although I think buffering sources on the box is more expensive than buffering compiled drivers, and buffering the compiled ones is too expensive (look at Microsoft).
Oh, and compiliation at boot or runtime won't waste much time in my OS. My compiler can compile a 200k source file in just over 4 seconds. All of my drivers don't even come close to 200k in size.
On what sort of platform, and is it open source (IE: can I look at it without going to court with you)?

Re:OS Syatem reqirements

Posted: Mon Aug 23, 2004 1:26 am
by crc
Now that is quite the sickest idea I've ever heard. It also applies to AtlantisOS as I think about it, but it's still sick. That's the more extreme form of plug&play. The most extreme would be that the OS looks for some driver sources online, downloads them, compiles them, links them in the kernel at runtime, and gives you a note: your hardware is ready to be used.

d*mn, good idea ... Although I think buffering sources on the box is more expensive than buffering compiled drivers, and buffering the compiled ones is too expensive (look at Microsoft).
Whether it's good or bad depends on your point of view. I don't support anywhere near as many hardware devices as Linux or Windows, so I have much less code. I would never try to support everything, but compiling drivers as needed is nice.

I began work on the (unreleased at this point) hardware detection/compile on demand drivers due to incompatibilities across my testing hardware. I have some drivers at various levels (text, 320x200 VGA, 640x480 VESA / No mouse, PS/2, or serial mouse, etc) that are detected. If it finds hardware that it supports it will compile the drivers for it, otherwise it just uses a basic textmode interface.

I have no intention of having the kernel go online to fetch source code for drivers; that would be overly complex for the minor benefits it yields. I'll probably produce a PHP script that allows the users to set the drivers they want, and have it produce a custom kernel for them to download. The detect/compile stuff is more for those times that you don't know what hardware you will be encountering.
On what sort of platform, and is it open source (IE: can I look at it without going to court with you)?
The performance tests were done on the FreeBSD-hosted port, on a 600mhz PC with 256MB of RAM. The native version *should* be slightly faster since it isn't running alongside a bunch of other processes. And yes, it is open source. Goto http://www.retroforth.org/release and click on the 'Native' link. I'd do a hard link, but I tend to make new releases rather suddenly...

Re:OS Syatem reqirements

Posted: Fri Aug 27, 2004 4:48 am
by Legend
I think this whole discussion is very, very problematic.
Who says that algorithms that work fast on small data (or operating systems that run fast on small computers) will be superior on large data sets (larger, more complex applications and systems with more complex hardware), too?

Some things might be easy and work well there, but do they scale up well enough, too?

Re:OS Syatem reqirements

Posted: Fri Aug 27, 2004 5:20 am
by Solar
I probably get flogged for bringing it up again, but...

...IMNSHO, the best solution would be if hardware manufacturers could ship drivers for their hardware (like they do for Windows) and have those drivers work on any platform, regardless of CPU and / or operating system. Less work and an open competition for OS developers, too.

Yes, it is possible, and no, it isn't going to happen since the Free Software Foundation found evil lurking in the concept because it isn't "free" to the bone...

Re:OS Syatem reqirements

Posted: Fri Aug 27, 2004 5:26 am
by Legend
At least it is possible, yet I guess by some % speed loss, but okay, if you can utilize the hardware at all is better then being unable to use it ...

I saw that the Project UDI seem to be dated some years ago, are there any things that are outdated now? And how about creating some new form of Project UDI, this time not driven by some companies, instead by some OS developers?

Re:OS Syatem reqirements

Posted: Fri Aug 27, 2004 7:49 am
by Solar
Legend wrote: I saw that the Project UDI seem to be dated some years ago...
The concept is cut & dried, with little to nothing yet to be done. The "proof of concept" has been made using network cards and SCSI controlers IIRC, and USB had been in the making; none of this requires changing the concept of UDI, and extending to e.g. sound cards should be easily possible (claim of the UDI people).

So, no, UDI isn't "outdated".

However, the big push toward UDI had been made during the high time of the dot-com-era, and with the FSF so openly opposing them, I guess they saw the writing on the wall and didn't really push the subject.

Nothing keeps alternative OS developers like us here from adopting it, though, which would in the very least mean that we could exchange drivers among us.

I also heard rumors about an effort to bring UDI to Linux, after all, without the "ga" from the FSF.
And how about creating some new form of Project UDI, this time not driven by some companies, instead by some OS developers?
I don't think anything like "a new form of Project UDI" is required. The whitepapers are there, ready to implement, and the guys on the mailing lists are quick to respond if you post there, if a bit discouraged by so many "I'll use this!" with so little follow-up.

I have yet to hear anyone to claim it's broken, though, so I guess it's the usual 99% of projects dying before crossing the goalline.

There's even example code available at SourceForge. It's all for the taking.

And then there's SNAP, which is basically the same for graphics cards...