aboutsummaryrefslogtreecommitdiff
path: root/diskio.asm
blob: 9f915fa59a2c32d0b6039fbecbec89975a069f39 (plain)
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
; Cheers to the BOOT12 bootloader for a lot of these handy definitions.
; Modified them slightly to fit the kernel's needs
;; TO DO: Confirm that these aren't destroyed as kernel loads
;%define	s_per_clu	0x7C00+0x0D		; byte		Sectors per cluster
;%define	s_b4_fat	0x7C00+0x0E		; word		Sectors (in partition) before FAT
;%define	fats		0x7C00+0x10		; byte		Number of FATs
;%define dir_ent		0x7C00+0x11		; word		Number of root directory entries
;%define	s_p_fat		0x7C00+0x16		; word		Sectors per FAT
;%define s_p_t		0x7C00+0x18		; word		Sectors per track
;%define heads		0x7C00+0x1A		; word		Number of heads
;%define s_b4_prt	0x7C00+0x1C		; dword		Sectors before partition

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  name: jaspos_disk_reset
;;  @param	disk	disk number to reset
;;  @return	none
;;  Resets the disk system
;;
jaspos_disk_reset:
	push	dx
	push	ax
	mov		dl, [Drive]				; DL = drive #
	xor		ah, ah					; AH = 0 = reset disk system
	int		0x13					; Perform the reset
	pop		ax
	pop		dx
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  name: jaspos_disk_readsector
;;  @param	buffer	memory buffer to write sector into
;;  @param	sector	relative sector number to load
;;  @return	none
;;  Loads one sector from the boot disk into memory
;;
jaspos_disk_readsector:
	pop		bp						; Save CALL's address
	pop		cx						; Get sector number into CX
	pop		bx						; Get buffer location
	push	bp						; Push CALL's address back onto stack ready for RET

	push	cx
	call	jaspos_disk_make_chs	; Convert the sector number supplied into a useful CHS (cylinder, head, sector) triplet
	;mov		dl, [Drive]				; DL = Drive number
	;xor		dh, dh					; DH = Head
	xor		ch, ch					; CH = Track number
	mov		al, 1					; AL = # Sectors to read
	mov		ah, 2					; AH = Read command
	int		0x13					; Read sector
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  name: jaspos_disk_make_chs
;;  @param	sector	relative sector number to load
;;  @return	CHS		registers ready for INT13
;;  Converts relative sector into CHS, ready for
;;  interrupt 13
;;
jaspos_disk_make_chs:
	pop		bp
	pop		ax
	push	bp

	xor		dx, dx					; DIV's input is DXAX - clear DX so we're only dividing AX
	div		word [s_per_track]		; Sectors per track
	inc		dl						; Sectors start at 1, not 0
	mov		cl, dl					; Sectors belong in CL for int 13h
	mov		ax, bx

	xor		dx, dx					; Now calculate the head
	div		word [s_per_track]		; Sectors per track

	xor		dx, dx
	div		word [heads]			; Floppy sides
	mov		dh, dl					; Head/side
	mov 	ch, al					; Track

	mov dl, [Drive]				; Set correct device

	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  name: jaspos_disk_get_info
;;  @param	none
;;  @return	none
;;  Load the boot sector into memory and patches
;;  the disk info (label, heads etc) into memory
;;  for use by kernel
;;
jaspos_disk_get_info:
	call	jaspos_disk_reset		;
	jc		jaspos.panic			; If the reset fails, just panic

	; We need to call INT13 manually, because jaspos_diskio_readsector
	; relies on having the disk info we're about to load, loaded.
	; Hooray for having to bootstrap
	mov		bx, free_ram			; Buffer location
	mov		dl, [Drive]				; DL = Drive number
	xor		dh, dh					; DH = Head
	xor		ch, ch					; CH = Track number
	mov		al, 1					; AL = # Sectors to read
	mov		ah, 2					; AH = Read command
	int		0x13					; Read sector

	mov		di, msgDiskLabel + 13	; Load the disk label into the disk label message
	mov		si, free_ram+0x2B		; The label starts 0x2B bytes into the sector
	mov		cx, 11d					; Disk labels are 11 bytes long on FAT12
	rep		movsb					; Copy 11 bytes from the sector buffer into the inside of

	mov		cx, 25d					; There are 25d bytes that I want copied and saved
	mov		si, free_ram+0x0B		; Start copying from byte 0x0B
	mov		di, b_per_s				; Start storing at the b_per_s label
	rep		movsb					; Copy the bytes

	ret								; the disk label message, thus filling it with the disk label
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;