Path: tut!enea!mcvax!seismo!uunet!pilchuck!amc!ipmoea!ericr
From: ericr@ipmoea.UUCP (Eric Roskos)
Newsgroups: comp.os.minix
Subject: Changes to Compile Minix with MSC (tools changes: 5 of 12)
Message-ID: <27@ipmoea.UUCP>
Date: 21 Aug 87 05:37:35 GMT
Reply-To: ericr@ipmoea.UUCP (Eric Roskos)
Organization: Redmond, WA
Lines: 1333

Directory: /usr2/ericr/minix/minix/tools

------------------------------------------------------------
*** ar.c	Sat Aug  1 13:37:47 1987
--- ../../dos/tools/ar.c	Sat Aug  1 13:32:37 1987
***************
*** 11,17
   *	  p: print named files
   */
  
! #include "stat.h"
  #include "signal.h"
  
  #define MAGIC_NUMBER	0177545

--- 11,19 -----
   *	  p: print named files
   */
  
! #include "sys/types.h"
! #include "sys/stat.h"
! #include "fcntl.h"
  #include "signal.h"
  
  #define MAGIC_NUMBER	0177545
***************
*** 52,58
  #define NIL_MEM		((MEMBER *) 0)
  #define NIL_LONG	((long *) 0)
  
! #define IO_SIZE		(10 * 1024)
  #define BLOCK_SIZE	1024
  
  #define flush()		print(NIL_PTR)

--- 54,60 -----
  #define NIL_MEM		((MEMBER *) 0)
  #define NIL_LONG	((long *) 0)
  
! #define IO_SIZE		(4 * 1024)
  #define BLOCK_SIZE	1024
  
  #define flush()		print(NIL_PTR)
***************
*** 84,89
  BOOL quit;
  char *str1, *str2;
  {
    write(2, str1, strlen(str1));
    if (str2 != NIL_PTR)
  	write(2, str2, strlen(str2));

--- 86,92 -----
  BOOL quit;
  char *str1, *str2;
  {
+   perror("ar");
    write(2, str1, strlen(str1));
    if (str2 != NIL_PTR)
  	write(2, str2, strlen(str2));
***************
*** 129,135
  	return fd;
    }
  
!   if ((fd = open(name, mode)) < 0) {
  	if (mode == APPEND) {
  		(void) close(open_archive(name, CREATE));
  		error(FALSE, "ar: creating ", name);

--- 132,138 -----
  	return fd;
    }
  
!   if ((fd = open(name, mode|O_BINARY)) < 0) {
  	if (mode == APPEND) {
  		(void) close(open_archive(name, CREATE|O_BINARY));
  		error(FALSE, "ar: creating ", name);
***************
*** 131,137
  
    if ((fd = open(name, mode)) < 0) {
  	if (mode == APPEND) {
! 		(void) close(open_archive(name, CREATE));
  		error(FALSE, "ar: creating ", name);
  		return open_archive(name, APPEND);
  	}

--- 134,140 -----
  
    if ((fd = open(name, mode|O_BINARY)) < 0) {
  	if (mode == APPEND) {
! 		(void) close(open_archive(name, CREATE|O_BINARY));
  		error(FALSE, "ar: creating ", name);
  		return open_archive(name, APPEND|O_BINARY);
  	}
***************
*** 133,139
  	if (mode == APPEND) {
  		(void) close(open_archive(name, CREATE));
  		error(FALSE, "ar: creating ", name);
! 		return open_archive(name, APPEND);
  	}
  	error(TRUE, "Cannot open ", name);
    }

--- 136,142 -----
  	if (mode == APPEND) {
  		(void) close(open_archive(name, CREATE|O_BINARY));
  		error(FALSE, "ar: creating ", name);
! 		return open_archive(name, APPEND|O_BINARY);
  	}
  	error(TRUE, "Cannot open ", name);
    }
***************
*** 437,446
  	mode_buf[i * 3 + 2] = (tmp & S_IEXEC) ? 'x' : '-';
  	tmp <<= 3;
    }
-   if (mode & S_ISUID)
- 	mode_buf[2] = 's';
-   if (mode & S_ISGID)
- 	mode_buf[5] = 's';
    print(mode_buf);
  }
  

--- 440,445 -----
  	mode_buf[i * 3 + 2] = (tmp & S_IEXEC) ? 'x' : '-';
  	tmp <<= 3;
    }
    print(mode_buf);
  }
  
------------------------------------------------------------
*** build.c	Sat Aug  1 13:37:43 1987
--- ../../dos/tools/build.c	Sat Aug  1 13:32:32 1987
***************
*** 1,3
  /* This program takes the previously compiled and linked pieces of the
   * operating system, and puts them together to build a boot diskette.
   * The files are read and put on the boot diskette in this order:

--- 1,5 -----
+ #define C_DISKIO	/* use JER's diskio for MSC */
+ 
  /* This program takes the previously compiled and linked pieces of the
   * operating system, and puts them together to build a boot diskette.
   * The files are read and put on the boot diskette in this order:
***************
*** 41,46
   * to get the resulting image onto the file "image".
   */
  
  
  #define PROGRAMS 5              /* kernel + mm + fs + init + fsck = 5 */
  #define PROG_ORG 1536           /* where does kernel begin in abs mem */

--- 43,53 -----
   * to get the resulting image onto the file "image".
   */
  
+ #ifdef MSDOS
+ #include <stdio.h>
+ #include <fcntl.h>
+ #include <dos.h>
+ #endif
  
  #define PROGRAMS 5              /* kernel + mm + fs + init + fsck = 5 */
  #define PROG_ORG 1536           /* where does kernel begin in abs mem */
***************
*** 67,73
  #define SEP_ID_BIT 0x20         /* bit that tells if file is separate I & D */
  
  #ifdef MSDOS
! # define BREAD 4                /* value 0 means ASCII read */
  #else
  # define BREAD 0
  #endif

--- 74,80 -----
  #define SEP_ID_BIT 0x20         /* bit that tells if file is separate I & D */
  
  #ifdef MSDOS
! # define BREAD (O_RDONLY|O_BINARY)                /* value 0 means ASCII read */
  #else
  error - not tested for non-dos with this version
  # define BREAD 0
***************
*** 69,74
  #ifdef MSDOS
  # define BREAD 4                /* value 0 means ASCII read */
  #else
  # define BREAD 0
  #endif
  

--- 76,82 -----
  #ifdef MSDOS
  # define BREAD (O_RDONLY|O_BINARY)                /* value 0 means ASCII read */
  #else
+ error - not tested for non-dos with this version
  # define BREAD 0
  #endif
  
***************
*** 114,121
    printf("Operating system size  %29ld     %5lx\n", cum_size, cum_size);
    printf("\nTotal size including fsck is %ld.\n", all_size);
  #else
!   printf("Operating system size  %29D     %5X\n", cum_size, cum_size);
!   printf("\nTotal size including fsck is %D.\n", all_size);
  #endif
  
    /* Make the three patches to the output file or diskette. */

--- 122,129 -----
    printf("Operating system size  %29ld     %5lx\n", cum_size, cum_size);
    printf("\nTotal size including fsck is %ld.\n", all_size);
  #else
!   printf("Operating system size  %29ld     %5lx\n", cum_size, cum_size);
!   printf("\nTotal size including fsck is %ld.\n", all_size);
  #endif
  
    /* Make the three patches to the output file or diskette. */
***************
*** 166,172
    unsigned text_bytes, data_bytes, bss_bytes, tot_bytes, rest, filler;
    unsigned left_to_read;
    char inbuf[READ_UNIT];
!   
    if ( (fd = open(file_name, BREAD)) < 0) pexit("can't open ", file_name);
  
    /* Read the header to see how big the segments are. */

--- 174,180 -----
    unsigned text_bytes, data_bytes, bss_bytes, tot_bytes, rest, filler;
    unsigned left_to_read;
    char inbuf[READ_UNIT];
! 
    if ( (fd = open(file_name, BREAD)) < 0) pexit("can't open ", file_name);
  
    /* Read the header to see how big the segments are. */
***************
*** 192,198
    sizes[num].sep_id    = sepid;
  
    /* Print a message giving the program name and size, except for fsck. */
!   if (num < FSCK) { 
          printf("%s  text=%5u  data=%5u  bss=%5u  tot=%5u  hex=%4x  %s\n",
                  name[num], text_bytes, data_bytes, bss_bytes, tot_bytes,
                  tot_bytes, (sizes[num].sep_id ? "Separate I & D" : ""));

--- 200,207 -----
    sizes[num].sep_id    = sepid;
  
    /* Print a message giving the program name and size, except for fsck. */
!   if (num < FSCK) 
!   { 
          printf("%s  text=%5u  data=%5u  bss=%5u  tot=%5u  hex=%4x  %s\n",
                  name[num], text_bytes, data_bytes, bss_bytes, tot_bytes,
                  tot_bytes, (sizes[num].sep_id ? "Separate I & D" : ""));
***************
*** 374,379
    data_offset = 512L + (long)sizes[KERN].text_size;    /* start of kernel data */
    i = (get_byte(data_offset+1L) << 8) + get_byte(data_offset);
    if (i != KERNEL_D_MAGIC)  {
  	pexit("kernel data space: no magic #","");
    }
    

--- 383,389 -----
    data_offset = 512L + (long)sizes[KERN].text_size;    /* start of kernel data */
    i = (get_byte(data_offset+1L) << 8) + get_byte(data_offset);
    if (i != KERNEL_D_MAGIC)  {
+ 	printf("Magic number in kernel is %x: should be %x\n",i,KERNEL_D_MAGIC);
  	pexit("kernel data space: no magic #","");
    }
    
***************
*** 399,404
          ds = PROG_ORG >> CLICK_SHIFT;   /* combined I & D space */
    else
          ds = (PROG_ORG + sizes[KERN].text_size) >> CLICK_SHIFT; /* separate */
    put_byte(512L + DS_OFFSET, ds & 0377);
    put_byte(512L + DS_OFFSET + 1L, (ds>>8) & 0377);
  }

--- 409,415 -----
          ds = PROG_ORG >> CLICK_SHIFT;   /* combined I & D space */
    else
          ds = (PROG_ORG + sizes[KERN].text_size) >> CLICK_SHIFT; /* separate */
+   printf("Kernel DS = %x\n", ds);
    put_byte(512L + DS_OFFSET, ds & 0377);
    put_byte(512L + DS_OFFSET + 1L, (ds>>8) & 0377);
  }
***************
*** 546,551
       buff = buff1;
  }
  
  
  read_block (blocknr,user)
  int blocknr;

--- 557,563 -----
       buff = buff1;
  }
  
+ #ifdef C_DISKIO
  
  int DMAoverrun(buff1)
  char *buff1;
***************
*** 547,552
  }
  
  
  read_block (blocknr,user)
  int blocknr;
  char user[SECTOR_SIZE];

--- 559,626 -----
  
  #ifdef C_DISKIO
  
+ int DMAoverrun(buff1)
+ char *buff1;
+ {
+ int i;
+ 
+ 	i = (int)buff1;
+ 	return(i > i + SECTOR_SIZE);
+ }
+ 
+ int
+ absio(fn, drive, blocknr, buff)
+ int fn;
+ int drive;
+ int blocknr;
+ char *buff;
+ {
+ union REGS iregs;
+ union REGS oregs;
+ int track;
+ 
+ 	iregs.h.ah = fn;
+ 	iregs.h.dl = drive;
+ 	track = blocknr / 9;
+ 	iregs.h.dh = track & 1;
+ 	iregs.h.ch = track >> 1;
+ 	iregs.h.cl = (blocknr % 9) + 1;
+ 	iregs.h.al = 1;
+ 	iregs.x.bx = (int)buff;
+ 
+ 	int86(0x13, &iregs, &oregs);
+ 
+ 	if (oregs.x.cflag)
+ 	{
+ 		fprintf(stderr, "absio: error %sing drv %c block %d address %x: bios code %x\n",
+ 			fn==2? "read" : "writ", 'A'+drive, blocknr, buff, oregs.h.ah&0xff);
+ 		return(oregs.x.ax);
+ 	}
+ 	else
+ 	{
+ 		return(0);
+ 	}
+ }
+ 
+ int
+ absread(drive, blocknr, buff)
+ int drive;
+ int blocknr;
+ char *buff;
+ {
+ 	return(absio(2, drive, blocknr, buff));
+ }
+ 
+ int
+ abswrite(drive, blocknr, buff)
+ int drive;
+ int blocknr;
+ char *buff;
+ {
+ 	return(absio(3, drive, blocknr, buff));
+ }
+ #endif
+ 
  read_block (blocknr,user)
  int blocknr;
  char user[SECTOR_SIZE];
***************
*** 609,615
    drive = (s[0] & ~32) - 'A';
    if (drive<0 || drive>32) pexit ("no such drive: ",s);
    printf("Put a blank, formatted diskette in drive %s\nHit return when ready",s);
!   gets (kbstr,10);
    puts("");
  }
  

--- 683,689 -----
    drive = (s[0] & ~32) - 'A';
    if (drive<0 || drive>32) pexit ("no such drive: ",s);
    printf("Put a blank, formatted diskette in drive %s\nHit return when ready",s);
!   gets(kbstr);
    puts("");
  }
  
------------------------------------------------------------
*** dos2out.c	Sat Aug  1 13:37:45 1987
--- ../../dos/tools/dos2out.c	Sat Aug  1 13:32:34 1987
***************
*** 97,103
  #define A_WLR(cputype)	((cputype&0x02)!=0)  /* TRUE if words left-to-right */
  
  
! #include "/lib/C86/stdio.h"
  
  
  #define PH_SECTSIZE	512		/* size of a disk-block */

--- 97,104 -----
  #define A_WLR(cputype)	((cputype&0x02)!=0)  /* TRUE if words left-to-right */
  
  
! #include <stdio.h>
! #include <fcntl.h>
  
  
  #define PH_SECTSIZE	512		/* size of a disk-block */
***************
*** 109,116
  unsigned char inbuf2[PH_SECTSIZE];
  unsigned char outbuf[PH_SECTSIZE];
  
! struct a_out_hdr *a_ptr= outbuf;
! struct d_fmt_hdr *d_ptr= inbuf;
  
  
  main (argc,argv)

--- 110,117 -----
  unsigned char inbuf2[PH_SECTSIZE];
  unsigned char outbuf[PH_SECTSIZE];
  
! struct a_out_hdr *a_ptr= (struct a_out_hdr *)outbuf;
! struct d_fmt_hdr *d_ptr= (struct d_fmt_hdr *)inbuf;
  
  
  main (argc,argv)
***************
*** 177,183
      } /* end switch */
  
      /* open & create files */
!     if ((inf=open(in_name,BREAD)) <0) {
         printf ("input file %s not found\n",in_name);
         exit(2);
      }

--- 178,184 -----
      } /* end switch */
  
      /* open & create files */
!     if ((inf=open(in_name,O_RDONLY|O_BINARY)) <0) {
         printf ("input file %s not found\n",in_name);
         exit(2);
      }
***************
*** 207,213
  
  
      /* input file is ok, open output (possibly destroy existing file) */
!     if ((outf=creat(out_name,BWRITE)) <0) {
  	printf ("cannot open output %s\n",out_name);
  	exit(2);
      }

--- 208,214 -----
  
  
      /* input file is ok, open output (possibly destroy existing file) */
!     if ((outf=open(out_name,O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,0666)) <0) {
  	printf ("cannot open output %s\n",out_name);
  	exit(2);
      }
***************
*** 237,243
  
      /* reposition file */
      close (inf);
!     inf=open(in_name,BREAD);
      in_cnt=read(inf,inbuf2,PH_SECTSIZE);
  
      /* make a.out header */

--- 238,244 -----
  
      /* reposition file */
      close (inf);
!     inf=open(in_name,O_RDONLY|O_BINARY);
      in_cnt=read(inf,inbuf2,PH_SECTSIZE);
  
      /* make a.out header */
***************
*** 301,306
      close (inf);
      if (delete) unlink (in_name);
      printf("   -done-\n");
  }
  
  

--- 302,308 -----
      close (inf);
      if (delete) unlink (in_name);
      printf("   -done-\n");
+ 	exit(0);
  }
  
  
------------------------------------------------------------
*** fsck.c	Sat Aug  1 13:38:01 1987
--- ../../dos/tools/fsck.c	Sat Aug  1 13:32:45 1987
***************
*** 87,92
  #define isupper(c)	between(c, 'A', 'Z')
  #define toupper(c)	( (c) + 'A' - 'a' )
  
  #define quote(x)	x
  #define nextarg(t)	(*argp.quote(u_)t++)
  

--- 87,93 -----
  #define isupper(c)	between(c, 'A', 'Z')
  #define toupper(c)	( (c) + 'A' - 'a' )
  
+ #ifndef MSDOS	/* actually, if not ANSI C */
  #define quote(x)	x
  #define nextarg(t)	(*argp.quote(u_)t++)
  #else
***************
*** 89,94
  
  #define quote(x)	x
  #define nextarg(t)	(*argp.quote(u_)t++)
  
  #define prn(t,b,s)	{ printnum((long)nextarg(t),b,s,width,pad); width = 0; }
  #define prc(c)		{ width -= printchar(c, mode); }

--- 90,98 -----
  #ifndef MSDOS	/* actually, if not ANSI C */
  #define quote(x)	x
  #define nextarg(t)	(*argp.quote(u_)t++)
+ #else
+ #define nextarg(t)	(*argp.u_##t++)
+ #endif
  
  #define prn(t,b,s)	{ printnum((long)nextarg(t),b,s,width,pad); width = 0; }
  #define prc(c)		{ width -= printchar(c, mode); }
***************
*** 180,186
  
  #ifdef STANDALONE
  extern end;			/* last variable */
! int *brk;			/* the ``break'' (end of data space) */
  #else
  int dev;			/* file descriptor of the device */
  #endif

--- 184,190 -----
  
  #ifdef STANDALONE
  extern end;			/* last variable */
! int *brksa;			/* the ``break'' (end of data space) */
  #else
  int dev;			/* file descriptor of the device */
  #endif
***************
*** 361,367
  	register level;
  
  #ifdef STANDALONE
! 	  brk = &end;
  #endif
  	nregular = ndirectory = nblkspec = ncharspec = nbadinode = 0;
  	for (level = 0; level < NLEVEL; level++)

--- 365,371 -----
  	register level;
  
  #ifdef STANDALONE
! 	  brksa = &end;
  #endif
  	nregular = ndirectory = nblkspec = ncharspec = nbadinode = 0;
  	for (level = 0; level < NLEVEL; level++)
***************
*** 478,486
  #ifdef STANDALONE
  	register *r;
  	
! 	p = (char *) brk;
! 	brk += nelem * ((elsize + sizeof(int) - 1) / sizeof(int));
! 	for (r = (int *) p; r < brk; r++)
  		*r = 0;
  	return(p);
  #else

--- 482,490 -----
  #ifdef STANDALONE
  	register *r;
  	
! 	p = (char *) brksa;
! 	brksa += nelem * ((elsize + sizeof(int) - 1) / sizeof(int));
! 	for (r = (int *) p; r < brksa; r++)
  		*r = 0;
  	return(p);
  #else
***************
*** 1832,1838
  	printf("\n\n\n\n");
  	for (;;) {
  		printf("\nHit key as follows:\n\n");
! 		printf("    =  start MINIX (root file system in drive 0)\n");
  		printf("    f  check the file system (first insert any file system diskette)\n");
  		printf("    l  check and list file system (first insert any file system diskette)\n");
  		printf("    m  make an (empty) file system (first insert blank, formatted diskette)\n");

--- 1836,1843 -----
  	printf("\n\n\n\n");
  	for (;;) {
  		printf("\nHit key as follows:\n\n");
! 		printf("    =  start MINIX (root file system in floppy drive 0)\n");
! 		printf("[1-9]  start MINIX (root file system on /dev/hd[1-9]\n");
  		printf("    f  check the file system (first insert any file system diskette)\n");
  		printf("    l  check and list file system (first insert any file system diskette)\n");
  		printf("    m  make an (empty) file system (first insert blank, formatted diskette)\n");
***************
*** 1881,1887
  			}
  			break;
  			
! 		case '=': return((c >> 8) & 0xFF);
  		default:
  			printf("Illegal command\n");
  			continue;

--- 1886,1902 -----
  			}
  			break;
  			
! 		case '=': 	/* boot from floppy 0 */
! 		case '1':	/* boot from a hard disk partition */
! 		case '2':	/* partitions 0 and 5 are raw and thus */
! 		case '3':	/* are not included in this list. */
! 		case '4':	/* Added 7/29/87 Eric Roskos (JER) */
! 		case '6':
! 		case '7':
! 		case '8':
! 		case '9':
! 			return((c >> 8) & 0xFF);
! 
  		default:
  			printf("Illegal command\n");
  			continue;
------------------------------------------------------------
*** fsck1.asm	Sat Aug  1 13:38:03 1987
--- ../../dos/tools/fsck1.asm	Sat Aug  1 13:32:50 1987
***************
*** 1,7
  title  fsck1  -  additional stuff for fsck
  page,132
  
- 
  INCLUDE ..\lib\prologue.h      
  
  

--- 1,6 -----
  title  fsck1  -  additional stuff for fsck
  page,132
  
  INCLUDE ..\lib\prologue.h      
  
  
***************
*** 10,18
  XTSECTORS  EQU  17
  XTCYLS     EQU  68
  IFDEF STANDALONE
!   PUBLIC $main, @end, edata, exit, kerstack,_prt
!   EXTRN  main:near
!  ;EXTRN  cinit:near, debug:near
  ENDIF
  PUBLIC reset_di, diskio, getc, putc, dmaoverr
  EXTRN cylsiz:word, tracksiz:word, drive:byte

--- 9,17 -----
  XTSECTORS  EQU  17
  XTCYLS     EQU  68
  IFDEF STANDALONE
!   PUBLIC $main, _end, _edata, _exit, _kerstack, _prt
!   EXTRN  _main:near
!  ;EXTRN  _cinit:near, _debug:near
  ENDIF
  PUBLIC _reset_diskette, _diskio, _getc, _putc, _dmaoverrun
  EXTRN _cylsiz:word, _tracksiz:word, _drive:byte
***************
*** 14,21
    EXTRN  main:near
   ;EXTRN  cinit:near, debug:near
  ENDIF
! PUBLIC reset_di, diskio, getc, putc, dmaoverr
! EXTRN cylsiz:word, tracksiz:word, drive:byte
  
  
  ;---------------------------------------+

--- 13,20 -----
    EXTRN  _main:near
   ;EXTRN  _cinit:near, _debug:near
  ENDIF
! PUBLIC _reset_diskette, _diskio, _getc, _putc, _dmaoverrun
! EXTRN _cylsiz:word, _tracksiz:word, _drive:byte
  
  PUBLIC __acrtused
  __acrtused	EQU	9876H
***************
*** 17,22
  PUBLIC reset_di, diskio, getc, putc, dmaoverr
  EXTRN cylsiz:word, tracksiz:word, drive:byte
  
  
  ;---------------------------------------+
  ;               Code                    |

--- 16,23 -----
  PUBLIC _reset_diskette, _diskio, _getc, _putc, _dmaoverrun
  EXTRN _cylsiz:word, _tracksiz:word, _drive:byte
  
+ PUBLIC __acrtused
+ __acrtused	EQU	9876H
  
  ;-------------------------------------------+
  ; DATA - JER - moved here from before stack |
***************
*** 18,23
  EXTRN cylsiz:word, tracksiz:word, drive:byte
  
  
  ;---------------------------------------+
  ;               Code                    |
  ;---------------------------------------+

--- 19,38 -----
  PUBLIC __acrtused
  __acrtused	EQU	9876H
  
+ ;-------------------------------------------+
+ ; DATA - JER - moved here from before stack |
+ ;-------------------------------------------+
+ 
+ _DATA	SEGMENT
+ magic	DW	0ABCDH
+ tmp	DW 0
+ tmp1	DW 0
+ tmp2	DW 0
+ fsckmsg DB "arrived at fsck1",0
+ _DATA	ENDS
+ 
+ 
+ IFDEF STANDALONE
  ;---------------------------------------+
  ;  Set up memory lay-out for standalone |
  ;---------------------------------------+
***************
*** 19,25
  
  
  ;---------------------------------------+
! ;               Code                    |
  ;---------------------------------------+
  ;
  @CODE   SEGMENT

--- 34,70 -----
  
  IFDEF STANDALONE
  ;---------------------------------------+
! ;  Set up memory lay-out for standalone |
! ;---------------------------------------+
! ;
! STACKSIZE EQU 8192
! 
! _DATA	SEGMENT
! _brksa	DW	?
! _DATA	ENDS
! 
! LOWCORE SEGMENT AT 0            ; tell where BIOS-data etc is
! 	ORG 120
! dskbase label word
! LOWCORE ENDS
! 
! MINIX	SEGMENT AT 60h          ; This is where Minix is loaded
! _kernel  label byte		; absolute address 0000:1536d = 0060:0000h
! MINIX	ENDS
! 
! _DATAT  SEGMENT			; DATAT holds nothing. The label tells us
! _edata   label byte              ; where .data ends.
! _DATAT  ENDS
! 
! _DATAU   SEGMENT		; allocate the stack in .bss
! _kerstack DB STACKSIZE dup(?)
! _DATAU   ENDS
! 
! _DATAV  SEGMENT			; DATAV holds nothing. The label tells us
! _end    label byte              ; where .data+.bss ends (first free memory)
! _DATAV  ENDS
! 
! 
  ;---------------------------------------+
  ;               Code                    |
  ;---------------------------------------+
***************
*** 21,26
  ;---------------------------------------+
  ;               Code                    |
  ;---------------------------------------+
  ;
  @CODE   SEGMENT
          assume  cs:@code,ds:dgroup

--- 66,73 -----
  
  
  ;---------------------------------------+
+ ;               Code                    |
+ ;---------------------------------------+
  ;
  _TEXT   SEGMENT
          assume  cs:_text,ds:dgroup
***************
*** 22,29
  ;               Code                    |
  ;---------------------------------------+
  ;
! @CODE   SEGMENT
!         assume  cs:@code,ds:dgroup
  
  IFDEF   STANDALONE
  $main:

--- 69,76 -----
  ;               Code                    |
  ;---------------------------------------+
  ;
! _TEXT   SEGMENT
!         assume  cs:_text,ds:dgroup
  
  IFDEF   STANDALONE
  $main:
***************
*** 29,36
  $main:
  	mov	dx,bx		; bootblok puts # sectors/track in bx
  	xor	ax,ax
!         mov     bx,offset dgroup:edata          ; prepare to clear bss
!         mov     cx,offset dgroup:@end
  	sub	cx,bx
  	sar	cx,1
      st1:mov	[bx],ax		; clear bss

--- 76,83 -----
  $main:
  	mov	dx,bx		; bootblok puts # sectors/track in bx
  	xor	ax,ax
!         mov     bx,offset dgroup:_edata          ; prepare to clear bss
!         mov     cx,offset dgroup:_end
  	sub	cx,bx
  	sar	cx,1
  st1: mov	[bx],ax		; clear bss
***************
*** 33,39
          mov     cx,offset dgroup:@end
  	sub	cx,bx
  	sar	cx,1
!     st1:mov	[bx],ax		; clear bss
  	add	bx,2
  	loop	st1
  

--- 80,86 -----
          mov     cx,offset dgroup:_end
  	sub	cx,bx
  	sar	cx,1
! st1: mov	[bx],ax		; clear bss
  	add	bx,2
  	loop	st1
  
***************
*** 37,43
  	add	bx,2
  	loop	st1
  
! 	mov	dgroup:tracksiz,dx	; dx (was bx) is # sectors/track
  	add	dx,dx
  	mov	dgroup:cylsiz,dx	; # sectors/cylinder
  	mov	sp,offset dgroup:kerstack+STACKSIZE

--- 84,90 -----
  	add	bx,2
  	loop	st1
  
! 	mov	dgroup:_tracksiz,dx	; dx (was bx) is # sectors/track
  	add	dx,dx
  	mov	dgroup:_cylsiz,dx	; # sectors/cylinder
  	mov	sp,offset dgroup:_kerstack+STACKSIZE
***************
*** 39,46
  
  	mov	dgroup:tracksiz,dx	; dx (was bx) is # sectors/track
  	add	dx,dx
! 	mov	dgroup:cylsiz,dx	; # sectors/cylinder
! 	mov	sp,offset dgroup:kerstack+STACKSIZE
  	
  ;	call	cinit
  ;	mov	ax,offset fsckmsg

--- 86,93 -----
  
  	mov	dgroup:_tracksiz,dx	; dx (was bx) is # sectors/track
  	add	dx,dx
! 	mov	dgroup:_cylsiz,dx	; # sectors/cylinder
! 	mov	sp,offset dgroup:_kerstack+STACKSIZE
  	
  
  ;	call	cinit
***************
*** 42,47
  	mov	dgroup:cylsiz,dx	; # sectors/cylinder
  	mov	sp,offset dgroup:kerstack+STACKSIZE
  	
  ;	call	cinit
  ;	mov	ax,offset fsckmsg
  ;	push	ax

--- 89,95 -----
  	mov	dgroup:_cylsiz,dx	; # sectors/cylinder
  	mov	sp,offset dgroup:_kerstack+STACKSIZE
  	
+ 
  ;	call	cinit
  ;	mov	ax,offset fsckmsg
  ;	push	ax
***************
*** 47,54
  ;	push	ax
  ;	call	debug
  ;	pop	ax
! 	
! 	call	main
  	mov	bx,ax		; put scan code for '=' in bx
  	cli
  	mov	dx,60h

--- 95,103 -----
  ;	push	ax
  ;	call	debug
  ;	pop	ax
! 
! 	call	_main
! 
  	mov	bx,ax		; put scan code for '=' in bx
  
  	ifdef	debug
***************
*** 50,55
  	
  	call	main
  	mov	bx,ax		; put scan code for '=' in bx
  	cli
  	mov	dx,60h
  	mov	ds,dx

--- 99,113 -----
  	call	_main
  
  	mov	bx,ax		; put scan code for '=' in bx
+ 
+ 	ifdef	debug
+ 	mov	ax,60H
+ 	mov	es,ax
+ 	mov	ax,word ptr es:4
+ 	call 	prtax
+ 	wto	'= DS word at kernel entry point'
+ 	endif
+ 
  	cli
  	mov	dx,60h
  	mov	ds,dx
***************
*** 55,61
  	mov	ds,dx
  	mov	es,dx
  	mov	ss,dx
!         jmp     far ptr kernel		; direct jmp to kernel & start Minix
          mov     ax,DGROUP               ; Force DOS-relocation (sep I&D)
  
  exit:	mov	bx,dgroup:tracksiz

--- 113,121 -----
  	mov	ds,dx
  	mov	es,dx
  	mov	ss,dx
! 
! 
!         jmp     far ptr _kernel		; direct jmp to kernel & start Minix
          mov     ax,DGROUP               ; Force DOS-relocation (sep I&D)
  
  _exit:	mov	bx,dgroup:_tracksiz
***************
*** 58,64
          jmp     far ptr kernel		; direct jmp to kernel & start Minix
          mov     ax,DGROUP               ; Force DOS-relocation (sep I&D)
  
! exit:	mov	bx,dgroup:tracksiz
  	jmp	$main
  
  

--- 118,124 -----
          jmp     far ptr _kernel		; direct jmp to kernel & start Minix
          mov     ax,DGROUP               ; Force DOS-relocation (sep I&D)
  
! _exit:	mov	bx,dgroup:_tracksiz
  	jmp	$main
  
  
***************
*** 85,90
          int     10h             ; call BIOS VIDEO_IO
          pop     bx              ; restore bx
          jmp     print           ; next character
      
  ENDIF   ; /* STANDALONE */
  

--- 145,210 -----
          int     10h             ; call BIOS VIDEO_IO
          pop     bx              ; restore bx
          jmp     print           ; next character
+ 
+ ;
+ ;	code for debug messages
+ ;
+ 	ifdef	debug
+ ;
+ ; prtnum - print low-order 4 bits of al register in hex
+ ;
+ 
+ prtnum	proc	near
+ 	push	ds
+ 	push	cs
+ 	pop	ds
+ 	push	bx
+ 	mov	bx,offset xltab
+ 	xlatb
+ 	mov	ah,14
+ 	mov	bh,10
+ 	int	10H
+ 	pop	bx
+ 	pop	ds
+ 	ret
+ 
+ xltab	db	'0123456789ABCDEF '
+ prtnum	endp
+ 
+ ;
+ ; prtax - print ax register's contents in hex
+ ;
+ 
+ prtax	proc	near
+ 	push	cx
+ 	push	ax
+ 	mov	al,ah
+ 	mov	cl,4
+ 	shr	al,cl
+ 	call	prtnum
+ 	pop	ax
+ 	push	ax
+ 	mov	al,ah
+ 	and	al,0fH
+ 	call	prtnum
+ 	pop	ax
+ 	push	ax
+ 	mov	cl,4
+ 	shr	al,cl
+ 	call	prtnum
+ 	pop	ax
+ 	push	ax
+ 	and	al,0fH
+ 	call	prtnum
+ 	mov	al,10H		; special value to print a space
+ 	call	prtnum
+ 	pop	ax
+ 	pop	cx
+ 	ret
+ 
+ prtax	endp
+ 
+ 	endif
      
  ENDIF   ; /* STANDALONE */
  
***************
*** 89,95
  ENDIF   ; /* STANDALONE */
  
  
! putc:
          xor     ax,ax
          call    csv
          mov     al,4[bp]        ; al contains char to be printed

--- 209,215 -----
  ENDIF   ; /* STANDALONE */
  
  
! _putc:
          xor     ax,ax
          call    csv
          mov     al,4[bp]        ; al contains char to be printed
***************
*** 100,106
          pop     bp
          jmp     cret
  
! getc:
          xor     ah,ah
          int     16h
          ret

--- 220,226 -----
          pop     bp
          jmp     cret
  
! _getc:
          xor     ah,ah
          int     16h
          ret
***************
*** 105,111
          int     16h
          ret
  
! reset_di:                       ; reset_diskette
          xor     ax,ax
          call    csv
          push    es              ; not preserved

--- 225,231 -----
          int     16h
          ret
  
! _reset_diskette:                       ; reset_diskette
          xor     ax,ax
          call    csv
          push    es              ; not preserved
***************
*** 115,121
  
  ; handle diskio(RW, sector_number, buffer, sector_count) call
  ; Do not issue a BIOS call that crosses a track boundary
! diskio:
  	xor	ax,ax
  	call	csv
  	mov	tmp1,0		; tmp1 = # sectors actually transferred

--- 235,241 -----
  
  ; handle diskio(RW, sector_number, buffer, sector_count) call
  ; Do not issue a BIOS call that crosses a track boundary
! _diskio:
  	xor	ax,ax
  	call	csv
  	mov	tmp1,0		; tmp1 = # sectors actually transferred
***************
*** 123,129
  	mov	tmp2,di		; di = # sectors to transfer
  d0:	mov	ax,6[bp]	; ax = sector number to start at
  	xor	dx,dx		; dx:ax is dividend
! 	div	dgroup:cylsiz	; ax = cylinder, dx = sector within cylinder
  	mov	cl,ah		; cl = hi-order bits of cylinder
  	ror	cl,1		; BIOS expects hi bits in a funny place
  	ror	cl,1		; ditto

--- 243,249 -----
  	mov	tmp2,di		; di = # sectors to transfer
  d0:	mov	ax,6[bp]	; ax = sector number to start at
  	xor	dx,dx		; dx:ax is dividend
! 	div	dgroup:_cylsiz	; ax = cylinder, dx = sector within cylinder
  	mov	cl,ah		; cl = hi-order bits of cylinder
  	ror	cl,1		; BIOS expects hi bits in a funny place
  	ror	cl,1		; ditto
***************
*** 130,136
  	mov	ch,al		; cx = sector # in BIOS format
  	mov	ax,dx		; ax = sector offset within cylinder
  	xor	dx,dx		; dx:ax is dividend
! 	div	dgroup:tracksiz	; ax = head, dx = sector
  	mov	dh,al		; dh = head
  	or	cl,dl		; cl = 2 high-order cyl bits || sector
  	inc	cl		; BIOS counts sectors starting at 1

--- 250,256 -----
  	mov	ch,al		; cx = sector # in BIOS format
  	mov	ax,dx		; ax = sector offset within cylinder
  	xor	dx,dx		; dx:ax is dividend
! 	div	dgroup:_tracksiz	; ax = head, dx = sector
  	mov	dh,al		; dh = head
  	or	cl,dl		; cl = 2 high-order cyl bits || sector
  	inc	cl		; BIOS counts sectors starting at 1
***************
*** 134,140
  	mov	dh,al		; dh = head
  	or	cl,dl		; cl = 2 high-order cyl bits || sector
  	inc	cl		; BIOS counts sectors starting at 1
! 	mov	dl,dgroup:drive	; dl = drive code (0-3 or 0x80 - 0x81)
  	mov	bx,8[bp]	; bx = address of buffer
  	mov	al,cl		; al = sector #
  	add	al,10[bp]	; compute last sector

--- 254,260 -----
  	mov	dh,al		; dh = head
  	or	cl,dl		; cl = 2 high-order cyl bits || sector
  	inc	cl		; BIOS counts sectors starting at 1
! 	mov	dl,dgroup:_drive	; dl = drive code (0-3 or 0x80 - 0x81)
  	mov	bx,8[bp]	; bx = address of buffer
  	mov	al,cl		; al = sector #
  	add	al,10[bp]	; compute last sector
***************
*** 139,145
  	mov	al,cl		; al = sector #
  	add	al,10[bp]	; compute last sector
  	dec	al		; al = last sector to transfer
! 	cmp	al,byte ptr dgroup:tracksiz ; see if last sector is on next track
  	jle	d1		; jump if last sector is on this track
  	mov	word ptr 10[bp],1    ; transfer 1 sector at a time
  d1:	mov	ah,4[bp]	; ah = READING or WRITING

--- 259,265 -----
  	mov	al,cl		; al = sector #
  	add	al,10[bp]	; compute last sector
  	dec	al		; al = last sector to transfer
! 	cmp	al,byte ptr dgroup:_tracksiz ; see if last sector is on next track
  	jle	d1		; jump if last sector is on this track
  	mov	word ptr 10[bp],1    ; transfer 1 sector at a time
  d1:	mov	ah,4[bp]	; ah = READING or WRITING
***************
*** 163,169
  d2:	jmp	cret
  
  
! dmaoverr:                       ; test if &buffer causes a DMA overrun
          push    bp
          mov     bp,sp
          push    bx

--- 283,289 -----
  d2:	jmp	cret
  
  
! _dmaoverrun:                       ; test if &buffer causes a DMA overrun
          push    bp
          mov     bp,sp
          push    bx
***************
*** 200,244
          pop     bp
          ret
  
! 
! @CODE   ENDS
! 
! 
! @DATAI	SEGMENT
! tmp	DW 0
! tmp1	DW 0
! tmp2	DW 0
! fsckmsg DB "arrived at fsck1",0
! @DATAI	ENDS
! 
! 
! IFDEF STANDALONE
! ;---------------------------------------+
! ;  Set up memory lay-out for standalone |
! ;---------------------------------------+
! ;
! STACKSIZE EQU 8192
! 
! LOWCORE SEGMENT AT 0            ; tell where BIOS-data etc is
! 	ORG 120
! dskbase label word
! LOWCORE ENDS
! 
! MINIX	SEGMENT AT 60h          ; This is where Minix is loaded
! kernel  label byte		; absolute address 0000:1536d = 0060:0000h
! MINIX	ENDS
! 
! @DATAT  SEGMENT			; DATAT holds nothing. The label tells us
! edata   label byte              ; where .data ends.
! @DATAT  ENDS
! 
! @DATAU   SEGMENT		; allocate the stack in .bss
! kerstack DB STACKSIZE dup(?)
! @DATAU   ENDS
! 
! @DATAV  SEGMENT			; DATAV holds nothing. The label tells us
! @end    label byte              ; where .data+.bss ends (first free memory)
! @DATAV  ENDS
  
  @STACK  SEGMENT BYTE STACK 'STACK' ; Satisfy DOS-linker
  @STACK  ENDS			   ; (dummy stack-segment)

--- 320,326 -----
          pop     bp
          ret
  
! _TEXT   ENDS
  
  @STACK  SEGMENT BYTE STACK 'STACK' ; Satisfy DOS-linker
  @STACK  ENDS			   ; (dummy stack-segment)
