delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/11/05:09:42

Date: Mon, 10 Oct 1994 22:28:06 -0500 (CDT)
From: Aaron Ucko <UCKO AT VAX1 DOT ROCKHURST DOT EDU>
Subject: Loading stuff into shadowed ROM (again)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Organization: Rockhurst College; Kansas City, MO

One or two weeks ago, I asked about loading a newer version of my video BIOS
into memory shadowed by EMM386.  Based on dj's suggestion (and R'ing TFM :-) I
wrote the following program, which not only fails to load the code (a hex dump
by DEBUG shows the old code is still there) but crashes (always at the same
point) when trying to load it.  The errors are more fully documented within the
code...Anyway, does anyone have any suggestions for getting this to work?  It's
not extremely important to me, so I don't intend to use an EPROM instead
(although the suggestion is appreciated); rather, it seems like an interesting
idea, and it _should_ be doable (shouldn't it?)  Feel free to comment on
anything but purely stylistic points.  Thanks!

/* LoadBIOS.c:
 Utility to load a given file (a replacement BIOS, one hopes :-) into a given 
 DOS memory address (given as the physical address where it theoretically 
 resides, although this program will fail if that address is actually ROM.)
*/
 
#include <stdlib.h>
#include <stdio.h>
#include <dpmi.h>
 
#define DIE(_p, _n) { _p; exit(_n); }
 
int main(int argc, char **argv) {
  char* usage="%s <file> <addr>\n",
        *fnf="\aUnable to find file %s\n",
        *badnum="\aBad hex address:  %s\n";
  FILE* fp;
  int addr, len, enabled;
  void* buff;
  _go32_dpmi_registers* regs;
 
  if(argc != 3) DIE(printf(usage, *argv), 1);
  if(!(fp = fopen(argv[1], "rb"))) DIE(printf(fnf, argv[1]), 2);
  if(!(addr = strtol(argv[2], NULL, 16))) DIE(printf(badnum, argv[2]), 3);
 
  fseek(fp, 0, SEEK_END); 
  len = ftell(fp); 
  fseek(fp, 0, SEEK_SET); /* ugly but effective */
 
  buff = malloc(len);
  fread(buff, len, 1, fp);
  fclose(fp);
 
  memset(regs, 0, sizeof(_go32_dpmi_registers));
  regs->x.cs = (short)(addr >> 4);
  regs->x.ip = 3; /* according to _PC Intern_ */
  
  puts("Loading BIOS...");
  enabled = disable();
  dosmemput(buff, len, addr); 
    /* memory still the same, even though shadowed by EMM386 -- are you
       sure this is the right function, dj? */
  enable();
  /* do NOTHING before BIOS initialized!  regs already set, so that's not
     the problem. */
  _go32_dpmi_simulate_fcall(regs); /* initialize new BIOS */
   /* dumps core, er, stack frame in int86_vec() according to gdb
      [symify says __ctype_+304, but it doesn't realize we're in a different
       segment; I trust gdb to be more reliable here] */
  /* interrupts already enabled--safer this way, I hope */
  puts("Done!\n");
}


-=-=-"f y cn rd ths tgln, dc lbxym h gyt ntz."-=-=-
Finger for PGP pubkey.  Geek code 2.1 [finger hayden AT vax1 DOT mankato DOT msus DOT edu]:
 GCS/M/S d(-) H s g+ p? !au a-- w+ v+ C++(+++)>++++ U-(S+)>++++ P+ L>++ 3(-) 
 E-(----) !N>++ K- W(--) M-(--) V(--) po-(--) Y+(++) t(+) !5 j R G tv--(-) 
 b+++ !D(--) B--(---) e>++++(*) u++(@) h!() f(+) r-(--)>+++ n+(-) y?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019