Subversion Repositories SvarDOS

Rev

Rev 1839 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1839 Rev 1840
Line 119... Line 119...
119
  outputnl(msg);
119
  outputnl(msg);
120
  return(1);
120
  return(1);
121
}
121
}
122
 
122
 
123
 
123
 
-
 
124
/* DR-DOS specific boot processing: check for F5/F8 boot key presses and reset
-
 
125
 * the wild pointer to DR-DOS kernel (CONFIG.SYS) environment because it is not
-
 
126
 * allocated memory hence will be overwritten soon.
-
 
127
 * details: https://github.com/SvarDOS/edrdos/issues/83
-
 
128
 * this function returns 0, FLAG_SKIP_AUTOEXEC or FLAG_STEPBYSTEP */
-
 
129
static unsigned char drdos_init(void) {
-
 
130
  unsigned short kernenvseg = 0;
-
 
131
  unsigned char far *e;
-
 
132
  unsigned short far *scancode;
-
 
133
 
-
 
134
  /* If I am init then query kernel's private data via INT 21,4458 (DR-DOS).
-
 
135
   * On success (CF not set) ES:BX contains a pointer to the private data.
-
 
136
   * Segment of kernel's environment is at offset 12h. This environment may
-
 
137
   * be terminated by a 1Ah code followed by a boot key scan code to record
-
 
138
   * an F5 or F8 key press during boot time. */
-
 
139
  _asm {
-
 
140
    push ax
-
 
141
    push bx
-
 
142
    push es
-
 
143
 
-
 
144
    mov ax, 0x4458       /* DR-DOS 5+ get ptr to internal variable table */
-
 
145
    int 0x21             /* ES:BX contains the ptr to the var table */
-
 
146
    jc FAIL              /* not DR-DOS */
-
 
147
 
-
 
148
    add bx, 0x12
-
 
149
    mov ax, es:[bx]      /* read the segment of the kernel environment */
-
 
150
    mov kernenvseg, ax   /* save the kern env segment for later */
-
 
151
    xor ax, ax
-
 
152
    mov es:[bx], ax      /* reset the pointer to kernel env as done by DR COMMAND.COM */
-
 
153
 
-
 
154
    FAIL:
-
 
155
    pop es
-
 
156
    pop bx
-
 
157
    pop ax
-
 
158
  }
-
 
159
 
-
 
160
  if (kernenvseg == 0) return(0); /* either not DR-DOS, or kern env was read already or something failed */
-
 
161
 
-
 
162
  e = MK_FP(kernenvseg, 0);
-
 
163
 
-
 
164
  /* move forward until the DRDOS' environment 1Ah terminator is found */
-
 
165
  while (*e != 0x1A) e++;
-
 
166
  e++;
-
 
167
 
-
 
168
  /* next I have the boot key press scancode: either 0x0000, 0x3F00 or 0x4200
-
 
169
   * 0x3F00 means "F5 was pressed" while 0x4200 is for F8 */
-
 
170
  scancode = (void far *)e;
-
 
171
  if (*scancode == 0x3F00) return(FLAG_SKIP_AUTOEXEC);
-
 
172
  if (*scancode == 0x4200) return(FLAG_STEPBYSTEP);
-
 
173
 
-
 
174
/*
-
 
175
  printf("kernel env seg is at %04X and starts with bytes 0x%02X 0x%02X 0x%02X 0x%02X\r\n", kernenvseg, e[0], e[1], e[2], e[3]);
-
 
176
  {
-
 
177
    int i;
-
 
178
    printf("=== KERNEL ENV BEGINS ===\r\n");
-
 
179
    for (i = 0; i < 100; i++) {
-
 
180
      printf("%c", e[i]);
-
 
181
    }
-
 
182
    printf("\r\n=== KERNEL ENV ENDS, DUMP FOLLOWS ===\r\n");
-
 
183
    for (i = 0; i < 260; i++) {
-
 
184
      if ((i > 0) && ((i % 26) == 0)) printf("\r\n");
-
 
185
      printf("%02X ", e[i]);
-
 
186
    }
-
 
187
    printf("\r\n=== DUMP ENDS ===\r\n");
-
 
188
  }
-
 
189
*/
-
 
190
  return(0);
-
 
191
}
-
 
192
 
-
 
193
 
124
/* parses command line the hard way (directly from PSP) */
194
/* parses command line the hard way (directly from PSP) */
125
static void parse_argv(struct config *cfg) {
195
static void parse_argv(struct config *cfg) {
126
  unsigned char *cmdlinelen = (void *)0x80;
196
  unsigned char *cmdlinelen = (void *)0x80;
127
  char *cmdline = (void *)0x81;
197
  char *cmdline = (void *)0x81;
128
 
198
 
Line 954... Line 1024...
954
  static unsigned short i; /* general-purpose variable for short-lived things */
1024
  static unsigned short i; /* general-purpose variable for short-lived things */
955
  static unsigned char flags;
1025
  static unsigned char flags;
956
 
1026
 
957
  rmod = rmod_find(BUFFER_len);
1027
  rmod = rmod_find(BUFFER_len);
958
  if (rmod == NULL) {
1028
  if (rmod == NULL) {
-
 
1029
 
959
    /* look at command line parameters (in case env size if set there) */
1030
    /* look at command line parameters (in case env size if set there) */
960
    parse_argv(&cfg);
1031
    parse_argv(&cfg);
-
 
1032
 
-
 
1033
    /* DR-DOS specific: if I am the init shell (zeroed env seg) then detect F5/F8 now
-
 
1034
     * This must be done BEFORE rmod_install() because DR-DOS's boot environment
-
 
1035
     * is located at an unallocated memory location that is likely to be overwritten
-
 
1036
     * by rmod_install(). */
-
 
1037
    cfg.flags |= drdos_init();
-
 
1038
 
961
    rmod = rmod_install(cfg.envsiz, BUFFER, BUFFER_len);
1039
    rmod = rmod_install(cfg.envsiz, BUFFER, BUFFER_len);
962
    if (rmod == NULL) {
1040
    if (rmod == NULL) {
963
      nls_outputnl_err(2,1); /* "FATAL ERROR: rmod_install() failed" */
1041
      nls_outputnl_err(2,1); /* "FATAL ERROR: rmod_install() failed" */
964
      return(1);
1042
      return(1);
965
    }
1043
    }
Line 968... Line 1046...
968
    /* printf("rmod installed at %Fp\r\n", rmod); */
1046
    /* printf("rmod installed at %Fp\r\n", rmod); */
969
    rmod->version = BYTE_VERSION;
1047
    rmod->version = BYTE_VERSION;
970
 
1048
 
971
    /* if my environment seg was zeroed, then I am the init process (under DR-DOS and MS-DOS 5 at least) */
1049
    /* if my environment seg was zeroed, then I am the init process (under DR-DOS and MS-DOS 5 at least) */
972
    if (rmod->origenvseg == 0) {
1050
    if (rmod->origenvseg == 0) {
973
      rmod->flags |= FLAG_PERMANENT; /* imply /P so AUTOEXEC.BAT is executed */
1051
      cfg.flags |= FLAG_PERMANENT; /* imply /P so AUTOEXEC.BAT is executed */
974
 
-
 
975
      /* If I am init then query kernel's private data via INT 21,4458 (DR-DOS).
-
 
976
       * On success (CF not set) ES:BX contains a pointer to the private data.
-
 
977
       * Segment of kernel's environment is at offset 12h. This environment may
-
 
978
       * be terminated by a 1Ah code followed by an boot key scan code to
-
 
979
       * record F5 or F8 key pressed at boot time. */
-
 
980
      /* TODO */
-
 
981
    }
1052
    }
982
  } else {
1053
  } else {
983
    /* printf("rmod found at %Fp\r\n", rmod); */
1054
    /* printf("rmod found at %Fp\r\n", rmod); */
984
    /* if I was spawned by rmod and FLAG_EXEC_AND_QUIT is set, then I should
1055
    /* if I was spawned by rmod and FLAG_EXEC_AND_QUIT is set, then I should
985
     * die asap, because the command has been executed already, so I no longer
1056
     * die asap, because the command has been executed already, so I no longer