delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/15/22:18:42

From: apsh AT ecr DOT mu DOT oz DOT au (Alistair_P SHILTON)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: self-mod code and DJGPP - writable code segment?
Date: 16 Mar 2000 02:46:55 GMT
Organization: Computer Science, The University of Melbourne
Lines: 75
Message-ID: <8aphuv$24q$1@mulga.cs.mu.OZ.AU>
References: <8ak78h$dsd$1 AT mulga DOT cs DOT mu DOT OZ DOT AU> <838zzmdkjv DOT fsf AT mercury DOT st DOT hmc DOT edu>
NNTP-Posting-Host: gromit.ecr.mu.oz.au
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Great, thanks.  It works now.  All it needed was the ds:'s
The working code fragment is:

.....

go_up   pop dword Zaddra
        pop dword Zaddrb
        retn


_z80_go nop   
byteoff nop
        mov byte [ds:_z80_go],0EBh
        mov byte [ds:byteoff],013h
        jmp short zstart
        nop
        nop

normop  push dword Zaddrb
        push dword Zaddra
        retn

zstart  jmp mf

zend    mov byte [ds:_z80_go],090h
        mov byte [ds:byteoff],090h
        call go_up

.....


Thanks

Alistair



Nate Eldredge (neldredge AT hmc DOT edu) wrote:
: apsh AT ecr DOT mu DOT oz DOT au (Alistair_P SHILTON) writes:

: > I was wondering if it is possible to link self-modifying assembler
: > code to DJGPP.  When I try, I get an error message.  So I checked
: > the documentation, which says that the code segment is not writable.
: > Is there some way around this?
: > 
: > I was planning to use the self-mod to make the code act differently
: > after the first call to it (ie. setup on first call, normal operation
: > on subsequent calls).  Now I know that there are other ways of achieving
: > the same end, but I like the concept of self-modding code.  Any
: > suggestions?

: The code segment, as addressed via the CS register, is not writable,
: true.  This is a feature of the cpu.  However, the DS segment
: addresses exactly the same memory (in DJGPP) and is writable.  So
: something like this should work:

: movb interrupt_number, %al
: movb %al, modify_here+1
: modify_here:
: int 0x42

: Do be careful to make sure you write it maintainably, though.
: Self-modifying code is dangerous in that respect.

: -- 

: Nate Eldredge
: neldredge AT hmc DOT edu







- Raw text -


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