Sfoglia il codice sorgente

A toy protect-mode bootloader can display string in real/protect mode of x86.

main
yuchen 9 anni fa
parent
commit
7d29eb7cf0
3 ha cambiato i file con 101 aggiunte e 0 eliminazioni
  1. +12
    -0
      related_info/lab1/pmbootloader/Makefile
  2. +81
    -0
      related_info/lab1/pmbootloader/pmboot.S
  3. +8
    -0
      related_info/lab1/pmbootloader/pmboot.md

+ 12
- 0
related_info/lab1/pmbootloader/Makefile Vedi File

@ -0,0 +1,12 @@
all:pmboot
pmboot.s: pmboot.S
gcc -E pmboot.S > pmboot.s
pmboot.o: pmboot.s
as -o pmboot.o pmboot.s
pmboot: pmboot.o
ld --oformat binary -N -e start -Ttext 0x7c00 -o pmboot pmboot.o
run: pmboot
qemu-system-i386 -fda pmboot
.PHONY: clean
clean:
rm pmboot.o pmboot pmboot.s

+ 81
- 0
related_info/lab1/pmbootloader/pmboot.S Vedi File

@ -0,0 +1,81 @@
#define Descriptor(base,lim,type)\
.word lim&0xffff;\
.word base&0xffff;\
.byte (base>>16)&0xff;\
.word ((lim>>8)&0xf00)|(type&0x0f0ff);\
.byte ((base>>24)&0xff)
DA_C = 0x98
DA_32 = 0x4000
DA_DRW = 0x92
.text
.globl start
.code16
start:
jmpl $0x0, $code
GDT_START:
Descriptor_DUMMY:Descriptor(0x0,0x0,0x0)
Descript_CODE32 :Descriptor(0x0,0xffffffff,DA_C+DA_32)
Descriptor_VIDEO:Descriptor(0xb8000,0x0ffff,DA_DRW)
GDT_END:
GdtPtr:
.word (GDT_END-GDT_START)-1 # so does gdt
.long GDT_START # This will be rewrite by code.
msg:
.string "Hello world!"
code:
mov %cs,%ax
mov %ax,%ds
mov %ax,%es
mov %ax,%ss
mov $0x8000,%sp
/*HelloWorld字符串*/
mov $msg ,%ax
mov %ax ,%bp
mov $12 ,%cx
mov $0x1301,%ax
mov $0x000c,%bx
mov $0 ,%dl
int $0x10
/*gdtr即将全局描述符表gdt的首地址和gdt的界限赋给gdtr寄存器*/
lgdt GdtPtr
/**/
cli
/*线A20*/
inb $0x92,%al
or $0x02,%al
outb %al,$0x92
/*cr0寄存器,*/
movl %cr0,%eax
or $1,%eax
movl %eax,%cr0
/*,CS=0x8,IP=LABEL_SEG_CODE32的偏移地址*/
ljmp $0x8,$(LABEL_SEG_CODE32)
/*CS:IP=1(0x8>>3)+LABEL_SEG_CODE32的偏移地址*/
LABEL_SEG_CODE32:
.align 32
.code32
movw $0x10,%ax
movw %ax,%gs
movl $((80*11+79)*2),%edi/*1179*/
movb $0x0c,%ah/*,*/
movb $'P',%al/**/
movw %ax,%gs:(%edi)
loop2:
jmp loop2
.org 0x1fe, 0x90
.word 0xaa55

+ 8
- 0
related_info/lab1/pmbootloader/pmboot.md Vedi File

@ -0,0 +1,8 @@
From http://blog.csdn.net/guocaigao/article/details/8477929
A toy protect-mode bootloader can display string in real/protect mode of x86.
Try
```
make run
```

Caricamento…
Annulla
Salva