Selaa lähdekoodia

9.393u-init: now we remove all schk

rain 5 vuotta sitten
vanhempi
sitoutus
c57bccd600
22 muutettua tiedostoa jossa 80 lisäystä ja 448 poistoa
  1. 1 0
      LINES
  2. 3 0
      README.md
  3. 4 3
      include/kernel/init.h
  4. 0 86
      include/kernel/schk.h
  5. 1 1
      include/lib/bitmap.h
  6. 0 13
      init/main.c
  7. 1 6
      kernel/console.c
  8. 2 101
      kernel/int.c
  9. 2 21
      kernel/irq.c
  10. 0 13
      kernel/keyboard.c
  11. 24 43
      kernel/mm.c
  12. 4 29
      kernel/panic.c
  13. 0 11
      kernel/pci.c
  14. 1 1
      kernel/rlib/Makefile
  15. 4 12
      kernel/rlib/bitmap.c
  16. 0 9
      kernel/rlib/fifo.c
  17. 6 54
      kernel/sched.c
  18. 1 11
      kernel/sys.c
  19. 0 9
      kernel/tty.c
  20. 0 2
      kernel/vsprintf.c
  21. 26 18
      modules/ahci.c
  22. 0 5
      modules/ide.c

+ 1 - 0
LINES

@@ -46,4 +46,5 @@
 2021-8-24 9.742: 9742 lines, 65 files, rain
 2021-8-24 9.707: 9707 lines, 65 files, rain
 2021-8-24 9.765: 9765 lines, 65 files, rain
+2021-8-26 9.393: 9393 lines, 64 files, rain
 

+ 3 - 0
README.md

@@ -184,3 +184,6 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 10.024u-mods:  
 &nbsp;&nbsp;&nbsp;&nbsp;now `print` can use `com0` and `console` to put, not only one. 
 
+9.590u-init:  
+&nbsp;&nbsp;&nbsp;&nbsp;we now removed all schk. 
+

+ 4 - 3
include/kernel/init.h

@@ -40,11 +40,12 @@
 
 // #define DEBUG_LEVEL		DEV_DEBUG_LEVEL
 
-/* slowest: schk will display function info in this mode */
+/* slowest */
 // #define DEBUG_LEVEL		TEST_DEBUG_LEVEL
 
-/* how many we should put on the screen (functions name) */
-#define TRACE_SYSLOG_NR 	8
+/* how many we should put on the screen */
+/* 80 characters */
+#define TRACE_SYSLOG_MAX	80
 
 #include <kernel/console.h>
 

+ 0 - 86
include/kernel/schk.h

@@ -1,86 +0,0 @@
-/* Copyright (C) 2021 Rain */
-
-/* This file is part of XNIX. */
-
-/* 
-  XNIX is free software: you can redistribute it and/or modify 
-  it under the terms of the GNU General Public License as published by 
-  the Free Software Foundation, either version 3 of the License, or 
-  (at your option) and later version. 
-*/
-
-/*
-  XNIX is distributed in the hope that it will be useful, 
-  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-  GNU General Public License for more details. 
-*/
-
-/*
-  You should have received a copy of the GNU General Public License 
-   along with XNIX. If not, see <https://www.gnu.org/licenses/>.  
-*/
-
-
-
-
-#ifndef _SCHK_H
-#define _SCHK_H
-
-#include <kernel/init.h>
-
-#include <kernel/types.h>
-#include <kernel/errno.h>
-#include <kernel/panic.h>
-
-#include <arch/sys.h>
-
-
-void __stack_chk_fail(void);
-
-#if DEBUG_LEVEL == TEST_DEBUG_LEVEL
-
-#define schk_init()					\
-	__uint64_t old_sp = get_rsp();			\
-	syslog(__FUNCTION__);				\
-	syslog("\t");					\
-	if (old_sp < 0x3000) {				\
-		syslog("#1#PANIC: SP < 0x3000\n");	\
-		__stack_chk_fail();			\
-	}						\
-	if (old_sp < 0x4000) 				\
-		syslog("#2#WARNING: SP < 0x4000 now");	\
-	else if (old_sp < 0x5000)			\
-		syslog("#3#WARNING: SP < 0x5000 now");	\
-	else if (old_sp < 0x6000)			\
-		syslog("#4#WARNING: SP < 0x6000 now");	\
-
-#elif DEBUG_LEVEL == DEV_DEBUG_LEVEL
-
-#define schk_init() 	__uint64_t old_sp = get_rsp();
-
-#elif DEBUG_LEVEL == DEFAULT_DEBUG_LEVEL
-
-#define schk_init()
-
-#else
-
-#error "unknow debug level (in init.h)"
-
-#endif
-
-
-#if DEBUG_LEVEL == DEFAULT_DEBUG_LEVEL
-
-#define schk_leave()
-
-#else
-
-#define schk_leave()			\
-	if (old_sp != get_rsp())	\
-		__stack_chk_fail()
-
-#endif
-
-#endif
-

+ 1 - 1
include/lib/bitmap.h

@@ -29,6 +29,6 @@
 
 extern char *bitmap_init(unsigned int size);
 extern void bitmap_set(unsigned char *bitmap, unsigned int pos, unsigned char value);
-extern char bitmap_read(unsigned char *bitmap, unsigned int pos);
+extern __uint8_t bitmap_read(unsigned char *bitmap, unsigned int pos);
 
 #endif

+ 0 - 13
init/main.c

@@ -29,7 +29,6 @@
 
 #include <kernel/console.h>
 #include <kernel/vsprintf.h>
-#include <kernel/schk.h>
 
 #include <kernel/mm.h>
 #include <kernel/pci.h>
@@ -80,8 +79,6 @@ time_t mktime(struct time *);
  * */
 
 int init(void) {
-	schk_init();
-
 	console_init();
 	serial_init();
 
@@ -107,14 +104,10 @@ int init(void) {
 
 	time_init();
 
-	schk_leave();
-
 	return 0;
 }
 
 void time_init(void) {
-	schk_init();
-
 	/* get current time, and save it to `startup_time` */
 	struct time tm;
 
@@ -145,8 +138,6 @@ void time_init(void) {
 
 	printk(white, "current unix time-stamp: %d. \n", mktime(&tm));
 
-	schk_leave();
-
 	return;
 }
 
@@ -168,8 +159,6 @@ static int month[] = {
 
 
 time_t mktime(struct time *tm) {
-	schk_init();
-
 	time_t res;
 	int year;
 
@@ -190,7 +179,5 @@ time_t mktime(struct time *tm) {
 	res += tm->min * MIN;
 	res += tm->sec;
 
-	schk_leave();
-
 	return res;
 }

+ 1 - 6
kernel/console.c

@@ -29,9 +29,8 @@
 
 #include <kernel/console.h>
 #include <kernel/vsprintf.h>
-#include <kernel/schk.h>
-
 #include <kernel/tty.h>
+
 #include <lib/string.h>
 #include <arch/io.h>
 
@@ -48,8 +47,6 @@ int nc_putc(struct tty *, char);
 
 
 errno_t console_init(void) {
-	schk_init();
-
 	/* stdout will be the tty1 if com0 exists */
 	stdout = &tty0;
 
@@ -74,8 +71,6 @@ errno_t console_init(void) {
 
 	/* well, this is the end */
 
-	schk_leave();
-
 	return 0;
 }
 

+ 2 - 101
kernel/int.c

@@ -29,10 +29,9 @@
 #include <kernel/types.h>
 
 #include <kernel/int.h>
-#include <kernel/schk.h>
 #include <kernel/mm.h>
-
 #include <kernel/console.h>
+#include <kernel/panic.h>
 
 #include <arch/x86/int.h>
 #include <arch/io.h>
@@ -40,11 +39,8 @@
 
 
 int int_init(void) {
-	schk_init();
-
 	/* init PIC */
 
-
 	/* ICW: initial control word */
 	outb(0x11, PIC0_ICW1);
 	outb(0x20, PIC0_ICW2);
@@ -114,15 +110,11 @@ int int_init(void) {
 
 	set_sys_gate(idt_table + 0x80, 1, &syscall);
 
-	schk_leave();
-
 	return 0;
 }
 
 
 void set_gate(struct idt_entry *entry, char attr, char ist, void *addr) {
-	schk_init();
-
 #define handler ((__uint64_t) addr)
 
 	entry->selector = KERNEL_CS;
@@ -134,15 +126,11 @@ void set_gate(struct idt_entry *entry, char attr, char ist, void *addr) {
 	entry->off_32_64 = handler >> 32;
 	entry->zero = 0x00000000;
 
-	schk_leave();
-
 	return;
 }
 
 
 void die(const char *s, const __uint64_t *rsp, char nr) {
-	schk_init();
-	
 	printk(red, "int #%b: %s. \n", nr, s);
 
 	printk(red, "rsp now: %q\n", rsp);
@@ -178,159 +166,99 @@ void die(const char *s, const __uint64_t *rsp, char nr) {
 
 	for (;;) hlt();
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_divide_error(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("divide error", rsp, 0);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_debug(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("debug", rsp, 1);
 
-	schk_leave();
-
 	return;
 }
 
 void do_nmi(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("nmi", rsp, 2);
 
-	schk_leave();
-
 	return;
 }
 
 void do_int3(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("int3", rsp, 3);
 
-	schk_leave();
-
 	return;
 }
 
 void do_overflow(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("overflow", rsp, 4);
 
-	schk_leave();
-
 	return;
 }
 
 void do_bound(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("bound", rsp, 5);
 
-	schk_leave();
-
 	return;
 }
 
 void do_ud(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("undefined instruction", rsp, 6);
 
-	schk_leave();
-
 	return;
 }
 
 void do_no_fpu(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("fpu not present", rsp, 7);
 
-	schk_leave();
-
 	return;
 }
 
 void do_double_fault(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("double fault", rsp, 8);
 
-	schk_leave();
-
 	return;
 }
 
 void do_fpu_overrun(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("fpu overrun", rsp, 9);
 
-	schk_leave();
-
 	return;
 }
 
 void do_invalid_tss(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("invalid tss", rsp, 10);
 
-	schk_leave();
-
 	return;
 }
 
 void do_no_segment(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("no such segment", rsp, 11);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_stack(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("stack error", rsp, 12);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_gp(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("general protection", rsp, 13);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_page_fault(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	printk(red, "error code: %q\n", errcode);
 
 	if (errcode & 1) 
@@ -356,77 +284,50 @@ void do_page_fault(const __uint64_t *rsp, __uint64_t errcode) {
 
 	putc('\n', red);
 
-
 	die("page fault", rsp, 14);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_reserved(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
-	die("reserved", rsp, 15);
-
-	schk_leave();
+	die("reserved exception", rsp, 15);
 
 	return;
 }
 
 
 void do_fpu_error(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("fpu error", rsp, 16);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_alignment(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("alignment error", rsp, 17);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_machine(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("machine check", rsp, 18);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_simd(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("simd error", rsp, 19);
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_virtualization(const __uint64_t *rsp, __uint64_t errcode) {
-	schk_init();
-
 	die("virtualization error", rsp, 20);
 
-	schk_leave();
-
 	return;
 }
 

+ 2 - 21
kernel/irq.c

@@ -30,7 +30,7 @@
 
 #include <kernel/console.h>
 #include <kernel/int.h>
-#include <kernel/schk.h>
+#include <kernel/panic.h>
 
 #include <arch/x86/int.h>
 #include <arch/io.h>
@@ -58,22 +58,16 @@ build_irq(0x2f);
 struct irq_entry irq_table[MAX_IRQ_NR];
 
 void set_irq(int nr, const void *handler) {
-	schk_init();
-
 	if (nr > 16) 
 		panic("set_irq: bad nr. ");
 
 	irq_table[nr].handler = handler;
 
-	schk_leave();
-
 	return;
 }
 
 
 void register_irq(int nr, void *entry, const void *handler) {
-	schk_init();
-
 	if (nr > 16) 
 		panic("register_irq: bad nr. ");
 
@@ -102,15 +96,11 @@ void register_irq(int nr, void *entry, const void *handler) {
 	/* IRQ nr starts at 0x20 */
 	set_int_gate(idt_table + 0x20 + nr, 0, entry);
 
-	schk_leave();
-
 	return;
 }
 
 
 void unregister_irq(int nr) {
-	schk_init();
-
 	__uint8_t mask;
 
 	irq_table[nr].handler = NULL;
@@ -125,15 +115,11 @@ void unregister_irq(int nr) {
 		outb(mask, 0xa1);
 	}
 
-	schk_leave();
-
 	return;
 }
 
 
 void do_irq(const __uint64_t *rsp, __uint64_t nr) {
-	schk_init();
-
 	void (*fn) (void) = irq_table[nr - 0x20].handler;
 
 	if (fn) 
@@ -152,17 +138,14 @@ void do_irq(const __uint64_t *rsp, __uint64_t nr) {
 	else 
 		outb(0x60 - 0x20 + nr, PIC0_OCW2);
 
-	schk_leave();
-
 	return;
 }
 
 void trace_irq(void) {
-	schk_init();
-
 	printk(yellow, "tracing irq: \n");
 
 	__uint8_t slave = 0, master = 0;
+
 	int i;
 
 	master = inb(0x21);
@@ -178,8 +161,6 @@ void trace_irq(void) {
 		if (!(slave & (1 << i))) 
 			printk(yellow, "\tirq %b (slave) enabled. \n", i + 8);
 
-	schk_leave();
-
 	return;
 }
 

+ 0 - 13
kernel/keyboard.c

@@ -31,7 +31,6 @@
 #include <kernel/console.h>
 #include <lib/string.h>
 #include <lib/fifo.h>
-#include <kernel/schk.h>
 
 #include <kernel/mm.h>
 #include <kernel/keyboard.h>
@@ -50,29 +49,21 @@ __uint8_t ext = 0;
 
 
 errno_t kbd_init(void) {
-	schk_init();
-
 	__fifo_buf_t *key_buf = kmalloc(&pool, MAX_KEYS * sizeof(__fifo_buf_t));
 
 	memset(key_buf, 0x00, MAX_KEYS * sizeof(__uint64_t));
 
 	fifo_init(&kbd_fifo, key_buf, MAX_KEYS);
 
-	schk_leave();
-
 	return 0;
 }
 
 void do_keyboard(void) {
-	schk_init();
-
 	__uint8_t code = inb(KBD_DATA);
 
 	/* insert it to the fifo */
 	fifo_put(&kbd_fifo, code);
 
-	schk_leave();
-
 	return;
 }
 
@@ -114,8 +105,6 @@ static char keycode_alphabet_shift[] = {
 };
 
 void put_keycode(void) {
-	schk_init();
-
 	__fifo_buf_t i;
 	i = fifo_get(&kbd_fifo);
 
@@ -229,7 +218,5 @@ undisplayable:
 
 	ext = 0;
 
-	schk_leave();
-
 	return;
 }

+ 24 - 43
kernel/mm.c

@@ -30,11 +30,11 @@
 
 #include <kernel/console.h>
 #include <kernel/int.h>
+#include <kernel/panic.h>
 #include <kernel/mm.h>
 
 #include <lib/bitmap.h>
 #include <lib/string.h>
-#include <kernel/schk.h>
 
 #include <arch/x86/int.h>
 #include <arch/x86/paging.h>
@@ -49,8 +49,6 @@ struct mempool pool, upool, devpool;
 
 
 void mm_init(void) {
-	schk_init();
-
 	mm = (struct sysmm *) PAGE_4K_ALIGN((__uint64_t) &_end);
 	
 	struct e820_entry *e820 = E820_ADDR;
@@ -206,8 +204,6 @@ void mm_init(void) {
 
 	upool.next = &devpool;
 
-	schk_leave();
-
 	return;
 
 #undef z
@@ -216,43 +212,54 @@ void mm_init(void) {
 /* find an empty page table entry, and return its number */
 
 void *mapping(void *p, __uint64_t attr) {
-	schk_init();
-
 	__uint64_t i;
 	void *addr = (void *) ((__uint64_t) p & PAGE_MASK);
 
 	/* we just use the (max) 1 GB memory in kernel (512 pages) */
 
-#define PT_ADDR    ((__uint64_t *) 0x2000)
+#define PT_ADDR	((__uint64_t *) 0x2000)
+
+	for (i = 0; i < 512; i++) 
+		if (PT_ADDR[i] == (__uint64_t) addr) 
+			return (void *) ((i << PAGE_SHIFT) + p - addr);
 
 	for (i = 0; i < 512; i++) {
 		if (!PT_ADDR[i]) {
 			PT_ADDR[i] = (__uint64_t) addr | attr;
 			invalidate();
-			schk_leave();
+
 			return (void *) ((i << PAGE_SHIFT) + p - addr);
 		}
 	}
 
-	schk_leave();
 	return NULL;
 #undef PT_ADDR
 }
 
 
-void *alloc_page(void) {
-	/* ...... */
-	schk_init();
+__uint64_t unmapping(void *p) {
+	int i;
+	__uint64_t addr = (__uint64_t) p & PAGE_MASK;
+
+#define PT_ADDR	((__uint64_t *) 0x2000)
+
+	for (i = 0; i < 512; i++) 
+		if (PT_ADDR[i] == addr) 
+			return PT_ADDR[i] & 0xff;
+
+	panic("unmapping: page not found. ");
 
-	schk_leave();
+	return 0;
+
+}
 
+
+void *alloc_page(void) {
 	return alloc_page_att(PATT_KERNEL);
 }
 
 
 void *alloc_page_att(__uint64_t attr) {
-	schk_init();
-
 	__uint64_t i;
 
 	for (i = 0; bitmap_read(mm->bitmap, i); i++) {
@@ -271,30 +278,22 @@ void *alloc_page_att(__uint64_t attr) {
 		return NULL;
 	}
 
-	schk_leave();
-
 	return addr;
 }
  
 
 void free_page(void *p) {
-	schk_init();
-
 	__uint64_t i;
 
 	i = (__uint64_t) p >> PAGE_SHIFT;
 
 	bitmap_set(mm->bitmap, i, 0);
-	
-	schk_leave();
 
 	return;
 }
 
 
 void *kmalloc(struct mempool *pool, __uint64_t size) {
-	schk_init();
-
 	if (!size || size > pool->size - pool->used) 
 		return NULL;
 
@@ -315,7 +314,6 @@ void *kmalloc(struct mempool *pool, __uint64_t size) {
 		bitmap_set(pool->bitmap, i, 1);
 		pool->used++;
 
-		schk_leave();
 		return pool->page + (i << POOL_ENTRY_SHIFT);
 	}
 
@@ -345,7 +343,6 @@ repeat:
 
 		pool->used += points;
 
-		schk_leave();
 		return pool->page + (i << POOL_ENTRY_SHIFT);
 	}
 
@@ -354,15 +351,11 @@ panic:
 	printk(yellow, "kmalloc: no enough memory (total %d KB, %d bytes used, requested %d bytes)\n", 
 		pool->size >> 10, pool->used << 6, points << 6);
 
-	schk_leave();
-
 	return NULL;
 }
 
 
 void kfree(struct mempool *pool, void *p, __uint64_t size) {
-	schk_init();
-
 	if (pool == &devpool) 
 		size = (size + 1023) & ~1023;
 	
@@ -376,15 +369,11 @@ void kfree(struct mempool *pool, void *p, __uint64_t size) {
 
 	pool->used -= points;
 
-	schk_leave();
-
 	return;
 }
 
 
 void trace_mm(void) {
-	schk_init();
-
 	printk(yellow, "tracing system memory: \n");
 
 	__uint64_t *cr3 = (__uint64_t *) get_cr3();
@@ -401,8 +390,6 @@ void trace_mm(void) {
 					pt[i] & ~0xff, pt[i] & 0xff);
 	}
 		
-	schk_leave();
-
 	return;
 }
 
@@ -414,8 +401,6 @@ void trace_mm(void) {
  * */
 
 void *mm_vphy(void *p) {
-	schk_init();
-
 	/* like mapping(), we just search in the first 1g */
 
 	__uint64_t addr = (__uint64_t) p & PAGE_MASK;
@@ -425,12 +410,8 @@ void *mm_vphy(void *p) {
 	__uint64_t i;
 
 	for (i = 0; i < 512; i++) 
-		if ((PT_ADDR[i] & ~0xff) == addr) {
-			schk_leave();
+		if ((PT_ADDR[i] & ~0xff) == addr) 
 			return (void *) ((i << PAGE_SHIFT) + ((__uint64_t) p - addr));
-		}
-
-	schk_leave();
 
 	return NULL;
 

+ 4 - 29
kernel/panic.c

@@ -57,8 +57,7 @@ void syslog(const char *s) {
 		if (syslog_index == 32768) 
 			syslog_index = 0;
 	
-		*(syslog_index + SYSLOG_BUFFER) = s[i];			
-		syslog_index++;
+		SYSLOG_BUFFER[syslog_index++] = s[i];			
 	}
 
 
@@ -67,36 +66,12 @@ void syslog(const char *s) {
 
 
 void trace_syslog(void) {
-	printk(yellow, "tracing system log: \n");
-
-#if DEBUG_LEVEL != TEST_DEBUG_LEVEL
-	printk(yellow, "system log disabled. \n");
-	return;
-
-#else 
-	/* put last 8 calls to the screen */
-
 	int i;
-	char *fname = SYSLOG_BUFFER + syslog_index - 1;
-
-	for (i = 0; i < TRACE_SYSLOG_NR; i++) {
-		while (*--fname != '\t');
 
-		char *fn = fname + 1;
-
-		if (!(i % 3)) 
-			putc('\n', yellow);
-
-		print(yellow, "+ ");
-
-		while (*fn != '\t') 
-			putc(*fn++, yellow);
-
-		putc('\t', white);
-	}
+	printk(yellow, "tracing system log: \n");
 
-	putc('\n', yellow);
+	for (i = 0; i < TRACE_SYSLOG_MAX; i++) 
+		putc(SYSLOG_BUFFER[syslog_index + i], yellow);
 
 	return;
-#endif
 }

+ 0 - 11
kernel/pci.c

@@ -31,7 +31,6 @@
 #include <kernel/int.h>
 #include <kernel/pci.h>
 #include <kernel/pci_vendors.h>
-#include <kernel/schk.h>
 
 #include <lib/string.h>
 
@@ -42,8 +41,6 @@
 
 
 __uint32_t pci_read_config(__uint8_t bus, __uint8_t slot, __uint8_t func, __uint8_t offset) {
-	schk_init();
-
 	__uint32_t addr;
 
 #define lbus  ((__uint32_t) bus)
@@ -58,8 +55,6 @@ __uint32_t pci_read_config(__uint8_t bus, __uint8_t slot, __uint8_t func, __uint
 }
 
 __uint32_t pci_lspci(void) {
-	schk_init();
-
 	__uint8_t bus, slot, func;
 	__uint32_t devs = 0;
 
@@ -80,15 +75,11 @@ __uint32_t pci_lspci(void) {
 		}
 	}
 
-	schk_leave();
-
 	return devs;
 }
 
 
 void pci_infodev(__uint8_t bus, __uint8_t slot, __uint8_t func) {
-	schk_init();
-
 	__uint32_t buf[256];
 	struct pci_header header;
 	int i;
@@ -152,8 +143,6 @@ void pci_infodev(__uint8_t bus, __uint8_t slot, __uint8_t func) {
 
 	dev_init(hdr);
 
-	schk_leave();
-
 	return;
 }
 

+ 1 - 1
kernel/rlib/Makefile

@@ -1,6 +1,6 @@
 C_FLAGS = -mcmodel=large -m64 -fno-builtin -nostdlib -I ../../include/ -Wall -Werror -O3 -g 
 
-OBJS = bitman.o bitmap.o fifo.o 
+OBJS = bitmap.o fifo.o 
 
 all: $(OBJS) rlib.o 
 

+ 4 - 12
kernel/rlib/bitmap.c

@@ -24,32 +24,24 @@
 
 
 
+#include <kernel/types.h>
 #include <lib/rlib.h>
-#include <kernel/schk.h>
 
 
 void bitmap_set(unsigned char *bitmap, unsigned int pos, unsigned char value) {
-	schk_init();
-
-	unsigned char mask = 0x80 >> (pos & 0x7);
+	__uint8_t mask = 0x80 >> (pos & 0x7);
 
 	if (value) 
 		bitmap[pos >> 3] |= mask;
 	
 	else 
 		bitmap[pos >> 3] &= ~mask;
-
-	schk_leave();
 	
 	return;
 }
 
-char bitmap_read(unsigned char *bitmap, unsigned int pos) {
-	schk_init();
-
-	unsigned char mask = 0x80 >> (pos & 0x7);
-
-	schk_leave();
+__uint8_t bitmap_read(unsigned char *bitmap, unsigned int pos) {
+	__uint8_t mask = 0x80 >> (pos & 0x07);
 
 	return (mask & bitmap[pos >> 3]) == mask ? 1 : 0;
 }

+ 0 - 9
kernel/rlib/fifo.c

@@ -26,29 +26,22 @@
 
 #include <kernel/init.h>
 #include <kernel/types.h>
-#include <kernel/schk.h>
 
 #include <lib/fifo.h>
 
 
 void fifo_init(struct fifo *fifo, __fifo_buf_t *buf, int total) {
-	schk_init();
-
 	fifo->buf = buf;
 	fifo->total = total;
 	
 	fifo->next_wr = fifo->next_rd = 0;
 	fifo->need_read = 0;
 
-	schk_leave();
-
 	return;
 }
 
 
 __fifo_buf_t fifo_get(struct fifo *fifo) {
-	schk_init();
-
 	__fifo_buf_t res;
 
 	if (!fifo->need_read) 
@@ -61,8 +54,6 @@ __fifo_buf_t fifo_get(struct fifo *fifo) {
 	if (fifo->next_rd == fifo->total) 
 		fifo->next_rd = 0;
 
-	schk_leave();
-
 	return res;
 }
 

+ 6 - 54
kernel/sched.c

@@ -33,7 +33,6 @@
 #include <kernel/sched.h>
 
 #include <kernel/console.h>
-#include <kernel/schk.h>
 #include <kernel/mm.h>
 
 #include <sys/syscall.h>
@@ -58,9 +57,6 @@ struct task *current;
 
 struct task *tasks[MAX_TASKS] = {0};
 
-/* user/hello.c */
-extern __uint64_t utask_a(__uint64_t);
-
 
 int do_exit(__uint64_t exitcode) {
 	printk(white, "do_exit: %q\n", exitcode);
@@ -70,8 +66,6 @@ int do_exit(__uint64_t exitcode) {
 
 
 int task_init(void) {
-	schk_init();
-
 	/* initial the init-tss */
 
 	init_tss.rsp0 = init_tss.rsp1 = init_tss.rsp2 = get_rsp();
@@ -83,8 +77,6 @@ int task_init(void) {
 
 	current = &init_task;
 
-	schk_leave();
-
 	return 0;
 }
 
@@ -148,8 +140,6 @@ __asm__(
  * */
 
 int ktask_create(__uint64_t (* entry) (__uint64_t), __uint64_t arg) {
-	schk_init();
-
 	struct registers regs;
 
 	memset(&regs, 0x00, sizeof(regs));
@@ -160,14 +150,10 @@ int ktask_create(__uint64_t (* entry) (__uint64_t), __uint64_t arg) {
 	/* argument */
 	regs.rdi = arg;
 
-	schk_leave();
-
 	return do_fork(&regs, 0);
 }
 
 int utask_create(__uint64_t (* entry) (__uint64_t), __uint64_t arg) {
-	schk_init();
-
 	struct registers regs;
 
 	memset(&regs, 0x00, sizeof(regs));
@@ -175,25 +161,17 @@ int utask_create(__uint64_t (* entry) (__uint64_t), __uint64_t arg) {
 	regs.rip = (__uint64_t) entry;
 	regs.rdi = arg;
 
-	schk_leave();
-
 	return do_fork(&regs, 3);
 }
 
 
 
 static __uint32_t find_free_pid(void) {
-	schk_init();
-
 	__uint32_t freepid;
 
 	for (freepid = 0; freepid < MAX_TASKS; freepid++) 
-		if (!tasks[freepid]) {
-			schk_leave();
+		if (!tasks[freepid]) 
 			return freepid;
-		}
-
-	schk_leave();
 
 	return -1;
 }
@@ -213,8 +191,6 @@ static __uint32_t find_free_pid(void) {
  * */
 
 int do_fork(struct registers *regs, __uint64_t dpl) {
-	schk_init();
-
 	__uint64_t start_stack;
 
 	if (!dpl) 
@@ -223,10 +199,8 @@ int do_fork(struct registers *regs, __uint64_t dpl) {
 	else 
 		start_stack = (__uint64_t) kmalloc(&upool, 65536);
 
-	if (!start_stack) {
-		schk_leave();
+	if (!start_stack) 
 		return -ENOMEM;
-	}
 
 	/* += stack_size: point to the top of stack. */
 
@@ -234,10 +208,8 @@ int do_fork(struct registers *regs, __uint64_t dpl) {
 
 	struct task *child = kmalloc(&pool, sizeof(struct task));
 
-	if (!child) {
-		schk_leave();
+	if (!child) 
 		return -ENOMEM;
-	}
 
 	/* current is this task's father */
 	memcpy(child, current, sizeof(struct task));
@@ -257,10 +229,8 @@ int do_fork(struct registers *regs, __uint64_t dpl) {
 
 	child->pid = find_free_pid();
 
-	if (child->pid == -1) {
-		schk_leave();
+	if (child->pid == -1) 
 		return -EAGAIN;
-	}
 
 	printk(white, "new task pid: %d\n", child->pid);
 
@@ -329,15 +299,11 @@ int do_fork(struct registers *regs, __uint64_t dpl) {
 
 	tasks[child->pid] = child;
 
-	schk_leave();
-
 	return 0;
 }
 
 
 void set_tss(struct tss *table, __uint64_t dpl) {
-	schk_init();
-
 	__uint64_t tss = (__uint64_t) table;
 
 	/* create a descriptor (in gdt) and register it */
@@ -356,8 +322,6 @@ void set_tss(struct tss *table, __uint64_t dpl) {
 	/* load it to tr */
 	ltr(40);
 
-	schk_leave();
-
 	return;
 }
 
@@ -365,8 +329,6 @@ void set_tss(struct tss *table, __uint64_t dpl) {
 static char need_open_clock = 0;
 
 void schedule(void) {
-	schk_init();
-
 	/* find and switch to a new task */
 
 	__uint32_t pid;
@@ -402,29 +364,21 @@ void schedule(void) {
 		}
 	}
 	
-	if (current->pid == bestpid) {
-		schk_leave();
+	if (current->pid == bestpid) 
 		return;
-	}
 
 	/* will sti() in switch_to() */
 
 	switch_to(tasks[bestpid]);
 
-	schk_leave();
-
 	return;
 }
 
 void do_clock(void) {
-	schk_init();
-
 	/* still in the init mode */
 
-	if (!current) {
-		schk_leave();
+	if (!current) 
 		return;
-	}
 
 	current->counter--;
 
@@ -435,7 +389,5 @@ void do_clock(void) {
 		schedule();
 	}
 
-	schk_leave();
-
 	return;
 }

+ 1 - 11
kernel/sys.c

@@ -28,10 +28,8 @@
 #include <kernel/errno.h>
 #include <kernel/types.h>
 
-#include <kernel/schk.h>
-
-#include <sys/syscall.h>
 #include <kernel/console.h>
+#include <sys/syscall.h>
 
 
 void *syscall_table[SYSCALL_NR] = {
@@ -45,18 +43,12 @@ void *syscall_table[SYSCALL_NR] = {
 
 
 int no_syscall(void) {
-	schk_init();
-	
 	printk(yellow, "no such system call. ");
 
-	schk_leave();
-
 	return -ENOSYS;
 }
 
 int sys_print(char *s) {
-	schk_init();
-
 	printk(yellow, "sys_print: s = %q\n", s);
 
 	if (!s) 
@@ -64,7 +56,5 @@ int sys_print(char *s) {
 
 	print(yellow, s);
 
-	schk_leave();
-
 	return 0;
 }

+ 0 - 9
kernel/tty.c

@@ -29,7 +29,6 @@
 #include <kernel/types.h>
 
 #include <kernel/console.h>
-#include <kernel/schk.h>
 #include <kernel/vsprintf.h>
 #include <kernel/tty.h>
 
@@ -44,8 +43,6 @@ struct tty *stdout;
 /* read a character from tty (keyboard) with non-cooked */
 
 int tty_read(struct tty *tty, char *buf, size_t nbytes) {
-	schk_init();
-
 	if (!buf) 
 		return -EINVAL;
 
@@ -57,15 +54,11 @@ int tty_read(struct tty *tty, char *buf, size_t nbytes) {
 		/* read from stdout, or stderr */
 		return -EINVAL;
 
-	schk_leave();
-
 	return -EIO;
 }
 
 
 int tty_write(struct tty *tty, char *buf, size_t nbytes) {
-	schk_init();
-
 	if (!buf) 
 		return -EINVAL;
 
@@ -81,8 +74,6 @@ int tty_write(struct tty *tty, char *buf, size_t nbytes) {
 		tty->putc(tty, buf[i]);
 	}
 
-	schk_leave();
-
 	return i;
 }
 

+ 0 - 2
kernel/vsprintf.c

@@ -27,9 +27,7 @@
 #include <kernel/init.h>
 #include <kernel/errno.h>
 #include <kernel/types.h>
-
 #include <kernel/vsprintf.h>
-#include <kernel/schk.h>
 
 #include <arch/x86/int.h>
 #include <arch/io.h>

+ 26 - 18
kernel/rlib/bitman.c → modules/ahci.c

@@ -23,33 +23,41 @@
 
 
 
+#include <kernel/init.h>
+#include <kernel/errno.h>
+#include <kernel/types.h>
 
-#include <lib/rlib.h>
-#include <kernel/schk.h>
+#include <kernel/console.h>
+#include <kernel/pci.h>
+#include <kernel/mm.h>
 
-unsigned int bitman_alloc(struct bitmap_manager *bm) {
-	schk_init();
+#include <kernel/int.h>
+#include <kernel/panic.h>
 
-	unsigned int p = bm->next_free;
-	bitmap_set(bm->bitmap, bm->next_free, 1);
+#include <arch/x86/paging.h>
+#include <modules/ahci.h>
+#include <lib/string.h>
 
-	for (; bitmap_read(bm->bitmap, bm->next_free) == 1; bm->next_free++);
 
-	schk_leave();
-	
-	return p;
-}
+struct ahci_hba_mem *hba;
+
+
+errno_t ahci_init(struct pci_header0 *hdr) {
+	ahci_info("ahci initialized. \n");
 
-void bitman_free(struct bitmap_manager *bm, unsigned int pos) {
-	schk_init();
+	ahci_info("PCI BAR5: \t%q\n", hdr->bar5);
 
-	bitmap_set(bm->bitmap, pos, 0);
+	hba = mapping((void *) (__uint64_t) hdr->bar5, PATT_DEVMM);
 
-	if (pos < bm->next_free) 
-		bm->next_free = pos;
+	ahci_info("HBA maps to %q. \n", hba);
 
-	schk_leave();
+	struct ahci_cmd_header *cmdlist;
 
-	return;
+	cmdlist = mapping((void *) (__uint64_t) hba->ports[0].cmd_list, PATT_DEVMM);
+
+	ahci_info("port[0] command list maps to %q. \n", cmdlist);
+
+	return 0;
 }
 
+

+ 0 - 5
modules/ide.c

@@ -33,7 +33,6 @@
 
 #include <kernel/int.h>
 #include <kernel/panic.h>
-#include <kernel/schk.h>
 
 #include <kernel/block.h>
 #include <arch/x86/paging.h>
@@ -59,8 +58,6 @@ __uint64_t hda_nsectors, hdb_nsectors;
 
 
 errno_t ide_init(struct pci_header0 *hdr) {
-	schk_init();
-
 	__io_t hd0_base, hd0_ctl;
 	__io_t hd1_base, hd1_ctl;
 
@@ -144,8 +141,6 @@ errno_t ide_init(struct pci_header0 *hdr) {
 
 	ide_info("ide_init: id completed. \n");
 
-	schk_leave();
-
 	return 0;
 }