sys call

14 views
Skip to first unread message

abs_sn121

unread,
Dec 5, 2012, 7:49:53 AM12/5/12
to osfrom...@googlegroups.com
���ڱ�дϵͳ���ò��֣�������һЩ���⣬����������
sys_get_tick()����ķ���ֵ������ʲô������еõ�������0��
===================================================================
get_ticks:
mov eax, 0
int 0x80 ; �ҽ�ϵͳ��������IDT��0x80��
ret
==============================
_sys_call:
call save
sti

call [sys_call_table+eax*4]
mov [esi+44], eax

cli
ret

==============================
void* sys_call_table[1] = {sys_get_ticks};

int sys_get_ticks() {
color_trace("+", 0x0E); // ���� disp_str
return 5;
}
====================================================================
�ڽ��A�е���get_ticks()��������Ǹ��Ӻţ�������ֵ�����㣬����������
��return 5����
�ҵĽ�̱�ṹ�����е�һ��eax��ֵӦ�ñ����ˣ�Ϊʲô�ܵò�����ȷ�𰸣�


abs_sn121

unread,
Dec 5, 2012, 11:48:03 PM12/5/12
to osfrom...@googlegroups.com
������ˡ�����
�Ұ����ж���صĴ����̸�����һ�ݣ�
save2:
pushad
push ds
push es
push fs
push gs

mov dx, ss
mov ds, dx
mov es, dx

mov esi, esp

inc dword[i_reenter]
cmp dword[i_reenter], 0
jne .1

mov esp, stack0+0x1000 ; point to kernel stack

push restart2
jmp [esi+48]

.1:
push restart_reenter2
jmp [esi+48]

restart2:
mov esp, [proc_to_go]
lea esi, [esp + 18*4]
mov dword[tss+4], esi
restart_reenter2:
dec dword[i_reenter]
; pop gs
; pop fs
; pop es
; pop ds
; popad
add esp, 4+48

iretd
��Щ�����ԭ������ֻ�������ϼ���һ��2������ע�͵���һ�ѵ�pop������ʱ��
����״̬�ָ���������espʱ�������Ĵ����ֶΣ��������� ֵ�����ˡ�������

�һ��Թ���һ�ַ��������ǰ�ԭ����popad�ö��popʵ�֣�����������Ǹ�pop
eax�����ȴ��#GP��������������ˡ�������

��������ܳ����⣬����SYSENTER/SYSEXIT����

��λ�ܰ��ҽ��

abs_sn121

unread,
Dec 6, 2012, 1:41:28 AM12/6/12
to osfrom...@googlegroups.com
���ҵ�����ĸ�Դ�ˡ�
������Щpush��pop�����⣬Ҳ����44��IJ��ԣ��ǵ���[sys_call_table+eax*4]
֮��esi��ֵ�����˱仯����esi ����ָ���̱��ָ�룬����esi��ֵ���ˣ�eax
��ֵ��û�б���ȷ�ر��档
�����ҽ������Ϊ��
_sys_call:
call save ; call save pushes the retaddr into stack.
sti

push esi
call [sys_call_table+eax*4]
pop esi
mov dword[esi+EAXREG-P_STACKBASE], eax ; return value

cli
ret
��make�����У�һЩ��
����save�������Ѿ���espָ�����ں�ջ�������������ö�ջ����esi��ֵӦ��ûʲ
ô���⡣
�������е�sys_get_ticks����Ϊʲô��û�ı�esi��ֵ�أ�

�������л�����ҽ������������ˡ�


彭锐

unread,
May 28, 2013, 4:00:46 AM5/28/13
to osfromscratch
先前你说这个问题的时候我没有怎么注意,后来自己去实现别的系统调用的时候也出现这个问题。我遇到的问题中esi的改变与++有关。
 

彭锐
 
发件人: abs_sn121
发送时间: 2012-12-06 14:41
收件人: osfromscratch
主题: Re: [OSFS:4577] sys call
我找到问题的根源了。
不是那些push和pop的问题,也不是44算的不对,是调用[sys_call_table+eax*4]
之后esi的值发生了变化,而esi 正是指向进程表的指针,所以esi的值变了,eax
的值便没有被正确地保存。
于是我将代码改为:
_sys_call:
call save ; call save pushes the retaddr into stack.
sti
 
push esi
call [sys_call_table+eax*4]
pop esi
mov dword[esi+EAXREG-P_STACKBASE], eax ; return value
 
cli
ret
再make,运行,一些正常。
由于save函数中已经将esp指向了内核栈,所以在这里用堆栈保存esi的值应该没什
么问题。
不过书中的sys_get_ticks函数为什么就没改变esi的值呢?
 
在这里感谢帮助我解答问题的所有人。
 
 
-- 
You received this message because you are subscribed to the Google
Groups "自己动手写操作系统" group.
To post to this group, send email to osfrom...@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group at
Reply all
Reply to author
Forward
0 new messages