![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
网络
文章平均质量分 62
baidu_25474831
这个作者很懒,什么都没留下…
展开
-
我的学习之旅(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 · 919 阅读 · 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 · 514 阅读 · 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 · 625 阅读 · 0 评论 -
我的学习之旅(13) printk.c
printk.c主要实现字符和字符串的打印包括x和y坐标以及字符的颜色。具体功能是:printk_char()在指定坐标打印字符;console初始化前调试打印使用。printk_string()在指定坐标处开始打印字符串;console初始化前调试打印使用。printk()在当前坐标(g_x,g_y)处开始打印字符串;snprintf()格式化字符串具体代码:#inclu原创 2015-01-22 16:34:30 · 460 阅读 · 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 · 329 阅读 · 0 评论 -
我的学习之旅(6)setup.s
;gdt表配置参考 linux source code: setup.s, 2个entry,第一个给CS,第二个给DSgdt: .word 0,0,0,0 ! dummy .word 0x3FFF ! 64Mb (4000*4096=64Mb),由于在boot.s中能识别的最大内存为64M .word 0x0000 ! base address=0 .word 0x9原创 2015-01-21 16:33:21 · 328 阅读 · 0 评论 -
我的学习之旅(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 · 384 阅读 · 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 · 425 阅读 · 0 评论 -
我的学习之旅(24)system.h
system.h主要定义一些常用的x86汇编宏和字节序的处理。大部分都是拷贝linux中源代码.system.h源代码:#ifndef __SYSTEM_H__#define __SYSTEM_H__#ifndef NULL#define NULL 0#endiftypedef unsigned short u16;typedef unsigned ch原创 2015-01-28 09:40:16 · 1315 阅读 · 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 · 583 阅读 · 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 · 1715 阅读 · 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 · 452 阅读 · 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 · 385 阅读 · 0 评论 -
我的学习之旅(36) sched.c
/*硬中断时候触发调用*/void do_timer(void){ unsigned int task_id; int ret; static long tmp = 0; /*扫描timer列表并处理timer对应的fn()*/ if (next_timer) { next_timer->jiffies--;原创 2015-01-31 09:25:38 · 644 阅读 · 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 · 273 阅读 · 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 · 1125 阅读 · 0 评论 -
我的学习之旅(22)vsprintf.c
switch (*fmt) { case '-': flags |= LEFT; goto repeat; case '+': flags |= PLUS; goto repeat; case ' ': flags |=原创 2015-01-28 09:21:40 · 236 阅读 · 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 · 365 阅读 · 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 · 219 阅读 · 0 评论 -
我的学习之旅(5) setup.s
;拷贝内核代码 从 0x1000:0000 到 0x0000:0000;需要保证内核代码小于64KBytes mov ax, #0x0000 cld do_move: mov es, ax mov ax, #0x1000 mov ds, ax sub di, di sub si, si mov cx, #0x8000 ;32768,每次2个字节 r原创 2015-01-21 16:31:57 · 251 阅读 · 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 · 261 阅读 · 0 评论 -
我的学习之旅(3)setup.s
setup.s作为承上启下,主要功能是CPU模式切换、加载内核代码并最终跳转到内核代码。;功能;1. 获取当前内存大小和硬盘参数;2. 从硬盘加载内核代码到内存地址: 0x1000:0000,默认内核代码最大不超过64K;3. 配置 8259a;4. 配置gdt表并进入到32bits保护模式并跳转到内核的kernel_start()函数入口代码:entry start原创 2015-01-21 16:26:28 · 286 阅读 · 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 · 235 阅读 · 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 · 181 阅读 · 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 · 204 阅读 · 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 · 235 阅读 · 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 · 262 阅读 · 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 · 260 阅读 · 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 · 224 阅读 · 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 · 234 阅读 · 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 · 332 阅读 · 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 · 381 阅读 · 0 评论 -
我的学习之旅(32)
setup.s并没有打开页功能,当前cpu只支持32位保护模式,这意味着访问的都是实际的物理地址。前面1M的内容不好乱动,所以内存都是从1M即:0x100000处开始分配使用。等网卡驱动的时候再考虑这个事情。现在先把任务调度功能跑起来再说。任务调度基本原理是:定时器触发中断,对应的中断相应函数保留当前现场(即:记录所有寄存器的值)后恢复之前的现场(即:加载上次记录的所有寄存器的值)。现场的原创 2015-01-30 15:18:32 · 317 阅读 · 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 · 312 阅读 · 0 评论 -
我的学习之旅(20)vsprintf.c
switch (*fmt) { case 'c': if (!(flags & LEFT)) { while (--field_width > 0) { *str++ = ' '; }原创 2015-01-28 09:25:42 · 272 阅读 · 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 · 268 阅读 · 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 · 520 阅读 · 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 · 396 阅读 · 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 · 776 阅读 · 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 · 451 阅读 · 0 评论