
内核
文章平均质量分 62
baidu_25474831
这个作者很懒,什么都没留下…
展开
-
我的学习之旅(26)system.h
#define lidt(_idt) \ __asm__ __volatile__ ( \ "lidtl (%%ebx)" \ : \ :"b"(_idt) \ ) #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n))原创 2015-01-30 14:13:58 · 414 阅读 · 0 评论 -
我的学习之旅(37) sched.c
//为每个要启动的任务设置初始堆栈地址。void start_another_task(unsigned char task_id, void *pdata ){ if( task_id >= MAX_TASK_NUMBER ) return; if( !g_task_tbl[task_id].task_func_p || !g原创 2015-01-31 09:32:34 · 493 阅读 · 0 评论 -
我的学习之旅(35)sched.c
void add_timer(long jiffies, void (*fn)(void)){ struct timer_list * p; if (!fn) return; cli(); if (jiffies <= 0) (fn)(); else { for (p = timer_list ; p < timer_list + TIME_REQUEST原创 2015-01-31 09:24:16 · 411 阅读 · 0 评论 -
我的学习之旅(34) sched.c
sched.c主要实现任务表初始化、任务调度、定时器、以及每个任务的处理。其中定时器部分直接拷贝linux sched.c的代码。sched.c源代码:#include #include #include #include #include #include #include #include #include #include #include原创 2015-01-31 09:03:21 · 497 阅读 · 0 评论 -
我的学习之旅(33) sched.h
sched.h主要定义了时钟频率、任务数据结构、和sleep宏。sleep宏的实现主要功能是设置当前任务的sleep_time,然后通过软中断0x80做任务软切换。#ifndef __SCHED_H__#define __SCHED_H__#define HZ 100#define delay(ticks) __asm__ __volatile__ ("cli"::); \原创 2015-01-30 14:40:45 · 987 阅读 · 0 评论 -
我的学习之旅 keyboard.h和keyboard.c
简化处理,只支持基本常用的按键操作。keyboard.h源代码:#ifndef __KEY_BOARD_H__#define __KEY_BOARD_H__/*shift键的按下和释放*/#define press_left_shift 0x2a#define press_right_shift 0x36#原创 2015-04-23 16:32:31 · 1252 阅读 · 0 评论 -
我的学习之旅(22)vsprintf.c
switch (*fmt) { case '-': flags |= LEFT; goto repeat; case '+': flags |= PLUS; goto repeat; case ' ': flags |=原创 2015-01-28 09:21:40 · 280 阅读 · 0 评论 -
我的学习之旅(20)console.h和console.c
void console_write(void *tty, char *buf ){ unsigned int number = 0; unsigned char ch; unsigned char *up; if( !tty || !buf ) return; /* 统计当前write_q队列中的字符原创 2015-04-23 15:26:53 · 567 阅读 · 0 评论 -
我的学习之旅 keybaord.h和keyboard.c
/*键盘中断处理程序*/void keyboard_interrupt(void){ /*1、从端口 0x60读取扫描码 2、写控制寄存器端口0x61,复位键盘触发器 3、复位8259,以便接收下一个键盘中断信号 */ unsigned char scan_code; scan_code = inb_p(0x60)原创 2015-04-23 16:40:14 · 634 阅读 · 0 评论 -
我的学习之旅(22)vsprintf.c
if (type & SPECIAL) { if (base == 8) { *str++ = '0'; } else if (base == 16) { *str++ = '0'; *str++ = digits[33]; } } if (!(t原创 2015-01-28 09:14:59 · 237 阅读 · 0 评论 -
我的学习之旅(21)vsprintf.c
static char * number(char *str, int num,int base, int size, int precision, int type){ char c, sign, tmp[36]; const char *digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int i;原创 2015-01-28 09:10:45 · 286 阅读 · 0 评论 -
我的学习之旅(2) boot.s
;用 bios提供的 int 13h 中断把存放在磁盘的第2和第3个扇区的setup.s 加载到内存起始地址 0x9020:0000 ;假定用floopy disk并且setup.s大小不超过1024字节 ; ah = 2 read, ah = 3 write ; al: section ; ch: load_setup: ;目标地址 mov ax, #0x90原创 2015-01-21 09:49:56 · 322 阅读 · 0 评论 -
我的学习之旅(1) boot.s
2015.1.20 目标: 看完赵炯的《linux内核完全注释》,尝试自己在x86下写一个简单的OS,然后移植网卡驱动,实现基本网络功能(ping)bootloader:这部分有很多可以参考,主要的功能应该是:加载后面的setup.s文件做准备。--编译工具:AS86和LD86具体代码: ; 功能:; 1. 拷贝boot.s 从 0x07c0:0000 to 0原创 2015-01-20 19:52:05 · 397 阅读 · 0 评论 -
我的学习之旅(7) build工具
build_boot.c#include #include #include #include #include #include #include #include #define MINIX_HEADER_LEN 32#define BOOT_LENGTH 512int main(int argc, char *argv[] ){ cha原创 2015-01-21 17:48:27 · 242 阅读 · 0 评论 -
我的学习之旅(25)system.h
#define int80() __asm__ ("int $0x80"::)/*copy from linux source code:system.h*/#define move_to_start_task() \__asm__ ("movl %%esp,%%eax\n\t" \ "pushl $0x10\n\t" \ "pushl %%eax\n\t" \ "push原创 2015-01-30 14:10:34 · 479 阅读 · 0 评论 -
我的学习之旅(23)traps.c和 start32.h
接下来就要先初始化中断向量。如书上所说,intel默认保留使用了0~31个中断给自己使用。这些中断目前不想处理。所以这些中断的处理函数只是打印一下就可以。traps.c源代码:#include #include #include void default_handle(void);void do_default_handle(){ /*do nothi原创 2015-01-28 09:33:42 · 317 阅读 · 0 评论 -
我的学习之旅keyboard.h和keyboard.c
/*按下alt之后的key与ascii的映射表 */static unsigned char g_key2ascii_alt_map_table[] = { 0, 0, 0, '@', 0, '$', 0, 0, '{', '[', ']', '}', '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '~', 10, 0,原创 2015-04-23 16:35:24 · 1794 阅读 · 0 评论 -
我的学习之旅(18)console.h和console.c
//设置屏幕的起始位置static void set_screen_origin(unsigned char flag){ if( flag ) cli(); outb_p(12, REG_PORT); outb_p(0xff&((g_screen_origin - DISP_BASE_ADDR) >> 9), VALUE_PORT);原创 2015-04-23 15:18:58 · 662 阅读 · 0 评论 -
我的学习之旅(14)printk.c
void clear_row(unsigned char y,unsigned char color){ unsigned char *p; unsigned char i; p = (unsigned char *)(DISP_BASE_ADDR + (unsigned short)(y*DISP_MAX_X * 2) ); for( i =0;原创 2015-01-27 17:50:18 · 266 阅读 · 0 评论 -
我的学习之旅(11) start32.s
/*拷贝linux head.s部分代码*/setup_idt: lea ignore_int,%edx movl $0x00080000,%eax movw %dx,%ax /* selector = 0x0008 = cs */ movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ lea idt,%edi原创 2015-01-22 10:27:39 · 352 阅读 · 0 评论 -
我的学习之旅(9) 小结
1、运行环境:bochs,支持单步调试,否则汇编真是不好调试。2、磁盘,扇区,磁道《完全注释》书上有讲,要看懂,否则没法加载磁盘文件到内存了。参考http://blog.youkuaiyun.com/misiter/article/details/7469710 上面有详细的讲解。3、8259的介绍书上有,更详细的参考:http://wenku.baidu.com/link?url=pOfCzDDkH原创 2015-01-22 08:59:57 · 271 阅读 · 0 评论 -
我的学习之旅(12) main.c
main.c里面就一个kernel_start()函数。到这可以用c语言写了。接下来的问题是解决打印。否则只能通过单步调试才能知道当前运行到kernel_start()函数了。先实现一个简单的main.c:void kernel_start(void){ printk_string(0,0,"kenel_start()\n", DISP_FG_GREEN); whi原创 2015-01-22 10:31:17 · 325 阅读 · 0 评论 -
我的学习之旅(15)tty.c
模仿linux tty,建立一个console,通过对console的写操作完成字符的显示。tty.c源代码:#include #include #include #include #include static tty_struct_t g_tty_table[MAX_CHANNEL_ID];void tty_init(void){ int i原创 2015-01-27 17:55:46 · 356 阅读 · 0 评论 -
我的学习之旅(8) Makefile
build_setup.c#include #include #include #include #include #include #include #include #define MINIX_HEADER_LEN 32int main(int argc, char *argv[] ){ char buf[2048]; int fd;原创 2015-01-21 17:52:54 · 227 阅读 · 0 评论 -
我的学习之旅(19)console.h和console.c
/*屏幕向上翻一行,等同于屏幕向下移动一行*/static void screen_up(void){ int i; unsigned char *src; unsigned char *dest; unsigned int len; /*是否需要整个屏幕向上翻一行*/ if ( g_screen_top == 0 && g_sc原创 2015-04-23 15:22:35 · 397 阅读 · 0 评论 -
我的学习之旅(17)console.h和console.c
console打印的思想基本参考linux0.1console.h的源代码:#ifndef __CONSOLE_H__#define __CONSOLE_H__#define COLOR_VGA_MODE/*不检查显卡模式,强制写死*/#ifdef COLOR_VGA_MODE#define DISP_BASE_ADDR 0xB8000 /* 0x原创 2015-04-23 15:07:08 · 873 阅读 · 0 评论 -
我的学习之旅(41)sched.c
//每个任务堆栈的初始化,其中cs必须是0x08, ss则是0x10 eflags是0x206unsigned int *task_stk_init(void (*task)(), unsigned int *task_stk ){ unsigned int *stk; int i; int j; stk = task_stk; *stk-原创 2015-02-02 09:06:35 · 305 阅读 · 0 评论 -
我的学习之旅(42)asm.s
asm.s只要实现软、硬中断发生后的响应。代码主要模仿linux的asm.s实现。asm.s:-------------.globl default_handle, timer_interrupt, restore_esp, system_call_interrupt /*全局变量*/default_handle: /*中断发生后的默认处理*/ call do_default_原创 2015-01-31 11:13:44 · 549 阅读 · 0 评论 -
我的学习之旅(39) sched.c
for(i=0;i p = &g_task_tbl[i]; if( p->task_id == i && p->task_func_p ) { if( p->sleep_time == 0 ) p->counter = 10; els原创 2015-01-31 10:26:20 · 305 阅读 · 0 评论 -
我的学习指旅(30) Makefile
boot_partition: @echo @echo Making boot... (cd boot; make clean; make;)kernel: $(OBJS) $(LIBS) $(DRIVERS) @echo @echo Making kernel... @$(LD) $(LDFLAGS) $(OBJ_DIR)start32.o $(OBJS) $(LI原创 2015-01-30 15:09:54 · 269 阅读 · 0 评论 -
我的学习之旅(28) 目录结构调整
kernel_start()函数增加对trap_init()的调用。void kernel_start(void){ clear_screen(DISP_FG_WHITE + DISP_BG_BLACK); (void)printk_init(); (void)trap_init(); return ;}文件越来越多,没办法了原创 2015-01-30 14:18:34 · 268 阅读 · 0 评论 -
我的学习之旅(32)
setup.s并没有打开页功能,当前cpu只支持32位保护模式,这意味着访问的都是实际的物理地址。前面1M的内容不好乱动,所以内存都是从1M即:0x100000处开始分配使用。等网卡驱动的时候再考虑这个事情。现在先把任务调度功能跑起来再说。任务调度基本原理是:定时器触发中断,对应的中断相应函数保留当前现场(即:记录所有寄存器的值)后恢复之前的现场(即:加载上次记录的所有寄存器的值)。现场的原创 2015-01-30 15:18:32 · 351 阅读 · 0 评论 -
我的学习之旅(31) schedule和tools目录下的Makefile
INCLUDE = ../include CC = gcc -march=i386LD = ldAS = asCCFLG = -O2 -c -nostdinc -fno-builtin -fstrength-reduce -fomit-frame-pointer -finline-functions -I$(INCLUDE) -I. %.o: %.c @echo M原创 2015-01-30 15:12:42 · 378 阅读 · 0 评论 -
我的学习之旅(29)Makefile
调整好目录后还要补充增加最外边的Makefile,主要功能是进入到boot、init、schedule、tools、drivers目录编译并做连接后用build_image工具打包成一个image整个image分布应该是这样:0~0x200:boot.s0x200~0x600: setup.s0x600~0x10000 kernel (setup.s 中加载kernel方法限制了当原创 2015-01-30 14:41:51 · 420 阅读 · 0 评论 -
我的学习之旅(20)vsprintf.c
switch (*fmt) { case 'c': if (!(flags & LEFT)) { while (--field_width > 0) { *str++ = ' '; }原创 2015-01-28 09:25:42 · 320 阅读 · 0 评论 -
我的学习之旅(22)Makefile
case 'd': case 'i': flags |= SIGN; case 'u': str = number(str, va_arg(args, unsigned long),原创 2015-01-28 09:27:52 · 349 阅读 · 0 评论 -
我的学习之旅(40) sched.c
if(c) { break; } for(i=0;i p = &g_task_tbl[i]; if( p->task_id == i && p->task_func_p ) { if( p->sleep_time == 0 )原创 2015-02-02 09:05:41 · 307 阅读 · 0 评论 -
我的学习之旅(45)pcnet32.c
pcnet32.c得放在driver目录中按linux驱动的做法先是扫描pci设备,这个当前不搞,直接使用通过lspci命令得到的bus 、slot和func号。根据网上pcie配置空间的读取方法实现几个读取配置空间int,short和byte的函数。具体还可以参考linux 代码中的early.cunsigned int read_pci_config(unsigned char bus原创 2015-01-31 12:00:31 · 456 阅读 · 0 评论 -
我的学习之旅(16)stdarg.h和vsprintf.c
//格式化字符串实现在stdarg.h和vsprintf.c,stdarg.h和vsprintf.c文件沿用linux的stdarg.h文件。stdarg.h源代码:#ifndef __STDARG_H__#define __STDARG_H__typedef char *va_list;/* Amount of space required in an argumen原创 2015-01-27 17:56:39 · 476 阅读 · 0 评论 -
我的学习之旅(4) setup.s
;正式开始加载内核read_begin: ;from sector x, track 0, drive 0, head 0, 其中x 的值存放在 [current_sector]中 xor cx, cx mov cl, byte [current_sector] mov ch, byte [current_track] ;每次加载一个扇区 xor ax, ax mo原创 2015-01-21 16:30:19 · 308 阅读 · 0 评论