ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
August 2021
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
16 participants
93 discussions
Start a n
N
ew thread
[reactos] 01/01: [IMM32] Rewrite ImmIsUIMessageA/W (#3907)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=77911014f3d55114d9a5c…
commit 77911014f3d55114d9a5c74893ded0b02154ac1a Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Mon Aug 16 15:33:51 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Mon Aug 16 15:33:51 2021 +0900 [IMM32] Rewrite ImmIsUIMessageA/W (#3907) - Rewrite ImmIsUIMessageA and ImmIsUIMessageW functions. - Modify HIMC and HIMCC handle types for strictness. Add typecasts. - Add WM_IME_SYSTEM macro. - Modify imm32.spec. CORE-11700 --- dll/win32/imm32/imm.c | 73 +++++++++++++++-------------- dll/win32/imm32/imm32.spec | 4 +- modules/rostests/apitests/imm32/clientimc.c | 6 +-- modules/rostests/winetests/imm32/imm32.c | 8 ++++ sdk/include/psdk/imm.h | 7 ++- win32ss/include/ntuser.h | 5 +- 6 files changed, 57 insertions(+), 46 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index d1fa849150e..7b0b415f74f 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -784,7 +784,7 @@ static void ImmInternalSendIMEMessage(InputContextData *data, UINT msg, WPARAM w static InputContextData* get_imc_data(HIMC hIMC) { - InputContextData *data = hIMC; + InputContextData *data = (InputContextData *)hIMC; if (hIMC == NULL) return NULL; @@ -861,7 +861,7 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC) if (old) { - InputContextData *old_data = old; + InputContextData *old_data = (InputContextData *)old; if (old_data->IMC.hWnd == hWnd) old_data->IMC.hWnd = NULL; } @@ -2546,7 +2546,7 @@ HIMC WINAPI ImmGetContext(HWND hWnd) if (rc) { - InputContextData *data = rc; + InputContextData *data = (InputContextData *)rc; data->IMC.hWnd = hWnd; } @@ -3340,26 +3340,38 @@ BOOL WINAPI ImmIsIME(HKL hKL) return !!ImmGetImeInfoEx(&info, ImeInfoExImeWindow, &hKL); } +static BOOL APIENTRY +ImmIsUIMessageAW(HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam, BOOL bAnsi) +{ + switch (msg) + { + case WM_IME_STARTCOMPOSITION: case WM_IME_ENDCOMPOSITION: + case WM_IME_COMPOSITION: case WM_IME_SETCONTEXT: case WM_IME_NOTIFY: + case WM_IME_COMPOSITIONFULL: case WM_IME_SELECT: case WM_IME_SYSTEM: + break; + default: + return FALSE; + } + + if (!hWndIME) + return TRUE; + + if (bAnsi) + SendMessageA(hWndIME, msg, wParam, lParam); + else + SendMessageW(hWndIME, msg, wParam, lParam); + + return TRUE; +} + /*********************************************************************** * ImmIsUIMessageA (IMM32.@) */ BOOL WINAPI ImmIsUIMessageA( HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam) { - TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam); - if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) || - (msg == WM_IME_SETCONTEXT) || - (msg == WM_IME_NOTIFY) || - (msg == WM_IME_COMPOSITIONFULL) || - (msg == WM_IME_SELECT) || - (msg == 0x287 /* FIXME: WM_IME_SYSTEM */)) - { - if (hWndIME) - SendMessageA(hWndIME, msg, wParam, lParam); - - return TRUE; - } - return FALSE; + TRACE("(%p, 0x%X, %p, %p)\n", hWndIME, msg, wParam, lParam); + return ImmIsUIMessageAW(hWndIME, msg, wParam, lParam, TRUE); } /*********************************************************************** @@ -3368,20 +3380,8 @@ BOOL WINAPI ImmIsUIMessageA( BOOL WINAPI ImmIsUIMessageW( HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam) { - TRACE("(%p, %x, %ld, %ld)\n", hWndIME, msg, wParam, lParam); - if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) || - (msg == WM_IME_SETCONTEXT) || - (msg == WM_IME_NOTIFY) || - (msg == WM_IME_COMPOSITIONFULL) || - (msg == WM_IME_SELECT) || - (msg == 0x287 /* FIXME: WM_IME_SYSTEM */)) - { - if (hWndIME) - SendMessageW(hWndIME, msg, wParam, lParam); - - return TRUE; - } - return FALSE; + TRACE("(%p, 0x%X, %p, %p)\n", hWndIME, msg, wParam, lParam); + return ImmIsUIMessageAW(hWndIME, msg, wParam, lParam, FALSE); } /*********************************************************************** @@ -4543,7 +4543,7 @@ BOOL WINAPI ImmTranslateMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lKeyD TRACE("%p %x %x %x\n",hwnd, msg, (UINT)wParam, (UINT)lKeyData); if (imc) - data = imc; + data = (InputContextData *)imc; else return FALSE; @@ -4602,7 +4602,7 @@ BOOL WINAPI ImmProcessKey(HWND hwnd, HKL hKL, UINT vKey, LPARAM lKeyData, DWORD TRACE("%p %p %x %x %x\n",hwnd, hKL, vKey, (UINT)lKeyData, unknown); if (imc) - data = imc; + data = (InputContextData *)imc; else return FALSE; @@ -4800,7 +4800,7 @@ BOOL WINAPI User32InitializeImmEntryTable(DWORD); BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { HKL hKL; - HWND hWnd; + HIMC hIMC; PTEB pTeb; TRACE("(%p, 0x%X, %p)\n", hinstDLL, fdwReason, lpReserved); @@ -4833,8 +4833,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) return TRUE; hKL = GetKeyboardLayout(0); - hWnd = (HWND)Imm32GetThreadState(THREADSTATE_CAPTUREWINDOW); - Imm32CleanupContext(hWnd, hKL, TRUE); + // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken. + hIMC = (HIMC)Imm32GetThreadState(4); + Imm32CleanupContext(hIMC, hKL, TRUE); break; case DLL_PROCESS_DETACH: diff --git a/dll/win32/imm32/imm32.spec b/dll/win32/imm32/imm32.spec index e196f08627a..bca6da02f8a 100644 --- a/dll/win32/imm32/imm32.spec +++ b/dll/win32/imm32/imm32.spec @@ -66,8 +66,8 @@ @ stdcall ImmInstallIMEA(str str) @ stdcall ImmInstallIMEW(wstr wstr) @ stdcall ImmIsIME(long) -@ stdcall ImmIsUIMessageA(long long long long) -@ stdcall ImmIsUIMessageW(long long long long) +@ stdcall ImmIsUIMessageA(ptr long ptr ptr) +@ stdcall ImmIsUIMessageW(ptr long ptr ptr) @ stdcall ImmLoadIME(ptr) @ stdcall ImmLoadLayout(ptr ptr) @ stdcall ImmLockClientImc(ptr) diff --git a/modules/rostests/apitests/imm32/clientimc.c b/modules/rostests/apitests/imm32/clientimc.c index 99ed8423537..0f43024efd0 100644 --- a/modules/rostests/apitests/imm32/clientimc.c +++ b/modules/rostests/apitests/imm32/clientimc.c @@ -28,11 +28,11 @@ START_TEST(clientimc) pClientImc->cLockObj = 2; pClientImc->dwFlags = 0x40; RtlInitializeCriticalSection(&pClientImc->cs); - ok_long(ImmGetIMCCSize(pClientImc->hImc), 4); + ok_long(ImmGetIMCCSize((HIMCC)pClientImc->hImc), 4); ImmUnlockClientImc(pClientImc); ok_long(pClientImc->cLockObj, 1); - ok_long(ImmGetIMCCSize(pClientImc->hImc), 4); + ok_long(ImmGetIMCCSize((HIMCC)pClientImc->hImc), 4); dwCode = 0; _SEH2_TRY @@ -47,7 +47,7 @@ START_TEST(clientimc) ok_long(dwCode, STATUS_ACCESS_VIOLATION); ok_long(pClientImc->cLockObj, 0); - ok_long(ImmGetIMCCSize(pClientImc->hImc), 0); + ok_long(ImmGetIMCCSize((HIMCC)pClientImc->hImc), 0); HeapFree(GetProcessHeap(), 0, pClientImc); } diff --git a/modules/rostests/winetests/imm32/imm32.c b/modules/rostests/winetests/imm32/imm32.c index 040a43fc058..fef5b0dbb0d 100644 --- a/modules/rostests/winetests/imm32/imm32.c +++ b/modules/rostests/winetests/imm32/imm32.c @@ -606,9 +606,17 @@ static void test_ImmIME(void) if (imc) { BOOL rc; +#ifdef __REACTOS__ + rc = ImmConfigureIMEA((HKL)imc, NULL, IME_CONFIG_REGISTERWORD, NULL); +#else rc = ImmConfigureIMEA(imc, NULL, IME_CONFIG_REGISTERWORD, NULL); +#endif ok (rc == 0, "ImmConfigureIMEA did not fail\n"); +#ifdef __REACTOS__ + rc = ImmConfigureIMEW((HKL)imc, NULL, IME_CONFIG_REGISTERWORD, NULL); +#else rc = ImmConfigureIMEW(imc, NULL, IME_CONFIG_REGISTERWORD, NULL); +#endif ok (rc == 0, "ImmConfigureIMEW did not fail\n"); } ImmReleaseContext(hwnd,imc); diff --git a/sdk/include/psdk/imm.h b/sdk/include/psdk/imm.h index 7b0888b033e..7fc769ee1eb 100644 --- a/sdk/include/psdk/imm.h +++ b/sdk/include/psdk/imm.h @@ -25,10 +25,13 @@ extern "C" { #endif -typedef HANDLE HIMC; -typedef HANDLE HIMCC; #ifdef __REACTOS__ +DECLARE_HANDLE(HIMC); +DECLARE_HANDLE(HIMCC); typedef HKL *LPHKL; +#else +typedef HANDLE HIMC; +typedef HANDLE HIMCC; #endif typedef struct tagREGISTERWORDA { diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h index 26e89fb396a..3147acfac6f 100644 --- a/win32ss/include/ntuser.h +++ b/win32ss/include/ntuser.h @@ -6,9 +6,8 @@ struct _THREADINFO; struct _DESKTOP; struct _WND; struct tagPOPUPMENU; -#ifndef HIMC -typedef HANDLE HIMC; -#endif + +#define WM_IME_SYSTEM 0x287 #define FIRST_USER_HANDLE 0x0020 /* first possible value for low word of user handle */ #define LAST_USER_HANDLE 0xffef /* last possible value for low word of user handle */
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Rewrite ImmEnumRegisterWordA/W (#3906)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cc097ec485fd831385c34…
commit cc097ec485fd831385c347543da264e6e73278a8 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Mon Aug 16 15:31:39 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Mon Aug 16 15:31:39 2021 +0900 [IMM32] Rewrite ImmEnumRegisterWordA/W (#3906) - Rewrite ImmEnumRegisterWordA and ImmEnumRegisterWordW functions. - Modify win32ss/include/imetable.h. CORE-11700 --- dll/win32/imm32/imm.c | 210 ++++++++++++++++++++++++++++++++++++--------- win32ss/include/imetable.h | 2 +- 2 files changed, 170 insertions(+), 42 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index e65b686a631..d1fa849150e 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -1132,6 +1132,87 @@ BOOL WINAPI ImmDisableIME(DWORD dwThreadId) return NtUserDisableThreadIme(dwThreadId); } +/* + * These functions absorb the difference between Ansi and Wide. + */ +typedef struct ENUM_WORD_A2W +{ + REGISTERWORDENUMPROCW lpfnEnumProc; + LPVOID lpData; + UINT ret; +} ENUM_WORD_A2W, *LPENUM_WORD_A2W; + +typedef struct ENUM_WORD_W2A +{ + REGISTERWORDENUMPROCA lpfnEnumProc; + LPVOID lpData; + UINT ret; +} ENUM_WORD_W2A, *LPENUM_WORD_W2A; + +static INT CALLBACK +Imm32EnumWordProcA2W(LPCSTR pszReadingA, DWORD dwStyle, LPCSTR pszRegisterA, LPVOID lpData) +{ + INT ret = 0; + LPENUM_WORD_A2W lpEnumData = lpData; + LPWSTR pszReadingW = NULL, pszRegisterW = NULL; + + if (pszReadingA) + { + pszReadingW = Imm32WideFromAnsi(pszReadingA); + if (pszReadingW == NULL) + goto Quit; + } + + if (pszRegisterA) + { + pszRegisterW = Imm32WideFromAnsi(pszRegisterA); + if (pszRegisterW == NULL) + goto Quit; + } + + ret = lpEnumData->lpfnEnumProc(pszReadingW, dwStyle, pszRegisterW, lpEnumData->lpData); + lpEnumData->ret = ret; + +Quit: + if (pszReadingW) + HeapFree(g_hImm32Heap, 0, pszReadingW); + if (pszRegisterW) + HeapFree(g_hImm32Heap, 0, pszRegisterW); + return ret; +} + +static INT CALLBACK +Imm32EnumWordProcW2A(LPCWSTR pszReadingW, DWORD dwStyle, LPCWSTR pszRegisterW, LPVOID lpData) +{ + INT ret = 0; + LPENUM_WORD_W2A lpEnumData = lpData; + LPSTR pszReadingA = NULL, pszRegisterA = NULL; + + if (pszReadingW) + { + pszReadingA = Imm32AnsiFromWide(pszReadingW); + if (pszReadingW == NULL) + goto Quit; + } + + if (pszRegisterW) + { + pszRegisterA = Imm32AnsiFromWide(pszRegisterW); + if (pszRegisterA == NULL) + goto Quit; + } + + ret = lpEnumData->lpfnEnumProc(pszReadingA, dwStyle, pszRegisterA, lpEnumData->lpData); + lpEnumData->ret = ret; + +Quit: + if (pszReadingA) + HeapFree(g_hImm32Heap, 0, pszReadingA); + if (pszRegisterA) + HeapFree(g_hImm32Heap, 0, pszRegisterA); + return ret; +} + /*********************************************************************** * ImmEnumRegisterWordA (IMM32.@) */ @@ -1140,31 +1221,54 @@ UINT WINAPI ImmEnumRegisterWordA( LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister, LPVOID lpData) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc, - debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister), lpData); - if (immHkl->hIME && immHkl->pImeEnumRegisterWord) + UINT ret = 0; + LPWSTR pszReadingW = NULL, pszRegisterW = NULL; + ENUM_WORD_W2A EnumDataW2A; + PIMEDPI pImeDpi; + + TRACE("(%p, %p, %s, 0x%lX, %s, %p)", hKL, lpfnEnumProc, debugstr_a(lpszReading), + dwStyle, debugstr_a(lpszRegister), lpData); + + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) + return 0; + + if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) { - if (!is_kbd_ime_unicode(immHkl)) - return immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc, - (LPCWSTR)lpszReading, dwStyle, (LPCWSTR)lpszRegister, lpData); - else - { - LPWSTR lpszwReading = strdupAtoW(lpszReading); - LPWSTR lpszwRegister = strdupAtoW(lpszRegister); - BOOL rc; + ret = pImeDpi->ImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle, + lpszRegister, lpData); + ImmUnlockImeDpi(pImeDpi); + return ret; + } - rc = immHkl->pImeEnumRegisterWord((REGISTERWORDENUMPROCW)lpfnEnumProc, - lpszwReading, dwStyle, lpszwRegister, - lpData); + if (lpszReading) + { + pszReadingW = Imm32WideFromAnsi(lpszReading); + if (pszReadingW == NULL) + goto Quit; + } - HeapFree(GetProcessHeap(),0,lpszwReading); - HeapFree(GetProcessHeap(),0,lpszwRegister); - return rc; - } + if (lpszRegister) + { + pszRegisterW = Imm32WideFromAnsi(lpszRegister); + if (pszRegisterW == NULL) + goto Quit; } - else - return 0; + + EnumDataW2A.lpfnEnumProc = lpfnEnumProc; + EnumDataW2A.lpData = lpData; + EnumDataW2A.ret = 0; + pImeDpi->ImeEnumRegisterWord(Imm32EnumWordProcW2A, pszReadingW, dwStyle, + pszRegisterW, &EnumDataW2A); + ret = EnumDataW2A.ret; + +Quit: + if (pszReadingW) + HeapFree(g_hImm32Heap, 0, pszReadingW); + if (pszRegisterW) + HeapFree(g_hImm32Heap, 0, pszRegisterW); + ImmUnlockImeDpi(pImeDpi); + return ret; } /*********************************************************************** @@ -1175,30 +1279,54 @@ UINT WINAPI ImmEnumRegisterWordW( LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister, LPVOID lpData) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %p, %s, %d, %s, %p):\n", hKL, lpfnEnumProc, - debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister), lpData); - if (immHkl->hIME && immHkl->pImeEnumRegisterWord) + UINT ret = 0; + LPSTR pszReadingA = NULL, pszRegisterA = NULL; + ENUM_WORD_A2W EnumDataA2W; + PIMEDPI pImeDpi; + + TRACE("(%p, %p, %s, 0x%lX, %s, %p)", hKL, lpfnEnumProc, debugstr_w(lpszReading), + dwStyle, debugstr_w(lpszRegister), lpData); + + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) + return 0; + + if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) { - if (is_kbd_ime_unicode(immHkl)) - return immHkl->pImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle, - lpszRegister, lpData); - else - { - LPSTR lpszaReading = strdupWtoA(lpszReading); - LPSTR lpszaRegister = strdupWtoA(lpszRegister); - BOOL rc; + ret = pImeDpi->ImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle, + lpszRegister, lpData); + ImmUnlockImeDpi(pImeDpi); + return ret; + } - rc = immHkl->pImeEnumRegisterWord(lpfnEnumProc, (LPCWSTR)lpszaReading, - dwStyle, (LPCWSTR)lpszaRegister, lpData); + if (lpszReading) + { + pszReadingA = Imm32AnsiFromWide(lpszReading); + if (pszReadingA == NULL) + goto Quit; + } - HeapFree(GetProcessHeap(),0,lpszaReading); - HeapFree(GetProcessHeap(),0,lpszaRegister); - return rc; - } + if (lpszRegister) + { + pszRegisterA = Imm32AnsiFromWide(lpszRegister); + if (pszRegisterA == NULL) + goto Quit; } - else - return 0; + + EnumDataA2W.lpfnEnumProc = lpfnEnumProc; + EnumDataA2W.lpData = lpData; + EnumDataA2W.ret = 0; + pImeDpi->ImeEnumRegisterWord(Imm32EnumWordProcA2W, pszReadingA, dwStyle, + pszRegisterA, &EnumDataA2W); + ret = EnumDataA2W.ret; + +Quit: + if (pszReadingA) + HeapFree(g_hImm32Heap, 0, pszReadingA); + if (pszRegisterA) + HeapFree(g_hImm32Heap, 0, pszRegisterA); + ImmUnlockImeDpi(pImeDpi); + return ret; } static inline BOOL EscapeRequiresWA(UINT uEscape) diff --git a/win32ss/include/imetable.h b/win32ss/include/imetable.h index 2385e812e3a..1b47380e954 100644 --- a/win32ss/include/imetable.h +++ b/win32ss/include/imetable.h @@ -4,7 +4,7 @@ DEFINE_IME_ENTRY(DWORD, ImeConversionList, (HIMC hIMC, LPCVOID lpSrc, LPCANDIDAT DEFINE_IME_ENTRY(BOOL, ImeRegisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString), FALSE) DEFINE_IME_ENTRY(BOOL, ImeUnregisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString), FALSE) DEFINE_IME_ENTRY(UINT, ImeGetRegisterWordStyle, (UINT nItem, LPVOID lpStyleBuf), FALSE) -DEFINE_IME_ENTRY(UINT, ImeEnumRegisterWord, (HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc, LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString, LPVOID lpData), FALSE) +DEFINE_IME_ENTRY(UINT, ImeEnumRegisterWord, (LPVOID lpfnEnumProc, LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString, LPVOID lpData), FALSE) DEFINE_IME_ENTRY(BOOL, ImeConfigure, (HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData), FALSE) DEFINE_IME_ENTRY(BOOL, ImeDestroy, (UINT uReserved), FALSE) DEFINE_IME_ENTRY(LRESULT, ImeEscape, (HIMC hIMC, UINT uEscape, LPVOID lpData), FALSE)
3 years, 4 months
1
0
0
0
[reactos] 01/01: [RTL/x64] Fix a typo RtplUnwindInternal -> RtlpUnwindInternal (#3912)
by Kento Oki
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3ba1d82c414712a191df9…
commit 3ba1d82c414712a191df9faf1df594125e082e3b Author: Kento Oki <hrn832(a)protonmail.com> AuthorDate: Mon Aug 16 10:23:02 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Mon Aug 16 04:23:02 2021 +0300 [RTL/x64] Fix a typo RtplUnwindInternal -> RtlpUnwindInternal (#3912) --- sdk/lib/rtl/amd64/except.c | 4 ++-- sdk/lib/rtl/amd64/unwind.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/lib/rtl/amd64/except.c b/sdk/lib/rtl/amd64/except.c index aebd525774b..1dc9b59c0cd 100644 --- a/sdk/lib/rtl/amd64/except.c +++ b/sdk/lib/rtl/amd64/except.c @@ -70,7 +70,7 @@ RtlpGetExceptionAddress(VOID) BOOLEAN NTAPI -RtplUnwindInternal( +RtlpUnwindInternal( _In_opt_ PVOID TargetFrame, _In_opt_ PVOID TargetIp, _In_ PEXCEPTION_RECORD ExceptionRecord, @@ -101,7 +101,7 @@ RtlDispatchException( } /* Call the internal unwind routine */ - Handled = RtplUnwindInternal(NULL, // TargetFrame + Handled = RtlpUnwindInternal(NULL, // TargetFrame NULL, // TargetIp ExceptionRecord, 0, // ReturnValue diff --git a/sdk/lib/rtl/amd64/unwind.c b/sdk/lib/rtl/amd64/unwind.c index af00aeec3bd..4fe42801281 100644 --- a/sdk/lib/rtl/amd64/unwind.c +++ b/sdk/lib/rtl/amd64/unwind.c @@ -683,7 +683,7 @@ Exit: */ BOOLEAN NTAPI -RtplUnwindInternal( +RtlpUnwindInternal( _In_opt_ PVOID TargetFrame, _In_opt_ PVOID TargetIp, _In_ PEXCEPTION_RECORD ExceptionRecord, @@ -907,7 +907,7 @@ RtlUnwindEx( } /* Call the internal function */ - RtplUnwindInternal(TargetFrame, + RtlpUnwindInternal(TargetFrame, TargetIp, ExceptionRecord, ReturnValue,
3 years, 4 months
1
0
0
0
[reactos] 01/01: [FREELDR][NTOS][HALPPC][SDK] Remove PowerPC code
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6ef6fabfc5271b9fb89cd…
commit 6ef6fabfc5271b9fb89cd9bdc2038588d55b3ea4 Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Sun Aug 8 01:50:20 2021 +0300 Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org> CommitDate: Sun Aug 15 15:35:51 2021 +0300 [FREELDR][NTOS][HALPPC][SDK] Remove PowerPC code Remove PowerPC-related code from the kernel, HAL, SDK and Freeloader. --- boot/freeldr/freeldr/arch/powerpc/boot.s | 111 -- boot/freeldr/freeldr/arch/powerpc/compat.h | 105 - boot/freeldr/freeldr/arch/powerpc/loader.c | 348 ---- boot/freeldr/freeldr/arch/powerpc/mach.c | 555 ------ boot/freeldr/freeldr/arch/powerpc/mboot.c | 852 --------- boot/freeldr/freeldr/arch/powerpc/mmu.c | 399 ---- boot/freeldr/freeldr/arch/powerpc/ofw_method.c | 26 - boot/freeldr/freeldr/arch/powerpc/ofw_util.s | 48 - boot/freeldr/freeldr/arch/powerpc/prep.c | 148 -- boot/freeldr/freeldr/arch/powerpc/prep.h | 28 - boot/freeldr/freeldr/arch/powerpc/prep_ide.c | 106 - boot/freeldr/freeldr/arch/powerpc/prep_pci.c | 127 -- boot/freeldr/freeldr/arch/powerpc/prep_vga.c | 28 - .../freeldr/include/arch/powerpc/hardware.h | 37 - boot/freeldr/freeldr/include/of.h | 16 - hal/CMakeLists.txt | 2 - hal/halppc/generic/beep.c | 42 - hal/halppc/generic/bus.c | 356 ---- hal/halppc/generic/cmos.c | 291 --- hal/halppc/generic/display.c | 383 ---- hal/halppc/generic/dma.c | 2020 -------------------- hal/halppc/generic/drive.c | 74 - hal/halppc/generic/enum.c | 22 - hal/halppc/generic/fmutex.c | 100 - hal/halppc/generic/font.c | 277 --- hal/halppc/generic/halinit.c | 158 -- hal/halppc/generic/irql.c | 452 ----- hal/halppc/generic/isa.c | 74 - hal/halppc/generic/misc.c | 105 - hal/halppc/generic/pci.c | 778 -------- hal/halppc/generic/portio.c | 282 --- hal/halppc/generic/processor.c | 75 - hal/halppc/generic/profil.c | 61 - hal/halppc/generic/reboot.c | 40 - hal/halppc/generic/spinlock.c | 210 -- hal/halppc/generic/sysinfo.c | 40 - hal/halppc/generic/timer.c | 138 -- hal/halppc/include/apic.h | 208 -- hal/halppc/include/bus.h | 291 --- hal/halppc/include/hal.h | 49 - hal/halppc/include/haldma.h | 380 ---- hal/halppc/include/halirq.h | 29 - hal/halppc/include/halp.h | 126 -- hal/halppc/include/ioapic.h | 97 - hal/halppc/include/mps.h | 200 -- hal/halppc/up/halinit_up.c | 31 - hal/halppc/up/halup.rc | 5 - ntoskrnl/config/powerpc/cmhardwr.c | 851 --------- ntoskrnl/ex/powerpc/ioport.s | 171 -- ntoskrnl/include/internal/powerpc/intrin_i.h | 5 - ntoskrnl/include/internal/powerpc/ke.h | 132 -- ntoskrnl/ke/powerpc/cpu.c | 271 --- ntoskrnl/ke/powerpc/ctxhelp.S | 252 --- ntoskrnl/ke/powerpc/ctxswitch.c | 124 -- ntoskrnl/ke/powerpc/exp.c | 103 - ntoskrnl/ke/powerpc/kiinit.c | 356 ---- ntoskrnl/ke/powerpc/main_asm.S | 76 - ntoskrnl/ke/powerpc/ppc_irq.c | 805 -------- ntoskrnl/ke/powerpc/stubs.c | 222 --- ntoskrnl/ke/powerpc/systimer.c | 20 - ntoskrnl/ke/powerpc/thrdini.c | 222 --- ntoskrnl/mm/powerpc/page.c | 470 ----- ntoskrnl/mm/powerpc/pfault.c | 111 -- ntoskrnl/ntos.cmake | 16 - sdk/include/reactos/libs/ppcmmu/mmu.h | 277 --- sdk/include/reactos/libs/ppcmmu/mmuutil.h | 23 - sdk/lib/CMakeLists.txt | 1 - sdk/lib/crt/except/except.cmake | 2 - sdk/lib/crt/except/powerpc/chkstk_asm.s | 22 - sdk/lib/crt/except/powerpc/seh.s | 75 - sdk/lib/ppcmmu/CMakeLists.txt | 8 - sdk/lib/ppcmmu/devint.s | 222 --- sdk/lib/ppcmmu/dummy.c | 0 sdk/lib/ppcmmu/gdblib.c | 475 ----- sdk/lib/ppcmmu/ldscript | 8 - sdk/lib/ppcmmu/mmuobject.c | 766 -------- sdk/lib/ppcmmu/mmuobject.h | 14 - sdk/lib/ppcmmu/mmutest.c | 23 - sdk/lib/ppcmmu/mmuutil.c | 411 ---- sdk/lib/pseh/CMakeLists.txt | 2 - sdk/lib/pseh/powerpc/framebased.S | 69 - sdk/lib/rtl/CMakeLists.txt | 10 - sdk/lib/rtl/powerpc/debug.c | 41 - sdk/lib/rtl/powerpc/except.c | 54 - sdk/lib/rtl/powerpc/interlocked.c | 128 -- sdk/lib/rtl/powerpc/rtlmem.s | 101 - sdk/lib/rtl/powerpc/rtlswap.s | 41 - sdk/lib/rtl/powerpc/thread.c | 38 - 88 files changed, 17348 deletions(-) diff --git a/boot/freeldr/freeldr/arch/powerpc/boot.s b/boot/freeldr/freeldr/arch/powerpc/boot.s deleted file mode 100644 index cc67a408b69..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/boot.s +++ /dev/null @@ -1,111 +0,0 @@ - .section ".text" - .extern PpcInit - .globl _start - .globl call_ofw -_start: - sync - isync - - lis %r1,stackend@ha - addi %r1,%r1,stackend@l - - /* Store ofw call addr */ - mr %r21,%r5 - lis %r10,ofw_call_addr@ha - stw %r5,ofw_call_addr@l(%r10) - - bl zero_registers - - /* Zero CTR */ - mtcr %r31 - - lis %r3,PpcInit@ha - addi %r3,%r3,PpcInit@l - mtlr %r3 - - /* Check for ofw */ - lis %r3,ofw_call_addr@ha - lwz %r3,ofw_call_addr@l(%r3) - cmpw %r3,%r31 /* Zero? */ - mr %r3,%r31 - beq initfp - - lis %r3,call_ofw@ha - addi %r3,%r3,call_ofw@l - b bootme - -initfp: - /* Enabling FP at this point won't hurt, and the varargs scheme we're - * using now requires it. */ - mfmsr %r0 - ori %r0,%r0,8192 - mtmsr %r0 - -bootme: - blr - -zero_registers: - xor %r2,%r2,%r2 - mr %r0,%r2 - mr %r3,%r2 - - mr %r4,%r2 - mr %r5,%r2 - mr %r6,%r2 - mr %r7,%r2 - - mr %r8,%r2 - mr %r9,%r2 - mr %r10,%r2 - mr %r11,%r2 - - mr %r12,%r2 - mr %r13,%r2 - mr %r14,%r2 - mr %r15,%r2 - - mr %r12,%r2 - mr %r13,%r2 - mr %r14,%r2 - mr %r15,%r2 - - mr %r16,%r2 - mr %r17,%r2 - mr %r18,%r2 - mr %r19,%r2 - - mr %r20,%r2 - mr %r21,%r2 - mr %r22,%r2 - mr %r23,%r2 - - mr %r24,%r2 - mr %r25,%r2 - mr %r26,%r2 - mr %r27,%r2 - - mr %r28,%r2 - mr %r29,%r2 - mr %r30,%r2 - mr %r31,%r2 - - blr - -ofw_memory_size: - .long 0 - .long 0 - .long 0 - .long 0 - - .align 4 -stack: - .space 0x4000 -stackend: - .long 0,0,0,0 - - .globl _bss - .section ".bss2" -_bss: - .long 0 - - .align 4 diff --git a/boot/freeldr/freeldr/arch/powerpc/compat.h b/boot/freeldr/freeldr/arch/powerpc/compat.h deleted file mode 100644 index e62d16debc5..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/compat.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -#define __init -#define __initdata - -#define SPRN_MSSCR0 0x3f6 /* Memory Subsystem Control Register 0 */ -#define SPRN_MSSSR0 0x3f7 /* Memory Subsystem Status Register 1 */ -#define SPRN_LDSTCR 0x3f8 /* Load/Store control register */ -#define SPRN_LDSTDB 0x3f4 /* */ -#define SPRN_LR 0x008 /* Link Register */ -#ifndef SPRN_PIR -#define SPRN_PIR 0x3FF /* Processor Identification Register */ -#endif -#define SPRN_PTEHI 0x3D5 /* 981 7450 PTE HI word (S/W TLB load) */ -#define SPRN_PTELO 0x3D6 /* 982 7450 PTE LO word (S/W TLB load) */ -#define SPRN_PURR 0x135 /* Processor Utilization of Resources Reg */ -#define SPRN_PVR 0x11F /* Processor Version Register */ -#define SPRN_RPA 0x3D6 /* Required Physical Address Register */ -#define SPRN_SDA 0x3BF /* Sampled Data Address Register */ -#define SPRN_SDR1 0x019 /* MMU Hash Base Register */ -#define SPRN_ASR 0x118 /* Address Space Register */ -#define SPRN_SIA 0x3BB /* Sampled Instruction Address Register */ -#define SPRN_SPRG0 0x110 /* Special Purpose Register General 0 */ -#define SPRN_SPRG1 0x111 /* Special Purpose Register General 1 */ -#define SPRN_SPRG2 0x112 /* Special Purpose Register General 2 */ -#define SPRN_SPRG3 0x113 /* Special Purpose Register General 3 */ -#define SPRN_SPRG4 0x114 /* Special Purpose Register General 4 */ -#define SPRN_SPRG5 0x115 /* Special Purpose Register General 5 */ -#define SPRN_SPRG6 0x116 /* Special Purpose Register General 6 */ -#define SPRN_SPRG7 0x117 /* Special Purpose Register General 7 */ -#define SPRN_SRR0 0x01A /* Save/Restore Register 0 */ -#define SPRN_SRR1 0x01B /* Save/Restore Register 1 */ -#ifndef SPRN_SVR -#define SPRN_SVR 0x11E /* System Version Register */ -#endif -#define SPRN_THRM1 0x3FC /* Thermal Management Register 1 */ -/* these bits were defined in inverted endian sense originally, ugh, confusing */ - -/* Values for PP (assumes Ks=0, Kp=1) */ -#define PP_RWXX 0 /* Supervisor read/write, User none */ -#define PP_RWRX 1 /* Supervisor read/write, User read */ -#define PP_RWRW 2 /* Supervisor read/write, User read/write */ -#define PP_RXRX 3 /* Supervisor read, User read */ - -/* Block size masks */ -#define BL_128K 0x000 -#define BL_256K 0x001 -#define BL_512K 0x003 -#define BL_1M 0x007 -#define BL_2M 0x00F -#define BL_4M 0x01F -#define BL_8M 0x03F -#define BL_16M 0x07F -#define BL_32M 0x0FF -#define BL_64M 0x1FF -#define BL_128M 0x3FF -#define BL_256M 0x7FF - -/* BAT Access Protection */ -#define BPP_XX 0x00 /* No access */ -#define BPP_RX 0x01 /* Read only */ -#define BPP_RW 0x02 /* Read/write */ - -/* Definitions for 40x embedded chips. */ -#define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */ -#define _PAGE_FILE 0x001 /* when !present: nonlinear file mapping */ -#define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */ -#define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */ -#define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */ -#define _PAGE_USER 0x010 /* matches one of the zone permission bits */ -#define _PAGE_RW 0x040 /* software: Writes permitted */ -#define _PAGE_DIRTY 0x080 /* software: dirty page */ -#define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */ -#define _PAGE_HWEXEC 0x200 /* hardware: EX permission */ -#define _PAGE_ACCESSED 0x400 /* software: R: page referenced */ - -#define _PMD_PRESENT 0x400 /* PMD points to page of PTEs */ -#define _PMD_BAD 0x802 -#define _PMD_SIZE 0x0e0 /* size field, != 0 for large-page PMD entry */ -#define _PMD_SIZE_4M 0x0c0 -#define _PMD_SIZE_16M 0x0e0 -#define PMD_PAGE_SIZE(pmdval) (1024 << (((pmdval) & _PMD_SIZE) >> 4)) - -#define PVR_VER(pvr)(((pvr) >> 16) & 0xFFFF) /* Version field */ - -#define KERNELBASE 0x80000000 - -typedef unsigned char __u8; -typedef unsigned short __u16; -typedef unsigned int __u32; - -typedef struct _pci_reg_property { - struct { - int a_hi, a_mid, a_lo; - } addr; - int size_hi, size_lo; -} pci_reg_property; - -void btext_drawstring(const char *c); -void btext_drawhex(unsigned long v); - -void *ioremap(__u32 phys, __u32 size); -void iounmap(void *logical); - -__u32 GetPVR(void); diff --git a/boot/freeldr/freeldr/arch/powerpc/loader.c b/boot/freeldr/freeldr/arch/powerpc/loader.c deleted file mode 100644 index c9770641658..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/loader.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com> - * Copyright (C) 2005 Alex Ionescu <alex(a)relsoft.net> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#define _NTSYSTEM_ -#include <freeldr.h> - -#include <debug.h> - -#define DbgPrint printf - -extern PVOID KernelBase; -extern PVOID KernelMemory; - -PVOID -NTAPI -LdrPEGetExportByName(PVOID BaseAddress, - PUCHAR SymbolName, - USHORT Hint); - -/* FUNCTIONS *****************************************************************/ - -PLOADER_MODULE -NTAPI -LdrGetModuleObject(PCHAR ModuleName) -{ - ULONG i; - - for (i = 0; i < LoaderBlock.ModsCount; i++) - { - if (strstr(_strupr((PCHAR)reactos_modules[i].String), _strupr(ModuleName))) - { - return &reactos_modules[i]; - } - } - - return NULL; -} - -PVOID -NTAPI -LdrPEFixupForward(IN PCHAR ForwardName) -{ - CHAR NameBuffer[128]; - PCHAR p; - PLOADER_MODULE ModuleObject; - - strcpy(NameBuffer, ForwardName); - p = strchr(NameBuffer, '.'); - if (p == NULL) return NULL; - *p = 0; - - ModuleObject = LdrGetModuleObject(NameBuffer); - if (!ModuleObject) - { - DbgPrint("LdrPEFixupForward: failed to find module %s\n", NameBuffer); - return NULL; - } - - return LdrPEGetExportByName((PVOID)ModuleObject->ModStart, (PUCHAR)(p + 1), 0xffff); -} - -PVOID -NTAPI -LdrPEGetExportByName(PVOID BaseAddress, - PUCHAR SymbolName, - USHORT Hint) -{ - PIMAGE_EXPORT_DIRECTORY ExportDir; - PULONG * ExFunctions; - PULONG * ExNames; - USHORT * ExOrdinals; - PVOID ExName; - ULONG Ordinal; - PVOID Function; - LONG minn, maxn, mid, res; - ULONG ExportDirSize; - - /* HAL and NTOS use a virtual address, switch it to physical mode */ - if ((ULONG_PTR)BaseAddress & 0x80000000) - { - BaseAddress = (PVOID)((ULONG_PTR)BaseAddress - KSEG0_BASE + (ULONG)KernelMemory); - } - - ExportDir = (PIMAGE_EXPORT_DIRECTORY) - RtlImageDirectoryEntryToData(BaseAddress, - TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, - &ExportDirSize); - if (!ExportDir) - { - DbgPrint("LdrPEGetExportByName(): no export directory!\n"); - return NULL; - } - - /* The symbol names may be missing entirely */ - if (!ExportDir->AddressOfNames) - { - DbgPrint("LdrPEGetExportByName(): symbol names missing entirely\n"); - return NULL; - } - - /* - * Get header pointers - */ - ExNames = (PULONG *)RVA(BaseAddress, ExportDir->AddressOfNames); - ExOrdinals = (USHORT *)RVA(BaseAddress, ExportDir->AddressOfNameOrdinals); - ExFunctions = (PULONG *)RVA(BaseAddress, ExportDir->AddressOfFunctions); - - /* - * Check the hint first - */ - if (Hint < ExportDir->NumberOfNames) - { - ExName = RVA(BaseAddress, ExNames[Hint]); - if (strcmp(ExName, (PCHAR)SymbolName) == 0) - { - Ordinal = ExOrdinals[Hint]; - Function = RVA(BaseAddress, ExFunctions[Ordinal]); - if ((ULONG_PTR)Function >= (ULONG_PTR)ExportDir && - (ULONG_PTR)Function < (ULONG_PTR)ExportDir + ExportDirSize) - { - Function = LdrPEFixupForward((PCHAR)Function); - if (Function == NULL) - { - DbgPrint("LdrPEGetExportByName(): failed to find %s\n", Function); - } - return Function; - } - - if (Function != NULL) return Function; - } - } - - /* - * Binary search - */ - minn = 0; - maxn = ExportDir->NumberOfNames - 1; - while (minn <= maxn) - { - mid = (minn + maxn) / 2; - - ExName = RVA(BaseAddress, ExNames[mid]); - res = strcmp(ExName, (PCHAR)SymbolName); - if (res == 0) - { - Ordinal = ExOrdinals[mid]; - Function = RVA(BaseAddress, ExFunctions[Ordinal]); - if ((ULONG_PTR)Function >= (ULONG_PTR)ExportDir && - (ULONG_PTR)Function < (ULONG_PTR)ExportDir + ExportDirSize) - { - Function = LdrPEFixupForward((PCHAR)Function); - if (Function == NULL) - { - DbgPrint("1: failed to find %s\n", Function); - } - return Function; - } - if (Function != NULL) - { - return Function; - } - } - else if (res > 0) - { - maxn = mid - 1; - } - else - { - minn = mid + 1; - } - } - - /* Fall back on unsorted */ - minn = 0; - maxn = ExportDir->NumberOfNames - 1; - while (minn <= maxn) - { - ExName = RVA(BaseAddress, ExNames[minn]); - res = strcmp(ExName, (PCHAR)SymbolName); - if (res == 0) - { - Ordinal = ExOrdinals[minn]; - Function = RVA(BaseAddress, ExFunctions[Ordinal]); - if ((ULONG_PTR)Function >= (ULONG_PTR)ExportDir && - (ULONG_PTR)Function < (ULONG_PTR)ExportDir + ExportDirSize) - { - Function = LdrPEFixupForward((PCHAR)Function); - if (Function == NULL) - { - DbgPrint("LdrPEGetExportByName(): failed to find %s\n",SymbolName); - } - return Function; - } - if (Function != NULL) - { - return Function; - } - DbgPrint("Failed to get function %s\n", SymbolName); - } - minn++; - } - - DbgPrint("2: failed to find %s\n",SymbolName); - return (PVOID)NULL; -} - -NTSTATUS -NTAPI -LdrPEProcessImportDirectoryEntry(PVOID DriverBase, - PLOADER_MODULE LoaderModule, - PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory) -{ - PVOID* ImportAddressList; - PULONG FunctionNameList; - - if (ImportModuleDirectory == NULL || ImportModuleDirectory->Name == 0) - { - return STATUS_UNSUCCESSFUL; - } - - /* Get the import address list. */ - ImportAddressList = (PVOID*)RVA(DriverBase, ImportModuleDirectory->FirstThunk); - - /* Get the list of functions to import. */ - if (ImportModuleDirectory->OriginalFirstThunk != 0) - { - FunctionNameList = (PULONG)RVA(DriverBase, ImportModuleDirectory->OriginalFirstThunk); - } - else - { - FunctionNameList = (PULONG)RVA(DriverBase, ImportModuleDirectory->FirstThunk); - } - - /* Walk through function list and fixup addresses. */ - while (*FunctionNameList != 0L) - { - if ((*FunctionNameList) & 0x80000000) - { - DbgPrint("Failed to import ordinal from %s\n", LoaderModule->String); - return STATUS_UNSUCCESSFUL; - } - else - { - IMAGE_IMPORT_BY_NAME *pe_name; - pe_name = RVA(DriverBase, *FunctionNameList); - *ImportAddressList = LdrPEGetExportByName((PVOID)LoaderModule->ModStart, pe_name->Name, pe_name->Hint); - - /* Fixup the address to be virtual */ - *ImportAddressList = (PVOID)(ULONG_PTR)*ImportAddressList + (ULONG_PTR)KernelBase - (ULONG_PTR)KernelMemory; - - - //DbgPrint("Looked for: %s and found: %x\n", pe_name->Name, *ImportAddressList); - if ((*ImportAddressList) == NULL) - { - DbgPrint("Failed to import %s from %s\n", pe_name->Name, LoaderModule->String); - return STATUS_UNSUCCESSFUL; - } - } - ImportAddressList++; - FunctionNameList++; - } - return STATUS_SUCCESS; -} - -extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos); - -NTSTATUS -NTAPI -LdrPEGetOrLoadModule(IN PCHAR ModuleName, - IN PCHAR ImportedName, - IN PLOADER_MODULE* ImportedModule) -{ - NTSTATUS Status = STATUS_SUCCESS; - - *ImportedModule = LdrGetModuleObject(ImportedName); - if (*ImportedModule == NULL) - { - /* - * For now, we only support import-loading the HAL. - * Later, FrLdrLoadDriver should be made to share the same - * code, and we'll just call it instead. - */ - FrLdrLoadDriver(ImportedName, 0); - - /* Return the new module */ - *ImportedModule = LdrGetModuleObject(ImportedName); - if (*ImportedModule == NULL) - { - DbgPrint("Error loading import: %s\n", ImportedName); - return STATUS_UNSUCCESSFUL; - } - } - - return Status; -} - -NTSTATUS -NTAPI -LdrPEFixupImports(IN PVOID DllBase, - IN PCHAR DllName) -{ - PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory; - PCHAR ImportedName; - NTSTATUS Status; - PLOADER_MODULE ImportedModule; - ULONG Size; - - /* Process each import module */ - ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR) - RtlImageDirectoryEntryToData(DllBase, - TRUE, - IMAGE_DIRECTORY_ENTRY_IMPORT, - &Size); - while (ImportModuleDirectory && ImportModuleDirectory->Name) - { - /* Check to make sure that import lib is kernel */ - ImportedName = (PCHAR) DllBase + ImportModuleDirectory->Name; - //DbgPrint("Processing imports for file: %s into file: %s\n", DllName, ImportedName); - - Status = LdrPEGetOrLoadModule(DllName, ImportedName, &ImportedModule); - if (!NT_SUCCESS(Status)) return Status; - - Status = LdrPEProcessImportDirectoryEntry(DllBase, ImportedModule, ImportModuleDirectory); - if (!NT_SUCCESS(Status)) return Status; - - //DbgPrint("Imports for file: %s into file: %s complete\n", DllName, ImportedName); - ImportModuleDirectory++; - } - - return STATUS_SUCCESS; -} diff --git a/boot/freeldr/freeldr/arch/powerpc/mach.c b/boot/freeldr/freeldr/arch/powerpc/mach.c deleted file mode 100644 index e5a93d9403d..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/mach.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * FreeLoader PowerPC Part - * Copyright (C) 2005 Art Yerkes - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "freeldr.h" -#include "machine.h" -#include "ppcmmu/mmu.h" -#include "of.h" -#include "prep.h" -#include "compat.h" - -extern void BootMain( PSTR CmdLine ); -extern ULONG CacheSizeLimit; -of_proxy ofproxy; -void *PageDirectoryStart, *PageDirectoryEnd; -static int chosen_package, stdin_handle, stdout_handle, part_handle = -1; -int mmu_handle = 0; -int claimed[4]; -BOOLEAN AcpiPresent = FALSE; -CHAR FrLdrBootPath[MAX_PATH] = "", BootPart[MAX_PATH] = "", CmdLine[MAX_PATH] = "bootprep"; -jmp_buf jmp; -volatile char *video_mem = 0; - -void PpcOfwPutChar( int ch ) { - char buf[3]; - if( ch == 0x0a ) { buf[0] = 0x0d; buf[1] = 0x0a; } - else { buf[0] = ch; buf[1] = 0; } - buf[2] = 0; - ofw_write(stdout_handle, buf, strlen(buf)); -} - -int PpcFindDevice( int depth, int parent, char *devname, int *nth ) { - static char buf[256]; - int next = 0; - int gotname = 0; - int match = 0; - int i; - - next = ofw_child( parent ); - - //printf( "next = %x\n", next ); - - gotname = ofw_getprop(parent, "name", buf, 256); - - //printf( "gotname = %d\n", gotname ); - - match = !strncmp(buf, devname, strlen(devname)); - - if( !nth && match ) return parent; - - for( i = 0; i < depth; i++ ) PpcOfwPutChar( ' ' ); - - if( depth == 1 ) { - if( gotname > 0 ) { - printf( "%c Name: %s\n", match ? '*' : ' ', buf ); - } else { - printf( "- No name attribute for %x\n", parent ); - } - } - - while( !match && next ) { - i = PpcFindDevice( depth+1, next, devname, nth ); - if( i ) return i; - next = ofw_peer( next ); - } - - return 0; -} - -BOOLEAN PpcConsKbHit() { - return FALSE; -} - -int PpcConsGetCh() { - char buf; - ofw_read( stdin_handle, &buf, 1 ); - return buf; -} - -void PpcVideoClearScreen( UCHAR Attr ) { -} - -VOID PpcVideoGetDisplaySize( PULONG Width, PULONG Height, PULONG Depth ) { - *Width = 80; - *Height = 25; - *Depth = 16; -} - -ULONG PpcVideoGetBufferSize() { - ULONG Width, Height, Depth; - MachVideoGetDisplaySize( &Width, &Height, &Depth ); - return Width * Height * Depth / 8; -} - -VIDEODISPLAYMODE PpcVideoSetDisplayMode( char *DisplayMode, BOOLEAN Init ) { - //printf( "DisplayMode: %s %s\n", DisplayMode, Init ? "true" : "false" ); - if( Init && !video_mem ) { - video_mem = MmAllocateMemory( PpcVideoGetBufferSize() ); - } - return VideoTextMode; -} - -VOID PpcVideoSetTextCursorPosition( ULONG X, ULONG Y ) { - printf("SetTextCursorPosition(%d,%d)\n", X,Y); -} - -VOID PpcVideoHideShowTextCursor( BOOLEAN Show ) { - printf("HideShowTextCursor(%s)\n", Show ? "true" : "false"); -} - -VOID PpcVideoPutChar( int Ch, UCHAR Attr, unsigned X, unsigned Y ) { - printf( "\033[%d;%dH%c", Y, X, Ch ); -} - -VOID PpcVideoCopyOffScreenBufferToVRAM( PVOID Buffer ) { - int i,j; - ULONG w,h,d; - PCHAR ChBuf = Buffer; - int offset = 0; - - MachVideoGetDisplaySize( &w, &h, &d ); - - for( i = 0; i < h; i++ ) { - for( j = 0; j < w; j++ ) { - offset = (j * 2) + (i * w * 2); - if( ChBuf[offset] != video_mem[offset] ) { - video_mem[offset] = ChBuf[offset]; - MachVideoPutChar(ChBuf[offset],0,j+1,i+1); - } - } - } -} - -BOOLEAN PpcVideoIsPaletteFixed() { - return FALSE; -} - -VOID PpcVideoSetPaletteColor( UCHAR Color, - UCHAR Red, UCHAR Green, UCHAR Blue ) { - printf( "SetPaletteColor(%x,%x,%x,%x)\n", Color, Red, Green, Blue ); -} - -VOID PpcVideoGetPaletteColor( UCHAR Color, - UCHAR *Red, UCHAR *Green, UCHAR *Blue ) { - printf( "GetPaletteColor(%x)\n", Color); -} - -VOID PpcVideoSync() { - printf( "Sync\n" ); -} - -int mmu_initialized = 0; -int mem_range_end; -VOID PpcInitializeMmu() -{ - if(!mmu_initialized) - { - MmuInit(); - MmuDbgInit(0, 0x800003f8); - MmuSetMemorySize(mem_range_end); - //MmuDbgEnter(0x20); - mmu_initialized = 1; - } -} - -ULONG PpcPrepGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap, - ULONG MaxMemoryMapSize ); - -/* - * Get memory the proper openfirmware way - */ -ULONG PpcGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap, - ULONG MaxMemoryMapSize ) { - int i, memhandle, total = 0, slots = 0, last = 0x40000, allocstart = 0x1000000; - int regdata[0x40]; - - printf("PpcGetMemoryMap(%d)\n", MaxMemoryMapSize); - - memhandle = ofw_finddevice("/memory"); - - ofw_getprop(memhandle, "reg", (char *)regdata, sizeof(regdata)); - - /* Try to claim some memory in usable blocks. Try to get some 8mb bits */ - for( i = 0; i < sizeof(claimed) / sizeof(claimed[0]); ) { - if (!claimed[i]) - claimed[i] = ofw_claim(allocstart, 8 * 1024 * 1024, 0x1000); - - allocstart += 8 * 1024 * 1024; - - if (claimed[i]) { - if (last < claimed[i]) { - BiosMemoryMap[slots].Type = BiosMemoryAcpiReclaim; - BiosMemoryMap[slots].BaseAddress = last; - BiosMemoryMap[slots].Length = claimed[i] - last; - slots++; - } - - BiosMemoryMap[slots].Type = BiosMemoryUsable; - BiosMemoryMap[slots].BaseAddress = claimed[i]; - BiosMemoryMap[slots].Length = 8 * 1024 * 1024; - - total += BiosMemoryMap[slots].Length; - last = - BiosMemoryMap[slots].BaseAddress + - BiosMemoryMap[slots].Length; - slots++; - i++; - } - } - - /* Get the rest until the end of the memory object as we see it */ - if (last < regdata[1]) { - BiosMemoryMap[slots].Type = BiosMemoryAcpiReclaim; - BiosMemoryMap[slots].BaseAddress = last; - BiosMemoryMap[slots].Length = regdata[1] - last; - slots++; - } - - for (i = 0; i < slots; i++) { - printf("MemoryMap[%d] = (%x:%x)\n", - i, - (int)BiosMemoryMap[i].BaseAddress, - (int)BiosMemoryMap[i].Length); - - } - - mem_range_end = regdata[1]; - - printf( "Returning memory map (%d entries, %dk free, %dk total ram)\n", - slots, total / 1024, regdata[1] / 1024 ); - - return slots; -} - -BOOLEAN PpcDiskReadLogicalSectors( ULONG DriveNumber, ULONGLONG SectorNumber, - ULONG SectorCount, PVOID Buffer ) { - int rlen = 0; - - if( part_handle == -1 ) { - part_handle = ofw_open( BootPart ); - - if( part_handle == -1 ) { - printf("Could not open any disk devices we know about\n"); - return FALSE; - } - } - - if( part_handle == -1 ) { - printf("Got partition handle %x\n", part_handle); - return FALSE; - } - - if( ofw_seek( part_handle, - (ULONG)(SectorNumber >> 25), - (ULONG)((SectorNumber * 512) & 0xffffffff) ) ) { - printf("Seek to %x failed\n", (ULONG)(SectorNumber * 512)); - return FALSE; - } - - rlen = ofw_read( part_handle, Buffer, (ULONG)(SectorCount * 512) ); - return rlen > 0; -} - -BOOLEAN PpcDiskGetDriveGeometry( ULONG DriveNumber, PGEOMETRY DriveGeometry ) { - printf("GetGeometry(%d)\n", DriveNumber); - DriveGeometry->BytesPerSector = 512; - DriveGeometry->Heads = 16; - DriveGeometry->Sectors = 63; - return TRUE; -} - -ULONG PpcDiskGetCacheableBlockCount( ULONG DriveNumber ) { - printf("GetCacheableBlockCount\n"); - return 1; -} - -TIMEINFO* -PpcGetTime(VOID) -{ - static TIMEINFO TimeInfo; - //printf("PpcGetTime\n"); - return &TimeInfo; -} - -VOID NarrowToWide(WCHAR *wide_name, char *name) -{ - char *copy_name; - WCHAR *wide_name_ptr; - for (wide_name_ptr = wide_name, copy_name = name; - (*wide_name_ptr = *copy_name); - wide_name_ptr++, copy_name++); -} - -/* Recursively copy the device tree into our representation - * It'll be passed to HAL. - * - * When NT was first done on PPC, it was on PReP hardware, which is very - * like PC hardware (really, just a PPC on a PC motherboard). HAL can guess - * the addresses of needed resources in this scheme as it can on x86. - * - * Most PPC hardware doesn't assign fixed addresses to hardware, which is - * the problem that open firmware partially solves. It allows hardware makers - * much more leeway in building PPC systems. Unfortunately, because - * openfirmware as originally specified neither captures nor standardizes - * all possible information, and also because of bugs, most OSs use a hybrid - * configuration scheme that relies both on verification of devices and - * recording information from openfirmware to be treated as hints. - */ -VOID OfwCopyDeviceTree -(PCONFIGURATION_COMPONENT_DATA ParentKey, - char *name, - int innode, - ULONG *BusNumber, - ULONG *DiskController, - ULONG *DiskNumber) -{ - int proplen = 0, node = innode; - char *prev_name, cur_name[64], data[256], *slash, devtype[64]; - wchar_t wide_name[64]; - PCONFIGURATION_COMPONENT_DATA NewKey; - - NarrowToWide(wide_name, name); - - /* Create a key for this device */ - FldrCreateComponentKey - (ParentKey, - AdapterClass, - MultiFunctionAdapter, - 0, - 0, - (ULONG)-1, - NULL, - NULL, - 0, - &NewKey); - - /* Add properties */ - for (prev_name = ""; ofw_nextprop(node, prev_name, cur_name) == 1; ) - { - proplen = ofw_getproplen(node, cur_name); - if (proplen > 256 || proplen < 0) - { - printf("Warning: not getting prop %s (too long: %d)\n", - cur_name, proplen); - continue; - } - ofw_getprop(node, cur_name, data, sizeof(data)); - - /* Get device type so we can examine it */ - if (!strcmp(cur_name, "device_type")) - strcpy(devtype, (char *)data); - - NarrowToWide(wide_name, cur_name); - //RegSetValue(NewKey, wide_name, REG_BINARY, data, proplen); - - strcpy(data, cur_name); - prev_name = data; - } - -#if 0 - /* Special device handling */ - if (!strcmp(devtype, "ata")) - { - OfwHandleDiskController(NewKey, node, *DiskController); - (*DiskController)++; - *DiskNumber = 0; - } - else if (!strcmp(devtype, "disk")) - { - OfwHandleDiskObject(NewKey, node, *DiskController, *DiskNumber); - (*DiskNumber)++; - } -#endif - - /* Subdevices */ - for (node = ofw_child(node); node; node = ofw_peer(node)) - { - ofw_package_to_path(node, data, sizeof(data)); - slash = strrchr(data, '/'); - if (slash) slash++; else continue; - OfwCopyDeviceTree - (NewKey, slash, node, BusNumber, DiskController, DiskNumber); - } -} - -PCONFIGURATION_COMPONENT_DATA PpcHwDetect() { - PCONFIGURATION_COMPONENT_DATA RootKey; - ULONG BusNumber = 0, DiskController = 0, DiskNumber = 0; - int node = ofw_finddevice("/"); - - FldrCreateSystemKey(&RootKey); - - OfwCopyDeviceTree(RootKey,"/",node,&BusNumber,&DiskController,&DiskNumber); - return RootKey; -} - -VOID -PpcHwIdle(VOID) -{ - /* UNIMPLEMENTED */ -} - -void PpcDefaultMachVtbl() -{ - MachVtbl.ConsPutChar = PpcOfwPutChar; - MachVtbl.ConsKbHit = PpcConsKbHit; - MachVtbl.ConsGetCh = PpcConsGetCh; - MachVtbl.VideoClearScreen = PpcVideoClearScreen; - MachVtbl.VideoSetDisplayMode = PpcVideoSetDisplayMode; - MachVtbl.VideoGetDisplaySize = PpcVideoGetDisplaySize; - MachVtbl.VideoGetBufferSize = PpcVideoGetBufferSize; - MachVtbl.VideoSetTextCursorPosition = PpcVideoSetTextCursorPosition; - MachVtbl.VideoHideShowTextCursor = PpcVideoHideShowTextCursor; - MachVtbl.VideoPutChar = PpcVideoPutChar; - MachVtbl.VideoCopyOffScreenBufferToVRAM = - PpcVideoCopyOffScreenBufferToVRAM; - MachVtbl.VideoIsPaletteFixed = PpcVideoIsPaletteFixed; - MachVtbl.VideoSetPaletteColor = PpcVideoSetPaletteColor; - MachVtbl.VideoGetPaletteColor = PpcVideoGetPaletteColor; - MachVtbl.VideoSync = PpcVideoSync; - - MachVtbl.GetMemoryMap = PpcGetMemoryMap; - - MachVtbl.DiskReadLogicalSectors = PpcDiskReadLogicalSectors; - MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry; - MachVtbl.DiskGetCacheableBlockCount = PpcDiskGetCacheableBlockCount; - - MachVtbl.GetTime = PpcGetTime; - - MachVtbl.HwDetect = PpcHwDetect; - MachVtbl.HwIdle = PpcHwIdle; -} - -void PpcOfwInit() -{ - chosen_package = ofw_finddevice( "/chosen" ); - - ofw_getprop(chosen_package, "bootargs", - CmdLine, sizeof(CmdLine)); - ofw_getprop( chosen_package, "stdin", - (char *)&stdin_handle, sizeof(stdin_handle) ); - ofw_getprop( chosen_package, "stdout", - (char *)&stdout_handle, sizeof(stdout_handle) ); - ofw_getprop( chosen_package, "mmu", - (char *)&mmu_handle, sizeof(mmu_handle) ); - - // Allow forcing prep for broken OFW - if(!strncmp(CmdLine, "bootprep", 8)) - { - printf("Going to PREP init...\n"); - ofproxy = NULL; - PpcPrepInit(); - return; - } - - printf( "FreeLDR version [%s]\n", FrLdrVersionString ); - - BootMain( CmdLine ); -} - -void PpcInit( of_proxy the_ofproxy ) { - // Hack to be a bit easier on ram - CacheSizeLimit = 64 * 1024; - ofproxy = the_ofproxy; - PpcDefaultMachVtbl(); - if(ofproxy) PpcOfwInit(); - else PpcPrepInit(); -} - -void MachInit(const char *CmdLine) { - int i, len; - char *sep; - - BootPart[0] = 0; - FrLdrBootPath[0] = 0; - - printf( "Determining boot device: [%s]\n", CmdLine ); - - sep = NULL; - for( i = 0; i < strlen(CmdLine); i++ ) { - if( strncmp(CmdLine + i, "boot=", 5) == 0) { - strcpy(BootPart, CmdLine + i + 5); - sep = strchr(BootPart, ','); - if( sep ) - *sep = 0; - while(CmdLine[i] && CmdLine[i]!=',') i++; - } - } - - if( strlen(BootPart) == 0 ) { - if (ofproxy) - len = ofw_getprop(chosen_package, "bootpath", - FrLdrBootPath, sizeof(FrLdrBootPath)); - else - len = 0; - if( len < 0 ) len = 0; - FrLdrBootPath[len] = 0; - printf( "Boot Path: %s\n", FrLdrBootPath ); - - sep = strrchr(FrLdrBootPath, ','); - - strcpy(BootPart, FrLdrBootPath); - if( sep ) { - BootPart[sep - FrLdrBootPath] = 0; - } - } - - printf( "FreeLDR starting (boot partition: %s)\n", BootPart ); -} - -void beep() { -} - -UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address) { - return GetPhysByte(((ULONG)Address)+0x80000000); -} - -void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value) { - SetPhysByte(((ULONG)Address)+0x80000000, Value); -} - -VOID __cdecl BootLinuxKernel( - IN ULONG KernelSize, - IN PVOID KernelCurrentLoadAddress, - IN PVOID KernelTargetLoadAddress, - IN UCHAR DriveNumber, - IN ULONG PartitionNumber) -{ - ofw_exit(); -} - -VOID __cdecl ChainLoadBiosBootSectorCode( - IN UCHAR BootDrive OPTIONAL, - IN ULONG BootPartition OPTIONAL) -{ - ofw_exit(); -} - -void DbgBreakPoint() { - __asm__("twi 31,0,0"); -} diff --git a/boot/freeldr/freeldr/arch/powerpc/mboot.c b/boot/freeldr/freeldr/arch/powerpc/mboot.c deleted file mode 100644 index 73a50d9d0c1..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/mboot.c +++ /dev/null @@ -1,852 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com> - * Copyright (C) 2005 Alex Ionescu <alex(a)relsoft.net> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <freeldr.h> -#include <elf/elf.h> -#include <elf/reactos.h> -#include <of.h> -#include "ppcmmu/mmu.h" -#include "compat.h" - -#include <debug.h> - -/* We'll check this to see if we're in OFW land */ -extern of_proxy ofproxy; - -PVOID KernelMemory = NULL; - -/* Bits to shift to convert a Virtual Address into an Offset in the Page Table */ -#define PFN_SHIFT 12 - -/* Bits to shift to convert a Virtual Address into an Offset in the Page Directory */ -#define PDE_SHIFT 22 -#define PDE_SHIFT_PAE 18 - -#define STARTUP_BASE 0xC0000000 -#define HYPERSPACE_BASE 0xC0400000 -#define HYPERSPACE_PAE_BASE 0xC0800000 -#define APIC_BASE 0xFEC00000 -#define KPCR_BASE 0xFF000000 - -#define LowMemPageTableIndex 0 -#define StartupPageTableIndex (STARTUP_BASE >> 22) -#define HyperspacePageTableIndex (HYPERSPACE_BASE >> 22) -#define KpcrPageTableIndex (KPCR_BASE >> 22) -#define ApicPageTableIndex (APIC_BASE >> 22) - -#define BAT_GRANULARITY (64 * 1024) -#define KernelMemorySize (8 * 1024 * 1024) -#define XROUNDUP(x,n) ((((ULONG)x) + ((n) - 1)) & (~((n) - 1))) - -#define TAG_MBOOT 'oobM' - -char reactos_module_strings[64][256]; // Array to hold module names - -/* Load Address of Next Module */ -ULONG_PTR NextModuleBase = 0; - -/* Currently Opened Module */ -PLOADER_MODULE CurrentModule = NULL; - -/* Unrelocated Kernel Base in Virtual Memory */ -ULONG_PTR KernelBase; - -/* Wether PAE is to be used or not */ -BOOLEAN PaeModeEnabled; - -/* Kernel Entrypoint in Physical Memory */ -ULONG_PTR KernelEntryPoint; - -/* Dummy to bring in memmove */ -PVOID memmove_dummy = memmove; - -PLOADER_MODULE -NTAPI -LdrGetModuleObject(PCHAR ModuleName); - -NTSTATUS -NTAPI -LdrPEFixupImports(IN PVOID DllBase, - IN PCHAR DllName); - -VOID PpcInitializeMmu(int max); - -/* FUNCTIONS *****************************************************************/ - -/*++ - * FrLdrStartup - * INTERNAL - * - * Prepares the system for loading the Kernel. - * - * Params: - * Magic - Multiboot Magic - * - * Returns: - * None. - * - * Remarks: - * None. - * - *--*/ - -typedef void (*KernelEntryFn)( void * ); - -int MmuPageMiss(int trapCode, ppc_trap_frame_t *trap) -{ - int i; - printf("TRAP %x\n", trapCode); - for( i = 0; i < 40; i++ ) - printf("r[%d] %x\n", i, trap->gpr[i]); - printf("HALT!\n"); - while(1); -} - -typedef struct _ppc_map_set_t { - int mapsize; - int usecount; - ppc_map_info_t *info; -} ppc_map_set_t; - -extern int mmu_handle; -paddr_t MmuTranslate(paddr_t possibly_virtual) -{ - if (ofproxy) - { - /* Openfirmware takes liberties with boot-time memory. - * if you're in a unitary kernel, it's not as difficult, but since - * we rely on loading things into virtual space from here, we need - * to detect the mappings so far. - */ - int args[2]; - args[0] = possibly_virtual; - args[1] = 1; /* Marker to tell we want a physical addr */ - return (paddr_t)ofw_callmethod_ret("translate", mmu_handle, 2, args, 3); - } - else - { - /* Other booters don't remap ram */ - return possibly_virtual; - } -} - -VOID -NTAPI -FrLdrAddPageMapping(ppc_map_set_t *set, int proc, paddr_t phys, vaddr_t virt) -{ - int j; - paddr_t page = ROUND_DOWN(phys, (1<<PFN_SHIFT)); - - if (virt == 0) - virt = ROUND_DOWN(page, (1<<PFN_SHIFT)); - else - virt = ROUND_DOWN(virt, (1<<PFN_SHIFT)); - - page = MmuTranslate(page); - - //printf("Mapping virt [%x] to phys [%x (from) %x]\n", virt, page, phys); - - for( j = 0; j < set->usecount; j++ ) - { - if(set->info[j].addr == page) return; - } - - if (!set->mapsize) - { - set->mapsize = 0x80; - set->info = MmAllocateMemory(0x80 * sizeof(*set->info)); - } - else if (set->mapsize <= set->usecount) - { - ppc_map_info_t *newinfo = MmAllocateMemory(set->mapsize * 2 * sizeof(*set->info)); - memcpy(newinfo, set->info, set->mapsize * sizeof(*set->info)); - MmFreeMemory(set->info); - set->info = newinfo; - set->mapsize *= 2; - } - - set->info[set->usecount].flags = MMU_ALL_RW; - set->info[set->usecount].proc = proc; - set->info[set->usecount].addr = virt; - set->info[set->usecount].phys = page; - set->usecount++; -} - -extern int _start[], _end[]; - -VOID -NTAPI -FrLdrStartup(ULONG Magic) -{ - ULONG_PTR i, tmp, OldModCount = 0; - PCHAR ModHeader; - CHAR ModulesTreated[64] = { 0 }; - ULONG NumberOfEntries = 0, UsedEntries = 0; - PPAGE_LOOKUP_TABLE_ITEM FreeLdrMap = MmGetMemoryMap(&NumberOfEntries); - ppc_map_set_t memmap = { }; - - printf("FrLdrStartup\n"); - - /* Disable EE */ - __asm__("mfmsr %0" : "=r" (tmp)); - tmp &= 0x7fff; - __asm__("mtmsr %0" : : "r" (tmp)); - - while(OldModCount != LoaderBlock.ModsCount) - { - printf("Added %d modules last pass\n", - LoaderBlock.ModsCount - OldModCount); - - OldModCount = LoaderBlock.ModsCount; - - for(i = 0; i < LoaderBlock.ModsCount; i++) - { - if (!ModulesTreated[i]) - { - ModulesTreated[i] = 1; - ModHeader = ((PCHAR)reactos_modules[i].ModStart); - if(ModHeader[0] == 'M' && ModHeader[1] == 'Z') - LdrPEFixupImports - ((PVOID)reactos_modules[i].ModStart, - (PCHAR)reactos_modules[i].String); - } - } - } - - printf("Starting mmu\n"); - - PpcInitializeMmu(0); - - printf("Allocating vsid 0 (kernel)\n"); - MmuAllocVsid(0, 0xff00); - - /* We'll use vsid 1 for freeldr (expendable) */ - printf("Allocating vsid 1 (freeldr)\n"); - MmuAllocVsid(1, 0xff); - - printf("Mapping Freeldr Code (%x-%x)\n", _start, _end); - - /* Map memory zones */ - /* Freeldr itself */ - for( i = (int)_start; - i < (int)_end; - i += (1<<PFN_SHIFT) ) { - FrLdrAddPageMapping(&memmap, 1, i, 0); - } - - printf("KernelBase %x\n", KernelBase); - - /* Heap pages -- this gets the entire freeldr heap */ - for( i = 0; i < NumberOfEntries; i++ ) { - tmp = i<<PFN_SHIFT; - if (FreeLdrMap[i].PageAllocated == LoaderSystemCode) { - UsedEntries++; - if (tmp >= (ULONG)KernelMemory && - tmp < (ULONG)KernelMemory + KernelMemorySize) { - FrLdrAddPageMapping(&memmap, 0, tmp, KernelBase + tmp - (ULONG)KernelMemory); - } else { - FrLdrAddPageMapping(&memmap, 1, tmp, 0); - } - } - } - - MmuMapPage(memmap.info, memmap.usecount); - - printf("Finished Mapping the Freeldr Heap (used %d pages)\n", UsedEntries); - - printf("Setting initial segments\n"); - MmuSetVsid(0, 8, 1); - MmuSetVsid(8, 16, 0); - - printf("Segments set!\n"); - - MmuTurnOn((KernelEntryFn)KernelEntryPoint, &LoaderBlock); - - /* Nothing more */ - while(1); -} - -/*++ - * FrLdrSetupPae - * INTERNAL - * - * Configures PAE on a MP System, and sets the PDBR if it's supported, or if - * the system is UP. - * - * Params: - * Magic - Multiboot Magic - * - * Returns: - * None. - * - * Remarks: - * None. - * - *--*/ -VOID -FASTCALL -FrLdrSetupPae(ULONG Magic) -{ -} - -/*++ - * FrLdrGetKernelBase - * INTERNAL - * - * Gets the Kernel Base to use. - * - * Params: - * - * Returns: - * None. - * - * Remarks: - * Sets both the FreeLdr internal variable as well as the one which - * will be used by the Kernel. - * - *--*/ -VOID -FASTCALL -FrLdrGetKernelBase(VOID) -{ - PCHAR p; - - /* Default kernel base at 2GB */ - KernelBase = 0x80800000; - - /* Set KernelBase */ - LoaderBlock.KernelBase = 0x80000000; - - /* Read Command Line */ - p = (PCHAR)LoaderBlock.CommandLine; - while ((p = strchr(p, '/')) != NULL) { - - /* Find "/3GB" */ - if (!_strnicmp(p + 1, "3GB", 3)) { - - /* Make sure there's nothing following it */ - if (p[4] == ' ' || p[4] == 0) { - - /* Use 3GB */ - KernelBase = 0xE0000000; - LoaderBlock.KernelBase = 0xC0000000; - } - } - - p++; - } -} - -/*++ - * FrLdrGetPaeMode - * INTERNAL - * - * Determines whether PAE mode should be enabled or not. - * - * Params: - * None. - * - * Returns: - * None. - * - * Remarks: - * None. - * - *--*/ -VOID -FASTCALL -FrLdrGetPaeMode(VOID) -{ -} - -/*++ - * FrLdrSetupPageDirectory - * INTERNAL - * - * Sets up the ReactOS Startup Page Directory. - * - * Params: - * None. - * - * Returns: - * None. - * - * Remarks: - * We are setting PDEs, but using the equivalent (for our purpose) PTE structure. - * As such, please note that PageFrameNumber == PageEntryNumber. - * - *--*/ -VOID -FASTCALL -FrLdrSetupPageDirectory(VOID) -{ -} - -/*++ - * FrLdrMapModule - * INTERNAL - * - * Loads the indicated elf image as PE. The target will appear to be - * a PE image whose ImageBase has ever been KernelAddr. - * - * Params: - * Image -- File to load - * ImageName -- Name of image for the modules list - * MemLoadAddr -- Freeldr address of module - * KernelAddr -- Kernel address of module - *--*/ -#define ELF_SECTION(n) ((Elf32_Shdr*)(sptr + (n * shsize))) -#define COFF_FIRST_SECTION(h) ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+(SWAPW(((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader)))) - -BOOLEAN -NTAPI -FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG KernelAddr) -{ - PIMAGE_DOS_HEADER ImageHeader = 0; - PIMAGE_NT_HEADERS NtHeader = 0; - PIMAGE_SECTION_HEADER Section; - ULONG SectionCount; - ULONG ImageSize; - INT i, j; - PLOADER_MODULE ModuleData; - //int phsize, phnum; - int shsize, shnum, relsize, SectionAddr = 0; - PCHAR sptr; - Elf32_Ehdr ehdr; - Elf32_Shdr *shdr; - LARGE_INTEGER Position; - PSTR TempName; - - TempName = strrchr(ImageName, '\\'); - if(TempName) TempName++; else TempName = (PSTR)ImageName; - ModuleData = LdrGetModuleObject(TempName); - - if(ModuleData) - { - return TRUE; - } - - if(!KernelAddr) - KernelAddr = (ULONG)NextModuleBase - (ULONG)KernelMemory + KernelBase; - if(!MemLoadAddr) - MemLoadAddr = (PCHAR)NextModuleBase; - - ModuleData = &reactos_modules[LoaderBlock.ModsCount]; - //printf("Loading file (elf at %x)\n", KernelAddr); - - /* Load the first 1024 bytes of the kernel image so we can read the PE header */ - if (ArcRead(KernelImage, &ehdr, sizeof(ehdr), NULL) != ESUCCESS) { - - /* Fail if we couldn't read */ - printf("Couldn't read the elf header\n"); - return FALSE; - } - - /* Start by getting elf headers */ - //phsize = ehdr.e_phentsize; - //phnum = ehdr.e_phnum; - shsize = ehdr.e_shentsize; - shnum = ehdr.e_shnum; - sptr = (PCHAR)FrLdrTempAlloc(shnum * shsize, TAG_MBOOT); - - /* Read section headers */ - Position.QuadPart = ehdr.e_shoff; - ArcSeek(KernelImage, &Position, SeekAbsolute); - ArcRead(KernelImage, sptr, shsize * shnum, NULL); - - /* Now we'll get the PE Header */ - for( i = 0; i < shnum; i++ ) - { - shdr = ELF_SECTION(i); - shdr->sh_addr = 0; - - /* Find the PE Header */ - if (shdr->sh_type == TYPE_PEHEADER) - { - Position.QuadPart = shdr->sh_offset; - ArcSeek(KernelImage, &Position, SeekAbsolute); - ArcRead(KernelImage, MemLoadAddr, shdr->sh_size, NULL); - ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr; - NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew)); -#if 0 - printf("NtHeader at %x\n", SWAPD(ImageHeader->e_lfanew)); - printf("SectionAlignment %x\n", - SWAPD(NtHeader->OptionalHeader.SectionAlignment)); - SectionAddr = ROUND_UP - (shdr->sh_size, SWAPD(NtHeader->OptionalHeader.SectionAlignment)); - printf("Header ends at %x\n", SectionAddr); -#endif - break; - } - } - - if(i == shnum) - { - printf("No peheader section encountered :-(\n"); - return 0; - } -#if 0 - else - { - printf("DOS SIG: %s\n", (PCHAR)MemLoadAddr); - } -#endif - - /* Save the Image Base */ - NtHeader->OptionalHeader.ImageBase = SWAPD(KernelAddr); - - /* Load the file image */ - Section = COFF_FIRST_SECTION(NtHeader); - SectionCount = SWAPW(NtHeader->FileHeader.NumberOfSections); - - /* Walk each section */ - for (i=0; i < SectionCount; i++, Section++) - { - shdr = ELF_SECTION((SWAPD(Section->PointerToRawData)+1)); - - shdr->sh_addr = SectionAddr = SWAPD(Section->VirtualAddress); - shdr->sh_addr += KernelAddr; - - Section->PointerToRawData = SWAPD((Section->VirtualAddress - KernelAddr)); - - if (shdr->sh_type != SHT_NOBITS) - { - /* Content area */ - printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size); - Position.QuadPart = shdr->sh_offset; - ArcSeek(KernelImage, &Position, SeekAbsolute); - ArcRead(KernelImage, MemLoadAddr + SectionAddr, shdr->sh_size, NULL); - } - else - { - /* Zero it out */ - printf("BSS section %d at %x\n", i, KernelAddr + SectionAddr); - memset(MemLoadAddr + SectionAddr, 0, - ROUND_UP(shdr->sh_size, - SWAPD(NtHeader->OptionalHeader.SectionAlignment))); - } - } - - ImageSize = SWAPD(NtHeader->OptionalHeader.SizeOfImage); - printf("Total image size is %x\n", ImageSize); - - /* Handle relocation sections */ - for (i = 0; i < shnum; i++) { - Elf32_Rela reloc = { }; - ULONG *Target32; - USHORT *Target16; - int numreloc, relstart, targetSection; - Elf32_Sym symbol; - PCHAR RelocSection, SymbolSection; - - shdr = ELF_SECTION(i); - /* Only relocs here */ - if((shdr->sh_type != SHT_REL) && - (shdr->sh_type != SHT_RELA)) continue; - - relstart = shdr->sh_offset; - relsize = shdr->sh_type == SHT_RELA ? 12 : 8; - numreloc = shdr->sh_size / relsize; - targetSection = shdr->sh_info; - - if (!ELF_SECTION(targetSection)->sh_addr) continue; - - RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); - Position.QuadPart = relstart; - ArcSeek(KernelImage, &Position, SeekAbsolute); - ArcRead(KernelImage, RelocSection, shdr->sh_size, NULL); - - /* Get the symbol section */ - shdr = ELF_SECTION(shdr->sh_link); - - SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); - Position.QuadPart = shdr->sh_offset; - ArcSeek(KernelImage, &Position, SeekAbsolute); - ArcRead(KernelImage, SymbolSection, shdr->sh_size, NULL); - - for(j = 0; j < numreloc; j++) - { - ULONG S,A,P; - - /* Get the reloc */ - memcpy(&reloc, RelocSection + (j * relsize), sizeof(reloc)); - - /* Get the symbol */ - memcpy(&symbol, SymbolSection + (ELF32_R_SYM(reloc.r_info) * sizeof(symbol)), sizeof(symbol)); - - /* Compute addends */ - S = symbol.st_value + ELF_SECTION(symbol.st_shndx)->sh_addr; - A = reloc.r_addend; - P = reloc.r_offset + ELF_SECTION(targetSection)->sh_addr; - -#if 0 - printf("Symbol[%d] %d -> %d(%x:%x) -> %x(+%x)@%x\n", - ELF32_R_TYPE(reloc.r_info), - ELF32_R_SYM(reloc.r_info), - symbol.st_shndx, - ELF_SECTION(symbol.st_shndx)->sh_addr, - symbol.st_value, - S, - A, - P); -#endif - - Target32 = (ULONG*)(((PCHAR)MemLoadAddr) + (P - KernelAddr)); - Target16 = (USHORT *)Target32; - - switch (ELF32_R_TYPE(reloc.r_info)) - { - case R_PPC_NONE: - break; - case R_PPC_ADDR32: - *Target32 = S + A; - break; - case R_PPC_REL32: - *Target32 = S + A - P; - break; - case R_PPC_UADDR32: /* Special: Treat as RVA */ - *Target32 = S + A - KernelAddr; - break; - case R_PPC_ADDR24: - *Target32 = (ADDR24_MASK & (S+A)) | (*Target32 & ~ADDR24_MASK); - break; - case R_PPC_REL24: - *Target32 = (ADDR24_MASK & (S+A-P)) | (*Target32 & ~ADDR24_MASK); - break; - case R_PPC_ADDR16_LO: - *Target16 = S + A; - break; - case R_PPC_ADDR16_HA: - *Target16 = (S + A + 0x8000) >> 16; - break; - default: - break; - } - -#if 0 - printf("reloc[%d:%x]: (type %x sym %d val %d) off %x add %x (old %x new %x)\n", - j, - ((ULONG)Target32) - ((ULONG)MemLoadAddr), - ELF32_R_TYPE(reloc.r_info), - ELF32_R_SYM(reloc.r_info), - symbol.st_value, - reloc.r_offset, reloc.r_addend, - x, *Target32); -#endif - } - - FrLdrTempFree(SymbolSection, TAG_MBOOT); - FrLdrTempFree(RelocSection, TAG_MBOOT); - } - - FrLdrTempFree(sptr, TAG_MBOOT); - - ModuleData->ModStart = (ULONG)MemLoadAddr; - /* Increase the next Load Base */ - NextModuleBase = ROUND_UP((ULONG)MemLoadAddr + ImageSize, PAGE_SIZE); - ModuleData->ModEnd = NextModuleBase; - ModuleData->String = (ULONG)MmAllocateMemory(strlen(ImageName)+1); - strcpy((PCHAR)ModuleData->String, ImageName); - printf("Module %s (%x-%x) next at %x\n", - ModuleData->String, - ModuleData->ModStart, - ModuleData->ModEnd, - NextModuleBase); - LoaderBlock.ModsCount++; - - /* Return Success */ - return TRUE; -} - -/*++ - * FrLdrMapKernel - * INTERNAL - * - * Maps the Kernel into memory, does PE Section Mapping, initializes the - * uninitialized data sections, and relocates the image. - * - * Params: - * KernelImage - FILE Structure representing the ntoskrnl image file. - * - * Returns: - * TRUE if the Kernel was mapped. - * - * Remarks: - * None. - * - *--*/ -BOOLEAN -NTAPI -FrLdrMapKernel(FILE *KernelImage) -{ - /* Get Kernel Base */ - FrLdrGetKernelBase(); - - /* Allocate kernel memory */ - KernelMemory = MmAllocateMemory(KernelMemorySize); - - return FrLdrMapModule(KernelImage, "ntoskrnl.exe", KernelMemory, KernelBase); -} - -ULONG_PTR -NTAPI -FrLdrLoadModule(FILE *ModuleImage, - PCSTR ModuleName, - PULONG ModuleSize) -{ - ARC_STATUS Status; - FILEINFORMATION FileInfo; - ULONG LocalModuleSize; - ULONG_PTR ThisModuleBase = NextModuleBase; - PLOADER_MODULE ModuleData; - PSTR NameBuffer; - PSTR TempName; - - /* Get current module data structure and module name string array */ - ModuleData = &reactos_modules[LoaderBlock.ModsCount]; - - /* Get only the Module Name */ - do { - - TempName = strchr(ModuleName, '\\'); - - if(TempName) { - ModuleName = TempName + 1; - } - - } while(TempName); - NameBuffer = reactos_module_strings[LoaderBlock.ModsCount]; - - /* Get Module Size */ - Status = ArcGetFileInformation(ModuleImage, &FileInfo); - if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0) - LocalModuleSize = 0; - else - LocalModuleSize = FileInfo.EndingAddress.LowPart; - - /* Fill out Module Data Structure */ - ModuleData->ModStart = NextModuleBase; - ModuleData->ModEnd = NextModuleBase + LocalModuleSize; - - /* Save name */ - strcpy(NameBuffer, ModuleName); - ModuleData->String = (ULONG_PTR)NameBuffer; - - /* Load the file image */ - ArcRead(ModuleImage, (PVOID)NextModuleBase, LocalModuleSize, NULL); - - /* Move to next memory block and increase Module Count */ - NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE); - LoaderBlock.ModsCount++; - - /* Return Module Size if required */ - if (ModuleSize != NULL) { - *ModuleSize = LocalModuleSize; - } - - printf("Module %s (%x-%x) next at %x\n", - ModuleData->String, - ModuleData->ModStart, - ModuleData->ModEnd, - NextModuleBase); - - return ThisModuleBase; -} - -PVOID -NTAPI -FrLdrMapImage(IN FILE *Image, IN PCHAR ShortName, IN ULONG ImageType) -{ - PVOID Result = NULL; - - printf("Loading image %s (type %d)\n", ShortName, ImageType); - - if (ImageType == 1) - { - if(FrLdrMapKernel(Image)) - Result = (PVOID)KernelMemory; - } - else - { - PVOID ModuleBase = (PVOID)NextModuleBase; - - if(FrLdrMapModule(Image, ShortName, 0, 0)) - Result = ModuleBase; - } - return Result; -} - -ULONG_PTR -NTAPI -FrLdrCreateModule(PCSTR ModuleName) -{ - PLOADER_MODULE ModuleData; - PSTR NameBuffer; - - /* Get current module data structure and module name string array */ - ModuleData = &reactos_modules[LoaderBlock.ModsCount]; - NameBuffer = reactos_module_strings[LoaderBlock.ModsCount]; - - /* Set up the structure */ - ModuleData->ModStart = NextModuleBase; - ModuleData->ModEnd = -1; - - /* Copy the name */ - strcpy(NameBuffer, ModuleName); - ModuleData->String = (ULONG_PTR)NameBuffer; - - /* Set the current Module */ - CurrentModule = ModuleData; - - /* Return Module Base Address */ - return(ModuleData->ModStart); -} - -BOOLEAN -NTAPI -FrLdrCloseModule(ULONG_PTR ModuleBase, - ULONG ModuleSize) -{ - PLOADER_MODULE ModuleData = CurrentModule; - - /* Make sure a module is opened */ - if (ModuleData) { - - /* Make sure this is the right module and that it hasn't been closed */ - if ((ModuleBase == ModuleData->ModStart) && (ModuleData->ModEnd == MAXULONG_PTR)) { - - /* Close the Module */ - ModuleData->ModEnd = ModuleData->ModStart + ModuleSize; - - /* Set the next Module Base and increase the number of modules */ - NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE); - LoaderBlock.ModsCount++; - - /* Close the currently opened module */ - CurrentModule = NULL; - - /* Success */ - return(TRUE); - } - } - - /* Failure path */ - return(FALSE); -} diff --git a/boot/freeldr/freeldr/arch/powerpc/mmu.c b/boot/freeldr/freeldr/arch/powerpc/mmu.c deleted file mode 100644 index e195eaeac07..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/mmu.c +++ /dev/null @@ -1,399 +0,0 @@ -#include <freeldr.h> -#include "ppcmmu/mmu.h" - -inline int GetMSR() { - register int res asm ("r3"); - __asm__("mfmsr 3"); - return res; -} - -inline int GetDEC() { - register int res asm ("r3"); - __asm__("mfdec 3"); - return res; -} - -__asm__("\t.globl GetPhys\n" - "GetPhys:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "isync\n\t" - "sync\n\t" - "lwz 3,0(3)\n\t" /* Get actual value at phys addr r3 */ - "mtmsr 5\n\t" - "isync\n\t" - "sync\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -__asm__("\t.globl GetPhysHalf\n" - "GetPhysHalf:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "isync\n\t" - "sync\n\t" - "lhz 3,0(3)\n\t" /* Get actual value at phys addr r3 */ - "mtmsr 5\n\t" - "isync\n\t" - "sync\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -__asm__("\t.globl GetPhysByte\n" - "GetPhysByte:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "isync\n\t" - "sync\n\t" - "lbz 3,0(3)\n\t" /* Get actual value at phys addr r3 */ - "mtmsr 5\n\t" - "isync\n\t" - "sync\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -__asm__("\t.globl SetPhys\n" - "SetPhys:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "sync\n\t" - "eieio\n\t" - "stw 4,0(3)\n\t" /* Set actual value at phys addr r3 */ - "dcbst 0,3\n\t" - "mtmsr 5\n\t" - "sync\n\t" - "eieio\n\t" - "mr 3,4\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -__asm__("\t.globl SetPhysHalf\n" - "SetPhysHalf:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "sync\n\t" - "eieio\n\t" - "sth 4,0(3)\n\t" /* Set actual value at phys addr r3 */ - "dcbst 0,3\n\t" - "mtmsr 5\n\t" - "sync\n\t" - "eieio\n\t" - "mr 3,4\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -__asm__("\t.globl SetPhysByte\n" - "SetPhysByte:\t\n" - "mflr 0\n\t" - "stwu 0,-16(1)\n\t" - "mfmsr 5\n\t" - "andi. 6,5,0xffef\n\t"/* turn off MSR[DR] */ - "mtmsr 6\n\t" - "sync\n\t" - "eieio\n\t" - "stb 4,0(3)\n\t" /* Set actual value at phys addr r3 */ - "dcbst 0,3\n\t" - "mtmsr 5\n\t" - "sync\n\t" - "eieio\n\t" - "mr 3,4\n\t" - "lwz 0,0(1)\n\t" - "addi 1,1,16\n\t" - "mtlr 0\n\t" - "blr" - ); - -inline int GetSR(int n) { - register int res asm ("r3"); - switch( n ) { - case 0: - __asm__("mfsr 3,0"); - break; - case 1: - __asm__("mfsr 3,1"); - break; - case 2: - __asm__("mfsr 3,2"); - break; - case 3: - __asm__("mfsr 3,3"); - break; - case 4: - __asm__("mfsr 3,4"); - break; - case 5: - __asm__("mfsr 3,5"); - break; - case 6: - __asm__("mfsr 3,6"); - break; - case 7: - __asm__("mfsr 3,7"); - break; - case 8: - __asm__("mfsr 3,8"); - break; - case 9: - __asm__("mfsr 3,9"); - break; - case 10: - __asm__("mfsr 3,10"); - break; - case 11: - __asm__("mfsr 3,11"); - break; - case 12: - __asm__("mfsr 3,12"); - break; - case 13: - __asm__("mfsr 3,13"); - break; - case 14: - __asm__("mfsr 3,14"); - break; - case 15: - __asm__("mfsr 3,15"); - break; - } - return res; -} - -inline void GetBat( int bat, int inst, int *batHi, int *batLo ) { - register int bh asm("r3"), bl asm("r4"); - if( inst ) { - switch( bat ) { - case 0: - __asm__("mfibatu 3,0"); - __asm__("mfibatl 4,0"); - break; - case 1: - __asm__("mfibatu 3,1"); - __asm__("mfibatl 4,1"); - break; - case 2: - __asm__("mfibatu 3,2"); - __asm__("mfibatl 4,2"); - break; - case 3: - __asm__("mfibatu 3,3"); - __asm__("mfibatl 4,3"); - break; - } - } else { - switch( bat ) { - case 0: - __asm__("mfdbatu 3,0"); - __asm__("mfdbatl 4,0"); - break; - case 1: - __asm__("mfdbatu 3,1"); - __asm__("mfdbatl 4,1"); - break; - case 2: - __asm__("mfdbatu 3,2"); - __asm__("mfdbatl 4,2"); - break; - case 3: - __asm__("mfdbatu 3,3"); - __asm__("mfdbatl 4,3"); - break; - } - } - *batHi = bh; - *batLo = bl; -} - -inline void SetBat( int bat, int inst, int batHi, int batLo ) { - register int bh asm("r3"), bl asm("r4"); - bh = batHi; - bl = batLo; - if( inst ) { - switch( bat ) { - case 0: - __asm__("mtibatu 0,3"); - __asm__("mtibatl 0,4"); - break; - case 1: - __asm__("mtibatu 1,3"); - __asm__("mtibatl 1,4"); - break; - case 2: - __asm__("mtibatu 2,3"); - __asm__("mtibatl 2,4"); - break; - case 3: - __asm__("mtibatu 3,3"); - __asm__("mtibatl 3,4"); - break; - } - } else { - switch( bat ) { - case 0: - __asm__("mtdbatu 0,3"); - __asm__("mtdbatl 0,4"); - break; - case 1: - __asm__("mtdbatu 1,3"); - __asm__("mtdbatl 1,4"); - break; - case 2: - __asm__("mtdbatu 2,3"); - __asm__("mtdbatl 2,4"); - break; - case 3: - __asm__("mtdbatu 3,3"); - __asm__("mtdbatl 3,4"); - break; - } - } - __asm__("isync\n\tsync"); -} - -inline int GetSDR1() { - register int res asm("r3"); - __asm__("mfsdr1 3"); - return res; -} - -inline void SetSDR1( int sdr ) { -#if 0 - int i,j; -#endif - __asm__("mtsdr1 3"); -#if 0 - __asm__("sync"); - __asm__("isync"); - __asm__("ptesync"); - - for( i = 0; i < 256; i++ ) { - j = i << 12; - __asm__("tlbie %0,0" : : "r" (j)); - } - __asm__("eieio"); - __asm__("tlbsync"); - __asm__("ptesync"); -#endif -} - -inline int BatHit( int bath, int batl, int virt ) { - int mask = 0xfffe0000 & ~((batl & 0x3f) << 17); - return (batl & 0x40) && ((virt & mask) == (bath & mask)); -} - -inline int BatTranslate( int bath, int batl, int virt ) { - return (virt & 0x007fffff) | (batl & 0xfffe0000); -} - -/* translate address */ -int PpcVirt2phys( int virt, int inst ) { - int msr = GetMSR(); - int txmask = inst ? 0x20 : 0x10; - int i, bath, batl, sr, sdr1, physbase, valo; - int hash, hashmask, ptehi, ptelo, ptegaddr; - //int vahi, npteg; - int vsid, pteh, ptevsid, pteapi; - - if( msr & txmask ) { - sr = GetSR( virt >> 28 ); - vsid = sr & 0xfffffff; - //vahi = vsid >> 4; - valo = (vsid << 28) | (virt & 0xfffffff); - if( sr & 0x80000000 ) { - return valo; - } - - for( i = 0; i < 4; i++ ) { - GetBat( i, inst, &bath, &batl ); - if( BatHit( bath, batl, virt ) ) { - return BatTranslate( bath, batl, virt ); - } - } - - sdr1 = GetSDR1(); - - physbase = sdr1 & ~0xffff; - hashmask = ((sdr1 & 0x1ff) << 10) | 0x3ff; - hash = (vsid & 0x7ffff) ^ ((valo >> 12) & 0xffff); - //npteg = hashmask + 1; - - for( pteh = 0; pteh < 0x80; pteh += 64, hash ^= 0x7ffff ) { - ptegaddr = ((hashmask & hash) * 64) + physbase; - - for( i = 0; i < 8; i++ ) { - ptehi = GetPhys( ptegaddr + (i * 8) ); - ptelo = GetPhys( ptegaddr + (i * 8) + 4 ); - - ptevsid = (ptehi >> 7) & 0xffffff; - pteapi = ptehi & 0x3f; - - if( (ptehi & 64) != pteh ) continue; - if( ptevsid != (vsid & 0xffffff) ) continue; - if( pteapi != ((virt >> 22) & 0x3f) ) continue; - - return (ptelo & 0xfffff000) | (virt & 0xfff); - } - } - return -1; - } else { - return virt; - } -} - -/* Add a new page table entry for the indicated mapping */ -BOOLEAN InsertPageEntry( int virt, int phys, int slot, int _sdr1 ) { - int i, ptehi, ptelo; - int sdr1 = _sdr1 ? _sdr1 : GetSDR1(); - int sr = GetSR( (virt >> 28) & 0xf ); - int vsid = sr & 0xfffffff; - int physbase = sdr1 & ~0xffff; - int hashmask = ((sdr1 & 0x1ff) << 10) | 0x3ff; - int valo = (vsid << 28) | (virt & 0xfffffff); - int hash = (vsid & 0x7ffff) ^ ((valo >> 12) & 0xffff); - int ptegaddr = ((hashmask & hash) * 64) + physbase; - - for( i = 0; i < 8; i++ ) { - ptehi = GetPhys( ptegaddr + (i * 8) ); - - if( (slot != i) && (ptehi & 0x80000000) ) continue; - - ptehi = (1 << 31) | (vsid << 7) | ((virt >> 22) & 0x3f); - ptelo = phys & ~0xfff; - - SetPhys( ptegaddr + (i * 8), ptehi ); - SetPhys( ptegaddr + (i * 8) + 4, ptelo ); - - return TRUE; - } - - return FALSE; -} diff --git a/boot/freeldr/freeldr/arch/powerpc/ofw_method.c b/boot/freeldr/freeldr/arch/powerpc/ofw_method.c deleted file mode 100644 index 0a160b54840..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/ofw_method.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <freeldr.h> -#include "of.h" - -typedef struct _ofw_method_call { - const char *call_method; - int nargs; - int nrets; - const char *method_name; - int handle; - int args_rets[8]; -} ofw_method_call; - -extern int (*ofw_call_addr)(void *argstruct); - -int ofw_callmethod_ret(const char *method, int handle, int nargs, int *args, int ret) -{ - ofw_method_call callframe = { 0 }; - callframe.call_method = "call-method"; - callframe.nargs = nargs + 2; - callframe.nrets = ret+1; - callframe.method_name = method; - callframe.handle = handle; - memcpy(callframe.args_rets, args, sizeof(int)*nargs); - ofw_call_addr(&callframe); - return callframe.args_rets[nargs+ret]; -} diff --git a/boot/freeldr/freeldr/arch/powerpc/ofw_util.s b/boot/freeldr/freeldr/arch/powerpc/ofw_util.s deleted file mode 100644 index 1a214451630..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/ofw_util.s +++ /dev/null @@ -1,48 +0,0 @@ - .section .text - .globl ofw_functions - .globl ofw_call_addr - .globl call_ofw -call_ofw: - /* R3 has the function offset to call (n * 4) - * Other arg registers are unchanged. */ - subi %r1,%r1,0x100 - stw %r8,24(%r1) - mflr %r8 - stw %r8,0(%r1) - stw %r3,4(%r1) - stw %r4,8(%r1) - stw %r5,12(%r1) - stw %r6,16(%r1) - stw %r7,20(%r1) - stw %r9,28(%r1) - stw %r10,32(%r1) - stw %r20,36(%r1) - - lis %r10,ofw_functions@ha - addi %r8,%r10,ofw_functions@l - add %r8,%r3,%r8 - lwz %r9,0(%r8) - mtctr %r9 - - mr %r3,%r4 - mr %r4,%r5 - mr %r5,%r6 - mr %r6,%r7 - mr %r7,%r8 - mr %r8,%r9 - - /* Call ofw proxy function */ - bctrl - - lwz %r8,0(%r1) - mtlr %r8 - lwz %r4,8(%r1) - lwz %r5,12(%r1) - lwz %r6,16(%r1) - lwz %r7,20(%r1) - lwz %r8,24(%r1) - lwz %r9,28(%r1) - lwz %r10,32(%r1) - lwz %r20,36(%r1) - addi %r1,%r1,0x100 - blr diff --git a/boot/freeldr/freeldr/arch/powerpc/prep.c b/boot/freeldr/freeldr/arch/powerpc/prep.c deleted file mode 100644 index 0d33e921bc4..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/prep.c +++ /dev/null @@ -1,148 +0,0 @@ -#include "freeldr.h" -#include "machine.h" -#include "ppcmmu/mmu.h" -#include "prep.h" - -int prep_serial = 0x800003f8; -extern int mem_range_end; - -void sync() { __asm__("eieio\n\tsync"); } - -/* Simple serial */ - -void PpcPrepPutChar( int ch ) { - if( ch == 0x0a ) { - SetPhysByte(prep_serial, 0x0d); - sync(); - } - SetPhysByte(prep_serial, ch); - sync(); -} - -BOOLEAN PpcPrepDiskReadLogicalSectors -( ULONG DriveNumber, ULONGLONG SectorNumber, - ULONG SectorCount, PVOID Buffer ) { - int secct; - - for(secct = 0; secct < SectorCount; secct++) - { - ide_seek(&ide1_desc, SectorNumber + secct, 0); - ide_read(&ide1_desc, ((PCHAR)Buffer) + secct * 512, 512); - } - /* Never give up! */ - return TRUE; -} - -BOOLEAN PpcPrepConsKbHit() -{ - return 1; - //return GetPhysByte(prep_serial+5) & 1; -} - -int PpcPrepConsGetCh() -{ - while(!PpcPrepConsKbHit()); - return GetPhysByte(prep_serial); -} - -void PpcPrepVideoClearScreen(UCHAR Attr) -{ - printf("\033c"); -} - -VIDEODISPLAYMODE PpcPrepVideoSetDisplayMode( char *DisplayMode, BOOLEAN Init ) -{ - return VideoTextMode; -} - -void PpcPrepVideoGetDisplaySize( PULONG Width, PULONG Height, PULONG Depth ) -{ - *Width = 80; - *Height = 25; - *Depth = 16; -} - -VOID PpcInitializeMmu(int max); - -ULONG PpcPrepGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap, - ULONG MaxMemoryMapSize ) -{ - // Probe memory - paddr_t physAddr; - register int oldStore = 0, newStore = 0, change = 0, oldmsr; - - __asm__("mfmsr %0\n" : "=r" (oldmsr)); - change = oldmsr & 0x6fff; - __asm__("mtmsr %0\n" : : "r" (change)); - - // Find the last ram address in physical space ... this bypasses mapping - // but could run into non-ram objects right above ram. Usually systems - // aren't designed like that though. - for (physAddr = 0x40000, change = newStore; - (physAddr < 0x80000000) && (change == newStore); - physAddr += 1 << 12) - { - oldStore = GetPhys(physAddr); - newStore = (physAddr & 0x1000) ? 0x55aa55aa : 0xaa55aa55; - SetPhys(physAddr, newStore); - change = GetPhys(physAddr); - SetPhys(physAddr, oldStore); - } - // Back off by one page - physAddr -= 0x1000; - BiosMemoryMap[0].BaseAddress = 0x30000; // End of ppcmmu - BiosMemoryMap[0].Type = BiosMemoryUsable; - BiosMemoryMap[0].Length = physAddr - BiosMemoryMap[0].BaseAddress; - - __asm__("mtmsr %0\n" : : "r" (oldmsr)); - - mem_range_end = physAddr; - - printf("Actual RAM: %d Mb\n", physAddr >> 20); - return 1; -} - -/* Most PReP hardware is in standard locations, based on the corresponding - * hardware on PCs. */ -PCONFIGURATION_COMPONENT_DATA PpcPrepHwDetect() { - PCONFIGURATION_COMPONENT_DATA SystemKey; - - /* Create the 'System' key */ - FldrCreateSystemKey(&SystemKey); - - printf("DetectHardware() Done\n"); - return SystemKey; -} - -VOID -PpcPrepHwIdle(VOID) -{ - /* UNIMPLEMENTED */ -} - -void PpcPrepInit() -{ - MachVtbl.ConsPutChar = PpcPrepPutChar; - - printf("Serial on\n"); - - ide_setup( &ide1_desc ); - - MachVtbl.DiskReadLogicalSectors = PpcPrepDiskReadLogicalSectors; - - MachVtbl.ConsKbHit = PpcPrepConsKbHit; - MachVtbl.ConsGetCh = PpcPrepConsGetCh; - - MachVtbl.VideoClearScreen = PpcPrepVideoClearScreen; - MachVtbl.VideoSetDisplayMode = PpcPrepVideoSetDisplayMode; - MachVtbl.VideoGetDisplaySize = PpcPrepVideoGetDisplaySize; - - MachVtbl.GetMemoryMap = PpcPrepGetMemoryMap; - MachVtbl.HwDetect = PpcPrepHwDetect; - MachVtbl.HwIdle = PcPrepHwIdle; - - printf( "FreeLDR version [%s]\n", FrLdrVersionString ); - - BootMain( "" ); -} - diff --git a/boot/freeldr/freeldr/arch/powerpc/prep.h b/boot/freeldr/freeldr/arch/powerpc/prep.h deleted file mode 100644 index c539b88bc8c..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/prep.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -extern struct _pci_desc pci1_desc; -extern struct _idectl_desc ide1_desc; -extern struct _vga_desc vga1_desc; -struct _pci_bar { - unsigned long data; -}; - -void sync( void ); -void PpcPrepInit( void ); -void ide_seek( void *extension, int low, int high ); -int ide_read( void *extension, char *buffer, int bytes ); -void ide_setup( void *extension ); - -void print_bar( struct _pci_bar *bar ); -void pci_setup -( PCONFIGURATION_COMPONENT_DATA pci_bus, - struct _pci_desc *pci_desc ); -void pci_read_bar -( struct _pci_desc *pci_desc, - int bus, int dev, int fn, int bar, - struct _pci_bar *bar_data ); - -void vga_setup -( PCONFIGURATION_COMPONENT_DATA pci_bus, - struct _pci_desc *pci_desc, struct _vga_desc *vga_desc, - int bus, int dev, int fn ); diff --git a/boot/freeldr/freeldr/arch/powerpc/prep_ide.c b/boot/freeldr/freeldr/arch/powerpc/prep_ide.c deleted file mode 100644 index a96bf4d14f2..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/prep_ide.c +++ /dev/null @@ -1,106 +0,0 @@ -#include "freeldr.h" -#include "machine.h" -#include "ppcmmu/mmu.h" -#include "prep.h" - -#define SWAP_W(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) - -typedef struct _idectl_desc { - int port; - long long seekto; - int seek_cylinder, seek_head, seek_sector; - int cylinders, heads, sectors, bytespersec; -} idectl_desc; - -idectl_desc ide1_desc = { 0x800001f0 }; - -void ide_seek( void *extension, int low, int high ) { - idectl_desc *desc = (idectl_desc *)extension; - long long seekto = ((((long long)high) << 32) | (low & 0xffffffff)); - /* order = sector, head, cylinder */ - desc->seek_sector = seekto % desc->sectors; - seekto /= desc->sectors; - desc->seek_head = seekto % desc->heads; - seekto /= desc->heads; - desc->seek_cylinder = seekto; - desc->seekto = seekto; -} - -/* Thanks chuck moore. This is based on the color forth ide code */ -/* Wait for ready */ -void ide_rdy( void *extension ) { - idectl_desc *desc = (idectl_desc *)extension; - while( !(GetPhysByte(desc->port+7) & 0x40) ) sync(); -} - -void ide_drq( void *extension ) { - idectl_desc *desc = (idectl_desc *)extension; - while( !(GetPhysByte(desc->port+7) & 0x08) ) sync(); -} - -void ide_bsy( void *extension ) { - idectl_desc *desc = (idectl_desc *)extension; - while( GetPhysByte(desc->port+7) & 0x80 ) - { - printf("Waiting for not busy\n"); - sync(); - } -} - -int ide_read( void *extension, char *buffer, int bytes ) { - idectl_desc *desc = (idectl_desc *)extension; - short *databuf = (short *)buffer; - int inwords; - - ide_bsy( extension ); - SetPhysByte(desc->port+2, bytes / desc->bytespersec); - SetPhysByte(desc->port+3, desc->seek_sector + 1); - SetPhysByte(desc->port+4, desc->seek_cylinder); - SetPhysByte(desc->port+5, desc->seek_cylinder >> 8); - SetPhysByte(desc->port+6, desc->seek_head | 0xa0); - SetPhysByte(desc->port+7, 0x20); - - for( inwords = 0; inwords < desc->bytespersec / sizeof(short); inwords++ ) { - databuf[inwords] = GetPhysHalf(desc->port); - } - - desc->seekto += desc->bytespersec; - ide_seek( extension, desc->seekto, desc->seekto >> 32 ); - - return bytes - (bytes % desc->bytespersec); -} - -void ide_setup( void *extension ) { - idectl_desc *desc = (idectl_desc *)extension; - short identbuffer[256]; - char namebuf[41]; - short *databuf = (short *)identbuffer, in; - int inwords; - - ide_rdy( extension ); - ide_bsy( extension ); - desc->bytespersec = 512; - SetPhysByte(desc->port+2, 1); - SetPhysByte(desc->port+3, 0); - SetPhysByte(desc->port+4, 0); - SetPhysByte(desc->port+5, 0); - SetPhysByte(desc->port+6, 0); - SetPhysByte(desc->port+7, 0xec); - ide_drq( extension ); - - for( inwords = 0; inwords < desc->bytespersec / sizeof(short); inwords++ ) { - in = GetPhysHalf(desc->port); - databuf[inwords] = SWAP_W(in); - sync(); - } - - desc->cylinders = identbuffer[1]; - desc->heads = identbuffer[3]; - desc->sectors = identbuffer[6]; - - /* Debug: Write out hard disc model */ - - strncpy(namebuf, (char *)(identbuffer+0x1b), 41); - printf("HARD DISC MODEL: %s c,h,s %d,%d,%d\n", - namebuf, desc->cylinders, desc->heads, desc->sectors); -} diff --git a/boot/freeldr/freeldr/arch/powerpc/prep_pci.c b/boot/freeldr/freeldr/arch/powerpc/prep_pci.c deleted file mode 100644 index df92704e1a4..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/prep_pci.c +++ /dev/null @@ -1,127 +0,0 @@ -#include <freeldr.h> -#include "prep.h" - -typedef struct _pci_cfg { - unsigned long addr; - unsigned long data; -} pci_cfg; - -typedef struct _pci_desc { - pci_cfg *cfg; -} pci_desc; - -pci_desc pci1_desc = { (void *)0x80000cf8 }; -#define rev16(x) ((((x)>>8)&0xff)|(((x)&0xff)<<8)) -#define rev32(x) ((((x)>>24)&0xff)|(((x)>>8)&0xff00)|(((x)&0xff00)<<8)|(((x)&0xff)<<24)) -#define pci_addr(bus,dev,fn,reg) \ - (0x80000000 | \ - ((bus & 0xff) << 16) | \ - ((dev & 0x1f) << 11) | \ - ((fn & 7) << 8) | \ - (reg & 0xfc)) -#if 0 -#define pci_cfg_addr(bus,dev,fn,reg) \ - ((bus == 0) ? \ - ((1 << (dev + 16)) | \ - (dev << 11) | \ - (fn << 8) | \ - ((reg & 0xfc) | 1)) : pci_addr(bus,dev,fn,reg)) -#else -#define pci_cfg_addr(bus,dev,fn,reg) pci_addr(bus,dev,fn,reg) -#endif - unsigned long pci_read( pci_desc *desc, int bus, int dev, int fn, int reg, int len ) { - sync(); - unsigned long save_state = desc->cfg->addr, ret = 0; - unsigned long addr = pci_cfg_addr(bus,dev,fn,reg); - unsigned long offset = reg & 3; - desc->cfg->addr = rev32(addr); - sync(); - switch( len ) { - case 4: - ret = desc->cfg->data; - break; - case 2: - ret = desc->cfg->data; - ret = (ret >> (offset << 3)) & 0xffff; - break; - case 1: - ret = desc->cfg->data; - ret = (ret >> (offset << 3)) & 0xff; - break; - } - desc->cfg->addr = save_state; - sync(); - return ret; - } - -void pci_read_bar( pci_desc *desc, int bus, int dev, int fn, int bar, - struct _pci_bar *bar_data ) { - bar_data->data = pci_read( desc, bus, dev, fn, 0x10 + (bar * 4), 4 ); -} - -/* - * Imagine: offset 3, len 1 - * let oldval = 0x12345678 and val = 0xabcd1234; - * mask = ((1 << 8) - 1) << 24; // 0xff000000 - * oldval = (0x12345678 & 0x00ffffff) | (0xabcd1234 & 0xff000000) = 0xab345678; - */ -void pci_write( pci_desc *desc, int bus, int dev, int fn, int reg, int len, int val ) { - unsigned long save_state = desc->cfg->addr; - unsigned long addr = pci_cfg_addr(bus,dev,fn,reg); - unsigned long offset = reg & 3; - unsigned long oldval = pci_read( desc, bus, dev, fn, reg & ~3, 4 ); - unsigned long mask = ((1 << (len * 8)) - 1) << (offset << 3); - oldval = (oldval & ~mask) | ((val << (offset << 3)) & mask); - desc->cfg->addr = rev32(addr); - sync(); - desc->cfg->data = rev32(oldval); - sync(); - desc->cfg->addr = save_state; - sync(); -} - -void pci_write_bar( pci_desc *desc, int bus, int dev, int fn, int bar, struct _pci_bar *bar_data ) { - pci_write( desc, bus, dev, fn, 0x10 + (bar * 4), 4, bar_data->data ); -} - -void print_bar( struct _pci_bar *bar ) { - printf("BAR: %x\n", bar->data); -} - -#define PCI_VENDORID 0 -#define PCI_DEVICEID 2 -#define PCI_HEADER_TYPE 0xe -#define PCI_BASECLASS 0xb - -void pci_setup( PCONFIGURATION_COMPONENT_DATA pcibus, pci_desc *desc ) { - unsigned char type; - unsigned short vendor, device, devclass; - int funcs, bus, dev, fn; - - pci1_desc.cfg = (pci_cfg *)0x80000cf8; - - printf("PCI Bus:\n"); - for( bus = 0; bus < 1; bus++ ) { - for( dev = 0; dev < 32; dev++ ) { - type = pci_read(desc,bus,dev,0,PCI_HEADER_TYPE,1); - vendor = pci_read(desc,bus,dev,0,PCI_VENDORID,2); - device = pci_read(desc,bus,dev,0,PCI_DEVICEID,2); - - if(vendor == 0 || vendor == 0xffff) continue; - if(type & 0x80) funcs = 8; else funcs = 1; - - for( fn = 0; fn < funcs; fn++ ) { - devclass = pci_read(desc,bus,dev,fn,PCI_BASECLASS,1); - printf(" %d:%d -> vendor:device:class %x:%x:%x\n", - bus, dev, vendor, device, devclass); - - if( devclass == 3 ) { - printf("Setting up vga...\n"); - vga_setup(pcibus,desc,&vga1_desc,bus,dev,fn); - printf("Done with vga\n"); - } - } - } - } - printf("^-- end PCI\n"); -} diff --git a/boot/freeldr/freeldr/arch/powerpc/prep_vga.c b/boot/freeldr/freeldr/arch/powerpc/prep_vga.c deleted file mode 100644 index ee8fdbbf4e7..00000000000 --- a/boot/freeldr/freeldr/arch/powerpc/prep_vga.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <freeldr.h> -#include "prep.h" - -struct _vga_desc { - char *port; - char *addr; -}; - -#define VGA_WIDTH 1024 -#define VGA_HEIGHT 768 -struct _vga_desc vga1_desc = { (char *)0x800003c0 }; - -void vga_setup( PCONFIGURATION_COMPONENT_DATA pcibus, - struct _pci_desc *desc, struct _vga_desc *vga_desc, - int bus, int dev, int fn ) { - struct _pci_bar bar_data; - int i; - - for( i = 0; i < 6; i++ ) { - pci_read_bar( desc, bus, dev, fn, i, &bar_data ); - print_bar( &bar_data ); - if( (bar_data.data > 0x10000) || ((bar_data.data&1) == 1) ) { - vga_desc->addr = (char *)(0xc0000000 + (bar_data.data & ~0x7ff)); -// BootInfo.dispDeviceBase = vga_desc->addr; - break; - } - } -} diff --git a/boot/freeldr/freeldr/include/arch/powerpc/hardware.h b/boot/freeldr/freeldr/include/arch/powerpc/hardware.h deleted file mode 100644 index fcf663ad50a..00000000000 --- a/boot/freeldr/freeldr/include/arch/powerpc/hardware.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * FreeLoader - * - * Copyright (C) 2003 Eric Kohl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#ifndef __REGISTRY_H -#include "../../reactos/registry.h" -#endif - -/* PROTOTYPES ***************************************************************/ - -/* hardware.c */ - -VOID StallExecutionProcessor(ULONG Microseconds); - -VOID HalpCalibrateStallExecution(VOID); - -ULONGLONG RDTSC(VOID); - -/* EOF */ diff --git a/boot/freeldr/freeldr/include/of.h b/boot/freeldr/freeldr/include/of.h deleted file mode 100644 index 76c9d2162ce..00000000000 --- a/boot/freeldr/freeldr/include/of.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#define OF_FAILED 0 -#define ERR_NOT_FOUND 0xc0000010 - -#include "of_call.h" -#include <string.h> - -typedef int (*of_proxy) - ( int table_off, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6 ); -typedef long jmp_buf[100]; -extern of_proxy ofproxy; - -int setjmp( jmp_buf buf ); -int longjmp( jmp_buf buf, int retval ); -int ofw_callmethod_ret(const char *method, int handle, int nargs, int *args, int ret); diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index f11bad8f864..299dc891acc 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -4,6 +4,4 @@ if((ARCH STREQUAL "i386") OR (ARCH STREQUAL "amd64")) add_subdirectory(halx86) elseif(ARCH STREQUAL "arm") add_subdirectory(halarm) -elseif(ARCH STREQUAL "powerpc") -# add_subdirectory(halppc) endif() diff --git a/hal/halppc/generic/beep.c b/hal/halppc/generic/beep.c deleted file mode 100644 index 178b7755086..00000000000 --- a/hal/halppc/generic/beep.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: hal/halppc/generic/beep.c - * PURPOSE: Speaker function (it's only one) - * PROGRAMMER: Eric Kohl - * UPDATE HISTORY: - * Created 31/01/99 - */ - -/* INCLUDES *****************************************************************/ - -#include <hal.h> -#define NDEBUG -#include <debug.h> - - -/* CONSTANTS *****************************************************************/ - -#define TIMER2 0x42 -#define TIMER3 0x43 -#define PORT_B 0x61 -#define CLOCKFREQ 1193167 - - -/* FUNCTIONS *****************************************************************/ -/* - * FUNCTION: Beeps the speaker. - * ARGUMENTS: - * Frequency = If 0, the speaker will be switched off, otherwise - * the speaker beeps with the specified frequency. - */ - -BOOLEAN -NTAPI -HalMakeBeep ( - ULONG Frequency - ) -{ - return TRUE; -} - diff --git a/hal/halppc/generic/bus.c b/hal/halppc/generic/bus.c deleted file mode 100644 index 23a9a07c8a4..00000000000 --- a/hal/halppc/generic/bus.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * PROJECT: ReactOS HAL - * LICENSE: GPL - See COPYING in the top level directory - * FILE: hal/halppc/generic/bus.c - * PURPOSE: Bus Support Routines - * PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org) - */ - -/* INCLUDES ******************************************************************/ - -#include <hal.h> -#define NDEBUG -#include <debug.h> - -/* GLOBALS *******************************************************************/ - -ULONG HalpBusType; - -/* PRIVATE FUNCTIONS *********************************************************/ - -VOID -NTAPI -HalpRegisterKdSupportFunctions(VOID) -{ - /* Register PCI Device Functions */ - KdSetupPciDeviceForDebugging = HalpSetupPciDeviceForDebugging; - KdReleasePciDeviceforDebugging = HalpReleasePciDeviceForDebugging; - - /* Register memory functions */ - KdMapPhysicalMemory64 = HalpMapPhysicalMemory64; - KdUnmapVirtualAddress = HalpUnmapVirtualAddress; - - /* Register ACPI stub */ - KdCheckPowerButton = HalpCheckPowerButton; -} - -NTSTATUS -NTAPI -HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath, - IN PUNICODE_STRING DriverClassName, - IN PDRIVER_OBJECT DriverObject, - IN PDEVICE_OBJECT DeviceObject, - IN INTERFACE_TYPE BusType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN OUT PCM_RESOURCE_LIST *AllocatedResources) -{ - BUS_HANDLER BusHandler; - PAGED_CODE(); - - /* Only PCI is supported */ - if (BusType != PCIBus) return STATUS_NOT_IMPLEMENTED; - - /* Setup fake PCI Bus handler */ - RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); - BusHandler.BusNumber = BusNumber; - - /* Call the PCI function */ - return HalpAssignPCISlotResources(&BusHandler, - &BusHandler, - RegistryPath, - DriverClassName, - DriverObject, - DeviceObject, - SlotNumber, - AllocatedResources); -} - -BOOLEAN -NTAPI -HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, - IN ULONG BusNumber, - IN PHYSICAL_ADDRESS BusAddress, - IN OUT PULONG AddressSpace, - OUT PPHYSICAL_ADDRESS TranslatedAddress) -{ - /* Translation is easy */ - TranslatedAddress->QuadPart = BusAddress.QuadPart; - return TRUE; -} - -ULONG -NTAPI -HalpGetSystemInterruptVector(IN ULONG BusNumber, - IN ULONG BusInterruptLevel, - IN ULONG BusInterruptVector, - OUT PKIRQL Irql, - OUT PKAFFINITY Affinity) -{ - ULONG Vector = IRQ2VECTOR(BusInterruptLevel); - *Irql = (KIRQL)VECTOR2IRQL(Vector); - *Affinity = 0xFFFFFFFF; - return Vector; -} - -BOOLEAN -NTAPI -HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress, - IN OUT PULONG AddressSpace, - OUT PPHYSICAL_ADDRESS TranslatedAddress, - IN OUT PULONG_PTR Context, - IN BOOLEAN NextBus) -{ - /* Make sure we have a context */ - if (!Context) return FALSE; - - /* If we have data in the context, then this shouldn't be a new lookup */ - if ((*Context != 0) && (NextBus != FALSE)) return FALSE; - - /* Return bus data */ - TranslatedAddress->QuadPart = BusAddress.QuadPart; - - /* Set context value and return success */ - *Context = 1; - return TRUE; -} - -VOID -NTAPI -HalpInitNonBusHandler(VOID) -{ - /* These should be written by the PCI driver later, but we give defaults */ - HalPciTranslateBusAddress = HalpTranslateBusAddress; - HalPciAssignSlotResources = HalpAssignSlotResources; - HalFindBusAddressTranslation = HalpFindBusAddressTranslation; -} - -/* PUBLIC FUNCTIONS **********************************************************/ - -/* - * @implemented - */ -NTSTATUS -NTAPI -HalAdjustResourceList(IN PCM_RESOURCE_LIST Resources) -{ - /* Deprecated, return success */ - return STATUS_SUCCESS; -} - -/* - * @implemented - */ -NTSTATUS -NTAPI -HalAssignSlotResources(IN PUNICODE_STRING RegistryPath, - IN PUNICODE_STRING DriverClassName, - IN PDRIVER_OBJECT DriverObject, - IN PDEVICE_OBJECT DeviceObject, - IN INTERFACE_TYPE BusType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN OUT PCM_RESOURCE_LIST *AllocatedResources) -{ - /* Check the bus type */ - if (BusType != PCIBus) - { - /* Call our internal handler */ - return HalpAssignSlotResources(RegistryPath, - DriverClassName, - DriverObject, - DeviceObject, - BusType, - BusNumber, - SlotNumber, - AllocatedResources); - } - else - { - /* Call the PCI registered function */ - return HalPciAssignSlotResources(RegistryPath, - DriverClassName, - DriverObject, - DeviceObject, - PCIBus, - BusNumber, - SlotNumber, - AllocatedResources); - } -} - -/* - * @implemented - */ -ULONG -NTAPI -HalGetBusData(IN BUS_DATA_TYPE BusDataType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Length) -{ - /* Call the extended function */ - return HalGetBusDataByOffset(BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length); -} - -/* - * @implemented - */ -ULONG -NTAPI -HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Offset, - IN ULONG Length) -{ - BUS_HANDLER BusHandler; - - /* Look as the bus type */ - if (BusDataType == Cmos) - { - /* Call CMOS Function */ - return HalpGetCmosData(0, SlotNumber, Buffer, Length); - } - else if (BusDataType == EisaConfiguration) - { - /* FIXME: TODO */ - ASSERT(FALSE); - } - else if ((BusDataType == PCIConfiguration) && - (HalpPCIConfigInitialized) && - ((BusNumber >= HalpMinPciBus) && (BusNumber <= HalpMaxPciBus))) - { - /* Setup fake PCI Bus handler */ - RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); - BusHandler.BusNumber = BusNumber; - - /* Call PCI function */ - return HalpGetPCIData(&BusHandler, - &BusHandler, - *(PPCI_SLOT_NUMBER)&SlotNumber, - Buffer, - Offset, - Length); - } - - /* Invalid bus */ - return 0; -} - -/* - * @implemented - */ -ULONG -NTAPI -HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType, - IN ULONG BusNumber, - IN ULONG BusInterruptLevel, - IN ULONG BusInterruptVector, - OUT PKIRQL Irql, - OUT PKAFFINITY Affinity) -{ - /* Call the system bus translator */ - return HalpGetSystemInterruptVector(BusNumber, - BusInterruptLevel, - BusInterruptVector, - Irql, - Affinity); -} - -/* - * @implemented - */ -ULONG -NTAPI -HalSetBusData(IN BUS_DATA_TYPE BusDataType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Length) -{ - /* Call the extended function */ - return HalSetBusDataByOffset(BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length); -} - -/* - * @implemented - */ -ULONG -NTAPI -HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, - IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Offset, - IN ULONG Length) -{ - BUS_HANDLER BusHandler; - - /* Look as the bus type */ - if (BusDataType == Cmos) - { - /* Call CMOS Function */ - return HalpSetCmosData(0, SlotNumber, Buffer, Length); - } - else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized)) - { - /* Setup fake PCI Bus handler */ - RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); - BusHandler.BusNumber = BusNumber; - - /* Call PCI function */ - return HalpSetPCIData(&BusHandler, - &BusHandler, - *(PPCI_SLOT_NUMBER)&SlotNumber, - Buffer, - Offset, - Length); - } - - /* Invalid bus */ - return 0; -} - -/* - * @implemented - */ -BOOLEAN -NTAPI -HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, - IN ULONG BusNumber, - IN PHYSICAL_ADDRESS BusAddress, - IN OUT PULONG AddressSpace, - OUT PPHYSICAL_ADDRESS TranslatedAddress) -{ - /* Look as the bus type */ - if (InterfaceType == PCIBus) - { - /* Call the PCI registered function */ - return HalPciTranslateBusAddress(PCIBus, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); - } - else - { - /* Translation is easy */ - TranslatedAddress->QuadPart = BusAddress.QuadPart; - return TRUE; - } -} - -/* EOF */ diff --git a/hal/halppc/generic/cmos.c b/hal/halppc/generic/cmos.c deleted file mode 100644 index faecb99cbb5..00000000000 --- a/hal/halppc/generic/cmos.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * PROJECT: ReactOS HAL - * LICENSE: GPL - See COPYING in the top level directory - * FILE: hal/halppc/generic/cmos.c - * PURPOSE: CMOS Access Routines (Real Time Clock and LastKnownGood) - * PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org) - * Eric Kohl - */ - -/* INCLUDES ******************************************************************/ - -#include <hal.h> -#define NDEBUG -#include <debug.h> - -/* GLOBALS *******************************************************************/ - -KSPIN_LOCK HalpSystemHardwareLock; - -/* PRIVATE FUNCTIONS *********************************************************/ - -UCHAR -FORCEINLINE -HalpReadCmos(IN UCHAR Reg) -{ - /* Select the register */ - WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, Reg); - - /* Query the value */ - return READ_PORT_UCHAR(CMOS_DATA_PORT); -} - -VOID -FORCEINLINE -HalpWriteCmos(IN UCHAR Reg, - IN UCHAR Value) -{ - /* Select the register */ - WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, Reg); - - /* Write the value */ - WRITE_PORT_UCHAR(CMOS_DATA_PORT, Value); -} - -ULONG -NTAPI -HalpGetCmosData(IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Length) -{ - PUCHAR Ptr = (PUCHAR)Buffer; - ULONG Address = SlotNumber; - ULONG Len = Length; - - /* FIXME: Acquire CMOS Lock */ - - /* Do nothing if we don't have a length */ - if (!Length) return 0; - - /* Check if this is simple CMOS */ - if (!BusNumber) - { - /* Loop the buffer up to 0xFF */ - while ((Len > 0) && (Address < 0x100)) - { - /* Read the data */ - *Ptr = HalpReadCmos((UCHAR)Address); - - /* Update position and length */ - Ptr++; - Address++; - Len--; - } - } - else if (BusNumber == 1) - { - /* Loop the buffer up to 0xFFFF */ - while ((Len > 0) && (Address < 0x10000)) - { - /* Write the data */ - *Ptr = HalpReadCmos((UCHAR)Address); - - /* Update position and length */ - Ptr++; - Address++; - Len--; - } - } - - /* FIXME: Release the CMOS Lock */ - - /* Return length read */ - return Length - Len; -} - -ULONG -NTAPI -HalpSetCmosData(IN ULONG BusNumber, - IN ULONG SlotNumber, - IN PVOID Buffer, - IN ULONG Length) -{ - PUCHAR Ptr = (PUCHAR)Buffer; - ULONG Address = SlotNumber; - ULONG Len = Length; - - /* FIXME: Acquire CMOS Lock */ - - /* Do nothing if we don't have a length */ - if (!Length) return 0; - - /* Check if this is simple CMOS */ - if (!BusNumber) - { - /* Loop the buffer up to 0xFF */ - while ((Len > 0) && (Address < 0x100)) - { - /* Write the data */ - HalpWriteCmos((UCHAR)Address, *Ptr); - - /* Update position and length */ - Ptr++; - Address++; - Len--; - } - } - else if (BusNumber == 1) - { - /* Loop the buffer up to 0xFFFF */ - while ((Len > 0) && (Address < 0x10000)) - { - /* Write the data */ - HalpWriteCmos((UCHAR)Address, *Ptr); - - /* Update position and length */ - Ptr++; - Address++; - Len--; - } - } - - /* FIXME: Release the CMOS Lock */ - - /* Return length read */ - return Length - Len; -} - -/* PUBLIC FUNCTIONS **********************************************************/ - -/* - * @implemented - */ -ARC_STATUS -NTAPI -HalGetEnvironmentVariable(IN PCH Name, - IN USHORT ValueLength, - IN PCH Value) -{ - UCHAR Val; - - /* Only variable supported on x86 */ - if (_stricmp(Name, "LastKnownGood")) return ENOENT; - - /* FIXME: Acquire CMOS Lock */ - - /* Query the current value */ - Val = HalpReadCmos(RTC_REGISTER_B) & 0x01; - - /* FIXME: Release CMOS lock */ - - /* Check the flag */ - if (Val) - { - /* Return false */ - strncpy(Value, "FALSE", ValueLength); - } - else - { - /* Return true */ - strncpy(Value, "TRUE", ValueLength); - } - - /* Return success */ - return ESUCCESS; -} - -/* - * @implemented - */ -ARC_STATUS -NTAPI -HalSetEnvironmentVariable(IN PCH Name, - IN PCH Value) -{ - UCHAR Val; - - /* Only variable supported on x86 */ - if (_stricmp(Name, "LastKnownGood")) return ENOMEM; - - /* Check if this is true or false */ - if (!_stricmp(Value, "TRUE")) - { - /* It's true, acquire CMOS lock (FIXME) */ - - /* Read the current value and add the flag */ - Val = HalpReadCmos(RTC_REGISTER_B) | 1; - } - else if (!_stricmp(Value, "FALSE")) - { - /* It's false, acquire CMOS lock (FIXME) */ - - /* Read the current value and mask out the flag */ - Val = HalpReadCmos(RTC_REGISTER_B) & ~1; - } - else - { - /* Fail */ - return ENOMEM; - } - - /* Write new value */ - HalpWriteCmos(RTC_REGISTER_B, Val); - - /* Release the lock and return success */ - return ESUCCESS; -} - -/* - * @implemented - */ -BOOLEAN -NTAPI -HalQueryRealTimeClock(OUT PTIME_FIELDS Time) -{ - /* FIXME: Acquire CMOS Lock */ - - /* Loop while update is in progress */ - while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP); - - /* Set the time data */ - Time->Second = BCD_INT(HalpReadCmos(0)); - Time->Minute = BCD_INT(HalpReadCmos(2)); - Time->Hour = BCD_INT(HalpReadCmos(4)); - Time->Weekday = BCD_INT(HalpReadCmos(6)); - Time->Day = BCD_INT(HalpReadCmos(7)); - Time->Month = BCD_INT(HalpReadCmos(8)); - Time->Year = BCD_INT(HalpReadCmos(9)); - Time->Milliseconds = 0; - - /* FIXME: Check century byte */ - - /* Compensate for the century field */ - Time->Year += (Time->Year > 80) ? 1900: 2000; - - /* FIXME: Release CMOS Lock */ - - /* Always return TRUE */ - return TRUE; -} - -/* - * @implemented - */ -BOOLEAN -NTAPI -HalSetRealTimeClock(IN PTIME_FIELDS Time) -{ - /* FIXME: Acquire CMOS Lock */ - - /* Loop while update is in progress */ - while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP); - - /* Write time fields to CMOS RTC */ - HalpWriteCmos(0, INT_BCD(Time->Second)); - HalpWriteCmos(2, INT_BCD(Time->Minute)); - HalpWriteCmos(4, INT_BCD(Time->Hour)); - HalpWriteCmos(6, INT_BCD(Time->Weekday)); - HalpWriteCmos(7, INT_BCD(Time->Day)); - HalpWriteCmos(8, INT_BCD(Time->Month)); - HalpWriteCmos(9, INT_BCD(Time->Year % 100)); - - /* FIXME: Set the century byte */ - - /* FIXME: Release the CMOS Lock */ - - /* Always return TRUE */ - return TRUE; -} - -/* EOF */ diff --git a/hal/halppc/generic/display.c b/hal/halppc/generic/display.c deleted file mode 100644 index 846a37a1145..00000000000 --- a/hal/halppc/generic/display.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * ReactOS kernel - * Copyright (C) 1998, 1999, 2000, 2001, 2002 ReactOS Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: hal/halppc/generic/display.c - * PURPOSE: Blue screen display - * PROGRAMMER: Eric Kohl - * UPDATE HISTORY: - * Created 08/10/99 - */ - -/* - * Portions of this code are from the XFree86 Project and available from the - * following license: - * - * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- - * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the XFree86 Project shall - * not be used in advertising or otherwise to promote the sale, use or other - * dealings in this Software without prior written authorization from the - * XFree86 Project. -*/ - -/* DISPLAY OWNERSHIP - * - * So, who owns the physical display and is allowed to write to it? - * - * In MS NT, upon boot HAL owns the display. Somewhere in the boot - * sequence (haven't figured out exactly where or by who), some - * component calls HalAcquireDisplayOwnership. From that moment on, - * the display is owned by that component and is switched to graphics - * mode. The display is not supposed to return to text mode, except - * in case of a bug check. The bug check will call HalDisplayString - * to output a string to the text screen. HAL will notice that it - * currently doesn't own the display and will re-take ownership, by - * calling the callback function passed to HalAcquireDisplayOwnership. - * After the bugcheck, execution is halted. So, under NT, the only - * possible sequence of display modes is text mode -> graphics mode -> - * text mode (the latter hopefully happening very infrequently). - * - * Things are a little bit different in the current state of ReactOS. - * We want to have a functional interactive text mode. We should be - * able to switch from text mode to graphics mode when a GUI app is - * started and switch back to text mode when it's finished. Then, when - * another GUI app is started, another switch to and from graphics mode - * is possible. Also, when the system bugchecks in graphics mode we want - * to switch back to text mode to show the registers and stack trace. - * Last but not least, HalDisplayString is used a lot more in ReactOS, - * e.g. to print debug messages when the /DEBUGPORT=SCREEN boot option - * is present. - * 3 Components are involved in ReactOS: HAL, BLUE.SYS and VIDEOPRT.SYS. - * As in NT, on boot HAL owns the display. When entering the text mode - * command interpreter, BLUE.SYS kicks in. It will write directly to the - * screen, more or less behind HALs back. - * When a GUI app is started, WIN32K.SYS will open the DISPLAY device. - * This open call will end up in VIDEOPRT.SYS. That component will then - * take ownership of the display by calling HalAcquireDisplayOwnership. - * When the GUI app terminates (WIN32K.SYS will close the DISPLAY device), - * we want to give ownership of the display back to HAL. Using the - * standard exported HAL functions, that's a bit of a problem, because - * there is no function defined to do that. In NT, this is handled by - * HalDisplayString, but that solution isn't satisfactory in ReactOS, - * because HalDisplayString is (in some cases) also used to output debug - * messages. If we do it the NT way, the first debug message output while - * in graphics mode would switch the display back to text mode. - * So, instead, if HalDisplayString detects that HAL doesn't have ownership - * of the display, it doesn't do anything. - * To return ownership to HAL, a new function is exported, - * HalReleaseDisplayOwnership. This function is called by the DISPLAY - * device Close routine in VIDEOPRT.SYS. It is also called at the beginning - * of a bug check, so HalDisplayString is activated again. - * Now, while the display is in graphics mode (not owned by HAL), BLUE.SYS - * should also refrain from writing to the screen buffer. The text mode - * screen buffer might overlap the graphics mode screen buffer, so changing - * something in the text mode buffer might mess up the graphics screen. To - * allow BLUE.SYS to detect if HAL owns the display, another new function is - * exported, HalQueryDisplayOwnership. BLUE.SYS will call this function to - * check if it's allowed to touch the text mode buffer. - * - * In an ideal world, when HAL takes ownership of the display, it should set - * up the CRT using real-mode (actually V86 mode, but who cares) INT 0x10 - * calls. Unfortunately, this will require HAL to setup a real-mode interrupt - * table etc. So, we chickened out of that by having the loader set up the - * display before switching to protected mode. If HAL is given back ownership - * after a GUI app terminates, the INT 0x10 calls are made by VIDEOPRT.SYS, - * since there is already support for them via the VideoPortInt10 routine. - */ - -#include <hal.h> -#include <ppcboot.h> -#include <ppcdebug.h> - -#define NDEBUG -#include <debug.h> - -boot_infos_t PpcEarlybootInfo; - -#define SCREEN_SYNCHRONIZATION - -/* VARIABLES ****************************************************************/ - -static ULONG CursorX = 0; /* Cursor Position */ -static ULONG CursorY = 0; -static ULONG SizeX = 80; /* Display size */ -static ULONG SizeY = 25; - -static BOOLEAN DisplayInitialized = FALSE; -static BOOLEAN HalOwnsDisplay = TRUE; -static ULONG GraphVideoBuffer = 0; -static PHAL_RESET_DISPLAY_PARAMETERS HalResetDisplayParameters = NULL; - -extern UCHAR XboxFont8x16[]; -extern void SetPhys( ULONG Addr, ULONG Data ); -extern ULONG GetPhys( ULONG Addr ); -extern void SetPhysByte( ULONG Addr, ULONG Data ); - -/* PRIVATE FUNCTIONS *********************************************************/ - -VOID FASTCALL -HalClearDisplay (UCHAR CharAttribute) -{ - ULONG i; - ULONG deviceSize = - PpcEarlybootInfo.dispDeviceRowBytes * - PpcEarlybootInfo.dispDeviceRect[3]; - for(i = 0; i < deviceSize; i += sizeof(int) ) - SetPhys(GraphVideoBuffer + i, CharAttribute); - - CursorX = 0; - CursorY = 0; -} - - -/* STATIC FUNCTIONS *********************************************************/ - -VOID STATIC -HalScrollDisplay (VOID) -{ - ULONG i, deviceSize = - PpcEarlybootInfo.dispDeviceRowBytes * - PpcEarlybootInfo.dispDeviceRect[3]; - ULONG Dest = (ULONG)GraphVideoBuffer, - Src = (ULONG)(GraphVideoBuffer + (16 * PpcEarlybootInfo.dispDeviceRowBytes)); - ULONG End = (ULONG) - GraphVideoBuffer + - (PpcEarlybootInfo.dispDeviceRowBytes * - (PpcEarlybootInfo.dispDeviceRect[3]-16)); - - while( Src < End ) - { - SetPhys((ULONG)Dest, GetPhys(Src)); - Src += 4; Dest += 4; - } - - /* Clear the bottom row */ - for(i = End; i < deviceSize; i += sizeof(int) ) - SetPhys(GraphVideoBuffer + i, 1); -} - -VOID STATIC FASTCALL -HalPutCharacter (CHAR Character) -{ - WRITE_PORT_UCHAR((PVOID)0x3f8, Character); -#if 0 - int i,j,k; - ULONG Dest = - (GraphVideoBuffer + - (16 * PpcEarlybootInfo.dispDeviceRowBytes * CursorY) + - (8 * (PpcEarlybootInfo.dispDeviceDepth / 8) * CursorX)), RowDest; - UCHAR ByteToPlace; - - for( i = 0; i < 16; i++ ) { - RowDest = Dest; - for( j = 0; j < 8; j++ ) { - ByteToPlace = ((128 >> j) & (XboxFont8x16[(16 * Character) + i])) ? 0xff : 1; - for( k = 0; k < PpcEarlybootInfo.dispDeviceDepth / 8; k++, RowDest++ ) { - SetPhysByte(RowDest, ByteToPlace); - } - } - Dest += PpcEarlybootInfo.dispDeviceRowBytes; - } -#endif -} - -/* PRIVATE FUNCTIONS ********************************************************/ - -VOID FASTCALL -HalInitializeDisplay (PROS_LOADER_PARAMETER_BLOCK LoaderBlock) -/* - * FUNCTION: Initialize the display - * ARGUMENTS: - * InitParameters = Parameters setup by the boot loader - */ -{ - if (! DisplayInitialized) - { - boot_infos_t *XBootInfo = (boot_infos_t *)LoaderBlock->ArchExtra; - GraphVideoBuffer = (ULONG)XBootInfo->dispDeviceBase; - memcpy(&PpcEarlybootInfo, XBootInfo, sizeof(*XBootInfo)); - - /* Set cursor position */ - CursorX = 0; - CursorY = 0; - - SizeX = XBootInfo->dispDeviceRowBytes / XBootInfo->dispDeviceDepth; - SizeY = XBootInfo->dispDeviceRect[3] / 16; - - HalClearDisplay(1); - - DisplayInitialized = TRUE; - } -} - - -/* PUBLIC FUNCTIONS *********************************************************/ - -VOID NTAPI -HalReleaseDisplayOwnership(VOID) -/* - * FUNCTION: Release ownership of display back to HAL - */ -{ - if (HalResetDisplayParameters == NULL) - return; - - if (HalOwnsDisplay != FALSE) - return; - - HalOwnsDisplay = TRUE; - HalClearDisplay(0); -} - - -VOID NTAPI -HalAcquireDisplayOwnership(IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters) -/* - * FUNCTION: - * ARGUMENTS: - * ResetDisplayParameters = Pointer to a driver specific - * reset routine. - */ -{ - HalOwnsDisplay = FALSE; - HalResetDisplayParameters = ResetDisplayParameters; -} - -VOID NTAPI -HalDisplayString(IN PCH String) -/* - * FUNCTION: Switches the screen to HAL console mode (BSOD) if not there - * already and displays a string - * ARGUMENT: - * string = ASCII string to display - * NOTE: Use with care because there is no support for returning from BSOD - * mode - */ -{ - PCH pch; - //static KSPIN_LOCK Lock; - KIRQL OldIrql; - BOOLEAN InterruptsEnabled = __readmsr(); - - /* See comment at top of file */ - if (! HalOwnsDisplay || ! DisplayInitialized) - { - return; - } - - pch = String; - - KeRaiseIrql(HIGH_LEVEL, &OldIrql); - //KiAcquireSpinLock(&Lock); - - _disable(); - - while (*pch != 0) - { - if (*pch == '\n') - { - CursorY++; - CursorX = 0; - } - else if (*pch == '\b') - { - if (CursorX > 0) - { - CursorX--; - } - } - else if (*pch != '\r') - { - HalPutCharacter (*pch); - CursorX++; - - if (CursorX >= SizeX) - { - CursorY++; - CursorX = 0; - } - } - - if (CursorY >= SizeY) - { - HalScrollDisplay (); - CursorY = SizeY - 1; - } - - pch++; - } - - __writemsr(InterruptsEnabled); - - //KiReleaseSpinLock(&Lock); - KeLowerIrql(OldIrql); -} - -VOID NTAPI -HalQueryDisplayParameters(OUT PULONG DispSizeX, - OUT PULONG DispSizeY, - OUT PULONG CursorPosX, - OUT PULONG CursorPosY) -{ - if (DispSizeX) - *DispSizeX = SizeX; - if (DispSizeY) - *DispSizeY = SizeY; - if (CursorPosX) - *CursorPosX = CursorX; - if (CursorPosY) - *CursorPosY = CursorY; -} - - -VOID NTAPI -HalSetDisplayParameters(IN ULONG CursorPosX, - IN ULONG CursorPosY) -{ - CursorX = (CursorPosX < SizeX) ? CursorPosX : SizeX - 1; - CursorY = (CursorPosY < SizeY) ? CursorPosY : SizeY - 1; -} - - -BOOLEAN NTAPI -HalQueryDisplayOwnership(VOID) -{ - return !HalOwnsDisplay; -} - -/* EOF */ diff --git a/hal/halppc/generic/dma.c b/hal/halppc/generic/dma.c deleted file mode 100644 index fd50a00d349..00000000000 --- a/hal/halppc/generic/dma.c +++ /dev/null @@ -1,2020 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: hal/halppc/generic/dma.c - * PURPOSE: DMA functions - * PROGRAMMERS: David Welch (welch(a)mcmail.com) - * Filip Navara (navaraf(a)reactos.com) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/** - * @page DMA Implementation Notes - * - * Concepts: - * - * - Map register - * - * Abstract encapsulation of physically contiguous buffer that resides - * in memory accessible by both the DMA device / controller and the system. - * The map registers are allocated and distributed on demand and are - * scarce resource. - * - * The actual use of map registers is to allow transfers from/to buffer - * located in physical memory at address inaccessible by the DMA device / - * controller directly. For such transfers the map register buffers - * are used as intermediate data storage. - * - * - Master adapter - * - * A container for map registers (typically corresponding to one physical - * bus connection type). There can be master adapters for 24-bit address - * ranges, 32-bit address ranges, etc. Every time a new DMA adapter is - * created it's associated with a corresponding master adapter that - * is used for any map register allocation requests. - * - * - Bus-master / Slave DMA - * - * Slave DMA is term used for DMA transfers done by the system (E)ISA - * controller as opposed to transfers mastered by the device itself - * (hence the name). - * - * For slave DMA special care is taken to actually access the system - * controller and handle the transfers. The relevant code is in - * HalpDmaInitializeEisaAdapter, HalReadDmaCounter, IoFlushAdapterBuffers - * and IoMapTransfer. - * - * Implementation: - * - * - Allocation of map registers - * - * Initial set of map registers is allocated on the system start to - * ensure that low memory won't get filled up later. Additional map - * registers are allocated as needed by HalpGrowMapBuffers. This - * routine is called on two places: - * - * - HalGetAdapter, since we're at PASSIVE_LEVEL and it's known that - * more map registers will probably be needed. - * - IoAllocateAdapterChannel (indirectly using HalpGrowMapBufferWorker - * since we're at DISPATCH_LEVEL and call HalpGrowMapBuffers directly) - * when no more map registers are free. - * - * Note that even if no more map registers can be allocated it's not - * the end of the world. The adapters waiting for free map registers - * are queued in the master adapter's queue and once one driver hands - * back it's map registers (using IoFreeMapRegisters or indirectly using - * the execution routine callback in IoAllocateAdapterChannel) the - * queue gets processed and the map registers are reassigned. - */ - -/* INCLUDES *****************************************************************/ - -#include <hal.h> -#define NDEBUG -#include <debug.h> - -static KEVENT HalpDmaLock; -static LIST_ENTRY HalpDmaAdapterList; -static PADAPTER_OBJECT HalpEisaAdapter[8]; -static BOOLEAN HalpEisaDma; -static PADAPTER_OBJECT HalpMasterAdapter; - -static const ULONG_PTR HalpEisaPortPage[8] = { - FIELD_OFFSET(DMA_PAGE, Channel0), - FIELD_OFFSET(DMA_PAGE, Channel1), - FIELD_OFFSET(DMA_PAGE, Channel2), - FIELD_OFFSET(DMA_PAGE, Channel3), - 0, - FIELD_OFFSET(DMA_PAGE, Channel5), - FIELD_OFFSET(DMA_PAGE, Channel6), - FIELD_OFFSET(DMA_PAGE, Channel7) -}; - -static DMA_OPERATIONS HalpDmaOperations = { - sizeof(DMA_OPERATIONS), - (PPUT_DMA_ADAPTER)HalPutDmaAdapter, - (PALLOCATE_COMMON_BUFFER)HalAllocateCommonBuffer, - (PFREE_COMMON_BUFFER)HalFreeCommonBuffer, - NULL, /* Initialized in HalpInitDma() */ - NULL, /* Initialized in HalpInitDma() */ - NULL, /* Initialized in HalpInitDma() */ - NULL, /* Initialized in HalpInitDma() */ - NULL, /* Initialized in HalpInitDma() */ - (PGET_DMA_ALIGNMENT)HalpDmaGetDmaAlignment, - (PREAD_DMA_COUNTER)HalReadDmaCounter, - /* FIXME: Implement the S/G funtions. */ - NULL /*(PGET_SCATTER_GATHER_LIST)HalGetScatterGatherList*/, - NULL /*(PPUT_SCATTER_GATHER_LIST)HalPutScatterGatherList*/, - NULL /*(PCALCULATE_SCATTER_GATHER_LIST_SIZE)HalCalculateScatterGatherListSize*/, - NULL /*(PBUILD_SCATTER_GATHER_LIST)HalBuildScatterGatherList*/, - NULL /*(PBUILD_MDL_FROM_SCATTER_GATHER_LIST)HalBuildMdlFromScatterGatherList*/ -}; - -#define MAX_MAP_REGISTERS 64 - -#define TAG_DMA ' AMD' - -/* FUNCTIONS *****************************************************************/ - -VOID -HalpInitDma(VOID) -{ - /* - * Initialize the DMA Operation table - */ - HalpDmaOperations.AllocateAdapterChannel = (PALLOCATE_ADAPTER_CHANNEL)IoAllocateAdapterChannel; - HalpDmaOperations.FlushAdapterBuffers = (PFLUSH_ADAPTER_BUFFERS)IoFlushAdapterBuffers; - HalpDmaOperations.FreeAdapterChannel = (PFREE_ADAPTER_CHANNEL)IoFreeAdapterChannel; - HalpDmaOperations.FreeMapRegisters = (PFREE_MAP_REGISTERS)IoFreeMapRegisters; - HalpDmaOperations.MapTransfer = (PMAP_TRANSFER)IoMapTransfer; - - /* - * Check if Extended DMA is available. We're just going to do a random - * read and write. - */ - - WRITE_PORT_UCHAR((PUCHAR)FIELD_OFFSET(EISA_CONTROL, DmaController2Pages.Channel2), 0x2A); - if (READ_PORT_UCHAR((PUCHAR)FIELD_OFFSET(EISA_CONTROL, DmaController2Pages.Channel2)) == 0x2A) - HalpEisaDma = TRUE; - - /* - * Intialize all the global variables and allocate master adapter with - * first map buffers. - */ - - InitializeListHead(&HalpDmaAdapterList); - KeInitializeEvent(&HalpDmaLock, NotificationEvent, TRUE); - - HalpMasterAdapter = HalpDmaAllocateMasterAdapter(); - - /* - * Setup the HalDispatchTable callback for creating PnP DMA adapters. It's - * used by IoGetDmaAdapter in the kernel. - */ - - HalGetDmaAdapter = HalpGetDmaAdapter; -} - -/** - * @name HalpGetAdapterMaximumPhysicalAddress - * - * Get the maximum physical address acceptable by the device represented - * by the passed DMA adapter. - */ - -PHYSICAL_ADDRESS NTAPI -HalpGetAdapterMaximumPhysicalAddress( - IN PADAPTER_OBJECT AdapterObject) -{ - PHYSICAL_ADDRESS HighestAddress; - - if (AdapterObject->MasterDevice) - { - if (AdapterObject->Dma64BitAddresses) - { - HighestAddress.QuadPart = 0xFFFFFFFFFFFFFFFFULL; - return HighestAddress; - } - else if (AdapterObject->Dma32BitAddresses) - { - HighestAddress.QuadPart = 0xFFFFFFFF; - return HighestAddress; - } - } - - HighestAddress.QuadPart = 0xFFFFFF; - return HighestAddress; -} - -/** - * @name HalpGrowMapBuffers - * - * Allocate initial, or additional, map buffers for DMA master adapter. - * - * @param MasterAdapter - * DMA master adapter to allocate buffers for. - * @param SizeOfMapBuffers - * Size of the map buffers to allocate (not including the size - * already allocated). - */ - -BOOLEAN NTAPI -HalpGrowMapBuffers( - IN PADAPTER_OBJECT AdapterObject, - IN ULONG SizeOfMapBuffers) -{ - PVOID VirtualAddress; - PHYSICAL_ADDRESS PhysicalAddress; - PHYSICAL_ADDRESS HighestAcceptableAddress; - PHYSICAL_ADDRESS LowestAcceptableAddress; - PHYSICAL_ADDRESS BoundryAddressMultiple; - KIRQL OldIrql; - ULONG MapRegisterCount; - - /* FIXME: Check if enough map register slots are available. */ - - MapRegisterCount = BYTES_TO_PAGES(SizeOfMapBuffers); - - /* - * Allocate memory for the new map registers. For 32-bit adapters we use - * two passes in order not to waste scare resource (low memory). - */ - - HighestAcceptableAddress = - HalpGetAdapterMaximumPhysicalAddress(AdapterObject); - LowestAcceptableAddress.HighPart = 0; - LowestAcceptableAddress.LowPart = - HighestAcceptableAddress.LowPart == 0xFFFFFFFF ? 0x1000000 : 0; - BoundryAddressMultiple.QuadPart = 0; - - VirtualAddress = MmAllocateContiguousMemorySpecifyCache( - MapRegisterCount << PAGE_SHIFT, LowestAcceptableAddress, - HighestAcceptableAddress, BoundryAddressMultiple, MmNonCached); - - if (VirtualAddress == NULL && LowestAcceptableAddress.LowPart != 0) - { - LowestAcceptableAddress.LowPart = 0; - VirtualAddress = MmAllocateContiguousMemorySpecifyCache( - MapRegisterCount << PAGE_SHIFT, LowestAcceptableAddress, - HighestAcceptableAddress, BoundryAddressMultiple, MmNonCached); - } - - if (VirtualAddress == NULL) - return FALSE; - - PhysicalAddress = MmGetPhysicalAddress(VirtualAddress); - - /* - * All the following must be done with the master adapter lock held - * to prevent corruption. - */ - - OldIrql = KfAcquireSpinLock(&AdapterObject->SpinLock); - - /* - * Setup map register entries for the buffer allocated. Each entry has - * a virtual and physical address and corresponds to PAGE_SIZE large - * buffer. - */ - - if (MapRegisterCount > 0) - { - PROS_MAP_REGISTER_ENTRY CurrentEntry, PreviousEntry; - - CurrentEntry = AdapterObject->MapRegisterBase + - AdapterObject->NumberOfMapRegisters; - do - { - /* - * Leave one entry free for every non-contiguous memory region - * in the map register bitmap. This ensures that we can search - * using RtlFindClearBits for contiguous map register regions. - * - * Also for non-EISA DMA leave one free entry for every 64Kb - * break, because the DMA controller can handle only coniguous - * 64Kb regions. - */ - - if (CurrentEntry != AdapterObject->MapRegisterBase) - { - PreviousEntry = CurrentEntry - 1; - if (PreviousEntry->PhysicalAddress.LowPart + PAGE_SIZE == - PhysicalAddress.LowPart) - { - if (!HalpEisaDma) - { - if ((PreviousEntry->PhysicalAddress.LowPart ^ - PhysicalAddress.LowPart) & 0xFFFF0000) - { - CurrentEntry++; - AdapterObject->NumberOfMapRegisters++; - } - } - } - else - { - CurrentEntry++; - AdapterObject->NumberOfMapRegisters++; - } - } - - RtlClearBit(AdapterObject->MapRegisters, - CurrentEntry - AdapterObject->MapRegisterBase); - CurrentEntry->VirtualAddress = VirtualAddress; - CurrentEntry->PhysicalAddress = PhysicalAddress; - - PhysicalAddress.LowPart += PAGE_SIZE; - VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE); - - CurrentEntry++; - AdapterObject->NumberOfMapRegisters++; - MapRegisterCount--; - } - while (MapRegisterCount != 0); - } - - KfReleaseSpinLock(&AdapterObject->SpinLock, OldIrql); - - return TRUE; -} - -/** - * @name HalpDmaAllocateMasterAdapter - * - * Helper routine to allocate and initialize master adapter object and it's - * associated map register buffers. - * - * @see HalpInitDma - */ - -PADAPTER_OBJECT NTAPI -HalpDmaAllocateMasterAdapter(VOID) -{ - PADAPTER_OBJECT MasterAdapter; - ULONG Size, SizeOfBitmap; - - SizeOfBitmap = MAX_MAP_REGISTERS; - Size = sizeof(ADAPTER_OBJECT); - Size += sizeof(RTL_BITMAP); - Size += (SizeOfBitmap + 7) >> 3; - - MasterAdapter = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_DMA); - if (MasterAdapter == NULL) - return NULL; - - RtlZeroMemory(MasterAdapter, Size); - - KeInitializeSpinLock(&MasterAdapter->SpinLock); - InitializeListHead(&MasterAdapter->AdapterQueue); - - MasterAdapter->MapRegisters = (PVOID)(MasterAdapter + 1); - RtlInitializeBitMap( - MasterAdapter->MapRegisters, - (PULONG)(MasterAdapter->MapRegisters + 1), - SizeOfBitmap); - RtlSetAllBits(MasterAdapter->MapRegisters); - MasterAdapter->NumberOfMapRegisters = 0; - MasterAdapter->CommittedMapRegisters = 0; - - MasterAdapter->MapRegisterBase = ExAllocatePoolWithTag( - NonPagedPool, - SizeOfBitmap * sizeof(ROS_MAP_REGISTER_ENTRY), - TAG_DMA); - if (MasterAdapter->MapRegisterBase == NULL) - { - ExFreePool(MasterAdapter); - return NULL; - } - - RtlZeroMemory(MasterAdapter->MapRegisterBase, - SizeOfBitmap * sizeof(ROS_MAP_REGISTER_ENTRY)); - if (!HalpGrowMapBuffers(MasterAdapter, 0x10000)) - { - ExFreePool(MasterAdapter); - return NULL; - } - - return MasterAdapter; -} - -/** - * @name HalpDmaAllocateChildAdapter - * - * Helper routine of HalGetAdapter. Allocate child adapter object and - * fill out some basic fields. - * - * @see HalGetAdapter - */ - -PADAPTER_OBJECT NTAPI -HalpDmaAllocateChildAdapter( - ULONG NumberOfMapRegisters, - PDEVICE_DESCRIPTION DeviceDescription) -{ - PADAPTER_OBJECT AdapterObject; - OBJECT_ATTRIBUTES ObjectAttributes; - NTSTATUS Status; - HANDLE Handle; - - InitializeObjectAttributes( - &ObjectAttributes, - NULL, - OBJ_KERNEL_HANDLE | OBJ_PERMANENT, - NULL, - NULL); - - Status = ObCreateObject( - KernelMode, - IoAdapterObjectType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(ADAPTER_OBJECT), - 0, - 0, - (PVOID)&AdapterObject); - if (!NT_SUCCESS(Status)) - return NULL; - - Status = ObReferenceObjectByPointer( - AdapterObject, - FILE_READ_DATA | FILE_WRITE_DATA, - IoAdapterObjectType, - KernelMode); - if (!NT_SUCCESS(Status)) - return NULL; - - RtlZeroMemory(AdapterObject, sizeof(ADAPTER_OBJECT)); - - Status = ObInsertObject( - AdapterObject, - NULL, - FILE_READ_DATA | FILE_WRITE_DATA, - 0, - NULL, - &Handle); - if (!NT_SUCCESS(Status)) - return NULL; - - ZwClose(Handle); - - AdapterObject->DmaHeader.Version = (USHORT)DeviceDescription->Version; - AdapterObject->DmaHeader.Size = sizeof(ADAPTER_OBJECT); - AdapterObject->DmaHeader.DmaOperations = &HalpDmaOperations; - AdapterObject->MapRegistersPerChannel = 1; - AdapterObject->Dma32BitAddresses = DeviceDescription->Dma32BitAddresses; - AdapterObject->ChannelNumber = 0xFF; - AdapterObject->MasterAdapter = HalpMasterAdapter; - KeInitializeDeviceQueue(&AdapterObject->ChannelWaitQueue); - - return AdapterObject; -} - -/** - * @name HalpDmaInitializeEisaAdapter - * - * Setup DMA modes and extended modes for (E)ISA DMA adapter object. - */ - -BOOLEAN NTAPI -HalpDmaInitializeEisaAdapter( - PADAPTER_OBJECT AdapterObject, - PDEVICE_DESCRIPTION DeviceDescription) -{ - UCHAR Controller; - DMA_MODE DmaMode = {{0 }}; - DMA_EXTENDED_MODE ExtendedMode = {{ 0 }}; - PVOID AdapterBaseVa; - - Controller = (DeviceDescription->DmaChannel & 4) ? 2 : 1; - - if (Controller == 1) - AdapterBaseVa = (PVOID)FIELD_OFFSET(EISA_CONTROL, DmaController1); - else - AdapterBaseVa = (PVOID)FIELD_OFFSET(EISA_CONTROL, DmaController2); - - AdapterObject->AdapterNumber = Controller; - AdapterObject->ChannelNumber = (UCHAR)(DeviceDescription->DmaChannel & 3); - AdapterObject->PagePort = (PUCHAR)HalpEisaPortPage[DeviceDescription->DmaChannel]; - AdapterObject->Width16Bits = FALSE; - AdapterObject->AdapterBaseVa = AdapterBaseVa; - - if (HalpEisaDma) - { - ExtendedMode.ChannelNumber = AdapterObject->ChannelNumber; - - switch (DeviceDescription->DmaSpeed) - { - case Compatible: ExtendedMode.TimingMode = COMPATIBLE_TIMING; break; - case TypeA: ExtendedMode.TimingMode = TYPE_A_TIMING; break; - case TypeB: ExtendedMode.TimingMode = TYPE_B_TIMING; break; - case TypeC: ExtendedMode.TimingMode = BURST_TIMING; break; - default: - return FALSE; - } - - switch (DeviceDescription->DmaWidth) - { - case Width8Bits: ExtendedMode.TransferSize = B_8BITS; break; - case Width16Bits: ExtendedMode.TransferSize = B_16BITS; break; - case Width32Bits: ExtendedMode.TransferSize = B_32BITS; break; - default: - return FALSE; - } - - if (Controller == 1) - WRITE_PORT_UCHAR((PUCHAR)FIELD_OFFSET(EISA_CONTROL, DmaExtendedMode1), - ExtendedMode.Byte); - else - WRITE_PORT_UCHAR((PUCHAR)FIELD_OFFSET(EISA_CONTROL, DmaExtendedMode2), - ExtendedMode.Byte); - } - else - { - /* - * Validate setup for non-busmaster DMA adapter. Secondary controller - * supports only 16-bit transfers and main controller supports only - * 8-bit transfers. Anything else is invalid. - */ - - if (!DeviceDescription->Master) - { - if (Controller == 2 && DeviceDescription->DmaWidth == Width16Bits) - AdapterObject->Width16Bits = TRUE; - else if (Controller != 1 || DeviceDescription->DmaWidth != Width8Bits) - return FALSE; - } - } - - DmaMode.Channel = AdapterObject->ChannelNumber; - DmaMode.AutoInitialize = DeviceDescription->AutoInitialize; - - /* - * Set the DMA request mode. - * - * For (E)ISA bus master devices just unmask (enable) the DMA channel - * and set it to cascade mode. Otherwise just select the right one - * bases on the passed device description. - */ - - if (DeviceDescription->Master) - { - DmaMode.RequestMode = CASCADE_REQUEST_MODE; - if (Controller == 1) - { - /* Set the Request Data */ - WRITE_PORT_UCHAR(&((PDMA1_CONTROL)AdapterBaseVa)->Mode, - DmaMode.Byte); - /* Unmask DMA Channel */ - WRITE_PORT_UCHAR(&((PDMA1_CONTROL)AdapterBaseVa)->SingleMask, - AdapterObject->ChannelNumber | DMA_CLEARMASK); - } else { - /* Set the Request Data */ - WRITE_PORT_UCHAR(&((PDMA2_CONTROL)AdapterBaseVa)->Mode, - DmaMode.Byte); - /* Unmask DMA Channel */ - WRITE_PORT_UCHAR(&((PDMA2_CONTROL)AdapterBaseVa)->SingleMask, - AdapterObject->ChannelNumber | DMA_CLEARMASK); - } - } - else - { - if (DeviceDescription->DemandMode) - DmaMode.RequestMode = DEMAND_REQUEST_MODE; - else - DmaMode.RequestMode = SINGLE_REQUEST_MODE; - } - - AdapterObject->AdapterMode = DmaMode; - - return TRUE; -} - -/** - * @name HalGetAdapter - * - * Allocate an adapter object for DMA device. - * - * @param DeviceDescription - * Structure describing the attributes of the device. - * @param NumberOfMapRegisters - * On return filled with the maximum number of map registers the - * device driver can allocate for DMA transfer operations. - * - * @return The DMA adapter on success, NULL otherwise. - * - * @implemented - */ - -PADAPTER_OBJECT NTAPI -HalGetAdapter( - PDEVICE_DESCRIPTION DeviceDescription, - PULONG NumberOfMapRegisters) -{ - PADAPTER_OBJECT AdapterObject = NULL; - PADAPTER_OBJECT MasterAdapter; - BOOLEAN EisaAdapter; - ULONG MapRegisters; - ULONG MaximumLength; - - /* Validate parameters in device description */ - if (DeviceDescription->Version > DEVICE_DESCRIPTION_VERSION2) - return NULL; - - /* - * See if we're going to use ISA/EISA DMA adapter. These adapters are - * special since they're reused. - * - * Also note that we check for channel number since there are only 8 DMA - * channels on ISA, so any request above this requires new adapter. - */ - - if (DeviceDescription->InterfaceType == Isa || !DeviceDescription->Master) - { - if (DeviceDescription->InterfaceType == Isa && - DeviceDescription->DmaChannel >= 8) - EisaAdapter = FALSE; - else - EisaAdapter = TRUE; - } - else - { - EisaAdapter = FALSE; - } - - /* - * Disallow creating adapter for ISA/EISA DMA channel 4 since it's used - * for cascading the controllers and it's not available for software use. - */ - - if (EisaAdapter && DeviceDescription->DmaChannel == 4) - return NULL; - - /* - * Calculate the number of map registers. - * - * - For EISA and PCI scatter/gather no map registers are needed. - * - For ISA slave scatter/gather one map register is needed. - * - For all other cases the number of map registers depends on - * DeviceDescription->MaximumLength. - */ - - MaximumLength = DeviceDescription->MaximumLength & MAXLONG; - if (DeviceDescription->ScatterGather && - (DeviceDescription->InterfaceType == Eisa || - DeviceDescription->InterfaceType == PCIBus)) - { - MapRegisters = 0; - } - else if (DeviceDescription->ScatterGather && - !DeviceDescription->Master) - { - MapRegisters = 1; - } - else - { - /* - * In the equation below the additional map register added by - * the "+1" accounts for the case when a transfer does not start - * at a page-aligned address. - */ - MapRegisters = BYTES_TO_PAGES(MaximumLength) + 1; - if (MapRegisters > 16) - MapRegisters = 16; - } - - /* - * Acquire the DMA lock that is used to protect adapter lists and - * EISA adapter array. - */ - - KeWaitForSingleObject(&HalpDmaLock, Executive, KernelMode, - FALSE, NULL); - - /* - * Now we must get ahold of the adapter object. For first eight ISA/EISA - * channels there are static adapter objects that are reused and updated - * on succesive HalGetAdapter calls. In other cases a new adapter object - * is always created and it's to the DMA adapter list (HalpDmaAdapterList). - */ - - if (EisaAdapter) - { - AdapterObject = HalpEisaAdapter[DeviceDescription->DmaChannel]; - if (AdapterObject != NULL) - { - if (AdapterObject->NeedsMapRegisters && - MapRegisters > AdapterObject->MapRegistersPerChannel) - AdapterObject->MapRegistersPerChannel = MapRegisters; - } - } - - if (AdapterObject == NULL) - { - AdapterObject = HalpDmaAllocateChildAdapter( - MapRegisters, DeviceDescription); - if (AdapterObject == NULL) - { - KeSetEvent(&HalpDmaLock, 0, 0); - return NULL; - } - - if (EisaAdapter) - { - HalpEisaAdapter[DeviceDescription->DmaChannel] = AdapterObject; - } - - if (MapRegisters > 0) - { - AdapterObject->NeedsMapRegisters = TRUE; - MasterAdapter = HalpMasterAdapter; - AdapterObject->MapRegistersPerChannel = MapRegisters; - - /* - * FIXME: Verify that the following makes sense. Actually - * MasterAdapter->NumberOfMapRegisters contains even the number - * of gaps, so this will not work correctly all the time. It - * doesn't matter much since it's only optimization to avoid - * queuing work items in HalAllocateAdapterChannel. - */ - - MasterAdapter->CommittedMapRegisters += MapRegisters; - if (MasterAdapter->CommittedMapRegisters > MasterAdapter->NumberOfMapRegisters) - HalpGrowMapBuffers(MasterAdapter, 0x10000); - } - else - { - AdapterObject->NeedsMapRegisters = FALSE; - if (DeviceDescription->Master) - AdapterObject->MapRegistersPerChannel = BYTES_TO_PAGES(MaximumLength) + 1; - else - AdapterObject->MapRegistersPerChannel = 1; - } - } - - if (!EisaAdapter) - InsertTailList(&HalpDmaAdapterList, &AdapterObject->AdapterList); - - /* - * Release the DMA lock. HalpDmaAdapterList and HalpEisaAdapter will - * no longer be touched, so we don't need it. - */ - - KeSetEvent(&HalpDmaLock, 0, 0); - - /* - * Setup the values in the adapter object that are common for all - * types of buses. - */ - - if (DeviceDescription->Version >= DEVICE_DESCRIPTION_VERSION1) - AdapterObject->IgnoreCount = DeviceDescription->IgnoreCount; - else - AdapterObject->IgnoreCount = 0; - - AdapterObject->Dma32BitAddresses = DeviceDescription->Dma32BitAddresses; - AdapterObject->Dma64BitAddresses = DeviceDescription->Dma64BitAddresses; - AdapterObject->ScatterGather = DeviceDescription->ScatterGather; - AdapterObject->MasterDevice = DeviceDescription->Master; - *NumberOfMapRegisters = AdapterObject->MapRegistersPerChannel; - - /* ... 13003 lines suppressed ...
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Delete Wine-specific functions (#3902)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=911fc3cf5b06610167c87…
commit 911fc3cf5b06610167c8729116131d9699fb80d2 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Sat Aug 14 10:42:02 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Aug 14 10:42:02 2021 +0900 [IMM32] Delete Wine-specific functions (#3902) We don't need Wine-specific functions for Japanese input. - Delete __wine_get_ui_window, __wine_register_window and __wine_unregister_window functions. - Modify imm32.spec. CORE-11700 --- dll/win32/imm32/imm.c | 130 --------------------------------------------- dll/win32/imm32/imm32.spec | 6 --- 2 files changed, 136 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index c3ea57fb2cd..e65b686a631 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -623,7 +623,6 @@ static CRITICAL_SECTION_DEBUG critsect_debug = 0, 0, { (DWORD_PTR)(__FILE__ ": threaddata_cs") } }; static CRITICAL_SECTION threaddata_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; -static BOOL disable_ime; static inline BOOL is_himc_ime_unicode(const InputContextData *data) { @@ -661,38 +660,6 @@ static inline CHAR *strdupWtoA( const WCHAR *str ) return ret; } -static IMMThreadData *IMM_GetThreadData(HWND hwnd, DWORD thread) -{ - IMMThreadData *data; - DWORD process; - - if (hwnd) - { - if (!(thread = GetWindowThreadProcessId(hwnd, &process))) return NULL; - if (process != GetCurrentProcessId()) return NULL; - } - else if (thread) - { - HANDLE h = OpenThread(THREAD_QUERY_INFORMATION, FALSE, thread); - if (!h) return NULL; - process = GetProcessIdOfThread(h); - CloseHandle(h); - if (process != GetCurrentProcessId()) return NULL; - } - else - thread = GetCurrentThreadId(); - - EnterCriticalSection(&threaddata_cs); - LIST_FOR_EACH_ENTRY(data, &ImmThreadDataList, IMMThreadData, entry) - if (data->threadID == thread) return data; - - data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data)); - data->threadID = thread; - list_add_head(&ImmThreadDataList,&data->entry); - TRACE("Thread Data Created (%x)\n",thread); - return data; -} - static HMODULE load_graphics_driver(void) { static const WCHAR display_device_guid_propW[] = { @@ -795,12 +762,6 @@ static ImmHkl *IMM_GetImmHkl(HKL hkl) } #undef LOAD_FUNCPTR -HWND WINAPI __wine_get_ui_window(HKL hkl) -{ - ImmHkl *immHkl = IMM_GetImmHkl(hkl); - return immHkl->UIWnd; -} - /* for posting messages as the IME */ static void ImmInternalPostIMEMessage(InputContextData *data, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -2605,97 +2566,6 @@ BOOL WINAPI ImmGetConversionStatus( return TRUE; } -static BOOL needs_ime_window(HWND hwnd) -{ - WCHAR classW[8]; - - if (GetClassNameW(hwnd, classW, ARRAY_SIZE(classW)) && !lstrcmpW(classW, szwIME)) - return FALSE; - if (GetClassLongPtrW(hwnd, GCL_STYLE) & CS_IME) return FALSE; - - return TRUE; -} - -/*********************************************************************** - * __wine_register_window (IMM32.@) - */ -BOOL WINAPI __wine_register_window(HWND hwnd) -{ - HWND new = NULL; - IMMThreadData *thread_data; - TRACE("(%p)\n", hwnd); - - if (!needs_ime_window(hwnd)) - return FALSE; - - thread_data = IMM_GetThreadData(hwnd, 0); - if (!thread_data) - return FALSE; - - if (thread_data->disableIME || disable_ime) - { - TRACE("IME for this thread is disabled\n"); - LeaveCriticalSection(&threaddata_cs); - return FALSE; - } - thread_data->windowRefs++; - TRACE("windowRefs=%u, hwndDefault=%p\n", - thread_data->windowRefs, thread_data->hwndDefault); - - /* Create default IME window */ - if (thread_data->windowRefs == 1) - { - /* Do not create the window inside of a critical section */ - LeaveCriticalSection(&threaddata_cs); - new = CreateWindowExW( 0, szwIME, szwDefaultIME, - WS_POPUP | WS_DISABLED | WS_CLIPSIBLINGS, - 0, 0, 1, 1, 0, 0, 0, 0); - /* thread_data is in the current thread so we can assume it's still valid */ - EnterCriticalSection(&threaddata_cs); - /* See if anyone beat us */ - if (thread_data->hwndDefault == NULL) - { - thread_data->hwndDefault = new; - new = NULL; - TRACE("Default is %p\n", thread_data->hwndDefault); - } - } - - LeaveCriticalSection(&threaddata_cs); - - /* Clean up an unused new window outside of the critical section */ - if (new != NULL) - DestroyWindow(new); - return TRUE; -} - -/*********************************************************************** - * __wine_unregister_window (IMM32.@) - */ -void WINAPI __wine_unregister_window(HWND hwnd) -{ - HWND to_destroy = 0; - IMMThreadData *thread_data; - TRACE("(%p)\n", hwnd); - - thread_data = IMM_GetThreadData(hwnd, 0); - if (!thread_data) return; - - thread_data->windowRefs--; - TRACE("windowRefs=%u, hwndDefault=%p\n", - thread_data->windowRefs, thread_data->hwndDefault); - - /* Destroy default IME window */ - if (thread_data->windowRefs == 0 && thread_data->hwndDefault) - { - to_destroy = thread_data->hwndDefault; - thread_data->hwndDefault = NULL; - } - LeaveCriticalSection(&threaddata_cs); - - if (to_destroy) DestroyWindow( to_destroy ); -} - /*********************************************************************** * ImmGetDefaultIMEWnd (IMM32.@) */ diff --git a/dll/win32/imm32/imm32.spec b/dll/win32/imm32/imm32.spec index 104e4242fc0..e196f08627a 100644 --- a/dll/win32/imm32/imm32.spec +++ b/dll/win32/imm32/imm32.spec @@ -113,9 +113,3 @@ @ stdcall -stub ImmWINNLSEnableIME(ptr long) @ stdcall -stub ImmWINNLSGetEnableStatus(ptr) @ stub ImmWINNLSGetIMEHotkey - -################################################################ -# Wine internal extensions -@ stdcall __wine_get_ui_window(ptr) -@ stdcall __wine_register_window(long) -@ stdcall __wine_unregister_window(long)
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Rewrite ImmGetRegisterWordStyleA/W (#3901)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=19d24143e92eb65b2a85b…
commit 19d24143e92eb65b2a85bf26c87d275b38c306d2 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Sat Aug 14 10:39:20 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Aug 14 10:39:20 2021 +0900 [IMM32] Rewrite ImmGetRegisterWordStyleA/W (#3901) - Rewrite ImmGetRegisterWordStyleA and ImmGetRegisterWordStyleW functions. - Modify win32ss/include/imetable.h. CORE-11700 --- dll/win32/imm32/imm.c | 127 +++++++++++++++++++++++++++++++++------------ win32ss/include/imetable.h | 2 +- 2 files changed, 96 insertions(+), 33 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index 29e8aba138d..c3ea57fb2cd 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -3087,26 +3087,58 @@ DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex) UINT WINAPI ImmGetRegisterWordStyleA( HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf); - if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle) + UINT iItem, ret = 0; + PIMEDPI pImeDpi; + LPSTYLEBUFA pDestA; + LPSTYLEBUFW pSrcW, pNewStylesW = NULL; + size_t cchW; + INT cchA; + + TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf); + + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) + return 0; + + if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) { - if (!is_kbd_ime_unicode(immHkl)) - return immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)lpStyleBuf); - else - { - STYLEBUFW sbw; - UINT rc; + ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf); + goto Quit; + } - rc = immHkl->pImeGetRegisterWordStyle(nItem,&sbw); - WideCharToMultiByte(CP_ACP, 0, sbw.szDescription, -1, - lpStyleBuf->szDescription, 32, NULL, NULL); - lpStyleBuf->dwStyle = sbw.dwStyle; - return rc; + if (nItem > 0) + { + pNewStylesW = Imm32HeapAlloc(0, nItem * sizeof(STYLEBUFW)); + if (!pNewStylesW) + goto Quit; + } + + ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesW); + + if (nItem > 0) + { + /* lpStyleBuf <-- pNewStylesW */ + for (iItem = 0; iItem < ret; ++iItem) + { + pSrcW = &pNewStylesW[iItem]; + pDestA = &lpStyleBuf[iItem]; + pDestA->dwStyle = pSrcW->dwStyle; + StringCchLengthW(pSrcW->szDescription, _countof(pSrcW->szDescription), &cchW); + cchA = WideCharToMultiByte(CP_ACP, MB_PRECOMPOSED, + pSrcW->szDescription, (INT)cchW, + pDestA->szDescription, _countof(pDestA->szDescription), + NULL, NULL); + if (cchA > _countof(pDestA->szDescription) - 1) + cchA = _countof(pDestA->szDescription) - 1; + pDestA->szDescription[cchA] = 0; } } - else - return 0; + +Quit: + if (pNewStylesW) + HeapFree(g_hImm32Heap, 0, pNewStylesW); + ImmUnlockImeDpi(pImeDpi); + return ret; } /*********************************************************************** @@ -3115,26 +3147,57 @@ UINT WINAPI ImmGetRegisterWordStyleA( UINT WINAPI ImmGetRegisterWordStyleW( HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %d, %p):\n", hKL, nItem, lpStyleBuf); - if (immHkl->hIME && immHkl->pImeGetRegisterWordStyle) + UINT iItem, ret = 0; + PIMEDPI pImeDpi; + LPSTYLEBUFA pSrcA, pNewStylesA = NULL; + LPSTYLEBUFW pDestW; + size_t cchA; + INT cchW; + + TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf); + + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) + return 0; + + if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) { - if (is_kbd_ime_unicode(immHkl)) - return immHkl->pImeGetRegisterWordStyle(nItem,lpStyleBuf); - else - { - STYLEBUFA sba; - UINT rc; + ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf); + goto Quit; + } - rc = immHkl->pImeGetRegisterWordStyle(nItem,(LPSTYLEBUFW)&sba); - MultiByteToWideChar(CP_ACP, 0, sba.szDescription, -1, - lpStyleBuf->szDescription, 32); - lpStyleBuf->dwStyle = sba.dwStyle; - return rc; + if (nItem > 0) + { + pNewStylesA = Imm32HeapAlloc(0, nItem * sizeof(STYLEBUFA)); + if (!pNewStylesA) + goto Quit; + } + + ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesA); + + if (nItem > 0) + { + /* lpStyleBuf <-- pNewStylesA */ + for (iItem = 0; iItem < ret; ++iItem) + { + pSrcA = &pNewStylesA[iItem]; + pDestW = &lpStyleBuf[iItem]; + pDestW->dwStyle = pSrcA->dwStyle; + StringCchLengthA(pSrcA->szDescription, _countof(pSrcA->szDescription), &cchA); + cchW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, + pSrcA->szDescription, (INT)cchA, + pDestW->szDescription, _countof(pDestW->szDescription)); + if (cchW > _countof(pDestW->szDescription) - 1) + cchW = _countof(pDestW->szDescription) - 1; + pDestW->szDescription[cchW] = 0; } } - else - return 0; + +Quit: + if (pNewStylesA) + HeapFree(g_hImm32Heap, 0, pNewStylesA); + ImmUnlockImeDpi(pImeDpi); + return ret; } /*********************************************************************** diff --git a/win32ss/include/imetable.h b/win32ss/include/imetable.h index 3bfd5c1d562..2385e812e3a 100644 --- a/win32ss/include/imetable.h +++ b/win32ss/include/imetable.h @@ -3,7 +3,7 @@ DEFINE_IME_ENTRY(BOOL, ImeInquire, (LPIMEINFO lpIMEInfo, LPVOID lpszWndClass, DW DEFINE_IME_ENTRY(DWORD, ImeConversionList, (HIMC hIMC, LPCVOID lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen, UINT uFlag), FALSE) DEFINE_IME_ENTRY(BOOL, ImeRegisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString), FALSE) DEFINE_IME_ENTRY(BOOL, ImeUnregisterWord, (LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString), FALSE) -DEFINE_IME_ENTRY(UINT, ImeGetRegisterWordStyle, (UINT nItem, LPSTYLEBUFW lpStyleBuf), FALSE) +DEFINE_IME_ENTRY(UINT, ImeGetRegisterWordStyle, (UINT nItem, LPVOID lpStyleBuf), FALSE) DEFINE_IME_ENTRY(UINT, ImeEnumRegisterWord, (HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc, LPCVOID lpszReading, DWORD dwStyle, LPCVOID lpszString, LPVOID lpData), FALSE) DEFINE_IME_ENTRY(BOOL, ImeConfigure, (HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData), FALSE) DEFINE_IME_ENTRY(BOOL, ImeDestroy, (UINT uReserved), FALSE)
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Refactor and simplify code (#3900)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1da5d7a305b023c687f29…
commit 1da5d7a305b023c687f29c0aa717e03989bf4bf4 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Sat Aug 14 10:38:06 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Aug 14 10:38:06 2021 +0900 [IMM32] Refactor and simplify code (#3900) - Add Imm32WideFromAnsi, Imm32AnsiFromWide and Imm32IsCrossThreadAccess helper functions. - Simplify the IMM32 code by using the helper functions. CORE-11700 --- dll/win32/imm32/imm.c | 211 ++++++++++++++++++++------------------------------ 1 file changed, 82 insertions(+), 129 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index 918b99502a9..29e8aba138d 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -96,6 +96,29 @@ LPVOID APIENTRY Imm32HeapAlloc(DWORD dwFlags, DWORD dwBytes) return HeapAlloc(g_hImm32Heap, dwFlags, dwBytes); } +static LPWSTR APIENTRY Imm32WideFromAnsi(LPCSTR pszA) +{ + INT cch = lstrlenA(pszA); + LPWSTR pszW = Imm32HeapAlloc(0, (cch + 1) * sizeof(WCHAR)); + if (pszW == NULL) + return NULL; + cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszA, cch, pszW, cch + 1); + pszW[cch] = 0; + return pszW; +} + +static LPSTR APIENTRY Imm32AnsiFromWide(LPCWSTR pszW) +{ + INT cchW = lstrlenW(pszW); + INT cchA = (cchW + 1) * sizeof(WCHAR); + LPSTR pszA = Imm32HeapAlloc(0, cchA); + if (!pszA) + return NULL; + cchA = WideCharToMultiByte(CP_ACP, 0, pszW, cchW, pszA, cchA, NULL, NULL); + pszA[cchA] = 0; + return pszA; +} + static DWORD_PTR APIENTRY Imm32QueryWindow(HWND hWnd, DWORD Index) { return NtUserQueryWindow(hWnd, Index); @@ -112,6 +135,13 @@ static DWORD APIENTRY Imm32QueryInputContext(HIMC hIMC, DWORD dwUnknown2) return NtUserQueryInputContext(hIMC, dwUnknown2); } +static inline BOOL Imm32IsCrossThreadAccess(HIMC hIMC) +{ + DWORD dwImeThreadId = Imm32QueryInputContext(hIMC, 1); + DWORD dwThreadId = GetCurrentThreadId(); + return (dwImeThreadId != dwThreadId); +} + static DWORD APIENTRY Imm32NotifyIMEStatus(HWND hwnd, HIMC hIMC, DWORD dwConversion) { return NtUserNotifyIMEStatus(hwnd, hIMC, dwConversion); @@ -416,6 +446,9 @@ static PIMEDPI APIENTRY Ime32LoadImeDpi(HKL hKL, BOOL bLock) } } +/*********************************************************************** + * ImmLoadIME (IMM32.@) + */ BOOL WINAPI ImmLoadIME(HKL hKL) { PW32CLIENTINFO pInfo; @@ -458,6 +491,9 @@ PIMEDPI APIENTRY ImmLockOrLoadImeDpi(HKL hKL) return pImeDpi; } +/*********************************************************************** + * ImmLoadLayout (IMM32.@) + */ HKL WINAPI ImmLoadLayout(HKL hKL, PIMEINFOEX pImeInfoEx) { DWORD cbData; @@ -1113,7 +1149,6 @@ BOOL APIENTRY Imm32CleanupContext(HIMC hIMC, HKL hKL, BOOL bKeep) */ BOOL WINAPI ImmDestroyContext(HIMC hIMC) { - DWORD dwImeThreadId, dwThreadId; HKL hKL; TRACE("(%p)\n", hIMC); @@ -1121,9 +1156,7 @@ BOOL WINAPI ImmDestroyContext(HIMC hIMC) if (g_psi == NULL || !(g_psi->dwSRVIFlags & SRVINFO_IMM32)) return FALSE; - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; hKL = GetKeyboardLayout(0); @@ -1505,17 +1538,11 @@ static BOOL APIENTRY Imm32KEnglish(HIMC hIMC) static BOOL APIENTRY Imm32ProcessHotKey(HWND hWnd, HIMC hIMC, HKL hKL, DWORD dwHotKeyID) { - DWORD dwImeThreadId, dwThreadId; PIMEDPI pImeDpi; BOOL ret; - if (hIMC) - { - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) - return FALSE; - } + if (hIMC && Imm32IsCrossThreadAccess(hIMC)) + return FALSE; switch (dwHotKeyID) { @@ -1565,6 +1592,9 @@ static BOOL APIENTRY Imm32ProcessHotKey(HWND hWnd, HIMC hIMC, HKL hKL, DWORD dwH return ret; } +/*********************************************************************** + * ImmLockClientImc (IMM32.@) + */ PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc) { PCLIENTIMC pClientImc; @@ -1602,6 +1632,9 @@ PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc) return pClientImc; } +/*********************************************************************** + * ImmUnlockClientImc (IMM32.@) + */ VOID WINAPI ImmUnlockClientImc(PCLIENTIMC pClientImc) { LONG cLocks; @@ -2403,7 +2436,6 @@ BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm) /*********************************************************************** * ImmGetContext (IMM32.@) - * */ HIMC WINAPI ImmGetContext(HWND hWnd) { @@ -2443,7 +2475,6 @@ DWORD WINAPI ImmGetConversionListA( DWORD dwBufLen, UINT uFlag) { DWORD ret = 0; - INT cchA, cchW; UINT cb; LPWSTR pszSrcW = NULL; LPCANDIDATELIST pCL = NULL; @@ -2465,13 +2496,9 @@ DWORD WINAPI ImmGetConversionListA( if (pSrc) { - cchA = lstrlenA(pSrc); - cchW = cchA + 1; - pszSrcW = Imm32HeapAlloc(0, cchW * sizeof(WCHAR)); + pszSrcW = Imm32WideFromAnsi(pSrc); if (pszSrcW == NULL) goto Quit; - cchW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pSrc, cchA, pszSrcW, cchW); - pszSrcW[cchW] = 0; } cb = pImeDpi->ImeConversionList(hIMC, pszSrcW, NULL, 0, uFlag); @@ -2506,8 +2533,7 @@ DWORD WINAPI ImmGetConversionListW( DWORD dwBufLen, UINT uFlag) { DWORD ret = 0; - INT cb, cchW; - BOOL bUsedDefault; + INT cb; PIMEDPI pImeDpi; LPCANDIDATELIST pCL = NULL; LPSTR pszSrcA = NULL; @@ -2528,13 +2554,9 @@ DWORD WINAPI ImmGetConversionListW( if (pSrc) { - cchW = lstrlenW(pSrc); - cb = (cchW + 1) * 2; - pszSrcA = Imm32HeapAlloc(0, cb); + pszSrcA = Imm32AnsiFromWide(pSrc); if (pszSrcA == NULL) goto Quit; - cb = WideCharToMultiByte(CP_ACP, 0, pSrc, cchW, pszSrcA, cb, NULL, &bUsedDefault); - pszSrcA[cb] = 0; } cb = pImeDpi->ImeConversionList(hIMC, pszSrcA, NULL, 0, uFlag); @@ -3166,32 +3188,26 @@ UINT WINAPI ImmGetVirtualKey(HWND hWnd) HKL WINAPI ImmInstallIMEA( LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText) { - INT cchFileName, cchLayoutText; - LPWSTR pszFileNameW, pszLayoutTextW; - HKL hKL; + HKL hKL = NULL; + LPWSTR pszFileNameW = NULL, pszLayoutTextW = NULL; TRACE("(%s, %s)\n", debugstr_a(lpszIMEFileName), debugstr_a(lpszLayoutText)); - cchFileName = lstrlenA(lpszIMEFileName) + 1; - cchLayoutText = lstrlenA(lpszLayoutText) + 1; - - pszFileNameW = Imm32HeapAlloc(0, cchFileName * sizeof(WCHAR)); + pszFileNameW = Imm32WideFromAnsi(lpszIMEFileName); if (pszFileNameW == NULL) - return NULL; + goto Quit; - pszLayoutTextW = Imm32HeapAlloc(0, cchLayoutText * sizeof(WCHAR)); + pszLayoutTextW = Imm32WideFromAnsi(lpszLayoutText); if (pszLayoutTextW == NULL) - { - HeapFree(g_hImm32Heap, 0, pszFileNameW); - return NULL; - } - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszIMEFileName, -1, pszFileNameW, cchFileName); - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszLayoutText, -1, pszLayoutTextW, cchLayoutText); + goto Quit; hKL = ImmInstallIMEW(pszFileNameW, pszLayoutTextW); - HeapFree(g_hImm32Heap, 0, pszFileNameW); - HeapFree(g_hImm32Heap, 0, pszLayoutTextW); + +Quit: + if (pszFileNameW) + HeapFree(g_hImm32Heap, 0, pszFileNameW); + if (pszLayoutTextW) + HeapFree(g_hImm32Heap, 0, pszLayoutTextW); return hKL; } @@ -3313,20 +3329,14 @@ BOOL WINAPI ImmIsUIMessageW( BOOL WINAPI ImmNotifyIME( HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue) { - DWORD dwImeThreadId, dwThreadId; HKL hKL; PIMEDPI pImeDpi; BOOL ret; TRACE("(%p, %lu, %lu, %lu)\n", hIMC, dwAction, dwIndex, dwValue); - if (hIMC) - { - dwImeThreadId = Imm32QueryWindow(hIMC, QUERY_WINDOW_UNIQUE_THREAD_ID); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) - return FALSE; - } + if (hIMC && Imm32IsCrossThreadAccess(hIMC)) + return FALSE; hKL = GetKeyboardLayout(0); pImeDpi = ImmLockImeDpi(hKL); @@ -3347,7 +3357,6 @@ BOOL WINAPI ImmRegisterWordA( BOOL ret = FALSE; PIMEDPI pImeDpi; LPWSTR pszReadingW = NULL, pszRegisterW = NULL; - INT cch; TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister)); @@ -3365,24 +3374,16 @@ BOOL WINAPI ImmRegisterWordA( if (lpszReading) { - cch = lstrlenA(lpszReading); - pszReadingW = Imm32HeapAlloc(0, (cch + 1) * sizeof(WCHAR)); + pszReadingW = Imm32WideFromAnsi(lpszReading); if (pszReadingW == NULL) goto Quit; - cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszReading, cch, - pszReadingW, cch + 1); - pszReadingW[cch] = 0; } if (lpszRegister) { - cch = lstrlenA(lpszRegister); - pszRegisterW = Imm32HeapAlloc(0, (cch + 1) * sizeof(WCHAR)); + pszRegisterW = Imm32WideFromAnsi(lpszRegister); if (pszRegisterW == NULL) goto Quit; - cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszRegister, cch, - pszRegisterW, cch + 1); - pszRegisterW[cch] = 0; } ret = pImeDpi->ImeRegisterWord(pszReadingW, dwStyle, pszRegisterW); @@ -3405,7 +3406,6 @@ BOOL WINAPI ImmRegisterWordW( BOOL ret = FALSE; PIMEDPI pImeDpi; LPSTR pszReadingA = NULL, pszRegisterA = NULL; - INT cchW, cchA; TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister)); @@ -3423,24 +3423,16 @@ BOOL WINAPI ImmRegisterWordW( if (lpszReading) { - cchW = lstrlenW(lpszReading); - cchA = (cchW + 1) * sizeof(WCHAR); - pszReadingA = Imm32HeapAlloc(0, cchA); + pszReadingA = Imm32AnsiFromWide(lpszReading); if (!pszReadingA) goto Quit; - cchA = WideCharToMultiByte(CP_ACP, 0, lpszReading, cchW, pszReadingA, cchA, NULL, NULL); - pszReadingA[cchA] = 0; } if (lpszRegister) { - cchW = lstrlenW(lpszRegister); - cchA = (cchW + 1) * sizeof(WCHAR); - pszRegisterA = Imm32HeapAlloc(0, cchA); + pszRegisterA = Imm32AnsiFromWide(lpszRegister); if (!pszRegisterA) goto Quit; - cchA = WideCharToMultiByte(CP_ACP, 0, lpszRegister, cchW, pszRegisterA, cchA, NULL, NULL); - pszRegisterA[cchA] = 0; } ret = pImeDpi->ImeRegisterWord(pszReadingA, dwStyle, pszRegisterA); @@ -3505,7 +3497,6 @@ BOOL WINAPI ImmSetCandidateWindow( HIMC hIMC, LPCANDIDATEFORM lpCandidate) { #define MAX_CANDIDATEFORM 4 - DWORD dwImeThreadId, dwThreadId; HWND hWnd; LPINPUTCONTEXT pIC; @@ -3514,9 +3505,7 @@ BOOL WINAPI ImmSetCandidateWindow( if (lpCandidate->dwIndex >= MAX_CANDIDATEFORM) return FALSE; - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pIC = ImmLockIMC(hIMC); @@ -3565,7 +3554,6 @@ static VOID APIENTRY AnsiToWideLogFont(const LOGFONTA *plfA, LPLOGFONTW plfW) BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf) { LOGFONTW lfW; - DWORD dwImeThreadId, dwThreadId; PCLIENTIMC pClientImc; BOOL bWide; LPINPUTCONTEXTDX pIC; @@ -3575,9 +3563,7 @@ BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf) TRACE("(%p, %p)\n", hIMC, lplf); - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pClientImc = ImmLockClientImc(hIMC); @@ -3625,7 +3611,6 @@ BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf) BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf) { LOGFONTA lfA; - DWORD dwImeThreadId, dwThreadId; PCLIENTIMC pClientImc; BOOL bWide; HWND hWnd; @@ -3635,9 +3620,7 @@ BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf) TRACE("(%p, %p)\n", hIMC, lplf); - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pClientImc = ImmLockClientImc(hIMC); @@ -3800,13 +3783,10 @@ BOOL WINAPI ImmSetCompositionStringW( BOOL WINAPI ImmSetCompositionWindow( HIMC hIMC, LPCOMPOSITIONFORM lpCompForm) { - DWORD dwImeThreadId, dwThreadId; LPINPUTCONTEXT pIC; HWND hWnd; - dwImeThreadId = NtUserQueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pIC = ImmLockIMC(hIMC); @@ -3833,7 +3813,7 @@ BOOL WINAPI ImmSetConversionStatus( { HKL hKL; LPINPUTCONTEXT pIC; - DWORD dwImeThreadId, dwThreadId, dwOldConversion, dwOldSentence; + DWORD dwOldConversion, dwOldSentence; BOOL fConversionChange = FALSE, fSentenceChange = FALSE; HWND hWnd; @@ -3849,9 +3829,7 @@ BOOL WINAPI ImmSetConversionStatus( } } - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pIC = ImmLockIMC(hIMC); @@ -3973,16 +3951,14 @@ VOID WINAPI ImmUnlockImeDpi(PIMEDPI pImeDpi) */ BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen) { - DWORD dwImeThreadId, dwThreadId, dwConversion; + DWORD dwConversion; LPINPUTCONTEXT pIC; HWND hWnd; BOOL bHasChange = FALSE; TRACE("(%p, %d)\n", hIMC, fOpen); - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pIC = ImmLockIMC(hIMC); @@ -4016,13 +3992,10 @@ BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos) { LPINPUTCONTEXT pIC; HWND hWnd; - DWORD dwImeThreadId, dwThreadId; TRACE("(%p, {%ld, %ld})\n", hIMC, lpptPos->x, lpptPos->y); - dwImeThreadId = Imm32QueryInputContext(hIMC, 1); - dwThreadId = GetCurrentThreadId(); - if (dwImeThreadId != dwThreadId) + if (Imm32IsCrossThreadAccess(hIMC)) return FALSE; pIC = ImmLockIMC(hIMC); @@ -4099,7 +4072,6 @@ BOOL WINAPI ImmUnregisterWordA( BOOL ret = FALSE; PIMEDPI pImeDpi; LPWSTR pszReadingW = NULL, pszUnregisterW = NULL; - INT cch; TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszUnregister)); @@ -4117,24 +4089,16 @@ BOOL WINAPI ImmUnregisterWordA( if (lpszReading) { - cch = lstrlenA(lpszReading); - pszReadingW = Imm32HeapAlloc(0, (cch + 1) * sizeof(WCHAR)); + pszReadingW = Imm32WideFromAnsi(lpszReading); if (pszReadingW == NULL) goto Quit; - cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszReading, cch, - pszReadingW, cch + 1); - pszReadingW[cch] = 0; } if (lpszUnregister) { - cch = lstrlenA(lpszUnregister); - pszUnregisterW = Imm32HeapAlloc(0, (cch + 1) * sizeof(WCHAR)); + pszUnregisterW = Imm32WideFromAnsi(lpszUnregister); if (pszUnregisterW == NULL) goto Quit; - cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszUnregister, cch, - pszUnregisterW, cch + 1); - pszUnregisterW[cch] = 0; } ret = pImeDpi->ImeUnregisterWord(pszReadingW, dwStyle, pszUnregisterW); @@ -4157,7 +4121,6 @@ BOOL WINAPI ImmUnregisterWordW( BOOL ret = FALSE; PIMEDPI pImeDpi; LPSTR pszReadingA = NULL, pszUnregisterA = NULL; - INT cchW, cchA; TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszUnregister)); @@ -4175,24 +4138,16 @@ BOOL WINAPI ImmUnregisterWordW( if (lpszReading) { - cchW = lstrlenW(lpszReading); - cchA = (cchW + 1) * sizeof(WCHAR); - pszReadingA = Imm32HeapAlloc(0, cchA); + pszReadingA = Imm32AnsiFromWide(lpszReading); if (!pszReadingA) goto Quit; - cchA = WideCharToMultiByte(CP_ACP, 0, lpszReading, cchW, pszReadingA, cchA, NULL, NULL); - pszReadingA[cchA] = 0; } if (lpszUnregister) { - cchW = lstrlenW(lpszUnregister); - cchA = (cchW + 1) * sizeof(WCHAR); - pszUnregisterA = Imm32HeapAlloc(0, cchA); + pszUnregisterA = Imm32AnsiFromWide(lpszUnregister); if (!pszUnregisterA) goto Quit; - cchA = WideCharToMultiByte(CP_ACP, 0, lpszUnregister, cchW, pszUnregisterA, cchA, NULL, NULL); - pszUnregisterA[cchA] = 0; } ret = pImeDpi->ImeUnregisterWord(pszReadingA, dwStyle, pszUnregisterA); @@ -4660,7 +4615,6 @@ BOOL WINAPI ImmEnumInputContext(DWORD dwThreadId, IMCENUMPROC lpfn, LPARAM lPara /*********************************************************************** * ImmGetHotKey(IMM32.@) */ - BOOL WINAPI ImmGetHotKey(IN DWORD dwHotKey, OUT LPUINT lpuModifiers, @@ -4727,15 +4681,14 @@ BOOL WINAPI CtfImmIsTextFrameServiceDisabled(VOID) return FALSE; } -/*********************************************************************** - * ImmGetImeInfoEx (IMM32.@) - */ - static BOOL APIENTRY Imm32GetImeInfoEx(PIMEINFOEX pImeInfoEx, IMEINFOEXCLASS SearchType) { return NtUserGetImeInfoEx(pImeInfoEx, SearchType); } +/*********************************************************************** + * ImmGetImeInfoEx (IMM32.@) + */ BOOL WINAPI ImmGetImeInfoEx(PIMEINFOEX pImeInfoEx, IMEINFOEXCLASS SearchType,
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Rewrite ImmGetProperty (#3896)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=719823179d7d6f5028f0e…
commit 719823179d7d6f5028f0e963bd4771fd3af0f659 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Thu Aug 12 12:33:12 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Thu Aug 12 12:33:12 2021 +0900 [IMM32] Rewrite ImmGetProperty (#3896) Implementing Japanese input... CORE-11700 --- dll/win32/imm32/imm.c | 53 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index de6a0ded6f3..918b99502a9 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -3017,27 +3017,46 @@ BOOL WINAPI ImmGetOpenStatus(HIMC hIMC) */ DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex) { - DWORD rc = 0; - ImmHkl *kbd; + IMEINFOEX ImeInfoEx; + LPIMEINFO pImeInfo; + DWORD dwValue; + PIMEDPI pImeDpi = NULL; + + TRACE("(%p, %lu)\n", hKL, fdwIndex); + + if (!ImmGetImeInfoEx(&ImeInfoEx, ImeInfoExKeyboardLayout, &hKL)) + return FALSE; - TRACE("(%p, %d)\n", hKL, fdwIndex); - kbd = IMM_GetImmHkl(hKL); + if (fdwIndex == IGP_GETIMEVERSION) + return ImeInfoEx.dwImeWinVersion; - if (kbd && kbd->hIME) + if (ImeInfoEx.fLoadFlag != 2) { - switch (fdwIndex) - { - case IGP_PROPERTY: rc = kbd->imeInfo.fdwProperty; break; - case IGP_CONVERSION: rc = kbd->imeInfo.fdwConversionCaps; break; - case IGP_SENTENCE: rc = kbd->imeInfo.fdwSentenceCaps; break; - case IGP_SETCOMPSTR: rc = kbd->imeInfo.fdwSCSCaps; break; - case IGP_SELECT: rc = kbd->imeInfo.fdwSelectCaps; break; - case IGP_GETIMEVERSION: rc = IMEVER_0400; break; - case IGP_UI: rc = 0; break; - default: rc = 0; - } + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (pImeDpi == NULL) + return FALSE; + + pImeInfo = &pImeDpi->ImeInfo; } - return rc; + else + { + pImeInfo = &ImeInfoEx.ImeInfo; + } + + switch (fdwIndex) + { + case IGP_PROPERTY: dwValue = pImeInfo->fdwProperty; break; + case IGP_CONVERSION: dwValue = pImeInfo->fdwConversionCaps; break; + case IGP_SENTENCE: dwValue = pImeInfo->fdwSentenceCaps; break; + case IGP_UI: dwValue = pImeInfo->fdwUICaps; break; + case IGP_SETCOMPSTR: dwValue = pImeInfo->fdwSCSCaps; break; + case IGP_SELECT: dwValue = pImeInfo->fdwSelectCaps; break; + default: dwValue = 0; break; + } + + if (pImeDpi) + ImmUnlockImeDpi(pImeDpi); + return dwValue; } /***********************************************************************
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Rewrite ImmGetConversionListA/W (#3895)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ee22951c1a8362374fd53…
commit ee22951c1a8362374fd53c61f73c00de0dbeb4d4 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Thu Aug 12 12:32:02 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Thu Aug 12 12:32:02 2021 +0900 [IMM32] Rewrite ImmGetConversionListA/W (#3895) - Rewrite ImmGetConversionListA and ImmGetConversionListW functions. - Delete useless convert_candidatelist_AtoW and convert_candidatelist_WtoA functions. CORE-11700 --- dll/win32/imm32/imm.c | 228 ++++++++++++++++++++++---------------------------- 1 file changed, 100 insertions(+), 128 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index 50820ba5601..de6a0ded6f3 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -625,84 +625,6 @@ static inline CHAR *strdupWtoA( const WCHAR *str ) return ret; } -static DWORD convert_candidatelist_WtoA( - LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen) -{ - DWORD ret, i, len; - - ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] ); - if ( lpDst && dwBufLen > 0 ) - { - *lpDst = *lpSrc; - lpDst->dwOffset[0] = ret; - } - - for ( i = 0; i < lpSrc->dwCount; i++) - { - LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i]; - - if ( lpDst && dwBufLen > 0 ) - { - LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i]; - - len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1, - (LPSTR)dest, dwBufLen, NULL, NULL); - - if ( i + 1 < lpSrc->dwCount ) - lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(char); - dwBufLen -= len * sizeof(char); - } - else - len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)src, -1, NULL, 0, NULL, NULL); - - ret += len * sizeof(char); - } - - if ( lpDst ) - lpDst->dwSize = ret; - - return ret; -} - -static DWORD convert_candidatelist_AtoW( - LPCANDIDATELIST lpSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen) -{ - DWORD ret, i, len; - - ret = FIELD_OFFSET( CANDIDATELIST, dwOffset[lpSrc->dwCount] ); - if ( lpDst && dwBufLen > 0 ) - { - *lpDst = *lpSrc; - lpDst->dwOffset[0] = ret; - } - - for ( i = 0; i < lpSrc->dwCount; i++) - { - LPBYTE src = (LPBYTE)lpSrc + lpSrc->dwOffset[i]; - - if ( lpDst && dwBufLen > 0 ) - { - LPBYTE dest = (LPBYTE)lpDst + lpDst->dwOffset[i]; - - len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, - (LPWSTR)dest, dwBufLen); - - if ( i + 1 < lpSrc->dwCount ) - lpDst->dwOffset[i+1] = lpDst->dwOffset[i] + len * sizeof(WCHAR); - dwBufLen -= len * sizeof(WCHAR); - } - else - len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, NULL, 0); - - ret += len * sizeof(WCHAR); - } - - if ( lpDst ) - lpDst->dwSize = ret; - - return ret; -} - static IMMThreadData *IMM_GetThreadData(HWND hwnd, DWORD thread) { IMMThreadData *data; @@ -2520,34 +2442,59 @@ DWORD WINAPI ImmGetConversionListA( LPCSTR pSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen, UINT uFlag) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_a(pSrc), lpDst, - dwBufLen, uFlag); - if (immHkl->hIME && immHkl->pImeConversionList) - { - if (!is_kbd_ime_unicode(immHkl)) - return immHkl->pImeConversionList(hIMC,(LPCWSTR)pSrc,lpDst,dwBufLen,uFlag); - else - { - LPCANDIDATELIST lpwDst; - DWORD ret = 0, len; - LPWSTR pwSrc = strdupAtoW(pSrc); + DWORD ret = 0; + INT cchA, cchW; + UINT cb; + LPWSTR pszSrcW = NULL; + LPCANDIDATELIST pCL = NULL; + PIMEDPI pImeDpi; - len = immHkl->pImeConversionList(hIMC, pwSrc, NULL, 0, uFlag); - lpwDst = HeapAlloc(GetProcessHeap(), 0, len); - if ( lpwDst ) - { - immHkl->pImeConversionList(hIMC, pwSrc, lpwDst, len, uFlag); - ret = convert_candidatelist_WtoA( lpwDst, lpDst, dwBufLen); - HeapFree(GetProcessHeap(), 0, lpwDst); - } - HeapFree(GetProcessHeap(), 0, pwSrc); + TRACE("(%p, %p, %s, %p, %lu, 0x%lX)\n", hKL, hIMC, debugstr_a(pSrc), + lpDst, dwBufLen, uFlag); - return ret; - } - } - else + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (pImeDpi == NULL) return 0; + + if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) + { + ret = pImeDpi->ImeConversionList(hIMC, pSrc, lpDst, dwBufLen, uFlag); + ImmUnlockImeDpi(pImeDpi); + return ret; + } + + if (pSrc) + { + cchA = lstrlenA(pSrc); + cchW = cchA + 1; + pszSrcW = Imm32HeapAlloc(0, cchW * sizeof(WCHAR)); + if (pszSrcW == NULL) + goto Quit; + cchW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pSrc, cchA, pszSrcW, cchW); + pszSrcW[cchW] = 0; + } + + cb = pImeDpi->ImeConversionList(hIMC, pszSrcW, NULL, 0, uFlag); + if (cb == 0) + goto Quit; + + pCL = Imm32HeapAlloc(0, cb); + if (pCL == NULL) + goto Quit; + + cb = pImeDpi->ImeConversionList(hIMC, pszSrcW, pCL, cb, uFlag); + if (cb == 0) + goto Quit; + + ret = CandidateListWideToAnsi(pCL, lpDst, dwBufLen, CP_ACP); + +Quit: + if (pszSrcW) + HeapFree(g_hImm32Heap, 0, pszSrcW); + if (pCL) + HeapFree(g_hImm32Heap, 0, pCL); + ImmUnlockImeDpi(pImeDpi); + return ret; } /*********************************************************************** @@ -2558,34 +2505,59 @@ DWORD WINAPI ImmGetConversionListW( LPCWSTR pSrc, LPCANDIDATELIST lpDst, DWORD dwBufLen, UINT uFlag) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %p, %s, %p, %d, %d):\n", hKL, hIMC, debugstr_w(pSrc), lpDst, - dwBufLen, uFlag); - if (immHkl->hIME && immHkl->pImeConversionList) - { - if (is_kbd_ime_unicode(immHkl)) - return immHkl->pImeConversionList(hIMC,pSrc,lpDst,dwBufLen,uFlag); - else - { - LPCANDIDATELIST lpaDst; - DWORD ret = 0, len; - LPSTR paSrc = strdupWtoA(pSrc); + DWORD ret = 0; + INT cb, cchW; + BOOL bUsedDefault; + PIMEDPI pImeDpi; + LPCANDIDATELIST pCL = NULL; + LPSTR pszSrcA = NULL; - len = immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, NULL, 0, uFlag); - lpaDst = HeapAlloc(GetProcessHeap(), 0, len); - if ( lpaDst ) - { - immHkl->pImeConversionList(hIMC, (LPCWSTR)paSrc, lpaDst, len, uFlag); - ret = convert_candidatelist_AtoW( lpaDst, lpDst, dwBufLen); - HeapFree(GetProcessHeap(), 0, lpaDst); - } - HeapFree(GetProcessHeap(), 0, paSrc); + TRACE("(%p, %p, %s, %p, %lu, 0x%lX)\n", hKL, hIMC, debugstr_w(pSrc), + lpDst, dwBufLen, uFlag); - return ret; - } - } - else + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) return 0; + + if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) + { + ret = pImeDpi->ImeConversionList(hIMC, pSrc, lpDst, dwBufLen, uFlag); + ImmUnlockImeDpi(pImeDpi); + return ret; + } + + if (pSrc) + { + cchW = lstrlenW(pSrc); + cb = (cchW + 1) * 2; + pszSrcA = Imm32HeapAlloc(0, cb); + if (pszSrcA == NULL) + goto Quit; + cb = WideCharToMultiByte(CP_ACP, 0, pSrc, cchW, pszSrcA, cb, NULL, &bUsedDefault); + pszSrcA[cb] = 0; + } + + cb = pImeDpi->ImeConversionList(hIMC, pszSrcA, NULL, 0, uFlag); + if (cb == 0) + goto Quit; + + pCL = Imm32HeapAlloc(0, cb); + if (!pCL) + goto Quit; + + cb = pImeDpi->ImeConversionList(hIMC, pszSrcA, pCL, cb, uFlag); + if (!cb) + goto Quit; + + ret = CandidateListAnsiToWide(pCL, lpDst, dwBufLen, CP_ACP); + +Quit: + if (pszSrcA) + HeapFree(g_hImm32Heap, 0, pszSrcA); + if (pCL) + HeapFree(g_hImm32Heap, 0, pCL); + ImmUnlockImeDpi(pImeDpi); + return ret; } /***********************************************************************
3 years, 4 months
1
0
0
0
[reactos] 01/01: [IMM32] Rewrite ImmUnregisterWordW (#3894)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9b7288df782bb70c237cf…
commit 9b7288df782bb70c237cf839fbfe40f6194cf631 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Thu Aug 12 12:31:06 2021 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Thu Aug 12 12:31:06 2021 +0900 [IMM32] Rewrite ImmUnregisterWordW (#3894) Implementing Japanese input... CORE-11700 --- dll/win32/imm32/imm.c | 66 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c index a64f38246f7..50820ba5601 100644 --- a/dll/win32/imm32/imm.c +++ b/dll/win32/imm32/imm.c @@ -4163,28 +4163,56 @@ Quit: BOOL WINAPI ImmUnregisterWordW( HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister) { - ImmHkl *immHkl = IMM_GetImmHkl(hKL); - TRACE("(%p, %s, %d, %s):\n", hKL, debugstr_w(lpszReading), dwStyle, - debugstr_w(lpszUnregister)); - if (immHkl->hIME && immHkl->pImeUnregisterWord) + BOOL ret = FALSE; + PIMEDPI pImeDpi; + LPSTR pszReadingA = NULL, pszUnregisterA = NULL; + INT cchW, cchA; + + TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_w(lpszReading), dwStyle, + debugstr_w(lpszUnregister)); + + pImeDpi = ImmLockOrLoadImeDpi(hKL); + if (!pImeDpi) + return FALSE; + + if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) { - if (is_kbd_ime_unicode(immHkl)) - return immHkl->pImeUnregisterWord(lpszReading,dwStyle,lpszUnregister); - else - { - LPSTR lpszaReading = strdupWtoA(lpszReading); - LPSTR lpszaUnregister = strdupWtoA(lpszUnregister); - BOOL rc; + ret = pImeDpi->ImeUnregisterWord(lpszReading, dwStyle, lpszUnregister); + ImmUnlockImeDpi(pImeDpi); + return ret; + } - rc = immHkl->pImeUnregisterWord((LPCWSTR)lpszaReading,dwStyle, - (LPCWSTR)lpszaUnregister); - HeapFree(GetProcessHeap(),0,lpszaReading); - HeapFree(GetProcessHeap(),0,lpszaUnregister); - return rc; - } + if (lpszReading) + { + cchW = lstrlenW(lpszReading); + cchA = (cchW + 1) * sizeof(WCHAR); + pszReadingA = Imm32HeapAlloc(0, cchA); + if (!pszReadingA) + goto Quit; + cchA = WideCharToMultiByte(CP_ACP, 0, lpszReading, cchW, pszReadingA, cchA, NULL, NULL); + pszReadingA[cchA] = 0; } - else - return FALSE; + + if (lpszUnregister) + { + cchW = lstrlenW(lpszUnregister); + cchA = (cchW + 1) * sizeof(WCHAR); + pszUnregisterA = Imm32HeapAlloc(0, cchA); + if (!pszUnregisterA) + goto Quit; + cchA = WideCharToMultiByte(CP_ACP, 0, lpszUnregister, cchW, pszUnregisterA, cchA, NULL, NULL); + pszUnregisterA[cchA] = 0; + } + + ret = pImeDpi->ImeUnregisterWord(pszReadingA, dwStyle, pszUnregisterA); + +Quit: + if (pszReadingA) + HeapFree(g_hImm32Heap, 0, pszReadingA); + if (pszUnregisterA) + HeapFree(g_hImm32Heap, 0, pszUnregisterA); + ImmUnlockImeDpi(pImeDpi); + return ret; } /***********************************************************************
3 years, 4 months
1
0
0
0
← Newer
1
2
3
4
5
6
7
8
9
10
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
Results per page:
10
25
50
100
200