1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-17 09:31:32 +02:00
iris/boot-programs/init.ccp
2009-10-04 19:47:20 +02:00

132 lines
3.7 KiB
COBOL

#pypp 0
// Iris: micro-kernel for a capability-based operating system.
// boot-programs/init.ccp: System boot manager.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "devices.hh"
#include "iris.hh"
static Keyboard kbd, sysreq
static Buzzer buzzer
static Device kbd_dev, buz_dev
static List <String> kbd_names
static unsigned slot
// Event types.
enum type:
MEMORY
KBDDEV
KBD
KEYNAMES
SYSREQ
BUZDEV
BUZZER
static void setup ():
unsigned state = 0
Kernel::Caps caps = Kernel::my_memory.create_caps (32)
slot = caps.use ()
Kernel::set_recv_arg (Kernel::Cap (slot, MEMORY))
Kernel::Cap driver_memory = Kernel::my_memory.create_memory ()
while true:
Kernel::wait ()
Kernel::Cap reply = Kernel::get_reply ()
Kernel::Cap arg = Kernel::get_arg ()
switch Kernel::recv.data[0].l:
case Keyboard::ID:
switch Kernel::recv.data[0].h:
case 0:
caps.set (KBDDEV, arg.copy ())
kbd_dev = Kernel::Cap (slot, KBDDEV)
break
case 1:
caps.set (SYSREQ, arg.copy ())
sysreq = Kernel::Cap (slot, SYSREQ)
break
default:
kdebug ("unexpected keyboard\n")
break
break
case Buzzer::ID:
caps.set (BUZDEV, arg.copy ())
buz_dev = Kernel::Cap (slot, BUZDEV)
break
default:
Kernel::free_cap (reply)
Kernel::free_cap (arg)
kdebug ("unknown setup request for init\n")
continue
reply.invoke ()
Kernel::free_cap (reply)
Kernel::free_cap (arg)
if ++state == 3:
break
// sysreq
Kernel::Cap cb = Kernel::my_receiver.create_capability (SYSREQ)
sysreq.set_cb (cb.copy ())
// keyboard user
Kernel::set_recv_arg (Kernel::Cap (slot, KBD))
kbd = kbd_dev.create_user (driver_memory)
kbd_dev.use (kbd)
// keyboard callback
Kernel::set_recv_arg (cb)
Kernel::my_receiver.create_capability (KBD)
kbd.set_cb (cb.copy ())
// keyboard name list
Kernel::set_recv_arg (Kernel::Cap (slot, KEYNAMES))
kbd_names = kbd.get_keys ()
// buzzer user
Kernel::set_recv_arg (Kernel::Cap (slot, BUZZER))
buzzer = buz_dev.create_user (driver_memory)
buz_dev.use (buzzer)
// clean up.
Kernel::free_cap (cb)
//char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*() T\n[],.-=/\\;|`'UDLREIKBPFZMS{}CA\":"
char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$*T\nE& B=UDLR+-F^CA"
Kernel::Num start ():
setup ()
kdebug ("init set up\n")
while true:
Kernel::wait ()
switch Kernel::recv.protected_data.value ():
case SYSREQ:
unsigned code = Kernel::recv.data[0].l
kdebug ("\n\nSystem request ")
if code & Keyboard::RELEASE:
kdebug ("released.\n\n")
else:
kdebug ("pressed.\n\n")
break
case KBD:
unsigned code = Kernel::recv.data[0].l
if code & Keyboard::RELEASE:
kdebug_char ('-')
else:
kdebug_char ('+')
buzzer.beep (2000, 100, 0)
String name = kbd_names.get (code & ~Keyboard::RELEASE)
unsigned size = name.get_size ().l
char buffer[16]
for unsigned i = 0; i < size; i += 16:
name.get_chars (i, buffer)
for unsigned k = 0; k < size - i && k < 16; ++k:
kdebug_char (buffer[k])
kdebug_char ('\n')
Kernel::free_cap (name)
break