I was testing the numbers on a boot I had from a small NASM build. Mainly I was practicing making more space from the 512 boot code from the BIOS 13h function. Curiously my build drops the link to other files at a certain level. I tried squeezing through as much through as I could to get to 512 section right before 0x10000 but I haven't been able to get anything else passed here.
I noticed how al=65 was the highest placement. Figures the computation here was around 66th for the 64kb boundary <=> 0x7C00 +66 (
(*512b=0x1000)=0x7C00+2*(0x0200)+64(0x0200) . Therefore the cause seems to be related to the int 13 BIOS configuration. The current model is more similar to other sources like wikipedia however I guess I still don't understand what is stopping the function. Here's when I tried calling int 13 from the section right before the gap but now I just keep getting this ld check.
ld: warning: cannot find entry symbol _start; defaulting to 0000000000010000
stage2.o:stage2.asm:15:(.text+0xc): relocation truncated to fit: R_386_16 against `.text'
make: *** [Makefile:27: stage2.bin] Error 1
I'd like to add too that if I change the address variables to before the 64k address (like 0xFC00 <=>64) the code does build. Now my question is on how to use the BIOS 13h for the sections.
Here's the quick version to illustrate the current bug I get.
boot.asm
[BITS 16]
;[ORG 0x7c00]
section .text
_prep_module:
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7C00
DriveIdPrep:
mov [DriveId],dl
mov ah,0x41
mov bx,0x55aa
int 0x13
; jc CheckPrep
cmp bx,0xaa55
; jne CheckPrep
SizeFunction:
mov bx,0x0000_7E00
mov cl,2
mov ah,0x02
; mov al,1
; mov al,12h
mov al,65
mov ch,0
mov dh,0
int 0x13
; jc ReadCheck
mov dl,[DriveId]
.move1:
mov cx,0xfe00
jmp cx
jmp $
Section .data
String: db 'Check',0
DriveId: db 0
MessageLen: equ $-String
ReadPacket: times 16 db 0
ROWS EQU 25
COLS1 EQU 80
BACK1 EQU 05h
FRONT1 EQU 12h
CHECKER EQU 0
Graphics_CTRLA EQU 03CEh
Sequencer_CTRLA EQU 03C4h
Crd1Size EQU 640
HDATA EQU (Crd1Size/8)
Graph_Segment EQU 0A000H
crd1 EQU 45
crd2 EQU 54
color EQU 05h
X dd 0
Y dd 0
color_pkg dw 0x05
LoopVar1: db 0
Value1: db 0
link.ld
INPUT (boot.o)
OUTPUT_FORMAT(binary)
OUTPUT_ARCH(i386)
ENTRY(_prep_module)
SECTIONS
{
. = 0x7c00;
_premier = .;
_prep_module =.;
.text . :
{boot.o(.text)}
.rodata : {boot.o(.rodata)}
.data 0x7D00 : {boot.o(.data)}
. = _premier + 512*1-2;
.dummy 0x7dfe : {BYTE(0x55); BYTE(0xaa);}
_bss_premier =.;
.bss : {*(.bss)}
_bss_stub = .;
_heap = .;
/DISCARD/ : {*(.comment)*(.eh_frame)*(.note.GNU.stack)}
}
stage1.asm
[BITS 16]
;[BITS 32]
section .text
SizeFunction2:
xor cx,cx
push cx
mov cx,0x1000
mov es,cx
mov bx,0x0000
mov cl,2
mov ah,0x02
; mov al,1
; mov al,12h
mov al,66
mov ch,0
mov dh,0
int 0x13
; jc ReadCheck
pop cx
mov es,cx
; mov dl,[DriveId]
mov ax,0
mov ds,ax
mov cx,0xb800
mov es,cx
cld
mov si,String
call print_str
.move1:
jmp 0x10000
; jmp 0xFC00
; jmp $
print_str:
mov ah,0xde
mov bp,320
.loop1:
mov al,byte [ds:si]
mov es:[bp],ax
inc si
; inc si
inc bp
inc bp
cmp bp,320+StringLen*2
jnz .loop1
ret
;section .data
String: db 'test string',0
StringLen: equ $-String
stage2.asm
[bits 16]
;[bits 32]
;_prep_module2:
;mov ax,0
mov ax,0x1000
mov ds,ax
mov cx,0xb800
mov es,cx
cld
mov si,String
call print_str
jmp $
print_str:
mov ah,0xde
mov bp,0
.loop1:
mov al,byte [ds:si]
mov es:[bp],ax
inc si
; inc si
inc bp
inc bp
cmp bp,StringLen*2
jnz .loop1
ret
;section .data
String: db 'test string',0
StringLen: equ $-String
Makefile
FILES =boot.o
FILES2 =stage2.o
PROCURE = rm -rf
all: boot.bin stage1.bin stage2.bin
dd if=boot.bin of=os.img bs=512 count=65 conv=notrunc
dd if=stage1.bin of=os.img bs=512 seek=65 conv=notrunc
dd if=stage2.bin of=os.img bs=512 seek=66 conv=notrunc
boot.o: boot.asm
nasm -f elf -g -o boot.o boot.asm
stage1.o: stage1.asm
nasm -f elf -g stage1.asm -o stage1.o
stage2.o: stage2.asm
nasm -f elf -g stage2.asm -o stage2.o
boot.bin: $(FILES)
ld -T link.ld $(FILES) -o boot.bin
stage1.bin: stage1.o
ld -g -m elf_i386 -Ttext 0xfe00 stage1.o -o stage1.bin --oformat binary
stage2.bin: stage2.o
ld -g -m elf_i386 -Ttext 0x10000 stage2.o -o stage2.bin --oformat binary
clean:
$(PROCURE) *\.o
$(PROCURE) *\.bin
$(PROCURE) os.img