Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //a.michelizza.free.fr
- #define mysect 2880
- #define nbrSectorsToRead 10//1*2048 //*512 pour obtenir le nombre d'octets.
- #include "types.h"
- #include "gdt.h"
- #include "io.h"
- void findString(char *addr,char *str);
- void printHexa(unsigned int dec,int nbrDigit);
- int bl_read(int drive, int numblock, int count, char *buf);
- void _start(void)
- {
- //check is A20 is OK
- init_gdt();
- asm(" movw $0x18, %ax \n \
- movw %ax, %ss \n \
- movl $0x1fffffff, %esp");
- asm volatile("mov %0,(0x00200000)\n\t"::"a"(printHexa));
- bl_read(0, mysect, nbrSectorsToRead, (char*)0x00400200);//512i
- findString((char *)0x00400200,"\n=BEGIN TRUE CODE=\n");
- asm volatile("jmp 0x00400200\n\t");
- }
- void findString(char *addr,char *str)
- {
- char *addrb;
- char *strb;
- while(1)
- {
- if(*addr == *str)
- {
- addrb=addr;
- strb=str;
- while(*addrb == *strb || *strb == 0)
- {
- if(*strb == 0)
- {
- asm volatile("movl %0,(0x10000000)"::"a"(addr));
- return;
- }
- addrb++;
- strb++;
- }
- }
- addr++;
- }
- }
- void printHexa(unsigned int dec,int nbrDigit)
- {
- return;
- }
- int bl_read(int drive, int numblock, int count, char *buf)
- {
- u16 tmpword;
- int idx;
- outb(0x1F1, 0x00); /* NULL byte to port 0x1F1 */
- outb(0x1F2, (unsigned char)count); /* Sector count */
- outb(0x1F3, (unsigned char) numblock); /* Low 8 bits of the block address */
- outb(0x1F4, (unsigned char) (numblock >> 8)); /* Next 8 bits of the block address */
- outb(0x1F5, (unsigned char) (numblock >> 16)); /* Next 8 bits of the block address */
- /* Drive indicator, magic bits, and highest 4 bits of the block address */
- outb(0x1F6, 0xE0 | (drive << 4) | ((numblock >> 24) & 0x0F));
- outb(0x1F7, 0x20);
- /* Wait for the drive to signal that it's ready: */
- while (!(inb(0x1F7) & 0x08));
- for (idx = 0; idx < 256 * count; idx++) {
- tmpword = inw(0x1F0);
- buf[idx * 2] = (unsigned char) tmpword;
- buf[idx * 2 + 1] = (unsigned char) (tmpword >> 8);
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment