What is wrong in this code? - Reading disks

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
JakTheFifth
Posts: 4
Joined: Tue Sep 15, 2015 1:19 pm

What is wrong in this code? - Reading disks

Post 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");
}
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

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

Post 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
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
Post Reply