-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathbios.c
1119 lines (935 loc) · 28 KB
/
bios.c
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
/*
* bios.c - C portion of BIOS initialization and front end
*
* Copyright (C) 2001 Lineo, Inc.
* Copyright (C) 2001-2017 The EmuTOS development team
*
* Authors:
* SCC Steve C. Cavender
* KTB Karl T. Braun (kral)
* JSL Jason S. Loveman
* EWF Eric W. Fleischman
* LTG Louis T. Garavaglia
* MAD Martin Doering
* LVL Laurent Vogel
*
* This file is distributed under the GPL, version 2 or at your
* option any later version. See doc/license.txt for details.
*/
/* #define ENABLE_KDEBUG */
#include "config.h"
#include "portab.h"
#include "biosext.h"
#include "bios.h"
#include "dos.h"
#include "pd.h"
#include "gemerror.h"
#include "kprint.h"
#include "tosvars.h"
#include "lineavars.h"
#include "vt52.h"
#include "processor.h"
#include "initinfo.h"
#include "machine.h"
#include "cookie.h"
#include "country.h"
#include "nls.h"
#include "biosmem.h"
#include "aespub.h"
#include "ikbd.h"
#include "mouse.h"
#include "midi.h"
#include "mfp.h"
#include "floppy.h"
#include "sound.h"
#include "dmasound.h"
#include "screen.h"
#include "clock.h"
#include "vectors.h"
#include "asm.h"
#include "chardev.h"
#include "blkdev.h"
#include "parport.h"
#include "serport.h"
#include "string.h"
#include "natfeat.h"
#include "delay.h"
#include "biosbind.h"
#include "memory.h"
#include "nova.h"
#ifdef MACHINE_AMIGA
#include "amiga.h"
#endif
#ifdef MACHINE_FIREBEE
#include "coldfire.h"
#endif
/*==== Defines ============================================================*/
#define DBGBIOS 0 /* If you want to enable debug wrappers */
#define ENABLE_RESET_RESIDENT 0 /* enable to run "reset-resident" code (see below) */
#define ENV_SIZE 20 /* sufficient for standard PATH=^X:\^^ (^=nul byte) */
#define DEF_PATH "C:\\" /* default value for path */
/*==== External declarations ==============================================*/
#if STONX_NATIVE_PRINT
extern void stonx_kprintf_init(void);
#endif
#if CONF_WITH_CARTRIDGE
extern void run_cartridge_applications(WORD typebit); /* found in startup.S */
#endif
#if WITH_CLI
extern void coma_start(void) NORETURN; /* found in cli/cmdasm.S */
#endif
#if CONF_WITH_ALT_RAM
extern long xmaddalt(UBYTE *start, long size); /* found in bdos/mem.h */
#endif
#if CONF_WITH_68040_PMMU
extern void setup_68040_pmmu(void);
#endif
/*==== Declarations =======================================================*/
/* Drive specific declarations */
static WORD defdrv; /* default drive number (0 is a:, 2 is c:) */
static BYTE default_env[ENV_SIZE]; /* default environment area */
/* used by kprintf() */
WORD boot_status; /* see kprint.h for bit flags */
/* Boot flags */
UBYTE bootflags;
/* Non-Atari hardware vectors */
#if !CONF_WITH_MFP
void (*vector_5ms)(void); /* 200 Hz system timer */
#endif
/*==== BOOT ===============================================================*/
/*
* setup all vectors
*/
static void vecs_init(void)
{
/* Initialize the exception vectors.
* By default, any unexpected exception calls dopanic().
*/
init_exc_vec();
init_user_vec();
/* Some user drivers may install interrupt handlers and call the previous
* ones. For example, ARAnyM's network driver for MiNT (nfeth.xif) and fVDI
* driver (aranym.sys) install custom handlers on INT3, and call the
* previous one. This panics with "Exception number 27" if VEC_LEVEL3 is
* not initialized with a valid default handler.
*/
VEC_LEVEL1 = just_rte;
VEC_LEVEL2 = just_rte;
VEC_LEVEL3 = just_rte;
VEC_LEVEL4 = just_rte;
VEC_LEVEL5 = just_rte;
VEC_LEVEL6 = just_rte;
VEC_LEVEL7 = just_rte;
#ifdef __mcoldfire__
/* On ColdFire, when a zero divide exception occurs, the PC value in the
* exception frame points to the offending instruction, not the next one.
* If we put a simple rte in the exception handler, this will result in
* an endless loop.
* New ColdFire programs are supposed to be clean and avoid zero
* divides. So we keep the default panic() behaviour in such case. */
#else
/* Original TOS cowardly ignores integer divide by zero. */
VEC_DIVNULL = just_rte;
#endif
/* initialise some vectors we really need */
VEC_AES = gemtrap;
VEC_BIOS = biostrap;
VEC_XBIOS = xbiostrap;
VEC_LINEA = int_linea;
/* Emulate some instructions unsupported by the processor. */
#ifdef __mcoldfire__
/* On ColdFire, all the unsupported assembler instructions
* will be emulated by a specific emulation layer loaded later. */
#else
if (longframe) {
/* On 68010+, "move from sr" called from user mode causes a
* privilege violation. This instruction must be emulated for
* compatibility with 68000 processors. */
VEC_PRIVLGE = int_priv;
} else {
/* On 68000, "move from ccr" is unsupported and causes an illegal
* instruction exception. This instruction must be emulated for
* compatibility with higher processors. */
VEC_ILLEGAL = int_illegal;
}
#endif
#if CONF_WITH_ADVANCED_CPU
/* On the 68060, instructions that were implemented in earlier
* processors but not in the 68060 cause this trap to be taken,
* for the purposes of emulation. The only instruction currently
* emulated is movep; fortunately this is both the simplest and
* commonest.
*/
VEC_UNIMPINT = int_unimpint;
#endif
}
/*
* Initialize the BIOS
*/
static void bios_init(void)
{
KDEBUG(("bios_init()\n"));
/* initialize Native Features, if available
* do it as soon as possible so that kprintf can make use of them
*/
#if DETECT_NATIVE_FEATURES
KDEBUG(("natfeat_init()\n"));
natfeat_init();
#endif
#if STONX_NATIVE_PRINT
KDEBUG(("stonx_kprintf_init()\n"));
stonx_kprintf_init();
#endif
#if CONF_WITH_UAE
KDEBUG(("amiga_uaelib_init()\n"));
amiga_uaelib_init();
#endif
/* Initialize the processor */
KDEBUG(("processor_init()\n"));
processor_init(); /* Set CPU type, longframe and FPU type */
#if CONF_WITH_ADVANCED_CPU
is_bus32 = (UBYTE)detect_32bit_address_bus();
#endif
KDEBUG(("Address Bus width is %d-bit\n", IS_BUS32 ? 32 : 24));
KDEBUG(("vecs_init()\n"));
vecs_init(); /* setup all exception vectors (above) */
KDEBUG(("init_delay()\n"));
init_delay(); /* set 'reasonable' default values for delay */
/* Detect optional hardware (video, sound, etc.) */
KDEBUG(("machine_detect()\n"));
machine_detect(); /* detect hardware */
KDEBUG(("machine_init()\n"));
machine_init(); /* initialise machine-specific stuff */
#if CONF_WITH_68040_PMMU
/*
* Initialize the 68040 MMU
* Must be done after TT-RAM memory detection (which takes place
* in machine_detect() above).
*/
if (mcpu == 40)
setup_68040_pmmu();
#endif /* CONF_WITH_68040_PMMU */
/* Initialize the BIOS memory management */
KDEBUG(("bmem_init()\n"));
bmem_init();
/* Initialize the screen */
KDEBUG(("screen_init()\n"));
screen_init(); /* detect monitor type, ... */
KDEBUG(("cookie_init()\n"));
cookie_init(); /* sets a cookie jar */
KDEBUG(("fill_cookie_jar()\n"));
fill_cookie_jar(); /* detect hardware features and fill the cookie jar */
/* Set up the BIOS console output */
KDEBUG(("linea_init()\n"));
linea_init(); /* initialize screen related line-a variables */
font_init(); /* initialize font ring (requires cookie_akp) */
font_set_default(-1);/* set default font */
vt52_init(); /* initialize the vt52 console */
/* Now kcprintf() will also send debug info to the screen */
KDEBUG(("after vt52_init()\n"));
/* misc. variables */
dumpflg = -1;
sysbase = (LONG) os_entry;
savptr = (LONG) trap_save_area;
etv_timer = (void(*)(int)) just_rts;
etv_critic = default_etv_critic;
etv_term = just_rts;
/* setup VBL queue */
nvbls = 8;
vblqueue = vbl_list;
{
int i;
for(i = 0 ; i < 8 ; i++) {
vbl_list[i] = 0;
}
}
#if CONF_WITH_MFP
KDEBUG(("mfp_init()\n"));
mfp_init();
#endif
#if CONF_WITH_TT_MFP
if (has_tt_mfp)
{
KDEBUG(("tt_mfp_init()\n"));
tt_mfp_init();
}
#endif
/* Initialize the system 200 Hz timer */
KDEBUG(("init_system_timer()\n"));
init_system_timer();
/* Initialize the RS-232 port(s) */
KDEBUG(("chardev_init()\n"));
chardev_init(); /* Initialize low-memory bios vectors */
boot_status |= CHARDEV_AVAILABLE; /* track progress */
KDEBUG(("init_serport()\n"));
init_serport();
boot_status |= RS232_AVAILABLE; /* track progress */
#if CONF_WITH_SCC
if (has_scc)
boot_status |= SCC_AVAILABLE; /* track progress */
#endif
/* The sound init must be done before allowing MFC interrupts,
* because of dosound stuff in the timer C interrupt routine.
*/
#if CONF_WITH_DMASOUND
KDEBUG(("dmasound_init()\n"));
dmasound_init();
#endif
KDEBUG(("snd_init()\n"));
snd_init(); /* Reset Soundchip, deselect floppies */
/* Init the two ACIA devices (MIDI and KBD). The three actions below can
* be done in any order provided they happen before allowing MFP
* interrupts.
*/
KDEBUG(("kbd_init()\n"));
kbd_init(); /* init keyboard, disable mouse and joystick */
KDEBUG(("midi_init()\n"));
midi_init(); /* init MIDI acia so that kbd acia irq works */
KDEBUG(("init_acia_vecs()\n"));
init_acia_vecs(); /* Init the ACIA interrupt vector and related stuff */
KDEBUG(("after init_acia_vecs()\n"));
boot_status |= MIDI_AVAILABLE; /* track progress */
/* Now we can enable the interrupts.
* We need a timer for DMA timeouts in floppy and harddisk initialisation.
* The VBL processing will be enabled later with the vblsem semaphore.
*/
#if CONF_WITH_ATARI_VIDEO
/* Keep the HBL disabled */
set_sr(0x2300);
#else
set_sr(0x2000);
#endif
KDEBUG(("calibrate_delay()\n"));
calibrate_delay(); /* determine values for delay() function */
/* - requires interrupts to be enabled */
KDEBUG(("blkdev_init()\n"));
blkdev_init(); /* floppy and harddisk initialisation */
KDEBUG(("after blkdev_init()\n"));
/* initialize BIOS components */
KDEBUG(("parport_init()\n"));
parport_init(); /* parallel port */
//mouse_init(); /* init mouse driver */
KDEBUG(("clock_init()\n"));
clock_init(); /* init clock */
KDEBUG(("after clock_init()\n"));
#if CONF_WITH_NOVA
/* Detect and initialize a Nova card, skip if Ctrl is pressed */
if (has_nova && !(kbshift(-1) & MODE_CTRL)) {
KDEBUG(("init_nova()\n"));
if (init_nova()) {
set_rez_hacked();
font_set_default(-1); /* set default font */
vt52_init(); /* initialize the vt52 console */
}
}
#endif
#if CONF_WITH_NLS
KDEBUG(("nls_init()\n"));
nls_init(); /* init native language support */
nls_set_lang(get_lang_name());
#endif
/* set start of user interface */
#if WITH_AES
exec_os = ui_start;
#elif WITH_CLI
exec_os = coma_start;
#else
exec_os = NULL;
#endif
KDEBUG(("osinit_before_xmaddalt()\n"));
osinit_before_xmaddalt(); /* initialize BDOS (part 1) */
KDEBUG(("after osinit_before_xmaddalt()\n"));
#if CONF_WITH_ALT_RAM
/* Add Alt-RAM to BDOS pool */
KDEBUG(("altram_init()\n"));
altram_init();
#endif
KDEBUG(("osinit_after_xmaddalt()\n"));
osinit_after_xmaddalt(); /* initialize BDOS (part 2) */
KDEBUG(("after osinit_after_xmaddalt()\n"));
boot_status |= DOS_AVAILABLE; /* track progress */
/* Enable VBL processing */
vblsem = 1;
#if CONF_WITH_CARTRIDGE
{
WORD save_hz = V_REZ_HZ, save_vt = V_REZ_VT, save_pl = v_planes;
/* Run all boot applications from the application cartridge.
* Beware: Hatari features a special cartridge which is used
* for GEMDOS drive emulation. It will hack drvbits and hook Pexec().
* It will also hack Line A variables to enable extended VDI video modes.
*/
KDEBUG(("run_cartridge_applications(3)\n"));
run_cartridge_applications(3); /* Type "Execute prior to bootdisk" */
KDEBUG(("after run_cartridge_applications()\n"));
if ((V_REZ_HZ != save_hz) || (V_REZ_VT != save_vt) || (v_planes != save_pl))
{
set_rez_hacked();
font_set_default(-1); /* set default font */
vt52_init(); /* initialize the vt52 console */
}
}
#endif
KDEBUG(("bios_init() end\n"));
}
static void bootstrap(void)
{
#if DETECT_NATIVE_FEATURES
/* start the kernel provided by the emulator */
PD *pd;
LONG length;
LONG r;
char args[128];
args[0] = '\0';
nf_getbootstrap_args(args, sizeof(args));
/* allocate space */
pd = (PD *) trap1_pexec(PE_BASEPAGEFLAGS, (char*)PF_STANDARD, args, default_env);
/* get the TOS executable from the emulator */
length = nf_bootstrap(pd->p_lowtpa + sizeof(PD), pd->p_hitpa - pd->p_lowtpa);
/* free the allocated space if something is wrong */
if ( length <= 0 )
goto err;
/* relocate the loaded executable */
r = trap1_pexec(PE_RELOCATE, (char*)length, pd, "");
if ( r != (LONG)pd )
goto err;
/* set the boot drive for the new OS to use */
bootdev = nf_getbootdrive();
/* execute the relocated process */
trap1_pexec(PE_GO, "", pd, "");
err:
trap1(0x49, (long)pd->p_env); /* Mfree() the environment */
trap1(0x49, (long)pd); /* Mfree() the process area */
#endif
}
#if ENABLE_RESET_RESIDENT
/*
* run_reset_resident - run "reset-resident" code
*
* "Reset-resident" code is code that has been loaded into RAM prior
* to a warm boot. It has a special header with a magic number, it
* is 512 bytes long (aligned on a 512-byte boundary), and it has a
* specific checksum (calculated on a word basis).
*
* Note: this is an undocumented feature of TOS that exists in all
* versions of Atari TOS.
*/
struct rrcode {
long magic;
struct rrcode *pointer;
char program[502];
short chksumfix;
};
#define RR_MAGIC 0x12123456L
#define RR_CHKSUM 0x5678
static void run_reset_resident(void)
{
const struct rrcode *p = (const struct rrcode *)phystop;
for (--p; p > (struct rrcode *)&etv_timer; p--)
{
if (p->magic != RR_MAGIC)
continue;
if (p->pointer != p)
continue;
if (compute_cksum((const UWORD *)p) != RR_CHKSUM)
continue;
regsafe_call(p->program);
}
}
#endif
/*
* autoexec - run programs in auto folder
*
* Skip this if user holds the Control key down.
*
* Note that GEMDOS already created a default basepage so it is safe
* to use GEMDOS calls here!
*/
static void run_auto_program(const char* filename)
{
char path[30];
strcpy(path, "\\AUTO\\");
strcat(path, filename);
KDEBUG(("Loading %s ...\n", path));
trap1_pexec(PE_LOADGO, path, "", default_env); /* Pexec */
KDEBUG(("[OK]\n"));
}
static void autoexec(void)
{
struct {
BYTE reserved[21];
BYTE attr;
WORD time;
WORD date;
LONG size;
BYTE name[14];
} dta;
WORD err;
/* check if the user does not want to run AUTO programs */
if (bootflags & BOOTFLAG_SKIP_AUTO_ACC)
return;
bootstrap(); /* try to boot the new OS kernel directly */
if( ! blkdev_avail(bootdev) ) /* check, if bootdev available */
return;
trap1( 0x1a, &dta); /* Setdta */
err = trap1( 0x4e, "\\AUTO\\*.PRG", 7); /* Fsfirst */
while(err == 0) {
#ifdef TARGET_PRG
if (!strncmp(dta.name, "EMUTOS", 6))
{
KDEBUG(("Skipping %s from AUTO folder\n", dta.name));
}
else
#endif
{
run_auto_program(dta.name);
/* Setdta. BetaDOS corrupted the AUTO load if the Setdta
* not repeated here */
trap1( 0x1a, &dta);
}
err = trap1( 0x4f ); /* Fsnext */
}
}
#if CONF_WITH_SHUTDOWN
/* Try to shutdown the machine. This may fail. */
static void shutdown(void)
{
#if DETECT_NATIVE_FEATURES
nf_shutdown();
#endif
#ifdef MACHINE_FIREBEE
firebee_shutdown();
#elif defined(MACHINE_AMIGA)
amiga_shutdown();
#endif
}
/* Will shutdown() succeed ? */
BOOL can_shutdown(void)
{
#if DETECT_NATIVE_FEATURES
if (has_nf_shutdown())
return TRUE;
#endif
#ifdef MACHINE_FIREBEE
return TRUE;
#elif defined(MACHINE_AMIGA)
return amiga_can_shutdown();
#else
return FALSE;
#endif
}
#endif /* CONF_WITH_SHUTDOWN */
/*
* biosmain - c part of the bios init code
*
* Print some status messages
* exec the user interface (shell or AES)
*/
void biosmain(void)
{
BOOL show_initinfo; /* TRUE if welcome screen must be displayed */
BYTE *p;
ULONG shiftbits;
bios_init(); /* Initialize the BIOS */
trap1( 0x30 ); /* initial test, if BDOS works: Sversion() */
if (!HAS_RTC)
trap1( 0x2b, os_dosdate); /* set initial date in GEMDOS format: Tsetdate() */
/* Steem needs this to initialize its GEMDOS hard disk emulation.
* This may change drvbits. See Steem sources:
* File steem/code/emulator.cpp, function intercept_bios(). */
Drvmap();
/*
* if it's not the first boot, we use the existing bootdev.
* this allows a boot device that was selected via the welcome
* screen to persist across warm boots.
*/
if (FIRST_BOOT)
bootdev = blkdev_avail(DEFAULT_BOOTDEV) ? DEFAULT_BOOTDEV : FLOPPY_BOOTDEV;
#if INITINFO_DURATION == 0
show_initinfo = FALSE;
#elif ALWAYS_SHOW_INITINFO
show_initinfo = TRUE;
#else
show_initinfo = FIRST_BOOT;
#endif
if (show_initinfo)
bootdev = initinfo(&shiftbits); /* show the welcome screen */
else
shiftbits = kbshift(-1);
KDEBUG(("bootdev = %d\n", bootdev));
if (shiftbits & MODE_ALT)
bootflags |= BOOTFLAG_SKIP_HDD_BOOT;
if (shiftbits & MODE_CTRL)
bootflags |= BOOTFLAG_SKIP_AUTO_ACC;
KDEBUG(("bootflags = 0x%02x\n", bootflags));
/* boot eventually from a block device (floppy or harddisk) */
blkdev_boot();
defdrv = bootdev;
trap1( 0x0e , defdrv ); /* Set boot drive: Dsetdrv(defdrv) */
#if ENABLE_RESET_RESIDENT
run_reset_resident(); /* see comments above */
#endif
/*
* build default environment, just a PATH= string
*/
strcpy(default_env,PATH_ENV);
p = default_env + sizeof(PATH_ENV); /* point to first byte of path string */
strcpy(p,DEF_PATH);
*p = 'A' + defdrv; /* fix up drive letter */
p += sizeof(DEF_PATH);
*p = '\0'; /* terminate with double nul */
#if WITH_CLI
if (bootflags & BOOTFLAG_EARLY_CLI) { /* run an early console */
PD *pd = (PD *) trap1_pexec(PE_BASEPAGEFLAGS, (char*)PF_STANDARD, "", default_env);
pd->p_tbase = (BYTE *) coma_start;
pd->p_tlen = pd->p_dlen = pd->p_blen = 0;
trap1_pexec(PE_GOTHENFREE, "", pd, "");
}
#endif
autoexec(); /* autoexec PRGs from AUTO folder */
/* clear commandline */
if(cmdload != 0) {
/* Pexec a program called COMMAND.PRG */
trap1_pexec(PE_LOADGO, "COMMAND.PRG", "", default_env);
} else if (exec_os) {
/* start the default (ROM) shell */
PD *pd;
pd = (PD *) trap1_pexec(PE_BASEPAGEFLAGS, (char*)PF_STANDARD, "", default_env);
pd->p_tbase = (BYTE *) exec_os;
pd->p_tlen = pd->p_dlen = pd->p_blen = 0;
trap1_pexec(PE_GO, "", pd, "");
}
#if CONF_WITH_SHUTDOWN
/* try to shutdown the machine / close the emulator */
shutdown();
#endif
/* hide cursor */
cprintf("\033f");
kcprintf(_("System halted!\n"));
halt();
}
/**
* bios_0 - (getmpb) Load Memory parameter block
*
* Returns values of the initial memory parameter block, which contains the
* start address and the length of the TPA.
* Just executed one time, before GEMDOS is loaded.
*
* Arguments:
* mpb - first memory descriptor, filled from BIOS
*
*/
#if DBGBIOS
static void bios_0(MPB *mpb)
{
getmpb(mpb);
}
#endif
/**
* bios_1 - (bconstat) Status of input device
*
* Arguments:
* handle - device handle (0:PRT 1:AUX 2:CON)
*
*
* Returns status in D0.L:
* -1 device is ready
* 0 device is not ready
*/
LONG bconstat(WORD handle) /* GEMBIOS character_input_status */
{
#if BCONMAP_AVAILABLE
WORD map_index;
#endif
if (!(boot_status & CHARDEV_AVAILABLE))
return 0;
#if BCONMAP_AVAILABLE
map_index = handle - BCONMAP_START_HANDLE;
if (map_index >= bconmap_root.maptabsize)
return 0L;
if (map_index >= 0)
return protect_v(bconmap_root.maptab[map_index].Bconstat);
#endif
if ((handle >= 0) && (handle <= 7))
return protect_v(bconstat_vec[handle]);
return 0L;
}
#if DBGBIOS
static LONG bios_1(WORD handle)
{
return bconstat(handle);
}
#endif
/**
* bconin - Get character from device
*
* Arguments:
* handle - device handle (0:PRT 1:AUX 2:CON)
*
* This function does not return until a character has been
* input. It returns the character value in D0.L, with the
* high word set to zero. For CON:, it returns the GSX 2.0
* compatible scan code in the low byte of the high word, &
* the ASCII character in the lower byte, or zero in the
* lower byte if the character is non-ASCII. For AUX:, it
* returns the character in the low byte.
*/
LONG bconin(WORD handle)
{
#if BCONMAP_AVAILABLE
WORD map_index;
#endif
if (!(boot_status & CHARDEV_AVAILABLE))
return 0;
#if BCONMAP_AVAILABLE
map_index = handle - BCONMAP_START_HANDLE;
if (map_index >= bconmap_root.maptabsize)
return 0L;
if (map_index >= 0)
return protect_v(bconmap_root.maptab[map_index].Bconin);
#endif
if ((handle >= 0) && (handle <= 7))
return protect_v(bconin_vec[handle]);
return 0L;
}
#if DBGBIOS
static LONG bios_2(WORD handle)
{
return bconin(handle);
}
#endif
/**
* bconout - Print character to output device
*/
LONG bconout(WORD handle, WORD what)
{
#if BCONMAP_AVAILABLE
WORD map_index;
#endif
if (!(boot_status & CHARDEV_AVAILABLE))
return 0;
#if BCONMAP_AVAILABLE
map_index = handle - BCONMAP_START_HANDLE;
if (map_index >= bconmap_root.maptabsize)
return 0L;
if (map_index >= 0)
return protect_ww((PFLONG)bconmap_root.maptab[map_index].Bconout, handle, what);
#endif
if ((handle >= 0) && (handle <= 7))
return protect_ww((PFLONG)bconout_vec[handle], handle, what);
return 0L;
}
#if DBGBIOS
static LONG bios_3(WORD handle, WORD what)
{
return bconout(handle, what);
}
#endif
#if CONF_SERIAL_CONSOLE_ANSI
/* Output a string via bconout() */
void bconout_str(WORD handle, const char* str)
{
while (*str)
bconout(handle, (UBYTE)*str++);
}
#endif
/**
* rwabs - Read or write sectors
*
* Returns a 2's complement error number in D0.L. It
* is the responsibility of the driver to check for
* media change before any write to FAT sectors. If
* media has changed, no write should take place, just
* return with error code.
*
* r_w = 0:Read 1:Write
* *adr = where to get/put the data
* numb = # of sectors to get/put
* first = 1st sector # to get/put = 1st record # tran
* drive = drive #: 0 = A:, 1 = B:, etc
*/
LONG lrwabs(WORD r_w, UBYTE *adr, WORD numb, WORD first, WORD drive, LONG lfirst)
{
return protect_wlwwwl((PFLONG)hdv_rw, r_w, (LONG)adr, numb, first, drive, lfirst);
}
#if DBGBIOS
static LONG bios_4(WORD r_w, UBYTE *adr, WORD numb, WORD first, WORD drive, LONG lfirst)
{
LONG ret;
KDEBUG(("BIOS rwabs(rw = %d, addr = %p, count = 0x%04x, "
"sect = 0x%04x, dev = 0x%04x, lsect = 0x%08lx)",
r_w, adr, numb, first, drive, lfirst));
ret = lrwabs(r_w, adr, numb, first, drive, lfirst);
KDEBUG((" = 0x%08lx\n", ret));
return ret;
}
#endif
/**
* Setexc - set exception vector
*
*/
LONG setexc(WORD num, LONG vector)
{
LONG oldvector;
LONG *addr = (LONG *) (4L * num);
oldvector = *addr;
if(vector != -1) {
*addr = vector;
}
return oldvector;
}
#if DBGBIOS
static LONG bios_5(WORD num, LONG vector)
{
LONG ret = setexc(num, vector);
KDEBUG(("Bios 5: Setexc(num = 0x%x, vector = %p)\n", num, (void*)vector));
return ret;
}
#endif
/**
* tickcal - Time between two systemtimer calls
*/
LONG tickcal(void)
{
return(20L); /* system timer is 50 Hz so 20 ms is the period */
}
#if DBGBIOS
static LONG bios_6(void)
{
return tickcal();
}
#endif
/**
* get_bpb - Get BIOS parameter block
* Returns a pointer to the BIOS Parameter Block for
* the specified drive in D0.L. If necessary, it
* should read boot header information from the media
* in the drive to determine BPB values.
*
* Arguments:
* drive - drive (0 = A:, 1 = B:, etc)
*/
LONG getbpb(WORD drive)
{
return protect_w(hdv_bpb, drive);
}
#if DBGBIOS
static LONG bios_7(WORD drive)
{
return getbpb(drive);
}
#endif
/**
* bcostat - Read status of output device
*
* Returns status in D0.L:
* -1 device is ready
* 0 device is not ready
*/
/* handle = 0:PRT 1:AUX 2:CON 3:MID 4:KEYB */
LONG bcostat(WORD handle) /* GEMBIOS character_output_status */
{
#if BCONMAP_AVAILABLE
WORD map_index;
#endif
if (!(boot_status & CHARDEV_AVAILABLE))
return 0;