/*
 * ramconsole-dump.c - Dump contents of kernel ramconsole
 *
 * Copyright (C) 2009 Timo Juhani Lindfors <timo.lindfors@iki.fi>
 *  
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>

#define CRASHDUMP_BASE (0x30000000 + (64<<20))
#define CRASHDUMP_SIZE (64<<20)

int main(int argc, char *argv[]) {
    unsigned char *crashdump;
    int fd, i;
    unsigned char marker = 'C';

    fd = open("/dev/mem", O_RDWR);
    if (fd < 0) {
        perror("/dev/mem");
        exit(1);
    }
    if (argc >= 2) {
        marker = argv[1][0];
    }

    crashdump = mmap(NULL,
                     CRASHDUMP_SIZE,
                     PROT_READ | PROT_WRITE,
                     MAP_SHARED,
                     fd,
                     CRASHDUMP_BASE);
    if (crashdump == MAP_FAILED) {
        perror("mmap");
        exit(1);
    }

    for (i = 0; i < CRASHDUMP_SIZE; i++) {
        crashdump[i++] = marker;
        crashdump[i++] = 0;
        crashdump[i++] = 0;
        crashdump[i] = 0;
    }
    return 0;
}
