mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-16 19:20:17 +02:00
154 lines
4.1 KiB
COBOL
154 lines
4.1 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 sysreq
|
|
static Device kbd_dev, buz_dev, backlight_dev, rootfs_dev
|
|
static unsigned slot
|
|
|
|
// Event types.
|
|
enum type:
|
|
SYSREQ
|
|
KBDDEV
|
|
BUZDEV
|
|
BACKLIGHTDEV
|
|
ROOTFSDEV
|
|
|
|
static void user_reply (Kernel::Cap target, unsigned dev):
|
|
switch dev:
|
|
case Keyboard::ID:
|
|
// keyboard user
|
|
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
|
|
Kernel::Cap buzzer = buz_dev.create_user (Kernel::Cap ())
|
|
buz_dev.use (buzzer)
|
|
target.invoke (0, 0, buzzer.copy ())
|
|
Kernel::free_cap (buzzer)
|
|
break
|
|
default:
|
|
kdebug ("invalid id requested:")
|
|
kdebug_num (dev)
|
|
kdebug_char ('\n')
|
|
break
|
|
|
|
static void setup ():
|
|
unsigned state = 0
|
|
Kernel::Caps caps = Kernel::my_memory.create_caps (32)
|
|
slot = caps.use ()
|
|
Kernel::Cap user
|
|
unsigned device
|
|
while true:
|
|
Kernel::wait ()
|
|
Kernel::Cap reply = Kernel::get_reply ()
|
|
Kernel::Cap arg = Kernel::get_arg ()
|
|
switch Kernel::recv.data[0].l:
|
|
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)
|
|
break
|
|
case Buzzer::ID:
|
|
caps.set (BUZDEV, arg.copy ())
|
|
buz_dev = Kernel::Cap (slot, BUZDEV)
|
|
reply.invoke ()
|
|
Kernel::free_cap (reply)
|
|
break
|
|
case Setting::ID:
|
|
caps.set (BACKLIGHTDEV, arg.copy ())
|
|
backlight_dev = Kernel::Cap (slot, BACKLIGHTDEV)
|
|
reply.invoke ()
|
|
Kernel::free_cap (reply)
|
|
break
|
|
case Directory::ID:
|
|
caps.set (ROOTFSDEV, arg.copy ())
|
|
rootfs_dev = Kernel::Cap (slot, ROOTFSDEV)
|
|
reply.invoke ()
|
|
Kernel::free_cap (reply)
|
|
break
|
|
default:
|
|
kdebug ("unexpected device: ")
|
|
kdebug_num (Kernel::recv.data[1].l)
|
|
kdebug_char ('\n')
|
|
break
|
|
break
|
|
case Parent::GET_DEVICE:
|
|
user = reply
|
|
device = Kernel::recv.data[1].l
|
|
break
|
|
default:
|
|
kdebug ("unknown setup request for init\n")
|
|
reply.invoke ()
|
|
Kernel::free_cap (reply)
|
|
Kernel::free_cap (arg)
|
|
continue
|
|
Kernel::free_cap (arg)
|
|
if ++state == 6:
|
|
break
|
|
// sysreq
|
|
Kernel::Cap cb = Kernel::my_receiver.create_capability (SYSREQ)
|
|
sysreq.set_cb (cb.copy ())
|
|
Kernel::free_cap (cb)
|
|
// First user reply.
|
|
user_reply (user, device)
|
|
Kernel::free_cap (user)
|
|
|
|
Kernel::Num start ():
|
|
Kernel::schedule ()
|
|
setup ()
|
|
// claim backlight
|
|
Setting backlight = backlight_dev.create_user (Kernel::Cap ())
|
|
backlight_dev.use (backlight)
|
|
while true:
|
|
Kernel::wait ()
|
|
switch Kernel::recv.protected_data.value ():
|
|
case SYSREQ:
|
|
unsigned code = Kernel::recv.data[0].l
|
|
if code & Keyboard::RELEASE:
|
|
backlight.set (~0)
|
|
else:
|
|
backlight.set (0)
|
|
break
|
|
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)
|
|
break
|