Currently, I'm reading the Linux kernel source code of v0.01. I'm trying to imitate the code and make it work. But got stuck at the very beginning of the bootsector.
In bootsect.s, the program first load at 0x7c00 and move itself to 0x90000, then jump to 0x90000, but somehow the 'jmpi'
instruction is not work.
SETUPLEN = 4 ! len of setup-sectors, 4 sectors
BOOTSEG = 0x07c0 ! original address of boot sector
INITSEG = 0x9000 ! move bootsect here
SETUPSEG = 0x9020 ! setup starts here
SYSSEG = 0x1000 ! system loaded at 0x10000 (65536)
ENDSEG = SYSSEG + SYSSIZE ! where to stop loading
entry start
start:
mov ax, #BOOTSEG
mov ds, ax
mov ax, #INITSEG
mov es, ax
mov cx, #256
sub si, si
sub di, di
rep
movw ! move bootsect itself to address 0x90000 (256 * 2 Bytes)
jmpi go, INITSEG ! jump to address 0x90000 and execute
!j go
go:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, #0xFF00 ! Top of the stack - ss:sp address is 0x9FF00
! print something
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
mov ax, #0x1300 ! write string, move cursor
int 0x10
msg:
.byte 13,10
.ascii "!"
.byte 13,10,13,10
one more thing I'd like to mention is if I replace the 'jmpi go, INITSEG'
with 'j go'
, it will definitely work and jump to the label 'go'
, but something weird is the character printed on the screen is not what I expected as '!'
, but showing something like "âĄS"
I am not sure if 'jmpi'
does totally not work or just because there's something wrong with the print(0x10) functions so that I can not see anything in the screen.
I am a beginner in assembly language and I have no idea what's wrong in the code, even the code is almost copied from Linux kernel.