Skip to content

Commit 46ea283

Browse files
committed
v0.7.2: hello world, again
1 parent ae743a7 commit 46ea283

20 files changed

Lines changed: 175 additions & 71 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ifeq (${RUN_MODE}, nographic)
1818
QEMU_ARGS = -nographic
1919
endif
2020

21-
.PHONY: build run debug clean launch \
21+
.PHONY: build run debug clean launch intdbg \
2222
target/x86_64-unknown-uefi/$(MODE)/ggos_boot.efi \
2323
target/x86_64-unknown-none/$(MODE)/ggos_kernel \
2424
target/x86_64-unknown-ggos/$(MODE)
@@ -32,6 +32,13 @@ launch:
3232
$(QEMU_ARGS) \
3333
-drive format=raw,file=fat:rw:${ESP}
3434

35+
intdbg:
36+
@qemu-system-x86_64 \
37+
-bios ${OVMF} \
38+
-net none \
39+
$(QEMU_ARGS) \
40+
-drive format=raw,file=fat:rw:${ESP} -no-reboot -d int,cpu_reset
41+
3542
debug: build
3643
@qemu-system-x86_64 \
3744
-bios ${OVMF} \

pkg/app/hello/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ fn main() {
99
println!("Hello, world!!!");
1010
let time = lib::sys_time();
1111
println!("Now at: {}", time);
12-
lib::sys_exit(0);
12+
println!("Exiting...");
13+
lib::sys_exit(233);
1314
}
1415

1516
entry!(main);

pkg/app/sh/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ extern crate lib;
1212

1313
fn main() {
1414

15-
sys_list_dir("/");
16-
1715
let mut root_dir = String::from("/APP/");
1816

1917
loop {
@@ -28,6 +26,9 @@ fn main() {
2826
// ggos::filesystem::cat(root_dir.as_str(), line[1]);
2927
}
3028
"cd" => {
29+
if line[1].starts_with("/") {
30+
root_dir = String::from(line[1]);
31+
}
3132
match line[1] {
3233
".." => {
3334
if root_dir.as_str() == "/" {
@@ -37,6 +38,7 @@ fn main() {
3738
let pos = root_dir.rfind('/').unwrap();
3839
root_dir = root_dir[..pos + 1].to_string();
3940
},
41+
"." => break,
4042
_ => {
4143
root_dir.push_str(line[1]);
4244
root_dir.push('/');
@@ -46,15 +48,22 @@ fn main() {
4648
}
4749
"exec" => {
4850
let path = root_dir.clone() + line[1];
49-
println!("ready to exec {}...", path);
51+
let start = sys_time();
52+
5053
let pid = sys_spawn(path.as_str());
5154
if pid == 0 {
52-
println!("failed to spawn process: {}#{}", line[1], pid);
55+
println!("[!] failed to spawn process: {}#{}", line[1], pid);
56+
continue;
5357
} else {
54-
println!("spawned process: {}#{}", line[1], pid);
58+
println!("[+] spawned process: {}#{}", line[1], pid);
5559
}
60+
61+
let ret = sys_wait_pid(pid);
62+
let time = sys_time() - start ;
63+
64+
println!("[+] process exited with code {} @ {}s", ret, time.num_seconds());
5665
}
57-
_ => println!("[=] {}", input),
66+
_ => println!("[=] you said \"{}\"", input),
5867
}
5968
}
6069

pkg/elf/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn map_physical_memory(
1616
page_table: &mut impl Mapper<Size2MiB>,
1717
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
1818
) {
19-
debug!("Mapping physical memory...");
19+
trace!("Mapping physical memory...");
2020
let start_frame = PhysFrame::containing_address(PhysAddr::new(0));
2121
let end_frame = PhysFrame::containing_address(PhysAddr::new(max_addr));
2222

@@ -40,7 +40,7 @@ pub fn map_elf(
4040
page_table: &mut impl Mapper<Size4KiB>,
4141
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
4242
) -> Result<(), MapToError<Size4KiB>> {
43-
debug!("Mapping ELF file...{:?}", elf.input.as_ptr());
43+
trace!("Mapping ELF file...{:?}", elf.input.as_ptr());
4444
let start = PhysAddr::new(elf.input.as_ptr() as u64);
4545
for segment in elf.program_iter() {
4646
map_segment(&segment, start, page_table, frame_allocator)?;
@@ -50,7 +50,7 @@ pub fn map_elf(
5050

5151
/// Unmap ELF file
5252
pub fn unmap_elf(elf: &ElfFile, page_table: &mut impl Mapper<Size4KiB>) -> Result<(), UnmapError> {
53-
debug!("Unmapping ELF file...");
53+
trace!("Unmapping ELF file...");
5454
let kernel_start = PhysAddr::new(elf.input.as_ptr() as u64);
5555
for segment in elf.program_iter() {
5656
unmap_segment(&segment, kernel_start, page_table)?;
@@ -65,7 +65,7 @@ pub fn map_stack(
6565
page_table: &mut impl Mapper<Size4KiB>,
6666
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
6767
) -> Result<(), MapToError<Size4KiB>> {
68-
debug!("mapping stack at {:#x}", addr);
68+
trace!("mapping stack at {:#x}", addr);
6969
// create a stack
7070
let stack_start = Page::containing_address(VirtAddr::new(addr));
7171
let stack_end = stack_start + pages;
@@ -96,7 +96,7 @@ fn map_segment(
9696
return Ok(());
9797
}
9898

99-
debug!("Mapping segment: {:#x?}", segment);
99+
trace!("Mapping segment: {:#x?}", segment);
100100
let mem_size = segment.mem_size();
101101
let file_size = segment.file_size();
102102
let file_offset = segment.offset() & !0xfff;
@@ -201,7 +201,7 @@ fn unmap_segment(
201201
if segment.get_type().unwrap() != program::Type::Load {
202202
return Ok(());
203203
}
204-
debug!("Unmapping segment: {:#x?}", segment);
204+
trace!("Unmapping segment: {:#x?}", segment);
205205
let mem_size = segment.mem_size();
206206
let file_size = segment.file_size();
207207
let file_offset = segment.offset() & !0xfff;

pkg/fs/src/device/disk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ where
181181
where
182182
F: FnMut(&DirEntry),
183183
{
184-
debug!("Iterating directory: {:?}", dir);
184+
trace!("Iterating directory: {:?}", dir);
185185
let mut current_cluster = Some(dir.cluster);
186186
let mut dir_sector_num = self.cluster_to_sector(&dir.cluster);
187187
let dir_size = match dir.cluster {
@@ -201,7 +201,7 @@ where
201201
if dir_entry.is_eod() {
202202
return Ok(());
203203
} else if dir_entry.is_valid() && !dir_entry.is_long_name() {
204-
debug!("found file {}", dir_entry.filename());
204+
trace!("found file {}", dir_entry.filename());
205205
func(&dir_entry);
206206
}
207207
}

pkg/kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ggos_kernel"
3-
version = "0.7.0"
3+
version = "0.7.2"
44
edition = "2021"
55
authors = ["GZTime <Time.GZ@outlook.com>"]
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

pkg/kernel/src/interrupt/handlers.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub unsafe fn reg_idt(idt: &mut InterruptDescriptorTable) {
3232

3333
idt[(consts::Interrupts::IRQ0 as u8 + consts::IRQ::Timer as u8) as usize]
3434
.set_handler_fn(clock_handler)
35-
.set_stack_index(crate::gdt::CONTEXT_SWITCH);
35+
.set_stack_index(crate::gdt::CONTEXT_SWITCH_IST_INDEX);
3636

3737
idt[consts::Interrupts::Syscall as usize]
3838
.set_handler_fn(syscall_handler)
39-
.set_stack_index(crate::gdt::CONTEXT_SWITCH)
39+
.set_stack_index(crate::gdt::SYSCALL_IST_INDEX)
4040
.set_privilege_level(x86_64::PrivilegeLevel::Ring3);
4141
}
4242

@@ -158,7 +158,9 @@ pub extern "C" fn clock(mut regs: Registers, mut sf: InterruptStackFrame) {
158158
as_handler!(clock);
159159

160160
pub extern "C" fn syscall(mut regs: Registers, mut sf: InterruptStackFrame) {
161-
super::syscall::dispatcher(&mut regs, &mut sf);
161+
x86_64::instructions::interrupts::without_interrupts(|| {
162+
super::syscall::dispatcher(&mut regs, &mut sf);
163+
});
162164
}
163165

164166
as_handler!(syscall);

pkg/kernel/src/interrupt/syscall/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum Syscall {
2121
Allocate = 10,
2222
Deallocate = 11,
2323
Draw = 12,
24+
WaitPid = 13,
2425
#[num_enum(default)]
2526
None = 255,
2627
}
@@ -42,19 +43,20 @@ pub fn dispatcher(regs: &mut Registers, sf: &mut InterruptStackFrame) {
4243
);
4344

4445
match args.syscall {
45-
Syscall::SpawnProcess => regs.set_rax(spawn_process(&args)),
46-
Syscall::ExitProcess => exit_process(regs, sf),
47-
Syscall::Read => regs.set_rax(sys_read(&args)),
48-
Syscall::Write => regs.set_rax(sys_write(&args)),
49-
Syscall::Open => {}
50-
Syscall::Close => {}
51-
Syscall::Stat => list_process(),
52-
Syscall::Time => regs.set_rax(sys_clock() as usize),
53-
Syscall::DirectoryList => list_dir(&args),
54-
Syscall::Allocate => regs.set_rax(sys_allocate(&args)),
55-
Syscall::Deallocate => sys_deallocate(&args),
56-
Syscall::Draw => sys_draw(&args),
57-
Syscall::None => {}
46+
Syscall::SpawnProcess => regs.set_rax(spawn_process(&args)),
47+
Syscall::ExitProcess => exit_process(&args, regs, sf),
48+
Syscall::Read => regs.set_rax(sys_read(&args)),
49+
Syscall::Write => regs.set_rax(sys_write(&args)),
50+
Syscall::Open => {}
51+
Syscall::Close => {}
52+
Syscall::Stat => list_process(),
53+
Syscall::Time => regs.set_rax(sys_clock() as usize),
54+
Syscall::DirectoryList => list_dir(&args),
55+
Syscall::Allocate => regs.set_rax(sys_allocate(&args)),
56+
Syscall::Deallocate => sys_deallocate(&args),
57+
Syscall::Draw => sys_draw(&args),
58+
Syscall::WaitPid => regs.set_rax(sys_wait_pid(&args)),
59+
Syscall::None => {}
5860
}
5961
}
6062

pkg/kernel/src/interrupt/syscall/service.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::alloc::Layout;
22

3+
use crate::process::ProcessId;
34
use crate::utils::Registers;
45
use crate::{display::get_display_for_sure, utils::*};
56
use embedded_graphics::prelude::*;
@@ -95,8 +96,8 @@ pub fn sys_write(args: &SyscallArgs) -> usize {
9596
}
9697
}
9798

98-
pub fn exit_process(regs: &mut Registers, sf: &mut InterruptStackFrame) {
99-
crate::process::process_exit(regs, sf);
99+
pub fn exit_process(args: &SyscallArgs, regs: &mut Registers, sf: &mut InterruptStackFrame) {
100+
crate::process::process_exit(args.arg0 as isize, regs, sf);
100101
}
101102

102103
pub fn list_process() {
@@ -116,3 +117,9 @@ pub fn list_dir(args: &SyscallArgs) {
116117
pub fn get_handle(fd: u8) -> Option<Resource> {
117118
crate::process::handle(fd)
118119
}
120+
121+
pub fn sys_wait_pid(args: &SyscallArgs) -> usize {
122+
let pid = ProcessId(args.arg0 as u16);
123+
let ret = crate::process::wait_pid(pid);
124+
ret as usize
125+
}

0 commit comments

Comments
 (0)