Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 1 | #include "defs.h" |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 2 | |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 3 | #include "xlat/kexec_load_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 4 | #include "xlat/kexec_arch_values.h" |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 5 | |
| 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 12 | |
| 13 | static void |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 14 | print_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 | |
| 24 | static void |
| 25 | print_kexec_segments(struct tcb *tcp, const unsigned long addr, |
| 26 | const unsigned long len) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 27 | { |
| 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. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 44 | struct { |
| 45 | void *buf; |
| 46 | size_t bufsz; |
| 47 | void *mem; |
| 48 | size_t memsz; |
| 49 | } seg; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 50 | # define sizeof_seg sizeof(seg) |
Dmitry V. Levin | 900ec1b | 2014-02-06 21:13:36 +0000 | [diff] [blame] | 51 | # 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 55 | #endif |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 56 | unsigned int i; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 57 | |
| 58 | if (!len) { |
| 59 | tprints("[]"); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (len > KEXEC_SEGMENT_MAX) { |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 64 | printaddr(addr); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 68 | if (umoven_or_printaddr(tcp, addr, sizeof_seg, &seg)) |
| 69 | return; |
| 70 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 71 | tprints("["); |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 72 | 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 79 | break; |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 80 | print_seg((unsigned long) seg_buf, seg_bufsz, |
| 81 | (unsigned long) seg_mem, seg_memsz); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 82 | } |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 83 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 84 | tprints("]"); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 87 | SYS_FUNC(kexec_load) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 88 | { |
| 89 | unsigned long n; |
| 90 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 91 | /* entry, nr_segments */ |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 92 | printaddr(tcp->u_arg[0]); |
| 93 | tprintf(", %lu, ", tcp->u_arg[1]); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 94 | |
| 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. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 105 | printflags(kexec_load_flags, n, "KEXEC_???"); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 108 | return RVAL_DECODED; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 109 | } |