ARM: Add ARM architecture detection to generic bootloader ARM code.

This detects everything up to ARMv6 right now. Need to check more
recent ARM ARMs for ARMv7 detection.

The detected details get passed on to the kernel, which can use
the pre-detected info for selecting right pagetable format and such.

Copyright removal of Axel done after agreement with Axel @ BeGeistert
that for files that were copy/pasted from x86 arch and then fully
replaced the implementation, removal of original copyright holder is
allowed, since their actual code is gone ;)
This commit is contained in:
Ithamar R. Adema 2012-11-13 12:04:35 +01:00
parent 959e7602bc
commit 1df5784a22
2 changed files with 78 additions and 38 deletions

View File

@ -33,14 +33,29 @@ struct iframe {
uint32 pc; uint32 pc;
} _PACKED; } _PACKED;
typedef struct arch_cpu_info { /**! Values for arch_cpu_info.arch */
} arch_cpu_info; enum {
ARCH_ARM_PRE_ARM7,
ARCH_ARM_v3,
ARCH_ARM_v4,
ARCH_ARM_v4T,
ARCH_ARM_v5,
ARCH_ARM_v5T,
ARCH_ARM_v5TE,
ARCH_ARM_v5TEJ,
ARCH_ARM_v6
};
extern int arch_cpu_type; typedef struct arch_cpu_info {
extern int arch_fpu_type; /* For a detailed interpretation of these values,
extern int arch_mmu_type; see "The System Control coprocessor",
extern int arch_platform; "Main ID register" in your ARM ARM */
extern int arch_machine; int implementor;
int part_number;
int revision;
int variant;
int arch;
} arch_cpu_info;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -1,12 +1,11 @@
/* /*
* Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2012, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* calculate_cpu_conversion_factor() was written by Travis Geiselbrecht and * Authors:
* licensed under the NewOS license. * Ithamar R. Adema <ithamar@upgrade-android.com>
*/ */
#include "cpu.h" #include "cpu.h"
#include <OS.h> #include <OS.h>
@ -17,50 +16,80 @@
#include <arch/cpu.h> #include <arch/cpu.h>
#include <arch_kernel.h> #include <arch_kernel.h>
#include <arch_system_info.h> #include <arch_system_info.h>
#include <arch_cpu.h>
#include <string.h> #include <string.h>
#define TRACE_CPU
//#define TRACE_CPU
#ifdef TRACE_CPU #ifdef TRACE_CPU
# define TRACE(x) dprintf x # define TRACE(x) dprintf x
#else #else
# define TRACE(x) ; # define TRACE(x) ;
#endif #endif
//uint32 gTimeConversionFactor; /*! check_cpu_features
*
* Please note the fact that ARM7 and ARMv7 are two different things ;)
static void * ARMx is a specific ARM CPU core instance, while ARMvX refers to the
calculate_cpu_conversion_factor() * ARM architecture specification version....
{ *
#warning U-Boot:TODO! * Most of the architecture versions we're detecting here we will probably
} * never run on, just included for completeness sake... ARMv5 and up are
* the likely ones for us to support (as they all have some kind of MMU).
*/
static status_t static status_t
check_cpu_features() check_cpu_features()
{ {
uint32 result = 0;
int arch, variant = 0, part = 0, revision = 0, implementor = 0;
asm volatile("MRC p15, 0, %[c1out], c0, c0, 0":[c1out] "=r" (result));
implementor = (result >> 24) & 0xff;
if (!(result & (1 << 19))) {
switch((result >> 12) & 0xf) {
case 0: /* early ARMv3 or even older */
arch = ARCH_ARM_PRE_ARM7;
break;
case 7: /* ARM7 processor */
arch = (result & (1 << 23)) ? ARCH_ARM_v4T : ARCH_ARM_v3;
variant = (result >> 16) & 0x7f;
part = (result >> 4) & 0xfff;
revision = result & 0xf;
break;
default:
revision = result & 0xf;
part = (result >> 4) & 0xfff;
switch((result >> 16) & 0xf) {
case 1: arch = ARCH_ARM_v4; break;
case 2: arch = ARCH_ARM_v4T; break;
case 3: arch = ARCH_ARM_v5; break;
case 4: arch = ARCH_ARM_v5T; break;
case 5: arch = ARCH_ARM_v5TE; break;
case 6: arch = ARCH_ARM_v5TEJ; break;
case 7: arch = ARCH_ARM_v6; break;
case 0xf: /* XXX TODO ARMv7 */; break;
}
variant = (result >> 20) & 0xf;
break;
}
}
TRACE(("%s: implementor=0x%x('%c'), arch=%d, variant=0x%x, part=0x%x, revision=0x%x\n",
__func__, implementor, implementor, arch, variant, part, revision));
#warning U-Boot:TODO!
return B_OK; return B_OK;
} }
// #pragma mark - // #pragma mark -
extern "C" void extern "C" void
arch_spin(bigtime_t microseconds) arch_spin(bigtime_t microseconds)
{ {
for(bigtime_t i=0;i<microseconds;i=i+1) panic("No timing support in bootloader yet!");
{
/*
asm volatile ("mov r0,r0");
asm volatile ("mov r0,r0");
*/
}
#warning U-Boot:ARM:TODO!!
} }
@ -68,17 +97,13 @@ extern "C" status_t
boot_arch_cpu_init(void) boot_arch_cpu_init(void)
{ {
status_t err = check_cpu_features(); status_t err = check_cpu_features();
if (err != B_OK) { if (err != B_OK) {
panic("Retire your old Acorn and get something modern to boot!\n"); panic("Retire your old Acorn and get something modern to boot!\n");
return err; return err;
} }
calculate_cpu_conversion_factor();
gKernelArgs.num_cpus = 1; gKernelArgs.num_cpus = 1;
// this will eventually be corrected later on // this will eventually be corrected later on
return B_OK; return B_OK;
} }