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

Make it compile again; fixed poweroff problem

This commit is contained in:
Bas Wijnen
2013-05-12 09:46:11 -04:00
parent 223ed86672
commit b06e011a07
16 changed files with 245 additions and 195 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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 <wijnen@debian.org>
@@ -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")

View File

@@ -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 <wijnen@debian.org>
@@ -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

View File

@@ -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 <wijnen@debian.org>
@@ -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 ()

View File

@@ -16,7 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// 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