<commit_before>#include "console.h"
#include "gdt.h"
#include "paging.h"
#include "string.h"
#include "task.h"
#include "util.h"

static_assert(tss_t_is_0x68_bytes_long, sizeof(tss_t) == 0x68);

static tss_t
tss;

void
task_init()
{
    printf("setting up TSS at 0x%x\n", &tss);

    gdt_set_tss(GDT_TSS, (uint32_t)&tss, sizeof(tss));
    gdt_reload();

    tss.ss0 = GDT_KERNEL_DATA;
    tss.esp0 = KERNEL_STACK_END;

    // pointer to the IO permission bitmap is beyond the end of the segment
    tss.iopb = sizeof(tss);

    __asm__ volatile("ltr ax" :: "a"((uint16_t)GDT_TSS));
}

void
task_new(task_t* task, const char* name)
{
    memset32(&task->regs, 0, sizeof(task->regs) / sizeof(uint32_t));

    task->kernel_stack = page_alloc();

    strlcpy(task->name, name, sizeof(task->name));
}<commit_msg>set ring 3 on the tss selector<commit_after>#include "console.h"
#include "gdt.h"
#include "paging.h"
#include "string.h"
#include "task.h"
#include "util.h"

static_assert(tss_t_is_0x68_bytes_long, sizeof(tss_t) == 0x68);

static tss_t
tss;

void
task_init()
{
    printf("setting up TSS at 0x%x\n", &tss);

    gdt_set_tss(GDT_TSS, (uint32_t)&tss, sizeof(tss));
    gdt_reload();

    tss.ss0 = GDT_KERNEL_DATA;
    tss.esp0 = KERNEL_STACK_END;

    // pointer to the IO permission bitmap is beyond the end of the segment
    tss.iopb = sizeof(tss);

    __asm__ volatile("ltr ax" :: "a"((uint16_t)GDT_TSS | 3));
}

void
task_new(task_t* task, const char* name)
{
    memset32(&task->regs, 0, sizeof(task->regs) / sizeof(uint32_t));

    task->kernel_stack = page_alloc();

    strlcpy(task->name, name, sizeof(task->name));
}
{'fraction_non_alphanumeric': 0.1559633027522936, 'fraction_numerical': 0.023241590214067277, 'mean_word_length': 4.260450160771704, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6391173', 'n_tokens_mistral': 716, 'n_tokens_neox': 682, 'n_words': 143}