<commit_before>#include "config.h"
#include "console.h"
#include "context.h"
#include "sbi_files.h"
#include "tinycstd.h"
#include "trap.h"
#include "mmu.h"
#include "elf.h"

#include "linker-syms.h"
#include <stdint.h>

int main(int argc, char** argv);
void usermode_test();

extern void perform_initial_ctxt_switch(uint64_t satp, struct registers* regs);
extern void _start_hang();


void setup_kernel_context(uint64_t lowest_lo_page, uint64_t highest_lo_page, uint64_t lowest_mid_page
        , uint64_t highest_mid_page, uint64_t lowest_hi_page, uint64_t highest_hi_page) {
    kernel_context.id = 0;

    kernel_context.pt = kernel_pt;

    kernel_context.program_break = highest_mid_page;

    // no need to ever save the kernel's registers

    kernel_context.legal_memory_boundaries.lowest_lo_page = lowest_lo_page;
    kernel_context.legal_memory_boundaries.highest_lo_page = highest_lo_page;
    kernel_context.legal_memory_boundaries.lowest_mid_page = lowest_mid_page;
    kernel_context.legal_memory_boundaries.highest_mid_page = highest_mid_page;
    kernel_context.legal_memory_boundaries.lowest_hi_page = lowest_hi_page;
    kernel_context.legal_memory_boundaries.highest_mid_page = highest_hi_page;
}

void bootstrap() {
    uint64_t val = 0xF00DBEEF;

    console_init();

    // TODO: Assert trampoline positioning on page boundary

    puts("Setting up kernel page table...\n");
    // No need to clear the page table - the BSS section is cleared automagically
    uint64_t stack_end = ((uint64_t)&_payload_end) + PAGESIZE * NUM_STACK_PAGES;
    setup_kernel_context(((uint64_t)&_payload_start) >> 12, ((uint64_t) &_payload_end) >> 12, stack_end >> 12
            , stack_end >> 12, TRAMPOLINE_VADDR >> 12, TRAMPOLINE_VADDR >> 12);
    kidentity_map_range(kernel_pt, &_payload_start, &_payload_end);
    kidentity_map_range(kernel_pt, &_payload_end, (void*)stack_end);

    // Map kernel upper half to its own vspace
    kmap_kernel_upper_half(kernel_pt);
<commit_msg>sbi_wrapper: Remove unused variable<commit_after>#include "config.h"
#include "console.h"
#include "context.h"
#include "sbi_files.h"
#include "tinycstd.h"
#include "trap.h"
#include "mmu.h"
#include "elf.h"

#include "linker-syms.h"
#include <stdint.h>

int main(int argc, char** argv);
void usermode_test();

extern void perform_initial_ctxt_switch(uint64_t satp, struct registers* regs);
extern void _start_hang();


void setup_kernel_context(uint64_t lowest_lo_page, uint64_t highest_lo_page, uint64_t lowest_mid_page
        , uint64_t highest_mid_page, uint64_t lowest_hi_page, uint64_t highest_hi_page) {
    kernel_context.id = 0;

    kernel_context.pt = kernel_pt;

    kernel_context.program_break = highest_mid_page;

    // no need to ever save the kernel's registers

    kernel_context.legal_memory_boundaries.lowest_lo_page = lowest_lo_page;
    kernel_context.legal_memory_boundaries.highest_lo_page = highest_lo_page;
    kernel_context.legal_memory_boundaries.lowest_mid_page = lowest_mid_page;
    kernel_context.legal_memory_boundaries.highest_mid_page = highest_mid_page;
    kernel_context.legal_memory_boundaries.lowest_hi_page = lowest_hi_page;
    kernel_context.legal_memory_boundaries.highest_mid_page = highest_hi_page;
}

void bootstrap() {
    console_init();

    // TODO: Assert trampoline positioning on page boundary

    puts("Setting up kernel page table...\n");
    // No need to clear the page table - the BSS section is cleared automagically
    uint64_t stack_end = ((uint64_t)&_payload_end) + PAGESIZE * NUM_STACK_PAGES;
    setup_kernel_context(((uint64_t)&_payload_start) >> 12, ((uint64_t) &_payload_end) >> 12, stack_end >> 12
            , stack_end >> 12, TRAMPOLINE_VADDR >> 12, TRAMPOLINE_VADDR >> 12);
    kidentity_map_range(kernel_pt, &_payload_start, &_payload_end);
    kidentity_map_range(kernel_pt, &_payload_end, (void*)stack_end);

    // Map kernel upper half to its own vspace
    kmap_kernel_upper_half(kernel_pt);

{'fraction_non_alphanumeric': 0.09510595358224017, 'fraction_numerical': 0.018920282542885972, 'mean_word_length': 5.128284389489954, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '6235207', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1364, 'n_words': 280}