<commit_before>/**
 * \file
 * \brief Core boot main
 */
/*
 * Copyright (c) 2013, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

#include <getopt.h>
#include "coreboot.h"

uint64_t start = 0;
uint64_t end = 0;

coreid_t my_arch_id;
struct capref kernel_cap;

bool done = false;

bool debug_flag = false;
bool new_kcb_flag = false;
bool nomsg_flag = false;

char* cmd_kernel_binary = NULL;
char* cmd_monitor_binary = NULL;
char* cmd_kernel_args = "loglevel=2 logmask=0";

static void load_arch_id(void)
{
    struct monitor_blocking_rpc_client *mc = get_monitor_blocking_rpc_client();
    errval_t err = mc->vtbl.get_arch_core_id(mc, (uintptr_t *)&my_arch_id);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "get_arch_core_id failed.");
    }
    DEBUG("%s:%d: my_arch_id is %"PRIuCOREID"\n", __FILE__, __LINE__, my_arch_id);
}

static void setup_monitor_messaging(void)
{
    struct monitor_binding *st = get_monitor_binding();
    st->rx_vtbl.boot_core_reply = boot_core_reply;
    st->rx_vtbl.power_down_response = power_down_response;
}

static void load_kernel_cap(void)
{
    struct monitor_blocking_rpc_client *mc = get_monitor_blocking_rpc_client();
    errval_t err = mc->vtbl.get_kernel_cap(mc, &kernel_cap);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "get_kernel_cap failed.");
    }
}

static void initialize(void)
{
    errval_t err;

    vfs_init();
    bench_arch_init();

    err = connect_to_acpi();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "connect to acpi failed.");
    }

    err = oct_init();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Octopus initialization failed.");
    }

    setup_monitor_messaging();
    load_arch_id();
    load_kernel_cap();
}


typedef int(*cmd_fn)(int argc, char** argv);
struct cmd {
    char* name;
    char* desc;
    char* help;
    cmd_fn fn;
    int argc;
};

static int list_cpu(int argc, char **argv) {
    printf("%s:%s:%d: \n", __FILE__, __FUNCTION__, __LINE__);

    char** names;
    size_t len;
    errval_t err = oct_get_names(&names, &len, "r'hw\\.processor\\.[0-9]+'");
    assert(err_is_ok(err));

    for (size_t i=0; i<len; i++) {
        char* record;
        err = oct_get(&record, names[i]);
        assert(err_is_ok(err));

        uint64_t barrelfish_id, apic_id;
        err = oct_read(record, "_ { barrelfish_id: %d, apic_id: %d }",
                       &barrelfish_id, &apic_id);
        assert(err_is_ok(err));

        printf("CPU %"PRIu64": APIC=%"PRIu64" STATUS=?\n", barrelfish_id, apic_id);
    }
    if (len == 0) {
        DEBUG("%s:%s:%d: No cpus found?\n",
              __FILE__, __FUNCTION__, __LINE__);
    }

    done = true;
    oct_free_names(names, len);
    return 0;
}

static int boot_cpu(int argc, char **argv)
{
    coreid_t target_id = (coreid_t) strtol(argv[1], NULL, 16);
    assert(target_id < MAX_COREID);

    //char* record;
    //errval_t err = oct_get(&record, "hw.processor.* { barrelfish_id: %d }", target_id);


    struct capref kcb;<commit_msg>Change listing of cores to include more ifno.<commit_after>/**
 * \file
 * \brief Core boot main
 */
/*
 * Copyright (c) 2013, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

#include <getopt.h>
#include "coreboot.h"

uint64_t start = 0;
uint64_t end = 0;

coreid_t my_arch_id;
struct capref kernel_cap;

bool done = false;

bool debug_flag = false;
bool new_kcb_flag = false;
bool nomsg_flag = false;

char* cmd_kernel_binary = NULL;
char* cmd_monitor_binary = NULL;
char* cmd_kernel_args = "loglevel=2 logmask=0";

static void load_arch_id(void)
{
    struct monitor_blocking_rpc_client *mc = get_monitor_blocking_rpc_client();
    errval_t err = mc->vtbl.get_arch_core_id(mc, (uintptr_t *)&my_arch_id);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "get_arch_core_id failed.");
    }
    DEBUG("%s:%d: my_arch_id is %"PRIuCOREID"\n", __FILE__, __LINE__, my_arch_id);
}

static void setup_monitor_messaging(void)
{
    struct monitor_binding *st = get_monitor_binding();
    st->rx_vtbl.boot_core_reply = boot_core_reply;
    st->rx_vtbl.power_down_response = power_down_response;
}

static void load_kernel_cap(void)
{
    struct monitor_blocking_rpc_client *mc = get_monitor_blocking_rpc_client();
    errval_t err = mc->vtbl.get_kernel_cap(mc, &kernel_cap);
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "get_kernel_cap failed.");
    }
}

static void initialize(void)
{
    errval_t err;

    vfs_init();
    bench_arch_init();

    err = connect_to_acpi();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "connect to acpi failed.");
    }

    err = oct_init();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Octopus initialization failed.");
    }

    setup_monitor_messaging();
    load_arch_id();
    load_kernel_cap();
}


typedef int(*cmd_fn)(int argc, char** argv);
struct cmd {
    char* name;
    char* desc;
    char* help;
    cmd_fn fn;
    int argc;
};

static int list_cpu(int argc, char **argv) {
    printf("%s:%s:%d: \n", __FILE__, __FUNCTION__, __LINE__);

    char** names;
    size_t len;
    errval_t err = oct_get_names(&names, &len, "r'hw\\.processor\\.[0-9]+'");
    assert(err_is_ok(err));

    for (size_t i=0; i<len; i++) {
        char* record;
        err = oct_get(&record, names[i]);
        assert(err_is_ok(err));

        uint64_t barrelfish_id, apic_id, processor_id, enabled;
        err = oct_read(record, "_ { barrelfish_id: %d, apic_id: %d, processor_id: %d, enabled: %d }",
                       &barrelfish_id, &apic_id, &processor_id, &enabled);
        assert(err_is_ok(err));

        printf("CPU %"PRIu64": APIC_ID=%"PRIu64" APIC_PROCESSOR_ID=%"PRIu64" ENABLED=%"PRIu64"\n",
               barrelfish_id, apic_id, processor_id, enabled);
    }
    if (len == 0) {
        DEBUG("%s:%s:%d: No cpus found?\n",
              __FILE__, __FUNCTION__, __LINE__);
    }

    done = true;
    oct_free_names(names, len);
    return 0;
}

static int boot_cpu(int argc, char **argv)
{
    coreid_t target_id = (coreid_t) strtol(argv[1], NULL, 16);
    assert(target_id < MAX_COREID);

    //char* record;
    //errval_t err = oct_get(&record, "hw.processor.* { barrelfish_id: %d }", target_id);


    struct capref kcb;
{'fraction_non_alphanumeric': 0.13537117903930132, 'fraction_numerical': 0.009938262309893088, 'mean_word_length': 3.4015904572564613, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3190728', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2477, 'n_words': 565}