seb15753

kern/kernel.c

Jun 24th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.19 KB | None | 0 0
  1. //a.michelizza.free.fr
  2. #define mysect 2880
  3.  
  4. #define nbrSectorsToRead 10//1*2048 //*512 pour obtenir le nombre d'octets.
  5. #include "types.h"
  6. #include "gdt.h"
  7. #include "io.h"
  8.  
  9. void findString(char *addr,char *str);
  10. void printHexa(unsigned int dec,int nbrDigit);
  11. int bl_read(int drive, int numblock, int count, char *buf);
  12. void _start(void)
  13. {
  14.     //check is A20 is OK
  15.         init_gdt();
  16.         asm("   movw $0x18, %ax \n \
  17.                movw %ax, %ss \n \
  18.                movl $0x1fffffff, %esp");
  19.        
  20.         asm volatile("mov %0,(0x00200000)\n\t"::"a"(printHexa));
  21.  
  22.     bl_read(0, mysect, nbrSectorsToRead, (char*)0x00400200);//512i
  23.     findString((char *)0x00400200,"\n=BEGIN TRUE CODE=\n");
  24.  
  25.         asm volatile("jmp 0x00400200\n\t");
  26. }
  27. void findString(char *addr,char *str)
  28. {
  29.     char *addrb;
  30.     char *strb;
  31.     while(1)
  32.     {
  33.         if(*addr == *str)
  34.         {
  35.             addrb=addr;
  36.             strb=str;
  37.             while(*addrb == *strb || *strb == 0)
  38.             {
  39.                 if(*strb == 0)
  40.                 {
  41.                     asm volatile("movl %0,(0x10000000)"::"a"(addr));
  42.                     return;
  43.                 }
  44.                 addrb++;
  45.                 strb++;
  46.             }
  47.         }
  48.  
  49.         addr++;
  50.     }
  51. }
  52. void printHexa(unsigned int dec,int nbrDigit)
  53. {
  54.         return;
  55. }
  56. int bl_read(int drive, int numblock, int count, char *buf)
  57. {
  58.  
  59.         u16 tmpword;
  60.         int idx;
  61.  
  62.         outb(0x1F1, 0x00);      /* NULL byte to port 0x1F1 */
  63.         outb(0x1F2, (unsigned char)count);      /* Sector count */
  64.         outb(0x1F3, (unsigned char) numblock);  /* Low 8 bits of the block address */
  65.         outb(0x1F4, (unsigned char) (numblock >> 8));   /* Next 8 bits of the block address */
  66.         outb(0x1F5, (unsigned char) (numblock >> 16));  /* Next 8 bits of the block address */
  67.  
  68.         /* Drive indicator, magic bits, and highest 4 bits of the block address */
  69.         outb(0x1F6, 0xE0 | (drive << 4) | ((numblock >> 24) & 0x0F));
  70.         outb(0x1F7, 0x20);
  71.  
  72.         /* Wait for the drive to signal that it's ready: */
  73.         while (!(inb(0x1F7) & 0x08));
  74.  
  75.         for (idx = 0; idx < 256 * count; idx++) {
  76.                 tmpword = inw(0x1F0);
  77.                 buf[idx * 2] = (unsigned char) tmpword;
  78.                 buf[idx * 2 + 1] = (unsigned char) (tmpword >> 8);
  79.         }
  80.         return count;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment