shoelace源代码分析,bochs调试过程,setup.s

<bochs:1> b 0x90200
<bochs:2> c
(0) Breakpoint 1, 0x90200 in ?? ()
Next at t=78342962
(0) [0x00090200] 9020:0000 (unk. ctxt): mov ax, 0x9000            ; b80090
<bochs:3> u /20 0x90000
00090000: (                    ): mov ax, 0x7c0             ; b8c007
00090003: (                    ): mov ds, ax                ; 8ed8
00090005: (                    ): mov ax, 0x9000            ; b80090
00090008: (                    ): mov es, ax                ; 8ec0
0009000a: (                    ): mov cx, 0x100             ; b90001
0009000d: (                    ): sub si, si                ; 29f6

0009000f: (                    ): sub di, di                ; 29ff


在b 0x90000不会被截获!因为没有出现

Loading system ...

shoelace源代码分析,bochs调试过程,setup.s_第1张图片


因为加载到了0x90000,然后从0x90200开始运行!



loadimage()函数里面有对filesize 的初始化,地址为  0x6aede


static int
loadimage F2(char *, name, INODEFN, fn)

{
  d_inode ibuf;                /* inode buffer */
  inode_nr inum;            /* inode number */
  int err;                /* error code */
  unsigned int filemode;        /* mode of this file */

/* Locate the file given the name */
  if ((inum = findinode(name, &err)) == 0) {
    printf("%s not found\n", name);
    return 0;
  }

  getinode(&ibuf, inum);

  filesize = ibuf.i_size;
  filemode = ibuf.i_mode & I_TYPE;

  if (filemode != I_REGULAR) {
    printf("%s is not a file\n", name);
    return 0;
  }

/* Scan the zones encompassed by this inode */
  dozones(&ibuf.i_zone[0], fn);
  return 1;
}


loadbuilt() 函数有对LoadPoint 的初始化

int
loadbuilt F1(char *, name)

{
  if (name == (char *) 0 || *name == 0)
    return 0;

/* Set up error return here */
  if (setjmp(errjmp))
    return 0;

/* Now attempt to the load the image */
  LoadPoint = KERNELBASEADDRESS;
  LoadStart = 1;
  return loadimage(name, (INODEFN) readkernel);
}

下面重点看readkernel()函数

红色的部分只会运行一次

static inode_nr
readkernel F1(buffer *, bp)

{
  unsigned int build_base;        /* base of parameters left by build */
  unsigned int bpsize;            /* size of unprocessed part of bp */
  unsigned int bpinx;            /* index to unprocessed part of bp */

  if (! LoadStart)
    bpinx  = 0;
  else {
    LoadStart = 0;

    build_base = SECTOR_SIZE-8;
    if (memcmp(&((char *) bp)[SECTOR_SIZE-sizeof(signature)],
               (char *) &signature[0],
           sizeof(signature)) == 0)
      build_base -= sizeof(signature);

    if ( (long) (* (unsigned int *) (&((char *) bp)[build_base]) + 1)
         * SECTOR_SIZE != filesize) {
      printf("%s conflicting size information\n", filename);
      longjmp(errjmp, 1);
    }

    fsck_ds = * (unsigned int *) (&((char *) bp)[build_base+2]);
    fsck_pc = * (unsigned int *) (&((char *) bp)[build_base+4]);
    fsck_cs = * (unsigned int *) (&((char *) bp)[build_base+6]);

    bpinx = SECTOR_SIZE;

  }

  bpsize = sizeof(*bp) - bpinx;

  if (filesize > bpsize) {
    copyto((char *) bp + bpinx, LoadPoint, bpsize);
    filesize  -= bpsize;
    LoadPoint += bpsize;
    return 0;
  }

  copyto((char *) bp + bpinx, LoadPoint, (unsigned int) filesize);
  filesize = 1;
  return ROOT_INODE;
}


<bochs:1> b 0x60e2c
<bochs:2> c
(0) Breakpoint 1, 0x60e2c in ?? ()
Next at t=78050424
(0) [0x00060e2c] 6000:0e2c (unk. ctxt): push bx                   ; 53
<bochs:3> u /20
00060e2c: (                    ): push bx                   ; 53
00060e2d: (                    ): call 0x4388               ; e85835
00060e30: (                    ): add sp, 0x4               ; 83c404

...

<bochs:4> info r
eax            0xb7             183
ecx            0xf3c15          998421
edx            0x280            640
ebx            0xdc1a           56346

0x6dc1a对应于&ibuf

<bochs:15> n
Next at t=78051763
(0) [0x00060e30] 6000:0e30 (unk. ctxt): add sp, 0x4               ; 83c404
<bochs:16> x /10 0x6dc1a
[bochs]:
0x0006dc1a <bogus+       0>:    0x00008180      0x0001ea00      0x52c4955e      0x15320100
0x0006dc2a <bogus+      16>:    0x15341533      0x15361535      0x15381537      0x00001539


0x0001ea00 既是125440既是Image的大小,上面的是对应的磁盘i节点。


你可能感兴趣的:(setup,bochs,shoelace)