Make userspace actually work.
[pintos-anon] / src / threads / loader.S
index f2563bb149af8b64c46a07473b3ec1d80906cd1c..c60e8dd6bd3347551b30f727617b113b88494388 100644 (file)
@@ -78,38 +78,53 @@ protcseg:
 
        movl $1, %ebx
        movl $0x100000, %edi
-read_sector:           
+read_sector:
+
+       ### Poll status register while controller busy.
        movl $0x1f7, %edx
 1:     inb %dx, %al
        testb $0x80, %al
        jnz 1b
-       
+
+       ### Read a single sector.
        movl $0x1f2, %edx
        movb $1, %al
        outb %al, %dx
 
+       ### Sector number to write in low 28 bits.
+       ### LBA mode, device 0 in top 4 bits.
        movl %ebx, %eax
        andl $0x0fffffff, %eax
        orl $0xe0000000, %eax
 
+       ### Dump %eax to ports 0x1f3...0x1f6.
        movl $4, %ecx
-2:     incl %edx
+2:     incw %dx
        outb %al, %dx
        shrl $8, %eax
        loop 2b
 
+       ### READ command to command register.
        incw %dx
        movb $0x20, %al
        outb %al, %dx
-       
+
+       ### Poll status register while controller busy.
 1:     inb %dx, %al
        testb $0x80, %al
        jnz 1b
 
+       ### Poll status register until data ready.
+1:     inb %dx, %al
+       testb $0x08, %al
+       jz 1b
+
+       ### Transfer sector.
        movl $512 / 4, %ecx
        movl $0x1f0, %edx
        rep insl
 
+       ### Next sector.
        incl %ebx
        cmpl $KERNEL_LOAD_PAGES*8 + 1, %ebx
        jnz read_sector
@@ -138,6 +153,13 @@ read_sector:
        movl %eax, %cr0
        jmp 1f
 1:
+
+##### Turn on EM bit in CR0, forcing most floating-point instructions
+##### to trap.  We don't support floating-point or MMX.
+
+       movl %cr0, %eax
+       orl $CR0_EM, %eax
+       movl %eax, %cr0
        
 ##### Jump to kernel entry point.