⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oboot1.s

📁 一个关于系统启动代码的各种版本的打包机和
💻 S
字号:

BOOTSEG equ 	0x07c0
INITSEG equ 	0x9000
SYSSEG  equ 	0x1000			; system loaded at 0x10000 (65536).


start:
   	;移动所有程序到0x9000处
   	jmp	start1
   	nop
   	nop
   	nop
   	nop

start1:
   	mov	ax,0xb800
   	mov	fs,ax
   	mov	byte [fs:0],'1'

   	mov	byte [fs:2],'2'

   	mov	byte [fs:4],'2'
   	mov	byte [fs:6],'2'
   	mov	ax,BOOTSEG
  	mov	ds,ax
   	mov	byte [fs:2],'2'
   	mov	ax,INITSEG
   	mov	es,ax
   	mov	cx,256
   	sub	si,si
   	sub	di,di

   	rep  	movsw
	mov	byte [fs:4],'3'
   	jmp  	INITSEG:go
go:
	mov	byte [fs:6],'4'

	mov	ax,cs
	mov	ds,ax
	mov	es,ax
	mov	ss,ax
	mov	sp,0x400		; arbitrary value >>512

	;读光标位置
	mov	ah,0x03	; read cursor pos
	xor	bh,bh
	int	0x10

	;显示字符串
	mov	cx,24
	mov	bx,0x0007	; page 0, attribute 7 (normal)
	mov	bp,msg1
	mov	ax,0x1301	; write string, move cursor
	int	0x10

	call	read_it
	call	kill_motor


	mov	ah,0x03		; read cursor pos
	xor	bh,bh
	int	0x10		; save it in known place, con_init fetches
	mov	[510],dx	; it from 0x90510.

	cli			
	cld

	push	ds
	push	es

	mov	ax,00
	mov	es,ax		;destination segment
	mov	ax,0x100
	mov	ds,ax
	xor	si,si
	xor	di,di
	mov	cx,BOOT_LENGTH
	rep	movsb


	pop	es
	pop	ds

	;准备进入保护模式
	mov	ax,cs			; right, forgot this at first. didn't work :-)
	mov	ds,ax
	lidt	[idt_48]		; load idt with 0,0
	lgdt	[gdt_48]		; load gdt with whatever appropriate


	;启动a20
	call	empty_8042
	mov	al,0xD1			; command write
	out	0x64,al
	call	empty_8042
	mov	al,0xDF			; A20 on
	out	0x60,al
	call	empty_8042


	mov	ax,0x0001		; protected mode (PE) bit;
	lmsw	ax			; This is it
	jmp 	8:00h			; jmp offset 0 of segment 8 (cs)



empty_8042:
	dw	0x00eb,0x00eb
	in	al,0x64	; 8042 status port
	test	al,2		; is input buffer full?
	jnz	empty_8042	; yes - loop
	ret

gdt_48:
	dw	0x800			; gdt limitequ2048, 256 GDT entries
	dw	gdt,0x9			; gdt base equ 0X9xxxx
idt_48:
	dw	0			; idt limit=0
	dw	0,0			; idt base=0L

read_it:
	mov   	ax,100h
	mov   	es,ax
read:
	call  	read_sector
   	mov   	ax,es
   	add   	ax,20h
   	mov   	es,ax    		;move 512 bytes(32*16=512)
	cmp   	dword [bootLength],200h
   	jbe   	read_finished
   	sub   	dword [bootLength],200h

   	inc   	byte [sector]
   	cmp   	byte [sector],sector_num
   	jbe   	aa
   	mov   	byte [sector],1
   	xor   	byte [head],00000001b
   	mov   	al,byte [head]
   	and   	al,byte [head]
   	jne   	aa

   	inc   	byte [track]
aa:
   	jmp   	read

read_finished:
   	ret

read_sector:

	mov   	ah,02h      	;function
	mov   	al,01    ;number of sectors
   	mov   	bx,00h      ;es:bx = address of buffer
   	mov   	ch,byte [track]   ;track
   	mov   	cl,byte [sector];sector
   	mov   	dh,byte [head] ;head
   	mov   	dl,00    ;drive
   	int   	13h
   	retn

kill_motor:
	push dx
	mov dx,0x3f2
	mov al,0
	outb
	pop dx
	ret

gdt:
	dw	0,0,0,0		; dummy


	dw	0x07FF		; 8Mb - limitequ2047 (2048*4096equ8Mb)
	dw	0x0000		; base addressequ0
	dw	0x9A00		; code read/exec
	dw	0x00C0		; granularityequ4096, 386

	dw	0x07FF		; 8Mb - limitequ2047 (2048*4096equ8Mb)
	dw	0x0000		; base addressequ0
	dw	0x9200		; data read/write
	dw	0x00C0		; granularityequ4096, 386

msg1:
	db 13,10
	db "Loading system ..."
	db 13,10,13,10

sector_num  	equ   12h
sector      	db 2
track    	db 0
head     	db 0
BOOT_LENGTH	equ	0x0f000
bootLength  	dd 	BOOT_LENGTH

        times 510-($-$$) db 0
        dw 0xAA55





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -