Skip to content

Commit 84d5faf

Browse files
committed
added panic function
1 parent 7c5687f commit 84d5faf

File tree

5 files changed

+117
-9
lines changed

5 files changed

+117
-9
lines changed

kernel/console.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2014 Kashyap
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
use super::uart::uart_put_str;
24+
25+
pub fn panic(text: &str) {
26+
uart_put_str(text);
27+
loop {};
28+
}

kernel/kalloc.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
use super::spinlock::{Spinlock, DUMMY_LOCK, init_lock};
2424
use super::mmu::{Address, PG_SIZE, pg_roundup};
25+
use super::memlayout::{v2p,PHYSTOP};
2526
use super::uart::uart_put_str;
27+
use super::console::panic;
2628

2729
struct KmemT {
2830
lock: Spinlock,
@@ -65,12 +67,20 @@ fn free_range(vstart: Address, vend: Address) {
6567
}
6668

6769
fn kfree(v : Address) {
70+
//struct run *r;
6871

69-
//struct run *r;
72+
if ((v % PG_SIZE) > 0) || (v2p(v) >= PHYSTOP) {
73+
panic("kfree");
74+
}
75+
76+
unsafe {
77+
if v < end {
78+
panic("kfree");
79+
}
80+
}
81+
82+
7083

71-
// if(v % PG_SIZE || v < end || v2p(v) >= PHYSTOP)
72-
// panic("kfree");
73-
//
7484
// // Fill with junk to catch dangling refs.
7585
// memset(v, 1, PGSIZE);
7686
//

kernel/kernel.rs

+63
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mod spinlock;
3939
mod kalloc;
4040
mod mmu;
4141
mod memlayout;
42+
mod console;
4243

4344

4445
fn main (end : u64) {
@@ -59,6 +60,68 @@ pub extern "C" fn cmain(end : u64) {
5960
//return 255;
6061
}
6162

63+
64+
65+
// Dummy functions to take care of missing libc function
66+
#[no_mangle]
67+
pub extern "C" fn trunc() {}
68+
#[no_mangle]
69+
pub extern "C" fn truncf() {}
70+
#[no_mangle]
71+
pub extern "C" fn floor() {}
72+
#[no_mangle]
73+
pub extern "C" fn floorf() {}
74+
#[no_mangle]
75+
pub extern "C" fn pow() {}
76+
#[no_mangle]
77+
pub extern "C" fn powf() {}
78+
#[no_mangle]
79+
pub extern "C" fn fmod() {}
80+
#[no_mangle]
81+
pub extern "C" fn fmodf() {}
82+
#[no_mangle]
83+
pub extern "C" fn log10() {}
84+
#[no_mangle]
85+
pub extern "C" fn log10f() {}
86+
#[no_mangle]
87+
pub extern "C" fn memcpy() {}
88+
#[no_mangle]
89+
pub extern "C" fn memcmp() {}
90+
#[no_mangle]
91+
pub extern "C" fn log() {}
92+
#[no_mangle]
93+
pub extern "C" fn logf() {}
94+
#[no_mangle]
95+
pub extern "C" fn log2() {}
96+
#[no_mangle]
97+
pub extern "C" fn log2f() {}
98+
#[no_mangle]
99+
pub extern "C" fn round() {}
100+
#[no_mangle]
101+
pub extern "C" fn roundf() {}
102+
#[no_mangle]
103+
pub extern "C" fn exp() {}
104+
#[no_mangle]
105+
pub extern "C" fn expf() {}
106+
#[no_mangle]
107+
pub extern "C" fn exp2() {}
108+
#[no_mangle]
109+
pub extern "C" fn exp2f() {}
110+
#[no_mangle]
111+
pub extern "C" fn ceil() {}
112+
#[no_mangle]
113+
pub extern "C" fn ceilf() {}
114+
#[no_mangle]
115+
pub extern "C" fn fma() {}
116+
#[no_mangle]
117+
pub extern "C" fn fmaf() {}
118+
#[no_mangle]
119+
pub extern "C" fn __powisf2() {}
120+
#[no_mangle]
121+
pub extern "C" fn __powidf2() {}
122+
123+
124+
62125
#[lang = "stack_exhausted"] extern fn stack_exhausted() { loop {} }
63126
#[lang = "eh_personality"] extern fn eh_personality() {loop {} }
64127
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }

kernel/memlayout.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222

2323
use super::mmu::Address;
2424

25-
pub const KERBASE : Address = 0xFFFFFFFF80000000;
25+
pub const KERNBASE : Address = 0xFFFFFFFF80000000;
2626
pub const PHYSTOP : Address = 0xE000000;
2727

2828
//TODO - in C this is a macro - need to figure out the right thing in RUST
2929
pub fn P2V(address : Address) -> Address {
30-
address + KERBASE
30+
address + KERNBASE
31+
}
32+
33+
pub fn v2p(address : Address) -> Address {
34+
address - KERNBASE
3135
}

staging/Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ ISO := os.iso
66

77
all:
88
rm -rf temp
9-
mkdir temp && cd temp && $(AR) x $(SOURCE_ROOT)/kernel/libkernel.a
10-
$(LD) -m elf_x86_64 -nodefaultlibs -T $(SOURCE_ROOT)/boot/x86_64/kernel64.ld -o kernel.sys $(SOURCE_ROOT)/boot/x86_64/entry64.o $(SOURCE_ROOT)/boot/x86_64/main.o temp/kernel.o -b binary $(SOURCE_ROOT)/boot/x86_64/initcode $(SOURCE_ROOT)/boot/x86_64/entryother
9+
mkdir temp
10+
cd temp && $(AR) x $(SOURCE_ROOT)/kernel/libkernel.a
11+
cd temp && $(AR) x $(SOURCE_ROOT)/kernel/libcompiler-rt.a
12+
cd temp && $(AR) x $(SOURCE_ROOT)/kernel/libmorestack.a
13+
cd temp && $(AR) x $(SOURCE_ROOT)/kernel/libcore.rlib
14+
$(LD) -m elf_x86_64 -nodefaultlibs -T $(SOURCE_ROOT)/boot/x86_64/kernel64.ld -o kernel.sys $(SOURCE_ROOT)/boot/x86_64/entry64.o $(SOURCE_ROOT)/boot/x86_64/main.o temp/kernel.o temp/core-*.o temp/morestack*.o -b binary $(SOURCE_ROOT)/boot/x86_64/initcode $(SOURCE_ROOT)/boot/x86_64/entryother
1115
#$(LD) -nodefaultlibs -z max-page-size=0x1000 -Tlinker.ld -o kernel.sys --start-group $(OBJECTS) --end-group
1216

1317

1418
iso:
1519
cp kernel.sys iso/boot
1620
grub-mkrescue -o $(ISO) iso
17-
1821

1922
clean:
2023
@rm -f $(ISO) iso/boot/kernel.sys kernel.sys

0 commit comments

Comments
 (0)