cannot make kernel calls + some forum wierdness
Posted: Wed Oct 21, 2009 12:44 pm
well first thing is:
i went to register at the forum and it said the username already used
so i went to log in with my normal forum username and password and it worked
and i never registered here
ok now getting on to the point:
i wrote a single tasking real mode kernel in tiny memory model
it far calls the child but i cannot call kernel calls like open() or write() or fopen()
it just locks up
child example:
map file:
kernel print function:
boot.asm thanks to the TheNbomr
[/code]
kernel execute function:
floppy image at http://forums.osdever.net/viewtopic.php?f=6&t=53&p=745
i went to register at the forum and it said the username already used
so i went to log in with my normal forum username and password and it worked
and i never registered here
ok now getting on to the point:
i wrote a single tasking real mode kernel in tiny memory model
it far calls the child but i cannot call kernel calls like open() or write() or fopen()
it just locks up
child example:
Code: Select all
void far main(){
((void (far*)(char *))0x40000280L)("Hello world");
asm {retf; db 0EAH} //compiler likes to return near
}
Code: Select all
Start Stop Length Name Class
00000H 01414H 01415H _TEXT CODE
01416H 02129H 00D14H _DATA DATA
0212AH 0212AH 00000H _BSS BSS
Address Publics by Name
0000:06EB absread(int,int,int,void near*)
0000:0746 abswrite(int,int,int,void near*)
0000:0457 clock_hook()
0000:0A33 createfile(char near*,int)
0000:117C debug(char near*,int,int)
0000:033E farstrcpy(char far*,char near*)
0000:0C4E fclose(jfile near*)
0000:0DE5 feof(jfile near*)
0000:09B5 findfile(char near*,int)
0000:0BA7 fopen(char near*,char near*)
0000:0CE2 fread(void near*,long,long,jfile near*)
0000:039B free(void near*)
0000:0E06 fseek(jfile near*,int,char)
0000:0E49 ftell(jfile near*)
0000:0E8B fwrite(void near*,int,int,jfile near*)
0000:0F23 gets(char near*)
0000:07F0 getstring(char near*,char near*,char,int)
0000:0D60 getvector(unsigned char)
0000:0F6E hexdump(char near*,int)
0000:0507 itoa(int,char near*,int)
0000:11B5 kernel_execute(char near*)
0000:0280 kernel_print(char near*)
0000:0234 keyready()
0000:0956 li(char near*,char)
0000:096E locate(char near*,char near*,int near*)
0000:0FA3 login()
0000:06AC malloc(int)
0000:0B08 mgen(char near*)
0000:0141 rand()
0000:0CAA readbyte(jfile near*)
0000:0245 read_keyboard()
0000:0AC9 refresh(jfile near*)
0000:07A1 seperate(char near*,__string near*)
0000:0C69 setbyte(jfile near*,unsigned char)
0000:0D38 setvector(unsigned char,(far*)(),...)
0000:0569 sprintf(char near*,const char near*,...)
0000:0828 str2int(char near*)
0000:0366 strcat(char near*,char near*)
0000:0314 strcpy(char near*,char near*)
0000:018E strlen(char near*)
0000:03DA strlwr(char near*)
0000:01E6 strncat(char near*,char near*,int)
0000:02A6 strncmp(char near*,char near*,int)
0000:0414 strncmpi(char near*,char near*,int)
0000:01AA strncpy(char near*,char near*,int)
0000:04AC strrev(char near*)
0000:03A0 strupr(char near*)
0000:0D82 timer(unsigned int)
0000:0E59 _k_panic(char near*,int)
0000:025E _video_clearscreen()
0000:0271 _video_movecursor(char,char)
0000:0250 _video_putchar(char)
0000:0DBA ____len(jfile near*)
0000:04A0 ____ticker()
0000:0110 DGROUP@
0000:0112 EXEC
0000:12EB _MAIN
0000:141E _OLD_CLOCK
0000:1E45 __P_
Code: Select all
void _far kernel_print(char *data){
for(int h = 0;data[h] && h < 80;h++){
_video_putchar(data[h]);
}
return ;
}
Code: Select all
;
; Boot-n-Load
;
; Bootable floppy. BIOS loads one sector, executes it. The
; executable loads the next level of code.
;
; To build & use (DOS Batch file):
;
;; ;; NASM16 -f bin -o bnl1.bin -l bnl1.lst bnl1.asm
;; ;; NASM16 -f bin -o bnl2.bin -l bnl2.lst bnl2.asm
;; ;; copy /b bnl1.bin+bnl2.bin bnl.bin
;; ;; rawrite2 -f bnl.bin -d A -n
;
LEVEL2_SEG equ 0x4000;0x9000
LEVEL2_OFF equ 0x0100;0x0000
[BITS 16]
[ORG 0]
BnL_start:
;
; We know the absolute address, but some BIOSes use different
; SEG:OFF combos. This makes sure we are using offsets that agree
; with our ORG statement
;
jmp 0x07c0:BnL_Go
BnL_HelloMsg:
db 'BnL ver 0.1',0x0d,0x0a,0
BnL_Go:
mov ax, cs
mov es, ax
mov ds, ax
;
; Set up a stack
;
cli
mov sp, 0xffff
mov ax, LEVEL2_SEG
mov ss, ax
sti
mov si, BnL_HelloMsg ; Print msg
BnL_SayHello:
lodsb ; AL=memory contents at DS:SI
cmp al, 0 ; If AL=0 then done talking
je BnL_ResetDisk ; go on to next step
mov ah, 0x0E ; Print AL
mov bx, 7 ; text attribute/colour
int 10h ; BIOS Print Char
jmp BnL_SayHello ; Print next character
;
; Load the next piece of code from sector 2, 3...
;
BnL_ResetDisk:
mov ax, 0
int 0x13 ;
jc BnL_ResetDisk
BnL_Reload:
mov ax, LEVEL2_SEG
mov es, ax ; SEgment address for destination
mov ah, 02 ; BIOS Int 13h func: Read disk
mov al, 17 ; sector count
mov bx, LEVEL2_OFF ; Address OFFSET for destination (ES:BX --> dest)
mov ch, 0 ; Disk cylinder
mov cl, 2 ; Sector (numbered from 1)
mov dh, 0 ; Head
mov dl, 0 ; Drive
int 0x13
jc BnL_Reload
jmp LEVEL2_SEG:LEVEL2_OFF
TIMES 510-($-$$) db 0x90
dw 0AA55h
;
;=========================================================================
; The following code is loaded from disk sector(s) following
; the sector 1 code loaded and invoked by the BIOS.
; We jump to this code from the bootstrap loader above.
;
;
; mov ax, cs
; mov es, ax
; mov ds, ax
;
; mov si, BnL2_HelloMsg
;BnL2_SayHello:
; lodsb ; AL=memory contents at DS:SI
;
; cmp al, 0 ; If AL=0 then done talking
; je BnL2_Go ; go on to next step
;
; mov ah, 0x0E ; Print AL
; mov bx, 7 ; text attribute/colour
; int 10h ; BIOS Print Char
;
; jmp BnL2_SayHello ; Print next character
;
;
;BnL2_Go:
; jmp $
;
;BnL2_HelloMsg:
; db 'Now using level2 code', 0
;
;times 1022-($-$$) db 0xff
;dw 0AA55h
kernel execute function:
Code: Select all
char kernel_execute(char *file){
kernel_print("\r\nExecuting program : ");
kernel_print(file);
FILE *f; char *buff,*prog,test[10];
int file_length;
f = fopen(file, "r");
kernel_print("\r\n");
kernel_print(itoa(f->sector, test, 10));
if(f==NULL)return FALSE;
file_length = ____len(f)+8;
hexdump(f->buffer); // read_keyboard();
buff = (char *) malloc(file_length + 16);
if (buff == NULL) {
return FALSE;
}
prog = buff + 16 - (((unsigned int) buff) % 16);
kernel_print(itoa(FP_SEG(prog), test, 16));
kernel_print(":");
kernel_print(itoa(FP_OFF(prog), test, 16));
kernel_print("\r\n");
for(int j = 0;j < file_length;j++){
fread(&prog[j], 1, 1, f);
kernel_print(itoa(prog[j], test, 10));
kernel_print(" ");
}
fclose(f);
exec((void *)prog);
free(buff);
return TRUE;
}