~pixelherodev/zyg

ref: 7dccbd7d9dc502f2cd859c4c7ebd84a0d8f3acd7 zyg/test/rk9/7.zig -rw-r--r-- 1.0 KiB
7dccbd7dNoam Preil merge 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const SoC = RK.RK3328;

const RK = struct{
	const RK3328 = struct{
		const CPU = ARM.A53;
	};
	const panic = fn() noreturn{
		//TODO: add a hlt in here and reduce power
		while(true){}
	};
};

const ARM = struct{
	const SpecialRegister = enum{
		const CPUACTLR_EL1 = "CPUACTLR_EL1";
		const set = fn(comptime reg: []const u8, val: u32) callconv(.Inline) void{
			// asm syntax rules:
			// $*N embeds COMPTIME string from argument N
			// $N references an argument which MUST be a LOCAL.
			asm("msr $2, $*1", reg, val);
		};
		const get = fn(comptime reg: []const u8) callconv(.Inline) u32 {
			return asm("mrs $*1, $>2", reg, u32);
		};
	};
	const A53 = struct {
		const Erratum = struct{
			const E855873 = fn() callconv(.Inline) void{
				var ACLTR = SpecialRegister.get(SpecialRegister.CPUACTLR_EL1);
				ACLTR = ACLTR | 1 << 44;
				SpecialRegister.set(SpecialRegister.CPUACTLR_EL1, ACLTR);
			};
			const all = fn() callconv(.Inline) void{
				E855873();
			};
		};
	};
};

pub export const start = fn() noreturn{
	defer RK.panic();
	SoC.CPU.Erratum.all();
};