Page 1 of 1

What is wrong in this code? - Reading disks

Posted: Mon Feb 15, 2016 4:40 am
by JakTheFifth
When I call this code with the kmain function and run it with virtualbox, it runs but shows nothing.
Can you tell me the problem?

Code: Select all

STRING Read_Disk_Sector()
{
	STRING buffer;
	__asm__ __volatile__ ("movl 0x1f0, %edx; movb 0xa0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f2, %edx; movb 1, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f3, %edx; movb 2, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f4, %edx; movb 0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f5, %edx; movb 0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f7, %edx; movb 0x20, %al; outb %al, %dx;");
	__asm__ __volatile__ ("_continue: inb %dx, %al; testb %al, 8; jz _continue;");
	__asm__ __volatile__ ("movl $512/2, %eax; xorw %bx, %bx; movw $1, %bx; mulw %bx; movl %eax, %ecx;");
	__asm__ __volatile__ ("movl 0x1f0, %edx; rep insw");
	__asm__ __volatile__ ("movl %%edi, %0" :"=r" (buffer) );
	return buffer;
}

void Write_Disk_Sector(STRING buffer)
{
	__asm__ __volatile__ ("movl 0x1f0, %edx; movb 0xa0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f2, %edx; movb 1, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f3, %edx; movb 2, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f4, %edx; movb 0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f5, %edx; movb 0, %al; outb %al, %dx;");
	__asm__ __volatile__ ("movl 0x1f7, %edx; movb 0x30, %al; outb %al, %dx;");
	__asm__ __volatile__ ("_cont: inb %dx, %al; testb %al, 8; jz _cont;");
	__asm__ __volatile__ ("movl $512/2, %eax; xorw %bx, %bx; movw $1, %bx; mulw %bx; movl %eax, %ecx;");
	__asm__ __volatile__ ("movl %0, %%esi;" : : "r"(buffer));
	__asm__ __volatile__ ("movl 0x1f0, %edx; rep outsw");
}

Re: What is wrong in this code? - Reading disks

Posted: Mon Feb 15, 2016 4:46 am
by FallenAvatar
JakTheFifth wrote:...Can you tell me the problem?...
You failed every part of the required knowledge and asking intelligent questions mentioned in the wiki and in the forum rules...?

- Monk

Re: What is wrong in this code? - Reading disks

Posted: Mon Feb 15, 2016 4:54 am
by iansjack
Your code does no screen output, so why would you expect it to show anything?

Large amounts of assembler, such as this, should be written using an assembler, not as inline assembly in a C function.