Browse Source

Needs a status screen and reserved memory detection, but the basic concept is done

Stephen D 1 year ago
parent
commit
b303f2d545
4 changed files with 164 additions and 9 deletions
  1. 21 6
      boot.asm
  2. 5 0
      drivers/screen.asm
  3. 129 0
      prog/cray.asm
  4. 9 3
      variables.asm

+ 21 - 6
boot.asm

@ -33,10 +33,10 @@
33 33
	;///mov ax, 0x300
34 34
	;//call print_hex
35 35
36
	;; Load sectors 2 and 3(more OS)
36
	;; Load sectors 2 to 4(more OS)
37 37
	mov cx, 2					;sector & cylinder
38 38
	mov dh, 0					;head
39
	mov al, 2					;Num sectors
39
	mov al, 3					;Num sectors
40 40
	mov bx, 0x7E00				;RAM
41 41
	call read_sector
42 42
@ -90,12 +90,14 @@ STARTUP:	db "Starting Steve16...", 0xA, 0xD,
90 90
	dw 0xaa55
91 91
92 92
	;; =====================================
93
	;; SECTOR 2 & 3
93
	;; SECTOR 2 & UP
94 94
	;; =====================================
95 95
	%include "string.asm"
96 96
	%include "textedit.asm"
97 97
	%include "memtest.asm"
98
	
98
	jmp tmp_skip
99
	%include "prog/cray.asm"
100
tmp_skip:	
99 101
100 102
kb_bs:
101 103
	cmp [CMD_BUFFER_POS], byte 0 ;Ignore the backspace if CMD_BUFFER is empty
@ -174,6 +176,7 @@ cmd:
174 176
	;//mov bx, CMD_BUFFER
175 177
	;//call print
176 178
	mov cx, CMD_BUFFER
179
	
177 180
	mov dx, CMD_HELP_STR
178 181
	call strcmp
179 182
	cmp cl, 1
@ -199,6 +202,11 @@ cmd:
199 202
	cmp cl, 1
200 203
	je cmd_strsplit
201 204
205
	mov dx, CMD_CRAY_STR
206
	call strcmp
207
	cmp cl, 1
208
	je cmd_cray
209
202 210
	;; don't print unknown command message if cmd is empty
203 211
	cmp [CMD_BUFFER_POS], byte 0
204 212
	je clear_cmd_buffer
@ -215,7 +223,7 @@ clear_cmd_buffer:
215 223
216 224
cmd_memtest:
217 225
	pusha
218
	mov bx, 0x8300
226
	mov bx, MEMTEST_START
219 227
	mov ax, 0xFFFF
220 228
	call memtest_init
221 229
	popa
@ -252,11 +260,18 @@ cmd_strsplit:
252 260
	
253 261
	jmp clear_cmd_buffer
254 262
263
cmd_cray:
264
	pusha
265
	call cray_init
266
	popa
267
	jmp clear_cmd_buffer
268
255 269
CMD_MEMTEST_STR:	 db "MEMTEST", 0
256 270
CMD_SEDIT_STR: db "SEDIT", 0
257 271
CMD_HELP_STR:  db "HELP", 0
258 272
CMD_CLEAR_STR: db "CLEAR", 0
259 273
CMD_STRSPLIT_STR:	db "STRSP", 0
274
CMD_CRAY_STR:	db "CRAY", 0
260 275
261 276
STRSPLIT_TEST_STR:	db "this is a test string", 0
262 277
STRSPLIT_TEST_OUTPUT:	times 16 dw 0 ;16 element 2-byte array
@ -273,7 +288,7 @@ RTN_HELP_STR:
273 288
RTN_UNKNOWN_STR:
274 289
	db "Unknown command. Type HELP for help.", 0xA, 0xD, 0
275 290
276
	times (1024+512)-($-$$) db 0
291
	times (1024+1024)-($-$$) db 0
277 292
278 293
	;; Everything after this is not loaded
279 294
	;; The padding is so we can write there in the future

+ 5 - 0
drivers/screen.asm

@ -1,3 +1,8 @@
1
	%define SCN_BLACK 0x00
2
	%define SCN_MAGNETA 0x0D
3
	%define SCN_WHITE 0xFF
4
5
1 6
kernel_scn_cls:
2 7
	push cx
3 8
	push ax

+ 129 - 0
prog/cray.asm

@ -0,0 +1,129 @@
1
	;; Fills a large section of RAM with 0xAA (alternating 0s and 1s)
2
	;; occasionally looks for bit flips
3
	
4
	;; all div 0x10
5
	%define cray_memory_start 0x900
6
	%define cray_memory_end 0xDFFF
7
	%define cray_vmem_start 0xB800
8
9
cray_init:
10
	;; set all memory to 0xAA
11
	;; from 0x9000 to 0xDFFF0 ~(880kb)
12
	mov di, 0
13
	mov ax, cray_memory_start
14
	mov es, ax				;0x9000
15
cray_init_loop:
16
	mov [es:di], word 0xAAAA
17
	add di, 2
18
	mov [es:di], word 0xAAAA
19
	add di, 2
20
	mov [es:di], word 0xAAAA
21
	add di, 2
22
	mov [es:di], word 0xAAAA
23
	add di, 2
24
	mov [es:di], word 0xAAAA
25
	add di, 2
26
	mov [es:di], word 0xAAAA
27
	add di, 2
28
	mov [es:di], word 0xAAAA
29
	add di, 2
30
	mov [es:di], word 0xAAAA
31
32
	mov di, 0
33
	inc ax
34
	mov es, ax
35
	
36
	cmp ax, cray_memory_end
37
	je cray_init_done
38
39
	jmp cray_init_loop
40
41
cray_init_done:
42
	jmp cray_memory_test_init
43
44
cray_memory_test_init:
45
	;; tests every single byte
46
	;; to make sure no bits were flipped
47
	mov di, 0
48
	mov ax, cray_memory_start
49
	mov es, ax
50
cray_memory_test_loop:
51
52
	cmp ax, cray_vmem_start
53
	je cray_skip_vmem
54
	
55
	cmp [es:di], word 0xAAAA
56
	jne cray_memory_test_error
57
	add di, 2
58
	
59
	cmp [es:di], word 0xAAAA
60
	jne cray_memory_test_error
61
	add di, 2
62
63
	cmp [es:di], word 0xAAAA
64
	jne cray_memory_test_error
65
	add di, 2
66
67
	cmp [es:di], word 0xAAAA
68
	jne cray_memory_test_error
69
	add di, 2
70
71
	cmp [es:di], word 0xAAAA
72
	jne cray_memory_test_error
73
	add di, 2
74
	
75
	cmp [es:di], word 0xAAAA
76
	jne cray_memory_test_error
77
	add di, 2
78
79
	cmp [es:di], word 0xAAAA
80
	jne cray_memory_test_error
81
	add di, 2
82
	
83
	cmp [es:di], word 0xAAAA
84
	jne cray_memory_test_error
85
86
	cmp ax, cray_memory_end - 1
87
	je cray_memory_test_done
88
	
89
	mov di, 0
90
	inc ax
91
	mov es, ax
92
	jmp cray_memory_test_loop
93
94
cray_skip_vmem:
95
	add ax, (640 * 480 / 16)
96
	jmp cray_memory_test_loop
97
	
98
99
cray_memory_test_error:
100
	;; cosmic ray detected!
101
	;; or memory is going bad
102
	mov bx, CRAY_DETECTED
103
	call print
104
105
	call print_hex				;mem address
106
107
	
108
	push ax
109
	mov ax, [es:di]
110
	call print_hex 				;mem value
111
	pop ax
112
113
	mov al, 0xD
114
	call print_char
115
116
	;; lastly, fix the bit
117
	mov [es:di], word 0xAAAA
118
	mov di, 0
119
	jmp cray_memory_test_loop
120
121
cray_memory_test_done:
122
	mov cx, SCN_WHITE
123
	mov bx, CRAY_MEM_OK
124
	call print
125
	ret
126
127
128
CRAY_DETECTED:	db "Cosmic ray detected!", 0
129
CRAY_MEM_OK:		db "Memory functional.", 0

+ 9 - 3
variables.asm

@ -3,9 +3,15 @@
3 3
	;; the disk, wasting time and space
4 4
	bits 16
5 5
6
	;; 0x8200 is the first byte not loaded from disk
7
	%define CMD_BUFFER 0x8200	;Length 0x100
8
	%define SEDIT_EDITOR_BUFFER 0x8300 ;Length 0x400
6
	;; 0x8600 is the first byte not loaded from disk
7
	%define free_mem_start 0x8600
8
	
9
	%define CMD_BUFFER free_mem_start	;Length 0x100
10
	%define SEDIT_EDITOR_BUFFER free_mem_start + 0x100 ;Length 0x400
11
12
13
14
	%define MEMTEST_START 0x8600 + 0x500
9 15
	
10 16
11 17
init_variables: