FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MS-DOS-kernel/kernel/config.c at master · Programuserbash/MS-DOS-kernel · GitHub
Programuserbash
/
MS-DOS-kernel
Public
forked from
FDOS/kernel
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MS-DOS-kernel
/
kernel
/
config.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
2788 lines (2369 loc) · 71.3 KB
Breadcrumbs
MS-DOS-kernel
/
kernel
/
config.c
Copy path
File metadata and controls
2788 lines (2369 loc) · 71.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************/
/* */
/* config.c */
/* DOS-C */
/* */
/* config.sys Processing Functions */
/* */
/* Copyright (c) 1996 */
/* Pasquale J. Villani */
/* All Rights Reserved */
/* */
/* This file is part of DOS-C. */
/* */
/* DOS-C is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version */
/* 2, or (at your option) any later version. */
/* */
/* DOS-C is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public */
/* License along with DOS-C; see the file COPYING. If not, */
/* write to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
/****************************************************************/
#include
"portab.h"
#include
"init-mod.h"
#include
"dyndata.h"
#include
"debug.h"
#define
para2far
(
seg
) ((mcb FAR *)MK_FP((seg), 0))
/**
Menu selection bar struct:
x pos, ypos, string
*/
#define
MENULINEMAX
80
#define
MENULINESMAX
10
struct
MenuSelector
{
int
x
;
int
y
;
BYTE
bSelected
;
BYTE
Text
[
MENULINEMAX
];
};
/** Structure below holds the menu-strings */
STATIC
struct
MenuSelector
MenuStruct
[
MENULINESMAX
]
BSS_INIT
({
0
});
int
nMenuLine
BSS_INIT
(
0
);
int
MenuColor
=
-1
;
extern
char
ASM
kernel_command_line
[
256
];
extern
int
kernel_command_line_length
;
STATIC
void
WriteMenuLine
(
struct
MenuSelector
*
menu
)
{
iregs
r
;
unsigned
char
attr
=
(
unsigned
char
)
MenuColor
;
char
*
pText
=
menu
->
Text
;
if
(
pText
[
0
]
==
0
)
return
;
if
(
menu
->
bSelected
)
attr
=
((
attr
<<
4
) | (
attr
>>
4
));
/* clear line */
r
.
a
.
x
=
0x0600
;
r
.
b
.
b
.
h
=
attr
;
r
.
c
.
b
.
l
=
r
.
d
.
b
.
l
=
menu
->
x
;
r
.
c
.
b
.
h
=
r
.
d
.
b
.
h
=
menu
->
y
;
r
.
d
.
b
.
l
+=
strlen
(
pText
)
-
1
;
init_call_intr
(
0x10
,
&
r
);
/* set cursor position: */
r
.
a
.
b
.
h
=
0x02
;
r
.
b
.
b
.
h
=
0
;
r
.
d
.
b
.
l
=
menu
->
x
;
r
.
d
.
b
.
h
=
menu
->
y
;
init_call_intr
(
0x10
,
&
r
);
printf
(
"%s"
,
pText
);
}
/* Deselect the previously selected line */
STATIC
void
DeselectLastLine
(
void
)
{
struct
MenuSelector
*
menu
;
for
(
menu
=
MenuStruct
;
menu
<
&
MenuStruct
[
MENULINESMAX
];
menu
++
)
{
if
(
menu
->
bSelected
)
{
/* deselect it: */
menu
->
bSelected
=
0
;
WriteMenuLine
(
menu
);
break
;
}
}
}
STATIC
void
SelectLine
(
int
MenuSelected
)
{
struct
MenuSelector
*
menu
;
DeselectLastLine
();
/* clear previous selection */
menu
=
&
MenuStruct
[
MenuSelected
];
menu
->
bSelected
=
1
;
/* set selection flag for this one */
WriteMenuLine
(
menu
);
}
UWORD
umb_start
BSS_INIT
(
0
),
UMB_top
BSS_INIT
(
0
);
UWORD
ram_top
BSS_INIT
(
0
);
/* How much ram in Kbytes */
size_t
ebda_size
BSS_INIT
(
0
);
static
UBYTE
ErrorAlreadyPrinted
[
128
]
BSS_INIT
({
0
});
static
char
FAR
*
envp
=
master_env
;
struct
config
Config
=
{
0
,
NUMBUFF
,
NFILES
,
0
,
NFCBS
,
0
,
"command.com"
,
" /P /E:256\r\n"
,
NLAST
,
0
,
NSTACKS
,
0
,
STACKSIZE
/* COUNTRY= is initialized within DoConfig() */
,
0
/* strategy for command.com is low by default */
,
0
/* default value for switches=/E:nnnn */
};
STATIC
seg
base_seg
BSS_INIT
(
0
);
STATIC
seg
umb_base_seg
BSS_INIT
(
0
);
BYTE
FAR
*
lpTop
BSS_INIT
(
0
);
STATIC
unsigned
nCfgLine
BSS_INIT
(
0
);
COUNT
UmbState
BSS_INIT
(
0
);
STATIC
BYTE
szLine
[
256
]
BSS_INIT
({
0
});
STATIC
BYTE
szBuf
[
256
]
BSS_INIT
({
0
});
#define
MAX_CHAINS
5
struct
CfgFile
{
COUNT
nFileDesc
;
COUNT
nCfgLine
;
}
cfgFile
[
MAX_CHAINS
]
BSS_INIT
({
0
});
COUNT
nCurChain
BSS_INIT
(
0
);
COUNT
nFileDesc
BSS_INIT
(
0
);
BYTE
singleStep
BSS_INIT
(FALSE);
/* F8 processing */
BYTE
SkipAllConfig
BSS_INIT
(FALSE);
/* F5 processing */
BYTE
askThisSingleCommand
BSS_INIT
(FALSE);
/* ?device= device?= */
BYTE
DontAskThisSingleCommand
BSS_INIT
(FALSE);
/* !files= */
COUNT
MenuTimeout
=
-1
;
BYTE
MenuSelected
BSS_INIT
(
0
);
UCOUNT
MenuLine
BSS_INIT
(
0
);
UCOUNT
Menus
BSS_INIT
(
0
);
STATIC
VOID
CfgMenuColor
(
BYTE
*
pLine
);
STATIC
VOID
Config_Buffers
(
BYTE
*
pLine
);
STATIC
VOID
CfgBuffersHigh
(
BYTE
*
pLine
);
STATIC
VOID
sysScreenMode
(
BYTE
*
pLine
);
STATIC
VOID
sysVersion
(
BYTE
*
pLine
);
STATIC
VOID
CfgBreak
(
BYTE
*
pLine
);
STATIC
VOID
Device
(
BYTE
*
pLine
);
STATIC
VOID
DeviceHigh
(
BYTE
*
pLine
);
STATIC
VOID
Files
(
BYTE
*
pLine
);
STATIC
VOID
FilesHigh
(
BYTE
*
pLine
);
STATIC
VOID
Fcbs
(
BYTE
*
pLine
);
STATIC
VOID
CfgKeyBuf
(
BYTE
*
pLine
);
STATIC
VOID
CfgLastdrive
(
BYTE
*
pLine
);
STATIC
VOID
CfgLastdriveHigh
(
BYTE
*
pLine
);
STATIC
BOOL
LoadDevice
(
BYTE
*
pLine
,
char
FAR
*
top
,
COUNT
mode
);
STATIC
VOID
Dosmem
(
BYTE
*
pLine
);
STATIC
VOID
DosData
(
BYTE
*
pLine
);
STATIC
VOID
Country
(
BYTE
*
pLine
);
STATIC
VOID
InitPgm
(
BYTE
*
pLine
);
STATIC
VOID
InitPgmHigh
(
BYTE
*
pLine
);
STATIC
VOID
CmdInstall
(
BYTE
*
pLine
);
STATIC
VOID
CmdInstallHigh
(
BYTE
*
pLine
);
STATIC
VOID
CmdChain
(
BYTE
*
pLine
);
STATIC
VOID
CmdSet
(
BYTE
*
pLine
);
STATIC
VOID
CfgSwitchar
(
BYTE
*
pLine
);
STATIC
VOID
CfgSwitches
(
BYTE
*
pLine
);
STATIC
VOID
CfgFailure
(
BYTE
*
pLine
);
STATIC
VOID
CfgIgnore
(
BYTE
*
pLine
);
STATIC
VOID
CfgMenu
(
BYTE
*
pLine
);
STATIC
VOID
CfgMenuEsc
(
BYTE
*
pLine
);
STATIC
VOID
DoMenu
(
void
);
STATIC
VOID
CfgMenuDefault
(
BYTE
*
pLine
);
STATIC
BYTE
*
skipwh
(
BYTE
*
s
);
STATIC
int
iswh
(
unsigned
char
c
);
STATIC
BYTE
*
scan
(
BYTE
*
s
,
BYTE
*
d
,
int
fMenuSelect
);
STATIC
BOOL
isnum
(
char
ch
);
#if
0
STATIC
COUNT
tolower
(
COUNT
c
);
#endif
STATIC
char
toupper
(
char
c
);
STATIC
VOID
strupr
(
char
*
s
);
STATIC
VOID
mcb_init
(
UCOUNT
seg
,
UWORD
size
,
BYTE
type
);
STATIC
VOID
mumcb_init
(
UCOUNT
seg
,
UWORD
size
);
STATIC
VOID
Stacks
(
BYTE
*
pLine
);
STATIC
VOID
StacksHigh
(
BYTE
*
pLine
);
STATIC
VOID
SetAnyDos
(
BYTE
*
pLine
);
STATIC
VOID
SetIdleHalt
(
BYTE
*
pLine
);
STATIC
VOID
Numlock
(
BYTE
*
pLine
);
STATIC
BYTE
*
GetNumArg
(
BYTE
*
pLine
,
COUNT
*
pnArg
);
BYTE
*
GetStringArg
(
BYTE
*
pLine
,
BYTE
*
pszString
);
STATIC
int
SkipLine
(
char
*
pLine
);
#if
0
STATIC
char
*
stristr
(
char
*
s1
,
char
*
s2
);
#endif
STATIC
char
strcaseequal
(
const
char
*
d
,
const
char
*
s
);
STATIC
int
LoadCountryInfoHardCoded
(
COUNT
ctryCode
);
STATIC
void
umb_init
(
void
);
void
HMAconfig
(
int
finalize
);
STATIC
void
config_init_buffers
(
int
anzBuffers
);
/* from BLOCKIO.C */
#ifdef
I86
STATIC
VOID
FAR
*
AlignParagraph
(
VOID
FAR
*
lpPtr
);
#else
#define
AlignParagraph
(
x
) ((VOID *)x)
#endif
#define
EOF
0x1a
STATIC
struct
table
*
LookUp
(
struct
table
*
p
,
BYTE
*
token
);
typedef
void
config_sys_func_t
(
BYTE
*
pLine
);
struct
table
{
BYTE
*
entry
;
signed
char
pass
;
config_sys_func_t
*
func
;
};
STATIC
struct
table
commands
[]
=
{
/* first = switches! this one is special; some options will
always be ran, others depends on F5/F8 and ? processing */
{
"SWITCHES"
,
0
,
CfgSwitches
},
/* rem is never executed by locking out pass */
{
"REM"
,
0
,
CfgIgnore
},
{
";"
,
0
,
CfgIgnore
},
{
"MENUCOLOR"
,
0
,
CfgMenuColor
},
{
"MENUDEFAULT"
,
0
,
CfgMenuDefault
},
{
"MENU"
,
0
,
CfgMenu
},
/* lines to print in pass 0 */
{
"ECHO"
,
2
,
CfgMenu
},
/* lines to print in pass 2 - install(high) */
{
"EECHO"
,
2
,
CfgMenuEsc
},
/* modified ECHO (ea) */
{
"BREAK"
,
1
,
CfgBreak
},
{
"BUFFERS"
,
1
,
Config_Buffers
},
{
"BUFFERSHIGH"
,
1
,
CfgBuffersHigh
},
/* as BUFFERS - we use HMA anyway */
{
"COMMAND"
,
1
,
InitPgm
},
{
"COUNTRY"
,
1
,
Country
},
{
"DOS"
,
1
,
Dosmem
},
{
"DOSDATA"
,
1
,
DosData
},
{
"FCBS"
,
1
,
Fcbs
},
{
"KEYBUF"
,
1
,
CfgKeyBuf
},
/* ea */
{
"FILES"
,
1
,
Files
},
{
"FILESHIGH"
,
1
,
FilesHigh
},
{
"LASTDRIVE"
,
1
,
CfgLastdrive
},
{
"LASTDRIVEHIGH"
,
1
,
CfgLastdriveHigh
},
{
"NUMLOCK"
,
1
,
Numlock
},
{
"SHELL"
,
1
,
InitPgm
},
{
"SHELLHIGH"
,
1
,
InitPgmHigh
},
{
"STACKS"
,
1
,
Stacks
},
{
"STACKSHIGH"
,
1
,
StacksHigh
},
{
"SWITCHAR"
,
1
,
CfgSwitchar
},
{
"SCREEN"
,
1
,
sysScreenMode
},
/* JPP */
{
"VERSION"
,
1
,
sysVersion
},
/* JPP */
{
"ANYDOS"
,
1
,
SetAnyDos
},
/* tom */
{
"IDLEHALT"
,
1
,
SetIdleHalt
},
/* ea */
{
"DEVICE"
,
2
,
Device
},
{
"DEVICEHIGH"
,
2
,
DeviceHigh
},
{
"INSTALL"
,
2
,
CmdInstall
},
{
"INSTALLHIGH"
,
2
,
CmdInstallHigh
},
{
"CHAIN"
,
2
,
CmdChain
},
{
"SET"
,
2
,
CmdSet
},
/* default action */
{
""
,
-1
,
CfgFailure
}
};
/* RE function for menu. */
int
findend
(
BYTE
*
s
)
{
int
nLen
=
0
;
/* 'marks' end if at least ten spaces, 0, or newline is found. */
while
(
*
s
&&
(
*
s
!=
0x0d
||
*
s
!=
0x0a
) )
{
BYTE
*
p
=
skipwh
(
s
);
/* ah, more than 9 whitespaces ? We're done here (hrmph!) */
if
(
p
-
s
>=
10
)
break
;
nLen
++
;
++
s
;
}
return
nLen
;
}
BYTE
*
pLineStart
BSS_INIT
(
0
);
BYTE
HMAState
BSS_INIT
(
0
);
#define
HMA_NONE
0
/* do nothing */
#define
HMA_REQ
1
/* DOS = HIGH detected */
#define
HMA_DONE
2
/* Moved kernel to HMA */
#define
HMA_LOW
3
/* Definitely LOW */
/* Do first time initialization. Store last so that we can reset it */
/* later. */
void
PreConfig
(
void
)
{
/* Initialize the base memory pointers */
CfgDbgPrintf
((
"SDA located at 0x%p\n"
,
internal_data
));
/* Begin by initializing our system buffers */
/* DebugPrintf(("Preliminary %d buffers allocated at 0x%p\n", Config.cfgBuffers, buffers));*/
LoL
->
sfthead
=
MK_FP
(
FP_SEG
(
LoL
),
0xcc
);
/* &(LoL->firstsftt) */
/* LoL->FCBp = (sfttbl FAR *)&FcbSft; */
/* LoL->FCBp = (sfttbl FAR *)
KernelAlloc(sizeof(sftheader)
+ Config.cfgFiles * sizeof(sft)); */
config_init_buffers
(
Config
.
cfgBuffers
);
LoL
->
CDSp
=
KernelAlloc
(
sizeof
(
struct
cds
)
*
LoL
->
lastdrive
,
'L'
,
0
);
/* CfgDbgPrintf((" FCB table 0x%p\n",LoL->FCBp));*/
CfgDbgPrintf
((
" sft table 0x%p\n"
,
LoL
->
sfthead
));
CfgDbgPrintf
((
" CDS table 0x%p\n"
,
LoL
->
CDSp
));
CfgDbgPrintf
((
" DPB table 0x%p\n"
,
LoL
->
DPBp
));
/* Done. Now initialize the MCB structure */
/* This next line is 8086 and 80x86 real mode specific */
CfgDbgPrintf
((
"Preliminary allocation completed: top at %p\n"
,
lpTop
));
}
/* Do second pass initialization: near allocation and MCBs */
void
PreConfig2
(
void
)
{
struct
sfttbl
FAR
*
sp
;
/* initialize NEAR allocated things */
/* Initialize the base memory pointers from last time. */
/*
if the kernel could be moved to HMA, everything behind the dynamic
near data is free.
otherwise, the kernel is moved down - behind the dynamic allocated data,
and allocation starts after the kernel.
*/
base_seg
=
LoL
->
first_mcb
=
FP_SEG
(
AlignParagraph
((
BYTE
FAR
*
)
DynLast
()
+
0x0f
));
if
(
Config
.
ebda2move
)
{
ebda_size
=
ebdasize
();
if
(
ebda_size
>
Config
.
ebda2move
)
ebda_size
=
Config
.
ebda2move
;
ram_top
+=
ebda_size
/
1024
;
}
/* We expect ram_top as Kbytes, so convert to paragraphs */
mcb_init
(
base_seg
,
ram_top
*
64
-
LoL
->
first_mcb
-
1
,
MCB_LAST
);
sp
=
LoL
->
sfthead
;
sp
=
sp
->
sftt_next
=
KernelAlloc
(
sizeof
(
sftheader
)
+
3
*
sizeof
(
sft
),
'F'
,
0
);
sp
->
sftt_next
=
(
sfttbl
FAR
*
)
-
1
;
sp
->
sftt_count
=
3
;
if
(
ebda_size
)
/* move the Extended BIOS Data Area from top of RAM here */
movebda
(
ebda_size
,
FP_SEG
(
KernelAlloc
(
ebda_size
,
'I'
,
0
)));
/* if (UmbState == 2)
umb_init();
*/
}
/* Do third pass initialization. */
/* Also, run config.sys to load drivers. */
void
PostConfig
(
void
)
{
sfttbl
FAR
*
sp
;
/* We could just have loaded FDXMS or HIMEM */
if
(
HMAState
==
HMA_REQ
&&
MoveKernelToHMA
())
HMAState
=
HMA_DONE
;
if
(
Config
.
cfgDosDataUmb
)
{
Config
.
cfgFilesHigh
=
TRUE;
Config
.
cfgLastdriveHigh
=
TRUE;
Config
.
cfgStacksHigh
=
TRUE;
}
/* compute lastdrive ... */
LoL
->
lastdrive
=
Config
.
cfgLastdrive
;
if
(
LoL
->
lastdrive
<
LoL
->
nblkdev
)
LoL
->
lastdrive
=
LoL
->
nblkdev
;
CfgDbgPrintf
((
"starting FAR allocations at %x\n"
,
base_seg
));
/* Begin by initializing our system buffers */
/* dma_scratch = (BYTE FAR *) KernelAllocDma(BUFFERSIZE); */
/* DebugPrintf(("DMA scratchpad allocated at 0x%p\n", dma_scratch)); */
config_init_buffers
(
Config
.
cfgBuffers
);
/* LoL->sfthead = (sfttbl FAR *)&basesft; */
/* LoL->FCBp = (sfttbl FAR *)&FcbSft; */
/* LoL->FCBp = KernelAlloc(sizeof(sftheader)
+ Config.cfgFiles * sizeof(sft)); */
sp
=
LoL
->
sfthead
->
sftt_next
;
sp
=
sp
->
sftt_next
=
(
sfttbl
FAR
*
)
KernelAlloc
(
sizeof
(
sftheader
)
+
(
Config
.
cfgFiles
-
8
)
*
sizeof
(
sft
),
'F'
,
Config
.
cfgFilesHigh
);
sp
->
sftt_next
=
(
sfttbl
FAR
*
)
-
1
;
sp
->
sftt_count
=
Config
.
cfgFiles
-
8
;
LoL
->
CDSp
=
KernelAlloc
(
sizeof
(
struct
cds
)
*
LoL
->
lastdrive
,
'L'
,
Config
.
cfgLastdriveHigh
);
/* CfgDbgPrintf((" FCB table 0x%p\n",LoL->FCBp));*/
CfgDbgPrintf
((
" sft table 0x%p\n"
,
LoL
->
sfthead
->
sftt_next
));
CfgDbgPrintf
((
" CDS table 0x%p\n"
,
LoL
->
CDSp
));
CfgDbgPrintf
((
" DPB table 0x%p\n"
,
LoL
->
DPBp
));
if
(
Config
.
cfgStacks
)
{
VOID
FAR
*
stackBase
=
KernelAlloc
(
Config
.
cfgStacks
*
Config
.
cfgStackSize
,
'S'
,
Config
.
cfgStacksHigh
);
init_stacks
(
stackBase
,
Config
.
cfgStacks
,
Config
.
cfgStackSize
);
CfgDbgPrintf
((
"Stacks allocated at %p\n"
,
stackBase
));
}
CfgDbgPrintf
((
"Allocation completed: top at 0x%x\n"
,
base_seg
));
}
/* This code must be executed after device drivers has been loaded */
VOID
configDone
(
VOID
)
{
if
(
UmbState
==
1
)
para2far
(
base_seg
)
->
m_type
=
MCB_LAST
;
if
(
HMAState
!=
HMA_DONE
)
{
mcb
FAR
*
p
;
unsigned short
kernel_seg
;
unsigned short
hma_paras
=
(
HMAFree
+
0xf
)/
16
;
kernel_seg
=
allocmem
(
hma_paras
);
p
=
para2far
(
kernel_seg
-
1
);
p
->
m_name
[
0
]
=
'S'
;
p
->
m_name
[
1
]
=
'C'
;
p
->
m_psp
=
8
;
CfgDbgPrintf
((
"HMA not available, moving text to %x\n"
,
kernel_seg
));
MoveKernel
(
kernel_seg
);
kernel_seg
+=
hma_paras
+
1
;
CfgDbgPrintf
((
"kernel is low, start alloc at %x\n"
,
kernel_seg
));
}
/* The standard handles should be reopened here, because
we may have loaded new console or printer drivers in CONFIG.SYS */
}
STATIC
seg
prev_mcb
(
seg
cur_mcb
,
seg
start
)
{
/* determine prev mcb */
seg
mcb_prev
,
mcb_next
;
mcb_prev
=
mcb_next
=
start
;
while
(
mcb_next
<
cur_mcb
&&
para2far
(
mcb_next
)
->
m_type
==
MCB_NORMAL
)
{
mcb_prev
=
mcb_next
;
mcb_next
+=
para2far
(
mcb_prev
)
->
m_size
+
1
;
}
return
mcb_prev
;
}
STATIC
void
umb_init
(
void
)
{
UCOUNT
umb_seg
,
umb_size
;
seg
umb_max
;
void
far
*
xms_addr
;
if
((
xms_addr
=
DetectXMSDriver
())
==
NULL
)
return
;
if
(
UMB_get_largest
(
xms_addr
,
&
umb_seg
,
&
umb_size
))
{
UmbState
=
1
;
/* reset root */
/* Note: since device drivers can change what is considered top of memory (e.g. move XBDA) we must requery */
ram_top
=
init_oem
();
LoL
->
uppermem_root
=
ram_top
*
64
-
1
;
/* create link mcb (below) */
para2far
(
base_seg
)
->
m_type
=
MCB_NORMAL
;
para2far
(
base_seg
)
->
m_size
--
;
mumcb_init
(
LoL
->
uppermem_root
,
umb_seg
-
LoL
->
uppermem_root
-
1
);
/* setup the real mcb for the devicehigh block */
mcb_init
(
umb_seg
,
umb_size
-
2
,
MCB_NORMAL
);
umb_base_seg
=
umb_max
=
umb_start
=
umb_seg
;
UMB_top
=
umb_size
;
/* there can be more UMBs !
this happens, if memory mapped devces are in between
like UMB memory c800..c8ff, d8ff..efff with device at d000..d7ff
However some of the xxxHIGH commands still only work with
the first UMB.
*/
while
(
UMB_get_largest
(
xms_addr
,
&
umb_seg
,
&
umb_size
))
{
seg
umb_prev
,
umb_next
;
/* setup the real mcb for the devicehigh block */
mcb_init
(
umb_seg
,
umb_size
-
2
,
MCB_NORMAL
);
/* determine prev and next umbs */
umb_prev
=
prev_mcb
(
umb_seg
,
LoL
->
uppermem_root
);
umb_next
=
umb_prev
+
para2far
(
umb_prev
)
->
m_size
+
1
;
if
(
umb_seg
<
umb_max
)
{
if
(
umb_next
-
umb_seg
-
umb_size
==
0
)
{
/* should the UMB driver return
adjacent memory in several pieces */
umb_size
+=
para2far
(
umb_next
)
->
m_size
+
1
;
para2far
(
umb_seg
)
->
m_size
=
umb_size
;
}
else
{
/* create link mcb (above) */
mumcb_init
(
umb_seg
+
umb_size
-
1
,
umb_next
-
umb_seg
-
umb_size
);
}
}
else
/* umb_seg >= umb_max */
{
umb_prev
=
umb_next
;
}
if
(
umb_seg
-
umb_prev
-
1
==
0
)
/* should the UMB driver return
adjacent memory in several pieces */
para2far
(
prev_mcb
(
umb_prev
,
LoL
->
uppermem_root
))
->
m_size
+=
umb_size
;
else
{
/* create link mcb (below) */
mumcb_init
(
umb_prev
,
umb_seg
-
umb_prev
-
1
);
}
if
(
umb_seg
>
umb_max
)
umb_max
=
umb_seg
;
}
para2far
(
umb_max
)
->
m_size
++
;
para2far
(
umb_max
)
->
m_type
=
MCB_LAST
;
CfgDbgPrintf
((
"UMB Allocation completed: start at 0x%x\n"
,
umb_base_seg
));
}
}
#ifdef
MEMDISK_ARGS
struct
memdiskinfo
{
UWORD
bytes
;
/* Total size of this structure, value >= 26 */
UBYTE
version_minor
;
/* Memdisk minor version */
UBYTE
version
;
/* Memdisk major version */
UDWORD
base
;
/* Pointer to disk data in high memory */
UDWORD
size
;
/* Size of disk in 512 byte sectors */
char
FAR
*
cmdline
;
/* Command line; currently <= 2047 chars */
ADDRESS
oldint13
;
/* Old INT 13h */
ADDRESS
oldint15
;
/* Old INT 15h */
UWORD
olddosmem
;
/* Amount of DOS memory before Memdisk loaded */
UBYTE
boot_id
;
/* major >= 3, boot loader ID */
UBYTE
unused
;
UWORD
DPT_offset
;
/* >= 3.71, ES based offset to installed DPT, +16 is Old INT 1Eh */
};
/* query_memdisk() based on similar subroutine in Eric Auer's public domain getargs.asm which is based on IFMEMDSK */
struct
memdiskinfo
FAR
*
ASMCFUNC
query_memdisk
(
UBYTE
drive
);
struct
memdiskopt
{
BYTE
*
name
;
UWORD
size
;
};
/* preprocesses memdisk command line to allow simpler handling
{ is replaced by unsigned offset to start of next config line
e.g. "{{HI{HI}{HI{HI" --> "13HI4HI}3HI3HI"
FreeDOS supports max 256 length config lines, memdisk 4 max command length 2047
*/
BYTE
FAR
*
ProcessMemdiskLine
(
BYTE
FAR
*
cLine
)
{
BYTE
FAR
*
ptr
;
BYTE
FAR
*
sLine
=
cLine
;
/* skip everything until end of line or starting { */
for
(;
*
cLine
&&
(
*
cLine
!=
'{'
);
++
cLine
)
;
sLine
=
cLine
;
for
(
ptr
=
cLine
;
*
cLine
;
ptr
=
cLine
)
{
/* skip everything until end of line or starting { */
for
(
++
cLine
;
*
cLine
&&
(
*
cLine
!=
'{'
);
++
cLine
)
;
/* calc offset from previous { to next { or eol and replace previous { with offset */
*
ptr
=
(
BYTE
)(
cLine
-
ptr
);
}
return
sLine
;
}
/* Given a pointer to a memdisk command line and buffer will copy the next
config.sys equivalent line to pLine and return updated cLine.
Call repeatedly until end of string (*cLine == '\0').
Each simulated line is indicated be enclosing the line in curly braces {}
with the end } optional - the next { will indicate end/beginning and
end of line. MEMDISK options may appear nearly anywhere on line and are
ignored - see memdisk_opts for list of recognized options.
*/
BYTE
FAR
*
GetNextMemdiskLine
(
BYTE
FAR
*
cLine
,
BYTE
*
pLine
)
{
STATIC
struct
memdiskopt
memdiskopts
[]
=
{
{
"initrd"
,
6
}, {
"BOOT_IMAGE"
,
10
},
{
"floppy"
,
6
}, {
"harddisk"
,
8
}, {
"iso"
,
3
},
{
"nopass"
,
6
}, {
"nopassany"
,
9
},
{
"edd"
,
3
}, {
"noedd"
,
5
}
/*
{"c", 1}, {"h", 1}, {"s", 1},
{"raw", 3}, {"bigraw", 6}, {"int", 3}, {"safeint", 7}
*/
};
int
ws
=
TRUE;
/* treat start of line same as if whitespace seen */
BYTE
FAR
*
mf
=
NULL
;
/* where last line split by memdisk option */
BYTE
FAR
*
ptr
=
cLine
;
/* start of current cfg line, where { was */
BYTE
FAR
*
sLine
=
cLine
;
/* exit early if already at end of command line */
if
(!
*
cLine
)
return
cLine
;
/* point to start of next line; terminates current line if no } found before here */
cLine
+=
*
cLine
;
/* restore original character we overwrite with offset, for next iteration of cfg file */
*
ptr
=
'{'
;
/* ASSERT ptr points to start of line { and cLine points to start of next line { (or eol)*/
/* copy chars to pLine buffer until } or start of next line */
for
(
++
ptr
; (
*
ptr
!=
'}'
)
&&
(
ptr
<
cLine
);
++
ptr
)
{
/* if not in last {} then simply copy chars up to } (or next {) */
if
(
*
cLine
) goto
copy_char
;
/* otherwise if last character was whitespace (or start of line) check for memdisk option to skip */
if
(
ws
)
{
int
i
;
for
(
i
=
0
;
i
<
9
;
++
i
)
{
/* compare with option */
if
(
fmemcmp
(
ptr
,
memdiskopts
[
i
].
name
,
memdiskopts
[
i
].
size
)
==
0
)
{
BYTE
c
=
*
(
ptr
+
memdiskopts
[
i
].
size
);
/* ensure character after is end of line, =, or whitespace */
if
(!
c
||
(
c
==
'='
)
||
iswh
(
c
))
{
/* flag this line split */
mf
=
ptr
;
/* matched option so point past it */
ptr
+=
memdiskopts
[
i
].
size
;
/* allow extra whitespace between option and = by skipping it */
while
(
iswh
(
*
ptr
))
++
ptr
;
/* if option has = value then skip it as well */
if
(
*
ptr
==
'='
)
{
/* allow extra whitespace between = and value by skipping it */
while
(
iswh
(
*
ptr
))
++
ptr
;
/* skip past all characters after = */
for
(; (
*
ptr
!=
'}'
)
&&
(
ptr
<
cLine
)
&&
!
iswh
(
*
ptr
);
++
ptr
)
;
}
break
;
/* memdisk option found, no need to keep check rest in list */
}
}
}
}
if
(
ptr
<
cLine
)
{
ws
=
iswh
(
*
ptr
);
/* allow replacing X=Y prior to memdisk options with X=Z after */
/* on 1st pass if find a match we overwrite it with spaces */
if
(
mf
&&
(
*
ptr
==
'='
))
{
BYTE
FAR
*
old
=
sLine
,
FAR
*
new
;
/* check for = in command line */
for
(;
old
<
mf
;
++
old
)
{
for
(; (
*
old
!=
'='
)
&&
(
old
<
mf
);
++
old
)
;
/* ASSERT ptr points to = after memdisk option and old points to = before memdisk option or mf */
/* compare backwards to see if same option */
for
(
new
=
ptr
; (
old
>=
sLine
)
&&
((
*
old
&
0xCD
)
==
(
*
new
&
0xCD
));
--
old
,
--
new
)
{
if
(
iswh
(
*
old
)
||
iswh
(
*
new
))
break
;
}
/* if match found then overwrite, otherwise skip past the = */
if
(((
old
<=
sLine
)
||
iswh
(
*
old
))
&&
iswh
(
*
new
))
{
/* match found so overwrite with spaces */
for
(
++
old
; !
iswh
(
*
old
)
&&
(
old
<
mf
);
++
old
)
*
old
=
' '
;
}
else
{
for
(; (
*
old
!=
'='
)
&&
(
old
<
mf
);
++
old
)
;
}
}
}
copy_char
:
*
pLine
=
*
ptr
;
++
pLine
;
}
}
*
pLine
=
0
;
/* return location to begin next scan from */
return
cLine
;
}
#endif
static
unsigned
check_config_commandline
(
char
*
*
pointer
,
char
*
cc
,
char
const
*
commandbuffer
,
char
const
*
command
);
static
unsigned
check_config_commandline
(
char
*
*
pointer
,
char
*
cc
,
char
const
*
commandbuffer
,
char
const
*
command
) {
unsigned
length
=
strlen
(
command
);
if
(
memcmp
(
commandbuffer
,
command
,
length
)
==
0
&&
(
commandbuffer
[
length
]
==
'\t'
||
commandbuffer
[
length
]
==
' '
||
commandbuffer
[
length
]
==
'='
||
commandbuffer
[
length
]
==
0
)) {
for
(
cc
+=
length
;
*
cc
==
'\t'
||
*
cc
==
' '
;
++
cc
);
if
(
*
cc
==
'='
)
++
cc
;
for
(;
*
cc
==
'\t'
||
*
cc
==
' '
;
++
cc
);
*
pointer
=
cc
;
return
1
;
}
return
0
;
}
VOID
DoConfig
(
int
nPass
)
{
BYTE
*
pLine
;
BOOL
bEof
=
FALSE;
#ifdef
MEMDISK_ARGS
/* check if MEMDISK used for LoL->BootDrive, if so check for special appended arguments */
struct
memdiskinfo
FAR
*
mdsk
=
NULL
;
BYTE
FAR
*
cLine
;
/* memdisk check & usage requires 386+, DO NOT invoke if less than 386 */
if
(
LoL
->
cpu
>=
3
)
{
UBYTE
drv
=
(
LoL
->
BootDrive
<
3
)?
0x0
:
0x80
;
/* 1=A,2=B,3=C */
mdsk
=
query_memdisk
(
drv
);
if
(
mdsk
!=
NULL
)
{
cLine
=
ProcessMemdiskLine
(
mdsk
->
cmdline
);
}
}
#endif
if
(
nPass
==
0
)
{
HaltCpuWhileIdle
=
0
;
/* init to "no HLT while idle" */
#ifdef
MEMDISK_ARGS
if
(
mdsk
!=
NULL
)
{
printf
(
"MEMDISK version %u.%02u (%lu sectors)\n"
,
mdsk
->
version
,
mdsk
->
version_minor
,
mdsk
->
size
);
CfgDbgPrintf
((
"MEMDISK args:{%S}\n"
,
mdsk
->
cmdline
));
}
else
{
CfgDbgPrintf
((
"MEMDISK not detected!\n"
));
}
#endif
}
{
char
*
pp
=
kernel_command_line
;
char
*
cc
;
unsigned
ii
;
static
char
commandbuffer
[
256
];
char
*
end
=
&
kernel_command_line
[
kernel_command_line_length
];
static
char
*
configfile
=
""
;
static
char
*
altconfigfile
=
"fdconfig.sys"
;
static
char
*
oldconfigfile
=
"config.sys"
;
static
struct
{
char
*
*
pointer
;
char
const
*
command
; }
configcommands
[]
=
{
{
&
configfile
,
"CONFIG"
},
{
&
altconfigfile
,
"ALTCONFIG"
},
{
&
oldconfigfile
,
"OLDCONFIG"
},
{
NULL
,
NULL
}
};
for
(;
pp
<
end
;
pp
+=
strlen
(
pp
)
+
1
) {
for
(
cc
=
pp
;
*
cc
==
'\t'
||
*
cc
==
' '
;
++
cc
);
strcpy
(
commandbuffer
,
cc
);
strupr
(
commandbuffer
);
for
(
ii
=
0
;
configcommands
[
ii
].
pointer
!=
NULL
;
++
ii
)
if
(
check_config_commandline
(
configcommands
[
ii
].
pointer
,
cc
,
commandbuffer
,
configcommands
[
ii
].
command
))
break
;
}
/* Check to see if we have a config.sys file. If not, just */
/* exit since we don't force the user to have one (but 1st */
/* also process MEMDISK passed config options if present). */
for
(
ii
=
0
;
configcommands
[
ii
].
pointer
!=
NULL
;
++
ii
) {
if
(
*
*
configcommands
[
ii
].
pointer
!=
'\0'
) {
if
((
nFileDesc
=
open
(
*
configcommands
[
ii
].
pointer
,
0
)) >=
0
) {
CfgDbgPrintf
((
"Reading \"%s\"...\n"
,
*
configcommands
[
ii
].
pointer
));
break
;
}
else
{
CfgDbgPrintf
((
"\"%s\" not found\n"
,
*
configcommands
[
ii
].
pointer
));
}
}
}
if
(
configcommands
[
ii
].
pointer
==
NULL
) {
/* at this point no config file was found, may return early */
#ifdef
MEMDISK_ARGS
/* if memdisk in use then only assume end of file reached and proceed, else return early */
if
(
mdsk
!=
NULL
)
bEof
=
TRUE;
else
#endif
return
;
}
}
nCfgLine
=
0
;
/* keep track of which line in file for errors */
/* Read each line into the buffer and then parse the line, */
/* do the table lookup and execute the handler for that */
/* function. */
#ifdef
MEMDISK_ARGS
for
(; !
bEof
||
(
mdsk
!=
NULL
);
nCfgLine
++
)
#else
for
(; !
bEof
;
nCfgLine
++
)
#endif
{
struct
table
*
pEntry
;
pLineStart
=
szLine
;
#ifdef
MEMDISK_ARGS
if
(!
bEof
)
{
#endif
/* read in a single line, \n or ^Z terminated */
for
(
pLine
=
szLine
;;)
{
if
(
read
(
nFileDesc
,
pLine
,
1
)
==
0
)
{
bEof
=
TRUE;
break
;
}
if
(
pLine
>=
szLine
+
sizeof
(
szLine
)
-
3
)
{
CfgFailure
(
pLine
);
printf
(
"error - line overflow line %d \n"
,
nCfgLine
);
break
;
}
if
(
*
pLine
==
'\n'
||
*
pLine
==
EOF
)
/* end of line */
break
;
if
(
*
pLine
!=
'\r'
)
/* ignore CR */
pLine
++
;
}
*
pLine
=
0
;
#ifdef
MEMDISK_ARGS
}
else
if
(
mdsk
!=
NULL
)
{
cLine
=
GetNextMemdiskLine
(
cLine
,
szLine
);
/* if end of memdisk command line reached, flag done */
if
(!
*
cLine
)
mdsk
=
NULL
;
}
#endif
if
(
bEof
&&
nCurChain
) {
struct
CfgFile
*
cfg
=
&
cfgFile
[
--
nCurChain
];
close
(
nFileDesc
);
bEof
=
FALSE;
nFileDesc
=
cfg
->
nFileDesc
;
nCfgLine
=
cfg
->
nCfgLine
;
continue
;
}
CfgDbgPrintf
((
"CONFIG=[%s]\n"
,
szLine
));
/* Skip leading white space and get verb. */
pLine
=
scan
(
szLine
,
szBuf
,
1
);
/* If the line was blank, skip it. Otherwise, look up */
/* the verb and execute the appropriate function. */
if
(
*
szBuf
==
'\0'
)
continue
;
pEntry
=
LookUp
(
commands
,
szBuf
);
/* should config command be executed on this pass? */
if
(
pEntry
->
pass
>=
0
&&
pEntry
->
pass
!=
nPass
)
continue
;
/* pass 0 always executed (rem Menu prompt switches) */
if
(
nPass
==
0
)
{
pEntry
->
func
(
pLine
);
continue
;
}
else
{
if
(
SkipLine
(
pLineStart
))
/* F5/F8/?/! processing */
continue
;
}
if
((
pEntry
->
func
!=
CfgMenu
)
&&
(
pEntry
->
func
!=
CfgMenuEsc
))
{
/* compatibility "device foo.sys" */
if
(
' '
!=
*
pLine
&&
'\t'
!=
*
pLine
&&
'='
!=
*
pLine
)
{
CfgFailure
(
pLine
);
continue
;
}
pLine
=
skipwh
(
pLine
);
}
if
(
'='
==
*
pLine
||
pEntry
->
func
==
CfgMenu
||
pEntry
->
func
==
CfgMenuEsc
)
pLine
=
skipwh
(
pLine
+
1
);
/* YES. DO IT */
pEntry
->
func
(
pLine
);
}
close
(
nFileDesc
);
if
(
nPass
==
0
)
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL