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

132 lines
3.7 KiB
Plaintext
Raw Normal View History

2009-07-21 13:17:52 +03:00
#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"
2009-07-21 13:17:52 +03:00
2009-10-04 20:47:20 +03:00
static Keyboard kbd, sysreq
static Buzzer buzzer
static Device kbd_dev, buz_dev
static List <String> kbd_names
static unsigned slot
2009-07-21 13:17:52 +03:00
// Event types.
2009-07-21 13:17:52 +03:00
enum type:
2009-10-04 20:47:20 +03:00
MEMORY
KBDDEV
KBD
KEYNAMES
SYSREQ
BUZDEV
BUZZER
2009-07-21 13:17:52 +03:00
static void setup ():
unsigned state = 0
2009-10-04 20:47:20 +03:00
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 ()
2009-07-21 13:17:52 +03:00
while true:
2009-09-06 12:04:09 +03:00
Kernel::wait ()
2009-09-07 00:34:50 +03:00
Kernel::Cap reply = Kernel::get_reply ()
2009-10-04 20:47:20 +03:00
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
2009-07-21 13:17:52 +03:00
break
2009-10-04 20:47:20 +03:00
case Buzzer::ID:
caps.set (BUZDEV, arg.copy ())
buz_dev = Kernel::Cap (slot, BUZDEV)
2009-07-21 13:17:52 +03:00
break
2009-09-07 00:34:50 +03:00
default:
2009-10-04 20:47:20 +03:00
Kernel::free_cap (reply)
Kernel::free_cap (arg)
2009-09-07 00:34:50 +03:00
kdebug ("unknown setup request for init\n")
continue
reply.invoke ()
Kernel::free_cap (reply)
2009-10-04 20:47:20 +03:00
Kernel::free_cap (arg)
if ++state == 3:
2009-07-21 13:17:52 +03:00
break
2009-10-04 20:47:20 +03:00
// 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)
2009-07-21 13:17:52 +03:00
2009-10-04 20:47:20 +03:00
//char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*() T\n[],.-=/\\;|`'UDLREIKBPFZMS{}CA\":"
char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$*T\nE& B=UDLR+-F^CA"
2009-09-06 12:04:09 +03:00
Kernel::Num start ():
2009-07-24 15:25:53 +03:00
setup ()
2009-09-30 00:48:33 +03:00
kdebug ("init set up\n")
2009-07-21 13:17:52 +03:00
while true:
2009-09-06 12:04:09 +03:00
Kernel::wait ()
switch Kernel::recv.protected_data.value ():
2009-10-04 20:47:20 +03:00
case SYSREQ:
2009-09-06 12:04:09 +03:00
unsigned code = Kernel::recv.data[0].l
2009-10-04 20:47:20 +03:00
kdebug ("\n\nSystem request ")
if code & Keyboard::RELEASE:
2009-10-04 20:47:20 +03:00
kdebug ("released.\n\n")
else:
kdebug ("pressed.\n\n")
2009-07-21 13:17:52 +03:00
break
2009-10-04 20:47:20 +03:00
case KBD:
unsigned code = Kernel::recv.data[0].l
if code & Keyboard::RELEASE:
kdebug_char ('-')
2009-07-25 23:00:32 +03:00
else:
2009-10-04 20:47:20 +03:00
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)
2009-07-21 13:17:52 +03:00
break