aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/fs/ata.c2
-rw-r--r--src/kernel/fs/elf.c94
-rw-r--r--src/kernel/fs/elf.h21
-rw-r--r--src/kernel/graphics/vesa.c14
-rw-r--r--src/kernel/kernel.c10
-rw-r--r--src/kernel/lib/memory.c2
-rw-r--r--src/kernel/lib/stdlib/itoa.c2
-rw-r--r--src/kernel/memory/alloc.c2
-rw-r--r--src/kernel/memory/alloc.h2
-rw-r--r--src/kernel/memory/paging.c2
-rw-r--r--src/kernel/memory/paging.h2
-rw-r--r--src/kernel/syscall/syscall.c2
-rw-r--r--src/kernel/system.c2
-rw-r--r--src/kernel/tasks/process.c206
-rw-r--r--src/kernel/tasks/process.h71
-rw-r--r--src/kernel/tasks/userspace.asm20
-rw-r--r--src/kernel/tasks/userspace.c65
-rw-r--r--src/kernel/tasks/userspace.h17
-rw-r--r--src/kernel/timer/timer.c6
-rw-r--r--src/kernel/timer/timer.h7
-rw-r--r--src/userspace/main.c2
21 files changed, 457 insertions, 94 deletions
diff --git a/src/kernel/fs/ata.c b/src/kernel/fs/ata.c
index 2a1ab6f..d5c758c 100644
--- a/src/kernel/fs/ata.c
+++ b/src/kernel/fs/ata.c
@@ -117,4 +117,4 @@ void read_abs_sectors(uint32_t lba, uint8_t sector_count, uint16_t buf[])
asm("rep insw" ::"c"(SECTOR_SIZE / 2), "d"(sel_base_port + DATA), "D"(buf + i));
i += SECTOR_SIZE / 2;
}
-}
+} \ No newline at end of file
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c
index fe024e3..aea191b 100644
--- a/src/kernel/fs/elf.c
+++ b/src/kernel/fs/elf.c
@@ -1,3 +1,5 @@
+#include <stdint.h>
+#include <stddef.h>
#include <kernel/system.h>
#include <kernel/fs/elf.h>
#include <kernel/lib/stdio.h>
@@ -6,8 +8,9 @@
#include <kernel/memory/paging.h>
#include <kernel/fs/ext2.h>
#include <kernel/gdt/gdt.h>
+#include <kernel/tasks/process.h>
-int is_elf(elf_header_t *header)
+int is_elf(struct elf_header *header)
{
if (header->ident[0] == ELF_MAG && header->ident[1] == 'E' && header->ident[2] == 'L' &&
header->ident[3] == 'F' && header->ident[4] == ELF_32 &&
@@ -18,75 +21,52 @@ int is_elf(elf_header_t *header)
return 0;
}
-void elf_load(char *path)
+struct process *elf_load(char *path)
{
uint8_t *file = read_file(path);
if (!file) {
warn("File or directory not found: %s", file);
- return;
+ return NULL;
}
- elf_header_t *header = (elf_header_t *)file;
- elf_program_header_t *program_header = (void *)header + header->phoff;
+ struct elf_header *header = (struct elf_header *)file;
+ struct elf_program_header *program_header = (void *)header + header->phoff;
if (!is_elf(header)) {
- warn("File not valid: %s", path);
- return;
+ panic("File not valid");
} else {
debug("File is valid: %s", path);
}
- uint32_t eip = 0;
- uint32_t seg_begin, seg_end;
- for (int i = 0; i < header->phnum; i++) {
- if (program_header->type == 1) {
- seg_begin = program_header->vaddr;
- seg_end = seg_begin + program_header->memsz;
+ struct process *proc = process_make_new();
+ proc->name = "TEST";
+ proc->registers.eip = header->entry;
+ paging_switch_directory(proc->cr3);
+ uint32_t stk = (uint32_t)kmalloc_a(PAGE_S);
+ proc->registers.useresp = 0x40000000 - (PAGE_S / 2);
+ proc->registers.ebp = proc->registers.useresp;
+ proc->registers.esp = proc->registers.useresp;
+ paging_map_user(proc->cr3, stk, 0x40000000 - PAGE_S);
- /* for (uint32_t z = 0; z < seg_end - seg_begin; z += 4096) */
- /* paging_map((uint32_t)seg_begin + z, (uint32_t)seg_begin + z, */
- /* PT_PRESENT | PT_RW | PT_USED | PT_ALL_PRIV); */
-
- memcpy((void *)seg_begin, file + program_header->offset,
+ for (int i = 0; i < header->phnum; i++, program_header++) {
+ switch (program_header->type) {
+ case 0:
+ break;
+ case 1:
+ i += 0;
+ debug("Allocating space for ELF binary section...");
+ uint32_t loc = (uint32_t)kmalloc_a(PAGE_S);
+ paging_map_user(proc->cr3, loc, program_header->vaddr);
+ memcpy((void *)program_header->vaddr,
+ ((void *)((uint32_t)file) + program_header->offset),
program_header->filesz);
- memset((void *)(seg_begin + program_header->filesz), 0,
- program_header->memsz - program_header->filesz);
-
- // Code segment
- if (program_header->flags == PF_X + PF_R + PF_W ||
- program_header->flags == PF_X + PF_R) {
- debug("Found code segment");
- eip = header->entry + seg_begin;
- }
+ if (program_header->filesz > PAGE_S)
+ panic("ELF binary section too large");
+ break;
+ default:
+ warn("Unknown header type");
}
- program_header++;
- };
-
- // Just some testing, will be moved later
- uint32_t sp;
- asm("mov %%esp, %0" : "=rm"(sp));
- set_kernel_stack(sp);
-
- // paging_switch_directory(1);
- /* uint32_t esp = paging_alloc_pages(0x1000); */
- /* asm("mov %0, %%esp" ::"r"(esp + 0x1000)); */
+ }
- log("Jumping to usermode!");
- asm volatile("\
- cli; \
- mov $0x23, %%ax; \
- mov %%ax, %%ds; \
- mov %%ax, %%es; \
- mov %%ax, %%fs; \
- mov %%ax, %%gs; \
- mov %%esp, %%eax; \
- pushl $0x23; \
- pushl %%esp; \
- pushf; \
- push $0x1B; \
- push %0; \
- iret; \
- "
- :
- : "r"(eip));
-}
+ return proc;
+} \ No newline at end of file
diff --git a/src/kernel/fs/elf.h b/src/kernel/fs/elf.h
index fa6dbb0..8c7d38a 100644
--- a/src/kernel/fs/elf.h
+++ b/src/kernel/fs/elf.h
@@ -2,6 +2,7 @@
#define MELVIX_ELF_H
#include <stdint.h>
+#include <kernel/tasks/process.h>
#define ELF_MAG 0x7F // 0
#define ELF_32 (1) // 4: 32-bit Architecture
@@ -27,11 +28,11 @@
#define PF_W 0x2
#define PF_R 0x4
-typedef struct {
+struct elf_priv_data {
uint32_t sig;
-} elf_priv_data;
+};
-typedef struct {
+struct elf_header {
uint8_t ident[16];
uint16_t type;
uint16_t machine;
@@ -46,9 +47,9 @@ typedef struct {
uint16_t shentsize;
uint16_t shnum;
uint16_t shstrndx;
-} elf_header_t;
+};
-typedef struct {
+struct elf_section_header {
uint32_t name;
uint32_t type;
uint32_t flags;
@@ -59,9 +60,9 @@ typedef struct {
uint32_t info;
uint32_t addralign;
uint32_t entsize;
-} elf_section_header_t;
+};
-typedef struct {
+struct elf_program_header {
uint32_t type;
uint32_t offset;
uint32_t vaddr;
@@ -70,9 +71,9 @@ typedef struct {
uint32_t memsz;
uint32_t flags;
uint32_t align;
-} elf_program_header_t;
+};
-int is_elf(elf_header_t *header);
-void elf_load(char *path);
+int is_elf(struct elf_header *header);
+struct process *elf_load(char *path);
#endif \ No newline at end of file
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index f116146..5284f7e 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -183,12 +183,12 @@ void set_optimal_resolution()
vbe_set_mode(highest);
uint32_t fb_size = vbe_width * vbe_height * vbe_bpl;
- cursor_buffer = kmalloc(fb_size);
- /* for (uint32_t z = 0; z < fb_size; z += 4096) { */
- /* paging_map((uint32_t)fb + z, (uint32_t)fb + z, PT_PRESENT | PT_RW | PT_USED); */
- /* paging_map((uint32_t)cursor_buffer + z, (uint32_t)cursor_buffer + z, */
- /* PT_PRESENT | PT_RW | PT_USED); */
- /* } */
+ /* cursor_buffer = kmalloc(fb_size); */
+ for (uint32_t z = 0; z < fb_size; z += 4096) {
+ paging_map(paging_root_directory, (uint32_t)fb + z, (uint32_t)fb + z);
+ /* paging_map(paging_root_directory, (uint32_t)cursor_buffer + z, */
+ /* (uint32_t)cursor_buffer + z); */
+ }
if (vbe_height > 1440)
vesa_set_font(32);
@@ -368,4 +368,4 @@ void vesa_set_color(uint32_t color)
{
vesa_convert_color(terminal_color, color);
vesa_convert_color(terminal_background, default_background_color);
-}
+} \ No newline at end of file
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 756721f..83e0b35 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -62,14 +62,12 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address)
load_binaries();
set_optimal_resolution();
- printf("Awesome!\n");
syscalls_install();
- elf_load("/bin/user");
+ struct process *proc = elf_load("/bin/user");
+ process_init(proc);
-#ifdef INSTALL_MELVIX
- panic("Installation isn't supported right now!");
-#endif
+ halt_loop();
// asm ("div %0" :: "r"(0)); // Exception testing x/0
-}
+} \ No newline at end of file
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index 5347add..6aed060 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -116,4 +116,4 @@ int memory_init(uint32_t multiboot_address)
}
}
return ret;
-}
+} \ No newline at end of file
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
index e6300d9..5bb3359 100644
--- a/src/kernel/lib/stdlib/itoa.c
+++ b/src/kernel/lib/stdlib/itoa.c
@@ -41,4 +41,4 @@ char *itoa(int n)
strinv(ret);
return ret;
-}
+} \ No newline at end of file
diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c
index fbf97d8..fd00cc7 100644
--- a/src/kernel/memory/alloc.c
+++ b/src/kernel/memory/alloc.c
@@ -186,4 +186,4 @@ void *umalloc(size_t size)
void ufree(void *address)
{
free_internal(uheap, address);
-}
+} \ No newline at end of file
diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h
index 16d61f5..7ce5739 100644
--- a/src/kernel/memory/alloc.h
+++ b/src/kernel/memory/alloc.h
@@ -42,4 +42,4 @@ void init_heap(struct heap_header *heap, size_t size);
#define HEAP_MINIMUM 1
#define HEAP_FIND_SIZE (HEAP_TOTAL + HEAP_MINIMUM)
-#endif
+#endif \ No newline at end of file
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index 910b569..4192ba3 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -140,4 +140,4 @@ struct page_directory *paging_copy_user_directory(struct page_directory *dir)
}
return copy;
-}
+} \ No newline at end of file
diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h
index c02cd3a..b4881a9 100644
--- a/src/kernel/memory/paging.h
+++ b/src/kernel/memory/paging.h
@@ -46,4 +46,4 @@ struct page_directory *paging_copy_user_directory(struct page_directory *dir);
#define EMPTY_TAB ((struct page_table *)0x00000002)
#define PAGE_S 0x400000
-#endif
+#endif \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index f883f2e..1454198 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -35,4 +35,4 @@ void syscall_handler(struct regs *r)
void syscalls_install()
{
isr_install_handler(0x80, syscall_handler);
-}
+} \ No newline at end of file
diff --git a/src/kernel/system.c b/src/kernel/system.c
index 18fbaf4..ba798a0 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -124,4 +124,4 @@ void v86(uint8_t code, regs16_t *regs)
/* paging_disable(); */
int32(code, regs);
/* paging_enable(); */
-}
+} \ No newline at end of file
diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c
new file mode 100644
index 0000000..5ac4010
--- /dev/null
+++ b/src/kernel/tasks/process.c
@@ -0,0 +1,206 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <kernel/tasks/process.h>
+#include <kernel/tasks/userspace.h>
+#include <kernel/interrupts/interrupts.h>
+#include <kernel/system.h>
+#include <kernel/lib/lib.h>
+#include <kernel/memory/paging.h>
+#include <kernel/memory/alloc.h>
+#include <kernel/timer/timer.h>
+
+uint32_t pid = 0;
+struct process *root;
+struct process *current_proc = NULL;
+
+struct regs hold_root;
+
+extern uint32_t stack_hold;
+
+void scheduler(struct regs *regs)
+{
+ memcpy(&current_proc->registers, regs, sizeof(struct regs));
+
+ debug("Task switch");
+
+ timer_handler(regs);
+
+ current_proc = current_proc->next;
+ if (current_proc == NULL) {
+ current_proc = root;
+ }
+
+ while (current_proc->state == PROC_ASLEEP) {
+ current_proc = current_proc->next;
+ if (current_proc == NULL)
+ current_proc = root;
+ }
+
+ memcpy(regs, &current_proc->registers, sizeof(struct regs));
+ paging_switch_directory(current_proc->cr3);
+}
+
+void process_init(struct process *proc)
+{
+ root = proc;
+ root->pid = pid++;
+ root->next = NULL;
+ root->thread = PROC_ROOT; // Unkillable
+ root->state = PROC_RUNNING;
+
+ current_proc = root;
+ irq_install_handler(0, scheduler);
+ userspace_enter(proc);
+}
+
+void process_kill(uint32_t pid)
+{
+ struct process *proc = process_from_pid(pid);
+
+ if (proc == PID_NOT_FOUND)
+ panic("Can't kill unknown PID");
+
+ // flush(proc->stdout);
+ // flush(proc->stderr);
+ proc->state = PROC_ASLEEP;
+
+ if (proc->parent != NULL) {
+ //warn("Child had parent");
+ //process_wake(proc->parent->pid);
+ }
+}
+
+uint32_t process_spawn(struct process *process)
+{
+ process->next = root->next;
+ root->next = process;
+ process->state = PROC_RUNNING;
+
+ process->parent = current_proc;
+
+ //process_suspend(current_proc->pid);
+
+ return process->pid;
+}
+
+int process_wait_gid(uint32_t gid, int *status)
+{
+ struct process *i = root;
+
+ while (i != NULL) {
+ if (i->gid == gid)
+ if (i->state == PROC_ASLEEP) {
+ *status = i->registers.ebx;
+ return i->pid;
+ }
+
+ i = i->next;
+ }
+
+ return WAIT_OKAY;
+}
+
+int process_wait_pid(uint32_t pid, int *status)
+{
+ struct process *i = current_proc->next;
+
+ while (i != NULL) {
+ if (i->pid == pid) {
+ if (i->state == PROC_ASLEEP) {
+ *status = i->registers.ebx;
+ return i->pid;
+ } else {
+ return WAIT_OKAY;
+ }
+ }
+ i = i->next;
+ }
+
+ return WAIT_ERROR;
+}
+
+void process_suspend(uint32_t pid)
+{
+ struct process *proc = process_from_pid(pid);
+
+ if (proc == PID_NOT_FOUND) {
+ warn("couldn't find PID for suspension");
+ return;
+ }
+
+ proc->state = PROC_ASLEEP;
+}
+
+void process_wake(uint32_t pid)
+{
+ struct process *proc = process_from_pid(pid);
+
+ if (proc == PID_NOT_FOUND)
+ return;
+
+ proc->state = PROC_RUNNING;
+}
+
+uint32_t process_child(struct process *child, uint32_t pid)
+{
+ process_suspend(pid);
+
+ struct process *parent = process_from_pid(pid);
+
+ if (parent == PID_NOT_FOUND) {
+ panic("Child process spawned without parent");
+ }
+
+ child->parent = parent;
+
+ return process_spawn(child);
+}
+
+uint32_t process_fork(uint32_t pid)
+{
+ warn("Fork is not implemented");
+
+ // With struct regs *regs
+ /*struct page_directory *dir = paging_copy_user_directory(current_proc->cr3);
+ struct process *proc = process_make_new();
+ proc->cr3 = dir;
+ memcpy(&proc->registers, regs, sizeof(struct regs));
+ proc->registers.eax = proc->pid;
+ proc->pid = current_proc->pid;
+
+ process_spawn(proc);*/
+ return pid++;
+}
+
+struct process *process_from_pid(uint32_t pid)
+{
+ struct process *proc = root;
+
+ while (proc != NULL) {
+ if (proc->pid == pid)
+ return proc;
+
+ proc = proc->next;
+ }
+
+ return PID_NOT_FOUND;
+}
+
+struct process *process_make_new()
+{
+ struct process *proc = (struct process *)kmalloc_a(sizeof(struct process));
+ proc->registers.cs = 0x1B;
+ proc->registers.ds = 0x23;
+ proc->registers.ss = 0x23;
+ proc->cr3 = paging_make_directory();
+
+ proc->brk = 0x50000000;
+
+ int i;
+ for (i = 0; i < 1024; i++)
+ proc->cr3->tables[i] = paging_root_directory->tables[i];
+
+ proc->pid = pid++;
+
+ return proc;
+} \ No newline at end of file
diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h
new file mode 100644
index 0000000..df0f51f
--- /dev/null
+++ b/src/kernel/tasks/process.h
@@ -0,0 +1,71 @@
+#ifndef MELVIX_PROCESS_H
+#define MELVIX_PROCESS_H
+
+#include <stdint.h>
+#include <kernel/memory/paging.h>
+#include <kernel/interrupts/interrupts.h>
+
+struct mmap {
+ uint32_t text;
+ uint32_t bss;
+ uint32_t data;
+ uint32_t stack;
+};
+
+struct process {
+ struct page_directory *cr3;
+ struct regs registers;
+
+ uint32_t pid;
+ uint32_t gid;
+ char *name;
+
+ int state;
+ int thread;
+
+ uint32_t stdint;
+ uint32_t stdout;
+ uint32_t stderr;
+
+ uint32_t brk;
+ uint32_t handlers[6];
+
+ struct process *parent;
+ struct process *next;
+};
+
+void process_kill(uint32_t pid);
+
+uint32_t process_spawn(struct process *process);
+
+void process_suspend(uint32_t pid);
+void process_wake(uint32_t pid);
+uint32_t process_child(struct process *process, uint32_t pid);
+uint32_t process_fork(uint32_t pid);
+
+int process_wait_gid(uint32_t gid, int *status);
+int process_wait_pid(uint32_t pid, int *status);
+
+struct process *process_from_pid(uint32_t pid);
+
+void process_init(struct process *proc);
+
+struct process *process_make_new();
+
+extern struct process *current_proc;
+
+extern uint32_t stack_hold;
+
+#define PID_NOT_FOUND ((struct process *)0xFFFFFFFF)
+
+#define PROC_RUNNING 0
+#define PROC_ASLEEP 1
+
+#define PROC_THREAD 0
+#define PROC_PROC 1
+#define PROC_ROOT 2
+
+#define WAIT_ERROR (-1)
+#define WAIT_OKAY 0
+
+#endif \ No newline at end of file
diff --git a/src/kernel/tasks/userspace.asm b/src/kernel/tasks/userspace.asm
new file mode 100644
index 0000000..4f79d4d
--- /dev/null
+++ b/src/kernel/tasks/userspace.asm
@@ -0,0 +1,20 @@
+global jump_userspace
+extern hl_cr3
+extern hl_esp
+extern hl_eip
+
+jump_userspace:
+ mov ax, 0x23
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+
+ mov eax, dword [hl_esp]
+ push 0x23
+ push eax
+ pushf
+ push 0x1B
+ push dword [hl_eip]
+
+ iret \ No newline at end of file
diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c
new file mode 100644
index 0000000..f8d0472
--- /dev/null
+++ b/src/kernel/tasks/userspace.c
@@ -0,0 +1,65 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <kernel/system.h>
+#include <kernel/tasks/userspace.h>
+#include <kernel/tasks/process.h>
+#include <kernel/memory/paging.h>
+#include <kernel/io/io.h>
+#include <kernel/interrupts/interrupts.h>
+#include <kernel/lib/lib.h>
+
+struct process *proc_bottom = NULL;
+
+uint32_t hl_cr3;
+uint32_t hl_eip;
+uint32_t hl_esp;
+
+uint32_t spawn_child(struct process *child)
+{
+ return (uint32_t)-1;
+}
+
+void userspace_enter(struct process *proc)
+{
+ proc_bottom = proc;
+ proc->next = NULL;
+ hl_eip = proc->registers.eip;
+ hl_esp = proc->registers.esp;
+ paging_switch_directory(proc->cr3);
+
+ current_proc = proc;
+
+ sti();
+ jump_userspace();
+}
+
+void single_yield(struct process *proc, struct regs *regs)
+{
+ memcpy(&proc_bottom->registers, regs, sizeof(struct regs));
+
+ if (proc == proc_bottom)
+ panic("Can't return from parent process");
+
+ proc->next = proc_bottom;
+ proc_bottom = proc;
+
+ memcpy(regs, &proc->registers, sizeof(struct regs));
+ paging_switch_directory(proc->cr3);
+}
+
+uint32_t single_exit(struct regs *regs)
+{
+ //close(current_proc->stdout);
+ //close(current_proc->stderr);
+
+ uint32_t hold = regs->ebx;
+ proc_bottom = proc_bottom->next;
+
+ if (proc_bottom == NULL)
+ panic("Return from process with no parent");
+
+ memcpy(regs, &proc_bottom->registers, sizeof(struct regs));
+ paging_switch_directory(proc_bottom->cr3);
+
+ return hold;
+} \ No newline at end of file
diff --git a/src/kernel/tasks/userspace.h b/src/kernel/tasks/userspace.h
new file mode 100644
index 0000000..90b64bf
--- /dev/null
+++ b/src/kernel/tasks/userspace.h
@@ -0,0 +1,17 @@
+#ifndef MELVIX_USERSPACE_H
+#define MELVIX_USERSPACE_H
+
+#include <stdint.h>
+#include <kernel/tasks/process.h>
+#include <kernel/interrupts/interrupts.h>
+
+uint32_t spawn_child(struct process *child);
+
+void userspace_enter(struct process *proc);
+
+void single_yield(struct process *proc, struct regs *regs);
+uint32_t single_exit(struct regs *regs);
+
+extern void jump_userspace();
+
+#endif \ No newline at end of file
diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c
index f1a296a..29017a5 100644
--- a/src/kernel/timer/timer.c
+++ b/src/kernel/timer/timer.c
@@ -1,3 +1,4 @@
+#include <stdint.h>
#include <kernel/interrupts/interrupts.h>
#include <kernel/io/io.h>
#include <kernel/system.h>
@@ -16,13 +17,12 @@ void timer_phase(int hz)
void timer_handler(struct regs *r)
{
timer_ticks++;
- // switch_task();
}
// "Delay" function with CPU sleep
void timer_wait(int ticks)
{
- unsigned int eticks;
+ uint32_t eticks;
eticks = timer_ticks + ticks;
while (timer_ticks < eticks) {
@@ -30,7 +30,7 @@ void timer_wait(int ticks)
}
}
-unsigned int get_time()
+uint32_t get_time()
{
return timer_ticks;
}
diff --git a/src/kernel/timer/timer.h b/src/kernel/timer/timer.h
index 389da6b..2315b62 100644
--- a/src/kernel/timer/timer.h
+++ b/src/kernel/timer/timer.h
@@ -1,6 +1,11 @@
#ifndef MELVIX_TIMER_H
#define MELVIX_TIMER_H
+#include <stdint.h>
+#include <kernel/interrupts/interrupts.h>
+
+void timer_handler(struct regs *r);
+
/**
* Install the timer and set the timer phase to 100
*/
@@ -16,6 +21,6 @@ void timer_wait(int ticks);
* Get the current timer ticks
* @return The current timer ticks (1000 ticks = 1 second)
*/
-unsigned int get_time();
+uint32_t get_time();
#endif \ No newline at end of file
diff --git a/src/userspace/main.c b/src/userspace/main.c
index 0e6dfa4..7a18f85 100644
--- a/src/userspace/main.c
+++ b/src/userspace/main.c
@@ -17,4 +17,4 @@ void main()
char test[] = "banane";
syscall_write(test);
syscall_halt();
-}
+} \ No newline at end of file