blob: e7ce07a056887a8be1066d553d5a940ce5ef20e6 [file] [log] [blame]
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +00001#include "defs.h"
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +00002
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +00003#include "xlat/kexec_load_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00004#include "xlat/kexec_arch_values.h"
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +00005
6#ifndef KEXEC_ARCH_MASK
7# define KEXEC_ARCH_MASK 0xffff0000
8#endif
9#ifndef KEXEC_SEGMENT_MAX
10# define KEXEC_SEGMENT_MAX 16
11#endif
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000012
13static void
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000014print_seg(const long seg_buf, const unsigned long seg_bufsz,
15 const long seg_mem, const unsigned long seg_memsz)
16{
17 tprints("{");
18 printaddr(seg_buf);
19 tprintf(", %lu, ", seg_bufsz);
20 printaddr(seg_mem);
21 tprintf(", %lu}", seg_memsz);
22}
23
24static void
25print_kexec_segments(struct tcb *tcp, const unsigned long addr,
26 const unsigned long len)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000027{
28#if SUPPORTED_PERSONALITIES > 1
29 union {
30 struct { u_int32_t buf, bufsz, mem, memsz; } seg32;
31 struct { u_int64_t buf, bufsz, mem, memsz; } seg64;
32 } seg;
33# define sizeof_seg \
34 (current_wordsize == 4 ? sizeof(seg.seg32) : sizeof(seg.seg64))
35# define seg_buf \
36 (current_wordsize == 4 ? (uint64_t) seg.seg32.buf : seg.seg64.buf)
37# define seg_bufsz \
38 (current_wordsize == 4 ? (uint64_t) seg.seg32.bufsz : seg.seg64.bufsz)
39# define seg_mem \
40 (current_wordsize == 4 ? (uint64_t) seg.seg32.mem : seg.seg64.mem)
41# define seg_memsz \
42 (current_wordsize == 4 ? (uint64_t) seg.seg32.memsz : seg.seg64.memsz)
43#else
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000044 struct {
45 void *buf;
46 size_t bufsz;
47 void *mem;
48 size_t memsz;
49 } seg;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000050# define sizeof_seg sizeof(seg)
Dmitry V. Levin900ec1b2014-02-06 21:13:36 +000051# define seg_buf seg.buf
52# define seg_bufsz seg.bufsz
53# define seg_mem seg.mem
54# define seg_memsz seg.memsz
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000055#endif
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000056 unsigned int i;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000057
58 if (!len) {
59 tprints("[]");
60 return;
61 }
62
63 if (len > KEXEC_SEGMENT_MAX) {
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000064 printaddr(addr);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000065 return;
66 }
67
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000068 if (umoven_or_printaddr(tcp, addr, sizeof_seg, &seg))
69 return;
70
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000071 tprints("[");
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000072 print_seg((unsigned long) seg_buf, seg_bufsz,
73 (unsigned long) seg_mem, seg_memsz);
74
75 for (i = 1; i < len; ++i) {
76 tprints(", ");
77 if (umoven_or_printaddr(tcp, addr + i * sizeof_seg,
78 sizeof_seg, &seg))
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000079 break;
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000080 print_seg((unsigned long) seg_buf, seg_bufsz,
81 (unsigned long) seg_mem, seg_memsz);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000082 }
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000083
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000084 tprints("]");
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000085}
86
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000087SYS_FUNC(kexec_load)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000088{
89 unsigned long n;
90
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000091 /* entry, nr_segments */
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000092 printaddr(tcp->u_arg[0]);
93 tprintf(", %lu, ", tcp->u_arg[1]);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000094
95 /* segments */
96 print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]);
97 tprints(", ");
98
99 /* flags */
100 n = tcp->u_arg[3];
101 printxval(kexec_arch_values, n & KEXEC_ARCH_MASK, "KEXEC_ARCH_???");
102 n &= ~KEXEC_ARCH_MASK;
103 if (n) {
104 tprints("|");
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +0000105 printflags(kexec_load_flags, n, "KEXEC_???");
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +0000106 }
107
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +0000108 return RVAL_DECODED;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +0000109}