Просмотр исходного кода

Add "partition table" to allow SectorLISP to boot from USB drive (#27)

tkchia 2 лет назад
Родитель
Сommit
03fca656d7
1 измененных файлов с 36 добавлено и 3 удалено
  1. 36 3
      sectorlisp.S

+ 36 - 3
sectorlisp.S

@@ -285,20 +285,53 @@ Eval:	test	%ax,%ax				# Eval(e:ax,a:dx):ax
 	call	Evlis
 	xchg	%ax,%si
 	pop	%ax
-	call	Apply
+	jmp	2f
+
+	.fill	0x1BE - (. - _start), 1, 0xce	# to have this boot from a USB
+						# drive on a modern PC, make a
+						# degenerate "partition table"
+						# where this sector starts the
+						# bootable partition; inactive
+						# partition table entries must
+						# also be empty, or have valid
+						# starting sector LBA numbers!
+
+						# * 1st partition entry *
+	.byte	0x80				#  - bootable indicator
+	.byte	0, 1, 0				#  - h₀, s₀ (& c₀ hi bits), c₀
+	.byte	0x7F				#  - OS or filesystem indicator
+	.byte	0xFF, 0xFF, 0xFF		#  - h₉, s₉ (& c₉ hi bits), c₉
+	.long	0				#  - c₀*Cₙ + h₀*Hₙ + s₀*Sₙ
+
+2:	call	Apply
+	.byte	0x3C
+						# * 2nd partition entry *
+	.byte	0x00				#  - bootable indicator
 	pop	%dx				# restore A
 	mov	%cx,%si				# si = B
 	xchg	%ax,%di
 	call	Gc
 	mov	%dx,%di				# di = A
+	.byte	0x3C				#
+	.byte	0x00				#  - hi8(c₀*Cₙ + h₀*Hₙ + s₀*Sₙ)
 	sub	%si,%cx				# cx = C - B
 	rep movsb
+						# * 3rd partition entry *
+	.byte	0x00				#  - bootable indicator
+	.byte	0xC9
 	mov	%di,%cx				# cx = A + (C - B)
 	pop	%dx				# restore a
 1:	ret
 
-.sig:	.fill	512 - (2f - 1f) - (. - _start), 1, 0xce
-1:	.ascii	" SECTORLISP v2 "
+	.fill	0x1DE + 0x8 - (. - _start), 1, 0xce
+	.long	0				#  - c₀*Cₙ + h₀*Hₙ + s₀*Sₙ
+
+	.fill	0x1EE - (. - _start), 1, 0xce	# * 4th partition entry *
+	.byte	0x00				#  - bootable indicator
+.sig:	.fill	0x200 - (2f - 1f) - (. - _start), 1, 0xce
+1:	.ascii	"SECTORLISP"
+	.byte	0				#  - hi8(c₀*Cₙ + h₀*Hₙ + s₀*Sₙ)
+	.ascii	" v2 "
 	.word	0xAA55
 2:	.type	.sig,@object
 	.type	kQuote,@object