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.
CodePudding user response:
Problem resolved!
I was using as86 & ld86 to compile and link. In order to make it bootable, I tried to set the 510 & 511 bytes to 0xAA, and 0x55. I expected there were only 512 bytes for the binary, and rewriting the 510&511 bytes would make it work.
But actually, there are 32 bytes MINIX header in the front of the binary which made the total size of the binary 544 bytes. rewriting the bytes on 510&511 makes the whole binary a mess.