code:estabur - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • 根据 正文段、数据段、栈段的大小,设置地址映照表
  • 共输入4个参数
    • nt : 正文段大小(块数)
    • nd : 数据段大小(块数)
    • ns : 栈段大小(块数)
    • sep : 此参数在 pdp11/40 中无效,始终为0,不作讨论
其意义参看 u.u_sep
  • 返回值
    • 若成功,则返回0
    • 失败,则返回-1

1640

1641 /*

1642  * Set up software prototype segmentation

1643  * registers to implement the 3 pseudo

1644  * text,data,stack segment sizes passed

1645  * as arguments.

1646  * The argument sep specifies if the

1647  * text and data+stack segments are to

1648  * be separated.

1649  */

1650 estabur(nt, nd, ns, sep)

1651 {

1652     register a, *ap, *dp;

1653

1654     if(sep) {

1655          if(cputype == 40)

1656           goto err;

1657          if(nseg(nt) > 8 || nseg(nd)+nseg(ns) > 8)

1658           goto err;

1659     } else

1660          if(nseg(nt)+nseg(nd)+nseg(ns) > 8)

1661           goto err;

  • 若 所需内存页 多余8页,则进入错误处理
1662     if(nt+nd+ns+USIZE > maxmem)

1663          goto err;

  • 若 所需内存数 大于 maxmem,则进入错误处理
    • USIZE 为 PPDA区大小,定义在param.h
    • maxmem 为 每进程能使用的最大内存块数,定义在systm.h
1664     a = 0;

1665     ap = &u.u_uisa[0];

1666     dp = &u.u_uisd[0];

1667     while(nt >= 128) {

1668          *dp++ = (127<<8) | RO;

1669          *ap++ = a;

1670          a =+ 128;

1671          nt =- 128;

1672     }

1673     if(nt) {

1674          *dp++ = ((nt-1)<<8) | RO;

1675          *ap++ = a;

1676     }

1677     if(sep)

1678          while(ap < &u.u_uisa[8]) {

1679            *ap++ = 0;

1680            *dp++ = 0;

1681          }

1664 - 1681
  • 设置 正文段 的地址映照表
1682     a = USIZE;

1683     while(nd >= 128) {

1684          *dp++ = (127<<8) | RW;

1685          *ap++ = a;

1686          a =+ 128;

1687          nd =- 128;

1688     }

1689     if(nd) {

1690          *dp++ = ((nd-1)<<8) | RW;

1691          *ap++ = a;

1692          a =+ nd;

1693     }

1694     while(ap << &u.u_uisa[8]) {

1695          *dp++ = 0;

1696          *ap++ = 0;

1697     }

1698     if(sep)

1699          while(ap < &u.u_uisa[16]) {

1700            *dp++ = 0;

1701            *ap++ = 0;

1702          }

1682 - 1702
  • 设置 数据段 的地址映照表
1703     a =+ ns;

1704     while(ns >= 128) {

1705          a =- 128;

1706          ns =- 128;

1707          *--dp = (127<<8) | RW;

1708          *--ap = a;

1709     }

1710     if(ns) {

1711          *--dp = ((128-ns)<<8) | RW | ED;

1712          *--ap = a-128;

1713     }

1714     if(!sep) {

1715          ap = &u.u_uisa[0];

1716          dp = &u.u_uisa[8];

1717          while(ap < &u.u_uisa[8])

1718            *dp++ = *ap++;

1719          ap = &u.u_uisd[0];

1720          dp = &u.u_uisd[8];

1721          while(ap < &u.u_uisd[8])

1722          *dp++ = *ap++;

1723     }

1703 - 1723
  • 设置 栈段 的地址映照表
1724     sureg();
  • 将 生成的相对地址映照表 装入 寄存器
1725     return(0);

1726

1727 err:

1728     u.u_error = ENOMEM;

1729     return(-1);

1730 }

1731 /*---------------------- */

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️