Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] System Calls #75

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us fix problems and bugs

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Platform**
Whichever platform was used to test the bug. E.g QEMU, Virtualbox, real Lenovo laptop.

**Additional context**
Add any other context about the problem here.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/Enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Enhancement
about: Suggest an enhancement or improvement to an already existing feature

---

**Description of enhancement**
Description of the enhancement. Include which feature is being enhanced, too.

**Why?**
How does this enhancement benefit the project? What is its usecase?
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/Feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Feature request
about: Suggest an idea for this project

---

**What feature would you like?**
What feature would you like to be implemented? Any other details go here too.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Why?**
What does this feature provide? What usecase does it fulfill?
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ iso: $(grub_iso)

# Run with qemu
run: $(grub_iso)
@qemu-system-x86_64 -cdrom $(grub_iso) $(qemu_flags) -m 128M
@qemu-system-x86_64 -cdrom $(grub_iso) $(qemu_flags) -m 128M #-d int

# Clean build dir
clean:
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,30 @@ You can also get builds from [Flower's CI/CD](https://ci.gegy1000.net/job/Flower

## Contributing

If you wish to PR something to Flower, thanks so much! Just note to please **pull request into development, not master**.
If you wish to PR something to Flower, thanks so much! Just note to please **pull request into development, not master**
if you are making a change to the codebase.

Generally, the workflow for submitting a pull request goes like this:

1. Open an issue that your PR aims to solve and request to be assigned. This is just so we don't have multiple people working on
the same thing on different branches/forks.
2. Fork flower
3. Create a new branch from `development` (if you're editing code and not e.g the README) which briefly describes the thing you
are doing, e.g `acpi`.
4. Commit your things
5. Open a pull request. Select base as `development` (again, if you're editing code).
6. Wait for review. Sorry if the reviews are a bit nitpicky -- @gegy1000 and I (@Restioson) usually write reviews like that. It
does help to keep code quality good though.
7. Debate review comments/implement requested changes.
8. Repeat until everyone is happy with the changes.
9. Your PR should be merged Soon™!

## Code Style

Generally, we try to follow [the rust style guidline](https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md).
To keep the code consistent, we ask if all contributors could also adhere to these guidelines. Unfortunately, we haven't run
Clippy or Rustfmt on flower [just yet](https://github.com/Restioson/flower/issues/13), but this is slated to be done just before
0.2.0. Thus, please refrain from formatting things unrelated to the PR you are working on. This is to avoid merge conflicts.

## Thanks

Expand Down
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "flower_kernel"
version = "0.1.0"
authors = ["Restioson <[email protected]>", "Gegy1000 <[email protected]"]
authors = ["Restioson <[email protected]>", "Gegy1000 <[email protected]>"]

[lib]
crate-type = ["staticlib"]
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/asm/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ gdt64:

section .text
bits 64
extern setup_syscall
long_mode_start:

; Set all data segment registers to 0
Expand All @@ -323,6 +324,8 @@ long_mode_start:
; Pass guard page address to kmain through rsi
mov rsi, guard_page_begin

call setup_syscall

call kmain

hlt
30 changes: 30 additions & 0 deletions kernel/src/asm/syscall.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
global setup_syscall

extern syscall_callback

bits 64

section .text
setup_syscall:
mov rcx, 0xc0000080
rdmsr
or al, 1
wrmsr

mov rcx, 0xc0000081
mov rdx, 0x00100008
mov rax, 0x00000000
wrmsr
mov rcx, 0xc0000082
mov rax, syscall_callback
mov rdx, rax
shr rdx, 32
and rax, 0xffffffff
wrmsr
mov rcx, 0xc0000084
mov rax, ~(0x202)
xor rdx, rdx
not rdx
wrmsr

ret
5 changes: 5 additions & 0 deletions kernel/src/interrupts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use x86_64::structures::idt::Idt;
mod legacy_pic;
mod exceptions;

mod syscalls;

lazy_static! {
static ref IDT: Idt = {
let mut idt = Idt::new();
Expand All @@ -26,6 +28,9 @@ lazy_static! {
idt.simd_floating_point.set_handler_fn(exceptions::simd_floating_point);
idt.virtualization.set_handler_fn(exceptions::virtualization);
idt.security_exception.set_handler_fn(exceptions::security_exception);

idt[0x80].set_handler_fn(syscalls::syscall_int);

idt
};
}
Expand Down
7 changes: 7 additions & 0 deletions kernel/src/interrupts/syscalls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use x86_64::structures::idt::ExceptionStackFrame;

use syscalls::syscall_handler;

pub extern "x86-interrupt" fn syscall_int(stack_frame: &mut ExceptionStackFrame) {
syscall_handler();
}
16 changes: 16 additions & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ mod log;
#[macro_use]
mod terminal;
mod io;
mod syscalls;
mod interrupts;
mod memory;
mod drivers;
mod acpi_impl;

use memory::heap::Heap;

pub use syscalls::syscall_callback;

#[cfg_attr(not(test), global_allocator)]
pub static HEAP: Heap = Heap::new();

Expand All @@ -82,6 +85,8 @@ pub extern fn kmain(multiboot_info_addr: usize, guard_page_addr: usize) -> ! {
Err(error) => error!("ps2c: {:?}", error),
}

test_syscalls();

keyboard_echo_loop(&mut controller);

halt()
Expand All @@ -105,6 +110,17 @@ fn say_hello() {
.expect("Color should be supported");
}

fn test_syscalls() {
// NOTE! This code that is commented out will crash the
// kernel, and is "supposed" to (at least i think)
// unsafe {
// asm!("mov rax, 0; syscall" :::: "intel"); // Call "ping" syscall
// }
unsafe {
asm!("mov rax, 0; syscall" :::: "intel"); // Call "ping" syscall
}
}

fn print_flower() -> Result<(), terminal::TerminalOutputError<()>> {
const FLOWER: &'static str = include_str!("resources/art/flower.txt");
const FLOWER_STEM: &'static str = include_str!("resources/art/flower_stem.txt");
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn print_memory_info(memory_map: &MemoryMapTag) {
}

// Calculate how many GiBs are available
let bytes_available: usize = memory_map.memory_areas()
let bytes_available: u64 = memory_map.memory_areas()
.map(|area| area.end_address() - area.start_address())
.sum();

Expand Down
19 changes: 19 additions & 0 deletions kernel/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mod test;

#[no_mangle]
pub extern fn syscall_callback() {
syscall_handler();
unsafe{asm!("sysret");}
}

pub fn syscall_handler() {
let mut id: usize;
unsafe{asm!("nop" : "={rax}"(id))}

match id {
0 => test::ping(),
_ => {},
};

let mut rcx: u64;
}
3 changes: 3 additions & 0 deletions kernel/src/syscalls/test/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn ping() {
info!("Pong!");
}