I am trying to build an old 16 bit dos like os.
My bootloader code:
; This is not my code. May be of Fritzos. I forgot the source.
ORG 7c00h
jmp Start
drive db 0
msg db " Loader Initialization",0
msg2 db "ACos Loaded",0
print:
lodsb
cmp al, 0
je end
mov ah, 0Eh
int 10h
jmp print
end: ret
Start: mov [ drive ], dl ; Get the floppy OS booted from
; Update the segment registers
xor ax, ax ; XOR ax
mov ds, ax ; Mov AX into DS
mov si,msg
call print
; Load Kernel.
ResetFloppy: mov ax, 0x00 ; Select Floppy Reset BIOS Function
mov dl, [ drive ] ; Select the floppy ADos booted from
int 13h ; Reset the floppy drive
jc ResetFloppy ; If there was a error, try again.
ReadFloppy: mov bx, 0x9000 ; Load kernel at 9000h.
mov ah, 0x02 ; Load disk data to ES:BX
mov al, 17 ; Load two floppy head full's worth of data.
mov ch, 0 ; First Cylinder
mov cl, 2 ; Start at the 2nd Sector to load the Kernel
mov dh, 0 ; Use first floppy head
mov dl, [ drive ] ; Load from the drive kernel booted from.
int 13h ; Read the floppy disk.
jc ReadFloppy ; Error, try again.
; Clear text mode screen
mov ax, 3
int 10h
;print starting message
mov si,msg2
call print
mov ax, 0x0
mov ss, ax
mov sp, 0xFFFF
jmp 9000h
; This part makes sure the bootsector is 512 bytes.
times 510-($-$$) db 0
;bootable sector signature
dw 0xAA55
My example kernel code:
asm(".code16\n");
void putchar(char);
int main()
{
putchar('A');
return 0;
}
void putchar(char val)
{
asm("movb %0, %%al\n"
"movb $0x0E, %%ah\n"
"int $0x10\n"
:
:"r"(val)
) ;
}
This is how I compile it :
nasm -f bin -o ./bin/boot.bin ./source/boot.asm
gcc -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0
dd if=/dev/zero of=./bin/empty.bin bs=1440K count=1
cat ./bin/boot.bin ./bin/kernel.bin ./bin/empty.bin|head -c 1440K > ./bin/os
rm ./bin/empty.bin
and I run it in virtual machine.
When I make the putchar function ( in kernel code ) for constant value ....i.e like this:
void putchar()
{
char val = 'A';
asm("movb %0, %%al\n"
"movb $0x0E, %%ah\n"
"int $0x10\n"
:
:"r"(val)
) ;
}
then it works fine. But when I pass argument to it ( That is in the previous code ) , then it prints a space for any character.
What should I do?