From b5d9a4d486f73d03943c6a81e49710e19dd26016 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 15 Jun 2003 22:13:02 +0000 Subject: [PATCH] more ppc work. Added most low level cpu operations git-svn-id: svn+ssh://newos.org/var/svn/newos/newos@931 c25cc9d1-44fa-0310-b259-ad778cb1d433 --- include/kernel/arch/int.h | 1 - include/kernel/arch/ppc/cpu.h | 1 + kernel/arch/i386/arch_int.c | 26 ----- kernel/arch/ppc/arch_asm.S | 160 ++++++++++++++++++++++-------- kernel/arch/ppc/arch_int.c | 5 - kernel/arch/ppc/arch_vm_translation_map.c | 2 +- 6 files changed, 119 insertions(+), 76 deletions(-) diff --git a/include/kernel/arch/int.h b/include/kernel/arch/int.h index 07e61ea..e88fdf8 100644 --- a/include/kernel/arch/int.h +++ b/include/kernel/arch/int.h @@ -13,7 +13,6 @@ int arch_int_init2(kernel_args *ka); void arch_int_enable_interrupts(void); void arch_int_disable_interrupts(void); -void arch_int_restore_interrupts(int oldstate); void arch_int_enable_io_interrupt(int irq); void arch_int_disable_io_interrupt(int irq); bool arch_int_are_interrupts_enabled(void); diff --git a/include/kernel/arch/ppc/cpu.h b/include/kernel/arch/ppc/cpu.h index 3eff4e6..57f4207 100644 --- a/include/kernel/arch/ppc/cpu.h +++ b/include/kernel/arch/ppc/cpu.h @@ -27,6 +27,7 @@ unsigned int getsr(unsigned int va); void setsr(unsigned int va, unsigned int val); unsigned int getmsr(void); void setmsr(unsigned int msr); +long long get_time_base(void); #endif diff --git a/kernel/arch/i386/arch_int.c b/kernel/arch/i386/arch_int.c index 0062906..66a4e04 100644 --- a/kernel/arch/i386/arch_int.c +++ b/kernel/arch/i386/arch_int.c @@ -109,32 +109,6 @@ void arch_int_disable_interrupts(void) asm("cli"); } -#if 0 -int arch_int_disable_interrupts(void) -{ - int flags; - - asm("pushfl;\n" - "popl %0;\n" - "cli" : "=g" (flags)); - return flags & 0x200 ? 1 : 0; -} - -void arch_int_restore_interrupts(int oldstate) -{ - int flags = oldstate ? 0x200 : 0; - - asm ( - "pushfl;\n" - "popl %1;\n" - "andl $0xfffffdff,%1;\n" - "orl %0,%1;\n" - "pushl %1;\n" - "popfl\n" - : : "r" (flags), "r" (0)); -} -#endif - bool arch_int_are_interrupts_enabled(void) { int flags; diff --git a/kernel/arch/ppc/arch_asm.S b/kernel/arch/ppc/arch_asm.S index c40568c..fde5206 100644 --- a/kernel/arch/ppc/arch_asm.S +++ b/kernel/arch/ppc/arch_asm.S @@ -2,42 +2,127 @@ ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#define FUNC(name) .align 4 ; .globl ##name ; ##name: +#define FUNCTION(x) .global x; .type x,@function; x .text -.globl reboot -reboot: +// XXX fixme +FUNCTION(reboot): + b . -.globl atomic_add -atomic_add: +/* int atomic_add(volatile int *val, int incr) */ +FUNCTION(atomic_add): +1: + isync + lwarx r5, r0, r3 // load & reserve + add r0, r4, r5 // do the add + stwcx. r0, r0, r3 // store the new value + bne- 1b // did we lose reservation? if so, repeat + mr r3, r5 // return the old value + isync + blr + +/* int atomic_and(volatile int *val, int incr) */ +FUNCTION(atomic_and): +1: + isync + lwarx r5, r0, r3 // load & reserve + and r0, r4, r5 // do the and + stwcx. r0, r0, r3 // store the new value + bne- 1b // did we lose reservation? if so, repeat + mr r3, r5 // return the old value + isync + blr + +/* int atomic_or(volatile int *val, int incr) */ +FUNCTION(atomic_or): +1: + isync + lwarx r5, r0, r3 // load & reserve + or r0, r4, r5 // do the or + stwcx. r0, r0, r3 // store the new value + bne- 1b // did we lose reservation? if so, repeat + mr r3, r5 // return the old value + isync + blr + +/* int atomic_set(volatile int *val, int set_to) */ +FUNCTION(atomic_set): +1: + isync + lwarx r5, r0, r3 // load & reserve + stwcx. r4, r0, r3 // store the new value + bne- 1b // did we lose reservation? if so, repeat + mr r3, r5 // return the old value + blr + +/* int test_and_set(int *val, int set_to, int test_val) */ +FUNCTION(test_and_set): +1: + isync + lwarx r1, r0, r3 // load & reserve + cmpw r1, r5 // see if the value == test_val + bne- 2f // if not, bail -.globl atomic_and -atomic_and: + stwcx. r4, r0, r3 // store the new value + bne- 1b // did we lose reservation? if so, repeat +2: + mr r3, r1 // return what was there (success or failure) + blr + +/* void arch_int_enable_interrupts(void) */ +FUNCTION(arch_int_enable_interrupts): + mfmsr r3 // load msr + + li r4, 1 + insrwi r3, r4, 1, 16 // set the EE bit + +/* + li r4, 0 + ori r4, r4, (1 << 15) // create a mask for EE bit of MSR + or r3, r3, r4 // set the EE bit +*/ + + mtmsr r3 // put it back into the msr + blr -.globl atomic_or -atomic_or: +/* void arch_int_disable_interrupts(void) */ +FUNCTION(arch_int_disable_interrupts): + mfmsr r3 // load msr -.globl atomic_set -atomic_set: + li r4, 0 + rlwinm r3, r4, 15, 16, 16 // mask the EE bit -.globl test_and_set -test_and_set: +/* + li r4, 0 + ori r4, r4, (1 << 15) // create a mask for EE bit of MSR + andc r3, r3, r4 // mask the EE bit +*/ -.globl arch_int_restore_interrupts -arch_int_restore_interrupts: + mtmsr r3 // put it back into the msr + blr -.globl arch_int_enable_interrupts -arch_int_enable_interrupts: +/* bool arch_int_are_interrupts_enabled(void) */ +FUNCTION(arch_int_are_interrupts_enabled): + mfmsr r3 // load msr + extrwi r3, r3, 1, 16 // mask out the EE bit + blr -.globl arch_int_disable_interrupts -arch_int_disable_interrupts: +// XXX fixme +FUNCTION(dbg_save_registers): + blr -.global dbg_save_registers -dbg_save_registers: +/* long long get_time_base(void) */ +FUNCTION(get_time_base): +1: + mftbu r3 // get the upper time base register + mftb r4 // get the lower time base register + mftbu r5 // get the upper again + cmpw r5, r3 // see if it changed while we were reading the lower + bne- 1b // if so, repeat + blr /* void getibats(int bats[8]); */ -.globl getibats -getibats: +FUNCTION(getibats): mfibatu r0,0 stw r0,0(r3) mfibatl r0,0 @@ -57,8 +142,7 @@ getibats: blr // void setibats(int bats[8]); -.globl setibats -setibats: +FUNCTION(setibats): mfmsr r8 li r0,0 mtmsr r0 @@ -94,8 +178,7 @@ setibats: blr // void getdbats(int bats[8]); -.globl getdbats -getdbats: +FUNCTION(getdbats): mfdbatu r0,0 stw r0,0(r3) mfdbatl r0,0 @@ -115,8 +198,7 @@ getdbats: blr // void setdbats(int bats[8]); -.globl setdbats -setdbats: +FUNCTION(setdbats): mfmsr r8 li r0,0 mtmsr r0 @@ -143,44 +225,36 @@ setdbats: blr // unsigned int getsdr1(); -.globl getsdr1 -getsdr1: +FUNCTION(getsdr1): mfsdr1 r3 blr // void setsdr1(unsigned int sdr); -.globl setsdr1 -setsdr1: +FUNCTION(setsdr1): sync mtsdr1 r3 sync blr // unsigned int getsr(unsigned int va); -.globl getsr -getsr: +FUNCTION(getsr): mfsrin r3,r3 sync blr // void setsr(unsigned int va, unsigned int val); -.globl setsr -setsr: +FUNCTION(setsr): mtsrin r4,r3 sync blr - - // unsigned int getmsr(); -.globl getmsr -getmsr: +FUNCTION(getmsr): mfmsr r3 blr // void setmsr(unsigned int msr); -.globl setmsr -setmsr: +FUNCTION(setmsr): mtmsr r3 blr diff --git a/kernel/arch/ppc/arch_int.c b/kernel/arch/ppc/arch_int.c index 6afb3f3..76ef53a 100644 --- a/kernel/arch/ppc/arch_int.c +++ b/kernel/arch/ppc/arch_int.c @@ -6,11 +6,6 @@ #include -bool arch_int_are_interrupts_enabled(void) -{ - return true; -} - void arch_int_enable_io_interrupt(int irq) { return; diff --git a/kernel/arch/ppc/arch_vm_translation_map.c b/kernel/arch/ppc/arch_vm_translation_map.c index 0208e66..aed463a 100644 --- a/kernel/arch/ppc/arch_vm_translation_map.c +++ b/kernel/arch/ppc/arch_vm_translation_map.c @@ -149,7 +149,7 @@ static struct ppc_pte *lookup_pagetable_entry(vm_translation_map *map, addr_t va // lookup the vsid based off the va vsid = VADDR_TO_ASID(map, va); - dprintf("vm_translation_map.lookup_pagetable_entry: vsid %d, va 0x%lx\n", vsid, va); +// dprintf("vm_translation_map.lookup_pagetable_entry: vsid %d, va 0x%lx\n", vsid, va); hash = primary_hash(vsid, va); // dprintf("hash = 0x%x\n", hash); -- 2.11.4.GIT