The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/boot/mkfhead.s

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 !       Mkfhead.s - DOS & BIOS support for mkfile.c     Author: Kees J. Bot
    2 !                                                               9 May 1998
    3 !
    4 ! This file contains the startup and low level support for the MKFILE.COM
    5 ! utility.  See doshead.ack.s for more comments on .COM files.
    6 !
    7 .sect .text; .sect .rom; .sect .data; .sect .bss
    8 .sect .text
    9 
   10 .define _PSP
   11 _PSP:
   12         .space  256                     ! Program Segment Prefix
   13 
   14 mkfile:
   15         cld                             ! C compiler wants UP
   16         xor     ax, ax                  ! Zero
   17         mov     di, _edata              ! Start of bss is at end of data
   18         mov     cx, _end                ! End of bss (begin of heap)
   19         sub     cx, di                  ! Number of bss bytes
   20         shr     cx, 1                   ! Number of words
   21  rep    stos                            ! Clear bss
   22 
   23         xor     cx, cx                  ! cx = argc
   24         xor     bx, bx
   25         push    bx                      ! argv[argc] = NULL
   26         movb    bl, (_PSP+0x80)         ! Argument byte count
   27 0:      movb    _PSP+0x81(bx), ch       ! Null terminate
   28         dec     bx
   29         js      9f
   30         cmpb    _PSP+0x81(bx), 0x20     ! Whitespace?
   31         jbe     0b
   32 1:      dec     bx                      ! One argument character
   33         js      2f
   34         cmpb    _PSP+0x81(bx), 0x20     ! More argument characters?
   35         ja      1b
   36 2:      lea     ax, _PSP+0x81+1(bx)     ! Address of argument
   37         push    ax                      ! argv[n]
   38         inc     cx                      ! argc++;
   39         test    bx, bx
   40         jns     0b                      ! More arguments?
   41 9:      movb    _PSP+0x81(bx), ch       ! Make a null string
   42         lea     ax, _PSP+0x81(bx)
   43         push    ax                      ! to use as argv[0]
   44         inc     cx                      ! Final value of argc
   45         mov     ax, sp
   46         push    ax                      ! argv
   47         push    cx                      ! argc
   48         call    _main                   ! main(argc, argv)
   49         push    ax
   50         call    _exit                   ! exit(main(argc, argv))
   51 
   52 ! int creat(const char *path, mode_t mode)
   53 !       Create a file with the old creat() call.
   54 .define _creat
   55 _creat:
   56         mov     bx, sp
   57         mov     dx, 2(bx)               ! Filename
   58         xor     cx, cx                  ! Ignore mode, always read-write
   59         movb    ah, 0x3C                ! "CREAT"
   60 dos:    int     0x21                    ! ax = creat(path, 0666);
   61         jc      seterrno
   62         ret
   63 
   64 seterrno:
   65         mov     (_errno), ax            ! Set errno to the DOS error code
   66         mov     ax, -1
   67         cwd                             ! return -1L;
   68         ret
   69 
   70 ! int open(const char *path, int oflag)
   71 !       Open a file with the oldfashioned two-argument open() call.
   72 .define _open
   73 _open:
   74         mov     bx, sp
   75         mov     dx, 2(bx)               ! Filename
   76         movb    al, 4(bx)               ! O_RDONLY, O_WRONLY, O_RDWR
   77         movb    ah, 0x3D                ! "OPEN"
   78         jmp     dos
   79 
   80 ! int close(int fd)
   81 !       Close an open file.
   82 .define _close
   83 _close:
   84         mov     bx, sp
   85         mov     bx, 2(bx)               ! bx = file handle
   86         movb    ah, 0x3E                ! "CLOSE"
   87         jmp     dos
   88 
   89 ! void exit(int status)
   90 ! void _exit(int status)
   91 !       Return to DOS.
   92 .define _exit, __exit, ___exit
   93 _exit:
   94 __exit:
   95 ___exit:
   96         pop     ax
   97         pop     ax                      ! al = status
   98         movb    ah, 0x4C                ! "EXIT"
   99         int     0x21
  100         hlt
  101 
  102 ! ssize_t read(int fd, void *buf, size_t n)
  103 !       Read bytes from an open file.
  104 .define _read
  105 _read:
  106         mov     bx, sp
  107         mov     cx, 6(bx)
  108         mov     dx, 4(bx)
  109         mov     bx, 2(bx)
  110         movb    ah, 0x3F                ! "READ"
  111         jmp     dos
  112 
  113 ! ssize_t write(int fd, const void *buf, size_t n)
  114 !       Write bytes to an open file.
  115 .define _write
  116 _write:
  117         mov     bx, sp
  118         mov     cx, 6(bx)
  119         mov     dx, 4(bx)
  120         mov     bx, 2(bx)
  121         movb    ah, 0x40                ! "WRITE"
  122         jmp     dos
  123 
  124 ! off_t lseek(int fd, off_t offset, int whence)
  125 !       Set file position for read or write.
  126 .define _lseek
  127 _lseek:
  128         mov     bx, sp
  129         movb    al, 8(bx)               ! SEEK_SET, SEEK_CUR, SEEK_END
  130         mov     dx, 4(bx)
  131         mov     cx, 6(bx)               ! cx:dx = offset
  132         mov     bx, 2(bx)
  133         movb    ah, 0x42                ! "LSEEK"
  134         jmp     dos
  135 
  136 !
  137 ! $PchId: mkfhead.ack.s,v 1.3 1999/01/14 21:17:06 philip Exp $

Cache object: 19ee19f6f9779a0e22a25cdd8bc0c099


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.