Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.pyc
*.pyo
*.swp
/arch/x86/*.lds
/arch/*/*.lds
/cscope.*
/dist/
/docs/autogenerated/
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAKEFLAGS += -rR
ROOT := $(abspath $(CURDIR))
export ROOT

# $(xtfdir) defaults to $(ROOT) so development and testing can be done
# straight out of the working tree.
Expand All @@ -19,7 +18,16 @@ endif

xtftestdir := $(xtfdir)/tests

export DESTDIR xtfdir xtftestdir
# Supported architectures
SUPPORTED_ARCH := x86
# Default architecture
ARCH ?= x86

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Discussed on the 17th Aug:) Switch this to default to the build host arch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #5

# Check if specified architecture is supported
ifeq ($(filter $(ARCH),$(SUPPORTED_ARCH)),)
$(error Architecture '$(ARCH)' not supported)
endif

export ROOT DESTDIR ARCH xtfdir xtftestdir

ifeq ($(LLVM),) # GCC toolchain
CC := $(CROSS_COMPILE)gcc
Expand Down Expand Up @@ -50,9 +58,12 @@ PYTHON ?= $(PYTHON_INTERPRETER)

export CC LD CPP INSTALL INSTALL_DATA INSTALL_DIR INSTALL_PROGRAM OBJCOPY PYTHON

# By default enable all the tests
TESTS ?= $(wildcard tests/*)

.PHONY: all
all:
@set -e; for D in $(wildcard tests/*); do \
@set -e; for D in $(TESTS); do \
[ ! -e $$D/Makefile ] && continue; \
$(MAKE) -C $$D build; \
done
Expand All @@ -61,7 +72,7 @@ all:
install:
@$(INSTALL_DIR) $(DESTDIR)$(xtfdir)
$(INSTALL_PROGRAM) xtf-runner $(DESTDIR)$(xtfdir)
@set -e; for D in $(wildcard tests/*); do \
@set -e; for D in $(TESTS); do \
[ ! -e $$D/Makefile ] && continue; \
$(MAKE) -C $$D install; \
done
Expand Down
35 changes: 35 additions & 0 deletions arch/arm/arm32/head.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <xtf/asm_macros.h>

#define ZIMAGE_MAGIC_NUMBER 0x016f2818

.arm

/*
* Common register usage for assembly boot code
*
* r10 - DTB physical address (boot CPU only)
* r9 - Offset between PA and VA ( PA - VA)
*/
ENTRY(_start)
/* 8 NOPs that make the compressed kernel bootable on legacy ARM systems */
.rept 8
mov r0, r0
.endr
b startup
/* Magic number used to identify this is an ARM Linux zImage */
.word ZIMAGE_MAGIC_NUMBER
/* The address the zImage starts at (0 = relocatable) */
.word 0
/* The address the zImage ends at */
.word (_end - _start)
startup:
/* Save DTB pointer */
mov r10, r2

/* Calculate where we are */
ldr r0, =_start /* r0 := vaddr(_start) */
adr r8, _start /* r8 := paddr(_start) */
sub r9, r8, r0 /* r9 := phys-offset */

/* Start an infinite loop */
1: b 1b
26 changes: 26 additions & 0 deletions arch/arm/arm64/cache.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <xtf/asm_macros.h>

/*
* flush_dcache_range(start, end)
* - x0(start) - start address of a region
* - x1(end) - end address of a region
* Clobbers: x2, x3, x4
*/
ENTRY(flush_dcache_range)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was difficult to understand whether the function would clean or just clean & invalidate the cache. How about renaming the function to clean_and_invalidate_dcache()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will rename it to clean_and_invalidate_dcache

/* Do not modify x0 */
mov x4, x0
/* Get the minimum D-cache line size */
mrs x3, ctr_el0
ubfm x3, x3, #16, #19
mov x2, #4
lsl x2, x2, x3
sub x3, x2, #1
bic x4, x4, x3
/* Clean and invalidate D-cache line */
1: dc civac, x4
add x4, x4, x2
cmp x4, x1
b.lo 1b
dsb sy
ret
ENDFUNC(flush_dcache_range)
90 changes: 90 additions & 0 deletions arch/arm/arm64/head.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <arch/page.h>
#include <xtf/asm_macros.h>
#include <xen/xen.h>

/* 1 if BE, 0 if LE */
#define HEAD_FLAG_ENDIANNESS 0
#define HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
#define HEAD_FLAG_PHYS_BASE 1
#define HEAD_FLAGS ((HEAD_FLAG_ENDIANNESS << 0) | \
(HEAD_FLAG_PAGE_SIZE << 1) | \
(HEAD_FLAG_PHYS_BASE << 3))

/*
* Print a string on the debug console
*
* Clobbers: x0, x1, x2, x3, x16
*/
#define PRINT(s) \
adr x2, 98f; \
mov x1, #0; \
97: ldrb w3, [x2, x1]; \
add x1, x1, #1; \
cbnz w3, 97b; \
mov x0, #CONSOLEIO_write; \
mov x16, #__HYPERVISOR_console_io; \
hvc #XEN_HYPERCALL_TAG; \
.pushsection .rodata.str, "aMS", %progbits, 1; \
98: .asciz s; \
.popsection

.section ".bss.page_aligned"
.p2align PAGE_SHIFT

.text
b _start /* branch to kernel start, magic */
.long 0 /* Executable code */
.quad 0x0 /* Image load offset from start of RAM */
.quad _end - _start /* Effective Image size */
.quad HEAD_FLAGS /* Informative flags, little-endian */
.quad 0 /* reserved */
.quad 0 /* reserved */
.quad 0 /* reserved */
.byte 0x41 /* Magic number, "ARM\x64" */
.byte 0x52
.byte 0x4d
.byte 0x64
.long 0 /* reserved */


/* Load a physical address of \sym to \xb */
.macro load_paddr xb, sym
ldr \xb, =\sym
add \xb, \xb, x21
.endm

/*
* Common register usage for assembly boot code
*
* x20 - DTB physical address (boot CPU only)
* x21 - Offset between PA and VA ( PA - VA)
* x30 - lr
*/
ENTRY(_start)
/* Save DTB pointer */
mov x20, x0

/* Calculate where we are */
ldr x22, =_start /* x22 := vaddr(_start) */
adr x21, _start /* x21 := paddr(_start) */
sub x21, x21, x22 /* x21 := phys-offset */

PRINT("- XTF booting -\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make these messages only output for XTF debug configurations?

At the moment, running a XTF test on Arm will generate different console output than running the same test on x86, which will make writing an architecture-independent parser more difficult.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm thinking of right now is adding DEBUG variable which by default will be set to =n. When specifying DEBUG=y on the command line when invoking make, those early prints should be executed. What do u think about it? I may need to discuss this with Andrew.


PRINT("- Zero BSS -\n")

load_paddr x0, __start_bss

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find a bit odd that the arm32 code and arm64 patches already diverge in this commit. I think it would be better if that code stay in par in each commit touch 32-bit and 64-bit.

If you want to add more code for arm64, that's fine. But I would suggest to do it separately.

load_paddr x1, __end_bss

bl flush_dcache_range

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to document in the code why the flush is necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will

1: str xzr, [x0], #8
cmp x0, x1
b.lo 1b

/* Load BSS start address again as x0 has been modified in the upper loop */
load_paddr x0, __start_bss
bl flush_dcache_range

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to document in the code why the flush is necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will


/* Start an infinite loop */
PRINT("- Infinite loop -\n")
2: b 2b
25 changes: 25 additions & 0 deletions arch/arm/decode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file arch/arm/decode.c
*
* Helper routines for decoding arm architectural state.
*/
#include <xtf/lib.h>
#include <xtf/libc.h>

bool arch_fmt_pointer(
char **str_ptr, char *end, const char **fmt_ptr, const void *arg,
int width, int precision, unsigned int flags)
{
UNIMPLEMENTED();
return false;
}

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
71 changes: 71 additions & 0 deletions arch/arm/include/arch/arm32/regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file arch/arm/include/arch/arm32/regs.h
*
* arm32 CPU user registers.
*/
#ifndef XTF_ARM32_REGS_H
#define XTF_ARM32_REGS_H

#include <xtf/types.h>

#ifndef __ASSEMBLY__
struct cpu_regs
{
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r4;
uint32_t r5;
uint32_t r6;
uint32_t r7;
uint32_t r8;
uint32_t r9;
uint32_t r10;
union {
uint32_t r11;
uint32_t fp;
};
uint32_t r12;
uint32_t sp;

union {
uint32_t lr;
uint32_t lr_usr;
};

union {
uint32_t pc, pc32;
};

uint32_t cpsr;
uint32_t hsr;

uint32_t sp_usr;

uint32_t sp_irq, lr_irq;
uint32_t sp_svc, lr_svc;
uint32_t sp_abt, lr_abt;
uint32_t sp_und, lr_und;

uint32_t r8_fiq, r9_fiq, r10_fiq, r11_fiq, r12_fiq;
uint32_t sp_fiq, lr_fiq;

uint32_t spsr_svc, spsr_abt, spsr_und, spsr_irq, spsr_fiq;

/* The stack should be 8-byte aligned */
uint32_t pad1;
};
#endif /* __ASSEMBLY__ */

#endif /* XTF_ARM32_REGS_H */

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
Loading