Page 1 of 1

Strange error occurs in my kernel and I don't know how to fix it.

Posted: Sat Aug 03, 2024 1:58 am
by TYDQSoft
I was trying to build my test OS kernel booted by UEFI and trying to make the whole screen become white color.
However,I was failed and can't resolve this error to now.I was confused and don't know how to do.
This is my test kernel's code(in pascal):

Code: Select all

program kernelmain;

uses bootconfig,graphics;

function kernel_main(param:sys_parameter):Pointer;[public,alias:'_start'];
var Pparam1:Pscreen_config;
    screenconfig:screen_config;
    ptr:Pgraphics_item;
    res:Pqword;
begin
 Pparam1:=Pointer(param.param_content);
 screenconfig:=Pparam1^;
 graphics_heap_initialize;
 ptr:=graphics_heap_getmem(1,1,screenconfig.screen_scanline,screenconfig.screen_height);
 graphics_draw_block(ptr,1,1,screenconfig.screen_scanline,screenconfig.screen_height,$FF,$FF,$FF,$FF);
 graphics_heap_output_to_screen(screenconfig.screen_address,screenconfig.screen_scanline,screenconfig.screen_height);
 res:=allocmem(sizeof(qword));
 res^:=120;
 kernel_main:=res;
end;

begin
end.
and graphics unit is too large to put forward in this forum,so I put forward in github website.
System.pas is also too large in this topic and put forward in github too.
You can read my problematic code in the hyperlink(the project itself is problematic so you do not imitate it) below:
My problematic kernel is on https://github.com/TYDQSoft/UEFIPascalOS

Re: Strange error occurs in my kernel and I don't know how to fix it.

Posted: Sat Aug 03, 2024 11:57 am
by PavelChekov
What exactly is the error? Does the screen not become white? Does the code not compile?

Re: Strange error occurs in my kernel and I don't know how to fix it.

Posted: Sat Aug 03, 2024 6:17 pm
by TYDQSoft
Yes,the screen does not become white and it stucks due to fault error.

Re: Strange error occurs in my kernel and I don't know how to fix it.

Posted: Sat Aug 03, 2024 10:24 pm
by nullplan
I would suggest that you get your exception handlers in order. In a graphical OS, a simple way to get debug information out would be through the serial port. A write-only PIO serial port driver is easy to write, and it would allow you to send diagnostic information, such as what exception is happening and where.

Re: Strange error occurs in my kernel and I don't know how to fix it.

Posted: Sun Aug 04, 2024 1:03 am
by TYDQSoft
nullplan wrote: Sat Aug 03, 2024 10:24 pm I would suggest that you get your exception handlers in order. In a graphical OS, a simple way to get debug information out would be through the serial port. A write-only PIO serial port driver is easy to write, and it would allow you to send diagnostic information, such as what exception is happening and where.
I discovered the parameters does not transmit properly.However,I can't find why the parameters does not transmit properly.
This is my code to execute the kernel by uefi loader.

Code: Select all

function sys_parameter_function_execute(func:sys_parameter_function_and_parameter):Pointer;[public,alias:'sys_parameter_function_execute'];
var ptr:PByte;
begin
 if(func.parameter_result_size>0) then
  begin
   ptr:=func.parameter_function.func(func.parameter_parameter);
   sys_parameter_function_execute:=ptr;
  end
 else if(func.parameter_result_size=0) then
  begin
   func.parameter_function.proc(func.parameter_parameter);
   sys_parameter_function_execute:=nil;
  end;
end;
And that is my code segment to load the elf and then execute the elf file:

Code: Select all

initparam:=allocmem(sizeof(sys_parameter_item));
 initparam^.item_content:=@screenconfig;
 initparam^.item_size:=sizeof(screen_config);
 param:=sys_parameter_construct(initparam,1);
 funcaddr:=sys_function(KernelEntry);
 efi_console_output_String(systemtable,'S1'#10);
 func.func:=funcaddr;
 efi_console_output_String(systemtable,'S2'#10);
 funcandparam:=sys_parameter_and_function_construct(param,func,sizeof(qword));
 efi_console_output_String(systemtable,'S3'#10);
 res:=sys_parameter_function_execute(funcandparam);
 efi_console_output_String(systemtable,'S4'#10);
 partstr:=UintToPWChar(Pqword(res)^);
 efi_console_output_string(systemtable,partstr);
 Wstrfree(partstr);
 efi_console_output_String(systemtable,'S5'#10);
 freemem(res);
 efi_console_output_String(systemtable,'S6'#10);
 sys_parameter_and_function_free(funcandparam);
 efi_console_output_String(systemtable,'S7'#10);
 freemem(initparam);
 efi_console_output_String(systemtable,'S8'#10);