Skelix的實驗平臺是linux,我這里沒有,索性在windows建立一個模擬的,用mysys和mingw也可以用,但代碼問題多多。
這里修改的代碼時Skelix教程的第二篇里面的源碼,一一記錄下來先:
1. 修改makefile,如下:
AS=as -Iinclude
LD=ld

KERNEL_OBJS= load.o

.s.o:

$
{AS} -a $< -o $*.o >$*.map

all: final.img


final.img: bootsect kernel $
{KERNEL_OBJS}
objcopy -S -O binary bootsect.o bootsect

objcopy -S -O binary $
{KERNEL_OBJS} kernel
@wc -c kernel
cat bootsect kernel > final.img
@wc -c final.img

bootsect: bootsect.o

$
{LD} -N -e start -Ttext 0x7c00 -o bootsect $<


kernel: $
{KERNEL_OBJS}

$
{LD} -N -e pm_mode -Ttext 0x0000 -o $@ $
{KERNEL_OBJS}

clean:
rm -f *.img kernel bootsect *.o *.map

修改理由:ld在windows無法之間生產(chǎn)二進制文件,需要使用objcopy來產(chǎn)生二進制文件
2. 修改load.s代碼如下:
# Skelix by Xiaoming Mo (xiaoming.mo@skelix.org)
# Licence: GPLv2
.text
.globl pm_mode
.include "kernel.inc"
.org 0
pm_mode:
movl $DATA_SEL,%eax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss
movl $STACK_BOT,%esp

cld
movl $0x10200,%esi
movl $0x200, %edi
movl $(KERNEL_SECT-1)<<7,%ecx
rep
movsl

movb $0x06, %al #橙色輸出
movl $msg, %esi
movl $0xb8000,%edi
1:
cmpb $0, (%esi)
je 1f
movsb
stosb
jmp 1b
1: jmp 1b
msg:
.string "Hello World!\x0"

修改理由:偶喜歡橙子,把白字干脆改成橙色的,純屬個人愛好
3.修改bootsect.s代碼如下(修改理由:不知是不是ld在windows下的bug,鏈結的代碼的起始地址0x7c00沒有效果,偶只好在程序里面在設定一下ds段寄存器):
# Skelix by Xiaoming Mo (xiaoming.mo@skelix.org)
# Licence: GPLv2
.text
.globl start
.include "kernel.inc"
.code16
start:
jmp code
gdt:
.quad 0x0000000000000000 # null descriptor
.quad 0x00cf9a000000ffff # cs
.quad 0x00cf92000000ffff # ds
.quad 0x0000000000000000 # reserved for further use
.quad 0x0000000000000000 # reserved for further use
gdt_48:
.word .-gdt-1 # Special pointer which includes the limit: The max bytes
# taken up by the GDT, minus 1. Again, this NEEDS to be packed

.long GDT_ADDR
code:
xorw %ax, %ax
movw %ax, %ds # ds = 0x0000
movw %ax, %ss # stack segment = 0x0000
movw $0x1000,%sp # arbitrary value
# used before pmode

## read rest of kernel to 0x10000
movw $0x1000,%ax
movw %ax, %es
xorw %bx, %bx # es:bs destination address
movw $KERNEL_SECT,%cx
movw $1, %si # 0 is boot sector,跳過引導扇區(qū)
rd_kern:
call read_sect
addw $512, %bx
incw %si
loop rd_kern
#add by Liu Qi for debug
pushw %ax
movb $0x32, %al
movb $0x0e, %ah
int $0x10
popw %ax
#end of add by Liu Qi

cli
## move first 512 bytes of kernel to 0x0000
## it will move rest of kernel to 0x0200,
## that is, next to this sector
##注意:實模式下的中斷向量表會被覆蓋
cld
movw $0x1000,%ax
movw %ax, %ds
movw $0x0000,%ax
movw %ax, %es
xorw %si, %si
xorw %di, %di
movw $512>>2,%cx
rep
movsl
#add by Liu Qi
movw $0x7c0, %ax
movw %ax, %ds
#end of add by Liu QI
## move gdt
movw $GDT_ADDR>>4,%ax
movw %ax, %es
movw $gdt, %si
xorw %di, %di
movw $GDT_SIZE>>2,%cx
rep
movsl


enable_a20:
## The Undocumented PC
inb $0x64, %al
testb $0x2, %al
jnz enable_a20
movb $0xdf, %al
outb %al, $0x64

#add by Liu Qi
movw $0x7c0, %ax
movw %ax, %ds
#end of add by Liu QI
lgdt gdt_48 #注意:這里應該使用的ds訪問gdt_48
## enter pmode
movl %cr0, %eax
orl $0x1,%eax
movl %eax, %cr0

ljmp $CODE_SEL, $0x0

## in: ax: LBA address, starts from 0
## es:bx address for reading sector
read_sect:
pushw %ax
pushw %cx
pushw %dx
pushw %bx

movw %si, %ax
xorw %dx, %dx
movw $18, %bx # 18 sectors per track
# for floppy disk
divw %bx
incw %dx
movb %dl, %cl # cl=sector number
xorw %dx, %dx
movw $2, %bx # 2 headers per track
# for floppy disk
divw %bx

movb %dl, %dh # head
xorb %dl, %dl # driver
movb %al, %ch # cylinder
popw %bx # save to es:bx
rp_read:
movb $0x1, %al # read 1 sector
movb $0x2, %ah
int $0x13
jc rp_read
popw %dx
popw %cx
popw %ax
ret
.org 0x1fe, 0x90
.word 0xaa55

這里修改的代碼時Skelix教程的第二篇里面的源碼,一一記錄下來先:
1. 修改makefile,如下:








































2. 修改load.s代碼如下:




































3.修改bootsect.s代碼如下(修改理由:不知是不是ld在windows下的bug,鏈結的代碼的起始地址0x7c00沒有效果,偶只好在程序里面在設定一下ds段寄存器):











































































































































