Can pass args to child via varargs
This commit is contained in:
parent
5729c6c893
commit
6e66cb9bbe
14
kernel.c
14
kernel.c
@ -212,7 +212,7 @@ void PrintFileList() {
|
|||||||
vga_text = nextLine(vga_text) + 3;
|
vga_text = nextLine(vga_text) + 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extern void create_child(uint32_t esp, uint32_t eip);
|
extern void create_child(uint32_t esp, uint32_t eip, uint32_t argc, ...);
|
||||||
void FileSelect() {
|
void FileSelect() {
|
||||||
fileCount = 5;
|
fileCount = 5;
|
||||||
uint16_t *vga_text = (uint16_t *)0xb8000;
|
uint16_t *vga_text = (uint16_t *)0xb8000;
|
||||||
@ -245,21 +245,23 @@ void FileSelect() {
|
|||||||
if (fileHovered < 0) fileHovered = fileCount - 1;
|
if (fileHovered < 0) fileHovered = fileCount - 1;
|
||||||
break;
|
break;
|
||||||
case 0x14: // t
|
case 0x14: // t
|
||||||
create_child(0x3C0000, (uintptr_t)RunTests);
|
create_child(0x380000, (uintptr_t)RunTests, 0);
|
||||||
SetCursorDisabled();
|
SetCursorDisabled();
|
||||||
DrawScreen();
|
DrawScreen();
|
||||||
reload = 1;
|
reload = 1;
|
||||||
break;
|
break;
|
||||||
case KEY_X:
|
case KEY_X:
|
||||||
File83ToPath((char*)entries[fileHovered].name, (char*)path);
|
File83ToPath((char*)entries[fileHovered].name, (char*)path);
|
||||||
HexViewTest(path, &vi);
|
//HexViewTest(path, &vi);
|
||||||
|
create_child(0x380000, (uintptr_t)HexViewTest, 2, path, &vi);
|
||||||
SetVideo25Lines();
|
SetVideo25Lines();
|
||||||
SetCursorDisabled();
|
SetCursorDisabled();
|
||||||
DrawScreen();
|
DrawScreen();
|
||||||
break;
|
break;
|
||||||
case KEY_V:
|
case KEY_V:
|
||||||
File83ToPath((char*)entries[fileHovered].name, (char*)path);
|
File83ToPath((char*)entries[fileHovered].name, (char*)path);
|
||||||
TextViewTest(path, &vi);
|
//TextViewTest(path, &vi);
|
||||||
|
create_child(0x380000, (uintptr_t)TextViewTest, 2, path, &vi);
|
||||||
SetVideo25Lines();
|
SetVideo25Lines();
|
||||||
SetCursorDisabled();
|
SetCursorDisabled();
|
||||||
DrawScreen();
|
DrawScreen();
|
||||||
@ -321,10 +323,10 @@ void start() {
|
|||||||
vga_text += printStr("Press T for tests, or any key to continue... ", vga_text);
|
vga_text += printStr("Press T for tests, or any key to continue... ", vga_text);
|
||||||
uint8_t key = get_key();
|
uint8_t key = get_key();
|
||||||
if (key == 't' || key == 'T')
|
if (key == 't' || key == 'T')
|
||||||
RunTests(vga_text);
|
create_child(0x380000, (uintptr_t)RunTests, 0);
|
||||||
DrawScreen();
|
|
||||||
SetVideo25Lines();
|
SetVideo25Lines();
|
||||||
SetCursorDisabled();
|
SetCursorDisabled();
|
||||||
|
DrawScreen();
|
||||||
FileSelect();
|
FileSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
task.nasm
15
task.nasm
@ -7,16 +7,25 @@ ret
|
|||||||
global task_ptr
|
global task_ptr
|
||||||
task_ptr: equ (0x310000-4)
|
task_ptr: equ (0x310000-4)
|
||||||
|
|
||||||
|
; TODO Is varargs too compiler dependent?
|
||||||
; extern void create_child(uint32_t esp, uint32_t eip);
|
; extern void create_child(uint32_t esp, uint32_t eip, uint32_t argc, ...);
|
||||||
global create_child
|
global create_child
|
||||||
create_child:
|
create_child:
|
||||||
|
xchg bx,bx
|
||||||
mov eax, [esp] ; return address
|
mov eax, [esp] ; return address
|
||||||
lea ecx, [esp+4] ; return stack, minus address
|
lea ecx, [esp+4] ; return stack, minus address
|
||||||
call save_current_task
|
call save_current_task
|
||||||
xchg bx,bx
|
|
||||||
mov eax, [esp+8] ; new eip
|
mov eax, [esp+8] ; new eip
|
||||||
|
mov ecx, [esp+12] ; argc
|
||||||
|
mov esi, esp ; old esp
|
||||||
mov esp, [esp+4] ; new esp
|
mov esp, [esp+4] ; new esp
|
||||||
|
lea esi, [esi+16] ; args
|
||||||
|
mov edx, ecx
|
||||||
|
neg edx
|
||||||
|
lea esp, [esp+edx*4] ; adjust for args
|
||||||
|
mov edi, esp
|
||||||
|
; copy varargs to new stack
|
||||||
|
rep movsd
|
||||||
push return_prev_task ; if child returns, return to prev task
|
push return_prev_task ; if child returns, return to prev task
|
||||||
push eax
|
push eax
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user