Browse Source

Added memory management, print_dec, more cray work

Stephen D 6 months ago
parent
commit
6f716c4941
5 changed files with 91 additions and 11 deletions
  1. 8 7
      boot.asm
  2. 27 0
      drivers/mem.asm
  3. 2 0
      drivers/screen.asm
  4. 48 0
      lib/print_adv.asm
  5. 6 4
      prog/cray.asm

+ 8 - 7
boot.asm

@ -29,10 +29,6 @@
29 29
	mov bx, STARTUP
30 30
	call print
31 31
32
	;; testing
33
	;///mov ax, 0x300
34
	;//call print_hex
35
36 32
	;; Load sectors 2 to 4(more OS)
37 33
	mov cx, 2					;sector & cylinder
38 34
	mov dh, 0					;head
@ -40,6 +36,11 @@
40 36
	mov bx, 0x7E00				;RAM
41 37
	call read_sector
42 38
39
	;; initialize memory
40
	pusha
41
	call mem_init
42
	popa
43
43 44
	push bx
44 45
	mov bx, 0xF
45 46
	mov al, '>'					;cmd line
@ -92,12 +93,12 @@ STARTUP:	db "Starting Steve16...", 0xA, 0xD,
92 93
	;; =====================================
93 94
	;; SECTOR 2 & UP
94 95
	;; =====================================
96
	%include "memtest.asm"
95 97
	%include "string.asm"
96 98
	%include "textedit.asm"
97
	%include "memtest.asm"
98
	jmp tmp_skip
99 99
	%include "prog/cray.asm"
100
tmp_skip:	
100
	%include "drivers/mem.asm"
101
	%include "lib/print_adv.asm"
101 102
102 103
kb_bs:
103 104
	cmp [CMD_BUFFER_POS], byte 0 ;Ignore the backspace if CMD_BUFFER is empty

+ 27 - 0
drivers/mem.asm

@ -0,0 +1,27 @@
1
mem_init:
2
	clc
3
	int 0x12					;detect amount of memory
4
	jc mem_init_error
5
6
	mov cx, SCN_YELLOW
7
	call print_dec
8
	mov bx, mem_free_str
9
	call print
10
11
	
12
	mov dl, 16
13
	mul dl						;ax *= 16
14
	mov [mem_rsv_start], ax
15
	ret
16
17
mem_init_error:
18
	mov bx, mem_init_error_string
19
	mov cx, 0xFF
20
	call print
21
	jmp $
22
23
mem_rsv_start:	dw 0
24
25
26
mem_init_error_string:	db "There was an error initializing memory. Halting now.", 0
27
mem_free_str:	db "KB free.", 0xA, 0xD, 0

+ 2 - 0
drivers/screen.asm

@ -1,6 +1,8 @@
1 1
	%define SCN_BLACK 0x00
2 2
	%define SCN_MAGNETA 0x0D
3 3
	%define SCN_WHITE 0xFF
4
	%define SCN_RED 0x04
5
	%define SCN_YELLOW 0xE
4 6
5 7
6 8
kernel_scn_cls:

+ 48 - 0
lib/print_adv.asm

@ -0,0 +1,48 @@
1
	;; holds print functions which are not needed immediately on boot
2
	;; these don't have to be in the first sector
3
4
	;; ax - number in
5
	;; cx - colour
6
	;; output in decimal
7
print_dec:
8
	pusha
9
	mov [dec_count], byte 0
10
11
print_dec_digit:
12
	mov dx, 0
13
	mov bx, 10
14
	div bx
15
	push ax
16
	add dl, '0'
17
	mov bx, dec_buffer
18
	add bx, [dec_count]
19
	mov [bx], dl
20
	add [dec_count], byte 1
21
22
	pop ax
23
	cmp ax, 0
24
	jg print_dec_digit
25
26
	mov bx, dec_buffer
27
	add bx, [dec_count]
28
29
output_dec_digit:
30
	sub bx, 1
31
	mov al, [bx]
32
	xchg bx, cx
33
	call print_char
34
	xchg bx, cx
35
	sub [dec_count], byte 1
36
	cmp [dec_count], byte 0
37
	jne output_dec_digit
38
39
	;; done
40
	popa
41
	ret
42
43
dec_buffer:	times 5 db 0
44
dec_count:	dw 0
45
46
;;; END print dec
47
48
	

+ 6 - 4
prog/cray.asm

@ -3,12 +3,13 @@
3 3
	
4 4
	;; all div 0x10
5 5
	%define cray_memory_start 0x900
6
	%define cray_memory_end 0xDFFF
6
	%define cray_memory_end mem_rsv_start
7 7
	%define cray_vmem_start 0xB800
8 8
9 9
cray_init:
10
	call kernel_scn_cls
10 11
	;; set all memory to 0xAA
11
	;; from 0x9000 to 0xDFFF0 ~(880kb)
12
	;; from 0x9000 to the end of the RAM ~(880kb)
12 13
	mov di, 0
13 14
	mov ax, cray_memory_start
14 15
	mov es, ax				;0x9000
@ -33,8 +34,8 @@ cray_init_loop:
33 34
	inc ax
34 35
	mov es, ax
35 36
	
36
	cmp ax, cray_memory_end
37
	je cray_init_done
37
	cmp ax, [cray_memory_end]
38
	jle cray_init_done
38 39
39 40
	jmp cray_init_loop
40 41
@ -99,6 +100,7 @@ cray_skip_vmem:
99 100
cray_memory_test_error:
100 101
	;; cosmic ray detected!
101 102
	;; or memory is going bad
103
	;//mov cx, SCN_GREEN
102 104
	mov bx, CRAY_DETECTED
103 105
	call print
104 106