#pypp 0 // Iris: micro-kernel for a capability-based operating system. // boot-programs/init.ccp: System boot manager. // Copyright 2009 Bas Wijnen // // 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 . #include "devices.hh" #include "iris.hh" static Keyboard sysreq static Device kbd_dev, buz_dev static unsigned slot // Event types. enum type: SYSREQ KBDDEV BUZDEV 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 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 default: kdebug ("unexpected device\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 == 4: break // sysreq kdebug ("using sysreq\n") Kernel::Cap cb = Kernel::my_receiver.create_capability (SYSREQ) sysreq.set_cb (cb.copy ()) Kernel::free_cap (cb) // First user reply. kdebug ("sending first user reply\n") user_reply (user, device) Kernel::free_cap (user) 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 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