flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Use UEFI Graphics Output Protocol Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next |
Author |
|
edfed 18 Apr 2020, 15:12
a caller is the code that's call a function.
a callee is the code called. in french, l'appelant (caller), c'est le programme qui appele l'appelé (callee). le callee, c'est la fonction appelléé par le caller. Code: caller: ;do stuff call callee ;do stuff ... callee: ;do stuff ret you clearlly miss the basics of asm programming, that's not really a problem cause you seems to understand what you talk about and coding in 64bits is not harder to get than in 16 or 32. did you read the fasm manual? it introduce the x86 architecture very well and you'll get every information you need about the function of registers like bp/ebp/rbp. |
|||
18 Apr 2020, 15:12 |
|
revolution 18 Apr 2020, 20:50
Fulgurance: It is a common convention to use RBP to access the stack parameters. This is mostly a historical restriction from the original 8086 where BP would use SS by default and SP could not be used to directly access the stack with MOV. So you will often see {E|R}BP used for reading/writing the stack. Plus using RSP to directly access the stack parameters can be tricky if you intermix PUSH and POP because the RSP value changes.
The requirement to align to a multiple of 16 bytes is to allow callee functions to use the SSE aligned access instructions to access stack data. Callee functions are not required to use SSE, but they can if they wish to, so if you decide not to align the stack then the functions can fail when they use SSE to read/write the stack. This is why some functions still work with an unaligned stack because they don't use SSE. But don't rely on this, a future implementation might use SSE, or a different BIOS from yours might use SSE. I don't see any requirement to have RAX point to the function you are calling. I think you can call it directly "call [R?? + EFI_table.function]". Try it. But get your print function working first, then start trying things and see when it breaks. Last edited by revolution on 19 Apr 2020, 07:50; edited 1 time in total |
|||
18 Apr 2020, 20:50 |
|
Fulgurance 18 Apr 2020, 22:21
I know base about FASM, but when i look after many test i don't understand how to UEFI work, i think i miss some things. I have habits to code with BIOS mbr, without any PE convention, it's very difficult for me now.
I test again.I think after many times, i finally understand something.... Ask me if i make some errors. I have added comments to explain my reason of what i do Code: format pe64 efi entry Main section '.text' code readable executable Main: mov [Handle],rcx mov [SystemTable],rdx push rbp sub rbp,0x20 mov rcx,GUID.EFIGraphicsOutputProtocol;It's address of 64 bits data with the GOP GUID xor rdx,rdx;Not used for this test mov r8,Interface.EFIGraphicsOutputProtocol;It's address where i store address of GOP protocol mov rax,[SystemTable] mov rax,[rax+EFISystemTable.BootServices+EFIBootServices.LocateProtocol] call rax add rsp,0x20 pop rbp jmp $ include "EFIBase/GUID.fasm" include "EFIBase/Interface.fasm" include "EFIBase/EFIDataTypes.fasm" include "EFITableHeader/EFITableHeader.fasm" include "EFISystemTable/EFISystemTable.fasm" include "EFIBootServices/EFIBootServices.fasm" include "EFIBootServices/IndexTables/EFILocateSearchType.fasm" include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm" section '.data' data readable writable executable Handle: dq ? SystemTable: dq ? |
|||
18 Apr 2020, 22:21 |
|
revolution 18 Apr 2020, 22:23
Start with a print output. Get your "hello world" working. Then move on to the GOP stuff.
|
|||
18 Apr 2020, 22:23 |
|
Fulgurance 18 Apr 2020, 22:30
Okay i start simple.I do that.
|
|||
18 Apr 2020, 22:30 |
|
DimonSoft 19 Apr 2020, 07:40
Actually, skipping layers of history is usually a bad idea. Modern stuff looks absolutely logical and goes without saying if you know what problems occured with its predecessors and which way they were solved. And knowing little to nothing about previous versions/platforms makes one just learn certain things by heart, and the things tend to look non-obvious.
|
|||
19 Apr 2020, 07:40 |
|
Fulgurance 19 Apr 2020, 11:09
Quote: Actually, skipping layers of history is usually a bad idea. Modern stuff looks absolutely logical and goes without saying if you know what problems occured with its predecessors and which way they were solved. And knowing little to nothing about previous versions/platforms makes one just learn certain things by heart, and the things tend to look non-obvious. I'm totally agree with you. I know many friend they have done informatic school, but i have seen many of them don't know very well the real working of computer. The worst today, i think all is do to make this more worse. Today all people have habit to go to facility, and many programmer use programming language very far to the true working of computer. Honestly, i'm sad when i seen programmer majority hate assembly and discourage any people to use it. I think the only problem (for me), it's to found good tutorial. Many tutorial are not complete, have errors, and don't explain simple. I have project after i understand totally UEFI system to make assembly programming website I think FASM is the best assembly language to learn and make progress. No any optimization or other features. Just understand what you doing |
|||
19 Apr 2020, 11:09 |
|
DimonSoft 19 Apr 2020, 12:24
Fulgurance wrote: The worst today, i think all is do to make this more worse. Today all people have habit to go to facility, and many programmer use programming language very far to the true working of computer. This will happen until we get another well-paid profession where such people move leaving programming in a burnt-to-ashes state. |
|||
19 Apr 2020, 12:24 |
|
Fulgurance 19 Apr 2020, 15:23
Well, now i have made simple code where i have success to show some text. I have already in past have success to do this with UEFI.
After this text, i have test to call LocateProtocol function, but, when my code run this part, this don't work. I think something is wrong, but i don't understand what... (text after LocateProtocol work) Look: Code: format pe64 efi entry Main section '.text' code readable executable Main: mov [Handle],rcx mov [SystemTable],rdx push rbp sub rbp,0x20 mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,Text call rax add rsp,0x20 pop rbp mov rdx,[SystemTable] ;----------------------------------------------------- push rbp sub rbp,0x20 mov rcx,GUID.EFIGraphicsOutputProtocol mov rax,[rdx+EFISystemTable.BootServices] xor rdx,rdx mov r8,Interface.EFIGraphicsOutputProtocol call [rax+EFIBootServices.LocateProtocol] add rsp,0x20 pop rbp mov rdx,[SystemTable] ;----------------------------------------------------- cmp rax,0x0 jne .Exit push rbp sub rbp,0x20 mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,Text call rax add rsp,0x20 pop rbp .Exit: jmp $ include "EFIBase/GUID.fasm" include "EFIBase/Interface.fasm" include "EFIBase/EFIDataTypes.fasm" include "EFITableHeader/EFITableHeader.fasm" include "EFISystemTable/EFISystemTable.fasm" include "EFIBootServices/EFIBootServices.fasm" include "EFIBootServices/IndexTables/EFILocateSearchType.fasm" include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm" section '.data' data readable writable executable Handle: dq ? SystemTable: dq ? Text: du 'Texte',0x0 |
|||
19 Apr 2020, 15:23 |
|
bitRAKE 19 Apr 2020, 20:24
The next step would be to print the function result - to see what UEFI is saying to you. It's possible your UEFI firmware doesn't support the protocol - can't know without examining the return code.
I'm going to assume it returns: EFI_NOT_FOUND. This would be because a protocol instance isn't attached to your image. The display driver doesn't give every image its interface. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
19 Apr 2020, 20:24 |
|
revolution 19 Apr 2020, 21:40
Fulgurance: This is good. We can now make progress to diagnose and follow what is happening.
But note that you only need the push rbp once at the code entry point. After that you don't need to do pop rbp or push rbp because the stack remains aligned for the entire procedure. |
|||
19 Apr 2020, 21:40 |
|
Fulgurance 19 Apr 2020, 22:37
Quote: But note that you only need the push rbp once at the code entry point. After that you don't need to do pop rbp or push rbp because the stack remains aligned for the entire procedure. Okay.I have applied your advice. Quote: The next step would be to print the function result - to see what UEFI is saying to you. It's possible your UEFI firmware doesn't support the protocol - can't know without examining the return code. But yes, i need to control the UEFI result. Quote: I'm going to assume it returns: EFI_NOT_FOUND. This would be because a protocol instance isn't attached to your image. The display driver doesn't give every image its interface. Do you think i need to pass registration parameter ? Last edited by Fulgurance on 19 Apr 2020, 23:00; edited 4 times in total |
|||
19 Apr 2020, 22:37 |
|
Fulgurance 19 Apr 2020, 22:43
Look, i have removed useless push or pop rbp, but now, the last text call don't work:
Code: format pe64 efi entry Main section '.text' code readable executable Main: mov [Handle],rcx mov [SystemTable],rdx push rbp sub rbp,0x20 mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,Text call rax add rsp,0x20 mov rdx,[SystemTable] ;----------------------------------------------------- sub rbp,0x20 mov rcx,GUID.EFIGraphicsOutputProtocol mov rax,[rdx+EFISystemTable.BootServices] xor rdx,rdx mov r8,Interface.EFIGraphicsOutputProtocol call [rax+EFIBootServices.LocateProtocol] add rsp,0x20 mov rdx,[SystemTable] ;----------------------------------------------------- cmp rax,0x0 jne .Exit sub rbp,0x20 mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,Text call rax add rsp,0x20 .Exit: jmp $ include "EFIBase/GUID.fasm" include "EFIBase/Interface.fasm" include "EFIBase/EFIDataTypes.fasm" include "EFITableHeader/EFITableHeader.fasm" include "EFISystemTable/EFISystemTable.fasm" include "EFIBootServices/EFIBootServices.fasm" include "EFIBootServices/IndexTables/EFILocateSearchType.fasm" include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm" include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm" section '.data' data readable writable executable Handle: dq ? SystemTable: dq ? Text: du 'Texte',0x0 |
|||
19 Apr 2020, 22:43 |
|
revolution 19 Apr 2020, 22:51
If you remove "jne .Exit" does it print the text twice?
|
|||
19 Apr 2020, 22:51 |
|
Fulgurance 19 Apr 2020, 22:56
Oh yes ... i have forgotten that OMG. It's to test quickly the result...sorry.
I have corrected 2 errors into my code, i use add rbp, but it's rsp... Just forgot my post about text problem, sorry But about attached image problem, what do you mean ? (i have checked, when i try to call LocateProtocol, i haven't any good error code. I think i don't call good function. Something is bad |
|||
19 Apr 2020, 22:56 |
|
Fulgurance 20 Apr 2020, 23:32
Just little question i ask me since many long. When i add value to memory, i do mov [memory],value.But when i add value to register, i do mov eax,value.
If i use [eax], what is this ??? |
|||
20 Apr 2020, 23:32 |
|
revolution 21 Apr 2020, 00:22
Code: mov eax,0x12345678 mov byte[0x12345678],'A'; value = 'A', address = 0x12345678 mov byte[eax],'A' ; value = 'A', address = 0x12345678 |
|||
21 Apr 2020, 00:22 |
|
Fulgurance 21 Apr 2020, 11:17
Code: sub rsp,0x20 mov rax,[rdx+EFISystemTable.BootServices+EFIBootServices.HandleProtocol] mov rcx,[Handle] mov rdx,GUID.EFIGraphicsOutputProtocol mov r8,Interface.EFIGraphicsOutputProtocol call rax add rsp,0x20 mov rdx,[SystemTable] I have tried with HandleProtocol function, but the same problem ... What is the problem do you think ? Error return status code don't correspond to any error code... Would you like i upload all of my code to test it? |
|||
21 Apr 2020, 11:17 |
|
sinsi 21 Apr 2020, 14:06
Untested
Code: ;assume the stack hasn't changed since program entry from RDX sub rsp,28h ;change to 20h if you have aligned the stack to 16 mov rax,[SystemTable] ;assuming saved on program entry mov rax,[rax+EFISystemTable.BootServices] mov rcx,[Handle] mov rdx,GUID.EFIGraphicsOutputProtocol ;RDX = address of GUID mov r8,Interface.EFIGraphicsOutputProtocol ;R8 = address of QWORD call [rax+EFIBootServices.HandleProtocol] add rsp,xx ;Interface.EFIGraphicsOutputProtocol should now have a pointer to the protocol |
|||
21 Apr 2020, 14:06 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.