From b06e011a077a5df20e0f856d2598e70ca3496cb5 Mon Sep 17 00:00:00 2001 From: Bas Wijnen Date: Sun, 12 May 2013 09:46:11 -0400 Subject: [PATCH] Make it compile again; fixed poweroff problem --- .gitignore | 28 +++-- Makefile.am | 89 +++++++++++----- alloc.ccp | 2 +- mips/arch.ccp | 11 +- mips/arch.hhp | 3 +- mips/entry.S | 222 +++++++++++++++++++--------------------- mips/init.ccp | 31 +++--- mips/interrupts.ccp | 5 + mips/nanonote/board.ccp | 8 +- mips/start.S | 2 +- panic.ccp | 6 +- schedule.ccp | 1 + source/alarm.ccp | 18 ++-- source/rtc.ccp | 6 +- source/sdmmc.ccp | 4 + source/udc.ccp | 4 +- 16 files changed, 245 insertions(+), 195 deletions(-) diff --git a/.gitignore b/.gitignore index 97ba5a0..7484676 100644 --- a/.gitignore +++ b/.gitignore @@ -9,18 +9,24 @@ uimage source/charset.data mips/nanonote/sdram-setup.raw nanonote-boot -mips/nanonote/server/.deps/ -mips/nanonote/server/Makefile -mips/nanonote/server/Makefile.in -mips/nanonote/server/aclocal.m4 -mips/nanonote/server/autom4te.cache/ -mips/nanonote/server/config.log -mips/nanonote/server/config.status -mips/nanonote/server/configure -mips/nanonote/server/depcomp -mips/nanonote/server/install-sh -mips/nanonote/server/missing +.deps/ +.dirstamp +mips/.dirstamp +source/.dirstamp +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +config.log +config.status +configure +depcomp +install-sh +missing mips/nanonote/server/usb-server +mips/start-hack.S +threadlist.S +native/usb-server fs/ iris-sd.tar unbrick diff --git a/Makefile.am b/Makefile.am index 2c78b42..c43a3e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,7 +24,7 @@ SERIAL = /dev/ttyUSB0 junk = mdebug.abi32 reginfo comment pdr note.gnu.build-id objcopyflags = -S $(addprefix --remove-section=.,$(junk)) -start_load = 0x80400000 +start_load = 0x80003000 load = 0x80000000 noinst_DATA = iris.raw mips/start.raw mips/start-hack.S mips/nanonote/sdram-setup.raw @@ -38,9 +38,10 @@ if UDC boot_threads = udc else if UNBRICK -boot_threads = nand sdmmc usbmassstorage +boot_threads = sdmmc usbmassstorage else boot_threads = sdmmc partition fat +noinst_DATA += iris.tar.gz endif endif @@ -67,6 +68,30 @@ mips_nanonote_sdram_setup_elf_LDFLAGS = -Wl,--omagic -Wl,-T -Wl,mips/nanonote/sd mips_nanonote_sdram_setup_elf_SOURCES = mips/nanonote/sdram-setup.cc program_targets = \ + source/alarm.elf \ + source/ball.elf \ + source/boot.elf \ + source/booter.elf \ + source/bootinit.elf \ + source/bsquare.elf \ + source/buzzer.elf \ + source/elfrun.elf \ + source/fat.elf \ + source/font.elf \ + source/gpio.elf \ + source/gui.elf \ + source/init.elf \ + source/lcd.elf \ + source/metronome.elf \ + source/nand.elf \ + source/partition.elf \ + source/rtc.elf \ + source/sdmmc.elf \ + source/test.elf \ + source/udc.elf \ + source/usbmassstorage.elf + +fs_targets = \ fs/alarm.elf \ fs/ball.elf \ fs/boot.elf \ @@ -91,6 +116,7 @@ program_targets = \ fs/usbmassstorage.elf noinst_PROGRAMS += $(program_targets) +noinst_DATA += $(fs_targets) AM_CPPFLAGS = -O5 -fno-inline -I. -I./mips -I./mips/nanonote -Wa,-mips32 -DNANONOTE AM_CXXFLAGS = -Wno-unused-parameter -fno-strict-aliasing -fno-builtin -ggdb3 AM_LDFLAGS = -nostdlib @@ -113,28 +139,31 @@ fs/font.dat: courier-10+8+32.png makefont fs/%: % ln -s ../$< $@ -fs_alarm_elf_SOURCES = source/crt0.cc source/alarm.cc ${headers} -fs_ball_elf_SOURCES = source/crt0.cc source/ball.cc ${headers} -fs_boot_elf_SOURCES = source/crt0.cc source/boot.cc ${headers} -fs_booter_elf_SOURCES = source/crt0.cc source/booter.cc ${headers} -fs_bootinit_elf_SOURCES = source/crt0.cc source/bootinit.cc ${headers} -fs_bsquare_elf_SOURCES = source/crt0.cc source/bsquare.cc ${headers} -fs_buzzer_elf_SOURCES = source/crt0.cc source/buzzer.cc ${headers} -fs_elfrun_elf_SOURCES = source/crt0.cc source/elfrun.cc ${headers} -fs_fat_elf_SOURCES = source/crt0.cc source/fat.cc ${headers} -fs_font_elf_SOURCES = source/crt0.cc source/font.cc ${headers} -fs_gpio_elf_SOURCES = source/crt0.cc source/gpio.cc ${headers} -fs_gui_elf_SOURCES = source/crt0.cc source/gui.cc ${headers} -fs_init_elf_SOURCES = source/crt0.cc source/init.cc ${headers} -fs_lcd_elf_SOURCES = source/crt0.cc source/lcd.cc ${headers} -fs_metronome_elf_SOURCES = source/crt0.cc source/metronome.cc ${headers} -fs_nand_elf_SOURCES = source/crt0.cc source/nand.cc ${headers} -fs_partition_elf_SOURCES = source/crt0.cc source/partition.cc ${headers} -fs_rtc_elf_SOURCES = source/crt0.cc source/rtc.cc ${headers} -fs_sdmmc_elf_SOURCES = source/crt0.cc source/sdmmc.cc ${headers} -fs_test_elf_SOURCES = source/crt0.cc source/test.cc ${headers} -fs_udc_elf_SOURCES = source/crt0.cc source/udc.cc ${headers} -fs_usbmassstorage_elf_SOURCES = source/crt0.cc source/usbmassstorage.cc ${headers} +fs/%.elf: source/%.elf + $(OBJCOPY) -S $< $@ + +source_alarm_elf_SOURCES = source/crt0.cc source/alarm.cc ${headers} +source_ball_elf_SOURCES = source/crt0.cc source/ball.cc ${headers} +source_boot_elf_SOURCES = source/crt0.cc source/boot.cc ${headers} +source_booter_elf_SOURCES = source/crt0.cc source/booter.cc ${headers} +source_bootinit_elf_SOURCES = source/crt0.cc source/bootinit.cc ${headers} +source_bsquare_elf_SOURCES = source/crt0.cc source/bsquare.cc ${headers} +source_buzzer_elf_SOURCES = source/crt0.cc source/buzzer.cc ${headers} +source_elfrun_elf_SOURCES = source/crt0.cc source/elfrun.cc ${headers} +source_fat_elf_SOURCES = source/crt0.cc source/fat.cc ${headers} +source_font_elf_SOURCES = source/crt0.cc source/font.cc ${headers} +source_gpio_elf_SOURCES = source/crt0.cc source/gpio.cc ${headers} +source_gui_elf_SOURCES = source/crt0.cc source/gui.cc ${headers} +source_init_elf_SOURCES = source/crt0.cc source/init.cc ${headers} +source_lcd_elf_SOURCES = source/crt0.cc source/lcd.cc ${headers} +source_metronome_elf_SOURCES = source/crt0.cc source/metronome.cc ${headers} +source_nand_elf_SOURCES = source/crt0.cc source/nand.cc ${headers} +source_partition_elf_SOURCES = source/crt0.cc source/partition.cc ${headers} +source_rtc_elf_SOURCES = source/crt0.cc source/rtc.cc ${headers} +source_sdmmc_elf_SOURCES = source/crt0.cc source/sdmmc.cc ${headers} +source_test_elf_SOURCES = source/crt0.cc source/test.cc ${headers} +source_udc_elf_SOURCES = source/crt0.cc source/udc.cc ${headers} +source_usbmassstorage_elf_SOURCES = source/crt0.cc source/usbmassstorage.cc ${headers} server: test -e native/Makefile || native/autogen.sh @@ -146,6 +175,14 @@ test: mips/start.raw mips/start.elf server mips/nanonote/sdram-setup.raw fs/init native/usb-server echo 'reboot $(start_load) 0x$(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') mips/start.raw' | nc localhost 5050 +# SD boot stuff +iris.tar.gz: mips/start.raw.gz mips/start.elf $(fs_targets) fs/init.config fs/font.dat + test -d fs/boot || mkdir fs/boot + mkimage -A mips -T kernel -a $(start_load) -e $(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') -n Iris -d mips/start.raw.gz fs/boot/uImage | sed -e 's/:/;/g' + cd fs && tar czvf ../$@ --dereference * +%.gz: % + gzip < $< > $@ + sources = \ source/alarm.cc \ source/ball.cc \ @@ -170,6 +207,10 @@ sources = \ source/udc.cc \ source/usbmassstorage.cc +debug: + stty -F $(SERIAL) 57600 raw + cat $(SERIAL) + autoclean: maintainer-clean $(MAKE) -C native autoclean rm -rf aclocal.m4 configure depcomp fs install-sh iris.raw iris-sd.tar Makefile.in missing $(iris_sources) $(boot_sources) $(sources) $(headers) mips/start-hack.S mips/start.raw diff --git a/alloc.ccp b/alloc.ccp index c5d34eb..1f65e31 100644 --- a/alloc.ccp +++ b/alloc.ccp @@ -528,7 +528,7 @@ void kPage::check_payment (): // No kPage is paying for this frame anymore. raw_pfree (frame) kPage *next - for p = share_prev, next = (p ? p->share_prev : NULL); p; p = next, next = p->share_prev: + for p = share_prev, next = (p ? p->share_prev : NULL); p; p = next, next = p ? p->share_prev : NULL: p->frame = NULL p->share_prev = NULL p->share_next = NULL diff --git a/mips/arch.ccp b/mips/arch.ccp index 2a8d29b..6229cdc 100644 --- a/mips/arch.ccp +++ b/mips/arch.ccp @@ -23,7 +23,6 @@ void kThread_arch_init (kThread *thread): thread->arch.at = 0 for unsigned i = 0; i < 2; ++i: thread->arch.v[i] = 0 - thread->arch.k[i] = 0 for unsigned i = 0; i < 4; ++i: thread->arch.a[i] = 0 for unsigned i = 0; i < 10; ++i: @@ -99,16 +98,12 @@ unsigned *kThread_arch_info (kThread *thread, unsigned num): case 25: return &thread->arch.t[9] case 26: - return &thread->arch.k[0] - case 27: - return &thread->arch.k[1] - case 28: return &thread->arch.gp - case 29: + case 27: return &thread->sp - case 30: + case 28: return &thread->arch.fp - case 31: + case 29: return &thread->arch.ra default: return NULL diff --git a/mips/arch.hhp b/mips/arch.hhp index f336933..9576434 100644 --- a/mips/arch.hhp +++ b/mips/arch.hhp @@ -83,7 +83,6 @@ #define SAVE_RA (SAVE_FP + 4) #define SAVE_HI (SAVE_RA + 4) #define SAVE_LO (SAVE_HI + 4) -#define SAVE_K (SAVE_LO + 4) #ifndef ASM @@ -91,7 +90,7 @@ void flush_tlb (unsigned asid) void arch_flush_cache () struct kThread_arch: - unsigned at, v[2], a[4], t[10], s[8], gp, fp, ra, hi, lo, k[2] + unsigned at, v[2], a[4], t[10], s[8], gp, fp, ra, hi, lo // The following is used for page mapping. // Each Memory has a directory with 0x400 page tables. diff --git a/mips/entry.S b/mips/entry.S index 01dc231..dd901b5 100644 --- a/mips/entry.S +++ b/mips/entry.S @@ -32,81 +32,80 @@ addr_000: #if 0 // TLB refill - bne $zero, $k1, slow_refill - nop - bne $zero, $k0, slow_refill - lw $k1, -0xd94($zero) + lui $k0, 0x8000 + lw $k1, 0x174($k0) // directory mfc0 $k0, $CP0_ENTRY_HI srl $k0, $k0, 19 - and $k0, $k0, 0x3fc + and $k0, $k0, 0xffc addu $k0, $k0, $k1 beq $zero, $k0, zero_refill lw $k0, 0($k0) mfc0 $k1, $CP0_ENTRY_HI srl $k1, $k1, 10 - and $k1, $k1, 0x1f8 + and $k1, $k1, 0xff8 add $k0, $k0, $k1 lw $k1, 0($k0) mtc0 $k1, $CP0_ENTRY_LO0 lw $k1, 4($k0) mtc0 $k1, $CP0_ENTRY_LO1 1: tlbwr - move $zero, $k0 - move $zero, $k1 + move $k0, $zero + move $k1, $zero eret zero_refill: - mtc0 $zero, $CP_ENTRY_LO0 + mtc0 $zero, $CP0_ENTRY_LO0 b 1b - mtc0 $zero, $CP_ENTRY_LO1 - -slow_refill: - move $k1, $zero -#endif - sw $ra, -0xd88($zero) + mtc0 $zero, $CP0_ENTRY_LO1 +#else + // Slow refill: use C code (which calls kdebug etc) + move $k1, $ra bal save_regs nop la $t9, tlb_refill jr $t9 nop +#endif .fill 0x100 - (. - addr_000) addr_100: // Cache error - sw $ra, -0xd88($zero) + move $k1, $ra bal save_regs nop la $t9, cache_error jr $t9 nop - .fill 0x180 - (. - addr_000) + .fill 0x180 - (. - addr_000) - 3 * 4 + +directory: // 0x174 + .word 0 +current: // 0x178 + .word idle + // 0x17c + .word _gp + addr_180: // General exception - sw $ra, -0xd88($zero) + move $k1, $ra bal save_regs nop la $t9, exception jr $t9 nop - .fill 0x200 - (. - addr_000) - 8 - .word 0x0000001e // 1f8 EntryLo data for idle page. + // This is annoying; it must fill it up so addr_200 is right. For some + // reason .fill 0x200 - (. - addr_000) - 2 * 4 doesn't work here. + .fill 0x60 + .word 0x00000012 // 1f8 EntryLo data for idle page. .word 0x80000000 // 1fc A pointer to the current page. addr_200: // Interrupt - sw $ra, -0xd88($zero) + move $k1, $ra bal save_regs nop la $t9, interrupt jr $t9 nop - .fill 0x280 - (. - addr_000) - 20 - -directory: - .word 0 // -d94 == directory - // space for save_regs - .word 0 // -d90 == k0 - .word idle // -d8c == current - .word 0 // -d88 == ra - .word _gp // -d84 == gp + .fill 0x280 - (. - addr_000) start_idle: // 280 // Wait for the next interrupt, then the first thread will be scheduled. @@ -118,111 +117,106 @@ start_idle: // 280 // TODO: save only fragile registers now, the rest on task switch. kernel_exit: + move $k0, $v0 + lui $k1, 0x8000 + sw $v0, 0x178($k1) // current + lw $k1, SAVE_PC($k0) + mtc0 $k1, $CP0_EPC + lw $k1, SAVE_LO($k0) + mtlo $k1 + lw $k1, SAVE_HI($k0) + mthi $k1 + lw $v0, SAVE_V + 0 * 4($k0) + lw $v1, SAVE_V + 1 * 4($k0) + lw $a0, SAVE_A + 0 * 4($k0) + lw $a1, SAVE_A + 1 * 4($k0) + lw $a2, SAVE_A + 2 * 4($k0) + lw $a3, SAVE_A + 3 * 4($k0) + lw $t0, SAVE_T + 0 * 4($k0) + lw $t1, SAVE_T + 1 * 4($k0) + lw $t2, SAVE_T + 2 * 4($k0) + lw $t3, SAVE_T + 3 * 4($k0) + lw $t4, SAVE_T + 4 * 4($k0) + lw $t5, SAVE_T + 5 * 4($k0) + lw $t6, SAVE_T + 6 * 4($k0) + lw $t7, SAVE_T + 7 * 4($k0) + lw $t8, SAVE_T + 8 * 4($k0) + lw $t9, SAVE_T + 9 * 4($k0) + lw $s0, SAVE_S + 0 * 4($k0) + lw $s1, SAVE_S + 1 * 4($k0) + lw $s2, SAVE_S + 2 * 4($k0) + lw $s3, SAVE_S + 3 * 4($k0) + lw $s4, SAVE_S + 4 * 4($k0) + lw $s5, SAVE_S + 5 * 4($k0) + lw $s6, SAVE_S + 6 * 4($k0) + lw $s7, SAVE_S + 7 * 4($k0) + lw $fp, SAVE_FP($k0) + lw $at, SAVE_AT($k0) + lw $sp, SAVE_SP($k0) + lw $gp, SAVE_GP($k0) + lw $ra, SAVE_RA($k0) #ifndef NDEBUG // Exceptions were enabled in the kernel; set them to usermode setting again. - mfc0 $k0, $CP0_STATUS - ori $k0, $k0, 0xff13 - mtc0 $k0, $CP0_STATUS + mfc0 $k1, $CP0_STATUS + ori $k1, $k1, 0xff13 + mtc0 $k1, $CP0_STATUS #endif - sw $v0, -0xd8c($zero) - lw $k0, SAVE_PC($v0) - mtc0 $k0, $CP0_EPC - lw $k0, SAVE_LO($v0) - lw $k1, SAVE_HI($v0) - mtlo $k0 - mthi $k1 - lw $v1, SAVE_V + 1 * 4($v0) - lw $a0, SAVE_A + 0 * 4($v0) - lw $a1, SAVE_A + 1 * 4($v0) - lw $a2, SAVE_A + 2 * 4($v0) - lw $a3, SAVE_A + 3 * 4($v0) - lw $t0, SAVE_T + 0 * 4($v0) - lw $t1, SAVE_T + 1 * 4($v0) - lw $t2, SAVE_T + 2 * 4($v0) - lw $t3, SAVE_T + 3 * 4($v0) - lw $t4, SAVE_T + 4 * 4($v0) - lw $t5, SAVE_T + 5 * 4($v0) - lw $t6, SAVE_T + 6 * 4($v0) - lw $t7, SAVE_T + 7 * 4($v0) - lw $t8, SAVE_T + 8 * 4($v0) - lw $t9, SAVE_T + 9 * 4($v0) - lw $s0, SAVE_S + 0 * 4($v0) - lw $s1, SAVE_S + 1 * 4($v0) - lw $s2, SAVE_S + 2 * 4($v0) - lw $s3, SAVE_S + 3 * 4($v0) - lw $s4, SAVE_S + 4 * 4($v0) - lw $s5, SAVE_S + 5 * 4($v0) - lw $s6, SAVE_S + 6 * 4($v0) - lw $s7, SAVE_S + 7 * 4($v0) - lw $fp, SAVE_FP($v0) - lw $ra, SAVE_RA($v0) - lw $at, SAVE_AT($v0) - lw $k0, SAVE_K + 0 * 4($v0) - lw $k1, SAVE_V + 0 * 4($v0) - sw $k1, -0xd90($zero) - lw $k1, SAVE_K + 1 * 4($v0) - lw $sp, SAVE_SP($v0) - lw $gp, SAVE_GP($v0) - lw $v0, -0xd90($zero) + move $k0, $zero + move $k1, $zero eret save_regs: - sw $k0, -0xd90($zero) - lw $k0, -0xd8c($zero) + lui $k0, 0x8000 + lw $k0, 0x178($k0) // current - sw $at, SAVE_AT($k0) + sw $k1, SAVE_RA($k0) sw $gp, SAVE_GP($k0) sw $sp, SAVE_SP($k0) + sw $at, SAVE_AT($k0) sw $fp, SAVE_FP($k0) - - sw $k1, SAVE_K + 4($k0) - lw $k1, -0xd90($zero) - sw $k1, SAVE_K + 0($k0) - - lw $k1, -0xd88($zero) - sw $k1, SAVE_RA($k0) - sw $v0, SAVE_V + 0 * 4($k0) - sw $v1, SAVE_V + 1 * 4($k0) - sw $a0, SAVE_A + 0 * 4($k0) - sw $a1, SAVE_A + 1 * 4($k0) - sw $a2, SAVE_A + 2 * 4($k0) - sw $a3, SAVE_A + 3 * 4($k0) - sw $t0, SAVE_T + 0 * 4($k0) - sw $t1, SAVE_T + 1 * 4($k0) - sw $t2, SAVE_T + 2 * 4($k0) - sw $t3, SAVE_T + 3 * 4($k0) - sw $t4, SAVE_T + 4 * 4($k0) - sw $t5, SAVE_T + 5 * 4($k0) - sw $t6, SAVE_T + 6 * 4($k0) - sw $t7, SAVE_T + 7 * 4($k0) - sw $t8, SAVE_T + 8 * 4($k0) - sw $t9, SAVE_T + 9 * 4($k0) - sw $s0, SAVE_S + 0 * 4($k0) - sw $s1, SAVE_S + 1 * 4($k0) - sw $s2, SAVE_S + 2 * 4($k0) - sw $s3, SAVE_S + 3 * 4($k0) - sw $s4, SAVE_S + 4 * 4($k0) - sw $s5, SAVE_S + 5 * 4($k0) - sw $s6, SAVE_S + 6 * 4($k0) sw $s7, SAVE_S + 7 * 4($k0) - mfhi $v0 - mflo $v1 - sw $v0, SAVE_HI($k0) - sw $v1, SAVE_LO($k0) + sw $s6, SAVE_S + 6 * 4($k0) + sw $s5, SAVE_S + 5 * 4($k0) + sw $s4, SAVE_S + 4 * 4($k0) + sw $s3, SAVE_S + 3 * 4($k0) + sw $s2, SAVE_S + 2 * 4($k0) + sw $s1, SAVE_S + 1 * 4($k0) + sw $s0, SAVE_S + 0 * 4($k0) + sw $t9, SAVE_T + 9 * 4($k0) + sw $t8, SAVE_T + 8 * 4($k0) + sw $t7, SAVE_T + 7 * 4($k0) + sw $t6, SAVE_T + 6 * 4($k0) + sw $t5, SAVE_T + 5 * 4($k0) + sw $t4, SAVE_T + 4 * 4($k0) + sw $t3, SAVE_T + 3 * 4($k0) + sw $t2, SAVE_T + 2 * 4($k0) + sw $t1, SAVE_T + 1 * 4($k0) + sw $t0, SAVE_T + 0 * 4($k0) + sw $a3, SAVE_A + 3 * 4($k0) + sw $a2, SAVE_A + 2 * 4($k0) + sw $a1, SAVE_A + 1 * 4($k0) + sw $a0, SAVE_A + 0 * 4($k0) + sw $v1, SAVE_V + 1 * 4($k0) + sw $v0, SAVE_V + 0 * 4($k0) + mfhi $k1 + sw $k1, SAVE_HI($k0) + mflo $k1 + sw $k1, SAVE_LO($k0) mfc0 $k1, $CP0_EPC sw $k1, SAVE_PC($k0) - lw $gp, -0xd84($zero) - la $sp, kernel_stack + KERNEL_STACK_SIZE - #ifndef NDEBUG // Allow kernel bugs to set EPC and friends. mfc0 $k0, $CP0_STATUS - li $k1, 0x10000000 + lui $k1, 0x1000 and $k0, $k0, $k1 mtc0 $k0, $CP0_STATUS #endif + lui $k0, 0x8000 + lw $gp, 0x17c($k0) + la $sp, kernel_stack + KERNEL_STACK_SIZE + move $t9, $ra la $ra, kernel_exit jr $t9 diff --git a/mips/init.ccp b/mips/init.ccp index a01b6fe..b8c4e8b 100644 --- a/mips/init.ccp +++ b/mips/init.ccp @@ -1,4 +1,5 @@ #pypp 0 +// vim: set filetype=cpp : // // Iris: micro-kernel for a capability-based operating system. // mips/init.ccp: mips-specific boot code. // Copyright 2009 Bas Wijnen @@ -73,40 +74,33 @@ static void init_cp0 (): // Use non-vectored interrupts. cp0_set0 (CP0_INT_CTL) - // clear the tlb, hardwire page 0 to 0xffffffff - // and soft-wire it to (0x294 << 20) + (0x290 << 10) - // (for the idle task). - - cp0_set (CP0_WIRED, 1) - cp0_set0 (CP0_PAGE_MASK) - cp0_set0 (CP0_ENTRY_LO0) - cp0_set0 (CP0_ENTRY_LO1) // Get number of tlb entries (is 31). unsigned num cp0_get (CP0_CONFIG1, num) num >>= 25 num &= 0x3f // Clear the tlb. - for unsigned i = 1; i <= num; ++i: + cp0_set (CP0_WIRED, 0) + cp0_set0 (CP0_PAGE_MASK) + cp0_set0 (CP0_ENTRY_LO0) + cp0_set0 (CP0_ENTRY_LO1) + for unsigned i = 0; i <= num; ++i: // with asid 0, no page faults will be triggered, so it's safe to map memory anywhere. - cp0_set (CP0_ENTRY_HI, 0x2000 * i) + // And it's set to invalid anyway. + cp0_set (CP0_ENTRY_HI, 0x2000 * (i + 1)) cp0_set (CP0_INDEX, i) // write the data. __asm__ volatile ("tlbwi") - // Fill the upper page in kseg3. - cp0_set (CP0_ENTRY_HI, 0xffffe000) - cp0_set (CP0_ENTRY_LO0, 0x1d) - cp0_set (CP0_ENTRY_LO1, 0x1f) - cp0_set0 (CP0_INDEX) - __asm__ volatile ("tlbwi") // Fill the idle task's page in useg. Set it to non-cachable. // its directory entry is at 1fc, so it's number 7f (0fe00000). // its table entry is at 1f8, so it's number 7e (0007e000). // its address is 280 (00000280), used below for EPC. unsigned const idle_entry_hi = 0x0fe7e000 cp0_set (CP0_ENTRY_HI, idle_entry_hi) - cp0_set (CP0_ENTRY_LO0, 0x16) - cp0_set (CP0_ENTRY_LO1, 0x14) + cp0_set (CP0_ENTRY_LO0, 0x00000012) + // The following value doesn't make much sense, but it is what is + // filled in at run-time. So for robustness it's used here as well. + cp0_set (CP0_ENTRY_LO1, 0x80000000) __asm__ volatile ("tlbwr") // Allow eret to be used to jump to the idle task. cp0_set (CP0_EPC, (idle_entry_hi & PAGE_MASK) | 0x280) @@ -318,5 +312,6 @@ void init (unsigned mem): // All interrupts enter the CPU through the interrupt controller at IP2, so enable that. cp0_set (CP0_STATUS, 0x1000ff13) + kdebug ("entering idle task\n") // Done; return to user space (the idle task). __asm__ volatile ("eret") diff --git a/mips/interrupts.ccp b/mips/interrupts.ccp index a10e948..d8a37b7 100644 --- a/mips/interrupts.ccp +++ b/mips/interrupts.ccp @@ -1,4 +1,5 @@ #pypp 0 +// vim: set filetype=cpp : // // Iris: micro-kernel for a capability-based operating system. // mips/interrupts.ccp: Functions called by mips/entry.S. // Copyright 2009 Bas Wijnen @@ -72,6 +73,7 @@ static kThread *handle_exit (): /// Otherwise, the ultra-fast code in entry.S is used. kThread *tlb_refill (): ++dbg_code.h + kdebug_num ((unsigned)directory) old_current = current if !directory: unsigned addr @@ -80,6 +82,9 @@ kThread *tlb_refill (): return handle_exit () unsigned EntryHi cp0_get (CP0_ENTRY_HI, EntryHi) + kdebug (" tlb ") + kdebug_num (EntryHi) + kdebug ("\n") Table *t = directory[EntryHi >> 21] if !t: unsigned addr diff --git a/mips/nanonote/board.ccp b/mips/nanonote/board.ccp index 35489a1..bede7c9 100644 --- a/mips/nanonote/board.ccp +++ b/mips/nanonote/board.ccp @@ -1,4 +1,5 @@ #pypp 0 +// vim: set filetype=cpp :// // Iris: micro-kernel for a capability-based operating system. // mips/nanonote/board.ccp: nanonote-specific definitions. // Copyright 2009 Bas Wijnen @@ -22,7 +23,7 @@ void board_init (): pll_init () - cpm_stop_all () + cpm_start_all () // Timer interrupts and buzzer. cpm_start_tcu () // sdram memory. @@ -38,7 +39,7 @@ void board_init (): // buzzer. gpio_as_pwm4 () // Set up memory. - //setup_sdram () + setup_sdram () // Use some gpio pins for lcd. gpio_as_gpio (2, (1 << 21) | (1 << 22) | (1 << 23)) gpio_as_output (2, (1 << 21) | (1 << 22) | (1 << 23)) @@ -52,6 +53,7 @@ void board_init (): // Set up keyboard: this breaks uart receive. gpio_as_gpio (3, 0x05fc0000) // Set up timed interrupts. + tcu_start_timer_clock (0) tcu_stop_counter (0) tcu_select_extalclk (0) tcu_select_clk_div4 (0) @@ -104,6 +106,8 @@ void arch_poweroff (): while !rtc_write_ready (): rtc_enabled () while !rtc_write_ready (): + rtc_set_hrcr_val (0x7f) + while !rtc_write_ready (): kdebug ("Power down.\n") sync_serial () rtc_power_down () diff --git a/mips/start.S b/mips/start.S index f9a5328..7fe02df 100644 --- a/mips/start.S +++ b/mips/start.S @@ -16,7 +16,7 @@ // along with this program. If not, see . // This program is a wrapper around the kernel. -// It is linked for loading at 0x80600000; however, it it position-independant and may be loaded anywhere. +// It is position-independant and may be loaded anywhere. // It does not use gp. This means that li and la must not be used. .globl __start .set noreorder diff --git a/panic.ccp b/panic.ccp index b998f4c..c6db9f2 100644 --- a/panic.ccp +++ b/panic.ccp @@ -136,11 +136,9 @@ static void panic_message (unsigned n, const char *line, char const *name, char kdebug_num (old_current->arch.hi) kdebug (" lo=") kdebug_num (old_current->arch.lo) - kdebug ("\nk=") - kdebug_num (old_current->arch.k[0]) - kdebug (" ") - kdebug_num (old_current->arch.k[1]) kdebug ('\n') + kdebug ("Directory: ") + kdebug_num ((unsigned)directory) kdebug ("; ") kdebug (name) kdebug (':') diff --git a/schedule.ccp b/schedule.ccp index 6fdf97f..9313255 100644 --- a/schedule.ccp +++ b/schedule.ccp @@ -1,4 +1,5 @@ #pypp 0 +// vim: set filetype=cpp : // // Iris: micro-kernel for a capability-based operating system. // schedule.ccp: Thread scheduling. // Copyright 2009 Bas Wijnen diff --git a/source/alarm.ccp b/source/alarm.ccp index 3fe240b..d364572 100644 --- a/source/alarm.ccp +++ b/source/alarm.ccp @@ -23,6 +23,7 @@ Iris::Num start (): Iris::my_parent.provide_capability (self) cap = Iris::my_receiver.create_capability (INTERRUPT) Iris::my_parent.init_done () + font.printf ("Press a key to attempt reboot.\n") while true: Iris::wait () switch Iris::recv.protected_data.l: @@ -38,13 +39,16 @@ Iris::Num start (): font.printf ("alarm: control event\n") break case KBD: - // Key press - unsigned time = rtc.get_time () - unsigned alarm = rtc.get_alarm () - unsigned enabled = Iris::recv.data[1].l - font.printf ("%d %d %d", time, alarm, enabled) - rtc.set_alarm (time + 10, cap) - Iris::poweroff () + if Iris::recv.data[0].l & Iris::Keyboard::RELEASE: + // Key release. + Iris::poweroff () + else: + // Key press. + unsigned time = rtc.get_time () + rtc.set_alarm (time + 5, cap) + unsigned alarm = rtc.get_alarm () + unsigned enabled = Iris::recv.data[1].l + font.printf ("Debug: %d %d %d\n", time, alarm, enabled) break default: Iris::panic (Iris::recv.protected_data.l, "invalid request for alarm") diff --git a/source/rtc.ccp b/source/rtc.ccp index 99c0577..a1085da 100644 --- a/source/rtc.ccp +++ b/source/rtc.ccp @@ -51,8 +51,8 @@ Iris::Num start (): rtc_set_adjc_val (0) ready () rtc_set_second (0) - ready () - rtc_disable_1Hz_irq () + ready () + rtc_set_alarm_second (0) ready () rtc_disable_alarm () ready () @@ -60,6 +60,8 @@ Iris::Num start (): ready () rtc_enable_alarm_irq () ready () + rtc_disable_1Hz_irq () + ready () rtc_set_hwfcr_val (0) ready () rtc_set_hrcr_val (0) diff --git a/source/sdmmc.ccp b/source/sdmmc.ccp index 2bf0107..405f65c 100644 --- a/source/sdmmc.ccp +++ b/source/sdmmc.ccp @@ -459,8 +459,10 @@ void Mmc::read_page (Iris::Page page, Iris::Num address, unsigned size, unsigned offset &= ~PAGE_MASK & ~3 if size + offset > PAGE_SIZE: size = PAGE_SIZE - offset + page.set_flags (Iris::Page::PAYING | Iris::Page::FRAME) page.share (buffer_page) buffer_page.set_flags (Iris::Page::PAYING | Iris::Page::FRAME) + page.set_flags (0, Iris::Page::PAYING) for unsigned i = 0; i < size; i += 4: ((unsigned *)buffer)[(offset + i) >> 2] = current_block[(start_pos + i) >> 2] @@ -475,8 +477,10 @@ void Mmc::write_page (Iris::Page page, Iris::Num address, unsigned size, unsigne offset &= ~PAGE_MASK & ~3 if size + offset > PAGE_SIZE: size = PAGE_SIZE - offset + page.set_flags (Iris::Page::PAYING | Iris::Page::FRAME) page.share (buffer_page) buffer_page.set_flags (Iris::Page::PAYING | Iris::Page::FRAME) + page.set_flags (0, Iris::Page::PAYING) for unsigned i = 0; i < size; i += 4: current_block[(start_pos + i) >> 2] = ((unsigned *)buffer)[(offset + i) >> 2] dirty = true diff --git a/source/udc.ccp b/source/udc.ccp index a11099e..73e40e4 100644 --- a/source/udc.ccp +++ b/source/udc.ccp @@ -1,4 +1,5 @@ #pypp 0 +// vim: set filetype=cpp : // // Iris: micro-kernel for a capability-based operating system. // boot-programs/udc.ccp: USB device controller driver. // Copyright 2009 Bas Wijnen @@ -551,13 +552,14 @@ enum pdata: NAME Iris::Num start (): + Iris::debug ("udc started") map_udc () map_gpio () map_cpm () Udc udc //Iris::Cap logcap = Iris::my_receiver.create_capability (LOG) - //__asm__ volatile ("li $a0, 1\nlw $a1, %0\nbreak" :: "m"(logcap.code): "a0", "a1", "memory") + //__asm__ volatile ("li $a0, 1\nlw $a1, %0\nbreak" :: "m"(logcap.code): "a0", "a1") Iris::Directory dir = Iris::my_receiver.create_capability (DIRECTORY) Iris::my_parent.provide_capability (dir.copy ()) Iris::free_cap (dir)