您的位置:首页 > 运维架构 > Linux

用nasm语言重新实现linux-0.11 asm.s(博古以通今)

2010-04-25 18:57 344 查看
;文件名:followking/kernel/asm.s
;本文件改写linux-0.11/kernel/asm.s,目的是为了体验整个系统构建的过程。
;作者:hk0625
;开始时间: 2010年03月26号星期五 18:47
;完成时间: 2010年03月31号星期三 15:53(完成)
;最后修改时间: 2010年04月20日星期二 23:51:
;地点: 北京化工大学郁夫图书馆文法阅览室小圆桌
;Email:shaohua20051231@163.com
;下面let's try!

;asm.s程序包括大部分的硬件故障(或出错)处理的底层代码。

;以下这些全局函数的声明将在/kernel/traps.c中用到。不知道,下划线是否需要?
;先不要吧,出错再改。呵呵,先实现一个函数,然后调试一下。如果通过,再写把
;其他的函数实现。如果想这样做,我的先回到/kernel/traps.c中把其他中断调用函数
;注释起来,只留下
global divide_error, debug, nmi, _int3, overflow, bounds, invalid_op
global double_fault, coprocessor_segment_overrun, parralled_interrupt
global invalid_TSS, segment_not_present, stack_segment
global general_protection, coprocessor_error, irq13, reserved
global device_not_available, general_protection, ;page_fault
extern do_divide_error, do_double_fault, do_general_protection
extern do_int3, do_nmi, do_debug, do_overflow, do_bounds
extern do_invalid_op, do_device_not_available, do_coprocessor_segment_overrun
extern do_invalid_TSS, do_segment_not_present, do_stack_segment
extern do_coprocessor_error, do_reserved, do_page_fault, do_parrelled_interrupt
extern coprocessor_error

section .text

divide_error:
push do_divide_error
no_error_code:
xchg [esp], eax
push ebx
push ecx
push edx
push edi
push esi
push ebp
push ds
push es
push fs
push 0
lea edx, [esp+44]
push edx
mov edx, 0x10
mov ds, dx
mov es, dx
mov fs, dx
call eax
add esp, 8
pop fs
pop es
pop ds
pop ebp
pop esi
pop edi
pop edx
pop ecx
pop ebx
pop eax
iret
;****************************************************************************
; 现在又有一个函数do_divide_error需要我们去实现了。呵呵,它在/kernel/traps.c*
;2010年03月26号星期五 20:11 *
;****************************************************************************

debug:
push do_int3
jmp no_error_code

nmi:
push do_nmi
jmp no_error_code

_int3:
push do_int3
jmp no_error_code

overflow:
push do_overflow
jmp no_error_code

bounds:
push do_bounds
jmp no_error_code

invalid_op:
push do_invalid_op
jmp no_error_code

coprocessor_segment_overrun:
push do_coprocessor_segment_overrun
jmp no_error_code

reserved:
push do_reserved
jmp no_error_code

irq13:
push eax
xor al, al
out 0xF0, al

mov al, 0x20

jmp coprocessor_error
iret ;调试用

double_fault:
push do_double_fault
error_code:
xchg [esp+4], eax
xchg [esp], ebx
push ecx
push edx
push edi
push esi
push ebp
push ds
push es
push fs
push eax
lea eax, [esp+44]
push eax
mov eax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
call ebx
add esp, 8
pop fs
pop es
pop ds
pop ebp
pop esi
pop edi
pop edx
pop ecx
pop ebx
pop eax
iret

invalid_TSS:
push do_invalid_TSS
jmp error_code

segment_not_present:
push do_segment_not_present
jmp error_code

stack_segment:
push do_stack_segment
jmp error_code

general_proctection:
push do_general_protection
jmp error_code

;调试用,具体实现不在这里
device_not_available:
push do_device_not_available
jmp error_code

general_protection:
push do_general_protection
jmp error_code

;page_fault:
; push do_page_fault
; jmp error_code

parralled_interrupt:
push do_parrelled_interrupt
jmp error_code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: