1 |
/* |
2 |
* $Id: mp.c,v 1.1 2007/02/11 09:19:27 debug Exp $ |
3 |
* |
4 |
* GXemul demo: Multi-Processor test |
5 |
* |
6 |
* This file is in the Public Domain. |
7 |
*/ |
8 |
|
9 |
#include "dev_cons.h" |
10 |
#include "dev_mp.h" |
11 |
|
12 |
|
13 |
#ifdef MIPS |
14 |
/* Note: The ugly cast to a signed int (32-bit) causes the address to be |
15 |
sign-extended correctly on MIPS when compiled in 64-bit mode */ |
16 |
#define PHYSADDR_OFFSET ((signed int)0xa0000000) |
17 |
#else |
18 |
#define PHYSADDR_OFFSET 0 |
19 |
#endif |
20 |
|
21 |
|
22 |
#define PUTCHAR_ADDRESS (PHYSADDR_OFFSET + \ |
23 |
DEV_CONS_ADDRESS + DEV_CONS_PUTGETCHAR) |
24 |
#define HALT_ADDRESS (PHYSADDR_OFFSET + \ |
25 |
DEV_CONS_ADDRESS + DEV_CONS_HALT) |
26 |
|
27 |
#define NCPUS_ADDRESS (PHYSADDR_OFFSET + \ |
28 |
DEV_MP_ADDRESS + DEV_MP_NCPUS) |
29 |
|
30 |
|
31 |
void printchar(char ch) |
32 |
{ |
33 |
*((volatile unsigned char *) PUTCHAR_ADDRESS) = ch; |
34 |
} |
35 |
|
36 |
|
37 |
void halt(void) |
38 |
{ |
39 |
*((volatile unsigned char *) HALT_ADDRESS) = 0; |
40 |
} |
41 |
|
42 |
|
43 |
void printstr(char *s) |
44 |
{ |
45 |
while (*s) |
46 |
printchar(*s++); |
47 |
} |
48 |
|
49 |
void printuint_internal(unsigned int u) |
50 |
{ |
51 |
int z = u / 10; |
52 |
if (z > 0) |
53 |
printuint_internal(z); |
54 |
printchar('0' + (u - z*10)); |
55 |
} |
56 |
|
57 |
void printuint(unsigned int u) |
58 |
{ |
59 |
if (u == 0) |
60 |
printchar('0'); |
61 |
else |
62 |
printuint_internal(u); |
63 |
} |
64 |
|
65 |
int get_nr_of_cpus(void) |
66 |
{ |
67 |
return *((volatile int *) NCPUS_ADDRESS); |
68 |
} |
69 |
|
70 |
void f(void) |
71 |
{ |
72 |
printstr("Multi-Processor demo\n"); |
73 |
printstr("--------------------\n\n"); |
74 |
|
75 |
printstr("Number of CPUs: "); |
76 |
printuint(get_nr_of_cpus()); |
77 |
printstr("\n\n"); |
78 |
|
79 |
halt(); |
80 |
} |
81 |
|