download SDRAM.ASM
Language: Assembler
License: GPL
Copyright: (C) 2002, Leif Ekblad
LOC: 765
Project Info
RDOS operating system(rdos)
Server: SourceForge
Type: cvs
SourceForge\r\rdos\rdos\bur\
   ad.cpp
   ad.def
   BOOT.ASM
   bur2bin.asm
   burload.cpp
   burload.def
   CFG2ROM.ASM
   CLEAN.BAT
   DEMO.CFG
   FLASH.ASM
   LCD.ASM
   MK.BAT
   SDRAM.ASM
   SHUTDOWN.ASM
   TEST.ASM
   TEST.DEF
   YMODEM.CPP
   YMODEM.H
   ZFX86.ASM

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RDOS operating system
; Copyright (C) 2002, Leif Ekblad
;
; This program 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 of the License, or
; (at your option) any later version. The only exception to this rule
; is for commercial usage in embedded systems. For information on
; usage in commercial embedded systems, contact embedded@rdos.net
;
; This program 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 this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;
; The author of this program may be contacted at leif@rdos.net
;
; SDRAM.ASM
; Setup SDRAM for BUR-loader
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        NAME  sdram

.model tiny
.code
.386p

WriteNB Macro index, data
    mov ax,index
    out 24h,ax
    mov ax,data
    out 26h,ax
        Endm

ReadNB  Macro index
    mov ax,index
    out 24h,ax
    in ax,26h
        ENDM

ReadPciDword Macro bus, device, function, index
    mov eax,80000000h OR (bus SHL 16) OR (device SHL 11) OR (function SHL 8) OR (index AND 0FFFCh)
	mov dx,0CF8h
	out dx,eax
	mov dx,0CFCh
	in eax,dx
        ENDM


WritePciDword Macro bus, device, function, index, data
    mov eax,80000000h OR (bus SHL 16) OR (device SHL 11) OR (function SHL 8) OR (index AND 0FFFCh)
	mov dx,0CF8h
	out dx,eax
    mov eax,data
	mov dx,0CFCh
    out dx,eax
	    ENDM

	org 0

Startup:
	jmp Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Data at the end of the BUR
;
;		org	0FF00h
;
;		dw	BUR_VERSION
;		dw	VAR_START		
;		dw	offset	FarReturn
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CIRC_BUFF_SIZE	=	128
CMD_LINE_LEN	=	70
FZ_FIELD_LEN	=	11

ZT_LED_RED	=	00000010b
ZT_LED_GREEN	=	00001000b

Seg0	STRUC

CircIn		    dw	0
CircOut		    dw	0
CircBuf		    db	CIRC_BUFF_SIZE dup (0)
Handshake	    db	0	; 1 if RTS/CTS is used
SerialMode	    db	0	; 0=none 1=Serial 2=ZTAG_LEDS
CRCFreez	    db	0	; if 1, ZTEXEC will freez on CRC errors
CmdLine		    db	CMD_LINE_LEN dup (0)
Addressing	    db	0	; 0=real mode, 1=linear mode
ColonInCmd	    db	0
LastDispCmd	    dw	0	; for 'd' command: 0=ignore, entry to command otherwise
LastEDX		    dd	0	; for 'd' command
UsrCmdStart	    dw	0	; start offset of user commands area (seg=70h)
UsrCmdCount	    dw	0	; number of uploaded user-defined commands
DownloadSegment	dw	0	; segment, where the downloadable code can start
YModemHdrByte	db	0	; first byte of filename
YModemFileSize	db	FZ_FIELD_LEN dup (0)
YModemCRChi	    db	0	; received by YModem
YModemCRClo	    db	0
YModemCRChi_C	db	0	; UpdCRC routine uses these
YModemCRClo_C	db	0
YModemPktNo	    db	0
CountDown	    dw	0		
QuickIRET	    db	0	; IRET placeholder		
RomSegment	    dw	0	; Code segment of ROM		
CachedOffset	dw	0	; used for checking on code copy to cache

Seg0    ENDS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			DSBX2Var
;
;		DESCRIPTION:	Get variable start
;
;       RETURNS:		DX:BX		address of variables
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DSBX2Var	proc
	push 0F000h
	pop	ds
	mov	bx, word ptr ds:[0FF02h]
	push 0
	pop	ds
	ret
DSBX2Var	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			CRLF
;
;		DESCRIPTION:	Display CR/LF to the active serial output console.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CRLF	Proc near
	db 9Ah
	dw 0FF0Ah
	dw 0F000h
	ret
CRLF		endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			Delay
;
;		DESCRIPTION:	Do some uncalibrated delaying
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Delay		proc
	db 9Ah
	dw 0FF0Eh
	dw 0F000h
	ret
Delay		endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			Parm2EDX
;
;		DESCRIPTION:	Parse command line numeric parameter to EDX
;
;       PARAMETERS:     AL		field type: 	
;							0 - byte:  0-0FFh
;							1 - word:  0-0FFFFh
;							2 - dword: 0-0FFFFFFFFh
;							3 - address: (xxxx:xxxx if real addressing,
;										      xxxxxxxx if linear addressing)
;						CL		parameter number (1=first parameter)
;
; 		RETURNS:		EDX		parsed parameter value
;						CY		success
;	 					NC		invalid parameter or parameter missing
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	 
Parm2EDX	Proc near
	push ds
	push bx
;
	call DSBX2Var
	db 9Ah
	dw 0FF12h
	dw 0F000h
;		
	pop	bx
	pop	ds
	ret
Parm2EDX	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			ResetCRC
;
;		DESCRIPTION:	?
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ResetCRC	proc
	db 9Ah
	dw 0FF16h
	dw 0F000h
	ret
ResetCRC	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SeekParm
;
;		DESCRIPTION:	Seek SI to the specified command parameter number, so 
; 						parameter start would be at 0:[Variables.CmsLine+SI]
;
;       PARAMETERS:     CL		parameter number
;
;		RETURNS:		SI		offset to parameter withing command line
;						CY		successful
;						NC		unsuccessful
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SeekParm	proc
	push ds
	push bx
;
	call DSBX2Var		
	db 9Ah
	dw 0FF1Ah
	dw 0F000h
;
	pop	bx
	pop	ds
	ret
SeekParm	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerOut8
;
;		DESCRIPTION:	Display 8-bit value in AL to active serial console as number
;
;       PARAMETERS:     AL		value to display
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerOut8		proc
	db 9Ah
	dw 0FF1Eh
	dw 0F000h
	ret
SerOut8		endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerOut16
;
;		DESCRIPTION:	Display 16-bit value in AL to active serial console as number
;
;       PARAMETERS:     AX		value to display
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerOut16	proc
	db 9Ah
	dw 0FF22h
	dw 0F000h
	ret
SerOut16	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerOut32
;
;		DESCRIPTION:	Display 32-bit value in AL to active serial console as number
;
;       PARAMETERS:     EAX		value to display
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerOut32	proc
	db 9Ah
	dw 0FF26h
	dw 0F000h
	ret
SerOut32	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerOutBits
;
;		DESCRIPTION:	Display 8-bit value in AL to active serial console as bits
;
;       PARAMETERS:     AL		value to display
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerOutBits	proc
	db 9Ah
	dw 0FF2Ah
	dw 0F000h
	ret
SerOutBits	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerRec
;
;		DESCRIPTION:	Receive character from active serial console input with no waiting
;
;       RETURNS:		AL		character received
;						ZF		if nothing was receiver
;						NZ		character is ready in AL
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerRec	Proc near
	db 9Ah
	dw 0FF2Eh
	dw 0F000h
	ret
SerRec	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerRecWait
;
;		DESCRIPTION:	Wait 220ms for a character from active serial console input
;
;       RETURNS:		AL		character received
;						ZF		if nothing was receiver
;						NZ		character is ready in AL
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerRecWait	Proc near
	db 9Ah
	dw 0FF32h
	dw 0F000h
	ret
SerRecWait	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerSend2
;
;		DESCRIPTION:	Send data byte to a active serial console output
;
;       PARAMETERS:     AL		byte to send
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerSend2	Proc near
	db 9Ah
	dw 0FF36h
	dw 0F000h
	ret
SerSend2	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			SerSend
;
;		DESCRIPTION:	Send string to a active serial console output
;
;       PARAMETERS:     ES:DI	string to transmit
;	 					CX		if string is not 0-terminated, this is the length to send
;								Must be 0 if string is 0-terminated
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SerSend	Proc near
	db 9Ah
	dw 0FF3Ah
	dw 0F000h
	ret
SerSend	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			YModemGetData
;
;		DESCRIPTION:	Get ymodem data
;
;       PARAMETERS:     EDI		Linear address to place data at
;
;		RETURNS:		EDI		Next byte to receive to
;						CY		Success
;						NC		Failed
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

YModemGetData	Proc near
	db 9Ah
	dw 0FF42h
	dw 0F000h
	ret
YModemGetData	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			YModemGetHeader
;
;		DESCRIPTION:	Get first block of data (filename & size) in a y-modem transfer
;
;       PARAMETERS:     CY		Success
;						NC		Failed
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

YModemGetHeader	Proc near
	db 9Ah
	dw 0FF46h
	dw 0F000h
	ret
YModemGetHeader	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			YModemSendData
;
;		DESCRIPTION:	Send y-modem data
;
;       PARAMETERS:     EDI		Linear address of data
;						EAX		Size of data
;
;		RETURNS:		CY		Success
;						NC		Failed
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

YModemSendData	Proc near
	db 9Ah
	dw 0FF4Ah
	dw 0F000h
	ret
YModemSendData	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			YModemSendHeader
;
;		DESCRIPTION:	Send first packet of y-modem data
;
;       PARAMETERS:     EDI		Linear address of data
;						EAX		Size of data
;
;		RETURNS:		CY		Success
;						NC		Failed
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

YModemSendHeader Proc near
	db 9Ah
	dw 0FF4Eh
	dw 0F000h
	ret
YModemSendHeader Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			InitFlatGs
;
;		DESCRIPTION:	Init flat 32-bit gs segment register
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

flat_sel	EQU 8

LoadGdt:
load_gdt0:
		 	DW 0Fh
			DD OFFSET LoadGdt + 0FFFF0000h
			DW 0
load_gdt_flat:
			DW 0FFFFh
			DD 92000000h
			DW 008Fh

InitFlatGs	Proc near
	mov eax,cs
	shl eax,4
	add eax,OFFSET LoadGdt
	mov cs:dword ptr load_gdt0+2,eax
	db 66h
	lgdt fword ptr cs:load_gdt0
;
	cli
	mov eax,cr0
	or al,1
	mov cr0,eax
	jmp short $+2
;
	mov ax,flat_sel
	mov gs,ax
;
	mov eax,cr0
	and al,NOT 1
	mov cr0,eax
	sti
	xor ax,ax
	mov gs,ax
	ret
InitFlatGs	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			InitNB
;
;		DESCRIPTION:	Init North bridge
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitNB  Proc near
    WriteNB 20Fh, 0
    WriteNB 11Bh, 210h
    WriteNB 11Dh, 3D0h
    WriteNB 110h, 0
    WriteNB 111h, 0
    WriteNB 112h, 0
    WriteNB 113h, 0
    WriteNB 114h, 0
    WriteNB 115h, 0
    WriteNB 117h, 0
    WriteNB 118h, 0
    WriteNB 119h, 6Bh
    WriteNB 11Ah, 220h
    WriteNB 11Eh, 0
    WriteNB 11Fh, 0
    WriteNB 120h, 0
    WriteNB 200h, 0
    WriteNB 201h, 0
    WriteNB 202h, 0
    WriteNB 204h, 0FFFFh
    WriteNB 205h, 0
    WriteNB 207h, 0FFFFh
    WriteNB 208h, 0
    WriteNB 20Ah, 0FFFFh
    WriteNB 20Bh, 0
    WriteNB 20Dh, 0FFFFh
    WriteNB 20Eh, 0
    WriteNB 20Fh, 0
    WriteNB 213h, 321h
    WriteNB 214h, 0    
    ret
InitNB  Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			InitSB
;
;		DESCRIPTION:	Init south bridge
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSB  Proc near
    WritePciDword 0, 12h, 0, 4, 0280000Fh
;
    ReadPciDword 0, 12h, 0, 0Ch
    and ax,0FF00h
    mov edi,eax
    WritePciDword 0, 12h, 0, 4, edi
;
    ReadPciDword 0, 12h, 0, 40h
    and eax,0FF0000h
    or eax,02000019h
    mov edi,eax
    WritePciDword 0, 12h, 0, 40h, edi
;    
    WritePciDword 0, 12h, 0, 10h, 00008101h
    WritePciDword 0, 12h, 0, 50h, 029A557Bh
;
    ReadPciDword 0, 12h, 0, 58h
    and eax,0FFFFh
    or eax,28CF0000h
    mov edi,eax
    WritePciDword 0, 12h, 0, 58h, edi
;
    ReadPciDword 0, 12h, 0, 5Ch
    xor ax,ax
    mov edi,eax
    WritePciDword 0, 12h, 0, 5Ch, edi
;    
    ReadPciDword 0, 12h, 0, 80h
    mov al,1
    mov edi,eax
    WritePciDword 0, 12h, 0, 80h, edi
;    
    ReadPciDword 0, 12h, 1, 4
    xor al,al
    mov edi,eax
    WritePciDword 0, 12h, 1, 4, edi
;
    ReadPciDword 0, 12h, 2, 4
    mov al,5
    mov edi,eax
    WritePciDword 0, 12h, 2, 4, edi
;
    ReadPciDword 0, 12h, 3, 4
    mov al,3
    mov edi,eax
    WritePciDword 0, 12h, 3, 4, edi
;
    WritePciDword 0, 12h, 3, 40h, 0FFFFFFC0h
    WritePciDword 0, 12h, 3, 10h, 00008201h
;
    ReadPciDword 0, 13h, 0, 4
    mov al,7
    mov edi,eax
    WritePciDword 0, 13h, 0, 4, edi
;
    ReadPciDword 0, 13h, 0, 0Ch
    xor ax,ax
    mov edi,eax
    WritePciDword 0, 13h, 0, 0Ch, edi     
;
    WritePciDword 0, 12h, 0, 44h, 02FE0000h
    ret
InitSB  Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			InitDram
;
;		DESCRIPTION:	Init SDRAM
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SaveAx  Macro
    mov bp,ax
    shl eax,16
    mov ax,bp
        Endm

SaveBx  Macro
    mov bp,bx
    shl ebx,16
    mov bx,bp
        Endm

SaveCx  Macro
    mov bp,cx
    shl ecx,16
    mov cx,bp
        Endm

SaveDx  Macro
    mov bp,dx
    shl edx,16
    mov dx,bp
        Endm

RestoreAx   Macro
    shr eax,16
        Endm

RestoreBx   Macro
    shr ebx,16
        Endm

RestoreCx   Macro
    shr ecx,16
        Endm

RestoreDx   Macro
    shr edx,16
        Endm
        
InitDram	Proc near
    push es
    push ebp
;
    WriteNB 4, 2
    WriteNB 239h, 1249h
    WriteNB 11Ch, 0000h
;
    ReadNB 11Ah
    mov bx,ax
    or bx,7
    WriteNB 11Ah, bx
;
    xor bx,bx
    mov cx,4

check_bank_loop:
    ReadNB 119h
    mov di,ax
    and di,0FFEh
    WriteNB 119h, di
;
    WriteNB 20Fh, 0000h
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    mov bx,80h
    shl bx,cl
;
    ReadNB 20Fh
    or bx,ax
    WriteNB 20Fh, bx
;
    WriteNB 214h, 0000h
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;    
    SaveAx
    SaveCx
    xor ch,ch
    dec cl
    mov ax,3
    mul cx
    xchg ax,dx
    add dx,202h
    RestoreAx
    RestoreCx
    WriteNB dx, 0000h
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    dec cx
    mov ax,3
    mul cx
;
    xchg ax,bx
    add bx,204h
    WriteNB bx, 0FC71h        
;
    mov bx,cx
    shl bx,1
    or bx,221h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,229h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,221h
;
    mov cx,8

check_mode_loop:
    and bx,0FFE7h
    WriteNB 213h, bx
;
    or bx,18h
    WriteNB 213h, bx
    loop check_mode_loop
;
    and bx,6
    or bx,231h    
    WriteNB 213h, bx
;
    and bx,6
    or bx,220h
    WriteNB 213h, bx
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;    
    mov esi,00800000h    
    mov dword ptr gs:[esi],5A5A5A5Ah
    mov dword ptr gs:[esi+100h],0
    mov eax,gs:[esi]
    cmp eax,5A5A5A5Ah
    jz init_dram_cont
;
    WriteNB 20Fh, 0
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    mov bx,8000h
    rol bx,cl
    ReadNB 20Fh
    or bx,ax
    WriteNB 20Fh, bx
;
    WriteNB 214h, 1
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;
    SaveAx
    SaveCx
    xor ch,ch
    dec cl
    mov ax,3
    mul cx
    xchg ax,dx
    add dx,202h
    RestoreAx
    RestoreCx
;    
    WriteNB dx, 0008
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    dec cx
    mov ax,3
    mul cx
    xchg ax,bx
    add bx,204h
    WriteNB bx, 0FC71h
;
    mov bx,cx
    shl bx,1
    or bx,221h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,229h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,221h
;
    mov cx,8

l3bd:
    and bx,0FFE7h
    WriteNB 213h, bx
;
    or bx,18h
    WriteNB 213h, bx
    loop l3bd 
;
    and bx,6
    or bx,231h
    WriteNB 213h, bx
;
    and bx,6
    or bx,220h
    WriteNB 213h, bx
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;
    mov esi,00800000h    
    mov dword ptr gs:[esi],5A5A5A5Ah
    mov dword ptr gs:[esi+100h],0
    mov eax,gs:[esi]
    cmp eax,5A5A5A5Ah
    jz init_dram_cont
;
    dec cx
    jnz check_bank_loop       
;   
    jmp check_bank_done

init_dram_cont:
    ReadNB 119h
    or ax,1
    mov di,ax
    WriteNB 119h, di
;
    ReadNB 20Fh
    or bx,ax
;
    SaveAx
    SaveCx
    xor ch,ch
    dec cl
    mov ax,3
    mul cx
    xchg ax,dx
    add dx,202h
    RestoreAx
    RestoreCx
;
    ReadNB dx
    or ax,2A00h
    mov di,ax
;
    mov esi,4
        
check_bank_col_loop:
    WriteNB dx, di

check_bank_mem_loop:
    mov ebp,00800000h    
    mov dword ptr gs:[ebp],1A56E2C6h
    mov dword ptr gs:[esi+ebp],5A5A5A5Ah
    mov eax,gs:[ebp]
    cmp eax,1A56E2C6h
    jnz check_bank_first_failed
;
    mov eax,gs:[esi+ebp]
    cmp eax,5A5A5A5Ah
    jnz check_bank_next
;
    shl esi,1
    cmp esi,ebp
    jnz check_bank_mem_loop
;
    shr esi,1
    jmp check_bank_next

check_bank_first_failed:
    mov eax,esi
    cmp eax,1000000h
    ja check_bank_next
;
    shl eax,1    
    test bx,0FFh
    jz check_bank_col_ok
;
    shl eax,1

check_bank_col_ok:
    and ax,3000h
    and di,0CFFFh
    or di,ax
    mov esi,4
    jmp check_bank_col_loop

check_bank_next:
    shr esi,17
    bsf eax,esi
    dec ax
    shl ax,9
    and di,0F1FFh
    or di,ax
;
    WriteNB 20Fh, 0
;
    and si,0FFh
    or di,si
    WriteNB dx, di
;
    dec cl
    jnz check_bank_loop

check_bank_done:
    call CRLF
;
    ReadNB 119h
    or ax,1
    mov di,ax
    WriteNB 119h, di
;
    WriteNB 20Fh, 0000h
;
    mov cx,1
    mov di,1
    xor dx,dx
    mov es,dx

setup_bank_loop:
    mov ch,cl
    test bx,cx
    jz l622
;
    xchg cx,di
    SaveAx
    SaveCx
    xor ch,ch
    dec cl
    mov ax,3
    mul cx
    xchg ax,dx
    add dx,202h
    RestoreAx
    RestoreCx 
    xchg cx,di
    ReadNB dx
;           
    mov si,ax
    and si,000FFh
    and ax,0FF00h
    mov dx,es
    add ax,dx
    add dx,si
    mov es,dx
    mov si,ax
;
    xchg cx,di
    SaveAx
    SaveCx
    xor ch,ch
    dec cl
    mov ax,3
    mul cx
    xchg ax,dx
    add dx,202h
    RestoreAx
    RestoreCx
    xchg cx,di
    WriteNB dx, si

l622:
    cmp di,4
    jz l62d
;
    shl cl,1
    inc di
    jmp setup_bank_loop

l62d:
    mov cx,1
    mov di,1

l633:
    test bl,cl
    jz l7b2
;
    xchg cx,di
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    mov bx,8000h
    rol bx,cl
;
    ReadNB 20Fh
    or bx,ax
    WriteNB 20Fh, bx
;
    WriteNB 214h, 0001h
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    dec cx
    mov ax,3
    mul cx
    xchg ax,bx
    add bx,204h
    WriteNB bx, 0FC71h
;
    mov bx,cx
    shl bx,1
    or bx,221h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,229h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,221h
;
    mov cx,8

l763:
    and bx,0FFE7h
    WriteNB 213h, bx
; 
    or bx,18h
    WriteNB 213h, bx
    loop l763
;
    and bx,6
    or bx,231h
    WriteNB 213h, bx
;
    and bx,6
    or bx,220h
    WriteNB 213h, bx
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
    xchg cx,di
    jmp l92e

l7b2:
    test cl,bh
    jz l92e
;
    xchg cx,di
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    mov bx,80h
    rol bx,cl
;
    ReadNB 20Fh
    or bx,ax
    WriteNB 20Fh, bx
;
    WriteNB 214h, 0000h
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
;
    SaveAx
    SaveBx
    SaveCx
    SaveDx
;
    dec cx
    mov ax,3
    mul cx
    xchg ax,bx
    add bx,204h
    WriteNB bx, 0FC71h
;
    mov bx,cx
    shl bx,1
    or bx,221h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,229h
    WriteNB 213h, bx
;
    mov bx,cx
    shl bx,1
    or bx,221h
;
    mov cx,8

l8e2:
    and bx,0FFE7h
    WriteNB 213h, bx
; 
    or bx,18h
    WriteNB 213h, bx
    loop l8e2
;
    and bx,6
    or bx,231h
    WriteNB 213h, bx
;
    and bx,6
    or bx,220h
    WriteNB 213h, bx
;
    RestoreAx
    RestoreBx
    RestoreCx
    RestoreDx
    xchg cx,di

l92e:
    cmp di,4
    jz l939
;
    shl cl,1
    inc di
    jmp l633

l939:
    SaveAx
    SaveCx
;
    WriteNB 211h, 0000h
;
    mov cx,-1
    
init_dram_delay:   
    loop init_dram_delay
;
    RestoreAx
    RestoreCx
;
    ReadNB 21Ah
    and ax,0FFF8h
    mov di,ax
    WriteNB 21Ah, di
;
    ReadNB 20Fh
    call SerOut16
    call CRLF
;
    pop ebp
    pop es
    ret
InitDram	Endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;		NAME:			Main
;
;		DESCRIPTION:	main procedure
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Main	Proc far
	call InitFlatGs
;
    call InitNB
    call InitSB
	call InitDram
	ret
Main	Endp	

	END Startup

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us