<commit_before>// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file
 * @brief Core dump port implementation for RISC-V based boards.
 */

#include <string.h>
#include <stdbool.h>
#include "soc/soc_memory_layout.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "riscv/rvruntime-frames.h"
#include "esp_rom_sys.h"
#include "esp_core_dump_common.h"
#include "esp_core_dump_port.h"

/* TAG used for logs */
const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port";

/* Code associated to RISC-V in ELF format */
#define COREDUMP_EM_RISCV                   0xF3

#define COREDUMP_INVALID_CAUSE_VALUE        0xFFFF
#define COREDUMP_FAKE_STACK_START           0x20000000
#define COREDUMP_FAKE_STACK_LIMIT           0x30000000

#if CONFIG_ESP_COREDUMP_ENABLE

#define min(a,b) ((a) < (b) ? (a) : (b))

/**
 * Union representing the registers of the CPU as they will be written
 * in the core dump.
 * Registers can be adressed with their names thanks to the structure, or as
 * an array of 32 words.
 */
#define RISCV_GP_REGS_COUNT 32

typedef union {
    struct {
        uint32_t pc;
        uint32_t ra;
        uint32_t sp;
        uint32_t gp;
        uint32_t tp;
        uint32_t t0;
        uint32_t t1;
        uint32_t t2;
        uint32_t s0;
        uint32_t s1;
        uint32_t a0;
        uint32_t a1;
        uint32_t a2;
        uint32_t a3;
        uint32_t a4;
        uint32_t a5;
        uint32_t a6;
        uint32_t a7;
        uint32_t s2;
        uint32_t s3;
        uint32_t s4;
        uint32_t s5;
        uint32_t s6;
        uint32_t s7;
        uint32_t s8;
        uint32_t s9;
        uint32_t s10;
        uint32_t s11;
        uint32_t t3;
        uint32_t t4;
        uint32_t t5;
        uint32_t t6;
    };

    uint32_t as_array[RISCV_GP_REGS_COUNT];
} riscv_regs;

/**
 * The following structure represents the NOTE section in the coredump.
 * Its type must be PR_STATUS as it contains the regsiters values and the
 * program status.
 * As our coredump will be used with GDB, we only need to fill the info
 * it needs. We are going to use the macros taken from GDB's elf32-riscv.c
 * Here is the structure GDB needs for PRSTATUS note:
 *
 * +---------------------------+--------------+---------------------------------+
 * |          Offset           | Size (bytes) |              Data               |
 * +---------------------------+--------------+---------------------------------+
 * | PRSTATUS_OFFSET_PR_CURSIG |            2 | Signal that triggered the panic |
 * | PRSTATUS_OFFSET_PR_PID    |            4 | PID                             |
 * | PRSTATUS_OFFSET_PR_REG    |           32 | Registers value                 |
 * +---------------------------+--------------+---------------------------------+
 *
 * Other fields are not strictly required by GDB, we can then replace them
 * by a padding. Among these fields, we can find PPID, SID or system time.
 */
#define PRSTATUS_SIZE				204
#define PRSTATUS_OFFSET_PR_CURSIG	12
#define PRSTATUS_OFFSET_PR_PID		24
#define PRSTATUS_OFFSET_PR_REG		72
#define ELF_GREGSET_T_SIZE		    128

/* We can determine the padding thank to the previous macros */
#define PRSTATUS_SIG_PADDING        (PRSTATUS_OFFSET_PR_CURSIG)
#define PRSTATUS_PID_PADDING        (PRSTATUS_OFFSET_PR_PID - PRSTATUS_OFFSET_PR_CURSIG - sizeof(uint32_t))
#define PRSTATUS_REG_PADDING        (PRSTATUS_OFFSET_PR_REG - PRSTATUS_OFFSET_PR_PID - sizeof(uint32_t))
#define PRSTATUS_END_PADDING        (PRSTATUS_SIZE - PRSTATUS_OFFSET_PR_REG - ELF_GREGSET_T_SIZE)

typedef struct {<commit_msg>fix(coredump): pr_status pid padding should be uint16<commit_after>// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file
 * @brief Core dump port implementation for RISC-V based boards.
 */

#include <string.h>
#include <stdbool.h>
#include "soc/soc_memory_layout.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "riscv/rvruntime-frames.h"
#include "esp_rom_sys.h"
#include "esp_core_dump_common.h"
#include "esp_core_dump_port.h"

/* TAG used for logs */
const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port";

/* Code associated to RISC-V in ELF format */
#define COREDUMP_EM_RISCV                   0xF3

#define COREDUMP_INVALID_CAUSE_VALUE        0xFFFF
#define COREDUMP_FAKE_STACK_START           0x20000000
#define COREDUMP_FAKE_STACK_LIMIT           0x30000000

#if CONFIG_ESP_COREDUMP_ENABLE

#define min(a,b) ((a) < (b) ? (a) : (b))

/**
 * Union representing the registers of the CPU as they will be written
 * in the core dump.
 * Registers can be adressed with their names thanks to the structure, or as
 * an array of 32 words.
 */
#define RISCV_GP_REGS_COUNT 32

typedef union {
    struct {
        uint32_t pc;
        uint32_t ra;
        uint32_t sp;
        uint32_t gp;
        uint32_t tp;
        uint32_t t0;
        uint32_t t1;
        uint32_t t2;
        uint32_t s0;
        uint32_t s1;
        uint32_t a0;
        uint32_t a1;
        uint32_t a2;
        uint32_t a3;
        uint32_t a4;
        uint32_t a5;
        uint32_t a6;
        uint32_t a7;
        uint32_t s2;
        uint32_t s3;
        uint32_t s4;
        uint32_t s5;
        uint32_t s6;
        uint32_t s7;
        uint32_t s8;
        uint32_t s9;
        uint32_t s10;
        uint32_t s11;
        uint32_t t3;
        uint32_t t4;
        uint32_t t5;
        uint32_t t6;
    };

    uint32_t as_array[RISCV_GP_REGS_COUNT];
} riscv_regs;

/**
 * The following structure represents the NOTE section in the coredump.
 * Its type must be PR_STATUS as it contains the regsiters values and the
 * program status.
 * As our coredump will be used with GDB, we only need to fill the info
 * it needs. We are going to use the macros taken from GDB's elf32-riscv.c
 * Here is the structure GDB needs for PRSTATUS note:
 *
 * +---------------------------+--------------+---------------------------------+
 * |          Offset           | Size (bytes) |              Data               |
 * +---------------------------+--------------+---------------------------------+
 * | PRSTATUS_OFFSET_PR_CURSIG |            2 | Signal that triggered the panic |
 * | PRSTATUS_OFFSET_PR_PID    |            4 | PID                             |
 * | PRSTATUS_OFFSET_PR_REG    |           32 | Registers value                 |
 * +---------------------------+--------------+---------------------------------+
 *
 * Other fields are not strictly required by GDB, we can then replace them
 * by a padding. Among these fields, we can find PPID, SID or system time.
 */
#define PRSTATUS_SIZE				204
#define PRSTATUS_OFFSET_PR_CURSIG	12
#define PRSTATUS_OFFSET_PR_PID		24
#define PRSTATUS_OFFSET_PR_REG		72
#define ELF_GREGSET_T_SIZE		    128

/* We can determine the padding thank to the previous macros */
#define PRSTATUS_SIG_PADDING        (PRSTATUS_OFFSET_PR_CURSIG)
#define PRSTATUS_PID_PADDING        (PRSTATUS_OFFSET_PR_PID - PRSTATUS_OFFSET_PR_CURSIG - sizeof(uint16_t))
#define PRSTATUS_REG_PADDING        (PRSTATUS_OFFSET_PR_REG - PRSTATUS_OFFSET_PR_PID - sizeof(uint32_t))
#define PRSTATUS_END_PADDING        (PRSTATUS_SIZE - PRSTATUS_OFFSET_PR_REG - ELF_GREGSET_T_SIZE)

typedef struct {
{'fraction_non_alphanumeric': 0.12461170848267622, 'fraction_numerical': 0.037037037037037035, 'mean_word_length': 2.172034861690034, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7483164', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2646, 'n_words': 828}