mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-09-12 16:44:36 +03:00
118 lines
3.3 KiB
Plaintext
118 lines
3.3 KiB
Plaintext
|
#pypp 0
|
||
|
// Iris: micro-kernel for a capability-based operating system.
|
||
|
// boot-programs/init.S: Startup code for initial Threads.
|
||
|
// 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 "iris.hh"
|
||
|
|
||
|
// For some unknown reason, gcc needs this to be defined.
|
||
|
unsigned __gxx_personality_v0
|
||
|
|
||
|
struct list:
|
||
|
list *prev, *next
|
||
|
|
||
|
static unsigned __slots, __caps
|
||
|
static list *__slot_admin, *__cap_admin
|
||
|
static list *__first_free_slot, *__first_free_cap
|
||
|
|
||
|
Receiver __my_receiver
|
||
|
Thread __my_thread
|
||
|
Memory __my_memory
|
||
|
Caps __my_caps
|
||
|
Cap __my_call
|
||
|
Cap __my_parent
|
||
|
Caps __tmp_caps
|
||
|
|
||
|
void free_slot (unsigned slot):
|
||
|
__slot_admin[slot].prev = NULL
|
||
|
__slot_admin[slot].next = __first_free_slot
|
||
|
if __slot_admin[slot].next:
|
||
|
__slot_admin[slot].next->prev = &__slot_admin[slot]
|
||
|
__first_free_slot = &__slot_admin[slot]
|
||
|
|
||
|
void free_cap (Cap cap):
|
||
|
list *l = &__cap_admin[cap.idx ()]
|
||
|
l->prev = NULL
|
||
|
l->next = __first_free_cap
|
||
|
if l->next:
|
||
|
l->next->prev = l
|
||
|
__first_free_cap = l
|
||
|
|
||
|
unsigned alloc_slot ():
|
||
|
if !__first_free_slot:
|
||
|
// Out of slots... Probably best to raise an exception. For now, just return NO_SLOT.
|
||
|
return ~0
|
||
|
list *ret = __first_free_slot
|
||
|
__first_free_slot = ret->next
|
||
|
if ret->next:
|
||
|
ret->next->prev = NULL
|
||
|
|
||
|
unsigned alloc_cap ():
|
||
|
if !__first_free_cap:
|
||
|
// Out of caps... Probably best to raise an exception. For now, just return NO_SLOT.
|
||
|
return ~0
|
||
|
list *ret = __first_free_cap
|
||
|
__first_free_cap = ret->next
|
||
|
if ret->next:
|
||
|
ret->next->prev = NULL
|
||
|
return ret - __slot_admin
|
||
|
|
||
|
extern "C":
|
||
|
void __main (unsigned slots, unsigned caps, list *slot_admin, list *cap_admin):
|
||
|
__slots = slots
|
||
|
__caps = caps
|
||
|
__slot_admin = slot_admin
|
||
|
__cap_admin = cap_admin
|
||
|
__first_free_slot = NULL
|
||
|
for unsigned i = 1; i < __slots; ++i:
|
||
|
free_slot (i)
|
||
|
__first_free_cap = NULL
|
||
|
for unsigned i = 7; i < __caps; ++i:
|
||
|
free_cap (Cap (0, i))
|
||
|
__my_receiver = Cap (0, __receiver_num)
|
||
|
__my_thread = Cap (0, __thread_num)
|
||
|
__my_memory = Cap (0, __memory_num)
|
||
|
__my_caps = Cap (0, __caps_num)
|
||
|
__my_call = Cap (0, __call_num)
|
||
|
__my_parent = Cap (0, __parent_num)
|
||
|
__tmp_caps = Cap (0, __tmp_num)
|
||
|
Num ret = start ()
|
||
|
__my_parent.invoke (~0, ret)
|
||
|
__my_memory.destroy (__my_thread)
|
||
|
// The program no longer exists. If it somehow does, generate an address fault.
|
||
|
while true:
|
||
|
*(volatile unsigned *)~0
|
||
|
|
||
|
__asm__ volatile ("\t.globl __start\n"
|
||
|
"\t.set noreorder\n"
|
||
|
"__start:\n"
|
||
|
"\tbal 1f\n"
|
||
|
"__hack_label:\n"
|
||
|
"\tnop\n"
|
||
|
"\t.word _gp\n"
|
||
|
"1:\n"
|
||
|
"\tlw $gp, 0($ra)\n"
|
||
|
"\tsll $v0, $a0, 3\n"
|
||
|
"\tsll $v1, $a1, 3\n"
|
||
|
"\tsubu $sp, $sp, $v0\n"
|
||
|
"\tmove $a2, $sp\n"
|
||
|
"\tsubu $sp, $sp, $v1\n"
|
||
|
"\tmove $a3, $sp\n"
|
||
|
"\tla $t9, __main\n"
|
||
|
"\tjr $t9\n"
|
||
|
"\tnop\n"
|
||
|
"\t.set reorder")
|