Win32Forth: Kernel Image 
Author Message
 Win32Forth: Kernel Image

Hi!

While experimenting with a call based forth using win32forth
as meta compiler I encountered the problem that the image
origin is not an absolute address. Would it be possible to
modify the C-Kernel so that it loads the image at fixed
address? If somebody could do that for me, I would be very
glad.

Thanx

Ciao    Bernd
--
  _
 /_)ernd      |  Malvenweg 32    |  Germany

neckar.netsurf.de  



Sat, 23 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

Hello Bernd,

Quote:
> While experimenting with a call based forth using win32forth
> as meta compiler I encountered the problem that the image
> origin is not an absolute address. Would it be possible to
> modify the C-Kernel so that it loads the image at fixed
> address? If somebody could do that for me, I would be very
> glad.

It is so easy (at least the last time I tried it) you won't
believe it.  Just edit the lines in META.F that places the origin
of application space, and system space.  They are very near the
beginning of the file.  Then re-meta compile.

The C-wrapper already knows how to load either relative, or abaolute.

WARNING!  you do this at your own risk!  Every version of windows
needs to be origined at a different address.

I hope it works, but no guarantee,

Tom Zimmer



Sat, 23 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

The Win32Forth image is relocatable, but on a given machine (and
operating system) I would expect the image to always load at the same
address. This is true for me under NT 4.0b2.

There is a way to make it load at a fixed address. Just change the
value of the constant ORIGIN in meta.f to the address you want and
rebuild the kernel. If this address is zero (as shipped) then the
kernel is loaded at whatever address the operating system decides. If
it is non-zero, it will try to load at that address. I have used HEX
40000000 on both NT and 95 without any problems.

--

Finnigan Corporation            
2215 Grand Avenue Parkway        Tel: (512) 251-1574
Austin, TX  78728-3812           Fax: (512) 251-1547

Quote:

> Hi!

> While experimenting with a call based forth using win32forth
> as meta compiler I encountered the problem that the image
> origin is not an absolute address. Would it be possible to
> modify the C-Kernel so that it loads the image at fixed
> address? If somebody could do that for me, I would be very
> glad.

> Thanx

> Ciao    Bernd
> --
>   _
>  /_)ernd      |  Malvenweg 32    |  Germany

> neckar.netsurf.de



Sun, 24 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image



Quote:
> The Win32Forth image is relocatable, but on a given machine
(and
> operating system) I would expect the image to always load at
the same
> address. This is true for me under NT 4.0b2.

> There is a way to make it load at a fixed address. Just
change the
> value of the constant ORIGIN in meta.f to the address you
want and
> rebuild the kernel. If this address is zero (as shipped)
then the
> kernel is loaded at whatever address the operating system
decides. If
> it is non-zero, it will try to load at that address. I have
used HEX
> 40000000 on both NT and 95 without any problems.

Unfortunately it did not work. Kernel.exe is unable to
allocate the
memory. Perhaps its a bug in my code. Ill send you the source
codes.
Load newmeta.f first and afterwards newkernel.f. This should
create the
new image.


Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image



Quote:
> The Win32Forth image is relocatable, but on a given machine
(and
> operating system) I would expect the image to always load at
the same
> address. This is true for me under NT 4.0b2.

> There is a way to make it load at a fixed address. Just
change the
> value of the constant ORIGIN in meta.f to the address you
want and
> rebuild the kernel. If this address is zero (as shipped)
then the
> kernel is loaded at whatever address the operating system
decides. If
> it is non-zero, it will try to load at that address. I have
used HEX
> 40000000 on both NT and 95 without any problems.

Unfortunately it did not work. Kernel.exe is unable to
allocate the
memory. Perhaps its a bug in my code. Ill send you the source
codes.
Load newmeta.f first and afterwards newkernel.f. This should
create the
new image.


Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

Hi!

While experimenting with a call based forth using win32forth
as meta compiler I encountered the problem that the image
origin is not an absolute address. Would it be possible to
modify the C-Kernel so that it loads the image at fixed
address? If somebody could do that for me, I would be very
glad.

Thanx

Ciao    Bernd
--
  _
 /_)ernd      |  Malvenweg 32    |  Germany

neckar.netsurf.de  



Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image



Quote:
> The Win32Forth image is relocatable, but on a given machine (and
> operating system) I would expect the image to always load at the same
> address. This is true for me under NT 4.0b2.

> There is a way to make it load at a fixed address. Just change the
> value of the constant ORIGIN in meta.f to the address you want and
> rebuild the kernel. If this address is zero (as shipped) then the
> kernel is loaded at whatever address the operating system decides. If
> it is non-zero, it will try to load at that address. I have used HEX
> 40000000 on both NT and 95 without any problems.

Unfortunately it did not work. Kernel.exe is unable to allocate the
memory. Perhaps its a bug in my code. Ill send you the source codes.
Load newmeta.f first and afterwards newkernel.f. This should create the
new image.


Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

Sorry for my wild posting.
I got it now. But I still dont know how to communicate with the C-
kernel. Ill post my sources into this thread. Perhaps you can find the
bug. Load newmeta.f first and newkernel afterwards. This should create
the new image.

Ciao
        Bernd

--
  _
 /_)ernd      |  Malvenweg 32    |  Germany



Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

26350037 constant MAGIC#         \ magic # to indentify a
dictionary image

\ -------------------- Boot-Up Literals ---------------------

HERE: ORIG        ORIGIN ,-t        \ My physical starting
addres
HERE: MAGIC       MAGIC# ,-t        \ magic number (make sure
I am ME)
HERE: ASIZE       200000 ,-t        \ desired dictionary size
in bytes
HERE: AACTUAL     0 ,-t             \ actual dictionary length
in bytes
HERE: SSIZE        50000 ,-t        \ desired head space size
in bytes
HERE: SACTUAL     0 ,-t             \ actual head length in
bytes
HERE: SSEPARATE   SSEPARATION ,-t   \ code to head separation
is 4 megabytes
HERE: ENTRY       0 ,-t             \ cold start entry point
HERE: TABLE       0 ,-t             \ pointer to xcall table
entries
HERE: HINST       0 ,-t             \ applications instance
handle
HERE: CMDLEN      0 ,-t             \ length  of command line
HERE: CMDADR      0 ,-t             \ address of command line
HERE: HCON        0 ,-t             \ applications console
handle
HERE: EXCEPT      0 ,-t             \ exception variable,-t
defaults to none
HERE: EXREC       0 ,-t             \ a pointer to the
expection record
HERE: EXRSTK      0 ,-t 0 ,-t 0 ,-t 0 ,-t       \ room for top
return stack entries,
HERE: UNFORTH     0 ,-t             \ un-initialize forth
HERE: DLLINIT     0 ,-t             \ dll initialization
function
HERE: DLLNTRY     0 ,-t             \ function entry for all
DLL functions
HERE: MSGNTRY     0 ,-t             \ message callbacks for
key and key?
HERE: WINMSGNTRY  0 ,-t             \ windows message
callbacks

\ -------------------- cold start and unload ----------------

code    cold
        mov     ebx, # 0                \ bye function call
        lea     ebx, [ebx*4]
        add     ebx, table [esi]
        call    [ebx]
        ret
        c;

code    unload
        ret
        c;

' cold   entry   !-t
' unload unforth !-t

here-t origin -               aactual !-t        \ set the
actual dictionary length
here-h origin sseparation + - sactual !-t        \ set the
actual header length

himage here-h origin sseparation + - image here-t origin -
dual-save fkernel.img

here-t origin - here-h origin sseparation + - +
cr . .( bytes written to file fkernel.img )



Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

\ Win32 Forth Metacompiler

' (find) is find

anew metacompiler

sys-warning-off        \ don't warn about use of system words

vocabulary meta

only forth also meta also definitions

decimal nostack         \ stack warnings off

\
==============================================================
========
\ Memory Access Words

4096  250 * VALUE SSEPARATION           \ offset from code to
heads
4096 2500 * VALUE ORIGIN                \ where target image
will run

CREATE  IMAGE 40000 ALLOT               \ where target code is
built
        IMAGE 40000 ERASE  ( clean start )
CREATE HIMAGE 20000 ALLOT               \ where target heads
are built
       HIMAGE 20000 ERASE

VARIABLE DP-T   ORIGIN               DP-T !     \ code space
pointer
VARIABLE DP-H   ORIGIN SSEPARATION + DP-H !     \ name space
pointer

\ target code space memory words
: THERE   ( taddr -- addr )     ORIGIN - IMAGE +  ;



: C!-T    ( char taddr -- )     THERE C! ;
: W!-T    ( word taddr -- )     THERE W! ;
: !-T     ( n taddr -- )        THERE !  ;

: ALLOT-T ( n -- )              DP-T +!  ;
: C,-T    ( char -- )           HERE-T C!-T   1 DP-T +!  ;
: W,-T    ( w -- )              DUP C,-T  8 RSHIFT C,-T  ;
: ,-T     ( n -- )              HERE-T  !-T   4 DP-T +!  ;
: S,-T    ( addr len -- )       DUP C,-T 0 ?DO  COUNT C,-T  
LOOP DROP  ;

: ALIGN   HERE-T ALIGNED HERE-T - ALLOT-T ;

\ target name space memory words
: ADDR-H  ( taddr -- addr )     ORIGIN - SSEPARATION - HIMAGE
+  ;



: C!-H    ( char taddr -- )     ADDR-H C! ;
: W!-H    ( word taddr -- )     ADDR-H W! ;
: !-H     ( n taddr -- )        ADDR-H !  ;

: ALLOT-H ( n -- )              DP-H +!  ;
: C,-H    ( char -- )           HERE-H C!-H   1 DP-H +!  ;
: W,-H    ( w -- )              DUP C,-H  8 RSHIFT C,-H  ;
: ,-H     ( n -- )              HERE-H  !-H   4 DP-H +!  ;
: S,-H    ( addr len -- )       DUP C,-H 0 ?DO  COUNT C,-H  
LOOP DROP  ;


: HALIGN   HERE-H ALIGNED HERE-H - ALLOT-H ;

: DUAL-SAVE  ( Haddr Hlen Daddr Dlen -<filename>- )
        BL WORD COUNT R/W BIN CREATE-FILE ABORT" Cannot create
file"   >R


        R> CLOSE-FILE ABORT" Cannot close file" ;

\
==============================================================
========
\ Modify assembler to place code into target

     ' HERE-T     ASSEMBLER ASM-HIDDEN IS CODE-HERE     META
     ' C,-T       ASSEMBLER ASM-HIDDEN IS CODE-C,       META
     ' W,-T       ASSEMBLER ASM-HIDDEN IS CODE-W,       META
     ' ,-T        ASSEMBLER ASM-HIDDEN IS CODE-D,       META

     ' C!-T       ASSEMBLER ASM-HIDDEN IS CODE-C!       META

     ' W!-T       ASSEMBLER ASM-HIDDEN IS CODE-W!       META

     '  !-T       ASSEMBLER ASM-HIDDEN IS CODE-D!       META

\
==============================================================
========
\ stack utility

((      structure of a stack
        --------------------------------------------------
        name      type    offset   description

        pointer   cell     +00     stack pointer
        bottom    cell     +04
        top       cell     +08
        data               +12     elements
))

: newStack  ( limit -- a-addr )
        align here
        dup 3 cells+ ,          \ stack pointer
        dup 3 cells+ ,          \ bottom
        over cells
        over 2 cells+ + ,       \ top
        swap cells allot ;

: Stack  ( limit -- )
        create
        newstack drop ;

: StackOverflow   ( -- )  abort" stack overflow" ;
: StackUnderflow  ( -- )  abort" stack underflow" ;

: >s    ( n stack -- )


        IF      swap over ! cell+ r> !
        ELSE    StackOverflow THEN ;

: s>    ( stack -- n )



        ELSE    StackUnderflow THEN ;





        ELSE    StackUnderflow THEN ;

\
==============================================================
========
\ Create Headers in Target Image

\ search path
10 stack current

\ header type constants
0 constant HT_CONTAINER
1 constant HT_CODE
2 constant HT_COLON

: >standard.link  ( addr -- addr' )  ;
: >standard.exec  ( addr -- addr' )  cell+ ;
: >standard.type  ( addr -- addr' )  2 cells+ ;
: >standard.file  ( addr -- addr' )  3 cells+ ;
: >standard.line  ( addr -- addr' )  4 cells+ ;
: >standard.attr  ( addr -- addr' )  5 cells+ ;
: >standard.name  ( addr -- addr' )  6 cells+ ;
: >standard.body  ( addr -- addr' )  6 cells+ hcount + aligned
;

: >container.last  ( addr -- addr ' )  >standard.body ;

((      conatainer header
        =================
        name   type  offset   description
        ------------------------------------------------------
-
        link   addr   +00     downward link to previous
header
        exec   addr   +04     execution address
        type   cell   +08     header type
        file   addr   +12     addr of source file header
        line   cell   +16     line of source code
        attr   cell   +20     some attributes ( e.g. immediate
)
        name   c-str  +24     word name
        last   addr  +body    addr of last header in thread
))

\ create a container header
: container  ( -- )
        halign here-h >r

entry
        here-h rot !-h                          \ update last
entry
            ( link ) ,-h        \ link
                NULL ,-h        \ exec
        HT_CONTAINER ,-h        \ type
                NULL ,-h        \ file
                NULL ,-h        \ line
                NULL ,-h        \ attr
                bl word count   \ parse name
           ( name ) s,-h        \ name
        halign
                  r> ,-h ;      \ last

((      standard header
        ===============
        name   type  offset  description
        ------------------------------------------------------
-
        link   addr   +00    downward link to previous header
        exec   addr   +04    execution address
        type   cell   +08    header type
        file   addr   +12    addr of source file header
        line   cell   +16    line of source code
        attr   cell   +20    some attributes ( e.g. immediate
)
        name   c-str  +24    word name
))

\ create a standard header
: standardHeader  ( type -- )
        halign

entry
        here-h rot !-h                          \ update last
entry
            ( link ) ,-h        \ link
        align here-T ,-h        \ exec
            ( type ) ,-h        \ type
                NULL ,-h        \ file
                NULL ,-h        \ line
                NULL ,-h        \ attr
                bl word count   \ parse name
           ( name ) s,-h ;      \ name

: codeHeader    ( -- )  HT_CODE  standardHeader ;
: colonHeader   ( -- )  HT_COLON standardHeader ;

\ make root header entry at the biginning of name space
halign here-h dup current >s
        NULL ,-h        \ link
        NULL ,-h        \ exec
HT_CONTAINER ,-h        \ type
        NULL ,-h        \ file
        NULL ,-h        \ line
        NULL ,-h        \ attr
   s" root" s,-h        \ name
halign
  ( here-h ) ,-h        \ last

\ make words container
halign here-h container words current >s

\ make forth container
halign here-h container forth current >s

\
==============================================================
========
\ search target dictionary

\ search target name space for c-str
: hfind  ( c-str -- cfa flag )

        BEGIN   dup >r
                >standard.name addr-h ?uppercase count
                2 pick count compare 0=
                IF      drop

                        true exit
                THEN

                dup 0<>
        WHILE REPEAT
        drop false ;

\ search target name space and forth name space for c-str
: newFind  ( c-str -- cfa flag )
        hfind ?dup 0=
        IF      (find) THEN ;

' newFind is find

\
==============================================================
========
\ make target code words

: init-assembler  ( -- )        \ prepare for assembly code
        [ assembler asm-hidden ] reset-asm [ meta ] also
assembler !csp ;

: code  ( -- )
        codeheader
        init-assembler ;

\
==============================================================
========

: here:  ( -<name>- )
        here-t constant ;



Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

26350037 constant MAGIC#         \ magic # to indentify a
dictionary image

\ -------------------- Boot-Up Literals ---------------------

HERE: ORIG        ORIGIN ,-t        \ My physical starting
addres
HERE: MAGIC       MAGIC# ,-t        \ magic number (make sure
I am ME)
HERE: ASIZE       200000 ,-t        \ desired dictionary size
in bytes
HERE: AACTUAL     0 ,-t             \ actual dictionary length
in bytes
HERE: SSIZE        50000 ,-t        \ desired head space size
in bytes
HERE: SACTUAL     0 ,-t             \ actual head length in
bytes
HERE: SSEPARATE   SSEPARATION ,-t   \ code to head separation
is 4 megabytes
HERE: ENTRY       0 ,-t             \ cold start entry point
HERE: TABLE       0 ,-t             \ pointer to xcall table
entries
HERE: HINST       0 ,-t             \ applications instance
handle
HERE: CMDLEN      0 ,-t             \ length  of command line
HERE: CMDADR      0 ,-t             \ address of command line
HERE: HCON        0 ,-t             \ applications console
handle
HERE: EXCEPT      0 ,-t             \ exception variable,-t
defaults to none
HERE: EXREC       0 ,-t             \ a pointer to the
expection record
HERE: EXRSTK      0 ,-t 0 ,-t 0 ,-t 0 ,-t       \ room for top
return stack entries,
HERE: UNFORTH     0 ,-t             \ un-initialize forth
HERE: DLLINIT     0 ,-t             \ dll initialization
function
HERE: DLLNTRY     0 ,-t             \ function entry for all
DLL functions
HERE: MSGNTRY     0 ,-t             \ message callbacks for
key and key?
HERE: WINMSGNTRY  0 ,-t             \ windows message
callbacks

\ -------------------- cold start and unload ----------------

code    cold
        mov     ebx, # 0                \ bye function call
        lea     ebx, [ebx*4]
        add     ebx, table [esi]
        call    [ebx]
        ret
        c;

code    unload
        ret
        c;

' cold   entry   !-t
' unload unforth !-t

here-t origin -               aactual !-t        \ set the
actual dictionary length
here-h origin sseparation + - sactual !-t        \ set the
actual header length

himage here-h origin sseparation + - image here-t origin -
dual-save fkernel.img

here-t origin - here-h origin sseparation + - +
cr . .( bytes written to file fkernel.img )



Thu, 28 Jan 1999 03:00:00 GMT  
 Win32Forth: Kernel Image

What operating system are you using? If you are using Windows 3.1 with
Win32s, you will have to choose an address in the 0x80000000 - 0xC0000000
range. Also, you will only be able to run one instance of Win32Forth,
because this address space is shared among Win32 processes. If 95 or NT,
0x40000000 should work.

Your code has:

4096 2500 * VALUE ORIGIN

That gives us 0x9C4000 which will not work in Win32s and probably won't
under NT either.

This is the danger of fixing the base address. You have to make sure the
operating system makes that address available. Win32 gives you no such
guarantee :-(

--

Finnigan Corporation            
2215 Grand Avenue Parkway        Tel: (512) 251-1574
Austin, TX  78728-3812           Fax: (512) 251-1547

Quote:



> > The Win32Forth image is relocatable, but on a given machine (and
> > operating system) I would expect the image to always load at the same
> > address. This is true for me under NT 4.0b2.

> > There is a way to make it load at a fixed address. Just change the
> > value of the constant ORIGIN in meta.f to the address you want and
> > rebuild the kernel. If this address is zero (as shipped) then the
> > kernel is loaded at whatever address the operating system decides. If
> > it is non-zero, it will try to load at that address. I have used HEX
> > 40000000 on both NT and 95 without any problems.

> Unfortunately it did not work. Kernel.exe is unable to allocate the
> memory. Perhaps its a bug in my code. Ill send you the source codes.
> Load newmeta.f first and afterwards newkernel.f. This should create the
> new image.



Sun, 31 Jan 1999 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. visual works 3.1 image has segmentation fault on 2.4 kernel (red hat 8.0)

2. H3rL kernel image

3. VHDL Image processing kernels

4. A Win32Forth kernel that supports PROC and CALL from the kernel directly.

5. import Image vs from PIL import Image vs import PIL.Image

6. win32forth 3.2 : fsave fails to copy kernel.bin ; makedefer ?

7. image file name changed on image save

8. VisualWorks 2.5.1: Image to Image Communication

9. Need help with LeadTools API and displaying image in image control

10. Moving Apps from image to image

11. Image Searcher: searching images without textual keywords.

12. New Imaging SDK - Image-XChange demo

 

 
Powered by phpBB® Forum Software