machine_androidarm.cc Source File

Back to the index.

machine_androidarm.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * COMMENT: ARM-based "Android" machines
29  *
30  * TODO. This is bogus so far, only enough to see the Linux kernel start
31  * executing instructions.
32  *
33  * gxemul -e sony-xperia-mini -tvvK boot.img
34  * gxemul -e finow-x5-air -tvvK boot.img
35  */
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 
41 #include "cpu.h"
42 #include "device.h"
43 #include "devices.h"
44 #include "machine.h"
45 #include "memory.h"
46 #include "misc.h"
47 
48 
49 uint32_t swap_if_little_endian(uint32_t v, struct cpu* cpu)
50 {
52  return v;
53 
54  return (v >> 24) | ((v & 0x00ff0000) >> 8)
55  | ((v & 0x0000ff00) << 8) | ((v & 0xff) << 24);
56 }
57 
58 
59 MACHINE_SETUP(androidarm)
60 {
61  char tmpstr[1000];
62  bool use_atags = false;
63 
65 
66  switch (machine->machine_subtype) {
67 
69  machine->machine_name = strdup("Finow X5 Air");
70 
71  // 2 GB ram at 0x80000000? Mirrored at 0 maybe? (But in GXemul's legacy
72  // framework, we have to make the mirror the other way around.)
73  dev_ram_init(machine, 0x80000000, 0x10000000, DEV_RAM_MIRROR, 0x0);
74  dev_ram_init(machine, 0x90000000, 0x70000000, DEV_RAM_RAM, 0x0);
75 
76  // Yet another mirror at 0x40000000?
77  dev_ram_init(machine, 0x40000000, 0x10000000, DEV_RAM_MIRROR, 0x0);
78 
79  // See https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/mt6580.dtsi
80  // timer: timer@10008000
81  // sysirq: interrupt-controller@10200100
82  // gic: interrupt-controller@10211000
83  // uart0: serial@11005000
84  // uart1: serial@11006000
85 
86  // "gic" interrupt controller:
87  // See https://github.com/torvalds/linux/blob/master/include/dt-bindings/interrupt-controller/arm-gic.h
88 
89  // TODO: interrupt "GIC_SPI 44"
90  snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=%s.cpu[%i].irq"
91  " addr=0x11005000 addr_mult=4 in_use=%i",
93  machine->main_console_handle = (size_t)
94  device_add(machine, tmpstr);
95 
97  0x12340000 /* TODO addr */,
99  400, 400,
100  400, 400,
101  24, machine->machine_name);
102 
103  break;
104 
106  machine->machine_name = strdup("Sony Xperia Mini");
107 
108  // Mirror at 0x40000000?
109  dev_ram_init(machine, 0x40000000, 0x20000000, DEV_RAM_MIRROR, 0x0);
110 
111  // Perhaps https://talk.sonymobile.com/t5/Xperia-mini-pro/Sk17i-in-continous-boot-loop/td-p/281671#gref
112  // could be of some help.
113 
115  0x23450000 /* TODO addr */,
116  VFB_GENERIC,
117  320, 480,
118  320, 480,
119  24, machine->machine_name);
120 
121  break;
122 
123  default:printf("Unimplemented android-arm machine number.\n");
124  exit(1);
125  }
126 
127  // See https://www.kernel.org/doc/Documentation/arm/Booting
128  cpu->cd.arm.r[0] = 0x00000000;
129  cpu->cd.arm.r[1] = 0xffffffff; // architecture ID. 0xffffffff = use DT (device tree)?
130 
131  if (use_atags) {
132  // ATAG list: TODO.
133  cpu->cd.arm.r[2] = 0x00002000; // ATAGs at 8KB from start of low RAM.
134  } else {
135  // Device Tree:
136  // https://www.kernel.org/doc/Documentation/devicetree/booting-without-of.txt
137  cpu->cd.arm.r[2] = 0x08000000; // Device Tree at 128 MB from start of RAM.
138 
139  store_32bit_word(cpu, cpu->cd.arm.r[2], swap_if_little_endian(0xd00dfeed, cpu));
140  }
141 }
142 
143 
145 {
146  switch (machine->machine_subtype) {
147 
149  // Cortex-A7? MTK6580 at 1.3 GHz? Quadcore?
150  machine->cpu_name = strdup("CORTEX-A5");
151  break;
152 
154  // "Qualcomm MSM8255 Snapdragon S2"
155  // My real Xperia Mini says the following when booting the Linux kernel:
156  // [ 0.000000] CPU: ARMv7 Processor [511f00f2] revision 2 (ARMv7), cr=10c53c7d
157  machine->cpu_name = strdup("SnapdragonS2");
158  break;
159 
160  default:
161  machine->cpu_name = strdup("CORTEX-A5");
162  }
163 }
164 
165 
167 {
168  switch (machine->machine_subtype) {
169 
171  // Ram is at 0x80000000?
173  break;
174 
177  break;
178 
179  default:
181  }
182 }
183 
184 
185 MACHINE_REGISTER(androidarm)
186 {
187  MR_DEFAULT(androidarm, "ARM-based \"Android\" machines", ARCH_ARM, MACHINE_ANDROIDARM);
188 
189  machine_entry_add_alias(me, "android-arm");
190 
192  "finow-x5-air", NULL);
193 
195  "sony-xperia-mini", NULL);
196 
197  me->set_default_ram = machine_default_ram_androidarm;
198 }
199 
machine::machine_subtype
int machine_subtype
Definition: machine.h:112
machine::bootstrap_cpu
int bootstrap_cpu
Definition: machine.h:136
VFB_GENERIC
#define VFB_GENERIC
Definition: devices.h:190
DEV_RAM_MIRROR
#define DEV_RAM_MIRROR
Definition: devices.h:365
cpu::byte_order
uint8_t byte_order
Definition: cpu.h:347
MACHINE_ANDROIDARM
#define MACHINE_ANDROIDARM
Definition: machine.h:245
EMUL_BIG_ENDIAN
#define EMUL_BIG_ENDIAN
Definition: misc.h:165
DEV_RAM_RAM
#define DEV_RAM_RAM
Definition: devices.h:364
device.h
MACHINE_REGISTER
MACHINE_REGISTER(androidarm)
Definition: machine_androidarm.cc:185
MACHINE_ANDROIDARM_SONYXPERIAMINI
#define MACHINE_ANDROIDARM_SONYXPERIAMINI
Definition: machine.h:336
swap_if_little_endian
uint32_t swap_if_little_endian(uint32_t v, struct cpu *cpu)
Definition: machine_androidarm.cc:49
machine::cpu_name
char * cpu_name
Definition: machine.h:133
machine_entry_add_subtype
void machine_entry_add_subtype(struct machine_entry *me, const char *name, int oldstyle_subtype,...)
Definition: machine.cc:717
x11_md::in_use
int in_use
Definition: machine.h:82
MACHINE_DEFAULT_CPU
MACHINE_DEFAULT_CPU(androidarm)
Definition: machine_androidarm.cc:144
misc.h
cpu::cd
union cpu::@1 cd
device_add
void * device_add(struct machine *machine, const char *name_and_params)
Definition: device.cc:252
machine.h
machine
Definition: machine.h:97
machine::main_console_handle
int main_console_handle
Definition: machine.h:128
MR_DEFAULT
#define MR_DEFAULT(x, name, arch, type)
Definition: machine.h:373
arm_cpu::r
uint32_t r[N_ARM_REGS]
Definition: cpu_arm.h:155
machine::x11_md
struct x11_md x11_md
Definition: machine.h:179
cpu.h
machine::path
char * path
Definition: machine.h:108
machine::memory
struct memory * memory
Definition: machine.h:126
machine::physical_ram_in_mb
uint32_t physical_ram_in_mb
Definition: machine.h:147
EMUL_LITTLE_ENDIAN
#define EMUL_LITTLE_ENDIAN
Definition: misc.h:164
cpu::arm
struct arm_cpu arm
Definition: cpu.h:444
store_32bit_word
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
Definition: memory.cc:783
MACHINE_DEFAULT_RAM
MACHINE_DEFAULT_RAM(androidarm)
Definition: machine_androidarm.cc:166
ARCH_ARM
#define ARCH_ARM
Definition: machine.h:206
MACHINE_SETUP
MACHINE_SETUP(androidarm)
Definition: machine_androidarm.cc:59
devices.h
machine::machine_name
const char * machine_name
Definition: machine.h:115
cpu
Definition: cpu.h:326
machine_entry_add_alias
void machine_entry_add_alias(struct machine_entry *me, const char *name)
Definition: machine.cc:697
dev_ram_init
void dev_ram_init(struct machine *machine, uint64_t baseaddr, uint64_t length, int mode, uint64_t otheraddress, const char *name)
Definition: dev_ram.cc:146
memory.h
dev_fb_init
struct vfb_data * dev_fb_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, int xsize, int ysize, int bit_depth, const char *name)
Definition: dev_fb.cc:834
MACHINE_ANDROIDARM_FINOWX5AIR
#define MACHINE_ANDROIDARM_FINOWX5AIR
Definition: machine.h:337

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18