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

📄 init.asm

📁 一个微型操作系统源码
💻 ASM
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	    Project:	LeeOS
;;	     Author:	Robert Lee  <robert.lee@leeos.cjb.net>
;;	       Date:	Thursday, January 04, 2001
;;	Description:	LeeOS Initialization Sequence
;;  Binary Location:	/system/init.sys
;;
;;	Notes:
;;		This file prepairs LeeOS for operation. It will detect the CPU, memory and
;;		disks. It loads the kernel, sets up the kernel services and so on.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.model tiny
.code
.386
	jmp initialize

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Data
;;
;;		Variable Declarations
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
welcome		db 13,10,'Welcome to LeeOS!',13,10,0
errmsg		db 'Error: Unable to load system.',13,10
rebootmsg	db 'Press CTRL+ALT+DEL to reboot',13,10,0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Initialize
;;
;;		Set segments and directives
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
initialize:
	mov ax, 3000h
	mov ds, ax
	mov es, ax

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Load Kernel
;;
;;		Load kernel into memory
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
loadkernel:
	push ds				; Reset Disks
	mov dl, 0
	mov ax, 0
	int 13h
	pop ds
	jc fail
	push es
	mov ax,1000h			; Load kernel from sector 3 into segment 1000h
	mov es,ax
	mov bx, 0
	mov ah, 2			; Load Sectors
	mov al, 5			; Number of sectors
	mov cx, 3			; Sector (1-based)
	mov dx, 0			; Floppy Disk
	int 13h
	pop es
	jc loadkernel			; Make sure it worked, try again if not

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Setup System
;;
;;		Map interupts for system services and type a pretty message
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					; Map Interupt
	mov AX, 1000h			; Segment to kernel = 1000h
	shl EAX, 16
	xor AX, AX			; Offset = 0
	xor BX, BX
	mov FS, BX
	cli
	mov FS:[20h*4], EAX
	sti
	mov ah, 4			; Clear Screen
	int 20h
	mov si, offset welcome		; Print Welcome Message
	mov ah, 2
	int 20h

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Video Initialization
;;
;;		Set VGA color palette
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					; Setup color palette
	mov dx, 3c6h
	mov al, 0ffh
	out dx, al
	mov dx, 3c8h			; Color 0 [background]
	xor al, al
	out dx, al
	mov dx, 3c9h
	mov al, 13
	out dx, al
	mov al, 13
	out dx, al
	mov al, 17
	out dx, al
	mov dx, 3c8h			; Color 1 [prompt]
	mov al, 1
	out dx, al
	mov dx, 3c9h
	mov al, 38
	out dx, al
	mov al, 38
	out dx, al
	mov al, 47
	out dx, al
	mov dx, 3c8h			; Color 7 [foreground]
	mov al, 7
	out dx, al
	mov dx, 3c9h
	mov al, 63
	out dx, al
	mov al, 63
	out dx, al
	mov al, 60
	out dx, al

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	Load Shell
;;
;;		Load user interface from disk and pass control to it
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
loadfile:
	mov ECX, 4			; Sector#
	xor bx, bx			; Offset
	mov ax, 5000h			; Segment
	mov es, ax
	mov si, 10			; Sector count
	mov dl, 0			; Floppy A:
	mov ah, 7
	int 20h

	mov ax, 5000h			; Pass control to shell
	mov es, ax
	mov ds, ax
	push ax
	mov ax, 0
	push ax
	retf
fail:
	jmp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;	The End
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	END

⌨️ 快捷键说明

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