1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-19 06:50:38 +02:00
iris/boot-programs/init.ccp

143 lines
3.8 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-10 02:31:10 +03:00
static Keyboard sysreq
2009-10-04 20:47:20 +03:00
static Device kbd_dev, buz_dev
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
SYSREQ
2009-10-10 02:31:10 +03:00
KBDDEV
2009-10-04 20:47:20 +03:00
BUZDEV
2009-10-10 02:31:10 +03:00
static void user_reply (Kernel::Cap target, unsigned dev):
switch dev:
case Keyboard::ID:
// keyboard user
kdebug ("keyboard requested\n")
Kernel::Cap kbd = kbd_dev.create_user (Kernel::Cap ())
kbd_dev.use (kbd)
target.invoke (0, 0, kbd.copy ())
Kernel::free_cap (kbd)
break
case Buzzer::ID:
// buzzer user
kdebug ("buzzer requested\n")
Kernel::Cap buzzer = buz_dev.create_user (Kernel::Cap ())
buz_dev.use (buzzer)
kdebug ("invoking reply: ")
kdebug_num (target.code)
kdebug ("\n")
target.invoke (0, 0, buzzer.copy ())
Kernel::free_cap (buzzer)
break
default:
kdebug ("invalid id requested:")
kdebug_num (dev)
kdebug_char ('\n')
break
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 ()
2009-10-10 02:31:10 +03:00
Kernel::Cap user
unsigned device
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:
2009-10-31 10:32:23 +02:00
case Parent::PROVIDE_DEVICE:
switch Kernel::recv.data[1].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
reply.invoke ()
Kernel::free_cap (reply)
2009-10-04 20:47:20 +03:00
break
2009-10-31 10:32:23 +02:00
case Buzzer::ID:
caps.set (BUZDEV, arg.copy ())
buz_dev = Kernel::Cap (slot, BUZDEV)
reply.invoke ()
Kernel::free_cap (reply)
2009-10-04 20:47:20 +03:00
break
default:
2009-10-31 10:32:23 +02:00
kdebug ("unexpected device\n")
2009-10-04 20:47:20 +03:00
break
2009-10-10 02:31:10 +03:00
break
case Parent::GET_DEVICE:
user = reply
device = Kernel::recv.data[1].l
2009-07-21 13:17:52 +03:00
break
2009-09-07 00:34:50 +03:00
default:
2009-10-10 02:31:10 +03:00
kdebug ("unknown setup request for init\n")
reply.invoke ()
2009-10-04 20:47:20 +03:00
Kernel::free_cap (reply)
Kernel::free_cap (arg)
2009-09-07 00:34:50 +03:00
continue
2009-10-04 20:47:20 +03:00
Kernel::free_cap (arg)
2009-10-10 02:31:10 +03:00
if ++state == 4:
2009-07-21 13:17:52 +03:00
break
2009-10-04 20:47:20 +03:00
// sysreq
2009-10-10 02:31:10 +03:00
kdebug ("using sysreq\n")
2009-10-04 20:47:20 +03:00
Kernel::Cap cb = Kernel::my_receiver.create_capability (SYSREQ)
sysreq.set_cb (cb.copy ())
Kernel::free_cap (cb)
2009-10-10 02:31:10 +03:00
// First user reply.
kdebug ("sending first user reply\n")
user_reply (user, device)
Kernel::free_cap (user)
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-10 02:31:10 +03:00
default:
if Kernel::recv.data[0].l != Parent::GET_DEVICE:
kdebug ("invalid call from user\n")
break
Kernel::Cap reply = Kernel::get_reply ()
user_reply (reply, Kernel::recv.data[1].l)
Kernel::free_cap (reply)
2009-07-21 13:17:52 +03:00
break