哈工大李治军OS-lab-1-9

 代码

entry _start
_start:
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	
	mov	cx,#27
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg1
	mov ax,#0x07c0
	mov es,ax
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
inf_loop:
	jmp inf_loop
msg1:
	.byte 13,10
	.ascii "YZH OS is Loading ..."
	.byte 13,10,13,10

.org 510
boot_flag:
	.word 0xAA55

编译结果

yzh@ubuntu:~/oslab$ hexdump -C linux-0.11/Image 
00000000  b4 03 30 ff cd 10 b9 1b  00 bb 07 00 bd 1b 00 b8  |..0.............|
00000010  c0 07 8e c0 b8 01 13 cd  10 eb fe 0d 0a 59 5a 48  |.............YZH|
00000020  20 4f 53 20 69 73 20 4c  6f 61 64 69 6e 67 20 2e  | OS is Loading .|
00000030  2e 2e 0d 0a 0d 0a 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

实验结果

2

代码boot

SETUPLEN=2
SETUPSEG=0x07e0

entry _start
_start:
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	
	mov	cx,#27
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg1
	mov ax,#0x07c0
	mov es,ax
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
load_setup:
	mov dx,#0x0000
	mov cx,#0x0002
	mov bx,#0x0200
	mov ax,#0x0200+SETUPLEN
	int 0x13
	jnc ok_load_setup
	mov dx,#0x0000
	mov ax,#0x0000
	int 0x13
	jmp load_setup
ok_load_setup:
	jmpi 0,SETUPSEG

msg1:
	.byte 13,10
	.ascii "YZH OS is Loading ..."
	.byte 13,10,13,10

.org 510
boot_flag:
	.word 0xAA55

setup

entry _start
_start:
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	
	mov	cx,#25
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg2
	mov ax,cs
	mov es,ax
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
inf_loop:
	jmp inf_loop

msg2:
	.byte 13,10
	.ascii "Now We are in SETUP"
	.byte 13,10,13,10

.org 510
boot_flag:
	.word 0xAA55

3 显示硬件信息

代码boot

SETUPLEN=2
SETUPSEG=0x07e0

entry _start
_start:
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	
	mov	cx,#27
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg1
	mov ax,#0x07c0
	mov es,ax
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
load_setup:
	mov dx,#0x0000
	mov cx,#0x0002
	mov bx,#0x0200
	mov ax,#0x0200+SETUPLEN
	int 0x13
	jnc ok_load_setup
	mov dx,#0x0000
	mov ax,#0x0000
	int 0x13
	jmp load_setup
ok_load_setup:
	jmpi 0,SETUPSEG

msg1:
	.byte 13,10
	.ascii "YZH OS is Loading ..."
	.byte 13,10,13,10

.org 510
boot_flag:
	.word 0xAA55

代码sec

INITSEG = 0x9000
entry _start
_start:
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	
	mov	cx,#25
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg2
	mov ax,cs
	mov es,ax
	mov	ax,#0x1301		! write string, move cursor
	int	0x10

	mov ax,cs
	mov es,ax

	mov ax,#INITSEG
	mov ss,ax
	mov sp,#0xFF00

! get param
	mov ax,#INITSEG
	mov ds,ax
	mov ah,#0x03
	xor bh,bh
	int 0x10
	mov [0],dx
	mov ah,#0x88
	int 0x15
	mov [2],ax
	mov ax,#0x0000
	mov ds,ax
	lds si,[4*0x41]
	mov ax,#INITSEG
	mov es,ax
	mov di,#0x0004
	mov cx,#0x10
	rep
	movsb

! be ready to print
	mov ax,cs
	mov es,ax
	mov ax,#INITSEG
	mov ds,ax

! cursor
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#18
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_cursor
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
	mov dx,[0]
	call print_hex

! memmory
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#14
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_memory
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
	mov dx,[2]
	call print_hex
! add KB
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#2
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_kb
	mov	ax,#0x1301		! write string, move cursor
	int	0x10	

! cyles
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#7
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_cycles
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
	mov dx,[4]
	call print_hex

! heads
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#8
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_heads
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
	mov dx,[6]
	call print_hex

! sectors
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#10
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_sectors
	mov	ax,#0x1301		! write string, move cursor
	int	0x10
	mov dx,[18]
	call print_hex

! lr
	mov	ah,#0x03		! read cursor pos
	xor	bh,bh
	int	0x10
	mov	cx,#2
	mov	bx,#0x0007		! page 0, attribute 7 (normal)
	mov	bp,#msg_lr
	mov	ax,#0x1301		! write string, move cursor
	int	0x10

inf_loop:
	jmp inf_loop

print_hex:
	mov cx,#4
print_digit:
	rol dx,#4
	mov ax,#0xe0f
	and al,dl
	add al,#0x30
	cmp al,#0x3a
	jl outp
	add al,#0x07

outp:
	int 0x10
	loop print_digit
	ret

print_nl:
	mov ax,#0xe0d
	int 0x10
	mov al,#0xa
	int 0x10
	ret

msg2:
	.byte 13,10
	.ascii "Now We are in SETUP"
	.byte 13,10,13,10

msg_cursor:
	.byte 13,10
	.ascii "cursor position:"

msg_memory:
	.byte 13,10
	.ascii "memory size:"

msg_cycles:
	.byte 13,10
	.ascii "cyls:"

msg_heads:
	.byte 13,10
	.ascii "heads:"

msg_sectors:
	.byte 13,10
	.ascii "sectors:"

msg_kb:
	.ascii "KB"

msg_lr:
	.byte 13,10

.org 510
boot_flag:
	.word 0xAA55

效果

验证

yzh@ubuntu:~/oslab$ cat bochs/bochsrc.bxrc
romimage: file=$OSLAB_PATH/bochs/BIOS-bochs-latest
megs: 16
vgaromimage: file=$OSLAB_PATH/bochs/vgabios.bin
floppya: 1_44="$OSLAB_PATH/linux-0.11/Image", status=inserted
ata0-master: type=disk, path="$OSLAB_PATH/hdc-0.11.img", mode=flat, cylinders=204, heads=16, spt=38
boot: a
log: $OSLAB_PATH/bochsout.txt
#parport1: enable=0
vga_update_interval: 300000
keyboard_serial_delay: 200
keyboard_paste_delay: 100000
#floppy_command_delay: 50000
cpu: count=1, ips=4000000
mouse: enabled=0
private_colormap: enabled=0
fullscreen: enabled=0
screenmode: name="sample"
i440fxsupport: enabled=0
yzh@ubuntu:~/oslab$ 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值