mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-12-29 02:39:53 +02:00
almost working
This commit is contained in:
parent
05f79658e1
commit
f1c608288f
10
alloc.ccp
10
alloc.ccp
@ -177,6 +177,9 @@ kPage *kMemory::alloc_page ():
|
||||
ret->frame = 0
|
||||
ret->flags = 0
|
||||
ret->mapping = ~0
|
||||
ret->share_prev = NULL
|
||||
ret->share_next = NULL
|
||||
kPage_arch_init (ret)
|
||||
return ret
|
||||
|
||||
kThread *kMemory::alloc_thread (unsigned size):
|
||||
@ -196,6 +199,9 @@ kThread *kMemory::alloc_thread (unsigned size):
|
||||
ret->slot[i].prev.thread = NULL
|
||||
ret->slot[i].next.thread = NULL
|
||||
ret->slot[i].caps = NULL
|
||||
//dbg_log ("new thread: ")
|
||||
//dbg_log_num ((unsigned)ret)
|
||||
//dbg_log ("\n")
|
||||
return ret
|
||||
|
||||
void kCaps::init (unsigned s):
|
||||
@ -466,6 +472,10 @@ void kMemory::free_memory (kMemory *mem):
|
||||
free_obj (mem, (void **)&memories)
|
||||
|
||||
void kPage::forget ():
|
||||
//dbg_log ("forget ")
|
||||
//dbg_log_num ((unsigned)this)
|
||||
//dbg_log ("\n")
|
||||
dbg_code.l = (unsigned)old_current
|
||||
if share_prev || share_next:
|
||||
if share_prev:
|
||||
share_prev->share_next = share_next
|
||||
|
@ -133,11 +133,6 @@ static void list_files (Directory root):
|
||||
for unsigned i = 0; i < num_files; ++i:
|
||||
String n = root.get_name (i)
|
||||
n.get_chars (0, files[i].name)
|
||||
kdebug ("file: ")
|
||||
for unsigned j = 0; j < 16; ++j:
|
||||
if files[i].name[j] != 0:
|
||||
kdebug_char (files[i].name[j])
|
||||
kdebug_char ('\n')
|
||||
Kernel::free_cap (n)
|
||||
Kernel::set_recv_arg (Kernel::Cap (slot, i))
|
||||
files[i].string = root.get_file_ro (i)
|
||||
@ -326,6 +321,13 @@ static void run (file *f, bool priv):
|
||||
Kernel::free_cap (parent)
|
||||
Kernel::free_cap (caps)
|
||||
|
||||
static void kdebug_name (char const *t, file *f):
|
||||
kdebug (t)
|
||||
for unsigned j = 0; j < 16; ++j:
|
||||
if f->name[j] != 0:
|
||||
kdebug_char (f->name[j])
|
||||
kdebug ("...")
|
||||
|
||||
Kernel::Num start ():
|
||||
// Wait for the debugging device to be active, in case there is one.
|
||||
Kernel::schedule ()
|
||||
@ -339,7 +341,10 @@ Kernel::Num start ():
|
||||
slot = caps.use ()
|
||||
mapping = alloc_space (max_pages)
|
||||
for unsigned i = 0; i < num_files; ++i:
|
||||
kdebug_name ("loading ", &files[index[i]])
|
||||
run (&files[index[i]], files[index[i]].name[0] == '#')
|
||||
kdebug ("running\n")
|
||||
Kernel::schedule ()
|
||||
root.unlock_ro ()
|
||||
Kernel::free_slot (slot)
|
||||
Kernel::my_memory.destroy (caps)
|
||||
|
23
invoke.ccp
23
invoke.ccp
@ -48,7 +48,10 @@ static void log_message (char const *prefix, unsigned target, unsigned pdata, kC
|
||||
|
||||
void kThread::raise (unsigned code, unsigned data):
|
||||
dbg_log ("raise ")
|
||||
if old_current:
|
||||
dbg_log_num (old_current->id, 2)
|
||||
else:
|
||||
dbg_log ("xx")
|
||||
dbg_log_char (':')
|
||||
dbg_log_num ((unsigned)old_current)
|
||||
dbg_log_char ('/')
|
||||
@ -400,7 +403,7 @@ static void thread_invoke (unsigned cmd, unsigned target, Kernel::Num protected_
|
||||
return
|
||||
case Kernel::Thread::SET_INFO & REQUEST_MASK:
|
||||
unsigned *value
|
||||
switch c->data[1].l:
|
||||
switch c->data[0].h:
|
||||
case Kernel::Thread::PC:
|
||||
value = &thread->pc
|
||||
break
|
||||
@ -422,11 +425,11 @@ static void thread_invoke (unsigned cmd, unsigned target, Kernel::Num protected_
|
||||
if (v & Kernel::Thread::RUNNING) != (*value & Kernel::Thread::RUNNING):
|
||||
if v & Kernel::Thread::RUNNING:
|
||||
thread->run ()
|
||||
else
|
||||
else:
|
||||
thread->unrun ()
|
||||
break
|
||||
default:
|
||||
value = kThread_arch_info (thread, c->data[1].l)
|
||||
value = kThread_arch_info (thread, c->data[0].h)
|
||||
break
|
||||
if value:
|
||||
*value = (*value & ~c->data[1].h) | (c->data[1].l & c->data[1].h)
|
||||
@ -479,6 +482,7 @@ static void thread_invoke (unsigned cmd, unsigned target, Kernel::Num protected_
|
||||
return
|
||||
case Kernel::Thread::PRIV_MAKE_PRIV & REQUEST_MASK:
|
||||
if !c->arg.valid () || ((unsigned)c->arg->target) & ~REQUEST_MASK != CAPTYPE_THREAD:
|
||||
dpanic (0, "not a thread argument for make priv")
|
||||
reply_num (Kernel::ERR_INVALID_ARGUMENT)
|
||||
return
|
||||
((kThread *)c->arg->protected_data.l)->flags |= Kernel::Thread::PRIV
|
||||
@ -556,7 +560,7 @@ static void thread_invoke (unsigned cmd, unsigned target, Kernel::Num protected_
|
||||
|
||||
static void page_check_payment (kPage *page):
|
||||
kPage *p
|
||||
for p = page->share_prev; p; p = p->share_prev:
|
||||
for p = page; p; p = p->share_prev:
|
||||
if p->flags & Kernel::Page::PAYING:
|
||||
return
|
||||
for p = page->share_next; p; p = p->share_next:
|
||||
@ -565,7 +569,7 @@ static void page_check_payment (kPage *page):
|
||||
// No kPage is paying for this frame anymore.
|
||||
raw_pfree (page->frame)
|
||||
kPage *next
|
||||
for p = page->share_prev, next = p->share_prev; p; p = next, next = p->share_prev:
|
||||
for p = page->share_prev, next = (p ? p->share_prev : NULL); p; p = next, next = p->share_prev:
|
||||
p->frame = NULL
|
||||
p->share_prev = NULL
|
||||
p->share_next = NULL
|
||||
@ -593,6 +597,7 @@ static void page_invoke (unsigned cmd, unsigned target, Kernel::Num protected_da
|
||||
reply_num (Kernel::ERR_INVALID_ARGUMENT)
|
||||
return
|
||||
kPage *t = (kPage *)c->arg->protected_data.l
|
||||
if t != page:
|
||||
t->forget ()
|
||||
if c->data[0].h & Kernel::Page::READONLY || cmd & Kernel::Page::READONLY:
|
||||
t->flags |= Kernel::Page::READONLY
|
||||
@ -623,6 +628,10 @@ static void page_invoke (unsigned cmd, unsigned target, Kernel::Num protected_da
|
||||
t->frame = raw_zalloc ()
|
||||
for unsigned i = 0; i < PAGE_SIZE; i += 4:
|
||||
((unsigned *)t->frame)[i >> 2] = d[i >> 2]
|
||||
if c->data[0].h & Kernel::Page::FORGET:
|
||||
page->frame = NULL
|
||||
page->flags &= ~Kernel::Page::FRAME
|
||||
kPage_arch_update_mapping (page)
|
||||
else:
|
||||
if t != page:
|
||||
t->frame = page->frame
|
||||
@ -630,6 +639,8 @@ static void page_invoke (unsigned cmd, unsigned target, Kernel::Num protected_da
|
||||
page->frame = NULL
|
||||
page->flags &= ~Kernel::Page::FRAME
|
||||
kPage_arch_update_mapping (page)
|
||||
else:
|
||||
dpanic (0, "sharing page with itself...")
|
||||
else:
|
||||
if t == page:
|
||||
dpanic (0, "sharing page with itself")
|
||||
@ -640,6 +651,8 @@ static void page_invoke (unsigned cmd, unsigned target, Kernel::Num protected_da
|
||||
if t->flags & Kernel::Page::PAYING:
|
||||
t->frame = page->frame
|
||||
t->flags |= Kernel::Page::FRAME
|
||||
else:
|
||||
dpanic (0, "move page failed because target is not paying")
|
||||
page->frame = NULL
|
||||
page->flags &= ~Kernel::Page::FRAME
|
||||
kPage_arch_update_mapping (page)
|
||||
|
@ -170,7 +170,6 @@ struct kPage : public kObject:
|
||||
unsigned frame
|
||||
unsigned flags
|
||||
unsigned mapping
|
||||
kPageP share_first
|
||||
kPageP share_prev, share_next
|
||||
kPage_arch arch
|
||||
void forget ()
|
||||
@ -306,6 +305,7 @@ void kMemory_arch_free (kMemory *mem)
|
||||
bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address)
|
||||
void kMemory_arch_unmap (kMemory *mem, kPage *page)
|
||||
kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address)
|
||||
void kPage_arch_init (kPage *page)
|
||||
void kPage_arch_update_mapping (kPage *page)
|
||||
void arch_register_interrupt (unsigned num, kReceiverP r)
|
||||
void arch_reboot ()
|
||||
@ -314,6 +314,7 @@ void arch_uncache_page (unsigned page)
|
||||
bool kMemory::map (kPage *page, unsigned address):
|
||||
return kMemory_arch_map (this, page, address)
|
||||
void kMemory::unmap (kPage *page):
|
||||
page->forget ()
|
||||
kMemory_arch_unmap (this, page)
|
||||
kPage *kMemory::get_mapping (unsigned address):
|
||||
return kMemory_arch_get_mapping (this, address)
|
||||
|
@ -34,6 +34,10 @@ void kThread_arch_init (kThread *thread):
|
||||
thread->arch.hi = 0
|
||||
thread->arch.lo = 0
|
||||
|
||||
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):
|
||||
thread->arch.a[0] = data[0].l
|
||||
thread->arch.a[1] = data[0].h
|
||||
|
@ -29,7 +29,7 @@ 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
|
||||
boot_threads = init udc
|
||||
programs = nanonote-gpio buzzer metronome lcd
|
||||
programs = \#nanonote-gpio \#buzzer \#lcd
|
||||
|
||||
all: test
|
||||
|
||||
|
@ -72,7 +72,7 @@ void board_init ():
|
||||
UART0_DLLR = uart_div
|
||||
UART0_LCR = UARTLCR_WLEN_8 | UARTLCR_STOP1
|
||||
UART0_FCR = UARTFCR_UUE | UARTFCR_FE | UARTFCR_RFLS | UARTFCR_TFLS
|
||||
dbg_log ("Serial port initialized\n")
|
||||
dbg_log ("\n\nSerial port initialized\n")
|
||||
#endif
|
||||
|
||||
void arch_reboot ():
|
||||
|
@ -39,7 +39,7 @@ struct data:
|
||||
static int const boot_product = 0x4740
|
||||
static int const run_vendor = 0xfffe
|
||||
static int const run_product = 0x0002
|
||||
static unsigned const timeout = 1000
|
||||
static unsigned const timeout = 10000
|
||||
void boot (unsigned entry)
|
||||
data (std::string const &port):
|
||||
handle = NULL
|
||||
@ -75,10 +75,15 @@ static std::string files ("fs")
|
||||
struct Name:
|
||||
char name[16]
|
||||
std::string full
|
||||
std::string content
|
||||
Name (std::string const &n):
|
||||
full = files + '/' + n
|
||||
memset (name, 0, 16)
|
||||
memcpy (name, n.data (), n.size () > 16 ? 16 : n.size ())
|
||||
std::ifstream f (full.c_str ())
|
||||
std::ostringstream s
|
||||
s << f.rdbuf ()
|
||||
content = s.str ()
|
||||
static std::vector <Name> dir
|
||||
unsigned lock (0)
|
||||
|
||||
@ -160,15 +165,13 @@ void data::poll ():
|
||||
return
|
||||
unsigned pos = buffer[0] >> 16
|
||||
std::cerr << "getting data from " << pos << '\n'
|
||||
std::ifstream file (dir[buffer[1]].full.c_str ())
|
||||
file.seekg (pos << 12)
|
||||
char page[1 << 12]
|
||||
memset (page, 0, 1 << 12)
|
||||
file.read (page, 1 << 12)
|
||||
shevek::dump (std::string (page, 32), std::cerr)
|
||||
std::cerr << "sending bulk\n"
|
||||
std::string page
|
||||
if dir[buffer[1]].content.size () <= pos << 12:
|
||||
page = std::string (1 << 12, 0)
|
||||
else:
|
||||
page = (dir[buffer[1]].content.substr (pos << 12, 1 << 12) + std::string (1 << 12, 0)).substr (0, 1 << 12)
|
||||
for unsigned i = 0; i < (1 << 12); i += 64:
|
||||
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page[i], 64, timeout) != 64:
|
||||
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page.data ()[i], 64, timeout) != 64:
|
||||
std::cerr << "unable to send file to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
@ -182,9 +185,7 @@ void data::poll ():
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::ifstream file (dir[buffer[1]].full.c_str ())
|
||||
file.seekg (0, std::ios_base::end)
|
||||
unsigned long long size = file.tellg ()
|
||||
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:
|
||||
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
|
||||
|
81
panic.ccp
81
panic.ccp
@ -45,30 +45,54 @@ void dbg_log_num (unsigned num, unsigned digits):
|
||||
return
|
||||
|
||||
#if 1 || defined (NDEBUG)
|
||||
static void print_addr (char const *t, unsigned addr):
|
||||
dbg_log (t)
|
||||
dbg_log_num (addr)
|
||||
unsigned de = addr >> 21
|
||||
unsigned te = (addr >> 12) & ((1 << 9) - 1)
|
||||
if de < 0x400 && old_current && old_current->address_space->arch.directory && old_current->address_space->arch.directory[de]:
|
||||
dbg_log ("; page = ")
|
||||
dbg_log_num ((unsigned)old_current->address_space->arch.directory[de]->page[te])
|
||||
dbg_log ("; EntryLo = ")
|
||||
dbg_log_num (old_current->address_space->arch.directory[de]->entrylo[te])
|
||||
dbg_log ("\n")
|
||||
else:
|
||||
dbg_log ("; no directory or page table\n")
|
||||
if old_current:
|
||||
cp0_set (CP0_ENTRY_HI, (addr & (PAGE_MASK << 1)) | old_current->address_space->arch.asid)
|
||||
__asm__ volatile ("tlbp")
|
||||
unsigned idx, hi
|
||||
cp0_get (CP0_INDEX, idx)
|
||||
dbg_log ("tlb index: ")
|
||||
if idx & (1 << 31):
|
||||
dbg_log ("none")
|
||||
else:
|
||||
dbg_log_num (idx, 2)
|
||||
dbg_log ("; EntryLo = ")
|
||||
unsigned lo
|
||||
cp0_get (CP0_ENTRY_LO0, lo)
|
||||
dbg_log_num (lo)
|
||||
dbg_log (":")
|
||||
cp0_get (CP0_ENTRY_LO1, lo)
|
||||
dbg_log_num (lo)
|
||||
dbg_log ("\n")
|
||||
if addr >= 0x80000000:
|
||||
for int i = -4; i < 4; ++i:
|
||||
dbg_log (" ")
|
||||
dbg_log_num (((unsigned *)addr)[i])
|
||||
dbg_log ("\n")
|
||||
|
||||
static void panic_message (unsigned n, const char *line, char const *name, char const *message):
|
||||
//unsigned addr
|
||||
//cp0_get (CP0_BAD_V_ADDR, addr)
|
||||
//unsigned de = addr >> 21
|
||||
//unsigned te = (addr >> 12) & ((1 << 9) - 1)
|
||||
//dbg_log_num ((unsigned)old_current->address_space->arch.directory[de]->page[te])
|
||||
//dbg_log (":")
|
||||
//dbg_log_num (old_current->address_space->arch.directory[de]->entrylo[te])
|
||||
//dbg_log ("\n")
|
||||
//__asm__ volatile ("tlbp")
|
||||
//unsigned idx, hi
|
||||
//cp0_get (CP0_INDEX, idx)
|
||||
//dbg_log_num (idx)
|
||||
//dbg_log (":")
|
||||
//cp0_get (CP0_ENTRY_HI, hi)
|
||||
//dbg_log_num (hi)
|
||||
//dbg_log (":")
|
||||
//unsigned lo
|
||||
//cp0_get (CP0_ENTRY_LO0, lo)
|
||||
//dbg_log_num (lo)
|
||||
//dbg_log (":")
|
||||
//cp0_get (CP0_ENTRY_LO1, lo)
|
||||
//dbg_log_num (lo)
|
||||
//dbg_log ("\n")
|
||||
unsigned vaddr, epc
|
||||
cp0_get (CP0_BAD_V_ADDR, vaddr)
|
||||
cp0_get (CP0_EPC, epc)
|
||||
#if 1
|
||||
unsigned addr
|
||||
print_addr ("BadVAddr: ", vaddr)
|
||||
if old_current:
|
||||
print_addr ("PC: ", old_current->pc)
|
||||
print_addr ("epc: ", epc)
|
||||
#endif
|
||||
dbg_log ("Panic: caller = ")
|
||||
if old_current:
|
||||
dbg_log_num (old_current->id, 2)
|
||||
@ -85,15 +109,10 @@ static void panic_message (unsigned n, const char *line, char const *name, char
|
||||
dbg_log (message)
|
||||
dbg_log_char ('/')
|
||||
dbg_log_num (n)
|
||||
dbg_log_char (';')
|
||||
dbg_log ("; debug: ")
|
||||
dbg_log_num (dbg_code.h)
|
||||
dbg_log (" bad vaddr = ")
|
||||
unsigned a
|
||||
cp0_get (CP0_BAD_V_ADDR, a)
|
||||
dbg_log_num (a)
|
||||
dbg_log (" epc = ")
|
||||
cp0_get (CP0_EPC, a)
|
||||
dbg_log_num (a)
|
||||
dbg_log_char (':')
|
||||
dbg_log_num (dbg_code.l)
|
||||
dbg_log_char ('\n')
|
||||
|
||||
void panic_impl (unsigned n, const char *line, char const *name, char const *message):
|
||||
|
@ -53,7 +53,7 @@ enum codes:
|
||||
BUZZER = 32
|
||||
|
||||
Kernel::Num start ():
|
||||
Kernel::schedule ()
|
||||
kdebug ("buzzer started.\n")
|
||||
map_tcu ()
|
||||
|
||||
DevBuzzer buzzer
|
@ -253,7 +253,6 @@ enum codes:
|
||||
PWM
|
||||
|
||||
Kernel::Num start ():
|
||||
Kernel::schedule ()
|
||||
map_gpio ()
|
||||
map_pwm0 ()
|
||||
|
@ -195,7 +195,6 @@ enum codes:
|
||||
PWR
|
||||
|
||||
Kernel::Num start ():
|
||||
Kernel::schedule ()
|
||||
map_gpio ()
|
||||
|
||||
DevKbd kbd
|
@ -122,7 +122,8 @@ extern "C":
|
||||
while true:
|
||||
*(volatile unsigned *)~0
|
||||
|
||||
__asm__ volatile ("\t.globl __start\n"
|
||||
__asm__ volatile ("\t.text\n"
|
||||
"\t.globl __start\n"
|
||||
"\t.set noreorder\n"
|
||||
"__start:\n"
|
||||
"\tbal 1f\n"
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "keys.hh"
|
||||
|
||||
Kernel::Num start ():
|
||||
Kernel::schedule ()
|
||||
Buzzer buzzer = Kernel::my_parent.get_device <Buzzer> ()
|
||||
Keyboard kbd = Kernel::my_parent.get_device <Keyboard> ()
|
||||
Kernel::Cap key = Kernel::my_receiver.create_capability (0)
|
||||
|
Loading…
Reference in New Issue
Block a user