From 69faceffe5241058dbd0324bcfba93e2f0d149c9 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Wed, 17 Mar 2004 21:28:54 +0000 Subject: [PATCH] int21/ah=26: new_psp now copies the old psp and just sets a few fields int21/ah=55: child_psp does the rest init code does the init (fixed values are always copied now) git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@799 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/init-mod.h | 2 +- kernel/inthndlr.c | 8 ++---- kernel/intr.asm | 12 --------- kernel/main.c | 64 +++++++++++++++++++++++++++++++++++++++++++++-- kernel/proto.h | 3 ++- kernel/task.c | 56 ++++++++++++++++++----------------------- 6 files changed, 91 insertions(+), 54 deletions(-) diff --git a/kernel/init-mod.h b/kernel/init-mod.h index 8265503..2b781dd 100644 --- a/kernel/init-mod.h +++ b/kernel/init-mod.h @@ -67,6 +67,7 @@ extern BYTE DosLoadedInHMA; void MoveKernel(unsigned NewKernelSegment); #define setvec(n, isr) (void)(*(intvec FAR *)MK_FP(0,4 * (n)) = (isr)) +#define getvec(n) (*(intvec FAR *)MK_FP(0,4 * (n))) #define GLOBAL extern #define NAMEMAX MAX_CDSPATH /* Maximum path for CDS */ @@ -120,7 +121,6 @@ int ASMCFUNC open(const char *pathname, int flags); int ASMCFUNC close(int fd); int ASMCFUNC dup2(int oldfd, int newfd); int ASMCFUNC allocmem(UWORD size, seg * segp); -VOID ASMCFUNC init_PSPInit(seg psp_seg); VOID ASMCFUNC init_PSPSet(seg psp_seg); COUNT ASMCFUNC init_DosExec(COUNT mode, exec_blk * ep, BYTE * lp); int ASMCFUNC init_setdrive(int drive); diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c index c69cd5f..b27c755 100644 --- a/kernel/inthndlr.c +++ b/kernel/inthndlr.c @@ -649,11 +649,7 @@ dispatch: /* Dos Create New Psp */ case 0x26: - { - psp FAR *p = MK_FP(cu_psp, 0); - - new_psp(lr.DX, p->ps_size); - } + new_psp(lr.DX, r->CS); break; /* Read random record(s) using FCB */ @@ -1175,7 +1171,7 @@ dispatch: /* ************UNDOCUMENTED************************************* */ /* Dos Create New Psp & set p_size */ case 0x55: - new_psp(lr.DX, lr.SI); + child_psp(lr.DX, cu_psp, lr.SI); cu_psp = lr.DX; break; diff --git a/kernel/intr.asm b/kernel/intr.asm index ad08028..cdac2be 100644 --- a/kernel/intr.asm +++ b/kernel/intr.asm @@ -226,18 +226,6 @@ _dup2: int 21h jmp short common_exit -;; VOID init_PSPInit(seg psp_seg) - global _init_PSPInit -_init_PSPInit: - push si - mov ah, 55h - mov bx, sp - mov dx, [bx+4] - xor si, si - int 21h - pop si - ret - ;; VOID init_PSPSet(seg psp_seg) global _init_PSPSet _init_PSPSet: diff --git a/kernel/main.c b/kernel/main.c index 176500e..f2ee738 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -153,6 +153,67 @@ void InitializeAllBPBs(VOID) } } +STATIC void PSPInit(void) +{ + psp far *p = MK_FP(DOS_PSP, 0); + + /* Clear out new psp first */ + fmemset(p, 0, sizeof(psp)); + + /* initialize all entries and exits */ + /* CP/M-like exit point */ + p->ps_exit = 0x20cd; + + /* CP/M-like entry point - call far to special entry */ + p->ps_farcall = 0x9a; + p->ps_reentry = MK_FP(0, 0x30 * 4); + /* unix style call - 0xcd 0x21 0xcb (int 21, retf) */ + p->ps_unix[0] = 0xcd; + p->ps_unix[1] = 0x21; + p->ps_unix[2] = 0xcb; + + /* Now for parent-child relationships */ + /* parent psp segment */ + p->ps_parent = FP_SEG(p); + /* previous psp pointer */ + p->ps_prevpsp = MK_FP(0xffff,0xffff); + + /* Environment and memory useage parameters */ + /* memory size in paragraphs */ + /* p->ps_size = 0; clear from above */ + /* environment paragraph */ + p->ps_environ = DOS_PSP + 8; + /* terminate address */ + p->ps_isv22 = getvec(0x22); + /* break address */ + p->ps_isv23 = getvec(0x23); + /* critical error address */ + p->ps_isv24 = getvec(0x24); + + /* user stack pointer - int 21 */ + /* p->ps_stack = NULL; clear from above */ + + /* File System parameters */ + /* maximum open files */ + p->ps_maxfiles = 20; + fmemset(p->ps_files, 0xff, 20); + + /* open file table pointer */ + p->ps_filetab = p->ps_files; + + /* first command line argument */ + /* p->ps_fcb1.fcb_drive = 0; already set */ + fmemset(p->ps_fcb1.fcb_fname, ' ', FNAME_SIZE + FEXT_SIZE); + /* second command line argument */ + /* p->ps_fcb2.fcb_drive = 0; already set */ + fmemset(p->ps_fcb2.fcb_fname, ' ', FNAME_SIZE + FEXT_SIZE); + + /* local command line */ + /* p->ps_cmd.ctCount = 0; command tail, already set */ + p->ps_cmd.ctBuffer[0] = 0xd; /* command tail */ +} + + STATIC void init_kernel(void) { COUNT i; @@ -196,8 +257,7 @@ STATIC void init_kernel(void) init_PSPSet(DOS_PSP); set_DTA(MK_FP(DOS_PSP, 0x80)); - init_PSPInit(DOS_PSP); - ((psp far *)MK_FP(DOS_PSP, 0))->ps_environ = DOS_PSP + 8; + PSPInit(); Init_clk_driver(); diff --git a/kernel/proto.h b/kernel/proto.h index a7d59e0..25dbd0d 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -339,7 +339,8 @@ const UWORD *is_leap_year_monthdays(UWORD year); UWORD DaysFromYearMonthDay(UWORD Year, UWORD Month, UWORD DayOfMonth); /* task.c */ -VOID new_psp(seg para, int psize); +VOID new_psp(seg para, seg cur_psp); +VOID child_psp(seg para, seg cur_psp, int psize); VOID return_user(void); COUNT DosExec(COUNT mode, exec_blk FAR * ep, BYTE FAR * lp); ULONG SftGetFsize(int sft_idx); diff --git a/kernel/task.c b/kernel/task.c index 11d19a6..32b6942 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -165,26 +165,29 @@ STATIC COUNT ChildEnv(exec_blk * exp, UWORD * pChildEnvSeg, char far * pathname) } /* The following code is 8086 dependant */ -void new_psp(seg para, int psize) +void new_psp(seg para, seg cur_psp) { psp FAR *p = MK_FP(para, 0); - psp FAR *q = MK_FP(cu_psp, 0); + + fmemcpy(p, MK_FP(cur_psp, 0), sizeof(psp)); + + /* terminate address */ + p->ps_isv22 = getvec(0x22); + /* break address */ + p->ps_isv23 = getvec(0x23); + /* critical error address */ + p->ps_isv24 = getvec(0x24); + /* parent psp segment set to 0 (see RBIL int21/ah=26) */ + p->ps_parent = 0; +} + +void child_psp(seg para, seg cur_psp, int psize) +{ + psp FAR *p = MK_FP(para, 0); + psp FAR *q = MK_FP(cur_psp, 0); int i; - - /* Clear out new psp first */ - fmemset(p, 0, sizeof(psp)); - /* initialize all entries and exits */ - /* CP/M-like exit point */ - p->ps_exit = 0x20cd; - - /* CP/M-like entry point - call far to special entry */ - p->ps_farcall = 0x9a; - p->ps_reentry = MK_FP(0, 0x30 * 4); - /* unix style call - 0xcd 0x21 0xcb (int 21, retf) */ - p->ps_unix[0] = 0xcd; - p->ps_unix[1] = 0x21; - p->ps_unix[2] = 0xcb; + new_psp(para, cur_psp); /* Now for parent-child relationships */ /* parent psp segment */ @@ -195,17 +198,6 @@ void new_psp(seg para, int psize) /* Environment and memory useage parameters */ /* memory size in paragraphs */ p->ps_size = psize; - /* environment paragraph */ - /* p->ps_environ = 0; cleared above */ - /* terminate address */ - p->ps_isv22 = getvec(0x22); - /* break address */ - p->ps_isv23 = getvec(0x23); - /* critical error address */ - p->ps_isv24 = getvec(0x24); - - /* user stack pointer - int 21 */ - p->ps_stack = q->ps_stack; /* File System parameters */ /* maximum open files */ @@ -221,14 +213,14 @@ void new_psp(seg para, int psize) p->ps_files[i] = q->ps_filetab[i]; /* first command line argument */ - /* p->ps_fcb1.fcb_drive = 0; already set */ + p->ps_fcb1.fcb_drive = 0; fmemset(p->ps_fcb1.fcb_fname, ' ', FNAME_SIZE + FEXT_SIZE); /* second command line argument */ - /* p->ps_fcb2.fcb_drive = 0; already set */ + p->ps_fcb2.fcb_drive = 0; fmemset(p->ps_fcb2.fcb_fname, ' ', FNAME_SIZE + FEXT_SIZE); /* local command line */ - /* p->ps_cmd.ctCount = 0; command tail, already set */ + p->ps_cmd.ctCount = 0; p->ps_cmd.ctBuffer[0] = 0xd; /* command tail */ } @@ -490,7 +482,7 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd) /* point to the PSP so we can build it */ setvec(0x22, MK_FP(user_r->CS, user_r->IP)); - new_psp(mem, mem + asize); + child_psp(mem, cu_psp, mem + asize); fcbcode = patchPSP(mem - 1, env, exp, namep); /* set asize to end of segment */ @@ -742,7 +734,7 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd) /* point to the PSP so we can build it */ setvec(0x22, MK_FP(user_r->CS, user_r->IP)); - new_psp(mem, mem + asize); + child_psp(mem, cu_psp, mem + asize); fcbcode = patchPSP(mem - 1, env, exp, namep); exp->exec.stack =