about summary refs log tree commit diff stats
path: root/tools/iso/kernel.soso/mouse.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-03 22:09:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-03 22:21:03 -0800
commit71e4f3812982dba2efb471283d310224e8db363e (patch)
treeea111a1acb8b8845dbda39c0e1b4bac1d198143b /tools/iso/kernel.soso/mouse.c
parentc6b928be29ac8cdb4e4d6e1eaa20420ff03e5a4c (diff)
downloadmu-71e4f3812982dba2efb471283d310224e8db363e.tar.gz
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.

So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.

A couple of things have gotten dropped in this process:
  - I had old ways to run on just a Linux kernel, or with a Soso kernel.
    No more.
  - I had some old tooling for running a single test at the cursor. I haven't
    used that lately. Maybe I'll bring it back one day.

The reorg isn't done yet. Still to do:
  - redo documentation everywhere. All the README files, all other markdown,
    particularly vocabulary.md.
  - clean up how-to-run comments at the start of programs everywhere
  - rethink what to do with the html/ directory. Do we even want to keep
    supporting it?

In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
Diffstat (limited to 'tools/iso/kernel.soso/mouse.c')
-rw-r--r--tools/iso/kernel.soso/mouse.c187
1 files changed, 0 insertions, 187 deletions
diff --git a/tools/iso/kernel.soso/mouse.c b/tools/iso/kernel.soso/mouse.c
deleted file mode 100644
index 235d931d..00000000
--- a/tools/iso/kernel.soso/mouse.c
+++ /dev/null
@@ -1,187 +0,0 @@
-#include "mouse.h"
-#include "isr.h"
-#include "common.h"
-#include "device.h"
-#include "alloc.h"
-#include "devfs.h"
-#include "list.h"
-#include "fifobuffer.h"
-#include "spinlock.h"
-
-static void handleMouseInterrupt(Registers *regs);
-
-static uint8 gMouseByteCounter = 0;
-
-static void prepareForRead();
-static void prepareForWrite();
-static void writeMouse(uint8 data);
-static void handleMouseInterrupt(Registers *regs);
-
-static BOOL mouse_open(File *file, uint32 flags);
-static void mouse_close(File *file);
-static int32 mouse_read(File *file, uint32 size, uint8 *buffer);
-
-#define MOUSE_PACKET_SIZE 3
-
-uint8 gMousePacket[MOUSE_PACKET_SIZE];
-
-static List* gReaders = NULL;
-
-static Spinlock gReadersLock;
-
-void initializeMouse() {
-    Device device;
-    memset((uint8*)&device, 0, sizeof(Device));
-    strcpy(device.name, "psaux");
-    device.deviceType = FT_CharacterDevice;
-    device.open = mouse_open;
-    device.close = mouse_close;
-    device.read = mouse_read;
-    registerInterruptHandler(IRQ12, handleMouseInterrupt);
-
-    registerDevice(&device);
-
-    memset(gMousePacket, 0, MOUSE_PACKET_SIZE);
-
-    gReaders = List_Create();
-
-    Spinlock_Init(&gReadersLock);
-
-    prepareForWrite();
-
-    outb(0x64, 0x20); //get status command
-
-    uint8 status = inb(0x60);
-    status = status | 2; //enable IRQ12
-
-    outb(0x64, 0x60); //set status command
-    outb(0x60, status);
-
-    outb(0x64, 0xA8); //enable Auxiliary Device command
-
-    writeMouse(0xF4); //0xF4: Enable Packet Streaming
-}
-
-static BOOL mouse_open(File *file, uint32 flags) {
-    FifoBuffer* fifo = FifoBuffer_create(60);
-
-    file->privateData = (void*)fifo;
-
-    Spinlock_Lock(&gReadersLock);
-
-    List_Append(gReaders, file);
-
-    Spinlock_Unlock(&gReadersLock);
-
-    return TRUE;
-}
-
-static void mouse_close(File *file) {
-    Spinlock_Lock(&gReadersLock);
-
-    List_RemoveFirstOccurrence(gReaders, file);
-
-    Spinlock_Unlock(&gReadersLock);
-
-    FifoBuffer* fifo = (FifoBuffer*)file->privateData;
-
-    FifoBuffer_destroy(fifo);
-}
-
-static int32 mouse_read(File *file, uint32 size, uint8 *buffer) {
-    FifoBuffer* fifo = (FifoBuffer*)file->privateData;
-
-    while (FifoBuffer_getSize(fifo) < MOUSE_PACKET_SIZE) {
-        file->thread->state = TS_WAITIO;
-        file->thread->state_privateData = mouse_read;
-        enableInterrupts();
-        halt();
-    }
-
-    disableInterrupts();
-
-
-    uint32 available = FifoBuffer_getSize(fifo);
-    uint32 smaller = MIN(available, size);
-
-    FifoBuffer_dequeue(fifo, buffer, smaller);
-
-    return smaller;
-}
-
-static void prepareForRead() {
-    //https://wiki.osdev.org/Mouse_Input
-    //Bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set
-
-    int32 tryCount = 1000;
-
-    uint8 data = 0;
-    do {
-        data = inb(0x64);
-    } while (((data & 0x01) == 0) && --tryCount > 0);
-}
-
-static void prepareForWrite() {
-    //https://wiki.osdev.org/Mouse_Input
-    //All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear
-
-    int32 tryCount = 1000;
-
-    uint8 data = 0;
-    do {
-        data = inb(0x64);
-    } while (((data & 0x02) != 0) && --tryCount > 0);
-}
-
-static void writeMouse(uint8 data) {
-    prepareForWrite();
-
-    outb(0x64, 0xD4);
-
-    prepareForWrite();
-
-    outb(0x60, data);
-}
-
-static void handleMouseInterrupt(Registers *regs) {
-    uint8 status = 0;
-    //0x20 (5th bit is mouse bit)
-    //read from 0x64, if its mouse bit is 1 then data is available at 0x60!
-
-    int32 tryCount = 1000;
-    do {
-        status = inb(0x64);
-    } while (((status & 0x20) == 0) && --tryCount > 0);
-
-    uint8 data = inb(0x60);
-
-    gMousePacket[gMouseByteCounter] = data;
-
-    gMouseByteCounter += 1;
-
-    if (gMouseByteCounter == MOUSE_PACKET_SIZE) {
-        gMouseByteCounter = 0;
-
-        Spinlock_Lock(&gReadersLock);
-
-        //Wake readers
-        List_Foreach(n, gReaders) {
-            File* file = n->data;
-
-            FifoBuffer* fifo = (FifoBuffer*)file->privateData;
-
-            FifoBuffer_enqueue(fifo, gMousePacket, MOUSE_PACKET_SIZE);
-
-            if (file->thread->state == TS_WAITIO) {
-                if (file->thread->state_privateData == mouse_read) {
-                    file->thread->state = TS_RUN;
-                    file->thread->state_privateData = NULL;
-                }
-            }
-        }
-
-        Spinlock_Unlock(&gReadersLock);
-    }
-
-    //printkf("mouse:%d\n", data);
-}