1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00

make things work with unfinished new startup procedure

This commit is contained in:
Bas Wijnen
2010-04-30 23:13:49 +02:00
parent 7c43204a7e
commit 12bfb320f7
37 changed files with 2374 additions and 1649 deletions

View File

@@ -38,7 +38,7 @@ void kPage_arch_init (kPage *page):
page->arch.prev_mapped = NULL
page->arch.next_mapped = NULL
void kThread_arch_receive (kThread *thread, Kernel::Num protected_data, Kernel::Num *data):
void kThread_arch_receive (kThread *thread, Iris::Num protected_data, Iris::Num *data):
thread->arch.a[0] = data[0].l
thread->arch.a[1] = data[0].h
thread->arch.a[2] = data[1].l
@@ -161,12 +161,12 @@ static unsigned make_entry_lo (kPage *page):
//kdebug ("not mapping because there is no frame\n")
return 0
unsigned flags
if page->flags & Kernel::Page::UNCACHED:
if page->flags & Iris::Page::UNCACHED:
flags = 0x10 | 0x2
else:
// 18 is write-back cache; 00 is write-through cache.
flags = 0x18 | 0x2
if ~page->flags & Kernel::Page::MAPPED_READONLY:
if ~page->flags & Iris::Page::MAPPED_READONLY:
flags |= 0x4
return ((page->frame & ~0x80000000) >> 6) | flags

View File

@@ -33,7 +33,7 @@ static void init_idle ():
idle.schedule_next = NULL
idle.address_space = &idle_memory
idle.refs.reset ()
idle.flags = Kernel::Thread::RUNNING | Kernel::Thread::PRIV
idle.flags = Iris::Thread::RUNNING | Iris::Thread::PRIV
// initialize idle_memory.
idle_memory.prev = NULL
idle_memory.next = NULL
@@ -52,7 +52,7 @@ static void init_idle ():
idle_page.prev = NULL
idle_page.next = NULL
idle_page.frame = 0x80000000
idle_page.flags = Kernel::Page::PAYING | Kernel::Page::FRAME
idle_page.flags = Iris::Page::PAYING | Iris::Page::FRAME
idle_page.refs.reset ()
idle_page.address_space = NULL
current = &idle
@@ -147,7 +147,7 @@ static void init_threads ():
return
thread->pc = header->e_entry
thread->sp = 0x80000000
unsigned *used = (unsigned *)mem->zalloc ()
kPage **used = (kPage **)mem->zalloc ()
for unsigned section = 0; section < header->e_shnum; ++section:
Elf32_Shdr *shdr = (Elf32_Shdr *)(thread_start[i] + header->e_shoff + section * header->e_shentsize)
if ~shdr->sh_flags & SHF_ALLOC:
@@ -168,12 +168,19 @@ static void init_threads ():
panic (0, "different pages mapped to one address in intitial file")
return
continue
used[idx] = 1
page = mem->alloc_page ()
page->frame = thread_start[i] + (idx << PAGE_BITS)
page->flags = Kernel::Page::PAYING | Kernel::Page::FRAME
page->flags = Iris::Page::PAYING | Iris::Page::FRAME
if used[idx]:
page->share_next = used[idx]
used[idx]->share_prev = page
used[idx]->flags |= Iris::Page::SHARED
used[idx] = page
page->flags |= Iris::Page::SHARED
else:
used[idx] = page
if readonly:
page->flags |= Kernel::Page::MAPPED_READONLY
page->flags |= Iris::Page::MAPPED_READONLY
if !mem->map (page, p):
panic (0x22446688, "unable to map initial page")
return
@@ -200,7 +207,7 @@ static void init_threads ():
if !page->frame:
panic (0x02220022, "out of memory");
return
page->flags = Kernel::Page::PAYING | Kernel::Page::FRAME
page->flags = Iris::Page::PAYING | Iris::Page::FRAME
if !mem->map (page, p):
panic (0x33557799, "unable to map initial bss page")
return
@@ -210,7 +217,7 @@ static void init_threads ():
kdebug_num (i, 1)
kdebug ('\n')
else:
if page->flags & Kernel::Page::MAPPED_READONLY:
if page->flags & Iris::Page::MAPPED_READONLY:
panic (0x20203030, "bss section starts on read-only page")
return
for unsigned a = p; a < ((p + PAGE_SIZE) & PAGE_MASK); a += 4:
@@ -230,7 +237,7 @@ static void init_threads ():
mem->pfree ((unsigned)used)
kPage *stackpage = mem->alloc_page ()
stackpage->frame = mem->zalloc ()
stackpage->flags = Kernel::Page::PAYING | Kernel::Page::FRAME
stackpage->flags = Iris::Page::PAYING | Iris::Page::FRAME
if !stackpage || !mem->map (stackpage, 0x7ffff000):
panic (0x13151719, "unable to map initial stack page")
return
@@ -242,11 +249,12 @@ static void init_threads ():
kReceiver *recv = mem->alloc_receiver ()
recv->owner = thread
thread->receivers = recv
thread->slot[0].caps->set (__receiver_num, (kReceiverP)(CAPTYPE_RECEIVER | CAP_MASTER), Kernel::Num ((unsigned)recv), kCapRef (), &recv->refs)
thread->slot[0].caps->set (__thread_num, (kReceiverP)(CAPTYPE_THREAD | CAP_MASTER), Kernel::Num ((unsigned)thread), kCapRef (), &thread->refs)
thread->slot[0].caps->set (__memory_num, (kReceiverP)(CAPTYPE_MEMORY | CAP_MASTER), Kernel::Num ((unsigned)mem), kCapRef (), &mem->refs)
thread->slot[0].caps->set (__call_num, (kReceiverP)(CAPTYPE_RECEIVER | Kernel::Receiver::CALL), Kernel::Num ((unsigned)recv), kCapRef (), &recv->refs)
thread->flags = Kernel::Thread::RUNNING | Kernel::Thread::PRIV
thread->slot[0].caps->set (__caps_num, (kReceiverP)(CAPTYPE_CAPS | CAP_MASTER), Iris::Num ((unsigned)thread->slot[0].caps), kCapRef (), &thread->slot[0].caps->refs)
thread->slot[0].caps->set (__receiver_num, (kReceiverP)(CAPTYPE_RECEIVER | CAP_MASTER), Iris::Num ((unsigned)recv), kCapRef (), &recv->refs)
thread->slot[0].caps->set (__thread_num, (kReceiverP)(CAPTYPE_THREAD | CAP_MASTER), Iris::Num ((unsigned)thread), kCapRef (), &thread->refs)
thread->slot[0].caps->set (__memory_num, (kReceiverP)(CAPTYPE_MEMORY | CAP_MASTER), Iris::Num ((unsigned)mem), kCapRef (), &mem->refs)
thread->slot[0].caps->set (__call_num, (kReceiverP)(CAPTYPE_RECEIVER | Iris::Receiver::CALL), Iris::Num ((unsigned)recv), kCapRef (), &recv->refs)
thread->flags = Iris::Thread::RUNNING | Iris::Thread::PRIV
if !i:
first_scheduled = thread
init_receiver = recv

View File

@@ -33,7 +33,7 @@ static kThread *handle_exit ():
schedule ()
if !current:
current = &idle
if (current->flags & (Kernel::Thread::RUNNING | Kernel::Thread::WAITING)) != Kernel::Thread::RUNNING:
if (current->flags & (Iris::Thread::RUNNING | Iris::Thread::WAITING)) != Iris::Thread::RUNNING:
panic (current->flags, "non-scheduled thread running")
if old_current == current:
return current
@@ -54,7 +54,7 @@ static kThread *handle_exit ():
asids[current->address_space->arch.asid] = (unsigned)current->address_space
cp0_set (CP0_ENTRY_HI, current->address_space->arch.asid)
directory = current->address_space->arch.directory
if current->flags & Kernel::Thread::PRIV:
if current->flags & Iris::Thread::PRIV:
cp0_set (CP0_STATUS, 0x1000ff13)
else:
cp0_set (CP0_STATUS, 0x0000ff13)
@@ -69,7 +69,7 @@ kThread *tlb_refill ():
if !directory:
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_NO_PAGE_DIRECTORY, addr)
current->raise (Iris::ERR_NO_PAGE_DIRECTORY, addr)
return handle_exit ()
unsigned EntryHi
cp0_get (CP0_ENTRY_HI, EntryHi)
@@ -77,7 +77,7 @@ kThread *tlb_refill ():
if !t:
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_NO_PAGE_TABLE, addr)
current->raise (Iris::ERR_NO_PAGE_TABLE, addr)
else:
// - 2 instead of - 1 means reset bit 0
unsigned idx = (EntryHi >> 12) & ((1 << 9) - 2)
@@ -161,13 +161,22 @@ static void arch_invoke ():
return
msg.reply = old_current->find_capability (old_current->arch.t[0], &msg.copy[0])
msg.arg = old_current->find_capability (old_current->arch.t[1], &msg.copy[1])
msg.data[0] = Kernel::Num (old_current->arch.a[0], old_current->arch.a[1])
msg.data[1] = Kernel::Num (old_current->arch.a[2], old_current->arch.a[3])
msg.data[0] = Iris::Num (old_current->arch.a[0], old_current->arch.a[1])
msg.data[1] = Iris::Num (old_current->arch.a[2], old_current->arch.a[3])
dbg_push (old_current->arch.v[0])
dbg_push (old_current->arch.t[0])
dbg_push (old_current->arch.t[1])
dbg_push (old_current->arch.a[0])
dbg_push (old_current->arch.a[1])
dbg_push (old_current->arch.a[2])
dbg_push (old_current->arch.a[3])
dbg_push (0xdeadbeef)
target->invoke (&msg)
dbg_push (0xfacebeef)
if do_schedule && !must_wait:
// If the call was to schedule without wait, it isn't done yet.
schedule ()
else if old_current != current && (old_current->flags & (Kernel::Thread::RUNNING | Kernel::Thread::WAITING)) == Kernel::Thread::RUNNING:
else if old_current != current && old_current && (old_current->flags & (Iris::Thread::RUNNING | Iris::Thread::WAITING)) == Iris::Thread::RUNNING:
// If the caller received an immediate reply from the kernel, it is no longer set as current. Don't let it lose its timeslice.
current = old_current
@@ -186,31 +195,31 @@ kThread *exception ():
// TLB modification.
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_WRITE_DENIED, addr)
current->raise (Iris::ERR_WRITE_DENIED, addr)
break
case 2:
// TLB load or instruction fetch.
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_UNMAPPED_READ, addr)
current->raise (Iris::ERR_UNMAPPED_READ, addr)
break
case 3:
// TLB store.
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_UNMAPPED_WRITE, addr)
current->raise (Iris::ERR_UNMAPPED_WRITE, addr)
break
case 4:
// Address error load or instruction fetch.
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_INVALID_ADDRESS_READ, addr)
current->raise (Iris::ERR_INVALID_ADDRESS_READ, addr)
break
case 5:
// Address error store.
unsigned addr
cp0_get (CP0_BAD_V_ADDR, addr)
current->raise (Kernel::ERR_INVALID_ADDRESS_WRITE, addr)
current->raise (Iris::ERR_INVALID_ADDRESS_WRITE, addr)
break
case 6:
// Bus error instruction fetch.
@@ -229,7 +238,7 @@ kThread *exception ():
case 9:
// Breakpoint.
#if 0 || defined (NDEBUG)
//current->raise (Kernel::ERR_BREAKPOINT, 0)
//current->raise (Iris::ERR_BREAKPOINT, 0)
#ifndef NDEBUG
current->pc += 4
#endif
@@ -251,19 +260,19 @@ kThread *exception ():
break
case 10:
// Reserved instruction.
current->raise (Kernel::ERR_RESERVED_INSTRUCTION, 0)
current->raise (Iris::ERR_RESERVED_INSTRUCTION, 0)
break
case 11:
// Coprocessor unusable.
current->raise (Kernel::ERR_COPROCESSOR_UNUSABLE, 0)
current->raise (Iris::ERR_COPROCESSOR_UNUSABLE, 0)
break
case 12:
// Arithmetic overflow.
current->raise (Kernel::ERR_OVERFLOW, 0)
current->raise (Iris::ERR_OVERFLOW, 0)
break
case 13:
// Trap.
current->raise (Kernel::ERR_TRAP, 0)
current->raise (Iris::ERR_TRAP, 0)
break
case 15:
// Floating point exception.
@@ -272,7 +281,7 @@ kThread *exception ():
case 23:
// Reference to WatchHi/WatchLo address.
cp0_set0 (CP0_WATCH_LO)
current->raise (Kernel::ERR_WATCHPOINT, 0)
current->raise (Iris::ERR_WATCHPOINT, 0)
break
case 24:
// Machine check.

View File

@@ -28,12 +28,12 @@ LDFLAGS = --omagic -Ttext $(load)
arch_iris_sources = mips/interrupts.cc mips/arch.cc
boot_sources = mips/init.cc mips/nanonote/board.cc
arch_headers = mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh devices.hh
boot_threads = init udc
programs = \#nanonote-gpio \#lcd display-emu bsquare display-emu2 ball \#buzzer metronome
boot_threads = bootinit udc
programs = init gpio lcd display-emu bsquare ball buzzer metronome elfrun
all: test
test: iris.raw mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw $(addsuffix .elf,$(addprefix fs/,$(programs)))
test: iris.raw mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw $(addsuffix .elf,$(addprefix fs/,$(programs))) fs/init.config
echo "reboot 0xa$(shell /bin/sh -c '$(OBJDUMP) -t iris.elf | grep __start$$ | cut -b2-8')" | nc localhost 5050
mips/nanonote/server/usb-server: mips/nanonote/server/usb-server.ccp mips/nanonote/server/Makefile.am mips/nanonote/server/configure.ac devices.hh
@@ -55,12 +55,15 @@ mips/nanonote/sdram-setup.elf: LDFLAGS = --omagic -T mips/nanonote/sdram-setup.l
mips/nanonote/threadlist.o: $(addsuffix .elf,$(boot_threads))
mips/boot.o: TARGET_FLAGS = -DMEMORY_SIZE="32 << 20"
mips/init.o: TARGET_FLAGS = -I/usr/include
boot-programs/init.o: TARGET_FLAGS = -I/usr/include
boot-programs/bootinit.o: TARGET_FLAGS = -I/usr/include
source/elfrun.o: TARGET_FLAGS = -I/usr/include
source/gpio.ccp: source/nanonote-gpio.ccp
ln -s $(subst source/,,$<) $@
$(addsuffix .elf,$(boot_threads)): TARGET_FLAGS = -I.
$(addsuffix .elf,$(boot_threads)): LDFLAGS = -EL
$(addprefix fs/,$(addsuffix .elf,$(programs))): LDFLAGS = -EL
$(addprefix boot-programs/,$(addsuffix .cc,$(boot_threads))): devices.hh keys.hh
source/\#lcd.o: source/charset.data
source/lcd.o: source/charset.data
source/charset.data: source/charset
$< > $@

View File

@@ -104,14 +104,14 @@
// Default lcd framebuffer mapping space.
#define LCD_FRAMEBUFFER_BASE ((unsigned *)0x00015000)
// Map IO memory (requires a priviledged Kernel::my_thread capability).
// Map IO memory (requires a priviledged Iris::my_thread capability).
#include <iris.hh>
static void __map_io (unsigned physical, unsigned mapping):
Kernel::Page p = Kernel::my_memory.create_page ()
Iris::Page p = Iris::my_memory.create_page ()
// false means not cachable; false means don't free when done.
p.alloc_physical (physical, false, false)
Kernel::my_memory.map (p, mapping)
Kernel::free_cap (p)
Iris::my_memory.map (p, mapping)
Iris::free_cap (p)
#define map_cpm() do { __map_io (CPM_PHYSICAL, CPM_BASE); } while (0)
#define map_intc() do { __map_io (INTC_PHYSICAL, INTC_BASE); } while (0)
@@ -135,8 +135,8 @@ static void __map_io (unsigned physical, unsigned mapping):
// udelay implementation
void cdelay (unsigned cs):
Kernel::my_receiver.set_alarm (cs + 1)
Kernel::Cap ().call ()
Iris::my_receiver.set_alarm (cs + 1)
Iris::Cap ().call ()
#endif

View File

@@ -105,37 +105,37 @@ void data::poll ():
case ~1 & 0xffff:
// No event.
break
case Directory::GET_SIZE:
case Iris::Directory::GET_SIZE:
unsigned long long size = dir.size ()
std::cerr << "sending dir size\n"
std::cerr << Directory::GET_SIZE << '\n'
std::cerr << Iris::Directory::GET_SIZE << '\n'
char *str = (char *)&size
for unsigned i = 0; i < 8; ++i:
std::cerr << " " << (unsigned)(str[i] & 0xff)
std::cerr << '\n'
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Iris::Directory::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
handle = NULL
return
continue
case Directory::GET_NAME:
case Iris::Directory::GET_NAME:
if buffer[1] >= dir.size ():
std::cerr << "invalid file name requested" << std::endl;
usb_release_interface (handle, 0)
usb_close (handle)
handle = NULL
return
std::cerr << "sending filename\n"
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_NAME, 0, 0, dir[buffer[1]].name, 16, timeout) != 16:
std::cerr << "sending filename " << dir[buffer[1]].full << "\n"
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Iris::Directory::GET_NAME, 0, 0, dir[buffer[1]].name, 16, timeout) != 16:
std::cerr << "unable to send name to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
handle = NULL
return
continue
case Directory::LOCK_RO:
case Iris::Directory::LOCK_RO:
std::cerr << "lock\n"
lock++
std::cerr << "freezing file list\n"
@@ -145,7 +145,7 @@ void data::poll ():
if !i->name.empty () && i->name[0] != '.':
dir.push_back (Name (i->name))
continue
case Directory::UNLOCK_RO:
case Iris::Directory::UNLOCK_RO:
std::cerr << "unlock\n"
if !lock:
std::cerr << "unlocking without lock" << std::endl
@@ -156,7 +156,7 @@ void data::poll ():
if !--lock:
dir.clear ()
continue
case String::GET_PAGE:
case Iris::String::GET_PAGE:
if buffer[1] >= dir.size ():
std::cerr << "reading invalid file" << std::endl
usb_release_interface (handle, 0)
@@ -178,16 +178,16 @@ void data::poll ():
handle = NULL
return
continue
case String::GET_SIZE:
case Iris::String::GET_SIZE:
if buffer[1] >= dir.size ():
std::cerr << "reading invalid file size" << std::endl
std::cerr << "reading invalid file size " << buffer[1] << " >= " << dir.size () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
handle = NULL
return
unsigned long long size = dir[buffer[1]].content.size ()
std::cerr << "sending file size " << size << "\n"
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, String::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Iris::String::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
@@ -312,18 +312,18 @@ void data::boot (unsigned entry):
std::cerr << "(re)booted NanoNote\n"
static void dump_devices ():
std::cerr << std::hex << "String: " << String::ID
std::cerr << "\nWString: " << WString::ID
std::cerr << "\nDevice: " << Device::ID
std::cerr << "\nParent: " << Parent::ID
std::cerr << "\nKeyboard: " << Keyboard::ID
std::cerr << "\nBuzzer: " << Buzzer::ID
std::cerr << "\nDisplay: " << Display::ID
std::cerr << "\nSetting: " << Setting::ID
std::cerr << "\nDirectory: " << Directory::ID
std::cerr << "\nWDirectory: " << WDirectory::ID
std::cerr << "\nFilesystem: " << Filesystem::ID
std::cerr << "\nStream: " << Stream::ID
std::cerr << std::hex << "String: " << Iris::String::ID
std::cerr << "\nWString: " << Iris::WString::ID
std::cerr << "\nDevice: " << Iris::Device::ID
std::cerr << "\nParent: " << Iris::Parent::ID
std::cerr << "\nKeyboard: " << Iris::Keyboard::ID
std::cerr << "\nBuzzer: " << Iris::Buzzer::ID
std::cerr << "\nDisplay: " << Iris::Display::ID
std::cerr << "\nSetting: " << Iris::Setting::ID
std::cerr << "\nDirectory: " << Iris::Directory::ID
std::cerr << "\nWDirectory: " << Iris::WDirectory::ID
std::cerr << "\nFilesystem: " << Iris::Filesystem::ID
std::cerr << "\nStream: " << Iris::Stream::ID
std::cerr << "\n"
int main (int argc, char **argv):

View File

@@ -21,7 +21,7 @@
.balign 0x1000
thread0:
.incbin "init.elf"
.incbin "bootinit.elf"
.balign 0x1000
thread1:

View File

@@ -137,14 +137,14 @@
// Default lcd framebuffer mapping space.
#define LCD_FRAMEBUFFER_BASE ((unsigned short *)0x00021000)
// Map IO memory (requires a priviledged Kernel::my_thread capability).
// Map IO memory (requires a priviledged Iris::my_thread capability).
#include <iris.hh>
static void __map_io (unsigned physical, unsigned mapping):
Kernel::Page p = Kernel::my_memory.create_page ()
Iris::Page p = Iris::my_memory.create_page ()
// false means not cachable; false means don't free when done.
p.alloc_physical (physical, false, false)
Kernel::my_memory.map (p, mapping)
Kernel::free_cap (p)
Iris::my_memory.map (p, mapping)
Iris::free_cap (p)
#define map_harb() do { __map_io (HARB_PHYSICAL, HARB_BASE); } while (0)
#define map_emc() do { __map_io (EMC_PHYSICAL, EMC_BASE); } while (0)
@@ -2326,8 +2326,8 @@ static __inline__ void udelay (unsigned us):
#ifndef __KERNEL__
static __inline__ void cdelay (unsigned ds):
Kernel::my_receiver.set_alarm (ds * (HZ / 100))
Kernel::Cap ().call (~0)
Iris::my_receiver.set_alarm (ds * (HZ / 100))
Iris::Cap ().call (~0)
#endif
/***************************************************************************