Reduce the use of size_t.

Many uses have more specific types that should be used instead. In
particular, size_t was used for register sized types so uintreg_t is
introduced to be more explicit and portable.

Change-Id: Ib8038bdd9cd164e6d9b1f42d10d4b1654a665997
diff --git a/inc/hf/boot_params.h b/inc/hf/boot_params.h
index f7eb324..7b486d5 100644
--- a/inc/hf/boot_params.h
+++ b/inc/hf/boot_params.h
@@ -18,6 +18,8 @@
 
 #include <stdbool.h>
 
+#include "hf/arch/cpu.h"
+
 #include "hf/mm.h"
 
 #define MAX_MEM_RANGES 20
@@ -32,7 +34,7 @@
 	size_t mem_ranges_count;
 	paddr_t initrd_begin;
 	paddr_t initrd_end;
-	size_t kernel_arg;
+	uintreg_t kernel_arg;
 };
 
 struct boot_params_update {
diff --git a/inc/hf/cpu.h b/inc/hf/cpu.h
index 1d3d640..af01151 100644
--- a/inc/hf/cpu.h
+++ b/inc/hf/cpu.h
@@ -77,7 +77,7 @@
 size_t cpu_index(struct cpu *c);
 void cpu_irq_enable(struct cpu *c);
 void cpu_irq_disable(struct cpu *c);
-bool cpu_on(struct cpu *c, ipaddr_t entry, size_t arg);
+bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg);
 void cpu_off(struct cpu *c);
 struct cpu *cpu_find(size_t id);
 
diff --git a/inc/hf/fdt.h b/inc/hf/fdt.h
index 14e7736..5467f7e 100644
--- a/inc/hf/fdt.h
+++ b/inc/hf/fdt.h
@@ -28,7 +28,7 @@
 };
 
 size_t fdt_header_size(void);
-size_t fdt_total_size(struct fdt_header *hdr);
+uint32_t fdt_total_size(struct fdt_header *hdr);
 void fdt_dump(struct fdt_header *hdr);
 bool fdt_root_node(struct fdt_node *node, const struct fdt_header *hdr);
 bool fdt_find_child(struct fdt_node *node, const char *child);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 48e707b..dc72e4a 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -51,5 +51,5 @@
 bool vm_init(uint32_t vcpu_count, struct vm **new_vm);
 uint32_t vm_get_count(void);
 struct vm *vm_get(uint32_t id);
-void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg);
+void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg);
 void vm_set_current(struct vm *vm);
diff --git a/src/arch/aarch64/handler.c b/src/arch/aarch64/handler.c
index 7eba337..a446402 100644
--- a/src/arch/aarch64/handler.c
+++ b/src/arch/aarch64/handler.c
@@ -25,11 +25,11 @@
 #include "psci.h"
 
 struct hvc_handler_return {
-	uint64_t user_ret;
+	uintreg_t user_ret;
 	struct vcpu *new;
 };
 
-int32_t smc(size_t arg0, size_t arg1, size_t arg2, size_t arg3);
+int32_t smc(uintreg_t arg0, uintreg_t arg1, uintreg_t arg2, uintreg_t arg3);
 void cpu_entry(struct cpu *c);
 
 static struct vcpu *current(void)
@@ -45,7 +45,7 @@
 	}
 }
 
-void sync_current_exception(uint64_t esr, uint64_t elr)
+void sync_current_exception(uintreg_t esr, uintreg_t elr)
 {
 	switch (esr >> 26) {
 	case 0x25: /* EC = 100101, Data abort. */
@@ -82,8 +82,8 @@
  *
  * Returns true if the request was a PSCI one, false otherwise.
  */
-static bool psci_handler(uint32_t func, size_t arg0, size_t arg1, size_t arg2,
-			 int32_t *ret)
+static bool psci_handler(uint32_t func, uintreg_t arg0, uintreg_t arg1,
+			 uintreg_t arg2, int32_t *ret)
 {
 	struct cpu *c;
 	int32_t sret;
@@ -158,8 +158,8 @@
 		 * itself off).
 		 */
 		do {
-			sret = smc(PSCI_CPU_ON, arg0, (size_t)&cpu_entry,
-				   (size_t)c);
+			sret = smc(PSCI_CPU_ON, arg0, (uintreg_t)&cpu_entry,
+				   (uintreg_t)c);
 		} while (sret == PSCI_RETURN_ALREADY_ON);
 
 		if (sret == PSCI_RETURN_SUCCESS) {
@@ -178,8 +178,8 @@
 	return true;
 }
 
-struct hvc_handler_return hvc_handler(size_t arg0, size_t arg1, size_t arg2,
-				      size_t arg3)
+struct hvc_handler_return hvc_handler(uintreg_t arg0, uintreg_t arg1,
+				      uintreg_t arg2, uintreg_t arg3)
 {
 	struct hvc_handler_return ret;
 
@@ -241,7 +241,7 @@
 	return api_yield(current());
 }
 
-struct vcpu *sync_lower_exception(uint64_t esr)
+struct vcpu *sync_lower_exception(uintreg_t esr)
 {
 	struct vcpu *vcpu = current();
 	int32_t ret;
diff --git a/src/arch/aarch64/inc/hf/arch/cpu.h b/src/arch/aarch64/inc/hf/arch/cpu.h
index e74c796..78f3cf2 100644
--- a/src/arch/aarch64/inc/hf/arch/cpu.h
+++ b/src/arch/aarch64/inc/hf/arch/cpu.h
@@ -22,37 +22,39 @@
 
 #include "hf/addr.h"
 
+typedef uint64_t uintreg_t;
+
 struct arch_regs {
 	/* General purpose registers. */
-	uint64_t r[31];
-	uint64_t pc;
-	uint64_t spsr;
+	uintreg_t r[31];
+	uintreg_t pc;
+	uintreg_t spsr;
 
 	/* TODO: We need to save virtual timer state. */
 	struct {
-		uint64_t vmpidr_el2;
-		uint64_t csselr_el1;
-		uint64_t sctlr_el1;
-		uint64_t actlr_el1;
-		uint64_t cpacr_el1;
-		uint64_t ttbr0_el1;
-		uint64_t ttbr1_el1;
-		uint64_t tcr_el1;
-		uint64_t esr_el1;
-		uint64_t afsr0_el1;
-		uint64_t afsr1_el1;
-		uint64_t far_el1;
-		uint64_t mair_el1;
-		uint64_t vbar_el1;
-		uint64_t contextidr_el1;
-		uint64_t tpidr_el0;
-		uint64_t tpidrro_el0;
-		uint64_t tpidr_el1;
-		uint64_t amair_el1;
-		uint64_t cntkctl_el1;
-		uint64_t sp_el0;
-		uint64_t sp_el1;
-		uint64_t par_el1;
+		uintreg_t vmpidr_el2;
+		uintreg_t csselr_el1;
+		uintreg_t sctlr_el1;
+		uintreg_t actlr_el1;
+		uintreg_t cpacr_el1;
+		uintreg_t ttbr0_el1;
+		uintreg_t ttbr1_el1;
+		uintreg_t tcr_el1;
+		uintreg_t esr_el1;
+		uintreg_t afsr0_el1;
+		uintreg_t afsr1_el1;
+		uintreg_t far_el1;
+		uintreg_t mair_el1;
+		uintreg_t vbar_el1;
+		uintreg_t contextidr_el1;
+		uintreg_t tpidr_el0;
+		uintreg_t tpidrro_el0;
+		uintreg_t tpidr_el1;
+		uintreg_t amair_el1;
+		uintreg_t cntkctl_el1;
+		uintreg_t sp_el0;
+		uintreg_t sp_el1;
+		uintreg_t par_el1;
 	} lazy;
 };
 
@@ -68,9 +70,9 @@
 
 static inline void arch_cpu_update(bool is_primary)
 {
-	uint64_t hcr;
-	uint64_t cptr;
-	uint64_t cnthctl;
+	uintreg_t hcr;
+	uintreg_t cptr;
+	uintreg_t cnthctl;
 
 	/* TODO: Determine if we need to set TSW. */
 	hcr = (1u << 31) | /* RW bit. */
@@ -100,7 +102,8 @@
 	__asm__ volatile("msr cnthctl_el2, %0" ::"r"(cnthctl));
 }
 
-static inline void arch_regs_init(struct arch_regs *r, ipaddr_t pc, size_t arg)
+static inline void arch_regs_init(struct arch_regs *r, ipaddr_t pc,
+				  uintreg_t arg)
 {
 	/* TODO: Use constant here. */
 	r->spsr = 5 |	 /* M bits, set to EL1h. */
@@ -114,7 +117,7 @@
 	r->lazy.vmpidr_el2 = index;
 }
 
-static inline void arch_regs_set_retval(struct arch_regs *r, size_t v)
+static inline void arch_regs_set_retval(struct arch_regs *r, uintreg_t v)
 {
 	r->r[0] = v;
 }
diff --git a/src/arch/aarch64/io.h b/src/arch/aarch64/io.h
index 1f1372e..07d410b 100644
--- a/src/arch/aarch64/io.h
+++ b/src/arch/aarch64/io.h
@@ -21,12 +21,12 @@
 
 #include "hf/arch/barriers.h"
 
-static inline uint32_t io_read(size_t addr)
+static inline uint32_t io_read(uintptr_t addr)
 {
 	return *(volatile uint32_t *)addr;
 }
 
-static inline uint32_t io_read_mb(size_t addr)
+static inline uint32_t io_read_mb(uintptr_t addr)
 {
 	uint32_t v = io_read(addr);
 	dsb();
@@ -34,12 +34,12 @@
 	return v;
 }
 
-static inline void io_write(size_t addr, uint32_t v)
+static inline void io_write(uintptr_t addr, uint32_t v)
 {
 	*(volatile uint32_t *)addr = v;
 }
 
-static inline void io_write_mb(size_t addr, uint32_t v)
+static inline void io_write_mb(uintptr_t addr, uint32_t v)
 {
 	dsb();
 	isb();
diff --git a/src/arch/aarch64/msr.h b/src/arch/aarch64/msr.h
index 6702ca4..8896c0a 100644
--- a/src/arch/aarch64/msr.h
+++ b/src/arch/aarch64/msr.h
@@ -20,14 +20,14 @@
 
 #define read_msr(name)                                          \
 	__extension__({                                         \
-		size_t __v;                                     \
+		uintreg_t __v;                                  \
 		__asm__ volatile("mrs %0, " #name : "=r"(__v)); \
 		__v;                                            \
 	})
 
-#define write_msr(name, value)                             \
-	do {                                               \
-		__asm__ volatile("msr " #name ", %x0"      \
-				 :                         \
-				 : "rZ"((size_t)(value))); \
+#define write_msr(name, value)                                \
+	do {                                                  \
+		__asm__ volatile("msr " #name ", %x0"         \
+				 :                            \
+				 : "rZ"((uintreg_t)(value))); \
 	} while (0)
diff --git a/src/arch/fake/inc/hf/arch/cpu.h b/src/arch/fake/inc/hf/arch/cpu.h
index 270942e..d374bcb 100644
--- a/src/arch/fake/inc/hf/arch/cpu.h
+++ b/src/arch/fake/inc/hf/arch/cpu.h
@@ -20,9 +20,11 @@
 
 #include "hf/addr.h"
 
+typedef uint64_t uintreg_t;
+
 struct arch_regs {
-	uint64_t r[5];
-	uint16_t vcpu_index;
+	uintreg_t r[5];
+	uintreg_t vcpu_index;
 };
 
 static inline void arch_irq_disable(void)
@@ -41,7 +43,8 @@
 	(void)is_primary;
 }
 
-static inline void arch_regs_init(struct arch_regs *r, ipaddr_t pc, size_t arg)
+static inline void arch_regs_init(struct arch_regs *r, ipaddr_t pc,
+				  uintreg_t arg)
 {
 	/* TODO */
 	(void)pc;
@@ -52,7 +55,7 @@
 	r->vcpu_index = index;
 }
 
-static inline void arch_regs_set_retval(struct arch_regs *r, size_t v)
+static inline void arch_regs_set_retval(struct arch_regs *r, uintreg_t v)
 {
 	r->r[0] = v;
 }
diff --git a/src/cpu.c b/src/cpu.c
index 739fdcc..9c7484b 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -28,7 +28,7 @@
 #include "vmapi/hf/call.h"
 
 /* The stack to be used by the CPUs. */
-alignas(2 * sizeof(size_t)) static char callstacks[MAX_CPUS][STACK_SIZE];
+alignas(2 * sizeof(uintreg_t)) static char callstacks[MAX_CPUS][STACK_SIZE];
 
 /* State of all supported CPUs. The stack of the first one is initialized. */
 struct cpu cpus[MAX_CPUS] = {
@@ -82,7 +82,7 @@
 /**
  * Turns CPU on and returns the previous state.
  */
-bool cpu_on(struct cpu *c, ipaddr_t entry, size_t arg)
+bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg)
 {
 	bool prev;
 
diff --git a/src/fdt.c b/src/fdt.c
index 3f7804e..b0cc45b 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -353,7 +353,7 @@
 			dlog("%*sNew node: \"%s\"\n", 2 * depth, "", name);
 			depth++;
 			while (fdt_next_property(&t, &name, &buf, &size)) {
-				size_t i;
+				uint32_t i;
 				dlog("%*sproperty: \"%s\" (", 2 * depth, "",
 				     name);
 				for (i = 0; i < size; i++) {
@@ -379,7 +379,8 @@
 	{
 		struct fdt_reserve_entry *e =
 			(struct fdt_reserve_entry
-				 *)((size_t)hdr + be32toh(hdr->off_mem_rsvmap));
+				 *)((uintptr_t)hdr +
+				    be32toh(hdr->off_mem_rsvmap));
 		while (e->address || e->size) {
 			dlog("Entry: %p (0x%x bytes)\n", be64toh(e->address),
 			     be64toh(e->size));
@@ -388,10 +389,11 @@
 	}
 }
 
-void fdt_add_mem_reservation(struct fdt_header *hdr, size_t addr, size_t len)
+void fdt_add_mem_reservation(struct fdt_header *hdr, uint64_t addr,
+			     uint64_t len)
 {
 	/* TODO: Clean this up. */
-	char *begin = (char *)hdr + be32toh(hdr->off_mem_rsvmap);
+	uint8_t *begin = (uint8_t *)hdr + be32toh(hdr->off_mem_rsvmap);
 	struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)begin;
 	hdr->totalsize = htobe32(be32toh(hdr->totalsize) +
 				 sizeof(struct fdt_reserve_entry));
@@ -410,7 +412,7 @@
 	return sizeof(struct fdt_header);
 }
 
-size_t fdt_total_size(struct fdt_header *hdr)
+uint32_t fdt_total_size(struct fdt_header *hdr)
 {
 	return be32toh(hdr->totalsize);
 }
diff --git a/src/fdt_handler.c b/src/fdt_handler.c
index 851facd..c29a0e2 100644
--- a/src/fdt_handler.c
+++ b/src/fdt_handler.c
@@ -232,7 +232,7 @@
 		goto out_unmap_fdt;
 	}
 
-	p->kernel_arg = (size_t)fdt;
+	p->kernel_arg = (uintreg_t)fdt;
 	ret = true;
 
 out_unmap_fdt:
diff --git a/src/load.c b/src/load.c
index c118b89..9779e2e 100644
--- a/src/load.c
+++ b/src/load.c
@@ -110,8 +110,7 @@
 /**
  * Loads the primary VM.
  */
-// TODO: kernel_arg is a size_t???
-bool load_primary(const struct memiter *cpio, size_t kernel_arg,
+bool load_primary(const struct memiter *cpio, uintreg_t kernel_arg,
 		  struct memiter *initrd)
 {
 	struct memiter it;
diff --git a/src/vm.c b/src/vm.c
index c840c2a..02b60ff 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -69,7 +69,7 @@
 }
 
 /* TODO: Shall we use index or id here? */
-void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg)
+void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg)
 {
 	struct vcpu *vcpu = &vm->vcpus[index];
 	if (index < vm->vcpu_count) {