Skip to content

Commit da900a5

Browse files
committed
LKMC v3.0
This is a squash commit, the unsquashed development went through many unstable phases which would break bisects. The unsquashed branch is: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/v3.0-unsquash The main improvement of this release was to greatly generalize the testing system. The key addition was cli_function.py, which allows scripts such as ./run to be transparently called either from Python or from the command line. New tests scripts were created using this improved framework: test-baremetal and test-user-mode. We were lazy to port some of less important tests to the new setup, TODO's were added, and we need comes they will be fixed. Getting started is however sacred as usual and should work. Other changes include: - gem5: update to 7fa4c946386e7207ad5859e8ade0bbfc14000d91 - run: --tmux-args implies --tmux - run: add --userland-args to make userland arguments across QEMU and gem5 Get rid of --userland-before as a consequence. - bring initrd and initramfs back to life - build-userland: create --static to make build a bit easier - gem5: --gem5-worktree also set --gem5-build-id - remove --gem5, use --emulator gem5 everywhere Allow passing --emulator multiple times for transparent tests selection just like --arch. - test-userland: allow selecting just a few tests - linux: update to v4.20 - buildroot: update to 2018.08 The main motivation for this was to fix the build for Ubuntu 18.10, which has glibc 2.28, which broke the 2018.05 build at the m4-host package with: #error "Please port gnulib fseeko.c to your platform! - getvar --type input - failed xen attempt, refactor timer, failed svc attempt, aarch64 use gicv3 - build-doc: exit 1 on error, add to release testing - build: add --apt option to make things easier on other distros - build-linux: --no-modules-install
1 parent 3b0a343 commit da900a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5235
-3537
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
[submodule "submodules/qemu"]
2222
path = submodules/qemu
2323
url = https://github.com/cirosantilli/qemu
24+
[submodule "submodules/xen"]
25+
path = submodules/xen
26+
url = git://xenbits.xen.org/xen.git
27+
[submodule "submodules/boot-wrapper-aarch64"]
28+
path = submodules/boot-wrapper-aarch64
29+
url = git://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git

README.adoc

Lines changed: 658 additions & 335 deletions
Large diffs are not rendered by default.

arm

Lines changed: 0 additions & 3 deletions
This file was deleted.

baremetal/add.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <common.h>
22

33
int main(void) {
4-
int i, j, k;
5-
i = 1;
4+
int i, j, k;
5+
i = 1;
66
/* test-gdb-op1 */
7-
j = 2;
7+
j = 2;
88
/* test-gdb-op2 */
9-
k = i + j;
9+
k = i + j;
1010
/* test-gdb-result */
11-
if (k != 3)
12-
common_assert_fail();
11+
if (k != 3)
12+
common_assert_fail();
1313
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef COMMON_AARCH64_H
2+
#define COMMON_AARCH64_H
3+
4+
#include <inttypes.h>
5+
6+
#define SYSREG_READ(type, name) \
7+
type sysreg_ ## name ## _read(void) { \
8+
type name; \
9+
__asm__ __volatile__("mrs %0, " #name : "=r" (name) : : ); \
10+
return name; \
11+
}
12+
13+
#define SYSREG_WRITE(type, name) \
14+
void sysreg_ ## name ## _write(type name) { \
15+
__asm__ __volatile__("msr " #name ", %0" : : "r" (name) : ); \
16+
}
17+
18+
#define SYSREG_READ_WRITE(name, type) \
19+
SYSREG_READ(name, type) \
20+
SYSREG_WRITE(name, type)
21+
22+
#define SVC(immediate) __asm__ __volatile__("svc " #immediate : : : )
23+
24+
#endif

baremetal/arch/aarch64/el.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55

66
int main(void) {
7-
register uint64_t x0 __asm__ ("x0");
8-
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
9-
printf("%" PRIu64 "\n", x0 >> 2);
10-
return 0;
7+
uint64_t el;
8+
__asm__ ("mrs %0, CurrentEL;" : "=r" (el) : :);
9+
printf("%" PRIu64 "\n", el >> 2);
10+
return 0;
1111
}

baremetal/arch/aarch64/multicore.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ main:
99

1010
/* Read cpu id into x1.
1111
* TODO: cores beyond 4th?
12+
* Mnemonic: Main Processor ID Register
1213
*/
1314
mrs x1, mpidr_el1
1415
ands x1, x1, 3

baremetal/arch/aarch64/svc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
4+
#include "common_aarch64.h"
5+
6+
/* Masks each of the 4 exception types: Synchronous, System error,
7+
* IRQ and FIQ.
8+
*/
9+
SYSREG_READ_WRITE(uint32_t, daif)
10+
11+
/* Determines if we use SP0 or SPx. Default: SP0.
12+
* See also: https://stackoverflow.com/questions/29393677/armv8-exception-vector-significance-of-el0-sp
13+
*/
14+
SYSREG_READ_WRITE(uint32_t, spsel)
15+
16+
/* Jump to this SP if spsel == SPx. */
17+
SYSREG_READ_WRITE(uint64_t, sp_el1)
18+
19+
int main(void) {
20+
printf("daif 0x%" PRIx32 "\n", sysreg_daif_read());
21+
printf("spsel 0x%" PRIx32 "\n", sysreg_spsel_read());
22+
/* TODO this breaks execution because reading system registers that end
23+
* in ELx "trap", leading into an exception on the upper EL.
24+
*/
25+
/*printf("sp_el1 0x%" PRIx64 "\n", sysreg_sp_el1_read());*/
26+
/*SVC(0);*/
27+
return 0;
28+
}

baremetal/arch/aarch64/timer.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
4+
#include "common_aarch64.h"
5+
6+
#define CNTV_CTL_ENABLE (1 << 0)
7+
#define CNTV_CTL_IMASK (1 << 1)
8+
#define CNTV_CTL_ISTATUS (1 << 2)
9+
10+
/* Frequency in Hz. ? */
11+
SYSREG_READ_WRITE(uint64_t, cntfrq_el0)
12+
13+
/* Current virtual counter value. */
14+
SYSREG_READ(uint64_t, cntvct_el0)
15+
16+
/* Compare value. See: cntv_ctl_el0_enable. */
17+
SYSREG_READ_WRITE(uint64_t, cntv_cval_el0)
18+
19+
/* On write, set cntv_cval_el0 = (cntvct_el0 + cntv_tval_el0).
20+
* This means that the next interrupt will happen in cntv_tval_el0 cycles.
21+
*/
22+
SYSREG_READ_WRITE(uint64_t, cntv_tval_el0)
23+
24+
/* Control register. */
25+
SYSREG_READ_WRITE(uint32_t, cntv_ctl_el0)
26+
27+
void cntv_ctl_el0_disable(void) {
28+
sysreg_cntv_ctl_el0_write(sysreg_cntv_ctl_el0_read() & ~CNTV_CTL_ENABLE);
29+
}
30+
31+
/* If enabled, when: cntv_ctl > cntv_cval then:
32+
*
33+
* * if CNTV_CTL_IMASK is clear, raise an interrupt
34+
* * set CNTV_CTL_ISTATUS
35+
*/
36+
void cntv_ctl_el0_enable(void) {
37+
sysreg_cntv_ctl_el0_write(sysreg_cntv_ctl_el0_read() | CNTV_CTL_ENABLE);
38+
}
39+
40+
int main(void) {
41+
/* Initial state. */
42+
printf("cntv_ctl_el0 0x%" PRIx32 "\n", sysreg_cntv_ctl_el0_read());
43+
printf("cntfrq_el0 0x%" PRIx64 "\n", sysreg_cntfrq_el0_read());
44+
printf("cntv_cval_el0 0x%" PRIx64 "\n", sysreg_cntv_cval_el0_read());
45+
46+
/* Get the counter value many times to watch the time pass. */
47+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
48+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
49+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
50+
51+
#if 0
52+
/* TODO crashes gem5. */
53+
puts("cntfrq_el0 = 1");
54+
sysreg_cntfrq_el0_write(1);
55+
printf("cntfrq_el0 0x%" PRIx64 "\n", sysreg_cntfrq_el0_read());
56+
#endif
57+
58+
return 0;
59+
}

baremetal/arch/arm/el.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55

66
int main(void) {
7-
register uint32_t r0 __asm__ ("r0");
8-
__asm__ ("mrs r0, CPSR" : : : "%r0");
9-
printf("%" PRIu32 "\n", r0 & 0x1F);
10-
return 0;
7+
uint32_t cpsr;
8+
__asm__ ("mrs %0, CPSR" : "=r" (cpsr) : :);
9+
printf("%" PRIu32 "\n", cpsr & 0x1F);
10+
return 0;
1111
}

0 commit comments

Comments
 (0)