Você está na página 1de 35

Department of Computer Science and Engineering, University Institute of Engineering and Technology, Chhatrapati Sahu Ji Maharaj University

Managed Code Toy OS


B. Tech Minor Project Report
Adhokshaj Mishra (29021)

Page 2 of 35

Managed Code Toy OS


Project Report Submitted in Partial Fulfillment of The Requirements for the Degree of

Bachelor of Technology In Computer Science and Engineering By

Adhokshaj Mishra (Roll No. 29021)

Department of Computer Science and Engineering University Institute of Engineering and Technology, CSJM University Kanpur

Page 3 of 35

Acknowledgement
I wish to express my deep sense of gratitude to my guide, Dr. Amit Anil Sohara, Head of R&D Wing, Global Artificial Solutions for his able guidance and useful suggestions, which helped me in completing the project work, in time. Words are inadequate in offering my thanks to the Project Assistants, G.A.S. for their encouragement and cooperation in carrying out the project work. Finally, yet importantly, I would like to express my heartfelt thanks to my beloved parents for their blessings, my friends for their help and wishes for the successful completion of this project.

Adhokshaj Mishra Department of Computer Science and Engineering, University Institute of Engineering and Technology, CSJM University Kanpur

Page 4 of 35

Table of Contents
oAbstract5 oChapter 1: Introduction..6 oChapter 2: Interfacing PS/2 Pointing Device.8 oChapter 3: Virtual File System.15 oChapter 4: Graphical User Interface.21 oResult and Snapshots27 oAppendix A: PS/2 Commands..30

Page 5 of 35

Abstract
From the development of general purpose computers, software industry has also evolved. However, there is not much improvement in OS development, as compared with other fields of software world: while other fields are enjoying power of garbage collection, OS developers are still doing their job in classic languages like C, C++ and assembly. Although there has been some research work regarding this, none of them was successful. This project is an attempt to develop a toy OS in pure managed code, particularly C# and .NET Framework 4.0.

Page 6 of 35

Chapter1: Introduction
In whole history of computers, operating systems are most challenging and complex piece of software ever developed. Despite the complexity, very little efforts are made to make whole OS designing process easier, and as a result, operating systems are still developed in C, C++ and assembly language. Although modern languages like C# have made software development process much easier, they cant be directly used for OS development due to the fact they are compiled to intermediate language (Byte-code or IL), instead of machine language for underlying architecture. Since development of GC1 based languages, various efforts have been made to harness the power of GC in OS development lifecycle. Some notable efforts in this direction are as follows:

Java OS
Java OS was the first attempt to develop an OS purely in managed code (Java in particular). It was announced by Sun Microsystems in 1996, and was claimed to run in anything from net computers to pagers. In 1998, IBM was hired to accelerate the project. The end of project was declared in 1999 by both companies, and was declared a legacy system in early 2003.

Singularity
Singularity is an experimental OS by Microsoft Research started in 2003. It was designed as a highly-dependable OS in which the kernel, device drivers, and applications are all written in managed code (C# in particular). However, C/C++ code has been used2 for executing managed code. This project was closed in 2010 and released in public domain under restricted licensing terms.
1 2

Garbage collection based languages like JAVA and C#. These languages provide automatic memory management. Source code is available at http://singularity.codeplex.com/SourceControl/changeset/view/45126

Page 7 of 35

MOSA
Managed Operating System Alliance (MOSA3) is an open source OS development tool-chain by developers mainly from USA, Germany and Netherlands. This project provides command line tools to compiled managed libraries (.NET Framework) to native code, boot loader configuration, ISO image generation etc.

COSMOS Framework
COSMOS (C# Open Source Managed Operating System) Project provides a framework and tool-chain to develop an OS purely in managed code (C# and VB .NET). Cosmos supports integration with Visual Studio, and therefore is much easier to use. However, the framework is not rich, and therefore, there is still a lot of work to be done on OS developer side (E.g., it does not support mouse, file system etc). In this project, a microkernel4 based OS is developed using COSMOS framework for x865 based computer systems. This project demonstrates device driver (PS/2 pointing device), and a GUI system.

3 4

http://www.mosa-project.org/ In microkernel architecture, 5 COSMOSE does not support x64 architecture yet.

Page 8 of 35

Chapter 2: Interfacing PS/2 Pointing Device


Pointing devices (mouse or touch-pad) play a key role in user interaction with GUI. They provide point-and-click mechanism to eliminate use of keyboard for a large number of tasks. However, to make them work in a computer, we need special software to communicate with the device. This special software is known as device driver, as it drives the hardware properly. Operating system interacts with the driver, and all the low level communication is handled by the driver.

System Architecture

Page 9 of 35

Pointing devices are connected via two6 bi-directional tri-state lines: Port60 and Port64. Port64 is used for signal7 traffic, and Port60 is used for data traffic. Since Cosmos allows direct manipulation of these ports, writing a basic driver is fairly simple, provided PS/2 communication protocol is known (ref: appendix).

Device Acknowledgements
Pointing devices send two acknowledgements: for data and signal. Before attempting to send or transmit any command/data, we have to wait for proper acknowledgement. Also, a timeout mechanism is required to prevent the driver from forever waiting state. Following code tracks acknowledgements:
private void WaitData() { for (int i = 0; i < 100 & ((BaseIOGroups.Mouse.p64.Byte & 1) == 1); i++) { ; } } private void WaitSignal() { for (int i = 0; i < 100 & ((BaseIOGroups.Mouse.p64.Byte & 2) != 0); i++) { ; } }

A timeout of 100 cycles8 has been used in both cases.

Device I/O
Device I/O consists of reading and writing over ports for communication with device. Before we read something, we should make sure that data is present. Following code reads data from port:
private byte Read()
6

There is only one physical port for communication. Cosmos provides an abstraction layer for easy driver programming. 7 Signals are alias for notifications. 8 Cycle should not be confused with CPU cycle. Here cycle is used for loop cycles.

Page 10 of 35
{ WaitData(); return BaseIOGroups.Mouse.p60.Byte; }

Writing over port is similar: send WRITE command (0xD4) over Port64, and after acknowledgement, write data over Port60. Code snippet for this is as follows:
private void Write(byte b) { WaitSignal(); BaseIOGroups.Mouse.p64.Byte = 0xD4; WaitSignal(); BaseIOGroups.Mouse.p60.Byte = b; }

Device Initialization
Mouse is initialized only once in whole system uptime, i.e., it is not hotpluggable. Initialization is performed in three steps: Handshake Load default values Enable data reporting Handshake is performed as follows:
WaitSignal(); BaseIOGroups.Mouse.p64.Byte = (byte)0xA8; WaitSignal(); BaseIOGroups.Mouse.p64.Byte = (byte)0x20; byte status = (byte)(BaseIOGroups.Mouse.p60.Byte | 2); WaitSignal(); BaseIOGroups.Mouse.p64.Byte = (byte)0x60; WaitSignal(); BaseIOGroups.Mouse.p60.Byte = status;

Loading mouse with default values is straightforward: issue 0xF6 command over Port60. Similarly, to enable data reporting issue 0xF4 command and set interrupt handler to parse data packets sent by mouse.

Page 11 of 35

Movement Data Packet


The standard PS/2 mouse sends movement and button information to the host using the following 3-byte packet: Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

Y X Byte Y X Always Middle Right Left sign sign 1 overflow overflow 1 Button Button Button bit bit Byte X movement 2 Byte Y movement 3 The movements values are 9-bit 2's complement integers, where the most significant bit appears as a "sign" bit in byte 1 of the movement data packet. Their value represents the mouse's offset relative to its position when the previous packet was sent, in units determined by the current resolution. The range of values that can be expressed is -255 to +255. If this range is exceeded, the appropriate overflow bit is set. Now, we can write a parser to extract data, as follows:

private int _x; private int _y; public MouseState Buttons; private readonly byte[] _mouseByte = new byte[4]; private byte _mouseCycle = 0; public enum MouseState { None = 0, Left = 1, Right = 2,

Page 12 of 35
Middle = 4 } switch (_mouseCycle) { case 0: _mouseByte[0] = Read(); //Bit 3 of byte 0 is 1, then we have a good package if ((_mouseByte[0] & 0x8) == 0x8) _mouseCycle++; break; case 1: _mouseByte[1] = Read(); _mouseCycle++; break; case 2: _mouseByte[2] = Read(); _mouseCycle = 0; if ((_mouseByte[0] & 0x10) == 0x10) { _x -= (_mouseByte[1] ^ 0xff); } else { _x += _mouseByte[1]; } if ((_mouseByte[0] & 0x20) == 0x20) { _y += (_mouseByte[2] ^ 0xff); } else { _y -= _mouseByte[2]; } if (_y { _y } if (_x { _x } < 0) = 0; < 0) = 0;

Buttons = (MouseState)(_mouseByte[0] & 0x7); break; }

Page 13 of 35

Since we will interact with our driver to use mouse services, there should be a public API. At bare minimum, methods to check mouse button, and to retrieve mouse coordinates will be required. Implementation of API is as follows:
public int X { get { return _x; } } public int Y { get { return _y; } } public Boolean CheckLeftClick() { if (Buttons == MouseState.Left) { return true; } else { return false; } } public Boolean CheckRightClick() { if (Buttons == MouseState.Right) { return true; } else { return false; } } public Boolean CheckMiddleClick() { if (Buttons == MouseState.Middle) { return true; } else { return false; } } public Boolean CheckNoClick()

Page 14 of 35
{ if (Buttons == MouseState.None) { return true; } else { return false; } }

Bibliography
Chapweske, A. (2003, 01 04). PS/2 Mouse Interfacing. Retrieved from Computer Engineering: http://www.computer-engineering.org/ps2mouse/ Furman, J. O. (2001). Rapid Prototyping of Digital Systems. Howei, J. (2009, 01 30). PS2 Commands. Retrieved from Altium: http://wiki.altium.com/display/ADOH/PS2+Commands

Page 15 of 35

Chapter 3: Virtual File System


File systems provide a way to store data arranged in files and folders, on some storage media like optical disc, magnetic disc, or RAM 9. The file system implemented in this toy OS is virtual: it uses RAM as its storage media. This file system emulates a real file system. Various FS elements are discussed below:

Directory
Directory is implemented using a class with single data member: path, as shown below:
public class Directory { //the path of the directory. public string path; #region " Directory Handlers " public Directory() { //Blank Directory. } public Directory(string p) { this.path = p; } #endregion " Directory Handlers " }

File
A file in the toy OS holds actual contents and some metadata in same unit. Metadata includes file name, size in bytes, type or extension, and path of directory to which it belongs. Implementation is as follows:
9

RAM is used as storage media in live operating systems. Live operating systems work without installation on physical hard disc.

Page 16 of 35
public public public public public string name = ""; string filetype = ""; int size = 0; string data = ""; Directory path = new Directory();

Since size of file should be updated each time file is edited, a public method is provided to update the same:
public void SetSize() { this.size = this.data.Length; }

Disk
A disk is a container which physically holds data in a computer system. Since total no. of files is dynamic, disk is implemented using List<> which is technically a linked list. Also, each disk is tagged with a driver letter10. To emulate mounting feature of LINUX family, swapping is also supported, where new disk is inserted in place of old disk with same driver letter11. Basic implementation is as follows:
public List<File> Files = new List<File>(); public string Driveletter = ""; public Disk() { } public Disk(string letter) { this.Driveletter = letter; } public void Start(string letter) { this.Files.Clear(); this.Driveletter = letter; }

10 11

It is similar to driver letters in Windows family of OS. Please refer to file system implementation for this feature.

Page 17 of 35
public void Start() { this.Files.Clear(); }

The file I/O system supports adding/removal of file(s), disk cleanup, formatting, and file editing. Code listing for it is given below:
public void AddFile(File newfile) { this.Files.Add(newfile); } public void AddFile(string name, string data, Directory path) { File newfile = new File(); newfile.name = name; newfile.data = data; newfile.path = path; newfile.SetSize(); Files.Add(newfile); } public void AddFile(string name, string data) { File newfile = new File(); newfile.name = name; newfile.data = data; newfile.SetSize(); Files.Add(newfile); } public void AddFile(string name, string data, string type) { File newfile = new File(); newfile.name = name; newfile.data = data; newfile.filetype = type; newfile.SetSize(); Files.Add(newfile); } public void RemoveFile(int i) { Files.RemoveAt(i); } public void RemoveFile(string name) { for (int i = 0; i < Files.Count; i++) { if (this.Files[i].name == name)

Page 18 of 35
{ Files.RemoveAt(i); break; } } } public void RemoveFile(int start, int end) { for (int i = start; i < end; i++) { Files.RemoveAt(i); } } public void PartitionDisk() { this.Files.Clear(); } public void CleanUpFiles(int sizeamount) { for (int i = 0; i < Files.Count; i++) { this.Files[i].SetSize(); if (this.Files[i].size <= sizeamount) { Files.RemoveAt(i); } } } public int GetTotalSize() { int size = 0; for (int i = 0; i < Files.Count; i++) { this.Files[i].SetSize(); size += this.Files[i].size; } return size; } public int GetFiles() { return Files.Count; } public string GetFileContents(string nme) { for (int i = 0; i < Files.Count; i++) { if (this.Files[i].name == nme) { return this.Files[i].data;

Page 19 of 35
} } return ""; } public bool SetFileContents(string nme, string newdata) { for (int i = 0; i < Files.Count; i++) { if (this.Files[i].name == nme) { Files[i].data = newdata; Files[i].SetSize(); return true; } } return false; }

File System
A file system is implemented as a container of disks, as a single file system can span up to multiple disks. It supports only three operations: adding, removal, and swapping of disks. Implementation is pretty straightforward:
public static List<Disk> Disks = new List<Disk>(); private static int i; public void AddDisk(Disk newdisk) { Disks.Add(newdisk); } public void RemoveDisk(string letter) { for (i = 0; i < Disks.Count; i++) { if (Disks[i].Driveletter == letter) { Disks.RemoveAt(i); break; } } } public void RemoveDisk(int i) { Disks.RemoveAt(i); }

Page 20 of 35

public void SwapDisks(Disk NewDisk, string letter) { for (i = 0; i < Disks.Count; i++) { if (Disks[i].Driveletter == letter) { Disks[i] = NewDisk; break; } } }

To lookup for a particular disk search by driver letter is supported.


public Disk GetDisk(string letter) { for (i = 0; i < Disks.Count; i++) { if (Disks[i].Driveletter == letter) { return Disks[i]; } } return new Disk(); }

Hard Disk
In the toy OS, a hard disk can contain only one file system within itself12. Hard disk is implemented as follows:
public class HardDrive { public static Filesystem Drive = new Filesystem(); }

12

In other words, hard disk partitioning is not supported.

Page 21 of 35

Chapter 4: Graphical User Interface


Graphical User Interface or GUI is probably easiest way to interact with a computer. Therefore, almost every modern OS provides a rich GUI to let the user explore the world more easily13. Since COSMOS framework does not support any GUI natively, whole graphics system is to be developed by the OS developer. Fortunately, the framework support graphics mode in which it lets the programmer to color any pixel on the screen, and therefore, GUI can be drawn using standard computer graphics algorithms. A sample snapshot of implemented GUI with various components is shown below:

Currently, GUI supports resizable windows, drag and drop, and overlapping windows. However, it does not support variable z index, i.e. foreground window cannot be put in background or vice versa. Core

13

One possible exception is BACKTRACK operating system, in which most of the work is have to be done through terminal or console. There is no GUI support for many tools blended with the OS.

Page 22 of 35

GUI is implemented in a single class window, which encapsulates all required functions. The code for implementation is as follows:
public window(uint x, uint y, uint Width, uint Height, uint color, window p, bool mod al) { this.X = x; this.Y = y; this.Width = Width; this.Height = Height; this.Color = color; this.Parent = p; p.Child = this; this.Modal = modal; this.Ch = 0U; Array.Clear((Array)this.Str, 0, this.Str.Length); window.LastWnd = this; } public static window Active(uint x, uint y, window lWnd) { if (x > lWnd.X && x < lWnd.X + lWnd.Width && (y > lWnd.Y && y < lWnd.Y + lWnd.Height)) window.ActiveWnd = lWnd; else if (lWnd.Parent != null) window.Active(x, y, lWnd.Parent); return window.ActiveWnd; } public static void ReDraw(window fWnd) { fWnd.Draw(); if (fWnd.Child == null) return; window.ReDraw(fWnd.Child); } public void Draw() { uint num1 = 0U; uint num2 = 0U; VGAScreen vgaScreen = new VGAScreen(); for (uint index = this.X; index < this.X + this.Width; ++index) { uint num3; for (num3 = this.Y; num3 < this.Y + this.Height; ++num3) { if ((int)index == (int)this.X || (int)num3 == (int)this.Y) vgaScreen.SetPixel320x200x8(index, num3, 8U); else vgaScreen.SetPixel320x200x8(index, num3, this.Color); vgaScreen.SetPixel320x200x8(this.X + this.Width, num3, 8U); }

Page 23 of 35
vgaScreen.SetPixel320x200x8(index, num3, 8U); } if (!this.Modal) { this.DrawBar(); this.DrawCorner(); num2 += 5U; } } public void DrawBar() { VGAScreen vgaScreen = new VGAScreen(); for (uint index = this.X; index < this.X + this.Width; ++index) { uint num; for (num = this.Y; num < this.Y + 5U; ++num) { if ((int)index == (int)this.X || (int)num == (int)this.Y) vgaScreen.SetPixel320x200x8(index, num, 8U); else vgaScreen.SetPixel320x200x8(index, num, 3U); vgaScreen.SetPixel320x200x8(this.X + this.Width, num, 8U); } vgaScreen.SetPixel320x200x8(index, num, 8U); } } public void DrawCorner() { VGAScreen vgaScreen = new VGAScreen(); uint num = 0U; for (uint index1 = (uint)((int)this.X + (int)this.Width 1); index1 > (uint)((int)this.X + (int)this.Width - 4); --index1) { for (uint index2 = (uint)((int)this.Y + (int)this.Height 3) + num++; index2 < this.Y + this.Height; ++index2) vgaScreen.SetPixel320x200x8(index1, index2, 3U); } } public uint Status(uint mx, uint my) { if (my < this.Y + 5U && mx < (uint)((int)this.X + (int)this.Width - 5)) return 1U; if (my < this.Y + 5U && mx > (uint)((int)this.X + (int)this.Width - 5)) return 2U; if (mx > (uint)((int)this.X + (int)this.Width 4) && mx <= this.X + this.Width && (my > (uint)((int)this.Y + (int)this.Height 4) && my <= this.Y + this.Height)) return 3U; else return 0U; }

Page 24 of 35
public static void Destroy(window d, window pWnd) { d = d.Parent; d.Child = (window)null; window.LastWnd = d; window.ReDraw(pWnd); } public void Sync(uint mx, uint my, window pWnd) { this.X = mx; this.Y = my; window.ReDraw(pWnd); } public void SynSz(uint mx, uint my, window pWnd) { this.Width = mx; this.Height = my; window.ReDraw(pWnd); } public void StringTo(string s) { this.Str = s.ToCharArray(); }

To use the mouse, we need to interact with the hardware through device driver implemented in chapter 2. Mouse is attached to GUI as shown below:
public static void Initialize(Cosmos.Hardware.VGAScreen scr, window parentWnd) { Mouse.Hardware.Mouse Mouse2 = new Mouse.Hardware.Mouse(); Mouse2.Initialize(); uint x = (uint)Mouse2.X; uint y = (uint)Mouse2.Y; uint oc = 0, oc1 = 0, oc2 = 0, oc3 = 0; uint k = 0; window nd = new window(10, 20, 150, 50, 5, window.LastWnd, false); window end = new window(parentWnd.Width / 2, parentWnd.Width / 2, 50, 30, 5, nd, false); end.StringTo("DIALOG WND");

Page 25 of 35
window wnd = null; window act = null; window.ReDraw(parentWnd); while (true) { #region Mouse Data uint mx = (uint)Mouse2.X; uint my = (uint)Mouse2.Y; if (mx != x || my != y) { scr.SetPixel320x200x8(x, y, oc); scr.SetPixel320x200x8(x, y + 1, oc1); scr.SetPixel320x200x8(x + 1, y, oc2); scr.SetPixel320x200x8(x + 1, y + 1, oc3); x = mx; y = my; oc = scr.GetPixel320x200x8(x, y); oc1 = scr.GetPixel320x200x8(x, y + 1); oc2 = scr.GetPixel320x200x8(x + 1, y); oc3 = scr.GetPixel320x200x8(x + 1, y + 1); //Mouse2.Draw(); } switch (k) { case 1: act.Sync(mx, my, parentWnd); break; case 2: window.Destroy(act, parentWnd); k = 0; break; case 3: act.SynSz(mx, my, parentWnd); break; case 4: window l = window.LastWnd; if (l.Ch == 666) window.Destroy(l, parentWnd); k = 0; break; } scr.SetPixel320x200x8(mx, my, 6); scr.SetPixel320x200x8(mx, my + 1, 6); scr.SetPixel320x200x8(mx + 1, my, 6); scr.SetPixel320x200x8(mx + 1, my + 1, 6); if (Mouse2.CheckRightClick()) { window last = window.LastWnd; if ((last.Modal == true) && (last.Ch == 666))

Page 26 of 35
{ window.Destroy(last, parentWnd); } wnd = new window(0, 0, 51, 51, oc, window.LastWnd, true); wnd.Color = 3; wnd.Ch = 666; wnd.StringTo("CREATE WND"); wnd.Sync(mx, my, parentWnd); } if (Mouse2.CheckLeftClick()) { act = window.Active(mx, my, window.LastWnd); if (act.Modal == true) { if (act.Ch == 666) { window newWnd = new window(parentWnd.Width / 3, parentWnd .Width / 3, 50, 30, 5, act.Parent, false); } else if (act.Ch == 0) { k = 4; } else { nd.CharTo(act.Ch - 1); } } else { k = act.Status(mx, my); } window.ReDraw(parentWnd); } if (Mouse2.CheckMiddleClick()) { k = 0; } #endregion Mouse Data } }

Page 27 of 35

Result
The developed microkernel based toy OS boots successfully in VMWare Player, and all implemented functionalities work flawlessly. It should boot on any x86 based real machine, however it is not guaranteed.
Snapshots

Page 28 of 35

Page 29 of 35

Page 30 of 35

Appendix A: PS/2 Mouse Commands

Commands Sent by Host to Mouse Code Description and Mouse Action E6h This command is used to set the current scaling from 2:1 to 1:1. After receipt of the command, the mouse replies with the acknowledge code (FAh) and changes the scaling to be 1:1. This command is used to set the current scaling from 1:1 to 2:1. After receipt of the command, the mouse replies with the acknowledge code (FAh) and changes the scaling to be 2:1. This command is used to set the resolution for the mouse. The mouse sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the resolution to be used, as follows: 00h 1 count 01h 2 counts 02h 4 counts 03h 8 counts per millimeter per per per millimeter millimeter millimeter

E7h

E8h

After receipt of this second byte, the mouse sends the acknowledge code again and resets its movement counters E9h This command is used to request the current status of the

Page 31 of 35

mouse. Upon receipt of the command, the mouse sends the acknowledge response code (FAh), followed by a three byte status packet, structured as follows: Byte1 Bit0 State of right mouse button (1=pressed; 0=not pressed) Bit1 State of middle mouse button (1=pressed; 0=not pressed) Bit2 State of left mouse button (1=pressed; 0=not pressed) Bit3 Not Used (set to 0) Bit4 Current scaling in use (1= 2:1; 0= 1:1) Bit5 Data reporting state (1=enabled; 0=disabled) Bit6 Current mode (1= Remote mode; 0= Stream mode) Bit7 Not Used (set to 0) Byte2 Current resolution in use Byte3 Current sampling rate in use After sending the status packet, the mouse resets its movement counters. EAh This command is used to set the mouse in Stream mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Stream mode. In this mode, a packet of data is sent every time the mouse detects movement, or when one of its buttons has changed state. Data is sent to the host, providing that data reporting is enabled. The frequency of packet transmission is determined by the sampling rate the default being 100 samples per second. This command is used to read sampled data from the mouse

EBh

Page 32 of 35

whilst it is in Remote mode. The mouse responds by sending the acknowledge response code (FAh) and then sending its current packet of movement data. The movement counters are subsequently reset. ECh This command is used to reset Wrap mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering the mode that it was in prior to entering Wrap mode (either Stream or Remote). This command is used to set the mouse in Wrap mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Wrap mode. In this mode, the mouse echoes all commands directly back to the host, without additional or further response. Two exceptions to this are the commands to reset (FFh) and reset Wrap mode (ECh). In these cases, the mouse responds as per the entries for these commands in this table. This command is used to set the mouse in Remote mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Remote mode. In this mode, the inputs to the mouse (movement and buttons) are still sampled, but no packets of data are sent to the host. This command is used to read the mouse ID. Upon receipt, the mouse responds with the acknowledge response code (FAh), followed by the code that represents its ID and distinguishes it as a standard PS/2 mouse 00h. The movement counters are also

EEh

F0h

F2h

Page 33 of 35

reset at this time. F3h This command is used to set the sampling rate for the mouse (when monitoring its movement and button inputs). The mouse sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the sampling rate to be used, as follows: 0Ah 10 samples 14h 20 samples 28h 40 samples 3Ch 60 samples 50h 80 samples 64h 100 samples C8h 200 samples per second. per per per per per per second second second second second second

After receipt of this second byte, the mouse sends the acknowledge code again and resets its movement counters. F4h This command is used to enable data reporting when the mouse is in Stream mode. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and resets its movement counters. It continues to sample its inputs (movement and buttons) and packets of data are once again sent to the host. This command is used to disable data reporting when the mouse is in Stream mode. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and resets its movement counters. It continues to sample its inputs

F5h

Page 34 of 35

(movement and buttons) but no packets of data are sent to the host. Stream mode with data reporting disabled is analogous to the mouse being in Remote mode. F6h This command is used to load the mouse with default values. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and then loads the following:

Sampling Rate 100 samples per second Resolution 4 counts per millimeter Scaling 1:1 Data Reporting Disabled.

These default values are also loaded when a reset command is received from the host, or when the mouse is powered-up (as part of its Basic Assurance Test). After loading the values, the mouse resets its movement counters and enters Stream mode. FEh This is the resend command and is used when the host requires the mouse to retransmit the last packet of data sent. Upon receipt of the command, the mouse sends the acknowledge response code (FAh), then proceeds to transmit the previously sent packet of data (e.g. movement data, status information, BAT code, ID, etc). This command is used to reset the mouse. Upon receipt of the command, the mouse sends the acknowledge response code (FAh). The mouse is reset and subsequently performs its poweron Basic Assurance Test (BAT). During this test, default values

FFh

Page 35 of 35

are loaded for the sampling rate, resolution and scaling, and data reporting is disabled. Depending on the result of the test, the mouse will either send the 'Passed' code (AAh) or the 'Failed' code (FCh). After the result of the power-on test is sent, the mouse sends its ID (00h). The mouse will then enter Stream mode. No movement data packets will be sent however, until the host first sends the command to enable data reporting.

Commands Sent by PS/2 Device

Code Description 00h AAh FCh FAh FEh Mouse ID Power-on Basic Assurance Test Passed Power-on Basic Assurance Test Failed Acknowledge Resend. Upon receipt of this code, the PS2 Controller will retransmit the previous byte.

Você também pode gostar