Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
fuck this
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinAlavik committed Mar 24, 2024
1 parent cfc798e commit 71da05d
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 34 deletions.
4 changes: 1 addition & 3 deletions arch/x86_64/cpu/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ void panic(const char *reason, int_frame_t frame)
draw_image(img, 0, 0, 0);
}

nighterm_set_cursor_position(0, 20);

printf("\tComputer no workie :( \n\n");
nighterm_set_cursor_position(0, 24);

printf("\t* %s\n\n", reason);

Expand Down
29 changes: 16 additions & 13 deletions arch/x86_64/idt/idt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@

#include <stdint.h>

typedef struct {
uint16_t offset_low;
uint16_t selector;
uint8_t ist;
uint8_t flags;
uint16_t offset_middle;
uint32_t offset_high;
uint32_t zero;
typedef struct
{
uint16_t offset_low;
uint16_t selector;
uint8_t ist;
uint8_t flags;
uint16_t offset_middle;
uint32_t offset_high;
uint32_t zero;
} __attribute__((packed)) idt_entry_t;

typedef struct {
uint16_t limit;
uint64_t base;
typedef struct
{
uint16_t limit;
uint64_t base;
} __attribute__((packed)) idt_pointer_t;

typedef struct {
typedef struct
{
uint64_t r15;
uint64_t r14;
uint64_t r13;
Expand Down Expand Up @@ -49,7 +52,7 @@ void load_idt(uint64_t);
void trigger_interupt(uint64_t a);
void set_idt_gate(int num, uint64_t base, uint16_t sel, uint8_t flags);
void init_idt();
void irq_register(uint8_t irq, void* handler);
void irq_register(uint8_t irq, void *handler);
void irq_deregister(uint8_t irq);

#endif /* IDT_H */
15 changes: 6 additions & 9 deletions kernel/entry/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ return codes)
#include <transform.h>
#include <vector.h>

void test()
{
printf("Hello from PID 0!\n");
}

int main()
{
keyboard.out = false;
register_pci();
printf("-------------------------\n\n");
vfs_op_status status;
char *motd;
status = driver_read(vfs, 0, "/etc/motd", &motd);

if (status != STATUS_OK)
return KERNEL_QUIT_ERROR;

printf("%s\n", motd);
spawn_process(0, test);
return KERNEL_QUIT_HANG;
}
1 change: 0 additions & 1 deletion kernel/system/pit/pit.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void pit_set_count(uint16_t count)
void pit_handler(int_frame_t *frame)
{
cur_frame = frame;
// update_wm();
pit_int();
}

Expand Down
77 changes: 70 additions & 7 deletions kernel/system/processes/processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,85 @@
#include <entry/init.h>
#include <system/memory/pmm.h>

struct Process processes[MAX_PROCESSES];

int_frame_t *cur_ctx = NULL;
struct Process *processes[MAX_PROCESSES];

void switch_context(uint16_t pid)
{
(void)pid;
if (processes[pid] == NULL || processes[pid]->context == NULL)
{
dprintf("[\e[0;31mProcesses\e[0m] Process with PID \"%d\" does not exist or has no context!", pid);
return;
}

if (cur_frame != NULL)
{
memcpy(cur_frame, &processes[pid]->context, sizeof(int_frame_t));
}

cur_frame = processes[pid]->context;
memcpy(&processes[pid]->context, cur_frame, sizeof(int_frame_t));
}

void spawn_process(uint16_t pid, void *entry)
{
(void)pid;
(void)entry;
if (pid >= MAX_PROCESSES)
{
dprintf("[\e[0;31mProcesses\e[0m] PID \"%d\" exceeds maximum allowed value!", pid);
return;
}

if (processes[pid] != NULL)
{
dprintf("[\e[0;31mProcesses\e[0m] PID \"%d\" is currently taken!", pid);
return;
}

struct Process *temp = (struct Process *)malloc(sizeof(struct Process));
if (temp == NULL)
{
dprintf("[\e[0;31mProcesses\e[0m] Failed to allocate memory for process!");
return;
}

temp->context = (int_frame_t *)malloc(sizeof(int_frame_t));
if (temp->context == NULL)
{
dprintf("[\e[0;31mProcesses\e[0m] Failed to allocate memory for process context!");
free(temp);
return;
}

temp->id = pid;
temp->context->rip = (uint64_t)entry;
temp->context->rsp = (uint64_t)malloc(1);

if (temp->context->rsp == 0)
{
dprintf("[\e[0;31mProcesses\e[0m] Failed to allocate stack memory for process!");
free(temp->context);
free(temp);
return;
}

processes[pid] = temp;
dprintf("[\e[0;32mProcesses\e[0m] Spawned process with PID \"%d\"!\n", pid);
switch_context(pid);
}

void kill_process(uint16_t pid)
{
(void)pid;
if (pid >= MAX_PROCESSES)
{
dprintf("[\e[0;31mProcesses\e[0m] PID \"%d\" exceeds maximum allowed value!", pid);
return;
}

if (processes[pid] == NULL)
{
dprintf("[\e[0;31mProcesses\e[0m] No process found with PID \"%d\"", pid);
return;
}

free(processes[pid]);
processes[pid] = NULL;
}
2 changes: 1 addition & 1 deletion kernel/system/processes/processes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Process
int_frame_t *context;
};

extern struct Process processes[MAX_PROCESSES];
extern struct Process *processes[MAX_PROCESSES];

void switch_context(uint16_t pid);

Expand Down

0 comments on commit 71da05d

Please sign in to comment.