Contribute
Register

[Guide] How to patch DSDT for working battery status

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,717
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dell XPS 18 - Is it possible?

After reading through the first portion, and going through my own DSDT, I only have 8 lines (all 16 bit) that need to be patched. I guess, being a newbie to this entire thing, I got a lucky break.:think:

What I need to figure out is where I have to type in the changes... that's the part that I still don't get. On to more reading... :banghead:
It is best to build a text file as you go. Then you copy/paste from the text file into the MaciASL patch window.

BTW, you definitely got lucky as having only 16-bit makes it pretty easy...
 
Joined
Dec 29, 2012
Messages
354
Motherboard
Dell XPS 18
CPU
Intel Core i3-3227U CPU @ 1.90GHz
Graphics
Intel HD Graphics 4000
Mac
Classic Mac
Mobile Phone
Dell XPS 18 - Is it possible?

quick question...

In the post that I'm following to fix the battery status, you wrote the following:

Code:
[FONT=Helvetica][FONT=arial]into method label GBTI code_regex \(BFC1, replaceall_matched begin (B1B2(FC10,FC11), end;[/FONT][/FONT]
[FONT=Helvetica][FONT=arial]into method label BTIF code_regex \(BFC0, replaceall_matched begin (B1B2(FC00,FC01), end;
[/FONT][/FONT]


how do you know whether you need to put GBTI, BTIF, etc in that spot? Also, do you just place this series of text right under the other series of text where the 16-bit registers are split into two parts? or are you supposed to run multiple patches instead of just one?

Maybe I missed this part in the text that explains it?
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,717
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dell XPS 18 - Is it possible?

quick question...

In the post that I'm following to fix the battery status, you wrote the following:

Code:
[FONT=Helvetica][FONT=arial]into method label GBTI code_regex \(BFC1, replaceall_matched begin (B1B2(FC10,FC11), end;[/FONT][/FONT]
[FONT=Helvetica][FONT=arial]into method label BTIF code_regex \(BFC0, replaceall_matched begin (B1B2(FC00,FC01), end;
[/FONT][/FONT]


how do you know whether you need to put GBTI, BTIF, etc in that spot?


It depends on where the code is that you wish to change. Those are method names and the code could be in any method. So, after writing/applying the patch that changes the names, you will compile to view the errors. Because you have changed the names, the old names will not exist and any code that references them will be in error. So, you look at the code that causes errors, examine what method they are in, then write patches that change the code. This is what I mean by patches are 'scoped' regex search/replace. The scope is determined by the 'into method label method_name' part; it tells the search/replace engine "where" to look. The code_regex part tells the search/replace "what" to look for, and the replaceall_matched begin...end part tells the regex engine what to replace it with.

Also, do you just place this series of text right under the other series of text where the 16-bit registers are split into two parts? or are you supposed to run multiple patches instead of just one?
Yes... you eventually end up with multiple patches in one file that accomplishes the goal. See the other patches in the repo, for example.
 
Joined
Dec 29, 2012
Messages
354
Motherboard
Dell XPS 18
CPU
Intel Core i3-3227U CPU @ 1.90GHz
Graphics
Intel HD Graphics 4000
Mac
Classic Mac
Mobile Phone
Dell XPS 18 - Is it possible?

ok. Below I"ve written my first patch:

Code:
[FONT=Helvetica]#16-bit Registers
into device label H_EC code_regex B0VL,\s+16, replace_matched begin 0VL0,8,0VL1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0CC,\s+16, replace_matched begin 0CC1,8,0CC2,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0RC,\s+16, replace_matched begin 0RC0,8,0RC1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BFCP,\s+16, replace_matched begin FCP0,8,FPC1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0ST,\s+16, replace_matched begin 0ST0,8,0ST1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BDCP,\s+16, replace_matched begin DCP0,8,DCP1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BDVL,\s+16, replace_matched begin DVL0,8,DVL1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0MD,\s+16, replace_matched begin 0MD0,8,0MD1,8, end;
[/FONT]
I'm unsure of how to make the patch work on my DSDT file. I've been able to make the patches from your github site work, as I did the ones for the Intel HD4000 graphics. I just don't know how to make the custom one work. Any guidance/Suggestions on that?
 
Joined
Dec 29, 2012
Messages
354
Motherboard
Dell XPS 18
CPU
Intel Core i3-3227U CPU @ 1.90GHz
Graphics
Intel HD Graphics 4000
Mac
Classic Mac
Mobile Phone
Dell XPS 18 - Is it possible?

Maybe if I open my eyes and realize that your device name is different than mine, it might actually work.

Updated patch:

Code:
[FONT=Helvetica]#16-bit registers[/FONT]
[FONT=Helvetica]into device label EC0 code_regex B0VL,\s+16, replace_matched begin 0VL0,8,0VL1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex B0CC,\s+16, replace_matched begin 0CC1,8,0CC2,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex B0RC,\s+16, replace_matched begin 0RC0,8,0RC1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex BFCP,\s+16, replace_matched begin FCP0,8,FPC1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex B0ST,\s+16, replace_matched begin 0ST0,8,0ST1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex BDCP,\s+16, replace_matched begin DCP0,8,DCP1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex BDVL,\s+16, replace_matched begin DVL0,8,DVL1,8, end;[/FONT]
[FONT=Helvetica]into device label EC0 code_regex B0MD,\s+16, replace_matched begin 0MD0,8,0MD1,8, end;

Once I apply that patch, I get the following red flags after clicking "Compile"

LINE CODE MESSAGE
8612 4064 Object does not exist (\_SB.PCI0.LPCB.EC0.MPSL)
8613 4064 Object does not exist (\_SB.PCI0.LPCB.EC0.MPSL)
8614 4064 Object does not exist (\_SB.PCI0.LPCB.EC0.CPSL)
8615 4064 Object does not exist (\_SB.PCI0.LPCB.EC0.TCRT)
8621 4064 Object does not exist (\_SB.PCI0.LPCB.EC0.TCRT)

[/FONT]
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,717
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dell XPS 18 - Is it possible?

ok. Below I"ve written my first patch:

Code:
[FONT=Helvetica]#16-bit Registers
into device label H_EC code_regex B0VL,\s+16, replace_matched begin 0VL0,8,0VL1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0CC,\s+16, replace_matched begin 0CC1,8,0CC2,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0RC,\s+16, replace_matched begin 0RC0,8,0RC1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BFCP,\s+16, replace_matched begin FCP0,8,FPC1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0ST,\s+16, replace_matched begin 0ST0,8,0ST1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BDCP,\s+16, replace_matched begin DCP0,8,DCP1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex BDVL,\s+16, replace_matched begin DVL0,8,DVL1,8, end;[/FONT]
[FONT=Helvetica]into device label H_EC code_regex B0MD,\s+16, replace_matched begin 0MD0,8,0MD1,8, end;
[/FONT]
I'm unsure of how to make the patch work on my DSDT file. I've been able to make the patches from your github site work, as I did the ones for the Intel HD4000 graphics. I just don't know how to make the custom one work. Any guidance/Suggestions on that?
Well, now is the time to start testing your patches... Because you'll learn more that way... So, if you copy/paste this text into the MaciASL patch window against your DSDT, you will notice that is says "8 Patches, 0 Changes, 0 Rejects". So, your patches are syntactically correct, but they don't match anything. If they did have matches, MaciASL would have shown you a preview of changes (and said something other than "0 Changes").

Let's just take the B0VL example. The B0VL identifier is a field inside of an EC region called ECMM, which is inside a device named EC0 (you look to the left in the tree to see what device you're in).

You wrote:
Code:
into device label H_EC code_regex B0VL,\s+16, replace_matched begin 0VL0,8,0VL1,8, end;
But your DSDT's EC is named EC0, not H_EC. If we try this instead:
Code:
into device label EC0 code_regex B0VL,\s+16, replace_matched begin 0VL0,8,0VL1,8, end;
It will actually indicate changes will be made. But now another problem... you're renaming them to 0VL0, and 0VL1. Identifiers must start with an alpha (not numeric) character, so you should use 'O' not '0'.

Code:
into device label EC0 code_regex B0VL,\s+16, replace_matched begin OVL0,8,OVL1,8, end;
Yes... this is detail oriented work.

I would probably shuffle the name around a bit differently. B0VL would be VL00,VL01. But it doesn't matter the names you choose just as long as they are different from anything else used and different from the original with some indication of byte1/byte2.

If you apply that one patch, then compile, you'll get only a single error from a line of code inside BVOT. I'll let you work out how to write a patch for that...
 
Joined
Dec 29, 2012
Messages
354
Motherboard
Dell XPS 18
CPU
Intel Core i3-3227U CPU @ 1.90GHz
Graphics
Intel HD Graphics 4000
Mac
Classic Mac
Mobile Phone
Dell XPS 18 - Is it possible?

So I figured out that I needed to change the device name (because i'm blind and I read to fast sometimes... I'm a girl, you know how we are... :cool:) before your last post. I fixed it and ran the patch... only then did I see that in that last post you said the integers need to start with an alpha, not a number.... oops! So I guess I'll be searching through all of the DSDT for the ones I started with a number (this may take a while) and change them around. However, I'll just go ahead and update the change log that i'm keeping in a txt file.

Would it be easier to delete the DSDT file and start over fresh? I didn't use that many patches... Something told me I should have made a copy before starting this part.... :crazy:

I'll await a response before I let my itchy trigger finger do any more damage...
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,717
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dell XPS 18 - Is it possible?

So I figured out that I needed to change the device name (because i'm blind and I read to fast sometimes... I'm a girl, you know how we are... :cool:) before your last post. I fixed it and ran the patch... only then did I see that in that last post you said the integers need to start with an alpha, not a number.... oops! So I guess I'll be searching through all of the DSDT for the ones I started with a number (this may take a while) and change them around. However, I'll just go ahead and update the change log that i'm keeping in a txt file.

Would it be easier to delete the DSDT file and start over fresh? I didn't use that many patches... Something told me I should have made a copy before starting this part.... :crazy:
Yes, always keep the original DSDT around so you can restore to it when you make a "wrong turn."

What I tend to do is open the DSDT with MaciASL. Then I have TextEdit open for my "in progress" patches. I write them in TextEdit first, then I paste into the MaciASL patch window, examine the changes, and Apply to test. If it doesn't work out, I make corrections to the patch(es) in TextEdit, close MaciASL without saving, and re-open to retry. This is why I use my own version of MaciASL that has auto-save turned off!

Eventually you come to a point where the patches are complete and you can open the DSDT, copy/paste all the patches from TextEdit, and successfully compile. At that point you're ready to test the result by saving the DSDT to /Extra/dsdt.aml.
 
Joined
Dec 29, 2012
Messages
354
Motherboard
Dell XPS 18
CPU
Intel Core i3-3227U CPU @ 1.90GHz
Graphics
Intel HD Graphics 4000
Mac
Classic Mac
Mobile Phone
Dell XPS 18 - Is it possible?

This is why I use my own version of MaciASL that has auto-save turned off!
This is a day of LUCK for me... I went to close MaciASL, and it said it couldn't autosave due to there being errors in the compile window.... SCORE! I Reopened to find that none of the changes were kept. Thank goodness... going to go make a copy of the DSDT.aml file now...:shh: We can just pretend this never happened...
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,717
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dell XPS 18 - Is it possible?

This is a day of LUCK for me... I went to close MaciASL, and it said it couldn't autosave due to there being errors in the compile window.... SCORE! I Reopened to find that none of the changes were kept. Thank goodness... going to go make a copy of the DSDT.aml file now...:shh: We can just pretend this never happened...
You could also grab my version of MaciASL. Eventually, you will come across a situation where there aren't compile errors and you save unintentionally.
 
Top