免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2021 | 回复: 7

[FreeBSD] 求看过4.4bsd代码的大虾指点 [复制链接]

论坛徽章:
0
发表于 2013-07-10 19:15 |显示全部楼层
本帖最后由 yizhengming 于 2013-07-10 19:19 编辑

下面代码来自4.4BSD-Lite2/usr/src/sys/hp300/hp300/locore.s
百思不得其解 a1 + (sp - kstack ) 代表什么地址?
  1. ENTRY(savectx)
  2.     movl    sp@(4),a1
  3.     movw    sr,a1@(PCB_PS)
  4.     movl    usp,a0          | grab USP
  5.     movl    a0,a1@(PCB_USP)     | and save it
  6.     moveml  #0xFCFC,a1@(PCB_REGS)   | save non-scratch registers

  7.     tstl    sp@(8)          | altreturn?
  8.     jeq Lsavedone
  9.     movl    sp,d0           | relocate current sp relative to a1
  10.     subl    #_kstack,d0     |   (sp is relative to kstack):
  11.     addl    d0,a1           |   a1 += sp - kstack
  12.    movl    sp@,a1@         | write return pc at (relocated) sp@
  13. Lsavedone:
  14.     moveq   #0,d0           | return 0
  15.     rts  
复制代码

论坛徽章:
5
丑牛
日期:2014-01-21 08:26:26卯兔
日期:2014-03-11 06:37:43天秤座
日期:2014-03-25 08:52:52寅虎
日期:2014-04-19 11:39:48午马
日期:2014-08-06 03:56:58
发表于 2013-07-10 19:56 |显示全部楼层
no  看过  

论坛徽章:
0
发表于 2013-07-10 20:01 |显示全部楼层
换句话说  我想知道内核栈位于哪个位置,它和user里的pcb的联系

论坛徽章:
29
技术图书徽章
日期:2013-09-02 19:59:502015元宵节徽章
日期:2015-03-06 15:51:332015小元宵徽章
日期:2015-03-06 15:57:20操作系统版块每日发帖之星
日期:2015-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17操作系统版块每日发帖之星
日期:2015-09-21 06:20:002015亚冠之水原三星
日期:2015-10-30 00:06:07数据库技术版块每日发帖之星
日期:2015-12-24 06:20:0015-16赛季CBA联赛之上海
日期:2016-01-07 10:32:07操作系统版块每日发帖之星
日期:2016-01-08 06:20:00操作系统版块每日发帖之星
日期:2016-05-18 06:20:00IT运维版块每日发帖之星
日期:2016-07-23 06:20:00
发表于 2013-07-10 23:04 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2013-07-11 12:42 |显示全部楼层
回复 1# yizhengming

要看接近原始4.4BSD的就看看freebsd1 或者netbsd1 吧,4.4的好像体系都太难找,hp300。。。

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2013-07-11 12:45 |显示全部楼层
回复 3# yizhengming


    栈是运行期结构,pcb是一堆数据描述一个进程,出入栈信息可以放在pcb里面。

论坛徽章:
0
发表于 2013-07-11 14:44 |显示全部楼层
回复 6# gvim


    谢谢了   这个内核栈的位置搞清楚了   还有个疑点 sp(内核堆栈指针) - kstack  代表什么?


cpu_fork(p1, p2)
    register struct proc *p1, *p2;
{
    register struct user *up = p2->p_addr;
    int offset;
    extern caddr_t getsp();
    extern char kstack[];

    p2->p_md.md_regs = p1->p_md.md_regs;
    p2->p_md.md_flags = (p1->p_md.md_flags & ~(MDP_AST|MDP_HPUXTRACE));

    /*  
     * Copy pcb and stack from proc p1 to p2.
     * We do this as cheaply as possible, copying only the active
     * part of the stack.  The stack and pcb need to agree;
     * this is tricky, as the final pcb is constructed by savectx,
     * but its frame isn't yet on the stack when the stack is copied.
     * switch compensates for this when the child eventually runs.
     * This should be done differently, with a single call
     * that copies and updates the pcb+stack,
     * replacing the bcopy and savectx.
     */
    p2->p_addr->u_pcb = p1->p_addr->u_pcb;
    offset = getsp() - kstack;
    bcopy((caddr_t)kstack + offset, (caddr_t)p2->p_addr + offset,
        (unsigned) ctob(UPAGES) - offset);


    PMAP_ACTIVATE(&p2->p_vmspace->vm_pmap, &up->u_pcb, 0);

    /*  
     * Arrange for a non-local goto when the new process
     * is started, to resume here, returning nonzero from setjmp.
     */
    if (savectx(up, 1)) {
        /*
         * Return 1 in child.
         */
        return (1);
    }
    return (0);
}

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2013-07-12 10:48 |显示全部楼层
回复 7# yizhengming


    体系太偏了,不理解就不好说。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP