woah! thaanks, guys!

i've already read into the portlist, but i didn't know that i have to wait for some bits to be cleared; i've just sent one byte after the other... as i already mentioned: easter holiday's comin! i'll dig myself into os-programming this time - i'll come up again when i'm done :), posting my results here.
one thing is still unclear: the port-list says

all commands except ECh and FFh are acknowledged by FAh (ACK) or FEh (Resend)

does that mean, i have to send 0xfa after sending a command? or after getting the data? or does the mouse send this byte and i have to fetch it?

i'm sure i'll attatch further questions withing my os-programming :)
Posted on 2003-04-08 13:27:10 by hartyl
The mouse sends this byte before sending the result of the command.
Posted on 2003-04-08 14:28:31 by Sephiroth3
So the Default of port 0x64 is reading keyboard value is not it ?
The value in my port 0x64 is 14, can someone explain it? what is A20 ?
Posted on 2003-04-08 20:51:41 by realvampire
A20 enables address line 20, and needless to say, you'd better set this bit.
When you read port 64, it returns a status. It has the following format:
76543210

x------- Parity error in last transferred byte
-x------ Time out
--x----- 0=Keyboard data returned 1=Mouse data returned
---x---- Computer unlocked
----x--- Set if port 64 was last written, clear if port 60 was written
-----x-- BIST completed
------x- Busy
-------x Data byte available


Therefore 14 means that the computer is not locked and that it has completed the power-up self test.
Posted on 2003-04-10 12:44:35 by Sephiroth3
re all!

i haven't had much time lately, but i tested your advice.
and here is what i've got out of this information:


;enable mouse port
mov bl,0xa8
call keybd_cmd
call keybd_read

mov bl,0x20
call keybd_cmd
call keybd_read

or al,0x02 ;enable mouse calling IRQ12
push ax
mov bl,0x60
call keybd_cmd
pop bx
call keybd_write ;write byte
mov bl,0xd4 ;cmd to mouse
call keybd_cmd
mov bl,0xf4 ;enable mouse
call keybd_write
call keybd_read

keybd_cmd:
xor ecx,ecx
mov cx,0xffff
@@:
in al,0x64
test al,0x02 ;bit1
jz @f ;wait until bit1 becomes clear
loop @b
ret
@@:
mov al,bl
out 0x64,al
ret

keybd_write:
xor ecx,ecx
mov cx,0xffff
@@:
in al,0x64
test al,0x02 ;bit1
jz @f ;wait until bit1 becomes clear
loop @b
ret
@@:
mov al,bl
out 0x60,al
ret

keybd_read:
xor ecx,ecx
mov cx,0xffff
@@:
in al,0x64
test al,0x01
jnz @f ;wait for bit0 to become set
loop @b
ret
@@:
in al,0x60
ret

as you might guess, this code doesn't work. and the following happens:
i can boot my code as usual. the keyboard interrupt does its part, the timer ticks and the os-task is running.
then i move the mouse (or click it):
everything keeps running (timer, os-task) but the keyboard interrupt doesn't react anymore when i hit a key. NO interrupt is being called by moving the mouse and i get no information from it (i.e. the data-packet)

so, does any1 know why this all happens? as you can see, something is going on, but what?
Posted on 2003-04-27 13:32:58 by hartyl
do you send a EOI?
Posted on 2003-04-27 14:01:51 by f0dder
Command 0xA8 doesn't return anything as far as I know.
What are commands 0x20 and 0x60 supposed to do?
Do you remember to set bit 2 of the output port and clear bit 7 when dealing with the mouse?
Posted on 2003-04-27 14:30:59 by Sephiroth3
Originally posted by f0dder
do you send a EOI?

yes i do. i initially thought the same, but i send eoi
but if i had forgotten it - where sould the IRQ0 come from?

Originally posted by Sephiroth3
Command 0xA8 doesn't return anything as far as I know.
What are commands 0x20 and 0x60 supposed to do?
Do you remember to set bit 2 of the output port and clear bit 7 when dealing with the mouse?


i had the problem. when i read this port after sending 0xa8 the system sometimes hung.
0x20 puts the statusbyte to port 0x60. when i read it i set the mouse-bit and write it with 0x60 to 0x60 (analog to cr0 when setting pe-bit)
nope, i didn't remember that. i just read port 0x64 to check wheather IRQ1 was called by mouse or by keyboard (i.e. what's the data for). this *could* solve the problem. i'll check when i have time (i guess that'll be wednesday)

i'll post the result here, when i've checked. but.. don't stop posting possible solutions...
Posted on 2003-04-27 15:49:37 by hartyl
humm humm. Next solution: study an existing keyboard handler to see what you might possibly do wrong. I can suggest looking at the one from Allegro (can't remember URL, but google - it's a graphics programming library mainly for DJGPP by... Shawn Hargraeves or summat). It's easy to follow.
Posted on 2003-04-27 15:55:41 by f0dder
Or you can study my OS source code :D

I have both PS/2 Mouse and keyboard working (aka drivers )

http://www.hostileencounter.com/sol_os/index.html


PS
---------
Well the PS/2 mouse **sometimes** (very rarely and only on one machine) is not initializad ok first try (but seccond try works) I will be very happy if somebody will have any ideaa why...but i will find it in time anyway
Posted on 2003-04-27 16:31:57 by BogdanOntanu
Bogdan, how about making a vesa1.1 emulation of vesa2 LFB in your "os"? It's not very hard when you have the pmode bank switching routines, if your kernel has paging up and running.
Posted on 2003-04-27 16:46:29 by f0dder
I am not using paging for my kernel yet... :D

Besides i do not know all bank switching routines for every video board out there ... but i will learn them.

LFB emulation via paging is not THAT much important for my OS

Because i do all GFX in a system back buffer and bank switch is only reguired when making the final copy to video ram (aka flip)...so simple swiching will actually work better... since copy is linear.

What i need for SOLAR OS right now is a dirty rectangle optimization and an clipper :D and a way to relocate bin code for each application.

I do not use segmentation neither...just plain flat memory model :D This is fast but has its consequences ...

But by all means... all feel free to implement paging and/or TSS task switching ...
Posted on 2003-04-27 20:27:35 by BogdanOntanu

I am not using paging for my kernel yet... :D

But you're doing a graphics mode and a windowing system? IMO, that's a wrong order if priorities. Don't tell me you're running everything ring0 too? ;)


Besides i do not know all bank switching routines for every video board out there ... but i will learn them.

I doubt you will learn all of them :-)
And why not use the vesa bank switching? Regular bank switching (requiring pm->rm or v86) should be in every version, the pmode entrypoints might only have been added in a later version and probably aren't on all cards, but with both bank switching and native LFB support, you should be covering all cards that are worth covering.


I do not use segmentation neither...just plain flat memory model :D This is fast but has its consequences ...

Good, segmentation is (imo) bad. At least on x86. It's useful to have FS point to a Thread Information Block like win32 does, but that's about it.
Posted on 2003-04-28 01:40:35 by f0dder
Do you have kernel for 32-bit set up? it mean your kernel set the prosesor to 32-bit mode load ds,es,fg etc. So I only have to made a exe and just running it?

On Pmode 8B C0 is mov eax,eax and mov ax,ax is 66 8B C0. So if I write 8B C0 in my prog it became mov eax,eax it self. Dont you understand?

I have your source, but it was too complex to understand. Seems I late following it. Can you guide me through, or at least made the masm Version so I can compile it and testing it.
Posted on 2003-04-28 07:38:33 by realvampire
@BogdanOntanu: i've already downloaded your os and wanted to test it. it loads successufully but when the kernel is started just yellow numbers on blue rectangles on black screen is displayed. normal?
i've also taken a look at your vesa-code, but not yet at the mouse&keyboard.

@all: i've just noticed that the problem with the mouse (as i explained in my last post) can't happen by wrongly reading the information - because NO interrupt is called. i.e. i don't even come to reading it, because nothing tells me to.
i haven't tested some further code yet, but i'll have time @ thursday (as i hope)
for further coding (the real system-code) i've switched back to textmode. i'll bother about vesa later... (mouse sould work first and i'll optimize my createtask-function)
Posted on 2003-04-28 12:55:58 by hartyl
To hartyl

No it is not normal,

See the screenshots on my web site for what is normal...maybe check requirements
One must have a Pentiun class CPU, and a VESA 2.0 compatible video board and at least 8M system RAM to run
it ... What version have you downloaded? I can walk you through if you so want either via emails or here ...or on a sepparate thread

To realvampire

Yes i have the cPU in 32bit protected mode GDT setups all memory as linear from 0 up to 4Gigabytes. Interupt are handled by the kernel. TO do applications see the sample one in sourcecode. Curently you must include application insides OS and compile as a whole (aka embeded style) Can not compile the application as an separated exe and run it from the OS... however that will be one of the next steeps in my OS evolution. Curently for embeded and/or testing works ok as it is.

Source cod etoo complex... hmmm i can guide anybody thru it...i tried to make as easy to understand and as much comments (some funny) as i could.

An advice do not focus too much on things you can not understand yet... ove on and try to get the big picture...where every part fits and stuff...why do i do that and other etc etc.

Yes i understand about 66h prefixes... in my os (system32 part) you can freely code in 32 bits no prefix is needed unles you use 16 bit operations of course :D

I will try to make a MASM version of it, cand promise when... i guess a FASM version will be faster..i still wonder how to make MASM generate absolute binary code (maybe Jloc will handle this)

As i said before i can guide anybody into my OS or just plain OS makeing... if you have the time to wait for my answers that are not always fast :)


the more complictated answer to f0dder in a sepparated message
Posted on 2003-04-28 13:49:21 by BogdanOntanu
to f0dder

For a start let me say that my oppinions are very different compared to other "standard" OS theory


But you're doing a graphics mode and a windowing system? IMO, that's a wrong order if priorities. Don't tell me you're running everything ring0 too?


YES i am :D

All OS runs in flat memory mode 0...4G and all is Ring0 code :) I like it this way

I consider all this "protection" scheme an stupid fuzz... who are we protecting against?

-Why sould i trash cache at every arbitrary task switch?
-Why loose CPU resources and time checking every instruction ? It should be checked at design time not at run time!
-Why make costly jumps from ring3 to ring0 at every system function call?

Against badly and poorly written applications of course, and by doing so we are waisting everybody's time and resources evry day and every seccond... just because we are afraid that the program will crash... LOL

IF it crashes then the programmer needs to redo its work...
IF it is NOT THEN we are doing all check for NOTHING.

Of course things are not the same while developing an program ...

SO I choose to let the one that write programms and/or developers to use protection WHILE they are testing only... but at run time every application must be bug free... :D eventualy source code also

The fuzz about protection makes easy for programmers to develop buggy applications and still release them on the market :P

Well i know you and/or they are not going to like this so i will ALLOW for standard protection schemes ring0/ring2/syscall/pagins ..etc...i will even implement them better .

But myself feel that i have no need for them and since i make my own OS... i implemented my way first

I also think GUI is an important part of OS nowdays and i think that the only way of knowing how to do a thing is by actually doing it... "thinking about walking the path too much is not the same as walking the path"..

I know that ONLY walking the path will show me what i need to do... so i try to implement as many aspects of an OS prettu fast to gain experience on what i need to do next

To conclude: that was the exact best way and order in doing things for my OS ...


I doubt you will learn all of them :-)
And why not use the vesa bank switching? Regular bank switching (requiring pm->rm or v86) should be in every version, the pmode entrypoints might only have been added in a later version and probably aren't on all cards, but with both bank switching and native LFB support, you should be covering all cards that are worth covering.


Well yeah maybe i will not learn them all...

But surely if anybody NEEDS something added to this OS it is free to do it. If it sends it back to me i will eventualy include it in the next release :)

I do not want to use V86 mode also... i might have to ... for you are indeed right: i could use BIOS in V86 mode to do standard VESA 1.2 bank switching to almost all known video boards.. that crossed my mind. As i migh need it for APM also...

I will see... maybe i will just return briefly to real mode as V2 OS once did :P



Good, segmentation is (imo) bad. At least on x86.
It's useful to have FS point to a Thread Information Block like win32 does, but that's about it.


Nah IMHO segmentation si good but i am a different kind of person remember...?

I consider segmentation the only real advancement in CPU theory i have seen in years...
While paging is evil and stupid year 1965 technology.

But as you say because so many people used paging before on huge computers they liked it so much... arghhh

IF i ever have had to choose between segmentation and paging i would surely choose segmentation.
But i guess one for my heart an done for "popular" demands: i will have to implement BOTH
Posted on 2003-04-28 14:18:54 by BogdanOntanu
Who are we protecting against? Humans. Humans != perfect. Once you find a way to do 100% coverage automated program testing, for all kinds of applications, then ring0 might be viable. I still doubt there's much (if anything) to be gained from ring0 vs. ring3 - at least if you take into account the benefits of full protection.


Why sould i trash cache at every arbitrary task switch?

If you're so worried about that, design your scheduler properly. For the few apps that _really_ require it (and no, this doesn't include games), you can always boost to realtime priority. Hell, you can get "almost realtime" on NT.


Why loose CPU resources and time checking every instruction ? It should be checked at design time not at run time!

100% test coverage? I doubt that. ring0 is too dangerous for a broad range of applications. While it's possible to remove a great many bugs by good design, we all know that bugs _always_ show up runtime. Besides, do you have any timing evidence that ring3 slows down matters all that much?


Why make costly jumps from ring3 to ring0 at every system function call?

Design the API decently, and a great many transitions can be saved. I don't really care about losing a few percent speed in return of having a stable + secure system. A pmmx-200 is enough for running NT4 smoothly...


I will see... maybe i will just return briefly to real mode as V2 OS once did :P

Ick :). What about using the 32bit pmode bank switching routines? I can't remember which vesa version specifies them, but I think it's before vesa2.

How come you would chose segmentation over paging? But oh well, you probably wont do OS support for virtual memory nor have separate process spaces, so I guess you don't have to answer that question.

It's nice that you're playing around and all, but if you think you're building an "OS" you're delusional :) - this is at best a toy kernel with some pretty wrong assumptions.
Posted on 2003-04-28 14:37:27 by f0dder

I will try to make a MASM version of it, cand promise when... i guess a FASM version will be faster..i still wonder how to make MASM generate absolute binary code (maybe Jloc will handle this)

Are you talking about making a MASM version of you OS, isn't that illegal?
As for a fasm version, that would be realy nice. :) (If I had time I would have voulontered to help translating it).

Sementation or Paging, excatly what differs, which is the "best"? What is the key-feature differences between paging and segementation? Limits/Possibilities?
Haven't read that much on paging (not enougth time and haven't found any simple docs on it), looks like alot of extra reading , how can that time be "justified"? (f0dder, you seem to understand paging in and out, please enlighten me)
Posted on 2003-04-28 14:52:55 by scientica

Are you talking about making a MASM version of you OS, isn't that illegal?

If it's the masm from masm32 (or rather, from the windows DDK), then yes. If you have purchased masm, it should be legal I guess.

Segmentation, paging... well, with segmentation you have "segments" of any size floating around just about anywhere. Swapping out segments != fun.

Paging is fixed-size (4k on "regular x86", though there's 2meg and 4meg page size extensions). Great thing about them, apart from being fixed size, is there's built-in translation hardware all the way since 386, making them rather fast (I haven't timed the overhead of paging, but when a pmmx-200 can run NT4 fluidly with all the ring3, paging, task switching, TONS of r3<>r0 context switches, ansi<>unicode conversions, security checks... and do that fluidly... honestly, I don't care much).

Paging is what makes it possible to have two apps run at address 0x400000 - they have separate address spaces. Something like this is also possible with segments, you have the "floating" model then (which makes absolute memory refs somewhat awful).

Paging makes memory mapping (files, IO) possible.

Paging, because of fixed size and native CPU support, is easy to handle when doing virtual memory / OS paging.

Of course bogdan will claim that VM is bad, that apps should handle VM themselves if they need it, that all the protection is slow and unnecessary etc.
Posted on 2003-04-28 15:01:33 by f0dder