Thread: Way back (again) -- farmalloc.

  1. #1
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    Way back (again) -- farmalloc.

    I'm stuck in a time warp. . .

    I'm using 16-bit Dr. DOS and need to be able to move large amounts of memory. What I'm attempting to do is to grab up a huge block of memory (400K), copy a file into that block of memory, then copy that block of memory from the low memory to the upper memory (I'm writing my own version of loadlin but attempting to not use Assembly except in my high-move code).

    From reading the data available to me in TC 3.5, using an char far *buf and farmalloc will do the trick for the first part. I'm guessing I need a near pointer to do my fread(), then use movedata() to copy the < 0x10000 chunks to the upper bound memory. Next, I'll move the far chunks by going PM.

    I have, however, several questions to which I'm unable to find answers.

    1) Will I be able to move between PM and RM without totally hosing up DOS, if I pusha and popa before and after I go into PM? I'm trying to not have to do assembly reads to the raw disk, but just use DOS to feed me data.

    2) I've got to move some data (the Linux real mode code) into 0x90000. Does DOS use this as part of its far heap? It isn't a problem if it does, I'll just copy that data at the end, then make sure that I copy my code segment to a location out of the way (to a location that I know), then copy that segment to a lower location (thereby getting me out of the 0x90000 segment), then copy back up.

    3) Will the far pointers map to memory in the ASM code correctly? (according to an old post of Bubba, there is a way to do this, but again, I just want to make sure that I'm not chasing my tail.)

    Thanks in advance for you help/advice.
    Andy

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    To add insult to injury: TC 3.0 does not recognize the e-extensions of the registers. Thus, I'm now having to go back and nasm the 32-bit code and load it into the data section of the code, then form a jmp to it in the code. . . Man oh man I really hate TC 3.0.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What is it you're wanting to do all this for?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    :::Sighs heavily:::

    Man oh man, this is really a pain in the rear. . .

    TC 3.0 allows inline asm, as we all know/expect. It *claims* to allow labels, however, it only allows labels in the past and apparently no forward labels. How can I, in the following code snip, declare the label before I call the label? Is this even possible?
    Code:
            asm {
                    pusha
                    push    es
                    push    ds
                    push    cs
                    mov     ax,hmnext
                    push    ax
                    mov     ax,newcs
                    mov     bx,newip
                    mov     di,bx
                    mov     es,ax
                    jmp     es:di
            hmnext: pop     ds
                    pop     es
                    popa
            }
    I really really really hate TC 3.0.

  5. #5
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    Can you say HACK?

    My further woes with TC 3.0 have continued, to the point where I have preformed the following hack:
    Code:
            asm {
                    pusha
                    push    es
                    push    ds
                    mov     ax,newcs
                    mov     bx,newip
                    dd      55aa55aah
                    dd      90909090h
                    dd      90909090h <=====  This repeats to 127 iterations.
                    pop     ds
                    pop     es
                    popa
            }
    After I compile the 16-bit code with TC 3.0, I then use a hex editor to delete the 512 bytes from 55aa55aa -> 90909090, then insert a 512 block of machine code from a file that saves the current code segment, then jumps to another location (defined by ax:bx).

    For those who may wonder, 55aa55aa is just an identifier so that I can locate the block in the file. 90h, however, is the no-op statement (or xchg ax,ax) and is a safe instruction to use for padding.

    Now, we'll just see if this works.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You know your relatives can use this stuff against you in your sanity hearing, don't you?

    Good luck!

  7. #7
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Just one more thing to add to the docket, I guess.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Back to the drawing board
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-08-2004, 05:53 PM
  2. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  3. UInt to CString and back
    By xlnk in forum Windows Programming
    Replies: 6
    Last Post: 08-27-2003, 03:08 PM
  4. Some woman back ended my car today, and back hurts
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 08-20-2003, 12:42 AM
  5. Returning a Tree node back to void main()
    By gazza in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2002, 02:48 AM