Hi, I want to call 'C' functions through my assembly language code at boot time. But its not working.
;---------bootmz.asm %define bootseg 0 %define bootoff 7C00h %define loadoff 7E00h ORG 7c00h ;Because BIOS loades the OS at ; address 0:7C00h so ORG 7C00h ; makes that the refrence to date ; are with the right offset (7c00h). ; CS = 0 / IP = 7C00h // SS = ? / SP = ? ; You are now at address 7c00. jmp start ;Here we start the, BIOS gave us now the control. ;/////////////////////////////////////////// ;//Here goes all the data of the program. ;/////////////////////////////////////////// xCursor db 0 yCursor db 0 nSector db 0 nTrack db 0 nSide db 0 nDrive db 0 nTrays db 0 ; szReady db 'Are You Ready to start Loading the OS...',0 szErrorReadingDrive db 'Error Reading Drive, Press any Key to reboot...',0 ;//Done Reading a track. szPlaceMarker db '~~~~',0 szDone db 'Done',0 pOS dw loadoff ;//Points to where to download the Operating System. ;///////////////////////////////// ;//Here the program starts. ;///////////////////////////////// start: CLI ;Clear Interupt Flag so while setting ;up the stack any interrupt would not be fired. ;----------------STACK mov AX,7B0h ;lets have the stack start at 7c00h-256 = 7B00h mov SS,ax ;SS:SP = 7B0h:256 = 7B00h:256 mov SP,256 ;Lets make the stack 256 bytes. XOR AX,AX ;Makes AX=0. MOV ES,AX ;Make ES=0 mov DS,ax STI ;Set Back the Interupt Flag after ;we finished setting a stack frame. Call ClearScreen ;ClearScreen() LEA AX,[szReady] ;Get Address of szReady. CALL PrintMessage ;Call PrintfMessage() CALL GetKey ;Call GetKey() mov bp, 1 ; sectors to load CALL DownloadOS ; CALL GetKey ;Call GetKey() CALL GiveControlToOS ;Give Control To OS. ;///////////////////////////////////// ;//Prints a message to the screen. ;///////////////////////////////////// PrintMessage: mov DI,AX ;AX holds the address of the string to Display. Mov byte [xCursor],1 ;Column. ContinuPrinting: cmp byte [DI],0 ;Did we get to the End of String. JE EndPrintingMessage ;if you get to the end of the string return. mov AH,2 ;Move Cursor mov DH,[yCursor] ;row. mov DL,[xCursor] ;column. mov BH,0 ;page number. INT 10h INC byte [xCursor] mov AH,0Ah ;Display Character Function. mov AL,[DI] ;character to display. mov BH,0 ;page number. mov CX,1 ;number of times to write character INT 10h INC DI ;Go to next character. JMP ContinuPrinting ;go to Print Next Character. EndPrintingMessage: Inc byte [yCursor] ;So Next time the message would ;be printed in the second line. cmp byte [yCursor],25 JNE dontMoveCorsurToBegin Mov byte [yCursor],0 dontMoveCorsurToBegin: ret ;PrintMessage EndP ;////////////////////////////////////// ;//Waits for the user to press a key. ;////////////////////////////////////// GetKey: ; PROC mov ah,0 int 16h ;Wait for a key press. Ret ;/////////////////////////////////////////// ;//Gives Control To Second Part Loader. ;/////////////////////////////////////////// GiveControlToOS: LEA AX,[szDone] Call PrintMessage CALL GetKey jmp 7E0h:40h mov ax, [loadoff + 18h] push 7E0h push ax retf ;/////////////////////////////////// ;//Clear Screen. ;/////////////////////////////////// ClearScreen: mov ax,0600h ;//Scroll All Screen UP to Clear Screen. mov bh,07 mov cx,0 mov dx,184fh int 10h Mov byte [xCursor],0 ;//Set Cursor Position So next ;//write would start in ;//the beginning of screen. Mov byte [yCursor],0 Ret ;///////////////////////////////// ;//PrintPlaceMarker. ;///////////////////////////////// PrintPlaceMarker: LEA AX,[szPlaceMarker] CALL PrintMessage ;Call PrintfMessage() ; CALL GetKey ;Call GetKey() ret ;/////////////////////////////////// ;//DownloadOS ;/////////////////////////////////// DownloadOS: mov byte [nDrive],0 mov byte [nSide],0 mov byte [nTrack],0 mov byte [nSector],1 ; desired sector - 1! ContinueDownload: INC byte [nSector] ;Read Next Sector. cmp byte [nSector],19 ;Did we get to end of track. JNE StayInTrack CALL PrintPlaceMarker ;Print now '~~~~' so the user would ;know that we finished reading a track INC byte [nTrack] ;If we get to end of track Move to next track. mov byte [nSector],1 ;And Read Next Sector. CMP byte [nTrack],5 ;Read 5 Tracks (Modify this value ;to how much Tracks you want to read). JE EndDownloadingOS StayInTrack: ;ReadSector(); Call ReadSector dec bp jz EndDownloadingOS JMP ContinueDownload ;If didn't yet finish Loading OS. EndDownloadingOS: ret ;//////////////////////////////////////// ;//Read Sector. ;//////////////////////////////////////// ReadSector: mov byte [nTrays],0 TryAgain: mov AH,2 ;//Read Function. mov AL,1 ;//1 Sector. mov CH,[nTrack] mov CL,[nSector] ;//Remember: Sectors start with 1, not 0. mov DH,[nSide] mov DL,[nDrive] Mov BX,[pOS] ;//ES:BX points to the address ;to were to store the sector. INT 13h jnc EndReadSector mov AH,0 ;Else Reset Drive . And Try Again... INT 13h cmp byte [nTrays],3 ;Check if you tryed reading ;more then 3 times. JE DisplayError ; if tryed 3 Times Display Error. INC byte [nTrays] jmp TryAgain ;Try Reading again. DisplayError: LEA AX,[szErrorReadingDrive] Call PrintMessage Call GetKey mov AH,0 ;Reboot Computer. INT 19h EndReadSector: ADD WORD [pOS],512 ;//Move the pointer ;(ES:BX = ES:pOS = 0:pOS) 512 bytes. ;//Here you set the varible ;pOS (pOS points to were BIOS ;//Would load the Next Sector). Ret ;//////////////////////////////////// ;// ;//////////////////////////////////// times 510 - ($ - $$) db 0 db 55h, 0AAh ;------------------- ;Kernel code calling 'C' language function ;test_k.asm global _Test extern _K_main segment code ;--- test kernel.bin--- segment code _Test: mov ds,ax mov es,ax mov si, msg mov ah, 0Eh mov bx, 7 top: lodsb cmp al, 0 jz blackhole int 10h jmp short top blackhole: call _K_main; this is in main1.c hlt jmp blackhole ret msg db 'Welcome to the Kernel!', 0 times 0x200-($-$$) db 0 ;----------------------------- ;C program, main1.c #define WHITE_TXT 0x07 void K_clear_screen(); unsigned int K_printf(char *message, unsigned int line); //void update_cursor(int row, int col); K_main(){ K_clear_screen(); K_printf("Hi\n How is this for a starter OS?",0); } void K_clear_screen() { char *vidmem=(char*) 0xb8000; unsigned int i=0; while(i<(80*25*2)) { vidmem[i]=' '; i++; vidmem[i]=WHITE_TXT; } } unsigned int K_printf(char *message, unsigned int line){ char *vidmem=(char *) 0xb8000; unsigned int i=0; i=(line*80*2); while(*message!=0) { if(*message=='\n') { line++; i=(line*80*2); *message++; } else { vidmem[i]=*message; *message++; i++; vidmem[i]=WHITE_TXT; i++; } } return 1; } ;-------------compiling infor nasm -f bin bootmz.asm -o boot.bin nasm -f obj test_k.asm gcc -c main1.c alink -oEXE test_k.obj main1.o copy /b boot.bin+test_k.exe image.bin partcopy image.bin 0 323 -f0 Can somebody plz help me with this? Zulfi. -- View this message in context: http://www.nabble.com/Unable-to-call-%27C%27-functions-at-boot-time-tp24585771p24585771.html Sent from the gcc - Gnu Help List mailing list archive at Nabble.com. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus