Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Implement tasks (but it's incomplete) #55

Merged
merged 29 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4d0c664
Add asm/processor.h
noriyotcp Jun 12, 2017
a984c2d
asm/stddef.h: Fix include guard
noriyotcp Jun 15, 2017
bc7f7c2
Add c_kernel/include/stddef.h
noriyotcp Jun 15, 2017
e69f6f7
Add c_kernel/include/tasks_types.h
noriyotcp Jun 15, 2017
5873503
Add c_kernel/include/tasks.h
noriyotcp Jun 15, 2017
69e2847
c_kernel/include: Move macros from stddef.h to config.h
noriyotcp Jun 15, 2017
cbf2bd4
c_kernel/include/config.h: Implement BUILTIN_EXPECT(exp, b) macro
noriyotcp Jun 20, 2017
3a5a4ea
Makefile: Add -O2 option to CFLAGS
noriyotcp Jun 20, 2017
166af59
c_kernel/include/tasks_types.h: Include asm/tasks_types.h
noriyotcp Jun 20, 2017
a157ff5
add c_kernel/include/errno.h
noriyotcp Jun 20, 2017
567cda1
Add c_kernel/include/stdlib.h
noriyotcp Jun 20, 2017
3c80c08
x86_64/c/isrs.c: Format the code
noriyotcp Jun 21, 2017
f96faeb
Add c_kernel/memory.c
noriyotcp Jun 21, 2017
27a1784
Fix source url
noriyotcp Jun 21, 2017
d70c15b
c_kernel/include/stdlib.h: Fix including from asm/stddef.h to stddef.h
noriyotcp Jun 21, 2017
12847a7
Enable to use create_default_frame
noriyotcp Jun 21, 2017
4484d68
Implement c_kernel/tasks.c
noriyotcp Jun 22, 2017
837d27e
main.cr: Comment out Division by zero
noriyotcp Jun 22, 2017
4da9b28
Implement LibU.multitasking_init
noriyotcp Jun 22, 2017
9c54c1c
x86_64/c/tasks.c: Fix rflags
noriyotcp Jun 29, 2017
54760f4
Add string.h which includes memset
noriyotcp Jun 29, 2017
22b2d12
long_mode_init: Call get_current_stack and finish_task_switch
noriyotcp Jun 29, 2017
c967ac4
Implement create_foo function for multitasking and fun for calling from
noriyotcp Jun 29, 2017
db46ccf
Implement C binding for multitasking...but it fails(OMG)
noriyotcp Jun 29, 2017
d646393
Add box.cr
noriyotcp Jun 29, 2017
9c3fffd
Add stdlib.cr for LibCR
noriyotcp Jun 29, 2017
cd612de
main.cr: Comment out on invoking LibU.create_foo
noriyotcp Jun 30, 2017
ff8bee9
Makefile: Add -monitor stdio to qemu
noriyotcp Jun 30, 2017
fd26c29
README: Bump up Crystal version to 0.23.0
noriyotcp Jun 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kernel := build/kernel-$(arch).bin
iso := build/utero-$(arch).iso
top_dir := $(shell pwd)
INCLUDE := -I$(top_dir)/src/c_kernel/include -I$(top_dir)/src/arch/x86_64/c/include
CFLAGS := -ffreestanding -nostdinc -Wno-implicit
CFLAGS := -O2 -ffreestanding -nostdinc -Wno-implicit

libcr := src/musl/lib/libcr.a
libu := build/arch/$(arch)/c/libu.a
Expand Down Expand Up @@ -61,7 +61,7 @@ cleanobjs:
@rm -rf target/

run: $(iso)
@qemu-system-$(arch) -cdrom $(iso)
@qemu-system-$(arch) -cdrom $(iso) -monitor stdio

iso: $(iso)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is the *work in progress*.

## Requirements

* Crystal 0.22.0
* Crystal 0.23.0
* llvm
* Please see [All required libraries](https://github.com/crystal-lang/crystal/wiki/All-required-libraries)
* nasm
Expand Down
108 changes: 108 additions & 0 deletions src/arch/x86_64/c/include/asm/processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) 2016-2017 Utero OS Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// The part of this file was taken from:
// https://github.com/RWTH-OS/eduOS/blob/master/arch/x86/include/asm/processor.h

#ifndef ASM_PROCESSOR_H
#define ASM_PROCESSOR_H

#include <asm/stddef.h>

// rdtsc (Read-time stamp counter)
// return the 64-bit time stamp value
inline static uint64_t
rdtsc(void)
{
uint64_t lo, hi;
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
return (hi << 32 | lo);
}

// wbinvd asm instruction(Write back and invalidate cache)
inline static void
flush_cache(void)
{
asm volatile("wbinvd" ::: "memory");
}

// invd asm instruction (Invalidate internal caches - without writing back)
inline static void
invalid_cache(void)
{
asm volatile("invd");
}

// NOTE: mb, rmb, wmb will be moved to arch/x86_64/c/processor.c
// and used via extern func_memory_barrier (mb|rmb|wmb)

// mb (Memory barrier)
// mfence asm instruction (Memory Fence - Serializes load and store operations)
inline static void
mb(void)
{
asm volatile("mfence" ::: "memory");
}

// rmb (Read memory barrier)
// lfence asm instruction (Load Fence - Serializes load operations)
inline static void
rmb(void)
{
asm volatile("lfence" ::: "memory");
}

// wmb (Write memory barrier)
// sfence asm instruction (Store Fence - Serializes store operations)
inline static void
wmb(void)
{
asm volatile("sfence" ::: "memory");
}

// search the most significant bit
// bsr (Bit Scan Reverse) asm instruction
static inline size_t
msb(size_t i)
{
size_t ret;

if (!i) {
return (sizeof(size_t) * 8);
}
asm volatile("bsr %1, %0" : "=r"(ret) : "r"(i) : "cc");

return ret;
}

// search the least significant bit
// bsf (Bit Scan Forward) asm instruction
static inline size_t
lsb(size_t i)
{
size_t ret;

if (!i) {
return (sizeof(size_t) * 8);
}
asm volatile("bsf %1, %0" : "=r"(ret) : "r"(i) : "cc");

return ret;
}

// A one-instruction-do-nothing
#define NOP1 asm volatile("nop")
// A two-instruction-do-nothing
#define NOP2 asm volatile("nop;nop")
// A four-instruction-do-nothing
#define NOP4 asm volatile("nop;nop;nop;nop")
// A eight-instruction-do-nothing
#define NOP8 asm volatile("nop;nop;nop;nop;nop;nop;nop;nop")

#endif /* end of include guard: ASM_PROCESSOR_H */
9 changes: 5 additions & 4 deletions src/arch/x86_64/c/include/asm/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// The part of this file was taken from:
// https://github.com/RWTH-OS/eduOS/blob/master/arch/x86/include/asm/stddef.h

#ifndef STDDEF_H
#define STDDEF_H
#ifndef ASM_STDDEF_H
#define ASM_STDDEF_H

// Unsigned 64 bit integer
typedef unsigned long long uint64_t;
Expand All @@ -34,7 +34,8 @@ typedef char int8_t;
typedef unsigned long long size_t;

// This defines what the stack looks like after the task context is saved.
struct state {
struct state
{
// R15 register
uint64_t r15;
// R14 register
Expand Down Expand Up @@ -80,4 +81,4 @@ struct state {
uint64_t ss;
};

#endif /* end of include guard: STDDEF_H */
#endif /* end of include guard: ASM_STDDEF_H */
31 changes: 31 additions & 0 deletions src/arch/x86_64/c/include/asm/tasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2016-2017 Utero OS Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// The part of this file was taken from:
// https://github.com/RWTH-OS/eduOS/blob/master/arch/x86/include/asm/tasks.h

#ifndef ASM_TASKS_H
#define ASM_TASKS_H

#include <stddef.h>

// Switch the current task
// stack: Pointer to the old stack pointer
void switch_context(size_t** stack);

// Setup a default frame for a new task
// task: Pointer to the task structure
// ep: The entry point for code execution
// arg: Arguments list pointer for the task's stack
// return
// - 0 on success
// - -EINVAL (-22) on failure
int create_default_frame(task_t* task, entry_point_t ep, void* arg);

#endif /* end of include guard: ASM_TASKS_H */
16 changes: 16 additions & 0 deletions src/arch/x86_64/c/include/asm/tasks_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// The part of this file was taken from:
// https://github.com/RWTH-OS/eduOS/blob/master/arch/x86/include/asm/tasks_types.h

#ifndef ASM_TASKS_TYPES_H
#define ASM_TASKS_TYPES_H

#include <asm/processor.h>
#include <stddef.h>

#endif /* end of include guard: ASM_TASKS_TYPES_H */
Loading