Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions kernel/hmamgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ static hmcb init_mcb = { .signature = HMCB_SIG, };
#define FIRST_MCB 0x10

#define nxtMCBsize(mcb,size) MK_FP(FP_SEG(mcb), FP_OFF(mcb) + (size) + 16)
#define nxtMCB(mcb) MK_FP(FP_SEG(mcb), mcb->next)
#define nxtMCBsizeTd(mcb,size) MK_FP(FP_SEG(mcb), FP_OFF(mcb) + (mcb)->size - (size))
#define nxtMCB(mcb) MK_FP(FP_SEG(mcb), (mcb)->next)

#define mcbFree(mcb) ((mcb)->owner == 0)
#define mcbValid(mcb) ( ((mcb)->signature == HMCB_SIG) )
Expand Down Expand Up @@ -99,10 +100,10 @@ STATIC COUNT joinMCBs(UWORD off)
size is the minimum size of the block to search for,
even if mode == LARGEST.
*/
COUNT DosHMAAlloc(UWORD size, UWORD *off)
COUNT DosHMAAlloc(UWORD size, BOOL topdown, UWORD *off)
{
REG hmcb FAR *p;
REG hmcb FAR *q = NULL;
hmcb FAR *p;
hmcb FAR *q = NULL;
hmcb FAR *foundSeg;
hmcb FAR *biggestSeg;

Expand Down Expand Up @@ -156,13 +157,16 @@ COUNT DosHMAAlloc(UWORD size, UWORD *off)
/* foundSeg := pointer to allocated block
p := pointer to MCB that will form the rest of the block
*/
p = nxtMCBsize(foundSeg, size);
p = topdown ? nxtMCBsizeTd(foundSeg, size) : nxtMCBsize(foundSeg, size);

fd_prot_mem(p, sizeof(*p), FD_MEM_NORMAL);
/* initialize stuff because p > foundSeg */
*p = init_mcb;
p->next = foundSeg->next;
p->size = foundSeg->size - size - 16;
if (topdown)
p->size = size;
else
p->size = foundSeg->size - size - 16;
fd_mark_mem(p, sizeof(*p), FD_MEM_READONLY);
fd_prot_mem(foundSeg, sizeof(*foundSeg), FD_MEM_NORMAL);
foundSeg->next = mcb2off(p);
Expand All @@ -173,8 +177,13 @@ COUNT DosHMAAlloc(UWORD size, UWORD *off)
p->owner = 0; /* unused */
fd_prot_mem(p, sizeof(*p), FD_MEM_READONLY);

foundSeg->size = size;
if (topdown)
foundSeg->size -= size + 16;
else
foundSeg->size = size;
fd_prot_mem(foundSeg, sizeof(*foundSeg), FD_MEM_READONLY);
if (topdown)
foundSeg = p;
}

/* Already initialized:
Expand Down
10 changes: 3 additions & 7 deletions kernel/inthndlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ VOID ASMCFUNC int2F_12_handler(struct int2f12regs FAR *regs)
r.BX = (r.BX + 0xf) & 0xfff0;
if (r.BX > avail)
r.BX = avail;
rc = DosHMAAlloc(r.BX, &r.DI);
rc = DosHMAAlloc(r.BX, 0, &r.DI);
break;
case 3:
if (!HMAclaimed)
Expand All @@ -1876,14 +1876,10 @@ VOID ASMCFUNC int2F_12_handler(struct int2f12regs FAR *regs)
switch (r.DL)
{
case 0: // alloc
case 1:
/* align to para */
r.BX = (r.BX + 0xf) & 0xfff0;
rc = DosHMAAlloc(r.BX, &r.DI);
break;
case 1: // resize
/* align to para */
r.BX = (r.BX + 0xf) & 0xfff0;
rc = DosHMAChange(r.DI, r.BX);
rc = DosHMAAlloc(r.BX, r.DL, &r.DI);
break;
case 2: // free
rc = DosHMAFree(r.DI);
Expand Down
2 changes: 1 addition & 1 deletion kernel/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void DosUmbLink(unsigned n);
VOID mcb_print(__FAR(mcb) mcbp);

COUNT DosHMAQuery(UWORD *off, UWORD *avail);
COUNT DosHMAAlloc(UWORD size, UWORD *off);
COUNT DosHMAAlloc(UWORD size, BOOL topdown, UWORD *off);
COUNT DosHMAFree(UWORD off);
COUNT DosHMAChange(UWORD para, UWORD size);
COUNT DosHMACheck(void);
Expand Down