From e2367e8fcbb23acc378bc9f99a8dd732bf731d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 8 Oct 2003 01:24:01 +0000 Subject: [PATCH] Added some PPC helper functions. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4980 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/arch/ppc/Jamfile | 2 + src/kernel/core/arch/ppc/arch_cpu_asm.S | 138 ++++++++++++++++++++++++ src/kernel/core/arch/ppc/arch_mmu.cpp | 40 +++++++ 3 files changed, 180 insertions(+) create mode 100644 src/kernel/core/arch/ppc/arch_cpu_asm.S create mode 100644 src/kernel/core/arch/ppc/arch_mmu.cpp diff --git a/src/kernel/core/arch/ppc/Jamfile b/src/kernel/core/arch/ppc/Jamfile index b9573ebc60..7b2fad597a 100644 --- a/src/kernel/core/arch/ppc/Jamfile +++ b/src/kernel/core/arch/ppc/Jamfile @@ -3,11 +3,13 @@ SubDir OBOS_TOP src kernel core arch ppc ; KernelStaticLibrary libppc : <$(SOURCE_GRIST)>arch_atomic.c <$(SOURCE_GRIST)>arch_cpu.c + <$(SOURCE_GRIST)>arch_cpu_asm.S <$(SOURCE_GRIST)>arch_dbg_console.c <$(SOURCE_GRIST)>arch_debug.c <$(SOURCE_GRIST)>arch_elf.c <$(SOURCE_GRIST)>arch_faults.c <$(SOURCE_GRIST)>arch_int.c + <$(SOURCE_GRIST)>arch_mmu.cpp <$(SOURCE_GRIST)>arch_smp.c <$(SOURCE_GRIST)>arch_thread.c <$(SOURCE_GRIST)>arch_timer.c diff --git a/src/kernel/core/arch/ppc/arch_cpu_asm.S b/src/kernel/core/arch/ppc/arch_cpu_asm.S new file mode 100644 index 0000000000..1bbc21d0ed --- /dev/null +++ b/src/kernel/core/arch/ppc/arch_cpu_asm.S @@ -0,0 +1,138 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + +#define FUNCTION(x) .global x; .type x,@function; x + +.text + +/* uint32 get_sdr1(void); + */ +FUNCTION(get_sdr1): + mfsdr1 %r3 + blr + +/* void set_sdr1(uint32 value); + * r3 + */ +FUNCTION(set_sdr1): + mtsdr1 %r3 + blr + +#define get_ibat(num) \ + mfibatu %r4, num; \ + stw %r4, 0(%r3); \ + mfibatl %r4, num; \ + stw %r4, 4(%r3); \ + +#define set_ibat(num); \ + lwz %r4, 0(%r3); \ + mtibatu num, %r4; \ + lwz %r4, 4(%r3); \ + mtibatl num, %r4; + +/* void get_ibat0-3(block_address_translation *bat); + * r3 + */ +FUNCTION(get_ibat0): + get_ibat(0) + blr +FUNCTION(get_ibat1): + get_ibat(1) + blr +FUNCTION(get_ibat2): + get_ibat(2) + blr +FUNCTION(get_ibat3): + get_ibat(3) + blr + +/* void set_ibat0-3(block_address_translation *bat); + * r3 + */ +FUNCTION(set_ibat0): + set_ibat(0) + blr +FUNCTION(set_ibat1): + set_ibat(1) + blr +FUNCTION(set_ibat2): + set_ibat(2) + blr +FUNCTION(set_ibat3): + set_ibat(3) + blr + +/* void reset_ibats(void) + */ +FUNCTION(reset_ibats): + li %r3, 0 + mtibatu 0, %r3 + mtibatl 0, %r3 + mtibatu 1, %r3 + mtibatl 1, %r3 + mtibatu 2, %r3 + mtibatl 2, %r3 + mtibatu 3, %r3 + mtibatl 3, %r3 + blr + +#define get_dbat(num) \ + mfdbatu %r4, num; \ + stw %r4, 0(%r3); \ + mfdbatl %r4, num; \ + stw %r4, 4(%r3); + +#define set_dbat(num) \ + lwz %r4, 0(%r3); \ + mtdbatu num, %r4; \ + lwz %r4, 4(%r3); \ + mtdbatl num, %r4; + +/* void get_dbat0-3(block_address_translation *bat); + * r3 + */ +FUNCTION(get_dbat0): + get_dbat(0) + blr +FUNCTION(get_dbat1): + get_dbat(1) + blr +FUNCTION(get_dbat2): + get_dbat(2) + blr +FUNCTION(get_dbat3): + get_dbat(3) + blr + +/* void set_dbat0-3(block_address_translation *bat); + * r3 + */ +FUNCTION(set_dbat0): + set_dbat(0) + blr +FUNCTION(set_dbat1): + set_dbat(1) + blr +FUNCTION(set_dbat2): + set_dbat(2) + blr +FUNCTION(set_dbat3): + set_dbat(3) + blr + +/* void reset_dbats(void) + */ +FUNCTION(reset_dbats): + li %r3, 0 + mtdbatu 0, %r3 + mtdbatl 0, %r3 + mtdbatu 1, %r3 + mtdbatl 1, %r3 + mtdbatu 2, %r3 + mtdbatl 2, %r3 + mtdbatu 3, %r3 + mtdbatl 3, %r3 + blr + diff --git a/src/kernel/core/arch/ppc/arch_mmu.cpp b/src/kernel/core/arch/ppc/arch_mmu.cpp new file mode 100644 index 0000000000..ecadbbc712 --- /dev/null +++ b/src/kernel/core/arch/ppc/arch_mmu.cpp @@ -0,0 +1,40 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include +#include + + +uint32 +page_table_entry::PrimaryHash(uint32 virtualSegmentID, uint32 virtualAddress) +{ + return (virtualSegmentID & 0x7ffff) ^ ((virtualAddress >> 12) & 0xffff); +} + + +uint32 +page_table_entry::SecondaryHash(uint32 virtualSegmentID, uint32 virtualAddress) +{ + return ~PrimaryHash(virtualSegmentID, virtualAddress); +} + + +void +ppc_get_page_table(void **_pageTable, size_t *_size) +{ + uint32 sdr1 = get_sdr1(); + + *_pageTable = (void *)(sdr1 & 0xffff0000); + *_size = ((sdr1 & 0x1ff) + 1) << 16; +} + + +void +ppc_set_page_table(void *pageTable, size_t size) +{ + set_sdr1(((uint32)pageTable & 0xffff0000) | (((size >> 16) - 1 ) & 0x1ff)); +} +