<commit_before>#include <io.h>
#include <task.h>
#include <debug.h>
#include <syscall.h>
#include <scheduler.h>

//TODO: reqest should be a pointer to an object that hold all of the arguments
unsigned int  _syscall(int code, void* request) {
    // on init code will be in r0 so we can easily pass it to the handler
    UNUSED(code);
    UNUSED(request);
    asm("swi 0");

    // r0 will have the return value of the operation
    register unsigned int ret asm ("r0");
    return ret;
}

int syscall_handle (uint code, void* request, uint* sp) {
    //    kprintf( "\nIC:\t%p\nR1:\t%p\nSP:\t%p\n", code, request, sp);
    task_active->sp = sp;

    switch(code) {
    case SYS_CREATE: {
        kreq_create* r = (kreq_create*) request;
        //debug_log("CREATING TASK (%d): %p", r->priority, r->code);
	task_create(task_active->tid, r->priority, r->code);
        break;
    }
    case SYS_TID:
        sp[0] = (uint)task_active->tid;
        break;
    case SYS_PTID:
        sp[0] = (uint)task_active->p_tid;
        break;
    case SYS_PASS:
	break;
    case SYS_EXIT:
	debug_log("Task %d exiting", task_active->tid);
	// task_destroy(task_active); // this works, but I wanted to test something...
	scheduler_get_next();
	scheduler_activate();
	break;
    case SYS_PRIORITY:
        sp[0] = (uint)task_active->priority;
        break;
    default:
	assert(false, "Invalid system call");
    }

    vt_flush();
    kernel_exit(task_active->sp);
    return 0;
}

int Create( int priority, void (*code) () ) {
    kreq_create req;
    req.code = code;
    req.priority = priority;

    // TODO: check priority level is valid

    return _syscall(SYS_CREATE, &req);
}

int myTid() {
    return _syscall(SYS_TID, NULL);
}

int myParentTid() {
    return _syscall(SYS_PTID, NULL);
}

int myPriority() {
    return _syscall(SYS_PRIORITY, NULL);
}

void Pass() {
    _syscall(SYS_PASS, NULL);
}

void Exit() {
    _syscall(SYS_EXIT, NULL);
}
<commit_msg>Actually pass the task id back to user space on Create()<commit_after>#include <io.h>
#include <task.h>
#include <debug.h>
#include <syscall.h>
#include <scheduler.h>

//TODO: reqest should be a pointer to an object that hold all of the arguments
unsigned int  _syscall(int code, void* request) {
    // on init code will be in r0 so we can easily pass it to the handler
    UNUSED(code);
    UNUSED(request);
    asm("swi 0");

    // r0 will have the return value of the operation
    register unsigned int ret asm ("r0");
    return ret;
}

int syscall_handle (uint code, void* request, uint* sp) {
    //    kprintf( "\nIC:\t%p\nR1:\t%p\nSP:\t%p\n", code, request, sp);
    task_active->sp = sp;

    switch(code) {
    case SYS_CREATE: {
        kreq_create* r = (kreq_create*) request;
        //debug_log("CREATING TASK (%d): %p", r->priority, r->code);
	sp[0] = task_create(task_active->tid, r->priority, r->code);
        break;
    }
    case SYS_TID:
        sp[0] = (uint)task_active->tid;
        break;
    case SYS_PTID:
        sp[0] = (uint)task_active->p_tid;
        break;
    case SYS_PASS:
	break;
    case SYS_EXIT:
	debug_log("Task %d exiting", task_active->tid);
	// task_destroy(task_active); // this works, but I wanted to test something...
	scheduler_get_next();
	scheduler_activate();
	break;
    case SYS_PRIORITY:
        sp[0] = (uint)task_active->priority;
        break;
    default:
	assert(false, "Invalid system call");
    }

    vt_flush();
    kernel_exit(task_active->sp);
    return 0;
}

int Create( int priority, void (*code) () ) {
    kreq_create req;
    req.code = code;
    req.priority = priority;

    // TODO: check priority level is valid

    return _syscall(SYS_CREATE, &req);
}

int myTid() {
    return _syscall(SYS_TID, NULL);
}

int myParentTid() {
    return _syscall(SYS_PTID, NULL);
}

int myPriority() {
    return _syscall(SYS_PRIORITY, NULL);
}

void Pass() {
    _syscall(SYS_PASS, NULL);
}

void Exit() {
    _syscall(SYS_EXIT, NULL);
}

{'fraction_non_alphanumeric': 0.13874147081122062, 'fraction_numerical': 0.004801617386909275, 'mean_word_length': 2.961961961961962, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, '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': '2041423', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1410, 'n_words': 389}