Index: branches/ErmaC/Trunk/Chameleon.xcodeproj/project.pbxproj =================================================================== --- branches/ErmaC/Trunk/Chameleon.xcodeproj/project.pbxproj (revision 2036) +++ branches/ErmaC/Trunk/Chameleon.xcodeproj/project.pbxproj (revision 2037) @@ -1288,13 +1288,6 @@ B0056DD911F3868000754B65 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = text_scroll_next.png; sourceTree = ""; }; B0056DDA11F3868000754B65 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = text_scroll_prev.png; sourceTree = ""; }; B0056DDB11F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = ""; }; - B0056DFD11F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; }; - B0056DFE11F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = ""; }; - B0056E0011F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; }; - B0056E0111F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = ""; }; - B0056E0311F3868000754B65 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = font_small.png; sourceTree = ""; }; - B0056E0411F3868000754B65 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; }; - B0056E0511F3868000754B65 /* theme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = theme.plist; sourceTree = ""; }; B0056E0811F3868000754B65 /* Users_Guide0.4.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Users_Guide0.4.pdf; sourceTree = ""; }; B0056E0911F3868000754B65 /* Users_Guide_v0.3.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Users_Guide_v0.3.pdf; sourceTree = ""; }; B0056E0A11F3868000754B65 /* UsersGuide-v0.2.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "UsersGuide-v0.2.pdf"; sourceTree = ""; }; @@ -1377,6 +1370,67 @@ B43E407714EE869800CD79F9 /* device_hfsplus_ml.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsplus_ml.png; sourceTree = ""; }; B43E407814EE869A00CD79F9 /* device_hfsraid_ml_o.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsraid_ml_o.png; sourceTree = ""; }; B43E407914EE869C00CD79F9 /* device_hfsraid_ml.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = device_hfsraid_ml.png; sourceTree = ""; }; + B442D9F515C216C900985ED1 /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = embed/background.png; sourceTree = ""; }; + B442D9F615C216C900985ED1 /* boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boot.png; path = embed/boot.png; sourceTree = ""; }; + B442D9F715C216C900985ED1 /* device_cdrom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_cdrom.png; path = embed/device_cdrom.png; sourceTree = ""; }; + B442D9F815C216C900985ED1 /* device_ext3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ext3.png; path = embed/device_ext3.png; sourceTree = ""; }; + B442D9F915C216C900985ED1 /* device_fat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_fat.png; path = embed/device_fat.png; sourceTree = ""; }; + B442D9FA15C216C900985ED1 /* device_generic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_generic.png; path = embed/device_generic.png; sourceTree = ""; }; + B442D9FB15C216C900985ED1 /* device_hfsplus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsplus.png; path = embed/device_hfsplus.png; sourceTree = ""; }; + B442D9FC15C216C900985ED1 /* device_hfsraid.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsraid.png; path = embed/device_hfsraid.png; sourceTree = ""; }; + B442D9FD15C216C900985ED1 /* device_ntfs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ntfs.png; path = embed/device_ntfs.png; sourceTree = ""; }; + B442D9FE15C216C900985ED1 /* device_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_next.png; path = embed/device_scroll_next.png; sourceTree = ""; }; + B442D9FF15C216C900985ED1 /* device_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_prev.png; path = embed/device_scroll_prev.png; sourceTree = ""; }; + B442DA0015C216C900985ED1 /* device_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_selection.png; path = embed/device_selection.png; sourceTree = ""; }; + B442DA0115C216C900985ED1 /* font_console.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_console.png; path = embed/font_console.png; sourceTree = ""; }; + B442DA0215C216C900985ED1 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_small.png; path = embed/font_small.png; sourceTree = ""; }; + B442DA0315C216C900985ED1 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = embed/logo.png; sourceTree = ""; }; + B442DA0415C216C900985ED1 /* menu_boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_boot.png; path = embed/menu_boot.png; sourceTree = ""; }; + B442DA0515C216C900985ED1 /* menu_help.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_help.png; path = embed/menu_help.png; sourceTree = ""; }; + B442DA0615C216C900985ED1 /* menu_ignore_caches_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches_disabled.png; path = embed/menu_ignore_caches_disabled.png; sourceTree = ""; }; + B442DA0715C216C900985ED1 /* menu_ignore_caches.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches.png; path = embed/menu_ignore_caches.png; sourceTree = ""; }; + B442DA0815C216C900985ED1 /* menu_memory_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_memory_info.png; path = embed/menu_memory_info.png; sourceTree = ""; }; + B442DA0915C216C900985ED1 /* menu_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_selection.png; path = embed/menu_selection.png; sourceTree = ""; }; + B442DA0A15C216C900985ED1 /* menu_single_user_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user_disabled.png; path = embed/menu_single_user_disabled.png; sourceTree = ""; }; + B442DA0B15C216C900985ED1 /* menu_single_user.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user.png; path = embed/menu_single_user.png; sourceTree = ""; }; + B442DA0C15C216C900985ED1 /* menu_verbose_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose_disabled.png; path = embed/menu_verbose_disabled.png; sourceTree = ""; }; + B442DA0D15C216C900985ED1 /* menu_verbose.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose.png; path = embed/menu_verbose.png; sourceTree = ""; }; + B442DA0E15C216C900985ED1 /* menu_video_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_video_info.png; path = embed/menu_video_info.png; sourceTree = ""; }; + B442DA0F15C216C900985ED1 /* progress_bar_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar_background.png; path = embed/progress_bar_background.png; sourceTree = ""; }; + B442DA1015C216C900985ED1 /* progress_bar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar.png; path = embed/progress_bar.png; sourceTree = ""; }; + B442DA1115C216C900985ED1 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_next.png; path = embed/text_scroll_next.png; sourceTree = ""; }; + B442DA1215C216C900985ED1 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_prev.png; path = embed/text_scroll_prev.png; sourceTree = ""; }; + B442DA1315C216C900985ED1 /* theme.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = theme.plist; path = embed/theme.plist; sourceTree = ""; }; + B442DA1415C216E500985ED1 /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = legacy/background.png; sourceTree = ""; }; + B442DA1515C216E500985ED1 /* boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boot.png; path = legacy/boot.png; sourceTree = ""; }; + B442DA1615C216E500985ED1 /* device_cdrom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_cdrom.png; path = legacy/device_cdrom.png; sourceTree = ""; }; + B442DA1715C216E500985ED1 /* device_ext3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ext3.png; path = legacy/device_ext3.png; sourceTree = ""; }; + B442DA1815C216E500985ED1 /* device_fat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_fat.png; path = legacy/device_fat.png; sourceTree = ""; }; + B442DA1915C216E500985ED1 /* device_generic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_generic.png; path = legacy/device_generic.png; sourceTree = ""; }; + B442DA1A15C216E500985ED1 /* device_hfsplus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_hfsplus.png; path = legacy/device_hfsplus.png; sourceTree = ""; }; + B442DA1B15C216E500985ED1 /* device_ntfs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_ntfs.png; path = legacy/device_ntfs.png; sourceTree = ""; }; + B442DA1C15C216E500985ED1 /* device_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_next.png; path = legacy/device_scroll_next.png; sourceTree = ""; }; + B442DA1D15C216E500985ED1 /* device_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_scroll_prev.png; path = legacy/device_scroll_prev.png; sourceTree = ""; }; + B442DA1E15C216E500985ED1 /* device_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = device_selection.png; path = legacy/device_selection.png; sourceTree = ""; }; + B442DA1F15C216E500985ED1 /* font_console.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_console.png; path = legacy/font_console.png; sourceTree = ""; }; + B442DA2015C216E500985ED1 /* font_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = font_small.png; path = legacy/font_small.png; sourceTree = ""; }; + B442DA2115C216E500985ED1 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = legacy/logo.png; sourceTree = ""; }; + B442DA2215C216E500985ED1 /* menu_boot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_boot.png; path = legacy/menu_boot.png; sourceTree = ""; }; + B442DA2315C216E500985ED1 /* menu_help.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_help.png; path = legacy/menu_help.png; sourceTree = ""; }; + B442DA2415C216E500985ED1 /* menu_ignore_caches_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches_disabled.png; path = legacy/menu_ignore_caches_disabled.png; sourceTree = ""; }; + B442DA2515C216E500985ED1 /* menu_ignore_caches.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_ignore_caches.png; path = legacy/menu_ignore_caches.png; sourceTree = ""; }; + B442DA2615C216E500985ED1 /* menu_memory_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_memory_info.png; path = legacy/menu_memory_info.png; sourceTree = ""; }; + B442DA2715C216E500985ED1 /* menu_selection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_selection.png; path = legacy/menu_selection.png; sourceTree = ""; }; + B442DA2815C216E500985ED1 /* menu_single_user_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user_disabled.png; path = legacy/menu_single_user_disabled.png; sourceTree = ""; }; + B442DA2915C216E500985ED1 /* menu_single_user.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_single_user.png; path = legacy/menu_single_user.png; sourceTree = ""; }; + B442DA2A15C216E500985ED1 /* menu_verbose_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose_disabled.png; path = legacy/menu_verbose_disabled.png; sourceTree = ""; }; + B442DA2B15C216E500985ED1 /* menu_verbose.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_verbose.png; path = legacy/menu_verbose.png; sourceTree = ""; }; + B442DA2C15C216E500985ED1 /* menu_video_info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = menu_video_info.png; path = legacy/menu_video_info.png; sourceTree = ""; }; + B442DA2D15C216E500985ED1 /* progress_bar_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar_background.png; path = legacy/progress_bar_background.png; sourceTree = ""; }; + B442DA2E15C216E500985ED1 /* progress_bar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = progress_bar.png; path = legacy/progress_bar.png; sourceTree = ""; }; + B442DA2F15C216E500985ED1 /* text_scroll_next.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_next.png; path = legacy/text_scroll_next.png; sourceTree = ""; }; + B442DA3015C216E500985ED1 /* text_scroll_prev.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text_scroll_prev.png; path = legacy/text_scroll_prev.png; sourceTree = ""; }; + B442DA3115C216E500985ED1 /* theme.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = theme.plist; path = legacy/theme.plist; sourceTree = ""; }; B4526097153EFCE90018E994 /* ar.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ar.po; sourceTree = ""; }; B4526098153EFCE90018E994 /* bg.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bg.po; sourceTree = ""; }; B4526099153EFCE90018E994 /* bs.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bs.po; sourceTree = ""; }; @@ -3216,15 +3270,15 @@ B0056CFC11F3868000754B65 /* graphics.c */, B0056CFD11F3868000754B65 /* graphics.h */, B0056CFE11F3868000754B65 /* gui.c */, - 6DBAFD1313B0D21E0047ED33 /* modules_support.s */, - 6DBAFD1413B0D21E0047ED33 /* modules.c */, - 6DBAFD1513B0D21E0047ED33 /* modules.h */, B0056CFF11F3868000754B65 /* gui.h */, B0056D0011F3868000754B65 /* IOHibernatePrivate.h */, B0056D0111F3868000754B65 /* lzss.c */, B0056D0211F3868000754B65 /* Makefile */, B0056D0311F3868000754B65 /* mboot.c */, B0056D0411F3868000754B65 /* mboot.h */, + 6DBAFD1313B0D21E0047ED33 /* modules_support.s */, + 6DBAFD1413B0D21E0047ED33 /* modules.c */, + 6DBAFD1513B0D21E0047ED33 /* modules.h */, B0056D0511F3868000754B65 /* multiboot.h */, B0056D0611F3868000754B65 /* options.c */, B0056D0711F3868000754B65 /* picopng.c */, @@ -3433,9 +3487,8 @@ children = ( B0056DBC11F3868000754B65 /* bullet */, B0056DDC11F3868000754B65 /* default */, - B0056DFC11F3868000754B65 /* msi_netbook */, - B0056DFF11F3868000754B65 /* pinktink */, - B0056E0211F3868000754B65 /* twilight */, + B442D9F315C2164800985ED1 /* embed */, + B442D9F415C2166000985ED1 /* legacy */, ); path = themes; sourceTree = ""; @@ -3552,34 +3605,6 @@ path = default; sourceTree = ""; }; - B0056DFC11F3868000754B65 /* msi_netbook */ = { - isa = PBXGroup; - children = ( - B0056DFD11F3868000754B65 /* logo.png */, - B0056DFE11F3868000754B65 /* theme.plist */, - ); - path = msi_netbook; - sourceTree = ""; - }; - B0056DFF11F3868000754B65 /* pinktink */ = { - isa = PBXGroup; - children = ( - B0056E0011F3868000754B65 /* logo.png */, - B0056E0111F3868000754B65 /* theme.plist */, - ); - path = pinktink; - sourceTree = ""; - }; - B0056E0211F3868000754B65 /* twilight */ = { - isa = PBXGroup; - children = ( - B0056E0311F3868000754B65 /* font_small.png */, - B0056E0411F3868000754B65 /* logo.png */, - B0056E0511F3868000754B65 /* theme.plist */, - ); - path = twilight; - sourceTree = ""; - }; B0056E0611F3868000754B65 /* doc */ = { isa = PBXGroup; children = ( @@ -3699,6 +3724,81 @@ name = lxdialog; sourceTree = ""; }; + B442D9F315C2164800985ED1 /* embed */ = { + isa = PBXGroup; + children = ( + B442D9F515C216C900985ED1 /* background.png */, + B442D9F615C216C900985ED1 /* boot.png */, + B442D9F715C216C900985ED1 /* device_cdrom.png */, + B442D9F815C216C900985ED1 /* device_ext3.png */, + B442D9F915C216C900985ED1 /* device_fat.png */, + B442D9FA15C216C900985ED1 /* device_generic.png */, + B442D9FB15C216C900985ED1 /* device_hfsplus.png */, + B442D9FC15C216C900985ED1 /* device_hfsraid.png */, + B442D9FD15C216C900985ED1 /* device_ntfs.png */, + B442D9FE15C216C900985ED1 /* device_scroll_next.png */, + B442D9FF15C216C900985ED1 /* device_scroll_prev.png */, + B442DA0015C216C900985ED1 /* device_selection.png */, + B442DA0115C216C900985ED1 /* font_console.png */, + B442DA0215C216C900985ED1 /* font_small.png */, + B442DA0315C216C900985ED1 /* logo.png */, + B442DA0415C216C900985ED1 /* menu_boot.png */, + B442DA0515C216C900985ED1 /* menu_help.png */, + B442DA0615C216C900985ED1 /* menu_ignore_caches_disabled.png */, + B442DA0715C216C900985ED1 /* menu_ignore_caches.png */, + B442DA0815C216C900985ED1 /* menu_memory_info.png */, + B442DA0915C216C900985ED1 /* menu_selection.png */, + B442DA0A15C216C900985ED1 /* menu_single_user_disabled.png */, + B442DA0B15C216C900985ED1 /* menu_single_user.png */, + B442DA0C15C216C900985ED1 /* menu_verbose_disabled.png */, + B442DA0D15C216C900985ED1 /* menu_verbose.png */, + B442DA0E15C216C900985ED1 /* menu_video_info.png */, + B442DA0F15C216C900985ED1 /* progress_bar_background.png */, + B442DA1015C216C900985ED1 /* progress_bar.png */, + B442DA1115C216C900985ED1 /* text_scroll_next.png */, + B442DA1215C216C900985ED1 /* text_scroll_prev.png */, + B442DA1315C216C900985ED1 /* theme.plist */, + ); + name = embed; + sourceTree = ""; + }; + B442D9F415C2166000985ED1 /* legacy */ = { + isa = PBXGroup; + children = ( + B442DA1415C216E500985ED1 /* background.png */, + B442DA1515C216E500985ED1 /* boot.png */, + B442DA1615C216E500985ED1 /* device_cdrom.png */, + B442DA1715C216E500985ED1 /* device_ext3.png */, + B442DA1815C216E500985ED1 /* device_fat.png */, + B442DA1915C216E500985ED1 /* device_generic.png */, + B442DA1A15C216E500985ED1 /* device_hfsplus.png */, + B442DA1B15C216E500985ED1 /* device_ntfs.png */, + B442DA1C15C216E500985ED1 /* device_scroll_next.png */, + B442DA1D15C216E500985ED1 /* device_scroll_prev.png */, + B442DA1E15C216E500985ED1 /* device_selection.png */, + B442DA1F15C216E500985ED1 /* font_console.png */, + B442DA2015C216E500985ED1 /* font_small.png */, + B442DA2115C216E500985ED1 /* logo.png */, + B442DA2215C216E500985ED1 /* menu_boot.png */, + B442DA2315C216E500985ED1 /* menu_help.png */, + B442DA2415C216E500985ED1 /* menu_ignore_caches_disabled.png */, + B442DA2515C216E500985ED1 /* menu_ignore_caches.png */, + B442DA2615C216E500985ED1 /* menu_memory_info.png */, + B442DA2715C216E500985ED1 /* menu_selection.png */, + B442DA2815C216E500985ED1 /* menu_single_user_disabled.png */, + B442DA2915C216E500985ED1 /* menu_single_user.png */, + B442DA2A15C216E500985ED1 /* menu_verbose_disabled.png */, + B442DA2B15C216E500985ED1 /* menu_verbose.png */, + B442DA2C15C216E500985ED1 /* menu_video_info.png */, + B442DA2D15C216E500985ED1 /* progress_bar_background.png */, + B442DA2E15C216E500985ED1 /* progress_bar.png */, + B442DA2F15C216E500985ED1 /* text_scroll_next.png */, + B442DA3015C216E500985ED1 /* text_scroll_prev.png */, + B442DA3115C216E500985ED1 /* theme.plist */, + ); + name = legacy; + sourceTree = ""; + }; B4526096153EFCE90018E994 /* po */ = { isa = PBXGroup; children = ( Index: branches/ErmaC/Trunk/i386/libsaio/fake_efi.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/fake_efi.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/fake_efi.h (revision 2037) @@ -1,5 +1,28 @@ /* - * Copyright 2007 David F. Elliott. All rights reserved. + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * Copyright 2007 David F. Elliott. + * All rights reserved. + * */ #ifndef __LIBSAIO_FAKE_EFI_H @@ -9,5 +32,5 @@ #define MAX_CONFIGURATION_TABLE_ENTRIES 10 extern void setupFakeEfi(void); - + #endif /* !__LIBSAIO_FAKE_EFI_H */ Index: branches/ErmaC/Trunk/i386/libsaio/xml.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/xml.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/xml.c (revision 2037) @@ -67,42 +67,46 @@ return ""; } -struct Module { - struct Module *nextModule; - long willLoad; - TagPtr dict; - char *plistAddr; - long plistLength; - char *driverPath; +struct Module +{ + struct Module *nextModule; + long willLoad; + TagPtr dict; + char * plistAddr; + long plistLength; + char * driverPath; }; typedef struct Module Module, *ModulePtr; -struct DriverInfo { - char *plistAddr; - long plistLength; - void *moduleAddr; - long moduleLength; +struct DriverInfo +{ + char * plistAddr; + long plistLength; + void * moduleAddr; + long moduleLength; }; typedef struct DriverInfo DriverInfo, *DriverInfoPtr; #define kDriverPackageSignature1 'MKXT' #define kDriverPackageSignature2 'MOSX' -struct DriversPackage { - unsigned long signature1; - unsigned long signature2; - unsigned long length; - unsigned long adler32; - unsigned long version; - unsigned long numDrivers; - unsigned long reserved1; - unsigned long reserved2; +struct DriversPackage +{ + unsigned long signature1; + unsigned long signature2; + unsigned long length; + unsigned long adler32; + unsigned long version; + unsigned long numDrivers; + unsigned long reserved1; + unsigned long reserved2; }; typedef struct DriversPackage DriversPackage; -enum { - kCFBundleType2, - kCFBundleType3 +enum +{ + kCFBundleType2, + kCFBundleType3 }; @@ -126,26 +130,33 @@ //========================================================================== // XMLGetProperty -TagPtr -XMLGetProperty( TagPtr dict, const char * key ) +TagPtr XMLGetProperty(TagPtr dict, const char * key) { - TagPtr tagList, tag; + if (dict->type != kTagTypeDict) + { + return 0; + } - if (dict->type != kTagTypeDict) return 0; - - tag = 0; - tagList = dict->tag; - while (tagList) - { - tag = tagList; - tagList = tag->tagNext; + TagPtr tag = 0; + TagPtr tagList = dict->tag; + + while (tagList) + { + tag = tagList; + tagList = tag->tagNext; - if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue; - - if (!strcmp(tag->string, key)) return tag->tag; - } - - return 0; + if ((tag->type != kTagTypeKey) || (tag->string == 0)) + { + continue; + } + + if (!strcmp(tag->string, key)) + { + return tag->tag; + } + } + + return 0; } //========================================================================== Index: branches/ErmaC/Trunk/i386/libsaio/console.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/console.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/console.c (revision 2037) @@ -69,8 +69,8 @@ struct putc_info //Azi: exists on gui.c & printf.c { - char * str; - char * last_str; + char * str; + char * last_str; }; static int @@ -83,7 +83,7 @@ return 0; } *(pi->str)++ = c; - return c; + return c; } void initBooterLog(void) @@ -91,7 +91,7 @@ msgbuf = malloc(BOOTER_LOG_SIZE); bzero(msgbuf, BOOTER_LOG_SIZE); cursor = msgbuf; - msglog("%s\n", "Enoch by ErmaC (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]"); + msglog("%s\n", "Enoch (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]"); } void msglog(const char * fmt, ...) @@ -100,10 +100,14 @@ struct putc_info pi; if (!msgbuf) + { return; + } if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) + { return; + } va_start(ap, fmt); pi.str = cursor; @@ -116,7 +120,9 @@ void setupBooterLog(void) { if (!msgbuf) + { return; + } Node *node = DT__FindNode("/", false); if (node) @@ -136,23 +142,27 @@ } if ( c == '\n' ) - { + { bios_putchar('\r'); - } + } bios_putchar(c); - return c; + return c; } int getc() { - int c = bgetc(); + int c = bgetc(); - if ((c & 0xff) == 0) - return c; - else - return (c & 0xff); + if ((c & 0xff) == 0) + { + return c; + } + else + { + return (c & 0xff); + } } // Read and echo a character from console. This doesn't echo backspace @@ -171,12 +181,16 @@ int printf(const char * fmt, ...) { - va_list ap; + va_list ap; va_start(ap, fmt); if (bootArgs->Video.v_display == VGA_TEXT_MODE) + { prf(fmt, ap, putchar, 0); + } else + { vprf(fmt, ap); + } { /* Kabyl: BooterLog */ @@ -194,7 +208,7 @@ } va_end(ap); - return 0; + return 0; } int verbose(const char * fmt, ...) @@ -202,44 +216,52 @@ va_list ap; va_start(ap, fmt); - if (gVerboseMode) - { + if (gVerboseMode) + { if (bootArgs->Video.v_display == VGA_TEXT_MODE) prf(fmt, ap, putchar, 0); else vprf(fmt, ap); - } + } { /* Kabyl: BooterLog */ struct putc_info pi; if (!msgbuf) + { return 0; + } if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) + { return 0; + } pi.str = cursor; pi.last_str = 0; prf(fmt, ap, sputc, &pi); cursor += strlen((char *)cursor); } - va_end(ap); - return(0); + va_end(ap); + return(0); } int error(const char * fmt, ...) { - va_list ap; - gErrors = true; - va_start(ap, fmt); + va_list ap; + gErrors = true; + va_start(ap, fmt); if (bootArgs->Video.v_display == VGA_TEXT_MODE) + { prf(fmt, ap, putchar, 0); - else + } + else + { vprf(fmt, ap); + } va_end(ap); - return(0); + return(0); } void stop(const char * fmt, ...) @@ -248,9 +270,12 @@ printf("\n"); va_start(ap, fmt); - if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + if (bootArgs->Video.v_display == VGA_TEXT_MODE) + { prf(fmt, ap, putchar, 0); - } else { + } + else + { vprf(fmt, ap); } va_end(ap); Index: branches/ErmaC/Trunk/i386/libsaio/xml.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/xml.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/xml.h (revision 2037) @@ -25,17 +25,18 @@ #ifndef __LIBSAIO_XML_H #define __LIBSAIO_XML_H -enum xmltype { - kTagTypeNone = 0, - kTagTypeDict, - kTagTypeKey, - kTagTypeString, - kTagTypeInteger, - kTagTypeData, - kTagTypeDate, - kTagTypeFalse, - kTagTypeTrue, - kTagTypeArray +enum xmltype +{ + kTagTypeNone = 0, + kTagTypeDict, + kTagTypeKey, + kTagTypeString, + kTagTypeInteger, + kTagTypeData, + kTagTypeDate, + kTagTypeFalse, + kTagTypeTrue, + kTagTypeArray }; struct string_ref @@ -70,11 +71,12 @@ #define kPropIONameMatch ("IONameMatch") /* -struct Tag { - long type; - char *string; - struct Tag *tag; - struct Tag *tagNext; +struct Tag +{ + long type; + char *string; + struct Tag *tag; + struct Tag *tagNext; }; typedef struct Tag Tag, *TagPtr; */ Index: branches/ErmaC/Trunk/i386/libsaio/efi.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/efi.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/efi.h (revision 2037) @@ -1,8 +1,6 @@ /* * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. * - * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -23,7 +21,6 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef _PEXPERT_I386_EFI_H @@ -71,9 +68,8 @@ */ -// // Modifiers for EFI Runtime and Boot Services -// + #define EFI_RUNTIMESERVICE #define EFIAPI #define IN @@ -82,9 +78,7 @@ #define EFI_MAX_BIT 0x80000000 -// // Set the upper bit to indicate EFI Error. -// #define EFIERR(a) (EFI_MAX_BIT | (a)) #define EFIWARN(a) (a) @@ -123,14 +117,14 @@ #define EFI_WARN_DELETE_FAILURE EFIWARN (2) #define EFI_WARN_WRITE_FAILURE EFIWARN (3) #define EFI_WARN_BUFFER_TOO_SMALL EFIWARN (4) - // // EFI Specification Revision information // #define EFI_SPECIFICATION_MAJOR_REVISION 1 #define EFI_SPECIFICATION_MINOR_REVISION 10 -typedef struct { +typedef struct +{ EFI_UINT32 Data1; EFI_UINT16 Data2; EFI_UINT16 Data3; @@ -143,7 +137,8 @@ #define EFI_GLOBAL_VARIABLE_GUID \ {0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} } -typedef union { +typedef union +{ EFI_GUID Guid; EFI_UINT8 Raw[16]; } EFI_GUID_UNION; @@ -159,7 +154,8 @@ // Nanosecond: 0 - 999,999,999 // TimeZone: -1440 to 1440 or 2047 // -typedef struct { +typedef struct +{ EFI_UINT16 Year; EFI_UINT8 Month; EFI_UINT8 Day; @@ -173,15 +169,15 @@ EFI_UINT8 Pad2; } EFI_TIME; -// + // Bit definitions for EFI_TIME.Daylight -// + #define EFI_TIME_ADJUST_DAYLIGHT 0x01 #define EFI_TIME_IN_DAYLIGHT 0x02 -// + // Value definition for EFI_TIME.TimeZone -// + #define EFI_UNSPECIFIED_TIMEZONE 0x07FF typedef enum { @@ -202,33 +198,33 @@ EfiMaxMemoryType } EFI_MEMORY_TYPE; -typedef struct { - EFI_UINT64 Signature; - EFI_UINT32 Revision; - EFI_UINT32 HeaderSize; - EFI_UINT32 CRC32; - EFI_UINT32 Reserved; +typedef struct +{ + EFI_UINT64 Signature; + EFI_UINT32 Revision; + EFI_UINT32 HeaderSize; + EFI_UINT32 CRC32; + EFI_UINT32 Reserved; } __attribute__((aligned(8))) EFI_TABLE_HEADER; -// // possible caching types for the memory range -// + #define EFI_MEMORY_UC 0x0000000000000001ULL #define EFI_MEMORY_WC 0x0000000000000002ULL #define EFI_MEMORY_WT 0x0000000000000004ULL #define EFI_MEMORY_WB 0x0000000000000008ULL #define EFI_MEMORY_UCE 0x0000000000000010ULL -// + // physical memory protection on range -// + #define EFI_MEMORY_WP 0x0000000000001000ULL #define EFI_MEMORY_RP 0x0000000000002000ULL #define EFI_MEMORY_XP 0x0000000000004000ULL -// + // range requires a runtime mapping -// + #define EFI_MEMORY_RUNTIME 0x8000000000000000ULL typedef EFI_UINT64 EFI_PHYSICAL_ADDRESS; @@ -263,9 +259,9 @@ IN OUT VOID **Address ) __attribute__((regparm(0))); -// + // Variable attributes -// + #define EFI_VARIABLE_NON_VOLATILE 0x00000001 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 @@ -302,10 +298,11 @@ IN VOID * Data ) __attribute__((regparm(0))); -// + // EFI Time -// -typedef struct { + +typedef struct +{ EFI_UINT32 Resolution; EFI_UINT32 Accuracy; EFI_BOOLEAN SetsToZero; @@ -371,18 +368,14 @@ OUT EFI_UINT32 * HighCount ) __attribute__((regparm(0))); -// // Definition of Status Code extended data header -// -// HeaderSize The size of the architecture. This is specified to enable -// the future expansion -// -// Size The size of the data in bytes. This does not include the size -// of the header structure. -// + +// HeaderSize The size of the architecture. This is specified to enable the future expansion + +// Size The size of the data in bytes. This does not include the size of the header structure. + // Type A GUID defining the type of the data -// -// + #ifdef TIANO_EXTENSION_FLAG typedef @@ -403,84 +396,77 @@ #define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552ULL #define EFI_RUNTIME_SERVICES_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION)) -typedef struct { - EFI_TABLE_HEADER Hdr; +typedef struct +{ + EFI_TABLE_HEADER Hdr; - // - // Time services - // - EFI_PTR32 GetTime; - EFI_PTR32 SetTime; - EFI_PTR32 GetWakeupTime; - EFI_PTR32 SetWakeupTime; + // Time Services + EFI_PTR32 GetTime; + EFI_PTR32 SetTime; + EFI_PTR32 GetWakeupTime; + EFI_PTR32 SetWakeupTime; - // - // Virtual memory services - // - EFI_PTR32 SetVirtualAddressMap; - EFI_PTR32 ConvertPointer; + // Virtual Memory Services - // - // Variable services - // - EFI_PTR32 GetVariable; - EFI_PTR32 GetNextVariableName; - EFI_PTR32 SetVariable; + EFI_PTR32 SetVirtualAddressMap; + EFI_PTR32 ConvertPointer; - // - // Misc - // - EFI_PTR32 GetNextHighMonotonicCount; - EFI_PTR32 ResetSystem; + // Variable Services + EFI_PTR32 GetVariable; + EFI_PTR32 GetNextVariableName; + EFI_PTR32 SetVariable; + + // Miscellaneous Services + EFI_PTR32 GetNextHighMonotonicCount; + EFI_PTR32 ResetSystem; + #ifdef TIANO_EXTENSION_FLAG - // - // //////////////////////////////////////////////////// - // Extended EFI Services - ////////////////////////////////////////////////////// - // - EFI_PTR32 ReportStatusCode; + + // //////////////////////////////////////////////////// + // Extended EFI Services + ////////////////////////////////////////////////////// + + EFI_PTR32 ReportStatusCode; #endif } __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_32; -typedef struct { - EFI_TABLE_HEADER Hdr; +typedef struct +{ + EFI_TABLE_HEADER Hdr; - // - // Time services - // - EFI_PTR64 GetTime; - EFI_PTR64 SetTime; - EFI_PTR64 GetWakeupTime; - EFI_PTR64 SetWakeupTime; - // - // Virtual memory services - // - EFI_PTR64 SetVirtualAddressMap; - EFI_PTR64 ConvertPointer; + // Time services - // - // Variable services - // - EFI_PTR64 GetVariable; - EFI_PTR64 GetNextVariableName; - EFI_PTR64 SetVariable; + EFI_PTR64 GetTime; + EFI_PTR64 SetTime; + EFI_PTR64 GetWakeupTime; + EFI_PTR64 SetWakeupTime; - // - // Misc - // - EFI_PTR64 GetNextHighMonotonicCount; - EFI_PTR64 ResetSystem; + // Virtual memory services + EFI_PTR64 SetVirtualAddressMap; + EFI_PTR64 ConvertPointer; + + // Variable services + + EFI_PTR64 GetVariable; + EFI_PTR64 GetNextVariableName; + EFI_PTR64 SetVariable; + + // Misc + + EFI_PTR64 GetNextHighMonotonicCount; + EFI_PTR64 ResetSystem; + #ifdef TIANO_EXTENSION_FLAG - // - // //////////////////////////////////////////////////// - // Extended EFI Services - ////////////////////////////////////////////////////// - // - EFI_PTR64 ReportStatusCode; + + // //////////////////////////////////////////////////// + // Extended EFI Services + ////////////////////////////////////////////////////// + + EFI_PTR64 ReportStatusCode; #endif } __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_64; @@ -488,71 +474,73 @@ // // EFI Configuration Table // -typedef struct { - EFI_GUID VendorGuid; - EFI_PTR32 VendorTable; +typedef struct +{ + EFI_GUID VendorGuid; + EFI_PTR32 VendorTable; } EFI_CONFIGURATION_TABLE_32; -typedef struct { - EFI_GUID VendorGuid; - EFI_PTR64 VendorTable; +typedef struct +{ + EFI_GUID VendorGuid; + EFI_PTR64 VendorTable; } __attribute__((aligned(8))) EFI_CONFIGURATION_TABLE_64; -// + // EFI System Table -// + #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249ULL #define EFI_SYSTEM_TABLE_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION)) #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | 00) #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | 02) #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | 10) -typedef struct EFI_SYSTEM_TABLE_32 { - EFI_TABLE_HEADER Hdr; +typedef struct EFI_SYSTEM_TABLE_32 +{ + EFI_TABLE_HEADER Hdr; - EFI_PTR32 FirmwareVendor; - EFI_UINT32 FirmwareRevision; + EFI_PTR32 FirmwareVendor; + EFI_UINT32 FirmwareRevision; - EFI_HANDLE32 ConsoleInHandle; - EFI_PTR32 ConIn; + EFI_HANDLE32 ConsoleInHandle; + EFI_PTR32 ConIn; - EFI_HANDLE32 ConsoleOutHandle; - EFI_PTR32 ConOut; + EFI_HANDLE32 ConsoleOutHandle; + EFI_PTR32 ConOut; - EFI_HANDLE32 StandardErrorHandle; - EFI_PTR32 StdErr; + EFI_HANDLE32 StandardErrorHandle; + EFI_PTR32 StdErr; - EFI_PTR32 RuntimeServices; - EFI_PTR32 BootServices; + EFI_PTR32 RuntimeServices; + EFI_PTR32 BootServices; - EFI_UINT32 NumberOfTableEntries; - EFI_PTR32 ConfigurationTable; + EFI_UINT32 NumberOfTableEntries; + EFI_PTR32 ConfigurationTable; } __attribute__((aligned(8))) EFI_SYSTEM_TABLE_32; -typedef struct EFI_SYSTEM_TABLE_64 { - EFI_TABLE_HEADER Hdr; +typedef struct EFI_SYSTEM_TABLE_64 +{ + EFI_TABLE_HEADER Hdr; - EFI_PTR64 FirmwareVendor; - EFI_UINT32 FirmwareRevision; + EFI_PTR64 FirmwareVendor; + EFI_UINT32 FirmwareRevision; - EFI_UINT32 __pad; + EFI_UINT32 __pad; + EFI_HANDLE64 ConsoleInHandle; + EFI_PTR64 ConIn; - EFI_HANDLE64 ConsoleInHandle; - EFI_PTR64 ConIn; + EFI_HANDLE64 ConsoleOutHandle; + EFI_PTR64 ConOut; - EFI_HANDLE64 ConsoleOutHandle; - EFI_PTR64 ConOut; + EFI_HANDLE64 StandardErrorHandle; + EFI_PTR64 StdErr; - EFI_HANDLE64 StandardErrorHandle; - EFI_PTR64 StdErr; + EFI_PTR64 RuntimeServices; + EFI_PTR64 BootServices; - EFI_PTR64 RuntimeServices; - EFI_PTR64 BootServices; - - EFI_UINT64 NumberOfTableEntries; - EFI_PTR64 ConfigurationTable; - + EFI_UINT64 NumberOfTableEntries; + EFI_PTR64 ConfigurationTable; } __attribute__((aligned(8))) EFI_SYSTEM_TABLE_64; #endif /* _PEXPERT_I386_EFI_H */ Index: branches/ErmaC/Trunk/i386/libsaio/vbe.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/vbe.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/vbe.c (revision 2037) @@ -29,52 +29,62 @@ #include "libsaio.h" #include "vbe.h" -/* - * Various inline routines for video I/O - */ -static inline void -outi (int port, int index, int val) +// Various inline routines for video I/O + +static biosBuf_t bb; + + +//============================================================================== + +static inline void outi(int port, int index, int val) { outw (port, (val << 8) | index); } -static inline void -outib (int port, int index, int val) + +//============================================================================== +static inline void outib(int port, int index, int val) { outb (port, index); outb (port + 1, val); } -static inline int -ini (int port, int index) + +//============================================================================== + +static inline int ini(int port, int index) { outb (port, index); return inb (port + 1); } -static inline void -rmwi (int port, int index, int clear, int set) + +//============================================================================== + +static inline void rmwi(int port, int index, int clear, int set) { outb (port, index); outb (port + 1, (inb (port + 1) & ~clear) | set); } -/* - * Globals - */ -static biosBuf_t bb; -int getVBEInfo( void * infoBlock ) +//============================================================================== + +int getVBEInfo(void * infoBlock) { bb.intno = 0x10; bb.eax.rr = funcGetControllerInfo; bb.es = SEG( infoBlock ); bb.edi.rr = OFF( infoBlock ); - bios( &bb ); + bios(&bb); + return(bb.eax.r.h); } -int getVBEModeInfo( int mode, void * minfo_p ) + +//============================================================================== + +int getVBEModeInfo(int mode, void * minfo_p) { bb.intno = 0x10; bb.eax.rr = funcGetModeInfo; @@ -82,9 +92,13 @@ bb.es = SEG(minfo_p); bb.edi.rr = OFF(minfo_p); bios(&bb); + return(bb.eax.r.h); } + +//============================================================================== + int getVBEDACFormat(unsigned char *format) { bb.intno = 0x10; @@ -95,6 +109,9 @@ return(bb.eax.r.h); } + +//============================================================================== + int setVBEDACFormat(unsigned char format) { bb.intno = 0x10; @@ -102,9 +119,11 @@ bb.ebx.r.l = subfuncSet; bb.ebx.r.h = format; bios(&bb); + return(bb.eax.r.h); } + /* * Default GTF parameter values. */ Index: branches/ErmaC/Trunk/i386/libsaio/bootstruct.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/bootstruct.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/bootstruct.h (revision 2037) @@ -62,27 +62,33 @@ /* * PCI bus information. */ -typedef struct _PCI_bus_info_t { - union { - struct { - unsigned char configMethod1 :1; - unsigned char configMethod2 :1; - unsigned char :2; - unsigned char specialCycle1 :1; - unsigned char specialCycle2 :1; - } s; - unsigned char d; - } u_bus; - unsigned char maxBusNum; - unsigned char majorVersion; - unsigned char minorVersion; - unsigned char BIOSPresent; +typedef struct _PCI_bus_info_t +{ + union + { + struct + { + unsigned char configMethod1 :1; + unsigned char configMethod2 :1; + unsigned char :2; + unsigned char specialCycle1 :1; + unsigned char specialCycle2 :1; + } s; + unsigned char d; + } u_bus; + + unsigned char maxBusNum; + unsigned char majorVersion; + unsigned char minorVersion; + unsigned char BIOSPresent; } PCI_bus_info_t; -typedef struct { - unsigned long address; // address where driver was loaded - unsigned long size; // number of bytes - unsigned long type; // driver type + +typedef struct +{ + unsigned long address; // address where driver was loaded + unsigned long size; // number of bytes + unsigned long type; // driver type } driver_config_t; /* Index: branches/ErmaC/Trunk/i386/libsaio/device_tree.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/device_tree.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/device_tree.c (revision 2037) @@ -1,31 +1,54 @@ /* - * Copyright (c) 2005 Apple Computer, Inc. All Rights Reserved. + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 2.0 (the "License"). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ */ #if 1 /* - + Structures for a Flattened Device Tree */ #define kPropNameLength 32 -typedef struct DeviceTreeNodeProperty { - char name[kPropNameLength]; // NUL terminated property name - unsigned long length; // Length (bytes) of folloing prop value +typedef struct DeviceTreeNodeProperty +{ + char name[kPropNameLength]; // NUL terminated property name + unsigned long length; // Length (bytes) of folloing prop value // unsigned long value[1]; // Variable length value of property // Padded to a multiple of a longword? } DeviceTreeNodeProperty; -typedef struct OpaqueDTEntry { - unsigned long nProperties; // Number of props[] elements (0 => end) - unsigned long nChildren; // Number of children[] elements +typedef struct OpaqueDTEntry + { + unsigned long nProperties; // Number of props[] elements (0 => end) + unsigned long nChildren; // Number of children[] elements // DeviceTreeNodeProperty props[];// array size == nProperties // DeviceTreeNode children[]; // array size == nChildren } DeviceTreeNode; typedef char DTPropertyNameBuf[32]; -/* Entry Name Definitions (Entry Names are C-Strings)*/ + +// Entry Name Definitions (Entry Names are C-Strings). enum { kDTMaxEntryNameLength = 31 /* Max length of a C-String Entry Name (terminator not included) */ }; @@ -48,490 +71,610 @@ #define RoundToLong(x) (((x) + 3) & ~3) -static struct _DTSizeInfo { - uint32_t numNodes; - uint32_t numProperties; - uint32_t totalPropertySize; +static struct _DTSizeInfo +{ + uint32_t numNodes; + uint32_t numProperties; + uint32_t totalPropertySize; } DTInfo; #define kAllocSize 4096 static Node *rootNode; -static Node *freeNodes, *allocedNodes; +static Node * freeNodes, *allocedNodes; static Property *freeProperties, *allocedProperties; -Property * -DT__AddProperty(Node *node, const char *name, uint32_t length, void *value) + +//============================================================================== + +Property * DT__AddProperty(Node *node, const char *name, uint32_t length, void *value) { - Property *prop; + Property *prop; - DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value); - if (freeProperties == NULL) { - void *buf = malloc(kAllocSize); - if (buf == 0) return 0; - int i; - DPRINTF("Allocating more free properties\n"); - bzero(buf, kAllocSize); - // Use the first property to record the allocated buffer - // for later freeing. - prop = (Property *)buf; - prop->next = allocedProperties; - allocedProperties = prop; - prop->value = buf; - prop++; - for (i=1; i<(kAllocSize / sizeof(Property)); i++) { - prop->next = freeProperties; - freeProperties = prop; - prop++; - } - } - prop = freeProperties; - freeProperties = prop->next; + DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value); - prop->name = name; - prop->length = length; - prop->value = value; + if (freeProperties == NULL) + { + void *buf = malloc(kAllocSize); + int i; - // Always add to end of list - if (node->properties == 0) { - node->properties = prop; - } else { - node->last_prop->next = prop; - } - node->last_prop = prop; - prop->next = 0; + DPRINTF("Allocating more free properties\n"); - DPRINTF("Done [0x%x]\n", prop); - - DTInfo.numProperties++; - DTInfo.totalPropertySize += RoundToLong(length); + if (buf == 0) + { + return 0; + } - return prop; + bzero(buf, kAllocSize); + // Use the first property to record the allocated buffer + // for later freeing. + prop = (Property *)buf; + prop->next = allocedProperties; + allocedProperties = prop; + prop->value = buf; + prop++; + + for (i = 1; i < (kAllocSize / sizeof(Property)); i++) + { + prop->next = freeProperties; + freeProperties = prop; + prop++; + } + } + + prop = freeProperties; + freeProperties = prop->next; + + prop->name = name; + prop->length = length; + prop->value = value; + + // Always add to end of list + if (node->properties == 0) + { + node->properties = prop; + } + else + { + node->last_prop->next = prop; + } + + node->last_prop = prop; + prop->next = 0; + + DPRINTF("Done [0x%x]\n", prop); + + DTInfo.numProperties++; + DTInfo.totalPropertySize += RoundToLong(length); + + return prop; } -Node * -DT__AddChild(Node *parent, const char *name) + +//============================================================================== + +Node * DT__AddChild(Node *parent, const char *name) { - Node *node; + Node *node; - if (freeNodes == NULL) { - void *buf = malloc(kAllocSize); - if (buf == 0) return 0; - int i; - DPRINTF("Allocating more free nodes\n"); - bzero(buf, kAllocSize); - node = (Node *)buf; - // Use the first node to record the allocated buffer - // for later freeing. - node->next = allocedNodes; - allocedNodes = node; - node->children = (Node *)buf; - node++; - for (i=1; i<(kAllocSize / sizeof(Node)); i++) { - node->next = freeNodes; - freeNodes = node; - node++; - } - } - DPRINTF("DT__AddChild(0x%x, '%s')\n", parent, name); - node = freeNodes; - freeNodes = node->next; - DPRINTF("Got free node 0x%x\n", node); - DPRINTF("prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next); + if (freeNodes == NULL) + { + void *buf = malloc(kAllocSize); - if (parent == NULL) { - rootNode = node; - node->next = 0; - } else { - node->next = parent->children; - parent->children = node; - } - DTInfo.numNodes++; - DT__AddProperty(node, "name", strlen(name) + 1, (void *) name); - return node; + if (buf == 0) + { + return 0; + } + + int i; + + DPRINTF("Allocating more free nodes\n"); + + bzero(buf, kAllocSize); + node = (Node *)buf; + + // Use the first node to record the allocated buffer for later freeing. + node->next = allocedNodes; + allocedNodes = node; + node->children = (Node *)buf; + node++; + + for (i = 1; i < (kAllocSize / sizeof(Node)); i++) + { + node->next = freeNodes; + freeNodes = node; + node++; + } + } + + DPRINTF("DT__AddChild(0x%x, '%s')\n", parent, name); + + node = freeNodes; + freeNodes = node->next; + + DPRINTF("Got free node 0x%x\n", node); + DPRINTF("prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next); + + if (parent == NULL) + { + rootNode = node; + node->next = 0; + } + else + { + node->next = parent->children; + parent->children = node; + } + + DTInfo.numNodes++; + DT__AddProperty(node, "name", strlen(name) + 1, (void *) name); + + return node; } -void -DT__FreeProperty(Property *prop) + +//============================================================================== + +void DT__FreeProperty(Property *prop) { - prop->next = freeProperties; - freeProperties = prop; + prop->next = freeProperties; + freeProperties = prop; } -void -DT__FreeNode(Node *node) + + +//============================================================================== + +void DT__FreeNode(Node *node) { - node->next = freeNodes; - freeNodes = node; + node->next = freeNodes; + freeNodes = node; } -void -DT__Initialize(void) + +//============================================================================== + +void DT__Initialize(void) { - DPRINTF("DT__Initialize\n"); - - freeNodes = 0; - allocedNodes = 0; - freeProperties = 0; - allocedProperties = 0; - - DTInfo.numNodes = 0; - DTInfo.numProperties = 0; - DTInfo.totalPropertySize = 0; - - rootNode = DT__AddChild(NULL, "/"); - DPRINTF("DT__Initialize done\n"); + DPRINTF("DT__Initialize\n"); + + freeNodes = 0; + allocedNodes = 0; + freeProperties = 0; + allocedProperties = 0; + + DTInfo.numNodes = 0; + DTInfo.numProperties = 0; + DTInfo.totalPropertySize = 0; + + rootNode = DT__AddChild(NULL, "/"); + DPRINTF("DT__Initialize done\n"); } +//============================================================================== /* - * Free up memory used by in-memory representation - * of device tree. + * Free up memory used by in-memory representation of device tree. */ -void -DT__Finalize(void) +void DT__Finalize(void) { - Node *node; - Property *prop; + Node *node; + Property *prop; - DPRINTF("DT__Finalize\n"); - for (prop = allocedProperties; prop != NULL; prop = prop->next) { - free(prop->value); - } - allocedProperties = NULL; - freeProperties = NULL; + DPRINTF("DT__Finalize\n"); - for (node = allocedNodes; node != NULL; node = node->next) { - free((void *)node->children); - } - allocedNodes = NULL; - freeNodes = NULL; - rootNode = NULL; + for (prop = allocedProperties; prop != NULL; prop = prop->next) + { + free(prop->value); + } + + allocedProperties = NULL; + freeProperties = NULL; + + for (node = allocedNodes; node != NULL; node = node->next) + { + free((void *)node->children); + } + + allocedNodes = NULL; + freeNodes = NULL; + rootNode = NULL; - // XXX leaks any created strings - - DTInfo.numNodes = 0; - DTInfo.numProperties = 0; - DTInfo.totalPropertySize = 0; + // XXX leaks any created strings + DTInfo.numNodes = 0; + DTInfo.numProperties = 0; + DTInfo.totalPropertySize = 0; } -static void * -FlattenNodes(Node *node, void *buffer) + +//============================================================================== + +static void * FlattenNodes(Node *node, void *buffer) { - Property *prop; - DeviceTreeNode *flatNode; - DeviceTreeNodeProperty *flatProp; - int count; + Property *prop; + DeviceTreeNode *flatNode; + DeviceTreeNodeProperty *flatProp; + int count; - if (node == 0) return buffer; + if (node == 0) + { + return buffer; + } - flatNode = (DeviceTreeNode *)buffer; - buffer += sizeof(DeviceTreeNode); + flatNode = (DeviceTreeNode *)buffer; + buffer += sizeof(DeviceTreeNode); - for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next) { - flatProp = (DeviceTreeNodeProperty *)buffer; - strcpy(flatProp->name, prop->name); - flatProp->length = prop->length; - buffer += sizeof(DeviceTreeNodeProperty); - bcopy(prop->value, buffer, prop->length); - buffer += RoundToLong(prop->length); - } - flatNode->nProperties = count; + for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next) + { + flatProp = (DeviceTreeNodeProperty *)buffer; + strcpy(flatProp->name, prop->name); + flatProp->length = prop->length; + buffer += sizeof(DeviceTreeNodeProperty); + bcopy(prop->value, buffer, prop->length); + buffer += RoundToLong(prop->length); + } - for (count = 0, node = node->children; node != 0; count++, node = node->next) { - buffer = FlattenNodes(node, buffer); - } - flatNode->nChildren = count; + flatNode->nProperties = count; - return buffer; + for (count = 0, node = node->children; node != 0; count++, node = node->next) + { + buffer = FlattenNodes(node, buffer); + } + + flatNode->nChildren = count; + + return buffer; } -/* - * Flatten the in-memory representation of the device tree - * into a binary DT block. + +/*============================================================================== + * Flatten the in-memory representation of the device tree into a binary DT block. * To get the buffer size needed, call with result = 0. * To have a buffer allocated for you, call with *result = 0. * To use your own buffer, call with *result = &buffer. */ -void -DT__FlattenDeviceTree(void **buffer_p, uint32_t *length) +void DT__FlattenDeviceTree(void **buffer_p, uint32_t *length) { - uint32_t totalSize; - void *buf; + uint32_t totalSize; + void * buf; - DPRINTF("DT__FlattenDeviceTree(0x%x, 0x%x)\n", buffer_p, length); + DPRINTF("DT__FlattenDeviceTree(0x%x, 0x%x)\n", buffer_p, length); + #if DEBUG - if (buffer_p) DT__PrintTree(rootNode); + if (buffer_p) + { + DT__PrintTree(rootNode); + } #endif - totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) + - DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) + - DTInfo.totalPropertySize; + totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) + DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) + DTInfo.totalPropertySize; - DPRINTF("Total size 0x%x\n", totalSize); - if (buffer_p != 0) { - if (totalSize == 0) { - buf = 0; - } else { - if (*buffer_p == 0) { - buf = malloc(totalSize); - } else { - buf = *buffer_p; - } - bzero(buf, totalSize); - - FlattenNodes(rootNode, buf); - } - *buffer_p = buf; - } - if (length) - *length = totalSize; + DPRINTF("Total size 0x%x\n", totalSize); + + if (buffer_p != 0) + { + if (totalSize == 0) + { + buf = 0; + } + else + { + if (*buffer_p == 0) + { + buf = malloc(totalSize); + } + else + { + buf = *buffer_p; + } + + bzero(buf, totalSize); + + FlattenNodes(rootNode, buf); + } + + *buffer_p = buf; + } + + if (length) + { + *length = totalSize; + } } -char * -DT__GetName(Node *node) + +//============================================================================== + +char * DT__GetName(Node *node) { - Property *prop; + Property *prop; - //DPRINTF("DT__GetName(0x%x)\n", node); - //DPRINTF("Node properties = 0x%x\n", node->properties); - for (prop = node->properties; prop; prop = prop->next) { - //DPRINTF("Prop '%s'\n", prop->name); - if (strcmp(prop->name, "name") == 0) { - return prop->value; - } - } - //DPRINTF("DT__GetName returns 0\n"); - return "(null)"; + //DPRINTF("DT__GetName(0x%x)\n", node); + //DPRINTF("Node properties = 0x%x\n", node->properties); + for (prop = node->properties; prop; prop = prop->next) + { + //DPRINTF("Prop '%s'\n", prop->name); + if (strcmp(prop->name, "name") == 0) + { + return prop->value; + } + } + + //DPRINTF("DT__GetName returns 0\n"); + return "(null)"; } -Node * -DT__FindNode(const char *path, bool createIfMissing) + +//============================================================================== + +Node * DT__FindNode(const char *path, bool createIfMissing) { - Node *node, *child; - DTPropertyNameBuf nameBuf; - char *bp; - int i; + Node *node, *child; + DTPropertyNameBuf nameBuf; + char *bp; + int i; - DPRINTF("DT__FindNode('%s', %d)\n", path, createIfMissing); + DPRINTF("DT__FindNode('%s', %d)\n", path, createIfMissing); - // Start at root - node = rootNode; - DPRINTF("root = 0x%x\n", rootNode); + // Start at root + node = rootNode; - while (node) { - // Skip leading slash - while (*path == '/') path++; + DPRINTF("root = 0x%x\n", rootNode); - for (i=0, bp = nameBuf; ++i < kDTMaxEntryNameLength && *path && *path != '/'; bp++, path++) *bp = *path; - *bp = '\0'; + while (node) + { + // Skip leading slash + while (*path == '/') + { + path++; + } - if (nameBuf[0] == '\0') { - // last path entry - break; - } - DPRINTF("Node '%s'\n", nameBuf); + for (i = 0, bp = nameBuf; ++i < kDTMaxEntryNameLength && *path && *path != '/'; bp++, path++) + { + *bp = *path; + } - for (child = node->children; child != 0; child = child->next) { - DPRINTF("Child 0x%x\n", child); - if (strcmp(DT__GetName(child), nameBuf) == 0) { - break; - } - } - if (child == 0 && createIfMissing) { - DPRINTF("Creating node\n"); - char *str = malloc(strlen(nameBuf) + 1); - // XXX this will leak - strcpy(str, nameBuf); + *bp = '\0'; - child = DT__AddChild(node, str); - } - node = child; - } - return node; + if (nameBuf[0] == '\0') + { + // last path entry + break; + } + + DPRINTF("Node '%s'\n", nameBuf); + + for (child = node->children; child != 0; child = child->next) + { + DPRINTF("Child 0x%x\n", child); + + if (strcmp(DT__GetName(child), nameBuf) == 0) + { + break; + } + } + + if (child == 0 && createIfMissing) + { + DPRINTF("Creating node\n"); + + char *str = malloc(strlen(nameBuf) + 1); + // XXX this will leak + strcpy(str, nameBuf); + + child = DT__AddChild(node, str); + } + + node = child; + } + + return node; } #if DEBUG -void -DT__PrintNode(Node *node, int level) +//============================================================================== + +void DT__PrintNode(Node *node, int level) { - char spaces[10], *cp = spaces; - Property *prop; + char spaces[10], *cp = spaces; + Property *prop; - if (level > 9) level = 9; - while (level--) *cp++ = ' '; - *cp = '\0'; + if (level > 9) + { + level = 9; + } - printf("%s===Node===\n", spaces); - for (prop = node->properties; prop; prop = prop->next) { - char c = *((char *)prop->value); - if (prop->length < 64 && ( - strcmp(prop->name, "name") == 0 || - (c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || c == '_')) { - printf("%s Property '%s' [%d] = '%s'\n", spaces, prop->name, prop->length, prop->value); - } else { - printf("%s Property '%s' [%d] = (data)\n", spaces, prop->name, prop->length); - } - } - printf("%s==========\n", spaces); + while (level--) + { + *cp++ = ' '; + } + + *cp = '\0'; + + printf("%s===Node===\n", spaces); + + for (prop = node->properties; prop; prop = prop->next) + { + char c = *((char *)prop->value); + if (prop->length < 64 && (strcmp(prop->name, "name") == 0 || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')) + { + printf("%s Property '%s' [%d] = '%s'\n", spaces, prop->name, prop->length, prop->value); + } + else + { + printf("%s Property '%s' [%d] = (data)\n", spaces, prop->name, prop->length); + } + } + + printf("%s==========\n", spaces); } -static void -_PrintTree(Node *node, int level) + +//============================================================================== + +static void _PrintTree(Node *node, int level) { - DT__PrintNode(node, level); - level++; - for (node = node->children; node; node = node->next) - _PrintTree(node, level); + DT__PrintNode(node, level); + + level++; + + for (node = node->children; node; node = node->next) + { + _PrintTree(node, level); + } } -void -DT__PrintTree(Node *node) +void DT__PrintTree(Node *node) { - if (node == 0) node = rootNode; - _PrintTree(node, 0); + if (node == 0) node = rootNode; + _PrintTree(node, 0); } -void -DT__PrintFlattenedNode(DTEntry entry, int level) +void DT__PrintFlattenedNode(DTEntry entry, int level) { - char spaces[10], *cp = spaces; - DTPropertyIterator propIter; - char *name; - void *prop; - int propSize; + char spaces[10], *cp = spaces; + DTPropertyIterator propIter; + char *name; + void *prop; + int propSize; - if (level > 9) level = 9; - while (level--) *cp++ = ' '; - *cp = '\0'; + if (level > 9) level = 9; + while (level--) *cp++ = ' '; + *cp = '\0'; - printf("%s===Entry %p===\n", spaces, entry); - if (kSuccess != DTCreatePropertyIterator(entry, &propIter)) { - printf("Couldn't create property iterator\n"); - return; - } - while( kSuccess == DTIterateProperties( propIter, &name)) { - if( kSuccess != DTGetProperty( entry, name, &prop, &propSize )) - continue; - printf("%s Property %s = %s\n", spaces, name, prop); - } - DTDisposePropertyIterator(propIter); + printf("%s===Entry %p===\n", spaces, entry); + if (kSuccess != DTCreatePropertyIterator(entry, &propIter)) + { + printf("Couldn't create property iterator\n"); + return; + } + while( kSuccess == DTIterateProperties( propIter, &name)) + { + if( kSuccess != DTGetProperty( entry, name, &prop, &propSize )) + continue; + printf("%s Property %s = %s\n", spaces, name, prop); + } + DTDisposePropertyIterator(propIter); - printf("%s==========\n", spaces); + printf("%s==========\n", spaces); } -static void -_PrintFlattenedTree(DTEntry entry, int level) +static void _PrintFlattenedTree(DTEntry entry, int level) { - DTEntryIterator entryIter; + DTEntryIterator entryIter; - PrintFlattenedNode(entry, level); + PrintFlattenedNode(entry, level); - if (kSuccess != DTCreateEntryIterator(entry, &entryIter)) { - printf("Couldn't create entry iterator\n"); - return; - } - level++; - while (kSuccess == DTIterateEntries( entryIter, &entry )) { - _PrintFlattenedTree(entry, level); - } - DTDisposeEntryIterator(entryIter); + if (kSuccess != DTCreateEntryIterator(entry, &entryIter)) + { + printf("Couldn't create entry iterator\n"); + return; + } + level++; + while (kSuccess == DTIterateEntries( entryIter, &entry )) + { + _PrintFlattenedTree(entry, level); + } + DTDisposeEntryIterator(entryIter); } -void -DT__PrintFlattenedTree(DTEntry entry) +void DT__PrintFlattenedTree(DTEntry entry) { - _PrintFlattenedTree(entry, 0); + _PrintFlattenedTree(entry, 0); } int main(int argc, char **argv) { - DTEntry dtEntry; - DTPropertyIterator propIter; - DTEntryIterator entryIter; - void *prop; - int propSize; - char *name; - void *flatTree; - uint32_t flatSize; + DTEntry dtEntry; + DTPropertyIterator propIter; + DTEntryIterator entryIter; + void *prop; + int propSize; + char *name; + void *flatTree; + uint32_t flatSize; - Node *node; + Node *node; - node = AddChild(NULL, "device-tree"); - AddProperty(node, "potato", 4, "foo"); - AddProperty(node, "chemistry", 4, "bar"); - AddProperty(node, "physics", 4, "baz"); + node = AddChild(NULL, "device-tree"); + AddProperty(node, "potato", 4, "foo"); + AddProperty(node, "chemistry", 4, "bar"); + AddProperty(node, "physics", 4, "baz"); - node = AddChild(node, "dev"); - AddProperty(node, "one", 4, "one"); - AddProperty(node, "two", 4, "two"); - AddProperty(node, "three", 6, "three"); + node = AddChild(node, "dev"); + AddProperty(node, "one", 4, "one"); + AddProperty(node, "two", 4, "two"); + AddProperty(node, "three", 6, "three"); - node = AddChild(rootNode, "foo"); - AddProperty(node, "aaa", 4, "aab"); - AddProperty(node, "bbb", 4, "bbc"); - AddProperty(node, "cccc", 6, "ccccd"); + node = AddChild(rootNode, "foo"); + AddProperty(node, "aaa", 4, "aab"); + AddProperty(node, "bbb", 4, "bbc"); + AddProperty(node, "cccc", 6, "ccccd"); - node = FindNode("/this/is/a/test", 1); - AddProperty(node, "dddd", 12, "abcdefghijk"); + node = FindNode("/this/is/a/test", 1); + AddProperty(node, "dddd", 12, "abcdefghijk"); - printf("In-memory tree:\n\n"); + printf("In-memory tree:\n\n"); - PrintTree(rootNode); + PrintTree(rootNode); - FlattenDeviceTree(&flatTree, &flatSize); + FlattenDeviceTree(&flatTree, &flatSize); - printf("Flat tree = %p, size %d\n", flatTree, flatSize); + printf("Flat tree = %p, size %d\n", flatTree, flatSize); - dtEntry = (DTEntry)flatTree; + dtEntry = (DTEntry)flatTree; - printf("\n\nPrinting flat tree\n\n"); + printf("\n\nPrinting flat tree\n\n"); - DTInit(dtEntry); + DTInit(dtEntry); - PrintFlattenedTree((DTEntry)flatTree); + PrintFlattenedTree((DTEntry)flatTree); #if 0 - printf("=== Entry %p ===\n", dtEntry); - if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) { - printf("Couldn't create property iterator\n"); - return 1; + printf("=== Entry %p ===\n", dtEntry); + if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) + { + printf("Couldn't create property iterator\n"); + return 1; + } + while( kSuccess == DTIterateProperties( propIter, &name)) + { + if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) + continue; + printf(" Property %s = %s\n", name, prop); } - while( kSuccess == DTIterateProperties( propIter, &name)) { - if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) - continue; - printf(" Property %s = %s\n", name, prop); - } - DTDisposePropertyIterator(propIter); - printf("========\n"); + DTDisposePropertyIterator(propIter); + printf("========\n"); - if (kSuccess != DTCreateEntryIterator(dtEntry, &entryIter)) { - printf("Couldn't create entry iterator\n"); - return 1; - } - while (kSuccess == DTIterateEntries( entryIter, &dtEntry )) { - printf("=== Entry %p ===\n", dtEntry); + if (kSuccess != DTCreateEntryIterator(dtEntry, &entryIter)) + { + printf("Couldn't create entry iterator\n"); + return 1; + } + while (kSuccess == DTIterateEntries( entryIter, &dtEntry )) + { + printf("=== Entry %p ===\n", dtEntry); - if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) { - printf("Couldn't create property iterator\n"); - return 1; - } - while( kSuccess == DTIterateProperties( propIter, &name)) { - if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) - continue; - printf(" Property %s = %s\n", name, prop); - } - DTDisposePropertyIterator(propIter); - printf("========\n"); - } - DTDisposeEntryIterator(entryIter); + if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) + { + printf("Couldn't create property iterator\n"); + return 1; + } + while( kSuccess == DTIterateProperties( propIter, &name)) + { + if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) + continue; + printf(" Property %s = %s\n", name, prop); + } + DTDisposePropertyIterator(propIter); + printf("========\n"); + } + DTDisposeEntryIterator(entryIter); #endif - return 0; + return 0; } #endif Index: branches/ErmaC/Trunk/i386/libsaio/hfs.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/hfs.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/hfs.c (revision 2037) @@ -77,24 +77,17 @@ #endif /* !__i386__ */ static long ReadFile(void *file, uint64_t *length, void *base, uint64_t offset); -static long GetCatalogEntryInfo(void *entry, long *flags, long *time, - FinderInfo *finderInfo, long *infoValid); -static long ResolvePathToCatalogEntry(char *filePath, long *flags, - void *entry, long dirID, long long *dirIndex); +static long GetCatalogEntryInfo(void *entry, long *flags, long *time, FinderInfo *finderInfo, long *infoValid); +static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry, long dirID, long long *dirIndex); -static long GetCatalogEntry(long long *dirIndex, char **name, - long *flags, long *time, - FinderInfo *finderInfo, long *infoValid); -static long ReadCatalogEntry(char *fileName, long dirID, void *entry, - long long *dirIndex); +static long GetCatalogEntry(long long *dirIndex, char **name, long *flags, long *time, FinderInfo *finderInfo, long *infoValid); +static long ReadCatalogEntry(char *fileName, long dirID, void *entry, long long *dirIndex); static long ReadExtentsEntry(long fileID, long startBlock, void *entry); static long ReadBTreeEntry(long btree, void *key, char *entry, long long *dirIndex); -static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize, - char **key, char **data); +static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize, char **key, char **data); -static long ReadExtent(char *extent, uint64_t extentSize, long extentFile, - uint64_t offset, uint64_t size, void *buffer, long cache); +static long ReadExtent(char *extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void *buffer, long cache); static long GetExtentStart(void *extents, long index); static long GetExtentSize(void *extents, long index); @@ -105,10 +98,11 @@ static long CompareHFSPlusExtentsKeys(void *key, void *testKey); extern long FastRelString(u_int8_t *str1, u_int8_t *str2); -extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1, - u_int16_t *uniStr2, u_int32_t len2); +extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1, u_int16_t *uniStr2, u_int32_t len2); +//============================================================================== + static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src) { dst->fdType = SWAP_BE32(src->fdType); @@ -117,6 +111,9 @@ // Don't bother with location } + +//============================================================================== + void HFSFree(CICell ih) { if(gCurrentIH == ih) @@ -124,47 +121,55 @@ free(ih); } + +//============================================================================== + bool HFSProbe (const void *buf) { - const HFSMasterDirectoryBlock *mdb; - const HFSPlusVolumeHeader *header; - mdb=(const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset); - header=(const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset); + const HFSMasterDirectoryBlock *mdb; + const HFSPlusVolumeHeader *header; + mdb = (const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset); + header = (const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset); if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord ) return true; - if (SWAP_BE16(header->signature) != kHFSPlusSigWord && - SWAP_BE16(header->signature) != kHFSXSigWord) + + if (SWAP_BE16(header->signature) != kHFSPlusSigWord && SWAP_BE16(header->signature) != kHFSXSigWord) return false; return true; } + +//============================================================================== + long HFSInitPartition(CICell ih) { - long extentSize, extentFile, nodeSize; - void *extent; + long extentSize, extentFile, nodeSize; + void *extent; - if (ih == gCurrentIH) { + if (ih == gCurrentIH) + { #ifdef __i386__ - CacheInit(ih, gCacheBlockSize); + CacheInit(ih, gCacheBlockSize); #endif - return 0; - } + return 0; + } #ifdef __i386__ - if (!gTempStr) gTempStr = (char *)malloc(4096); - if (!gLinkTemp) gLinkTemp = (char *)malloc(64); - if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)malloc(512); - if (!gHFSMdbVib) { + if (!gTempStr) gTempStr = (char *)malloc(4096); + if (!gLinkTemp) gLinkTemp = (char *)malloc(64); + if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)malloc(512); + if (!gHFSMdbVib) + { gHFSMdbVib = (char *)malloc(kBlockSize); gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib; - } - if (!gHFSPlusHeader) { - gHFSPlusHeader = (char *)malloc(kBlockSize); - gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader; - } - if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || - !gHFSMdbVib || !gHFSPlusHeader) return -1; + } + if (!gHFSPlusHeader) + { + gHFSPlusHeader = (char *)malloc(kBlockSize); + gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader; + } + if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || !gHFSMdbVib || !gHFSPlusHeader) return -1; #endif /* __i386__ */ gAllocationOffset = 0; @@ -177,12 +182,13 @@ Seek(ih, kMDBBaseOffset); Read(ih, (long)gHFSMdbVib, kBlockSize); - if ( SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord ) { - gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize; + if (SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord) + { + gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize; - // See if it is HFSPlus - if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord) { - // Normal HFS; + // See if it is HFSPlus + if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord) { + // Normal HFS; gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSMDB->drAlBlkSiz); CacheInit(ih, gCacheBlockSize); gCurrentIH = ih; @@ -194,20 +200,20 @@ extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); extentFile = kHFSCatalogFileID; - ReadExtent(extent, extentSize, extentFile, 0, 256, - gBTreeHeaderBuffer + kBTreeCatalog * 256, 0); + ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0); nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 + sizeof(BTNodeDescriptor)))->nodeSize); // If the BTree node size is larger than the block size, reset the cache. - if (nodeSize > gBlockSize) { - gCacheBlockSize = nodeSize; - CacheInit(ih, gCacheBlockSize); - } + if (nodeSize > gBlockSize) + { + gCacheBlockSize = nodeSize; + CacheInit(ih, gCacheBlockSize); + } - return 0; - } + return 0; + } // Calculate the offset to the embeded HFSPlus volume. gAllocationOffset += (long long)SWAP_BE16(gHFSMDB->drEmbedExtent.startBlock) * @@ -219,12 +225,12 @@ Read(ih, (long)gHFSPlusHeader, kBlockSize); // Not a HFS+ or HFSX volume. - if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord && - SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord) { - verbose("HFS signature was not present.\n"); - gCurrentIH = 0; - return -1; - } + if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord && SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord) + { + verbose("HFS signature was not present.\n"); + gCurrentIH = 0; + return -1; + } gIsHFSPlus = 1; gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSPlus->blockSize); @@ -248,14 +254,18 @@ sizeof(BTNodeDescriptor)))->nodeSize); // If the BTree node size is larger than the block size, reset the cache. - if (nodeSize > gBlockSize) { - gCacheBlockSize = nodeSize; - CacheInit(ih, gCacheBlockSize); - } + if (nodeSize > gBlockSize) + { + gCacheBlockSize = nodeSize; + CacheInit(ih, gCacheBlockSize); + } - return 0; + return 0; } + +//============================================================================== + long HFSLoadFile(CICell ih, char * filePath) { return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0); @@ -267,27 +277,41 @@ char devStr[12]; long dirID, result, flags =0; - if (HFSInitPartition(ih) == -1) return -1; - + if (HFSInitPartition(ih) == -1) + { + return -1; + } + dirID = kHFSRootFolderID; // Skip a lead '\'. Start in the system folder if there are two. - if (filePath[0] == '/') { - if (filePath[1] == '/') { - if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); - else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); - if (dirID == 0) { + if (filePath[0] == '/') + { + if (filePath[1] == '/') + { + if (gIsHFSPlus) + { + dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); + } + else + { + dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); + } + + if (dirID == 0) + { + return -1; + } + filePath++; + } + filePath++; + } + + result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); + if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) + { return -1; - } - filePath++; - } - filePath++; - } + } - result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); - if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) { - return -1; - } - #if UNUSED // Not yet for Intel. System.config/Default.table will fail this check. // Check file owner and permissions. @@ -307,44 +331,83 @@ return length; } -long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, - long * flags, long * time, - FinderInfo * finderInfo, long * infoValid) +long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid) { - char entry[512]; - long dirID, dirFlags = 0; + char entry[512]; - if (HFSInitPartition(ih) == -1) return -1; + long dirID, dirFlags = 0; - if (*dirIndex == -1) return -1; + if (HFSInitPartition(ih) == -1) + { + return -1; + } - dirID = kHFSRootFolderID; - // Skip a lead '\'. Start in the system folder if there are two. - if (dirPath[0] == '/') { - if (dirPath[1] == '/') { - if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); - else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); - if (dirID == 0) return -1; - dirPath++; - } - dirPath++; - } + if (*dirIndex == -1) + { + return -1; + } - if (*dirIndex == 0) { - ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex); - if (*dirIndex == 0) *dirIndex = -1; - if ((dirFlags & kFileTypeMask) != kFileTypeUnknown) return -1; - } + dirID = kHFSRootFolderID; + + // Skip a lead '\'. Start in the system folder if there are two. + if (dirPath[0] == '/') + { + if (dirPath[1] == '/') + { + if (gIsHFSPlus) + { + dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); + } + else + { + dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); + } - GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid); - if (*dirIndex == 0) *dirIndex = -1; - if ((*flags & kFileTypeMask) == kFileTypeUnknown) return -1; + if (dirID == 0) + { + return -1; + } - return 0; + dirPath++; + } + + dirPath++; + } + + if (*dirIndex == 0) + { + ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex); + + if (*dirIndex == 0) + { + *dirIndex = -1; + } + + if ((dirFlags & kFileTypeMask) != kFileTypeUnknown) + { + return -1; + } + } + + GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid); + + if (*dirIndex == 0) + { + *dirIndex = -1; + } + + if ((*flags & kFileTypeMask) == kFileTypeUnknown) + { + return -1; + } + + return 0; } -void -HFSGetDescription(CICell ih, char *str, long strMaxLen) + +//============================================================================== + +void HFSGetDescription(CICell ih, char *str, long strMaxLen) { UInt16 nodeSize; @@ -353,162 +416,198 @@ char *name; long flags =0, time; - if (HFSInitPartition(ih) == -1) { return; } + if (HFSInitPartition(ih) == -1) + { + return; + } - /* Fill some crucial data structures by side effect. */ - dirIndex = 0; - HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0); + /* Fill some crucial data structures by side effect. */ + dirIndex = 0; + HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0); - /* Now we can loook up the volume name node. */ - nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); - firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode); + /* Now we can loook up the volume name node. */ + nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); + firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode); - dirIndex = (long long) firstLeafNode * nodeSize; + dirIndex = (long long) firstLeafNode * nodeSize; - GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0); + GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0); - strncpy(str, name, strMaxLen); - str[strMaxLen] = '\0'; + strncpy(str, name, strMaxLen); + str[strMaxLen] = '\0'; } -long -HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock) +//============================================================================== + +long HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock) { - char entry[512]; - long dirID, result, flags =0; - void *extents; - HFSCatalogFile *hfsFile = (void *)entry; - HFSPlusCatalogFile *hfsPlusFile = (void *)entry; + char entry[512]; + long dirID, result, flags =0; + void *extents; + HFSCatalogFile *hfsFile = (void *)entry; + HFSPlusCatalogFile *hfsPlusFile = (void *)entry; - if (HFSInitPartition(ih) == -1) return -1; + if (HFSInitPartition(ih) == -1) return -1; - dirID = kHFSRootFolderID; - // Skip a lead '\'. Start in the system folder if there are two. - if (filePath[0] == '/') { - if (filePath[1] == '/') { - if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); - else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); - if (dirID == 0) { + dirID = kHFSRootFolderID; + // Skip a lead '\'. Start in the system folder if there are two. + if (filePath[0] == '/') + { + if (filePath[1] == '/') + { + if (gIsHFSPlus) + { + dirID = SWAP_BE32(((long *) gHFSPlus->finderInfo)[5]); + } + else + { + dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); + } + + if (dirID == 0) + { + return -1; + } + filePath++; + } + filePath++; + } + + result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); + + if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) + { + printf("HFS: Resolve path %s failed\n", filePath); return -1; - } - filePath++; - } - filePath++; - } + } - result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); - if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) { - printf("HFS: Resolve path %s failed\n", filePath); - return -1; - } + if (gIsHFSPlus) + { + extents = &hfsPlusFile->dataFork.extents; + } + else + { + extents = &hfsFile->dataExtents; + } - if (gIsHFSPlus) { - extents = &hfsPlusFile->dataFork.extents; - } else { - extents = &hfsFile->dataExtents; - } - #if DEBUG - printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0)); - printf("block size 0x%x\n", (unsigned long)gBlockSize); - printf("Allocation offset 0x%x\n", (unsigned long)gAllocationOffset); + printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0)); + printf("block size 0x%x\n", (unsigned long)gBlockSize); + printf("Allocation offset 0x%x\n", (unsigned long)gAllocationOffset); #endif - *firstBlock = ((unsigned long long)GetExtentStart(extents, 0) * (unsigned long long) gBlockSize + gAllocationOffset) / 512ULL; - return 0; + *firstBlock = ((unsigned long long)GetExtentStart(extents, 0) * (unsigned long long) gBlockSize + gAllocationOffset) / 512ULL; + return 0; } + +//============================================================================== + long HFSGetUUID(CICell ih, char *uuidStr) { - if (HFSInitPartition(ih) == -1) return -1; - if (gVolID == 0LL) return -1; + if (HFSInitPartition(ih) == -1) + return -1; + if (gVolID == 0LL) + return -1; + return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr); } + +//============================================================================== // Private Functions static long ReadFile(void * file, uint64_t * length, void * base, uint64_t offset) { - void *extents; - long fileID; - uint64_t fileLength; - HFSCatalogFile *hfsFile = file; - HFSPlusCatalogFile *hfsPlusFile = file; + void *extents; + long fileID; + uint64_t fileLength; + HFSCatalogFile *hfsFile = file; + HFSPlusCatalogFile *hfsPlusFile = file; - if (gIsHFSPlus) { - fileID = SWAP_BE32(hfsPlusFile->fileID); - fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize); - extents = &hfsPlusFile->dataFork.extents; - } else { - fileID = SWAP_BE32(hfsFile->fileID); - fileLength = SWAP_BE32(hfsFile->dataLogicalSize); - extents = &hfsFile->dataExtents; - } + if (gIsHFSPlus) + { + fileID = SWAP_BE32(hfsPlusFile->fileID); + fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize); + extents = &hfsPlusFile->dataFork.extents; + } + else + { + fileID = SWAP_BE32(hfsFile->fileID); + fileLength = SWAP_BE32(hfsFile->dataLogicalSize); + extents = &hfsFile->dataExtents; + } - if (offset > fileLength) { - printf("Offset is too large.\n"); - return -1; - } + if (offset > fileLength) + { + printf("Offset is too large.\n"); + return -1; + } - if ((*length == 0) || ((offset + *length) > fileLength)) { - *length = fileLength - offset; - } + if ((*length == 0) || ((offset + *length) > fileLength)) + { + *length = fileLength - offset; + } -/* if (*length > kLoadSize) { - printf("File is too large.\n"); - return -1; - }*/ +/* + if (*length > kLoadSize) + { + printf("File is too large.\n"); + return -1; + } +*/ - *length = ReadExtent((char *)extents, fileLength, fileID, - offset, *length, (char *)base, 0); + *length = ReadExtent((char *)extents, fileLength, fileID, offset, *length, (char *)base, 0); - return 0; + return 0; } -static long GetCatalogEntryInfo(void * entry, long * flags, long * time, - FinderInfo * finderInfo, long * infoValid) + +//============================================================================== + +static long GetCatalogEntryInfo(void * entry, long * flags, long * time, FinderInfo * finderInfo, long * infoValid) { - long tmpTime = 0; - long valid = 0; + long tmpTime = 0; + long valid = 0; - // Get information about the file. + // Get information about the file. - switch ( SWAP_BE16(*(short *)entry) ) - { - case kHFSFolderRecord : - *flags = kFileTypeDirectory; - tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate); - break; + switch (SWAP_BE16(*(short *)entry)) + { + case kHFSFolderRecord : + *flags = kFileTypeDirectory; + tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate); + break; - case kHFSPlusFolderRecord : - *flags = kFileTypeDirectory | - (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask); - if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0) - *flags |= kOwnerNotRoot; - tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate); - break; + case kHFSPlusFolderRecord : + *flags = kFileTypeDirectory | (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask); + if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0) + *flags |= kOwnerNotRoot; + tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate); + break; - case kHFSFileRecord : - *flags = kFileTypeFlat; - tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate); - if (finderInfo) { - SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo); - valid = 1; - } - break; + case kHFSFileRecord : + *flags = kFileTypeFlat; + tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate); + if (finderInfo) + { + SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo); + valid = 1; + } + break; - case kHFSPlusFileRecord : - *flags = kFileTypeFlat | - (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask); - if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0) - *flags |= kOwnerNotRoot; - tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate); - if (finderInfo) { - SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo); - valid = 1; - } - break; + case kHFSPlusFileRecord : + *flags = kFileTypeFlat | (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask); + if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0) + *flags |= kOwnerNotRoot; + tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate); + if (finderInfo) + { + SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo); + valid = 1; + } + break; case kHFSFileThreadRecord : case kHFSPlusFileThreadRecord : @@ -519,89 +618,117 @@ break; default: break; - } + } - if (time != 0) { - // Convert base time from 1904 to 1970. - *time = tmpTime - 2082844800; - } - if (infoValid) *infoValid = valid; + if (time != 0) + { + // Convert base time from 1904 to 1970. + *time = tmpTime - 2082844800; + } - return 0; + if (infoValid) + { + *infoValid = valid; + } + + return 0; } -static long ResolvePathToCatalogEntry(char * filePath, long * flags, - void * entry, long dirID, long long * dirIndex) + +//============================================================================== + +static long ResolvePathToCatalogEntry(char * filePath, long * flags, void * entry, long dirID, long long * dirIndex) { - char *restPath; - long result, cnt, subFolderID = 0; - long long tmpDirIndex; - HFSPlusCatalogFile *hfsPlusFile; + char *restPath; + long result, cnt, subFolderID = 0; + long long tmpDirIndex; + HFSPlusCatalogFile *hfsPlusFile; - // Copy the file name to gTempStr - cnt = 0; - while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) cnt++; - strlcpy(gTempStr, filePath, cnt+1); + // Copy the file name to gTempStr + cnt = 0; + while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) + { + cnt++; + } - // Move restPath to the right place. - if (filePath[cnt] != '\0') cnt++; - restPath = filePath + cnt; + strlcpy(gTempStr, filePath, cnt+1); - // gTempStr is a name in the current Dir. - // restPath is the rest of the path if any. + // Move restPath to the right place. + if (filePath[cnt] != '\0') + { + cnt++; + } - result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex); - if (result == -1) { - return -1; - } + restPath = filePath + cnt; - GetCatalogEntryInfo(entry, flags, 0, 0, 0); + // gTempStr is a name in the current Dir. + // restPath is the rest of the path if any. - if ((*flags & kFileTypeMask) == kFileTypeDirectory) { - if (gIsHFSPlus) - subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID); - else - subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID); - } + result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex); - if ((*flags & kFileTypeMask) == kFileTypeDirectory) - result = ResolvePathToCatalogEntry(restPath, flags, entry, - subFolderID, dirIndex); + if (result == -1) + { + return -1; + } - if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat)) { - hfsPlusFile = (HFSPlusCatalogFile *)entry; - if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) && - (SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator)) { - sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, - HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum)); - result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, - kHFSRootFolderID, &tmpDirIndex); - } - } + GetCatalogEntryInfo(entry, flags, 0, 0, 0); - return result; + if ((*flags & kFileTypeMask) == kFileTypeDirectory) + { + if (gIsHFSPlus) + { + subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID); + } + else + { + subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID); + } + } + + if ((*flags & kFileTypeMask) == kFileTypeDirectory) + { + result = ResolvePathToCatalogEntry(restPath, flags, entry, subFolderID, dirIndex); + } + + if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat)) + { + hfsPlusFile = (HFSPlusCatalogFile *)entry; + + if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) && + (SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator)) + { + sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum)); + result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, kHFSRootFolderID, &tmpDirIndex); + } + } + + return result; } -static long GetCatalogEntry(long long * dirIndex, char ** name, - long * flags, long * time, - FinderInfo * finderInfo, long * infoValid) + +//============================================================================== + +static long GetCatalogEntry(long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid) { - long extentSize, nodeSize, curNode, index; - void *extent; - char *nodeBuf, *testKey, *entry; - BTNodeDescriptor *node; + long extentSize, nodeSize, curNode, index; + void *extent; + char *nodeBuf, *testKey, *entry; + BTNodeDescriptor *node; - if (gIsHFSPlus) { - extent = &gHFSPlus->catalogFile.extents; - extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); - } + if (gIsHFSPlus) + { + extent = &gHFSPlus->catalogFile.extents; + extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); + } - nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); - node = (BTNodeDescriptor *)nodeBuf; + nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); + nodeBuf = (char *)malloc(nodeSize); + node = (BTNodeDescriptor *)nodeBuf; index = (long) (*dirIndex % nodeSize); curNode = (long) (*dirIndex / nodeSize); @@ -613,227 +740,319 @@ GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid); - // Get the file name. - if (gIsHFSPlus) { - utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode, + // Get the file name. + if (gIsHFSPlus) + { + utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode, SWAP_BE16(((HFSPlusCatalogKey *)testKey)->nodeName.length), (u_int8_t *)gTempStr, 256, OSBigEndian); - } else { - strncpy(gTempStr, - (const char *)&((HFSCatalogKey *)testKey)->nodeName[1], - ((HFSCatalogKey *)testKey)->nodeName[0]); - gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0'; - } + } + else + { + strncpy(gTempStr, (const char *)&((HFSCatalogKey *)testKey)->nodeName[1], + ((HFSCatalogKey *)testKey)->nodeName[0]); + + gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0'; + } *name = gTempStr; // Update dirIndex. index++; - if (index == SWAP_BE16(node->numRecords)) { - index = 0; - curNode = SWAP_BE32(node->fLink); + + if (index == SWAP_BE16(node->numRecords)) + { + index = 0; + curNode = SWAP_BE32(node->fLink); } *dirIndex = (long long) curNode * nodeSize + index; - free(nodeBuf); + free(nodeBuf); - return 0; + return 0; } -static long ReadCatalogEntry(char * fileName, long dirID, - void * entry, long long * dirIndex) + +//============================================================================== + +static long ReadCatalogEntry(char * fileName, long dirID, void * entry, long long * dirIndex) { - long length; - char key[sizeof(HFSPlusCatalogKey)]; - HFSCatalogKey *hfsKey = (HFSCatalogKey *)key; - HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key; + long length; + char key[sizeof(HFSPlusCatalogKey)]; + HFSCatalogKey *hfsKey = (HFSCatalogKey *)key; + HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key; - // Make the catalog key. - if ( gIsHFSPlus ) - { - hfsPlusKey->parentID = SWAP_BE32(dirID); - length = strlen(fileName); - if (length > 255) length = 255; - utf_decodestr((u_int8_t *)fileName, hfsPlusKey->nodeName.unicode, - &(hfsPlusKey->nodeName.length), 512, OSBigEndian); - } else { - hfsKey->parentID = SWAP_BE32(dirID); - length = strlen(fileName); - if (length > 31) length = 31; - hfsKey->nodeName[0] = length; - strncpy((char *)(hfsKey->nodeName + 1), fileName, length); - } + // Make the catalog key. + if (gIsHFSPlus) + { + hfsPlusKey->parentID = SWAP_BE32(dirID); + length = strlen(fileName); - return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex); + if (length > 255) + { + length = 255; + } + + utf_decodestr((u_int8_t *)fileName, hfsPlusKey->nodeName.unicode, &(hfsPlusKey->nodeName.length), 512, OSBigEndian); + } + else + { + hfsKey->parentID = SWAP_BE32(dirID); + length = strlen(fileName); + + if (length > 31) + { + length = 31; + } + + hfsKey->nodeName[0] = length; + strncpy((char *)(hfsKey->nodeName + 1), fileName, length); + } + + return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex); } + +//============================================================================== + static long ReadExtentsEntry(long fileID, long startBlock, void * entry) { - char key[sizeof(HFSPlusExtentKey)]; - HFSExtentKey *hfsKey = (HFSExtentKey *)key; - HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key; + char key[sizeof(HFSPlusExtentKey)]; + HFSExtentKey *hfsKey = (HFSExtentKey *)key; + HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key; - // Make the extents key. - if (gIsHFSPlus) { - hfsPlusKey->forkType = 0; - hfsPlusKey->fileID = SWAP_BE32(fileID); - hfsPlusKey->startBlock = SWAP_BE32(startBlock); - } else { - hfsKey->forkType = 0; - hfsKey->fileID = SWAP_BE32(fileID); - hfsKey->startBlock = SWAP_BE16(startBlock); - } + // Make the extents key. + if (gIsHFSPlus) + { + hfsPlusKey->forkType = 0; + hfsPlusKey->fileID = SWAP_BE32(fileID); + hfsPlusKey->startBlock = SWAP_BE32(startBlock); + } + else + { + hfsKey->forkType = 0; + hfsKey->fileID = SWAP_BE32(fileID); + hfsKey->startBlock = SWAP_BE16(startBlock); + } - return ReadBTreeEntry(kBTreeExtents, &key, entry, 0); + return ReadBTreeEntry(kBTreeExtents, &key, entry, 0); } + +//============================================================================== + static long ReadBTreeEntry(long btree, void * key, char * entry, long long * dirIndex) { - long extentSize; - void *extent; - short extentFile; - char *nodeBuf; - BTNodeDescriptor *node; - long nodeSize, result = 0, entrySize = 0; - long curNode, index = 0, lowerBound, upperBound; - char *testKey, *recordData =0; + long extentSize; + void *extent; + short extentFile; + char *nodeBuf; + BTNodeDescriptor *node; + long nodeSize, result = 0, entrySize = 0; + long curNode, index = 0, lowerBound, upperBound; + char *testKey, *recordData =0; - // Figure out which tree is being looked at. - if (btree == kBTreeCatalog) { - if (gIsHFSPlus) { - extent = &gHFSPlus->catalogFile.extents; - extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); - } - extentFile = kHFSCatalogFileID; - } else { - if (gIsHFSPlus) { - extent = &gHFSPlus->extentsFile.extents; - extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drXTFlSize); - } - extentFile = kHFSExtentsFileID; - } + // Figure out which tree is being looked at. + if (btree == kBTreeCatalog) + { + if (gIsHFSPlus) + { + extent = &gHFSPlus->catalogFile.extents; + extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); + } + extentFile = kHFSCatalogFileID; + } + else + { + if (gIsHFSPlus) + { + extent = &gHFSPlus->extentsFile.extents; + extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drXTFlSize); + } + extentFile = kHFSExtentsFileID; + } - // Read the BTree Header if needed. - if (gBTHeaders[btree] == 0) { - ReadExtent(extent, extentSize, extentFile, 0, 256, - gBTreeHeaderBuffer + btree * 256, 0); - gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + - sizeof(BTNodeDescriptor)); - if ((gIsHFSPlus && btree == kBTreeCatalog) && - (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare)) { - gCaseSensitive = 1; - } - } + // Read the BTree Header if needed. + if (gBTHeaders[btree] == 0) + { + ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + btree * 256, 0); + gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + sizeof(BTNodeDescriptor)); - curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); - nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); - node = (BTNodeDescriptor *)nodeBuf; + if ((gIsHFSPlus && btree == kBTreeCatalog) && (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare)) + { + gCaseSensitive = 1; + } + } - while (1) { - // Read the current node. - ReadExtent(extent, extentSize, extentFile, - (long long) curNode * nodeSize, nodeSize, nodeBuf, 1); + curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); + nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); + nodeBuf = (char *)malloc(nodeSize); + node = (BTNodeDescriptor *)nodeBuf; - // Find the matching key. - lowerBound = 0; - upperBound = SWAP_BE16(node->numRecords) - 1; - while (lowerBound <= upperBound) { - index = (lowerBound + upperBound) / 2; + while (1) + { + // Read the current node. + ReadExtent(extent, extentSize, extentFile, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1); - GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); + // Find the matching key. + lowerBound = 0; + upperBound = SWAP_BE16(node->numRecords) - 1; - if (gIsHFSPlus) { - if (btree == kBTreeCatalog) { - result = CompareHFSPlusCatalogKeys(key, testKey); - } else { - result = CompareHFSPlusExtentsKeys(key, testKey); - } - } else { - if (btree == kBTreeCatalog) { - result = CompareHFSCatalogKeys(key, testKey); - } else { - result = CompareHFSExtentsKeys(key, testKey); - } - } + while (lowerBound <= upperBound) + { + index = (lowerBound + upperBound) / 2; - if (result < 0) upperBound = index - 1; // search < trial - else if (result > 0) lowerBound = index + 1; // search > trial - else break; // search = trial - } + GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); - if (result < 0) { - index = upperBound; - GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); - } + if (gIsHFSPlus) + { + if (btree == kBTreeCatalog) + { + result = CompareHFSPlusCatalogKeys(key, testKey); + } + else + { + result = CompareHFSPlusExtentsKeys(key, testKey); + } + } + else + { + if (btree == kBTreeCatalog) + { + result = CompareHFSCatalogKeys(key, testKey); + } + else + { + result = CompareHFSExtentsKeys(key, testKey); + } + } + + if (result < 0) + { + upperBound = index - 1; // search < trial + } + else if (result > 0) + { + lowerBound = index + 1; // search > trial + } + else + { + break; // search = trial + } + } + + if (result < 0) + { + index = upperBound; + GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); + } - // Found the closest key... Recurse on it if this is an index node. - if (node->kind == kBTIndexNode) { - curNode = SWAP_BE32( *((long *)recordData) ); - } else break; - } + // Found the closest key... Recurse on it if this is an index node. + if (node->kind == kBTIndexNode) + { + curNode = SWAP_BE32( *((long *)recordData) ); + } + else + { + break; + } + } - // Return error if the file was not found. - if (result != 0) { free(nodeBuf); return -1; } + // Return error if the file was not found. + if (result != 0) + { + free(nodeBuf); + return -1; + } - if (btree == kBTreeCatalog) { - switch (SWAP_BE16(*(short *)recordData)) { - case kHFSFolderRecord : entrySize = 70; break; - case kHFSFileRecord : entrySize = 102; break; - case kHFSFolderThreadRecord : entrySize = 46; break; - case kHFSFileThreadRecord : entrySize = 46; break; - case kHFSPlusFolderRecord : entrySize = 88; break; - case kHFSPlusFileRecord : entrySize = 248; break; - case kHFSPlusFolderThreadRecord : entrySize = 264; break; - case kHFSPlusFileThreadRecord : entrySize = 264; break; - } - } else { - if (gIsHFSPlus) entrySize = sizeof(HFSPlusExtentRecord); - else entrySize = sizeof(HFSExtentRecord); - } + if (btree == kBTreeCatalog) + { + switch (SWAP_BE16(*(short *)recordData)) + { + case kHFSFolderRecord : entrySize = 70; + break; + case kHFSFileRecord : entrySize = 102; + break; + case kHFSFolderThreadRecord : entrySize = 46; + break; + case kHFSFileThreadRecord : entrySize = 46; + break; + case kHFSPlusFolderRecord : entrySize = 88; + break; + case kHFSPlusFileRecord : entrySize = 248; + break; + case kHFSPlusFolderThreadRecord : entrySize = 264; + break; + case kHFSPlusFileThreadRecord : entrySize = 264; + break; + } + } + else + { + if (gIsHFSPlus) + { + entrySize = sizeof(HFSPlusExtentRecord); + } + else + { + entrySize = sizeof(HFSExtentRecord); + } + } - bcopy(recordData, entry, entrySize); + bcopy(recordData, entry, entrySize); - // Update dirIndex. - if (dirIndex != 0) { - index++; - if (index == SWAP_BE16(node->numRecords)) { - index = 0; - curNode = SWAP_BE32(node->fLink); - } - *dirIndex = (long long) curNode * nodeSize + index; - } + // Update dirIndex. + if (dirIndex != 0) + { + index++; + if (index == SWAP_BE16(node->numRecords)) + { + index = 0; + curNode = SWAP_BE32(node->fLink); + } + *dirIndex = (long long) curNode * nodeSize + index; + } - free(nodeBuf); + free(nodeBuf); - return 0; + return 0; } -static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize, - char ** key, char ** data) + +//============================================================================== + +static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize, char ** key, char ** data) { - long keySize; - long recordOffset; + long keySize; + long recordOffset; - recordOffset = SWAP_BE16(*((short *)(nodeBuffer + (nodeSize - 2 * index - 2)))); - *key = nodeBuffer + recordOffset; - if (gIsHFSPlus) { - keySize = SWAP_BE16(*(short *)*key); - *data = *key + 2 + keySize; - } else { - keySize = **key; - *data = *key + 2 + keySize - (keySize & 1); - } + recordOffset = SWAP_BE16(*((short *)(nodeBuffer + (nodeSize - 2 * index - 2)))); + *key = nodeBuffer + recordOffset; + if (gIsHFSPlus) + { + keySize = SWAP_BE16(*(short *)*key); + *data = *key + 2 + keySize; + } + else + { + keySize = **key; + *data = *key + 2 + keySize - (keySize & 1); + } } -static long ReadExtent(char * extent, uint64_t extentSize, - long extentFile, uint64_t offset, uint64_t size, - void * buffer, long cache) + +//============================================================================== + +static long ReadExtent(char * extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void * buffer, long cache) { uint64_t lastOffset; long long blockNumber, countedBlocks = 0; @@ -843,7 +1062,10 @@ long long extentDensity, sizeofExtent, currentExtentSize; char *currentExtent, *extentBuffer = 0, *bufferPos = buffer; - if (offset >= extentSize) return 0; + if (offset >= extentSize) + { + return 0; + } if (gIsHFSPlus) { @@ -857,6 +1079,7 @@ } lastOffset = offset + size; + while (offset < lastOffset) { blockNumber = offset / gBlockSize; @@ -879,10 +1102,15 @@ if (extentBuffer == 0) { extentBuffer = malloc(sizeofExtent * extentDensity); - if (extentBuffer == 0) return -1; + + if (extentBuffer == 0) + { + return -1; + } } nextExtentBlock = nextExtent / extentDensity; + if (currentExtentBlock != nextExtentBlock) { ReadExtentsEntry(extentFile, countedBlocks, extentBuffer); @@ -900,56 +1128,82 @@ countedBlocks += currentExtentSize; } - readOffset = ((blockNumber - countedBlocks) * gBlockSize) + - (offset % gBlockSize); + readOffset = ((blockNumber - countedBlocks) * gBlockSize) + (offset % gBlockSize); // MacWen: fix overflow in multiplication by forcing 64bit multiplication readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset; - if (readSize > (size - sizeRead)) readSize = size - sizeRead; + if (readSize > (size - sizeRead)) + { + readSize = size - sizeRead; + } readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize; - CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, - readSize, cache); + CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, readSize, cache); sizeRead += readSize; offset += readSize; bufferPos += readSize; } - if (extentBuffer) free(extentBuffer); + if (extentBuffer) + { + free(extentBuffer); + } return sizeRead; } + +//============================================================================== + static long GetExtentStart(void * extents, long index) { - long start; - HFSExtentDescriptor *hfsExtents = extents; - HFSPlusExtentDescriptor *hfsPlusExtents = extents; + long start; - if (gIsHFSPlus) start = SWAP_BE32(hfsPlusExtents[index].startBlock); - else start = SWAP_BE16(hfsExtents[index].startBlock); + HFSExtentDescriptor *hfsExtents = extents; + HFSPlusExtentDescriptor *hfsPlusExtents = extents; + if (gIsHFSPlus) + { + start = SWAP_BE32(hfsPlusExtents[index].startBlock); + } + else + { + start = SWAP_BE16(hfsExtents[index].startBlock); + } + return start; } + +//============================================================================== + static long GetExtentSize(void * extents, long index) { - long size; + long size; HFSExtentDescriptor *hfsExtents = extents; HFSPlusExtentDescriptor *hfsPlusExtents = extents; - if (gIsHFSPlus) size = SWAP_BE32(hfsPlusExtents[index].blockCount); - else size = SWAP_BE16(hfsExtents[index].blockCount); + if (gIsHFSPlus) + { + size = SWAP_BE32(hfsPlusExtents[index].blockCount); + } + else + { + size = SWAP_BE16(hfsExtents[index].blockCount); + } return size; } + +//============================================================================== + static long CompareHFSCatalogKeys(void * key, void * testKey) { HFSCatalogKey *searchKey, *trialKey; - long result, searchParentID, trialParentID; + long result, searchParentID, trialParentID; searchKey = key; trialKey = testKey; @@ -958,8 +1212,14 @@ trialParentID = SWAP_BE32(trialKey->parentID); // parent dirID is unsigned - if (searchParentID > trialParentID) result = 1; - else if (searchParentID < trialParentID) result = -1; + if (searchParentID > trialParentID) + { + result = 1; + } + else if (searchParentID < trialParentID) + { + result = -1; + } else { // parent dirID's are equal, compare names @@ -969,10 +1229,13 @@ return result; } + +//============================================================================== + static long CompareHFSPlusCatalogKeys(void * key, void * testKey) { HFSPlusCatalogKey *searchKey, *trialKey; - long result, searchParentID, trialParentID; + long result, searchParentID, trialParentID; searchKey = key; trialKey = testKey; @@ -981,16 +1244,23 @@ trialParentID = SWAP_BE32(trialKey->parentID); // parent dirID is unsigned - if (searchParentID > trialParentID) result = 1; - else if (searchParentID < trialParentID) result = -1; + if (searchParentID > trialParentID) + { + result = 1; + } + else if (searchParentID < trialParentID) + { + result = -1; + } else { // parent dirID's are equal, compare names if ((searchKey->nodeName.length == 0) || (trialKey->nodeName.length == 0)) - result = searchKey->nodeName.length - trialKey->nodeName.length; - else - if (gCaseSensitive) { + result = searchKey->nodeName.length - trialKey->nodeName.length; + } + else if (gCaseSensitive) + { result = BinaryUnicodeCompare(&searchKey->nodeName.unicode[0], SWAP_BE16(searchKey->nodeName.length), &trialKey->nodeName.unicode[0], @@ -1008,75 +1278,111 @@ return result; } + +//============================================================================== + static long CompareHFSExtentsKeys(void * key, void * testKey) { - HFSExtentKey *searchKey, *trialKey; - long result; + HFSExtentKey *searchKey, *trialKey; + long result; - searchKey = key; - trialKey = testKey; + searchKey = key; + trialKey = testKey; - // assume searchKey < trialKey - result = -1; + // assume searchKey < trialKey + result = -1; - if (searchKey->fileID == trialKey->fileID) { - // FileNum's are equal; compare fork types - if (searchKey->forkType == trialKey->forkType) { - // Fork types are equal; compare allocation block number - if (searchKey->startBlock == trialKey->startBlock) { - // Everything is equal - result = 0; - } else { - // Allocation block numbers differ; determine sign - if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock)) - result = 1; - } - } else { - // Fork types differ; determine sign - if (searchKey->forkType > trialKey->forkType) result = 1; - } - } else { - // FileNums differ; determine sign - if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) - result = 1; - } + if (searchKey->fileID == trialKey->fileID) + { + // FileNum's are equal; compare fork types + if (searchKey->forkType == trialKey->forkType) + { + // Fork types are equal; compare allocation block number + if (searchKey->startBlock == trialKey->startBlock) + { + // Everything is equal + result = 0; + } + else + { + // Allocation block numbers differ; determine sign + if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock)) + { + result = 1; + } + } + } + else + { + // Fork types differ; determine sign + if (searchKey->forkType > trialKey->forkType) + { + result = 1; + } + } + } + else + { + // FileNums differ; determine sign + if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) + { + result = 1; + } + } - return result; + return result; } + +//============================================================================== + static long CompareHFSPlusExtentsKeys(void * key, void * testKey) { - HFSPlusExtentKey *searchKey, *trialKey; - long result; + HFSPlusExtentKey *searchKey, *trialKey; - searchKey = key; - trialKey = testKey; + long result = -1; // assume searchKey < trialKey - // assume searchKey < trialKey - result = -1; + searchKey = key; + trialKey = testKey; - if (searchKey->fileID == trialKey->fileID) { - // FileNum's are equal; compare fork types - if (searchKey->forkType == trialKey->forkType) { - // Fork types are equal; compare allocation block number - if (searchKey->startBlock == trialKey->startBlock) { - // Everything is equal - result = 0; - } else { - // Allocation block numbers differ; determine sign - if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock)) - result = 1; - } - } else { - // Fork types differ; determine sign - if (searchKey->forkType > trialKey->forkType) result = 1; - } - } else { - // FileNums differ; determine sign - if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) - result = 1; - } + if (searchKey->fileID == trialKey->fileID) + { + // FileNum's are equal; compare fork types + if (searchKey->forkType == trialKey->forkType) + { + // Fork types are equal; compare allocation block number + if (searchKey->startBlock == trialKey->startBlock) + { + // Everything is equal + result = 0; + } + else + { + // Allocation block numbers differ; determine sign + if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock)) + { + result = 1; + } + } + } + else + { + // Fork types differ; determine sign + if (searchKey->forkType > trialKey->forkType) + { + result = 1; + } + } + } + else + { + // FileNums differ; determine sign + if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) + { + result = 1; + } + } - return result; + return result; } Index: branches/ErmaC/Trunk/i386/libsaio/device_tree.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/device_tree.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/device_tree.h (revision 2037) @@ -1,5 +1,25 @@ /* - * Copyright (c) 2005 Apple Computer, Inc. All Rights Reserved. + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 2.0 (the "License"). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ */ #ifndef __DEVICE_TREE_H @@ -8,52 +28,46 @@ #include #include -typedef struct _Property { - const char * name; - uint32_t length; - void * value; - struct _Property * next; +//============================================================================== + +typedef struct _Property +{ + const char * name; + uint32_t length; + void * value; + struct _Property * next; } Property; -typedef struct _Node { - struct _Property * properties; - struct _Property * last_prop; - - struct _Node * children; - struct _Node * next; +//============================================================================== + +typedef struct _Node +{ + struct _Property * properties; + struct _Property * last_prop; + struct _Node * children; + struct _Node * next; } Node; -extern Property * -DT__AddProperty(Node *node, const char *name, uint32_t length, void *value); -extern Node * -DT__AddChild(Node *parent, const char *name); +extern Property * DT__AddProperty(Node *node, const char *name, uint32_t length, void *value); -Node * -DT__FindNode(const char *path, bool createIfMissing); +extern Node * DT__AddChild(Node *parent, const char *name); -extern void -DT__FreeProperty(Property *prop); +Node * DT__FindNode(const char *path, bool createIfMissing); -extern void -DT__FreeNode(Node *node); +extern void DT__FreeProperty(Property *prop); -extern char * -DT__GetName(Node *node); +extern void DT__FreeNode(Node *node); -void -DT__Initialize(void); +extern char * DT__GetName(Node *node); -/* - * Free up memory used by in-memory representation - * of device tree. - */ -extern void -DT__Finalize(void); +void DT__Initialize(void); -void -DT__FlattenDeviceTree(void **result, uint32_t *length); +// Free up memory used by in-memory representation of device tree. +extern void DT__Finalize(void); +void DT__FlattenDeviceTree(void **result, uint32_t *length); + #endif /* __DEVICE_TREE_H */ Index: branches/ErmaC/Trunk/i386/libsaio/allocate.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/allocate.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/allocate.c (revision 2037) @@ -33,46 +33,57 @@ #define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1)) -long -AllocateMemoryRange(char * rangeName, long start, long length, long type) +//============================================================================== + +long AllocateMemoryRange(char * rangeName, long start, long length, long type) { - char *nameBuf; - uint32_t *buffer; + char *nameBuf; + uint32_t *buffer; - nameBuf = malloc(strlen(rangeName) + 1); - if (nameBuf == 0) return -1; - strcpy(nameBuf, rangeName); + nameBuf = malloc(strlen(rangeName) + 1); + + if (nameBuf == 0) + { + return -1; + } + + strcpy(nameBuf, rangeName); + + buffer = malloc(2 * sizeof(uint32_t)); + + if (buffer == 0) + { + return -1; + } + + buffer[0] = start; + buffer[1] = length; + + DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer); - buffer = malloc(2 * sizeof(uint32_t)); - if (buffer == 0) return -1; - - buffer[0] = start; - buffer[1] = length; - - DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer); - - return 0; + return 0; } -long -AllocateKernelMemory( long inSize ) + +//============================================================================== + +long AllocateKernelMemory(long inSize) { - long addr; + long addr; - if (gImageLastKernelAddr == 0) + if (gImageLastKernelAddr == 0) { - gImageLastKernelAddr = RoundPage( bootArgs->kaddr + - bootArgs->ksize ); - } - addr = gImageLastKernelAddr; - gImageLastKernelAddr += RoundPage(inSize); + gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize); + } + addr = gImageLastKernelAddr; + gImageLastKernelAddr += RoundPage(inSize); - if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) + if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) { - stop ("AllocateKernelMemory error"); - } + stop ("AllocateKernelMemory error"); + } - bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr; + bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr; - return addr; + return addr; } Index: branches/ErmaC/Trunk/i386/libsaio/hfs.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/hfs.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/hfs.h (revision 2037) @@ -23,9 +23,7 @@ extern long HFSInitPartition(CICell ih); extern long HFSLoadFile(CICell ih, char * filePath); extern long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length); -extern long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, - char ** name, long * flags, long * time, - FinderInfo * finderInfo, long * infoValid); +extern long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid); extern void HFSGetDescription(CICell ih, char *str, long strMaxLen); extern long HFSGetFileBlock(CICell ih, char *str, unsigned long long *firstBlock); extern long HFSGetUUID(CICell ih, char *uuidStr); Index: branches/ErmaC/Trunk/i386/libsaio/hfs_compare.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/hfs_compare.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/hfs_compare.c (revision 2037) @@ -32,8 +32,7 @@ #if ! UNCOMPRESSED -static unsigned short * -UncompressStructure(struct compressed_block *bp, int count, int size) +static unsigned short * UncompressStructure(struct compressed_block *bp, int count, int size) { unsigned short *out = malloc(size); unsigned short *op = out; @@ -58,8 +57,7 @@ return out; } -static void -InitCompareTables(void) +static void InitCompareTables(void) { if (gCompareTable == 0) { gCompareTable = UncompressStructure(gCompareTableCompressed, @@ -306,8 +304,7 @@ * ucslen is the number of UCS-2 input characters (not bytes) * bufsize is the size of the output buffer in bytes */ -void -utf_encodestr( const u_int16_t * ucsp, int ucslen, +void utf_encodestr( const u_int16_t * ucsp, int ucslen, u_int8_t * utf8p, u_int32_t bufsize, int byte_order ) { u_int8_t *bufend; Index: branches/ErmaC/Trunk/i386/libsaio/spd.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/spd.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/spd.c (revision 2037) @@ -69,6 +69,19 @@ #define SMBHSTDAT 5 #define SBMBLKDAT 7 +int spd_indexes[] = { + SPD_MEMORY_TYPE, + SPD_DDR3_MEMORY_BANK, + SPD_DDR3_MEMORY_CODE, + SPD_NUM_ROWS, + SPD_NUM_COLUMNS, + SPD_NUM_DIMM_BANKS, + SPD_NUM_BANKS_PER_SDRAM, + 4,7,8,9,12,64, /* TODO: give names to these values */ + 95,96,97,98, 122,123,124,125 /* UIS */ +}; +#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int)) + /** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */ unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd) @@ -107,18 +120,6 @@ /* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */ #define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x) -int spd_indexes[] = { - SPD_MEMORY_TYPE, - SPD_DDR3_MEMORY_BANK, - SPD_DDR3_MEMORY_CODE, - SPD_NUM_ROWS, - SPD_NUM_COLUMNS, - SPD_NUM_DIMM_BANKS, - SPD_NUM_BANKS_PER_SDRAM, - 4,7,8,9,12,64, /* TODO: give names to these values */ - 95,96,97,98, 122,123,124,125 /* UIS */ -}; -#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int)) /** Read from spd *used* values only*/ static void init_spd(char * spd, uint32_t base, int slot) @@ -134,34 +135,40 @@ have different formats, always return a valid ptr.*/ const char * getVendorName(RamSlotInfo_t* slot, uint32_t base, int slot_num) { - uint8_t bank = 0; - uint8_t code = 0; - int i = 0; - uint8_t * spd = (uint8_t *) slot->spd; + uint8_t bank = 0; + uint8_t code = 0; + int i = 0; + uint8_t * spd = (uint8_t *) slot->spd; - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { // DDR3 - bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1 - code = spd[SPD_DDR3_MEMORY_CODE]; - for (i=0; i < VEN_MAP_SIZE; i++) - if (bank==vendorMap[i].bank && code==vendorMap[i].code) - return vendorMap[i].name; - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) { - if(spd[64]==0x7f) { - for (i=64; i<72 && spd[i]==0x7f;i++) { - bank++; - READ_SPD(spd, base, slot_num,i+1); // prefetch next spd byte to read for next loop + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) + { // DDR3 + bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1 + code = spd[SPD_DDR3_MEMORY_CODE]; + for (i=0; i < VEN_MAP_SIZE; i++) + if (bank==vendorMap[i].bank && code==vendorMap[i].code) + return vendorMap[i].name; + } + else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) + { + if(spd[64]==0x7f) + { + for (i=64; i<72 && spd[i]==0x7f;i++) + { + bank++; + READ_SPD(spd, base, slot_num,i+1); // prefetch next spd byte to read for next loop } READ_SPD(spd, base, slot_num,i); - code = spd[i]; - } else { - code = spd[64]; - bank = 0; - } - for (i=0; i < VEN_MAP_SIZE; i++) - if (bank==vendorMap[i].bank && code==vendorMap[i].code) - return vendorMap[i].name; - } + code = spd[i]; + } + else + { + code = spd[64]; + bank = 0; + } + for (i=0; i < VEN_MAP_SIZE; i++) + if (bank==vendorMap[i].bank && code==vendorMap[i].code) + return vendorMap[i].name; + } /* OK there is no vendor id here lets try to match the partnum if it exists */ if (strstr(slot->PartNo,"GU332") == slot->PartNo) // Unifosa fingerprint return "Unifosa"; @@ -171,33 +178,37 @@ /** Get Default Memory Module Speed (no overclocking handled) */ int getDDRspeedMhz(const char * spd) { - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { - switch(spd[12]) { - case 0x0f: - return 1066; - case 0x0c: - return 1333; - case 0x0a: - return 1600; - case 0x14: - default: - return 800; - } - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) { - switch(spd[9]) { - case 0x50: - return 400; - case 0x3d: - return 533; - case 0x30: - return 667; - case 0x25: - default: - return 800; - } - } - return 800; // default freq for unknown types + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) + { + switch(spd[12]) + { + case 0x0f: + return 1066; + case 0x0c: + return 1333; + case 0x0a: + return 1600; + case 0x14: + default: + return 800; + } + } + else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) + { + switch(spd[9]) + { + case 0x50: + return 400; + case 0x3d: + return 533; + case 0x30: + return 667; + case 0x25: + default: + return 800; + } + } + return 800; // default freq for unknown types } #define SMST(a) ((uint8_t)((spd[a] & 0xf0) >> 4)) @@ -208,14 +219,14 @@ { static char asciiSerial[16]; - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3 - { - sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) // DDR2 or DDR - { - sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); - } + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3 + { + sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); + } + else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) // DDR2 or DDR + { + sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); + } return strdup(asciiSerial); } @@ -226,10 +237,12 @@ static char asciiPartNo[32]; int i, start=0, index = 0; - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) + { start = 128; } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2) { + else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) + { start = 73; } @@ -291,7 +304,7 @@ bzero(slot->spd, spd_size); - // Copy spd data into buffer + // Copy spd data into buffer //for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x); init_spd(slot->spd, base, i); @@ -388,25 +401,26 @@ pci_dt_t *current = pci_dt; int i; - while (current) { + while (current) + { #if 0 printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n", current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func, current->class_id, current->vendor_id, current->device_id, get_pci_dev_path(current)); #endif - for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) - { - if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) + for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) { - smbus_controllers[i].read_smb(current); // read smb - return true; + if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) + { + smbus_controllers[i].read_smb(current); // read smb + return true; } } find_and_read_smbus_controller(current->children); current = current->next; } - return false; // not found + return false; // not found } void scan_spd(PlatformInfo_t *p) Index: branches/ErmaC/Trunk/i386/libsaio/spd.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/spd.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/spd.h (revision 2037) @@ -12,11 +12,12 @@ void scan_spd(PlatformInfo_t *p); -struct smbus_controllers_t { +struct smbus_controllers_t +{ uint32_t vendor; uint32_t device; char *name; - void (*read_smb)(pci_dt_t *smbus_dev); + void (*read_smb)(pci_dt_t *smbus_dev); }; Index: branches/ErmaC/Trunk/i386/libsaio/bios.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/bios.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/bios.h (revision 2037) @@ -31,75 +31,84 @@ #include "bootargs.h" -typedef union { - unsigned int rx; - unsigned short rr; - struct { - unsigned char l; - unsigned char h; - } r; +typedef union +{ + unsigned int rx; + unsigned short rr; + + struct + { + unsigned char l; + unsigned char h; + } r; } machineRegister_t; -typedef struct { - unsigned short cf :1; - unsigned short :1; - unsigned short pf :1; - unsigned short :1; - unsigned short af :1; - unsigned short :1; - unsigned short zf :1; - unsigned short sf :1; - unsigned short tf :1; - unsigned short _if :1; - unsigned short df :1; - unsigned short of :1; - unsigned short iopl:2; - unsigned short nt :1; + +typedef struct +{ + unsigned short cf :1; + unsigned short :1; + unsigned short pf :1; + unsigned short :1; + unsigned short af :1; + unsigned short :1; + unsigned short zf :1; + unsigned short sf :1; + unsigned short tf :1; + unsigned short _if :1; + unsigned short df :1; + unsigned short of :1; + unsigned short iopl:2; + unsigned short nt :1; } machineFlags_t; -typedef struct { - unsigned int intno; - machineRegister_t eax; - machineRegister_t ebx; - machineRegister_t ecx; - machineRegister_t edx; - machineRegister_t edi; - machineRegister_t esi; - machineRegister_t ebp; - unsigned short cs; - unsigned short ds; - unsigned short es; - machineFlags_t flags; + +typedef struct +{ + unsigned int intno; + machineRegister_t eax; + machineRegister_t ebx; + machineRegister_t ecx; + machineRegister_t edx; + machineRegister_t edi; + machineRegister_t esi; + machineRegister_t ebp; + unsigned short cs; + unsigned short ds; + unsigned short es; + machineFlags_t flags; } biosBuf_t; -#define EBIOS_FIXED_DISK_ACCESS 0x01 -#define EBIOS_LOCKING_ACCESS 0x02 -#define EBIOS_ENHANCED_DRIVE_INFO 0x04 +#define EBIOS_FIXED_DISK_ACCESS 0x01 +#define EBIOS_LOCKING_ACCESS 0x02 +#define EBIOS_ENHANCED_DRIVE_INFO 0x04 -#define BASE_HD_DRIVE 0x80 +#define BASE_HD_DRIVE 0x80 #if 0 /* * ACPI defined memory range types. */ -enum { - kMemoryRangeUsable = 1, // RAM usable by the OS. - kMemoryRangeReserved = 2, // Reserved. (Do not use) - kMemoryRangeACPI = 3, // ACPI tables. Can be reclaimed. - kMemoryRangeNVS = 4, // ACPI NVS memory. (Do not use) +enum +{ + kMemoryRangeUsable = 1, // RAM usable by the OS. + kMemoryRangeReserved = 2, // Reserved. (Do not use) + kMemoryRangeACPI = 3, // ACPI tables. Can be reclaimed. + kMemoryRangeNVS = 4, // ACPI NVS memory. (Do not use) - /* Undefined types should be treated as kMemoryRangeReserved */ + /* Undefined types should be treated as kMemoryRangeReserved */ }; #endif /* * Memory range descriptor. */ -typedef struct MemoryRange { - unsigned long long base; // 64-bit base address - unsigned long long length; // 64-bit length in bytes - unsigned long type; // type of memory range - unsigned long reserved; +typedef struct MemoryRange +{ + unsigned long long base; // 64-bit base address + unsigned long long length; // 64-bit length in bytes + unsigned long type; // type of memory range + unsigned long reserved; } MemoryRange; #endif /* !__LIBSAIO_BIOS_H */ Index: branches/ErmaC/Trunk/i386/libsaio/gma.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/gma.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/gma.c (revision 2037) @@ -191,7 +191,7 @@ pause(); return false; } - + devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1)); devprop_add_value(device, "device_type", (uint8_t*)"display", 8); @@ -308,7 +308,7 @@ devprop_add_value(device, "AAPL,tbl-info", HD3000_tbl_info, 18); devprop_add_value(device, "AAPL,os-info", HD3000_os_info, 20); } - + stringdata = malloc(sizeof(uint8_t) * string->length); if (!stringdata) { Index: branches/ErmaC/Trunk/i386/libsaio/memvendors.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/memvendors.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/memvendors.h (revision 2037) @@ -7,10 +7,11 @@ #ifndef __MEMVEN_H #define __MEMVEN_H -typedef struct _vidTag { - uint8_t bank; - uint8_t code; - const char* name; +typedef struct _vidTag +{ + uint8_t bank; + uint8_t code; + const char* name; } VenIdName; VenIdName vendorMap[] = { Index: branches/ErmaC/Trunk/i386/libsaio/device_inject.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/device_inject.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/device_inject.c (revision 2037) @@ -206,12 +206,12 @@ int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len) { - + if(!nm || !vl || !len) { return 0; } - + uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); uint8_t *data = (uint8_t*)malloc(length); { @@ -219,12 +219,12 @@ { return 0; } - + memset(data, 0, length); uint32_t off= 0; data[off+1] = ((strlen(nm) * 2) + 6) >> 8; data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; - + off += 4; uint32_t i=0, l = strlen(nm); for(i = 0 ; i < l ; i++, off += 2) @@ -241,7 +241,7 @@ { data[off] = *vl++; } - } + } uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); @@ -272,10 +272,10 @@ { free(device->data); } - + free(data); device->data = newdata; - + return 1; } @@ -307,7 +307,7 @@ dp_swap32(string->entries[i]->acpi_dev_path._UID)); buffer += 24; - for(x=0;x < string->entries[i]->num_pci_devpaths; x++) + for(x = 0;x < string->entries[i]->num_pci_devpaths; x++) { sprintf(buffer, "%02x%02x%04x%02x%02x", string->entries[i]->pci_dev_path[x].type, string->entries[i]->pci_dev_path[x].subtype, Index: branches/ErmaC/Trunk/i386/libsaio/device_inject.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/device_inject.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/device_inject.h (revision 2037) @@ -18,7 +18,8 @@ extern void setupDeviceProperties(Node *node); -struct ACPIDevPath { +struct ACPIDevPath +{ uint8_t type; // = 2 ACPI device-path uint8_t subtype; // = 1 ACPI Device-path uint16_t length; // = 0x0c @@ -26,7 +27,8 @@ uint32_t _UID; // = 0x00000000 PCI ROOT }; -struct PCIDevPath { +struct PCIDevPath +{ uint8_t type; // = 1 Hardware device-path uint8_t subtype; // = 1 PCI uint16_t length; // = 6 @@ -34,13 +36,15 @@ uint8_t device; // pci dev number }; -struct DevicePathEnd { +struct DevicePathEnd +{ uint8_t type; // = 0x7f uint8_t subtype; // = 0xff uint16_t length; // = 4; }; -struct DevPropDevice { +struct DevPropDevice +{ uint32_t length; uint16_t numentries; uint16_t WHAT2; // 0x0000 ? @@ -55,7 +59,8 @@ // ------------------------ }; -struct DevPropString { +struct DevPropString +{ uint32_t length; uint32_t WHAT2; // 0x01000000 ? uint16_t numentries; Index: branches/ErmaC/Trunk/i386/libsaio/fdisk.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/fdisk.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/fdisk.h (revision 2037) @@ -35,11 +35,11 @@ #ifndef __LIBSAIO_FDISK_H #define __LIBSAIO_FDISK_H -#define DISK_BLK0 0 /* blkno of boot block */ -#define DISK_BLK0SZ 512 /* size of boot block */ -#define DISK_BOOTSZ 446 /* size of boot code in boot block */ +#define DISK_BLK0 0 /* blkno of boot block */ +#define DISK_BLK0SZ 512 /* size of boot block */ +#define DISK_BOOTSZ 446 /* size of boot code in boot block */ #define DISK_SIGNATURE 0xAA55 /* signature of the boot record */ -#define FDISK_NPART 4 /* number of entries in fdisk table */ +#define FDISK_NPART 4 /* number of entries in fdisk table */ #define FDISK_ACTIVE 0x80 /* indicator of active partition */ #define FDISK_NEXTNAME 0xA7 /* indicator of NeXT partition */ #define FDISK_DOS12 0x01 /* 12-bit fat < 10MB dos partition */ @@ -49,8 +49,8 @@ #define FDISK_NTFS 0x07 /* NTFS partition */ #define FDISK_SMALLFAT32 0x0b /* FAT32 partition */ #define FDISK_FAT32 0x0c /* FAT32 partition */ -#define FDISK_DOS16SLBA 0x0e -#define FDISK_LINUX 0x83 +#define FDISK_DOS16SLBA 0x0e /* 16-bit FAT, LBA-mapped */ +#define FDISK_LINUX 0x83 /* Linux native */ #define FDISK_OPENBSD 0xa6 /* OpenBSD FFS partition */ #define FDISK_FREEBSD 0xa5 /* FreeBSD UFS2 partition */ #define FDISK_BEFS 0xeb /* Haiku BeFS partition */ Index: branches/ErmaC/Trunk/i386/libsaio/sys.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/sys.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/sys.c (revision 2037) @@ -81,11 +81,12 @@ extern int multiboot_skip_partition; extern int multiboot_skip_partition_set; -struct devsw { - const char * name; - // size increased from char to short to handle non-BIOS internal devices - unsigned short biosdev; - int type; +struct devsw +{ + const char * name; + // size increased from char to short to handle non-BIOS internal devices + unsigned short biosdev; + int type; }; // Device entries must be ordered by bios device numbers. @@ -99,7 +100,8 @@ }; // Pseudo BIOS devices -enum { +enum +{ kPseudoBIOSDevRAMDisk = 0x100, kPseudoBIOSDevBooter = 0x101 }; @@ -120,7 +122,8 @@ //static BVRef getBootVolumeRef( const char * path, const char ** outPath ); static BVRef newBootVolumeRef( int biosdev, int partno ); -//========================================================================== + +//============================================================================== // LoadVolumeFile - LOW-LEVEL FILESYSTEM FUNCTION. // Load the specified file from the specified volume // to the load buffer at LOAD_ADDR. @@ -128,7 +131,7 @@ long LoadVolumeFile(BVRef bvr, const char *filePath) { - long fileSize; + long fileSize; // Read file into load buffer. The data in the load buffer will be // overwritten by the next LoadFile() call. @@ -142,87 +145,116 @@ return fileSize; } -//========================================================================== + +//============================================================================== // LoadFile - LOW-LEVEL FILESYSTEM FUNCTION. // Load the specified file to the load buffer at LOAD_ADDR. // If the file is fat, load only the i386 portion. long LoadFile(const char * fileSpec) { - const char * filePath; - BVRef bvr; + const char * filePath; + BVRef bvr; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { + return -1; + } - return LoadVolumeFile(bvr, filePath); + return LoadVolumeFile(bvr, filePath); } + +//============================================================================== + long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length) { - const char *filePath; - BVRef bvr; + const char *filePath; + BVRef bvr; - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { + return -1; + } - if (bvr->fs_readfile == NULL) - return -1; + if (bvr->fs_readfile == NULL) + { + return -1; + } - return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length); + return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length); } + +//============================================================================== + long LoadThinFatFile(const char *fileSpec, void **binary) { - const char *filePath; - FSReadFile readFile; - BVRef bvr; - unsigned long length, length2; + const char * filePath; + FSReadFile readFile; + BVRef bvr; + unsigned long length, length2; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { + return -1; + } + + *binary = (void *)kLoadAddr; + + // Read file into load buffer. The data in the load buffer will be + // overwritten by the next LoadFile() call. - *binary = (void *)kLoadAddr; + gFSLoadAddress = (void *) LOAD_ADDR; - // Read file into load buffer. The data in the load buffer will be - // overwritten by the next LoadFile() call. + readFile = bvr->fs_readfile; + + if (readFile != NULL) + { + // Read the first 4096 bytes (fat header) + length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000); - gFSLoadAddress = (void *) LOAD_ADDR; - - readFile = bvr->fs_readfile; - - if (readFile != NULL) { - // Read the first 4096 bytes (fat header) - length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000); - if (length > 0) { - if (ThinFatFile(binary, &length) == 0) { + if (length > 0) + { + if (ThinFatFile(binary, &length) == 0) + { if (length == 0) return 0; + // We found a fat binary; read only the thin part - length = readFile(bvr, (char *)filePath, - (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); + length = readFile(bvr, (char *)filePath, (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); *binary = (void *)kLoadAddr; - } else { + } + else + { // Not a fat binary; read the rest of the file length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0); - if (length2 == -1) return -1; + + if (length2 == -1) + return -1; + length += length2; } } - } else { + } + else + { length = bvr->fs_loadfile(bvr, (char *)filePath); - if (length > 0) { + + if (length > 0) ThinFatFile(binary, &length); - } } - + return length; } + +//============================================================================== + #if UNUSED long GetFSUUID(char *spec, char *uuidStr) { @@ -241,6 +273,7 @@ #endif // filesystem-specific getUUID functions call this shared string generator + long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr) { unsigned fmtbase, fmtidx, i; @@ -264,50 +297,68 @@ // generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292 - i = 0; fmtbase = 0; - for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) { - for(i=0; i < uuidfmt[fmtidx]; i++) { - uint8_t byte = mdresult[fmtbase+i]; - char nib; + i = 0; + fmtbase = 0; - nib = byte >> 4; - *p = nib + '0'; // 0x4 -> '4' - if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' - p++; + for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) + { + for (i = 0; i < uuidfmt[fmtidx]; i++) + { + uint8_t byte = mdresult[fmtbase + i]; + char nib = byte >> 4; + *p = nib + '0'; // 0x4 -> '4' - nib = byte & 0xf; - *p = nib + '0'; // 0x4 -> '4' - if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' - p++; + if (*p > '9') + { + *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + } - } - fmtbase += i; - if(fmtidx < sizeof(uuidfmt)-1) - *(p++) = '-'; - else - *p = '\0'; - } + p++; - return 0; + nib = byte & 0xf; + *p = nib + '0'; // 0x4 -> '4' + + if (*p > '9') + { + *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + } + + p++; + } + + fmtbase += i; + + if (fmtidx < sizeof(uuidfmt) - 1) + { + *(p++) = '-'; + } + else + { + *p = '\0'; + } + } + + return 0; } -//========================================================================== +//============================================================================== // GetDirEntry - LOW-LEVEL FILESYSTEM FUNCTION. // Fetch the next directory entry for the given directory. -long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, - long * flags, long * time) +long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, long * flags, long * time) { - const char * dirPath; - BVRef bvr; + const char * dirPath; + BVRef bvr; - // Resolve the boot volume from the dir spec. + // Resolve the boot volume from the dir spec. if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) - return -1; + { + return -1; + } - // Return 0 on success, or -1 if there are no additional entries. + // Returns 0 on success or -1 when there are no additional entries. return bvr->fs_getdirentry( bvr, /* dirPath */ (char *)dirPath, @@ -315,65 +366,80 @@ /* dirEntry */ (char **)name, flags, time, 0, 0 ); } -//========================================================================== + +//============================================================================== // GetFileInfo - LOW-LEVEL FILESYSTEM FUNCTION. // Get attributes for the specified file. static char* gMakeDirSpec; -long GetFileInfo(const char * dirSpec, const char * name, - long * flags, long * time) +long GetFileInfo(const char * dirSpec, const char * name, long * flags, long * time) { - long long index = 0; - const char * entryName; + long long index = 0; + const char * entryName; - if (gMakeDirSpec == 0) - gMakeDirSpec = (char *)malloc(1024); + if (gMakeDirSpec == 0) + { + gMakeDirSpec = (char *)malloc(1024); + } - if (!dirSpec) { - long idx, len; + if (!dirSpec) + { + long idx, len; - len = strlen(name); + len = strlen(name); for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {} - if (idx == 0) { - if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly - gMakeDirSpec[0] = '/'; - gMakeDirSpec[1] = '\0'; - gMakeDirSpec[idx] = '\0'; - } else { - idx++; - strncpy(gMakeDirSpec, name, idx); - gMakeDirSpec[idx] = '\0'; // ISSUE: http://forge.voodooprojects.org/p/chameleon/issues/270/ - name += idx; - } - dirSpec = gMakeDirSpec; - } + if (idx == 0) + { + if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly + gMakeDirSpec[0] = '/'; + gMakeDirSpec[1] = '\0'; + gMakeDirSpec[idx] = '\0'; + } + else + { + idx++; + strncpy(gMakeDirSpec, name, idx); + gMakeDirSpec[idx] = '\0'; // ISSUE: http://forge.voodooprojects.org/p/chameleon/issues/270/ + name += idx; + } - while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0) - { - if (strcmp(entryName, name) == 0) - return 0; // success - } - return -1; // file not found + dirSpec = gMakeDirSpec; + } + + while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0) + { + if (strcmp(entryName, name) == 0) + { + return 0; // success + } + } + + return -1; // file not found } + +//============================================================================== + long GetFileBlock(const char *fileSpec, unsigned long long *firstBlock) { - const char * filePath; - BVRef bvr; + const char * filePath; + BVRef bvr; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { - printf("Boot volume for '%s' is bogus\n", fileSpec); - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { + // printf("Boot volume for '%s' is bogus\n", fileSpec); + return -1; } return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock); } -//========================================================================== + +//============================================================================== // GetFreeFD() static int GetFreeFd(void) @@ -381,8 +447,10 @@ int fd; // Locate a free descriptor slot. - for (fd = 0; fd < NFILES; fd++) { - if (iob[fd].i_flgs == 0) { + for (fd = 0; fd < NFILES; fd++) + { + if (iob[fd].i_flgs == 0) + { return fd; } } @@ -391,7 +459,7 @@ return -1; } -//========================================================================== +//============================================================================== // iob_from_fdesc() // // Return a pointer to an allocated 'iob' based on the file descriptor @@ -399,16 +467,18 @@ static struct iob * iob_from_fdesc(int fdesc) { - register struct iob * io; + register struct iob * io; - if (fdesc < 0 || fdesc >= NFILES || - ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) + if (fdesc < 0 || fdesc >= NFILES || ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) + { return NULL; - else - return io; + } + + return io; } -//========================================================================== + +//============================================================================== // openmem() int openmem(char * buf, int len) @@ -430,7 +500,8 @@ return fdesc; } -//========================================================================== + +//============================================================================== // open() - Open the file specified by 'path' for reading. static int open_bvr(BVRef bvr, const char *filePath, int flags) @@ -439,7 +510,8 @@ int fdesc; int i; - if (bvr == NULL) { + if (bvr == NULL) + { return -1; } @@ -450,22 +522,32 @@ // Mark the descriptor as taken. io->i_flgs = F_ALLOC; + // Find the next available memory block in the download buffer. + io->i_buf = (char *) LOAD_ADDR; - for (i = 0; i < NFILES; i++) { - if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) { + + for (i = 0; i < NFILES; i++) + { + if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) + { continue; } + io->i_buf = MAX(iob[i].i_filesize + iob[i].i_buf, io->i_buf); } // Load entire file into memory. Unnecessary open() calls must be avoided. + gFSLoadAddress = io->i_buf; io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath); - if (io->i_filesize < 0) { + + if (io->i_filesize < 0) + { close(fdesc); return -1; } + return fdesc; } @@ -475,7 +557,8 @@ BVRef bvr; // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) { + if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) + { return open_bvr(bvr, filepath, flags); } return -1; @@ -491,29 +574,36 @@ int unit; int partition; - if ((i = open(path, flags)) >= 0) { + if ((i = open(path, flags)) >= 0) + { return i; } - if (bvd == NULL || (len = strlen(bvd)) < 2) { + if (bvd == NULL || (len = strlen(bvd)) < 2) + { return -1; } - for (dp=devsw; dp->name; dp++) { - if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) { + for (dp=devsw; dp->name; dp++) + { + if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) + { unit = 0; partition = 0; /* get optional unit and partition */ if (len >= 5 && bvd[2] == '(') { /* min must be present xx(0) */ cp = &bvd[3]; i = 0; - while ((cp - path) < len && isdigit(*cp)) { + while ((cp - path) < len && isdigit(*cp)) + { i = i * 10 + *cp++ - '0'; unit = i; } - if (*cp++ == ',') { + if (*cp++ == ',') + { i = 0; - while ((cp - path) < len && isdigit(*cp)) { + while ((cp - path) < len && isdigit(*cp)) + { i = i * 10 + *cp++ - '0'; partition = i; } @@ -526,75 +616,92 @@ return -1; } -//========================================================================== + +//============================================================================== // close() - Close a file descriptor. int close(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + if ((io = iob_from_fdesc(fdesc)) == NULL) + { + return (-1); + } - io->i_flgs = 0; + io->i_flgs = 0; - return 0; + return 0; } -//========================================================================== + +//============================================================================== // lseek() - Reposition the byte offset of the file descriptor from the // beginning of the file. Returns the relocated offset. int b_lseek(int fdesc, int offset, int ptr) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + if ((io = iob_from_fdesc(fdesc)) == NULL) + { + return (-1); + } - io->i_offset = offset; + io->i_offset = offset; - return offset; + return offset; } -//========================================================================== + +//============================================================================== // tell() - Returns the byte offset of the file descriptor. int tell(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return 0; + if ((io = iob_from_fdesc(fdesc)) == NULL) + { + return 0; + } - return io->i_offset; + return io->i_offset; } -//========================================================================== + +//============================================================================== // read() - Read up to 'count' bytes of data from the file descriptor // into the buffer pointed to by buf. int read(int fdesc, char * buf, int count) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + if ((io = iob_from_fdesc(fdesc)) == NULL) + { + return (-1); + } - if ((io->i_offset + count) > (unsigned int)io->i_filesize) - count = io->i_filesize - io->i_offset; + if ((io->i_offset + count) > (unsigned int)io->i_filesize) + { + count = io->i_filesize - io->i_offset; + } - if (count <= 0) - return 0; // end of file + if (count <= 0) + { + return 0; // end of file + } - bcopy(io->i_buf + io->i_offset, buf, count); + bcopy(io->i_buf + io->i_offset, buf, count); - io->i_offset += count; + io->i_offset += count; - return count; + return count; } -//========================================================================== + +//============================================================================== // write() - Write up to 'count' bytes of data to the file descriptor // from the buffer pointed to by buf. @@ -650,50 +757,57 @@ return 4; } -//========================================================================== + +//============================================================================== // file_size() - Returns the size of the file described by the file // descriptor. int file_size(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == 0) - return 0; + if ((io = iob_from_fdesc(fdesc)) == 0) + { + return 0; + } - return io->i_filesize; + return io->i_filesize; } -//========================================================================== +//============================================================================== + struct dirstuff * vol_opendir(BVRef bvr, const char * path) { - struct dirstuff * dirp = 0; + struct dirstuff * dirp = 0; - dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); - if (dirp == NULL) - goto error; + dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); - dirp->dir_path = newString(path); - if (dirp->dir_path == NULL) - goto error; + if (dirp == NULL) + goto error; - dirp->dir_bvr = bvr; + dirp->dir_path = newString(path); + if (dirp->dir_path == NULL) + goto error; - return dirp; + dirp->dir_bvr = bvr; + return dirp; + error: - closedir(dirp); - return NULL; + closedir(dirp); + + return NULL; } -//========================================================================== +//============================================================================== + struct dirstuff * opendir(const char * path) { - struct dirstuff * dirp = 0; - const char * dirPath; - BVRef bvr; + struct dirstuff * dirp = 0; + const char * dirPath; + BVRef bvr; if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL) goto error; @@ -715,56 +829,63 @@ return NULL; } -//========================================================================== +//============================================================================== + int closedir(struct dirstuff * dirp) { - if (dirp) { - if (dirp->dir_path) free(dirp->dir_path); - free(dirp); - } + if (dirp) + { + if (dirp->dir_path) + { + free(dirp->dir_path); + } + + free(dirp); + } + return 0; } -//========================================================================== -int readdir(struct dirstuff * dirp, const char ** name, long * flags, - long * time) +//============================================================================== + +int readdir(struct dirstuff * dirp, const char ** name, long * flags,long * time) { - return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr, - /* dirPath */ dirp->dir_path, - /* dirIndex */ &dirp->dir_index, - /* dirEntry */ (char **)name, flags, time, - 0, 0); + return dirp->dir_bvr->fs_getdirentry(dirp->dir_bvr, + /* dirPath */ dirp->dir_path, + /* dirIndex */ &dirp->dir_index, + /* dirEntry */ (char **)name, flags, time, 0, 0); } -//========================================================================== -int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags, - long * time, FinderInfo *finderInfo, long *infoValid) +//============================================================================== + +int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags, long * time, FinderInfo *finderInfo, long *infoValid) { - return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr, - /* dirPath */ dirp->dir_path, - /* dirIndex */ &dirp->dir_index, - /* dirEntry */ (char **)name, - flags, time, - finderInfo, infoValid); + return dirp->dir_bvr->fs_getdirentry(dirp->dir_bvr, + /* dirPath */ dirp->dir_path, + /* dirIndex */ &dirp->dir_index, + /* dirEntry */ (char **)name, + flags, time, finderInfo, infoValid); } -//========================================================================== +//============================================================================== + const char * systemConfigDir() { - if (gBootFileType == kNetworkDeviceType) - return ""; - return "/Library/Preferences/SystemConfiguration"; + if (gBootFileType == kNetworkDeviceType) + return ""; + return "/Library/Preferences/SystemConfiguration"; } -//========================================================================== +//============================================================================== + int gBootFileType; -void scanBootVolumes( int biosdev, int * count ) +void scanBootVolumes(int biosdev, int * count) { BVRef bvr = 0; @@ -783,8 +904,11 @@ } } -//========================================================================== + +//============================================================================== + + void scanDisks(int biosdev, int *count) { #define MAX_HDD_COUNT 32 @@ -807,8 +931,9 @@ } } -//========================================================================== +//============================================================================== + BVRef selectBootVolume( BVRef chain ) { bool filteredChain = false; @@ -884,8 +1009,9 @@ return bvr; } -//========================================================================== +//============================================================================== + #define LP '(' #define RP ')' int gBIOSDev; @@ -899,22 +1025,22 @@ void setRootVolume(BVRef volume) { - gRootVolume = volume; - // Veto non-native FS. Basically that means don't allow the root volume to - // be set to a volume we can't read files from. - if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0)) - gRootVolume = NULL; + gRootVolume = volume; + // Veto non-native FS. Basically that means don't allow the root volume to + // be set to a volume we can't read files from. + if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0)) + gRootVolume = NULL; } void setBootGlobals(BVRef chain) { - // Record default boot device. - gBootVolume = selectBootVolume(chain); + // Record default boot device. + gBootVolume = selectBootVolume(chain); - // turbo - Save the ORIGINAL boot volume too for loading our mkext - if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume; + // turbo - Save the ORIGINAL boot volume too for loading our mkext + if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume; - setRootVolume(gBootVolume); + setRootVolume(gBootVolume); } /*! @@ -925,103 +1051,131 @@ is changed to the selected volume unless the volume selector is that of a ramdisk. */ -BVRef getBootVolumeRef( const char * path, const char ** outPath ) +BVRef getBootVolumeRef(const char * path, const char ** outPath) { const char * cp; BVRef bvr = gRootVolume; - int biosdev = gBIOSDev; + int biosdev = gBIOSDev; // Search for left parenthesis in the path specification. - for (cp = path; *cp; cp++) { - if (*cp == LP || *cp == '/') break; - } + for (cp = path; *cp; cp++) + { + if (*cp == LP || *cp == '/') + { + break; + } + } - if (*cp != LP) // no left paren found - { - // Path is using the implicit current device so if there is - // no current device, then we must fail. - cp = path; - if ( gRootVolume == NULL ) - return NULL; - } - else if ((cp - path) == 2) // found "xx(" - { - const struct devsw * dp; - const char * xp = path; - int i; - int unit = -1; - int part = -1; + if (*cp != LP) // no left paren found + { + cp = path; + // Path is using the implicit current device so if there is + // no current device, then we must fail. + if (gRootVolume == NULL) + { + return NULL; + } + } + else if ((cp - path) == 2) // found "xx(" + { + const struct devsw * dp; + const char * xp = path; - cp++; + int i; + int unit = -1; + int part = -1; - // Check the 2 character device name pointed by 'xp'. + cp++; - for (dp = devsw; dp->name; dp++) - { - if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1])) - break; // found matching entry - } - if (dp->name == NULL) - { - error("Unknown device '%c%c'\n", xp[0], xp[1]); - return NULL; - } + // Check the 2 character device name pointed by 'xp'. + + for (dp = devsw; dp->name; dp++) + { + if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1])) + { + break; // Found matching entry. + } + } + + if (dp->name == NULL) + { + error("Unknown device '%c%c'\n", xp[0], xp[1]); + return NULL; + } - // Extract the optional unit number from the specification. - // hd(unit) or hd(unit, part). + // Extract the optional unit number from the specification. + // hd(unit) or hd(unit, part). - i = 0; - while (*cp >= '0' && *cp <= '9') - { - i = i * 10 + *cp++ - '0'; - unit = i; - } + i = 0; + while (*cp >= '0' && *cp <= '9') + { + i = i * 10 + *cp++ - '0'; + unit = i; + } + // Unit is no longer optional and never really was. // If the user failed to specify it then the unit number from the previous kernDev // would have been used which makes little sense anyway. // For example, if the user did fd()/foobar and the current root device was the // second hard disk (i.e. unit 1) then fd() would select the second floppy drive! - if(unit == -1) - return NULL; + if (unit == -1) + { + return NULL; + } - // Extract the optional partition number from the specification. + // Extract the optional partition number from the specification. - if (*cp == ',') - part = atoi(++cp); + if (*cp == ',') + { + part = atoi(++cp); + } - // If part is not specified part will be -1 whereas before it would have been - // whatever the last partition was which makes about zero sense if the device - // has been switched. + // If part is not specified part will be -1 whereas before it would have been + // whatever the last partition was which makes about zero sense if the device + // has been switched. - // Skip past the right paren. + // Skip past the right paren. - for ( ; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) cp++; + for ( ; *cp && *cp != RP; cp++) /* LOOP */; + + if (*cp == RP) + { + cp++; + } - biosdev = dp->biosdev + unit; - bvr = newBootVolumeRef(biosdev, part); + biosdev = dp->biosdev + unit; - if(bvr == NULL) - return NULL; - } - else - { - // Bad device specifier, skip past the right paren. + bvr = newBootVolumeRef(biosdev, part); - for ( cp++; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) cp++; - // If gRootVolume was NULL, then bvr will be NULL as well which - // should be caught by the caller. - } + if (bvr == NULL) + { + return NULL; + } + } + else + { + // Bad device specifier, skip past the right paren. - // Returns the file path following the device spec. - // e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'. + for (cp++; *cp && *cp != RP; cp++) /* LOOP */; + { + if (*cp == RP) + { + cp++; + } + } - *outPath = cp; + // If gRootVolume was NULL, then bvr will be NULL as well which + // should be caught by the caller. + } - return bvr; + // Returns the file path following the device spec. + // e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'. + + *outPath = cp; + + return bvr; } //========================================================================== Index: branches/ErmaC/Trunk/i386/libsaio/load.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/load.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/load.c (revision 2037) @@ -32,6 +32,15 @@ #include +/* + * Backward compatibility fix for the SDK 10.7 version of loader.h + */ + +#ifndef LC_MAIN + #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */ +#endif + + static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size); static long DecodeUnixThread(long cmdBase, unsigned int *entry); static long DecodeSymbolTable(long cmdBase); @@ -41,17 +50,18 @@ bool gHaveKernelCache; /* XXX aserebln: uninitialized? and only set to true, never to false */ cpu_type_t archCpuType=CPU_TYPE_I386; -// Public Functions +//============================================================================== +// Public function. + long ThinFatFile(void **binary, unsigned long *length) { - unsigned long nfat, swapped, size = 0; - struct fat_header *fhp = (struct fat_header *)*binary; - struct fat_arch *fap = - (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); - cpu_type_t fapcputype; - uint32_t fapoffset; - uint32_t fapsize; + unsigned long nfat, swapped, size = 0; + struct fat_header *fhp = (struct fat_header *)*binary; + struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); + cpu_type_t fapcputype; + uint32_t fapoffset; + uint32_t fapsize; if (fhp->magic == FAT_MAGIC) { @@ -67,6 +77,7 @@ { return -1; } + for (; nfat > 0; nfat--, fap++) { if (swapped) @@ -81,6 +92,7 @@ fapoffset = fap->offset; fapsize = fap->size; } + if (fapcputype == archCpuType) { *binary = (void *) ((unsigned long)*binary + fapoffset); @@ -89,65 +101,80 @@ } } - if (length != 0) *length = size; + if (length != 0) + { + *length = size; + } return 0; } + +//============================================================================== + long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize) { - struct mach_header *mH; - unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart; - // long headerBase, headerAddr, headerSize; - unsigned int vmaddr = ~0; - unsigned int vmend = 0; - unsigned long cnt; - long ret = -1; - unsigned int entry = 0; + struct mach_header *mH; + unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart; + // long headerBase, headerAddr, headerSize; + unsigned int vmaddr = ~0; + unsigned int vmend = 0; + unsigned long cnt; + long ret = -1; + unsigned int entry = 0; - gBinaryAddress = (unsigned long)binary; + gBinaryAddress = (unsigned long)binary; + mH = (struct mach_header *)(gBinaryAddress); - mH = (struct mach_header *)(gBinaryAddress); - switch (archCpuType) +#if DEBUG + printf("magic: %x\n", (unsigned)mH->magic); + printf("cputype: %x\n", (unsigned)mH->cputype); + printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype); + printf("filetype: %x\n", (unsigned)mH->filetype); + printf("ncmds: %x\n", (unsigned)mH->ncmds); + printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds); + printf("flags: %x\n", (unsigned)mH->flags); + getchar(); +#endif + + switch (archCpuType) { case CPU_TYPE_I386: + if (mH->magic != MH_MAGIC) { error("Mach-O file has bad magic number\n"); return -1; } + cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header); break; + case CPU_TYPE_X86_64: - if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) + + if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) + { return -1; + } + if (mH->magic != MH_MAGIC_64) { error("Mach-O file has bad magic number\n"); return -1; } + cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header_64); break; + default: + error("Unknown CPU type\n"); return -1; } - cmdBase = cmdstart; + cmdBase = cmdstart; + ncmds = mH->ncmds; -#if DEBUG - printf("magic: %x\n", (unsigned)mH->magic); - printf("cputype: %x\n", (unsigned)mH->cputype); - printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype); - printf("filetype: %x\n", (unsigned)mH->filetype); - printf("ncmds: %x\n", (unsigned)mH->ncmds); - printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds); - printf("flags: %x\n", (unsigned)mH->flags); - getchar(); -#endif - - ncmds = mH->ncmds; - for (cnt = 0; cnt < ncmds; cnt++) { cmd = ((long *)cmdBase)[0]; @@ -157,17 +184,21 @@ switch (cmd) { - case LC_SEGMENT_64: + case LC_SEGMENT_64: case LC_SEGMENT: + ret = DecodeSegment(cmdBase, &load_addr, &load_size); + if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) { vmaddr = MIN(vmaddr, load_addr); vmend = MAX(vmend, load_addr + load_size); } break; + + case LC_MAIN: /* Mountain Lion's replacement for LC_UNIXTHREAD */ case LC_UNIXTHREAD: - ret = DecodeUnixThread(cmdBase, &entry); + ret = DecodeUnixThread(cmdBase, &entry); break; case LC_SYMTAB: @@ -175,116 +206,122 @@ default: #if NOTDEF - printf("Ignoring cmd type %d.\n", (unsigned)cmd); + printf("Ignoring cmd type %d.\n", (unsigned)cmd); #endif break; - } + } + + + if (ret != 0) return -1; - if (ret != 0) return -1; - - cmdBase += cmdsize; - } + cmdBase += cmdsize; + } - *rentry = (entry_t)( (unsigned long) entry & 0x3fffffff ); - *rsize = vmend - vmaddr; - *raddr = (char *)vmaddr; + *rentry = (entry_t)( (unsigned long) entry & 0x3fffffff ); + *rsize = vmend - vmaddr; + *raddr = (char *)vmaddr; - cmdBase = cmdstart; - for (cnt = 0; cnt < ncmds; cnt++) + cmdBase = cmdstart; + + for (cnt = 0; cnt < ncmds; cnt++) { cmd = ((long *)cmdBase)[0]; cmdsize = ((long *)cmdBase)[1]; - if(cmd==LC_SYMTAB) - if (DecodeSymbolTable(cmdBase)!=0) - return -1; - - cmdBase += cmdsize; - } + if (cmd == LC_SYMTAB) + { + if (DecodeSymbolTable(cmdBase) != 0) + { + return -1; + } + } + + cmdBase += cmdsize; + } - return ret; + return ret; } -// Private Functions +//============================================================================== +// Private function. + + static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size) { - unsigned long vmaddr, fileaddr; - long vmsize, filesize; - char *segname; - - if (((long *)cmdBase)[0]==LC_SEGMENT_64) - { - struct segment_command_64 *segCmd; - - segCmd = (struct segment_command_64 *)cmdBase; - - vmaddr = (segCmd->vmaddr & 0x3fffffff); - vmsize = segCmd->vmsize; - fileaddr = (gBinaryAddress + segCmd->fileoff); - filesize = segCmd->filesize; + char *segname; + long vmsize, filesize; + unsigned long vmaddr, fileaddr; - segname=segCmd->segname; + if (((long *)cmdBase)[0] == LC_SEGMENT_64) + { + struct segment_command_64 *segCmd; + segCmd = (struct segment_command_64 *)cmdBase; + vmaddr = (segCmd->vmaddr & 0x3fffffff); + vmsize = segCmd->vmsize; + fileaddr = (gBinaryAddress + segCmd->fileoff); + filesize = segCmd->filesize; + segname = segCmd->segname; #ifdef DEBUG printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); getchar(); -#endif - } - else - { - struct segment_command *segCmd; +#endif + } + else + { + struct segment_command *segCmd; - segCmd = (struct segment_command *)cmdBase; - - vmaddr = (segCmd->vmaddr & 0x3fffffff); - vmsize = segCmd->vmsize; - fileaddr = (gBinaryAddress + segCmd->fileoff); - filesize = segCmd->filesize; - - segname=segCmd->segname; + segCmd = (struct segment_command *)cmdBase; + vmaddr = (segCmd->vmaddr & 0x3fffffff); + vmsize = segCmd->vmsize; + fileaddr = (gBinaryAddress + segCmd->fileoff); + filesize = segCmd->filesize; + segname = segCmd->segname; + #ifdef DEBUG - printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", - segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, - (unsigned) segCmd->nsects, (unsigned)segCmd->flags); - getchar(); -#endif - } + printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", + segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); + getchar(); +#endif + } - if (vmsize == 0 || filesize == 0) - { - *load_addr = ~0; - *load_size = 0; - return 0; - } + if (vmsize == 0 || filesize == 0) + { + *load_addr = ~0; + *load_size = 0; + return 0; + } + + if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || + (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) + { + stop("Kernel overflows available space"); + } + + if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) + gHaveKernelCache = true; - if (! ((vmaddr >= KERNEL_ADDR && - (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || - (vmaddr >= HIB_ADDR && - (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { - stop("Kernel overflows available space"); - } - - if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) - gHaveKernelCache = true; - // Copy from file load area. if (vmsize>0 && filesize>0) - bcopy((char *)fileaddr, (char *)vmaddr, vmsize>filesize?filesize:vmsize); + bcopy((char *)fileaddr, (char *)vmaddr, vmsize>filesize?filesize:vmsize); - // Zero space at the end of the segment. - if (vmsize > filesize) - bzero((char *)(vmaddr + filesize), vmsize - filesize); + // Zero space at the end of the segment. + if (vmsize > filesize) + bzero((char *)(vmaddr + filesize), vmsize - filesize); - *load_addr = vmaddr; - *load_size = vmsize; + *load_addr = vmaddr; + *load_size = vmsize; - return 0; + return 0; } + +//============================================================================== + static long DecodeUnixThread(long cmdBase, unsigned int *entry) { switch (archCpuType) @@ -292,10 +329,8 @@ case CPU_TYPE_I386: { i386_thread_state_t *i386ThreadState; - - i386ThreadState = (i386_thread_state_t *) - (cmdBase + sizeof(struct thread_command) + 8); - + i386ThreadState = (i386_thread_state_t *) (cmdBase + sizeof(struct thread_command) + 8); + *entry = i386ThreadState->eip; return 0; } @@ -303,10 +338,7 @@ case CPU_TYPE_X86_64: { x86_thread_state64_t *x86_64ThreadState; - - x86_64ThreadState = (x86_thread_state64_t *) - (cmdBase + sizeof(struct thread_command) + 8); - + x86_64ThreadState = (x86_thread_state64_t *) (cmdBase + sizeof(struct thread_command) + 8); *entry = x86_64ThreadState->rip; return 0; } @@ -317,38 +349,42 @@ } } + +//============================================================================== + static long DecodeSymbolTable(long cmdBase) { - struct symtab_command *symTab, *symTableSave; - long tmpAddr, symsSize, totalSize; - long gSymbolTableAddr; - long gSymbolTableSize; + long tmpAddr, symsSize, totalSize; + long gSymbolTableAddr; + long gSymbolTableSize; - symTab = (struct symtab_command *)cmdBase; + struct symtab_command *symTab, *symTableSave; + + symTab = (struct symtab_command *)cmdBase; #if DEBUG - printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", - symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); - getchar(); + + printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); + getchar(); #endif - symsSize = symTab->stroff - symTab->symoff; - totalSize = symsSize + symTab->strsize; + symsSize = symTab->stroff - symTab->symoff; + totalSize = symsSize + symTab->strsize; - gSymbolTableSize = totalSize + sizeof(struct symtab_command); - gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize); - // Add the SymTab to the memory-map. - AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); + gSymbolTableSize = totalSize + sizeof(struct symtab_command); + gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize); + // Add the SymTab to the memory-map. + AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); - symTableSave = (struct symtab_command *)gSymbolTableAddr; - tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command); + symTableSave = (struct symtab_command *)gSymbolTableAddr; + tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command); - symTableSave->symoff = tmpAddr; - symTableSave->nsyms = symTab->nsyms; - symTableSave->stroff = tmpAddr + symsSize; - symTableSave->strsize = symTab->strsize; + symTableSave->symoff = tmpAddr; + symTableSave->nsyms = symTab->nsyms; + symTableSave->stroff = tmpAddr + symsSize; + symTableSave->strsize = symTab->strsize; - bcopy((char *)(gBinaryAddress + symTab->symoff), - (char *)tmpAddr, totalSize); - return 0; + bcopy((char *)(gBinaryAddress + symTab->symoff), (char *)tmpAddr, totalSize); + + return 0; } Index: branches/ErmaC/Trunk/i386/libsaio/sl.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/sl.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/sl.h (revision 2037) @@ -38,23 +38,24 @@ #define SWAP_LE64(x) OSSwapLittleToHostInt64(x) // File Permissions and Types -enum { - kPermOtherExecute = 1 << 0, - kPermOtherWrite = 1 << 1, - kPermOtherRead = 1 << 2, - kPermGroupExecute = 1 << 3, - kPermGroupWrite = 1 << 4, - kPermGroupRead = 1 << 5, - kPermOwnerExecute = 1 << 6, - kPermOwnerWrite = 1 << 7, - kPermOwnerRead = 1 << 8, - kPermMask = 0x1FF, - kOwnerNotRoot = 1 << 9, - kFileTypeUnknown = 0x0 << 16, - kFileTypeFlat = 0x1 << 16, - kFileTypeDirectory = 0x2 << 16, - kFileTypeLink = 0x3 << 16, - kFileTypeMask = 0x3 << 16 +enum +{ + kPermOtherExecute = 1 << 0, + kPermOtherWrite = 1 << 1, + kPermOtherRead = 1 << 2, + kPermGroupExecute = 1 << 3, + kPermGroupWrite = 1 << 4, + kPermGroupRead = 1 << 5, + kPermOwnerExecute = 1 << 6, + kPermOwnerWrite = 1 << 7, + kPermOwnerRead = 1 << 8, + kPermMask = 0x1FF, + kOwnerNotRoot = 1 << 9, + kFileTypeUnknown = 0x0 << 16, + kFileTypeFlat = 0x1 << 16, + kFileTypeDirectory = 0x2 << 16, + kFileTypeLink = 0x3 << 16, + kFileTypeMask = 0x3 << 16 }; #define Seek(c, p) diskSeek(c, p); Index: branches/ErmaC/Trunk/i386/libsaio/cpu.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/cpu.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/cpu.c (revision 2037) @@ -378,20 +378,23 @@ fsbFrequency = 0; cpuFrequency = 0; - if ((p->CPU.Vendor == CPUID_VENDOR_INTEL) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) { + if ((p->CPU.Vendor == CPUID_VENDOR_INTEL) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) + { int intelCPU = p->CPU.Model; - if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) { + if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) + { /* Nehalem CPU model */ if (p->CPU.Family == 0x06 && (p->CPU.Model == CPU_MODEL_NEHALEM || - p->CPU.Model == CPU_MODEL_FIELDS || - p->CPU.Model == CPU_MODEL_DALES || + p->CPU.Model == CPU_MODEL_FIELDS || + p->CPU.Model == CPU_MODEL_DALES || p->CPU.Model == CPU_MODEL_DALES_32NM || p->CPU.Model == CPU_MODEL_WESTMERE || p->CPU.Model == CPU_MODEL_NEHALEM_EX || p->CPU.Model == CPU_MODEL_WESTMERE_EX || p->CPU.Model == CPU_MODEL_SANDYBRIDGE || p->CPU.Model == CPU_MODEL_JAKETOWN || - p->CPU.Model == CPU_MODEL_IVYBRIDGE )) { + p->CPU.Model == CPU_MODEL_IVYBRIDGE )) + { msr = rdmsr64(MSR_PLATFORM_INFO); DBG("msr(%d): platform_info %08x\n", __LINE__, bitfield(msr, 31, 0)); bus_ratio_max = bitfield(msr, 14, 8); @@ -420,18 +423,21 @@ } } - if (bus_ratio_max) { + if (bus_ratio_max) + { fsbFrequency = (tscFrequency / bus_ratio_max); } //valv: Turbo Ratio Limit - if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) { + if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) + { msr = rdmsr64(MSR_TURBO_RATIO_LIMIT); cpuFrequency = bus_ratio_max * fsbFrequency; max_ratio = bus_ratio_max * 10; } else { cpuFrequency = tscFrequency; } - if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) { + if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) + { max_ratio = atoi(newratio); max_ratio = (max_ratio * 10); if (len >= 3) max_ratio = (max_ratio + 5); @@ -439,7 +445,8 @@ verbose("Bus-Ratio: min=%d, max=%s\n", bus_ratio_min, newratio); // extreme overclockers may love 320 ;) - if ((max_ratio >= min_ratio) && (max_ratio <= 320)) { + if ((max_ratio >= min_ratio) && (max_ratio <= 320)) + { cpuFrequency = (fsbFrequency * max_ratio) / 10; if (len >= 3) maxdiv = 1; else maxdiv = 0; @@ -476,18 +483,18 @@ } if (maxcoef) + { + if (maxdiv) { - if (maxdiv) - { - fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); - } else { - fsbFrequency = (tscFrequency / maxcoef); + fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); + } else { + fsbFrequency = (tscFrequency / maxcoef); } - if (currdiv) - { - cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); - } else { - cpuFrequency = (fsbFrequency * currcoef); + if (currdiv) + { + cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); + } else { + cpuFrequency = (fsbFrequency * currcoef); } DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); } Index: branches/ErmaC/Trunk/i386/libsaio/platform.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/platform.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/platform.h (revision 2037) @@ -102,21 +102,27 @@ /* Size of SMBIOS UUID in bytes */ #define UUID_LEN 16 -typedef struct _RamSlotInfo_t { - uint32_t ModuleSize; // Size of Module in MB - uint32_t Frequency; // in Mhz - const char* Vendor; - const char* PartNo; - const char* SerialNo; - char* spd; // SPD Dump - bool InUse; - uint8_t Type; - uint8_t BankConnections; // table type 6, see (3.3.7) - uint8_t BankConnCnt; +typedef struct _RamSlotInfo_t +{ + uint32_t ModuleSize; // Size of Module in MB + uint32_t Frequency; // in Mhz + const char* Vendor; + const char* PartNo; + const char* SerialNo; + char* spd; // SPD Dump + bool InUse; + uint8_t Type; + uint8_t BankConnections; // table type 6, see (3.3.7) + uint8_t BankConnCnt; } RamSlotInfo_t; -typedef struct _PlatformInfo_t { - struct CPU { + +//============================================================================== + +typedef struct _PlatformInfo_t +{ + struct CPU + { uint32_t Features; // CPU Features like MMX, SSE2, VT, MobileCPU uint32_t Vendor; // Vendor uint32_t Signature; // Signature @@ -140,7 +146,8 @@ uint32_t CPUID[CPUID_MAX][4]; // CPUID 0..4, 80..81 Raw Values } CPU; - struct RAM { + struct RAM + { uint64_t Frequency; // Ram Frequency uint32_t Divider; // Memory divider uint8_t CAS; // CAS 1/2/2.5/3/4/5/6/7 @@ -153,7 +160,8 @@ RamSlotInfo_t DIMM[MAX_RAM_SLOTS]; // Information about each slot } RAM; - struct DMI { + struct DMI + { int MaxMemorySlots; // number of memory slots populated by SMBIOS int CntMemorySlots; // number of memory slots counted int MemoryModules; // number of memory modules installed Index: branches/ErmaC/Trunk/i386/libsaio/disk.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/disk.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/disk.c (revision 2037) @@ -125,7 +125,7 @@ extern void spinActivityIndicator(int sectors); -//========================================================================== +//============================================================================== static int getDriveInfo(int biosdev, struct driveInfo *dip) { @@ -158,7 +158,7 @@ if (!cached_di.valid || biosdev != cached_di.biosdev) { - cc = get_drive_info(biosdev, &cached_di); + cc = get_drive_info(biosdev, &cached_di); if (cc < 0) { @@ -173,7 +173,8 @@ return 0; } -//========================================================================== + +//============================================================================== // Maps (E)BIOS return codes to message strings. struct NamedValue @@ -182,6 +183,9 @@ const char * name; }; + +//============================================================================== + static const char * getNameForValue(const struct NamedValue * nameTable, unsigned char value) { const struct NamedValue * np; @@ -193,12 +197,14 @@ return np->name; } } + return NULL; } #define ECC_CORRECTED_ERR 0x11 -static const struct NamedValue bios_errors[] = { +static const struct NamedValue bios_errors[] = +{ { 0x10, "Media error" }, { 0x11, "Corrected ECC error" }, { 0x20, "Controller or device error" }, @@ -208,6 +214,12 @@ { 0x00, 0 } }; + +static bool cache_valid = false; + + +//============================================================================== + static const char * bios_error(int errnum) { static char errorstr[] = "Error 0x00"; @@ -224,14 +236,13 @@ return errorstr; // No string, print error code only } -//========================================================================== + +//============================================================================== // Use BIOS INT13 calls to read the sector specified. This function will also // perform read-ahead to cache a few subsequent sector to the sector cache. // // Returns 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call. -static bool cache_valid = false; - static int Biosread(int biosdev, unsigned long long secno) { static int xbiosdev, xcyl, xhead; @@ -249,8 +260,7 @@ } if (di.no_emulation) { - /* Always assume 2k block size; BIOS may lie about geometry */ - bps = 2048; + bps = 2048; /* Always assume 2K block size since the BIOS may lie about the geometry */ } else { @@ -284,8 +294,7 @@ { if (rc == ECC_CORRECTED_ERR) { - /* Ignore corrected ECC errors */ - rc = 0; + rc = 0; /* Ignore corrected ECC errors */ break; } @@ -305,6 +314,7 @@ if (cache_valid && (biosdev == xbiosdev) && (cyl == xcyl) && (head == xhead) && ((unsigned int)sec >= xsec) && ((unsigned int)sec < (xsec + xnsecs))) + { // this sector is in trackbuf cache biosbuf = trackbuf + (BPS * (sec - xsec)); @@ -324,13 +334,11 @@ { if (rc == ECC_CORRECTED_ERR) { - /* Ignore corrected ECC errors */ - rc = 0; + rc = 0; /* Ignore corrected ECC errors */ break; } error(" BIOS read error: %s\n", bios_error(rc), rc); - error(" Block %d, Cyl %d Head %d Sector %d\n", - secno, cyl, head, sec); + error(" Block %d, Cyl %d Head %d Sector %d\n", secno, cyl, head, sec); sleep(1); } } @@ -344,21 +352,23 @@ biosbuf = trackbuf + (secno % divisor) * BPS; xbiosdev = biosdev; - + spinActivityIndicator(xnsecs); return rc; } -//========================================================================== +//============================================================================== + int testBiosread(int biosdev, unsigned long long secno) { return Biosread(biosdev, secno); } -//========================================================================== +//============================================================================== + static int readBytes(int biosdev, unsigned long long blkno, unsigned int byteoff, unsigned int byteCount, void * buffer) { // ramdisks require completely different code for reading. @@ -380,6 +390,7 @@ if (error) { DEBUG_DISK(("error\n")); + return (-1); } @@ -394,7 +405,7 @@ return 0; } -//========================================================================== +//============================================================================== static int isExtendedFDiskPartition( const struct fdisk_part * part ) { @@ -417,7 +428,7 @@ return 0; } -//========================================================================== +//============================================================================== static int getNextFDiskPartition( int biosdev, int * partno, const struct fdisk_part ** outPart ) @@ -506,7 +517,7 @@ return (part != NULL); } -//========================================================================== +//============================================================================== static BVRef newFDiskBVRef( int biosdev, int partno, unsigned int blkoff, const struct fdisk_part * part, @@ -579,7 +590,7 @@ } } -//========================================================================== +//============================================================================== BVRef newAPMBVRef( int biosdev, int partno, unsigned int blkoff, const DPME * part, @@ -592,63 +603,63 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); - if ( bvr ) - { - bzero(bvr, sizeof(*bvr)); + BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + if ( bvr ) + { + bzero(bvr, sizeof(*bvr)); - bvr->biosdev = biosdev; - bvr->part_no = partno; - bvr->part_boff = blkoff; - bvr->fs_loadfile = loadFunc; - bvr->fs_readfile = readFunc; - bvr->fs_getdirentry = getdirFunc; - bvr->fs_getfileblock= getBlockFunc; - bvr->fs_getuuid = getUUIDFunc; - bvr->description = getDescriptionFunc; - bvr->type = type; - bvr->bv_free = bvFreeFunc; - strlcpy(bvr->name, part->dpme_name, DPISTRLEN); - strlcpy(bvr->type_name, part->dpme_type, DPISTRLEN); + bvr->biosdev = biosdev; + bvr->part_no = partno; + bvr->part_boff = blkoff; + bvr->fs_loadfile = loadFunc; + bvr->fs_readfile = readFunc; + bvr->fs_getdirentry = getdirFunc; + bvr->fs_getfileblock= getBlockFunc; + bvr->fs_getuuid = getUUIDFunc; + bvr->description = getDescriptionFunc; + bvr->type = type; + bvr->bv_free = bvFreeFunc; + strlcpy(bvr->name, part->dpme_name, DPISTRLEN); + strlcpy(bvr->type_name, part->dpme_type, DPISTRLEN); - /* - if ( part->bootid & FDISK_ACTIVE ) - bvr->flags |= kBVFlagPrimary; - */ + /* + if ( part->bootid & FDISK_ACTIVE ) + bvr->flags |= kBVFlagPrimary; + */ - // Probe the filesystem. + // Probe the filesystem. - if ( initFunc ) - { - bvr->flags |= kBVFlagNativeBoot | kBVFlagBootable | kBVFlagSystemVolume; + if ( initFunc ) + { + bvr->flags |= kBVFlagNativeBoot | kBVFlagBootable | kBVFlagSystemVolume; - if ( probe && initFunc( bvr ) != 0 ) - { - // filesystem probe failed. + if ( probe && initFunc( bvr ) != 0 ) + { + // filesystem probe failed. - DEBUG_DISK(("%s: failed probe on dev %x part %d\n", __FUNCTION__, biosdev, partno)); + DEBUG_DISK(("%s: failed probe on dev %x part %d\n", __FUNCTION__, biosdev, partno)); - (*bvr->bv_free)(bvr); - bvr = NULL; - } - } - /* - else if ( readBootSector( biosdev, blkoff, (void *)0x7e00 ) == 0 ) - { - bvr->flags |= kBVFlagForeignBoot; - } - */ - else - { - (*bvr->bv_free)(bvr); - bvr = NULL; - } - } - if (bvr) bvr->flags |= bvrFlags; - return bvr; + (*bvr->bv_free)(bvr); + bvr = NULL; + } + } + /* + else if ( readBootSector( biosdev, blkoff, (void *)0x7e00 ) == 0 ) + { + bvr->flags |= kBVFlagForeignBoot; + } + */ + else + { + (*bvr->bv_free)(bvr); + bvr = NULL; + } + } + if (bvr) bvr->flags |= bvrFlags; + return bvr; } -//========================================================================== +//============================================================================== // GUID's in LE form: // http://en.wikipedia.org/wiki/GUID_Partition_Table @@ -673,7 +684,7 @@ // 4C616265-6C00-11AA-AA11-00306543ECAC - Apple Label // 5265636F-7665-11AA-AA11-00306543ECAC - Apple TV Recovery partition // 53746F72-6167-11AA-AA11-00306543ECAC - Apple Core Storage (i.e. Lion FileVault) partition (Apple_Boot Recovery HD) -// EFI_GUID const GPT_RECOVERY_GUID = { 0x53746F72, 0x6167, 0x11AA, { 0xAA, 0x11, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC } }; +EFI_GUID const GPT_CORESTORAGE_GUID = { 0x53746F72, 0x6167, 0x11AA, { 0xAA, 0x11, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC } }; BVRef newGPTBVRef( int biosdev, int partno, unsigned int blkoff, const gpt_ent * part, @@ -750,7 +761,7 @@ return bvr; } -//========================================================================== +//============================================================================== /* A note on partition numbers: * IOKit makes the primary partitions numbers 1-4, and then @@ -1039,7 +1050,7 @@ return map ? map->bvr : NULL; } -//========================================================================== +//============================================================================== static BVRef diskScanAPMBootVolumes( int biosdev, int * countPtr ) { @@ -1077,7 +1088,7 @@ blksize = BPS; factor = 1; } - + do { // Create a new mapping. @@ -1148,10 +1159,8 @@ return map ? map->bvr : NULL; } -//========================================================================== +//============================================================================== -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* * Trying to figure out the filsystem type of a given partition. */ @@ -1224,9 +1233,9 @@ return efi_guid_is_null((EFI_GUID const*)partition->ent_type) ? false : true; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +//============================================================================== -static BVRef diskScanGPTBootVolumes( int biosdev, int * countPtr ) +static BVRef diskScanGPTBootVolumes(int biosdev, int * countPtr) { struct DiskBVMap * map = NULL; void *buffer = malloc(BPS); @@ -1528,7 +1537,7 @@ return valid; } -//========================================================================== +//============================================================================== static void scanFSLevelBVRSettings(BVRef chain) { @@ -1841,7 +1850,7 @@ return ret; } -//========================================================================== +//============================================================================== static const struct NamedValue fdiskTypes[] = { @@ -1863,7 +1872,7 @@ { 0x00, 0 } /* must be last */ }; -//========================================================================== +//============================================================================== bool matchVolumeToString( BVRef bvr, const char* match, long matchLen) { @@ -1883,22 +1892,22 @@ sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) return true; - + // Try to match volume UUID. if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0) { if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) return true; } - + // Try to match volume label (always quoted). if ( bvr->description ) { bvr->description(bvr, testStr, sizeof(testStr)-1); if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) - return true; + return true; } - + return false; } @@ -2025,7 +2034,9 @@ sprintf(bvr->label, p); } -//========================================================================== + +//============================================================================== + int readBootSector(int biosdev, unsigned int secno, void * buffer) { int error; @@ -2043,7 +2054,7 @@ } } - bootSector = gBootSector; + bootSector = gBootSector; } error = readBytes(biosdev, secno, 0, BPS, bootSector); @@ -2097,7 +2108,8 @@ return 0; } -//========================================================================== + +//============================================================================== // Handle seek request from filesystem modules. void diskSeek(BVRef bvr, long long position) @@ -2106,16 +2118,13 @@ bvr->fs_byteoff = position % BPS; } -//========================================================================== + +//============================================================================== // Handle read request from filesystem modules. -int diskRead( BVRef bvr, long addr, long length ) +int diskRead(BVRef bvr, long addr, long length) { - return readBytes( bvr->biosdev, - bvr->fs_boff + bvr->part_boff, - bvr->fs_byteoff, - length, - (void *) addr ); + return readBytes(bvr->biosdev, bvr->fs_boff + bvr->part_boff, bvr->fs_byteoff, length, (void *) addr); } int rawDiskRead( BVRef bvr, unsigned int secno, void *buffer, unsigned int len ) Index: branches/ErmaC/Trunk/i386/libsaio/cache.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/cache.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/cache.c (revision 2037) @@ -30,10 +30,11 @@ #include // #include -struct CacheEntry { - CICell ih; - long time; - long long offset; +struct CacheEntry +{ + CICell ih; + long time; + long long offset; }; typedef struct CacheEntry CacheEntry; @@ -48,17 +49,17 @@ static long gCacheTime; #ifdef __i386__ -static CacheEntry *gCacheEntries; -static char *gCacheBuffer; + static CacheEntry *gCacheEntries; + static char *gCacheBuffer; #else -static CacheEntry gCacheEntries[kCacheMaxEntries]; -static char gCacheBuffer[kCacheSize]; + static CacheEntry gCacheEntries[kCacheMaxEntries]; + static char gCacheBuffer[kCacheSize]; #endif #if CACHE_STATS -unsigned long gCacheHits; -unsigned long gCacheMisses; -unsigned long gCacheEvicts; + unsigned long gCacheHits; + unsigned long gCacheMisses; + unsigned long gCacheEvicts; #endif void CacheReset() @@ -70,29 +71,40 @@ { #ifdef __i386__ if ((ih == gCacheIH) && (blockSize == gCacheBlockSize)) + { return; + } #endif - if ((blockSize < kCacheMinBlockSize) || - (blockSize > kCacheMaxBlockSize)) + if ((blockSize < kCacheMinBlockSize) || (blockSize > kCacheMaxBlockSize)) + { return; + } gCacheBlockSize = blockSize; gCacheNumEntries = kCacheSize / gCacheBlockSize; gCacheTime = 0; #if CACHE_STATS - gCacheHits = 0; - gCacheMisses = 0; - gCacheEvicts = 0; + gCacheHits = 0; + gCacheMisses = 0; + gCacheEvicts = 0; #endif gCacheIH = ih; #ifdef __i386__ - if (!gCacheBuffer) gCacheBuffer = (char *) malloc(kCacheSize); - if (!gCacheEntries) gCacheEntries = (CacheEntry *) malloc(kCacheMaxEntries * sizeof(CacheEntry)); - if ( !gCacheBuffer || !gCacheEntries ) + if (!gCacheBuffer) + { + gCacheBuffer = (char *) malloc(kCacheSize); + } + + if (!gCacheEntries) + { + gCacheEntries = (CacheEntry *) malloc(kCacheMaxEntries * sizeof(CacheEntry)); + } + + if (!gCacheBuffer || !gCacheEntries) { gCacheIH = 0; // invalidate cache return; @@ -102,25 +114,29 @@ bzero(gCacheEntries, kCacheMaxEntries * sizeof(CacheEntry)); } -long CacheRead( CICell ih, char * buffer, long long offset, - long length, long cache ) +long CacheRead(CICell ih, char * buffer, long long offset, long length, long cache) { - long cnt, oldestEntry = 0, oldestTime, loadCache = 0; + long cnt, oldestEntry = 0, oldestTime, loadCache = 0; CacheEntry *entry; // See if the data can be cached. - if (cache && (gCacheIH == ih) && (length == gCacheBlockSize)) { + if (cache && (gCacheIH == ih) && (length == gCacheBlockSize)) + { // Look for the data in the cache. - for (cnt = 0; cnt < gCacheNumEntries; cnt++) { + for (cnt = 0; cnt < gCacheNumEntries; cnt++) + { entry = &gCacheEntries[cnt]; - if ((entry->ih == ih) && (entry->offset == offset)) { + + if ((entry->ih == ih) && (entry->offset == offset)) + { entry->time = ++gCacheTime; break; } } // If the data was found copy it to the caller. - if (cnt != gCacheNumEntries) { + if (cnt != gCacheNumEntries) + { bcopy(gCacheBuffer + cnt * gCacheBlockSize, buffer, gCacheBlockSize); #if CACHE_STATS gCacheHits++; @@ -135,28 +151,40 @@ // Read the data from the disk. Seek(ih, offset); Read(ih, (long)buffer, length); + #if CACHE_STATS - if (cache) gCacheMisses++; + if (cache) + { + gCacheMisses++; + } #endif // Put the data from the disk in the cache if needed. - if (loadCache) { + if (loadCache) + { // Find a free entry. oldestTime = gCacheTime; - for (cnt = 0; cnt < gCacheNumEntries; cnt++) { + + for (cnt = 0; cnt < gCacheNumEntries; cnt++) + { entry = &gCacheEntries[cnt]; // Found a free entry. - if (entry->ih == 0) break; + if (entry->ih == 0) + { + break; + } - if (entry->time < oldestTime) { + if (entry->time < oldestTime) + { oldestTime = entry->time; oldestEntry = cnt; } } // If no free entry was found, use the oldest. - if (cnt == gCacheNumEntries) { + if (cnt == gCacheNumEntries) + { cnt = oldestEntry; #if CACHE_STATS gCacheEvicts++; Index: branches/ErmaC/Trunk/i386/libsaio/pci.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/pci.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/pci.c (revision 2037) @@ -106,7 +106,7 @@ case PCI_HEADER_TYPE_CARDBUS: secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS); if (secondary_bus != 0) - { + { scan_pci_bus(new, secondary_bus); } break; Index: branches/ErmaC/Trunk/i386/libsaio/stringTable.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/stringTable.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/stringTable.c (revision 2037) @@ -20,11 +20,9 @@ * under the License. * * @APPLE_LICENSE_HEADER_END@ + * + * Copyright 1993 NeXT, Inc. All rights reserved. */ -/* - * Copyright 1993 NeXT, Inc. - * All rights reserved. - */ #include "bootstruct.h" #include "libsaio.h" @@ -135,34 +133,34 @@ return true; } -char * -newStringFromList( - char **list, - int *size -) +char *newStringFromList(char **list, int *size) { - char *begin = *list, *end; - char *newstr; - int newsize = *size; - int bufsize; + char *begin = *list, *end; + char *newstr; + int newsize = *size; + int bufsize; - while (*begin && newsize && isspace(*begin)) { - begin++; - newsize--; - } - end = begin; - while (*end && newsize && !isspace(*end)) { - end++; - newsize--; - } - if (begin == end) - return 0; - bufsize = end - begin + 1; - newstr = malloc(bufsize); - strlcpy(newstr, begin, bufsize); - *list = end; - *size = newsize; - return newstr; + while (*begin && newsize && isspace(*begin)) + { + begin++; + newsize--; + } + end = begin; + while (*end && newsize && !isspace(*end)) + { + end++; + newsize--; + } + if (begin == end) + { + return 0; + } + bufsize = end - begin + 1; + newstr = malloc(bufsize); + strlcpy(newstr, begin, bufsize); + *list = end; + *size = newsize; + return newstr; } #endif @@ -194,22 +192,26 @@ bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size) { - if (config->dictionary != 0 ) { + if (config->dictionary != 0 ) + { // Look up key in XML dictionary TagPtr value; value = XMLGetProperty(config->dictionary, key); - if (value != 0) { - if (value->type != kTagTypeString) { - error("Non-string tag '%s' found in config file\n", - key); + if (value != 0) + { + if (value->type != kTagTypeString) + { + error("Non-string tag '%s' found in config file\n", key); return false; } *val = value->string; *size = strlen(value->string); return true; } - } else { - + } + else + { + // Legacy plist-style table } @@ -224,42 +226,44 @@ * in the string table matching 'key'. Also translates * \n escapes in the string. */ -char *newStringForStringTableKey( - char *table, - char *key, - config_file_t *config -) +char *newStringForStringTableKey(char *table, char *key, config_file_t *config) { - const char *val; - char *newstr, *p; - int size; + const char *val; + char *newstr, *p; + int size; - if (getValueForConfigTableKey(config, key, &val, &size)) { - newstr = (char *)malloc(size+1); - for (p = newstr; size; size--, p++, val++) { - if ((*p = *val) == '\\') { - switch (*++val) { - case 'r': - *p = '\r'; - break; - case 'n': - *p = '\n'; - break; - case 't': - *p = '\t'; - break; - default: - *p = *val; - break; + if (getValueForConfigTableKey(config, key, &val, &size)) + { + newstr = (char *)malloc(size+1); + for (p = newstr; size; size--, p++, val++) + { + if ((*p = *val) == '\\') + { + switch (*++val) + { + case 'r': + *p = '\r'; + break; + case 'n': + *p = '\n'; + break; + case 't': + *p = '\t'; + break; + default: + *p = *val; + break; + } + size--; } - size--; - } } *p = '\0'; return newstr; - } else { - return 0; - } + } + else + { + return 0; + } } #endif @@ -267,17 +271,20 @@ char * newStringForKey(char *key, config_file_t *config) { - const char *val; - char *newstr; - int size; + const char *val; + char *newstr; + int size; - if (getValueForKey(key, &val, &size, config) && size) { - newstr = (char *)malloc(size + 1); - strlcpy(newstr, val, size + 1); - return newstr; - } else { - return 0; - } + if (getValueForKey(key, &val, &size, config) && size) + { + newstr = (char *)malloc(size + 1); + strlcpy(newstr, val, size + 1); + return newstr; + } + else + { + return 0; + } } /* parse a command line @@ -440,22 +447,22 @@ { if (*val < '0' || *val > '9') return false; - + sum = (sum * 10) + (*val++ - '0'); } if (percentage) sum = ( dimension_max * sum ) / 100; - + // calculate offset from opposite origin if (negative) sum = ( ( dimension_max - object_size ) - sum ); } else { - + // null value calculate center sum = ( dimension_max - object_size ) / 2; - + } *value = (uint16_t) sum; Index: branches/ErmaC/Trunk/i386/libsaio/biosfn.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/biosfn.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/biosfn.c (revision 2037) @@ -48,57 +48,75 @@ static biosBuf_t bb; + +//============================================================================== + int bgetc(void) { - /* Poll for the next character. Most real BIOS do not need this as the - INT 16h,AH=0h function will block until one is received. - Unfortunately, Apple's EFI CSM will never wake up. This idea is lifted - from the grub-a20.patch to GRUB's stage2/asm.S file. - */ - while(!readKeyboardStatus()) - ; - bb.intno = 0x16; - bb.eax.r.h = 0x00; - bios(&bb); - return bb.eax.rr; + /* Poll for the next character. Most real BIOS do not need this as the + INT 16h,AH=0h function will block until one is received. + Unfortunately, Apple's EFI CSM will never wake up. This idea is lifted + from the grub-a20.patch to GRUB's stage2/asm.S file. + */ + while(!readKeyboardStatus()); + + bb.intno = 0x16; + bb.eax.r.h = 0x00; + bios(&bb); + + return bb.eax.rr; } + +//============================================================================== + int readKeyboardStatus(void) { - bb.intno = 0x16; - bb.eax.r.h = 0x01; - bios(&bb); - if (bb.flags.zf) { - return 0; - } else { - return bb.eax.rr; - } + bb.intno = 0x16; + bb.eax.r.h = 0x01; + bios(&bb); + + if (bb.flags.zf) + { + return 0; + } + else + { + return bb.eax.rr; + } } int readKeyboardShiftFlags(void) { - bb.intno = 0x16; - bb.eax.r.h = 0x02; - bios(&bb); - return bb.eax.r.l; + bb.intno = 0x16; + bb.eax.r.h = 0x02; + bios(&bb); + return bb.eax.r.l; } + +//============================================================================== + unsigned int time18(void) { - union { - struct { - unsigned int low:16; - unsigned int high:16; - } s; - unsigned int i; - } time; + union + { + struct + { + unsigned int low:16; + unsigned int high:16; + } s; + + unsigned int i; + } time; - bb.intno = 0x1a; - bb.eax.r.h = 0x00; - bios(&bb); - time.s.low = bb.edx.rr; - time.s.high = bb.ecx.rr; - return time.i; + bb.intno = 0x1a; + bb.eax.r.h = 0x00; + bios(&bb); + time.s.low = bb.edx.rr; + time.s.high = bb.ecx.rr; + + return time.i; } #if 0 @@ -165,314 +183,367 @@ unsigned long * conMemSizePtr, unsigned long * extMemSizePtr ) { - #define kMemoryMapSignature 'SMAP' - #define kDescriptorSizeMin 20 + #define kMemoryMapSignature 'SMAP' + #define kDescriptorSizeMin 20 - MemoryRange * range = (MemoryRange *)BIOS_ADDR; - unsigned long count = 0; - // unsigned long rerangedCount; - unsigned long long conMemSize = 0; - unsigned long long extMemSize = 0; + MemoryRange * range = (MemoryRange *)BIOS_ADDR; + unsigned long count = 0; + // unsigned long rerangedCount; + unsigned long long conMemSize = 0; + unsigned long long extMemSize = 0; - // Prepare for the INT15 E820h call. Each call returns a single - // memory range. A continuation value is returned that must be - // provided on a subsequent call to fetch the next range. - // - // Certain BIOSes (Award 6.00PG) expect the upper word in EAX - // to be cleared on entry, otherwise only a single range will - // be reported. - // - // Some BIOSes will simply ignore the value of ECX on entry. - // Probably best to keep its value at 20 to avoid surprises. + // Prepare for the INT15 E820h call. Each call returns a single + // memory range. A continuation value is returned that must be + // provided on a subsequent call to fetch the next range. + // + // Certain BIOSes (Award 6.00PG) expect the upper word in EAX + // to be cleared on entry, otherwise only a single range will + // be reported. + // + // Some BIOSes will simply ignore the value of ECX on entry. + // Probably best to keep its value at 20 to avoid surprises. - //printf("Get memory map 0x%x, %d\n", rangeArray); getchar(); - if (maxRangeCount > (BIOS_LEN / sizeof(MemoryRange))) { - maxRangeCount = (BIOS_LEN / sizeof(MemoryRange)); - } - bb.ebx.rx = 0; // Initial continuation value must be zero. + //printf("Get memory map 0x%x, %d\n", rangeArray); getchar(); + if (maxRangeCount > (BIOS_LEN / sizeof(MemoryRange))) + { + maxRangeCount = (BIOS_LEN / sizeof(MemoryRange)); + } + bb.ebx.rx = 0; // Initial continuation value must be zero. - while ( count < maxRangeCount ) - { - bb.intno = 0x15; - bb.eax.rx = 0xe820; - bb.ecx.rx = kDescriptorSizeMin; - bb.edx.rx = kMemoryMapSignature; - bb.edi.rr = NORMALIZED_OFFSET( (unsigned long) range ); - bb.es = NORMALIZED_SEGMENT( (unsigned long) range ); - bios(&bb); + while (count < maxRangeCount) + { + bb.intno = 0x15; + bb.eax.rx = 0xe820; + bb.ecx.rx = kDescriptorSizeMin; + bb.edx.rx = kMemoryMapSignature; + bb.edi.rr = NORMALIZED_OFFSET( (unsigned long) range ); + bb.es = NORMALIZED_SEGMENT( (unsigned long) range ); + bios(&bb); - // Check for errors. + // Check for errors. - if ( bb.flags.cf - || bb.eax.rx != kMemoryMapSignature - || bb.ecx.rx != kDescriptorSizeMin ) { - //printf("Got an error %x %x %x\n", bb.flags.cf, - // bb.eax.rx, bb.ecx.rx); - break; - } + if ( bb.flags.cf || bb.eax.rx != kMemoryMapSignature || bb.ecx.rx != kDescriptorSizeMin ) + { + //printf("Got an error %x %x %x\n", bb.flags.cf, + // bb.eax.rx, bb.ecx.rx); + break; + } - // Tally up the conventional/extended memory sizes. + // Tally up the conventional/extended memory sizes. - if ( range->type == kMemoryRangeUsable || - range->type == kMemoryRangeACPI || - range->type == kMemoryRangeNVS ) - { - // Tally the conventional memory ranges. - if ( range->base + range->length <= 0xa0000 ) { - conMemSize += range->length; - } + if (range->type == kMemoryRangeUsable || range->type == kMemoryRangeACPI || range->type == kMemoryRangeNVS ) + { + // Tally the conventional memory ranges. + if (range->base + range->length <= 0xa0000) + { + conMemSize += range->length; + } - // Record the top of extended memory. - if ( range->base >= EXTENDED_ADDR ) { - extMemSize += range->length; - } - } + // Record the top of extended memory. + if (range->base >= EXTENDED_ADDR) + { + extMemSize += range->length; + } + } - range++; - count++; + range++; + count++; - // Is this the last address range? + // Is this the last address range? - if ( bb.ebx.rx == 0 ) { - //printf("last range\n"); - break; - } - } - *conMemSizePtr = conMemSize / 1024; // size in KB - *extMemSizePtr = extMemSize / 1024; // size in KB + if ( bb.ebx.rx == 0 ) + { + //printf("last range\n"); + break; + } + } + *conMemSizePtr = conMemSize / 1024; // size in KB + *extMemSizePtr = extMemSize / 1024; // size in KB #if 0 - rerangedCount = rerangeMemoryMap(count); - range += rerangedCount - count; + rerangedCount = rerangeMemoryMap(count); + range += rerangedCount - count; #endif - // Copy out data - bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR)); + // Copy out data + bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR)); #if DEBUG - { - int i; - printf("%d total ranges\n", count); getchar(); - for (i=0, range = rangeArray; itype, (unsigned int)range->base, (unsigned int)range->length); getchar(); - } - } + { + int i; + printf("%d total ranges\n", count); + + getchar(); + + for (i = 0, range = rangeArray; itype, (unsigned int)range->base, (unsigned int)range->length); + getchar(); + } + } #endif - return count; + return count; } + +//============================================================================== + + unsigned long getExtendedMemorySize() { - // Get extended memory size for large configurations. Not used unless - // the INT15, E820H call (Get System Address Map) failed. - // - // Input: - // - // AX Function Code E801h - // - // Outputs: - // - // CF Carry Flag Carry cleared indicates no error. - // AX Extended 1 Number of contiguous KB between 1 and 16 MB, - // maximum 0x3C00 = 15 MB. - // BX Extended 2 Number of contiguous 64 KB blocks between - // 16 MB and 4 GB. - // CX Configured 1 Number of contiguous KB between 1 and 16 MB, - // maximum 0x3C00 = 15 MB. - // DX Configured 2 Number of contiguous 64 KB blocks between - // 16 MB and 4 GB. + // Get extended memory size for large configurations. Not used unless + // the INT15, E820H call (Get System Address Map) failed. + // + // Input: + // + // AX Function Code E801h + // + // Outputs: + // + // CF Carry Flag Carry cleared indicates no error. + // AX Extended 1 Number of contiguous KB between 1 and 16 MB, + // maximum 0x3C00 = 15 MB. + // BX Extended 2 Number of contiguous 64 KB blocks between + // 16 MB and 4 GB. + // CX Configured 1 Number of contiguous KB between 1 and 16 MB, + // maximum 0x3C00 = 15 MB. + // DX Configured 2 Number of contiguous 64 KB blocks between + // 16 MB and 4 GB. - bb.intno = 0x15; - bb.eax.rx = 0xe801; - bios(&bb); + bb.intno = 0x15; + bb.eax.rx = 0xe801; + bios(&bb); - // Return the size of memory above 1MB (extended memory) in kilobytes. + // Return the size of memory above 1MB (extended memory) in kilobytes. - if ( bb.flags.cf == 0 ) return (bb.ebx.rr * 64 + bb.eax.rr); + if (bb.flags.cf == 0) + { + return (bb.ebx.rr * 64 + bb.eax.rr); + } - // Get Extended memory size. Called on last resort since the return - // value is limited to 16-bits (a little less than 64MB max). May - // not be supported by modern BIOSes. - // - // Input: - // - // AX Function Code E801h - // - // Outputs: - // - // CF Carry Flag Carry cleared indicates no error. - // AX Memory Count Number of contiguous KB above 1MB. + // Get Extended memory size. Called on last resort since the return + // value is limited to 16-bits (a little less than 64MB max). May + // not be supported by modern BIOSes. + // + // Input: + // + // AX Function Code E801h + // + // Outputs: + // + // CF Carry Flag Carry cleared indicates no error. + // AX Memory Count Number of contiguous KB above 1MB. - bb.intno = 0x15; - bb.eax.rx = 0x88; - bios(&bb); + bb.intno = 0x15; + bb.eax.rx = 0x88; + bios(&bb); - // Return the size of memory above 1MB (extended memory) in kilobytes. + // Return the size of memory above 1MB (extended memory) in kilobytes. - return bb.flags.cf ? 0 : bb.eax.rr; + return bb.flags.cf ? 0 : bb.eax.rr; } + +//============================================================================== + + unsigned long getConventionalMemorySize() { - bb.intno = 0x12; - bios(&bb); - return bb.eax.rr; // kilobytes + bb.intno = 0x12; + bios(&bb); + + return bb.eax.rr; // kilobytes } + +//============================================================================== + + void video_mode(int mode) { - bb.intno = 0x10; - bb.eax.r.h = 0x00; - bb.eax.r.l = mode; - bios(&bb); + bb.intno = 0x10; + bb.eax.r.h = 0x00; + bb.eax.r.l = mode; + bios(&bb); } + +//============================================================================== + int biosread(int dev, int cyl, int head, int sec, int num) { - int i; + int i; - bb.intno = 0x13; - sec += 1; /* sector numbers start at 1 */ + bb.intno = 0x13; + sec += 1; // sector numbers start at 1. - for (i=0;;) { - bb.ecx.r.h = cyl; - bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F); - bb.edx.r.h = head; - bb.edx.r.l = dev; - bb.eax.r.l = num; - bb.ebx.rr = OFFSET(ptov(BIOS_ADDR)); - bb.es = SEGMENT(ptov(BIOS_ADDR)); + for (i=0;;) + { + bb.ecx.r.h = cyl; + bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F); + bb.edx.r.h = head; + bb.edx.r.l = dev; + bb.eax.r.l = num; + bb.ebx.rr = OFFSET(ptov(BIOS_ADDR)); + bb.es = SEGMENT(ptov(BIOS_ADDR)); - bb.eax.r.h = 0x02; - bios(&bb); + bb.eax.r.h = 0x02; + bios(&bb); - /* In case of a successful call, make sure we set AH (return code) to zero. */ - if (bb.flags.cf == 0) - bb.eax.r.h = 0; + // In case of a successful call, make sure we set AH (return code) to zero. + if (bb.flags.cf == 0) + { + bb.eax.r.h = 0; + } - /* Now we can really check for the return code (AH) value. */ - if ((bb.eax.r.h == 0x00) || (i++ >= 5)) - break; + // Now we can really check for the return code (AH) value. + if ((bb.eax.r.h == 0x00) || (i++ >= 5)) + { + break; + } - /* reset disk subsystem and try again */ - bb.eax.r.h = 0x00; - bios(&bb); - } - return bb.eax.r.h; + // Reset disk subsystem and try again. + bb.eax.r.h = 0x00; + bios(&bb); + } + + return bb.eax.r.h; } + +//============================================================================== + int ebiosread(int dev, unsigned long long sec, int count) { - int i; - static struct { - unsigned char size; - unsigned char reserved; - unsigned char numblocks; - unsigned char reserved2; - unsigned short bufferOffset; - unsigned short bufferSegment; - unsigned long long startblock; - } addrpacket __attribute__((aligned(16))) = {0}; - addrpacket.size = sizeof(addrpacket); + int i; - for (i=0;;) { - bb.intno = 0x13; - bb.eax.r.h = 0x42; - bb.edx.r.l = dev; - bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket); - bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket); - addrpacket.reserved = addrpacket.reserved2 = 0; - addrpacket.numblocks = count; - addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR)); - addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR)); - addrpacket.startblock = sec; - bios(&bb); + static struct + { + unsigned char size; + unsigned char reserved; + unsigned char numblocks; + unsigned char reserved2; + unsigned short bufferOffset; + unsigned short bufferSegment; + unsigned long long startblock; + } addrpacket __attribute__((aligned(16))) = {0}; + addrpacket.size = sizeof(addrpacket); - /* In case of a successful call, make sure we set AH (return code) to zero. */ - if (bb.flags.cf == 0) - bb.eax.r.h = 0; + for (i = 0; ;) + { + bb.intno = 0x13; + bb.eax.r.h = 0x42; + bb.edx.r.l = dev; + bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket); + bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket); + addrpacket.reserved = addrpacket.reserved2 = 0; + addrpacket.numblocks = count; + addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR)); + addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR)); + addrpacket.startblock = sec; + bios(&bb); - /* Now we can really check for the return code (AH) value. */ - if ((bb.eax.r.h == 0x00) || (i++ >= 5)) - break; + // In case of a successful call, make sure we set AH (return code) to zero. + if (bb.flags.cf == 0) + { + bb.eax.r.h = 0; + } - /* reset disk subsystem and try again */ - bb.eax.r.h = 0x00; - bios(&bb); - } - return bb.eax.r.h; + // Now we can really check for the return code (AH) value. + if ((bb.eax.r.h == 0x00) || (i++ >= 5)) + { + break; + } + + // Reset disk subsystem and try again. + bb.eax.r.h = 0x00; + bios(&bb); + } + + return bb.eax.r.h; } +//============================================================================== + int ebioswrite(int dev, long sec, int count) { - int i; - static struct { - unsigned char size; - unsigned char reserved; - unsigned char numblocks; - unsigned char reserved2; - unsigned short bufferOffset; - unsigned short bufferSegment; - unsigned long long startblock; - } addrpacket __attribute__((aligned(16))) = {0}; - addrpacket.size = sizeof(addrpacket); + int i; + static struct + { + unsigned char size; + unsigned char reserved; + unsigned char numblocks; + unsigned char reserved2; + unsigned short bufferOffset; + unsigned short bufferSegment; + unsigned long long startblock; + } addrpacket __attribute__((aligned(16))) = {0}; + addrpacket.size = sizeof(addrpacket); - for (i=0;;) { - bb.intno = 0x13; - bb.eax.r.l = 0; /* Don't verify */ - bb.eax.r.h = 0x43; - bb.edx.r.l = dev; - bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket); - bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket); - addrpacket.reserved = addrpacket.reserved2 = 0; - addrpacket.numblocks = count; - addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR)); - addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR)); - addrpacket.startblock = sec; - bios(&bb); + for (i=0;;) + { + bb.intno = 0x13; + bb.eax.r.l = 0; /* Don't verify */ + bb.eax.r.h = 0x43; + bb.edx.r.l = dev; + bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket); + bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket); + addrpacket.reserved = addrpacket.reserved2 = 0; + addrpacket.numblocks = count; + addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR)); + addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR)); + addrpacket.startblock = sec; + bios(&bb); - /* In case of a successful call, make sure we set AH (return code) to zero. */ - if (bb.flags.cf == 0) - bb.eax.r.h = 0; + /* In case of a successful call, make sure we set AH (return code) to zero. */ + if (bb.flags.cf == 0) + bb.eax.r.h = 0; - /* Now we can really check for the return code (AH) value. */ - if ((bb.eax.r.h == 0x00) || (i++ >= 5)) - break; + /* Now we can really check for the return code (AH) value. */ + if ((bb.eax.r.h == 0x00) || (i++ >= 5)) + break; - /* reset disk subsystem and try again */ - bb.eax.r.h = 0x00; - bios(&bb); - } - return bb.eax.r.h; + /* reset disk subsystem and try again */ + bb.eax.r.h = 0x00; + bios(&bb); + } + return bb.eax.r.h; } void bios_putchar(int ch) { - bb.intno = 0x10; - bb.ebx.r.h = 0x00; /* background black */ - bb.ebx.r.l = 0x0F; /* foreground white */ - bb.eax.r.h = 0x0e; - bb.eax.r.l = ch; - bios(&bb); + bb.intno = 0x10; + bb.ebx.r.h = 0x00; /* background black */ + bb.ebx.r.l = 0x0F; /* foreground white */ + bb.eax.r.h = 0x0e; + bb.eax.r.l = ch; + bios(&bb); } + +//============================================================================== + void putca(int ch, int attr, int repeat) { - bb.intno = 0x10; - bb.ebx.r.h = 0x00; /* page number */ - bb.ebx.r.l = attr; /* attribute */ - bb.eax.r.h = 0x9; - bb.eax.r.l = ch; - bb.ecx.rx = repeat; /* repeat count */ - bios(&bb); + bb.intno = 0x10; + bb.ebx.r.h = 0x00; /* page number */ + bb.ebx.r.l = attr; /* attribute */ + bb.eax.r.h = 0x9; + bb.eax.r.l = ch; + bb.ecx.rx = repeat; /* repeat count */ + bios(&bb); } -/* Check to see if the passed-in drive is in El Torito no-emulation mode. */ + +//============================================================================== +// Check to see if the passed-in drive is in El Torito no-emulation mode. + int is_no_emulation(int drive) { - struct packet { + struct packet + { unsigned char packet_size; unsigned char media_type; unsigned char drive_num; @@ -488,34 +559,36 @@ unsigned char reseved; } __attribute__((packed)); static struct packet pkt; - + bzero(&pkt, sizeof(pkt)); pkt.packet_size = 0x13; - - bb.intno = 0x13; - bb.eax.r.h = 0x4b; - bb.eax.r.l = 0x01; // subfunc: get info - bb.edx.r.l = drive; - bb.esi.rr = NORMALIZED_OFFSET((unsigned)&pkt); - bb.ds = NORMALIZED_SEGMENT((unsigned)&pkt); - + + bb.intno = 0x13; + bb.eax.r.h = 0x4b; + bb.eax.r.l = 0x01; // subfunc: get info + bb.edx.r.l = drive; + bb.esi.rr = NORMALIZED_OFFSET((unsigned)&pkt); + bb.ds = NORMALIZED_SEGMENT((unsigned)&pkt); + bios(&bb); + #if DEBUG printf("el_torito info drive %x\n", drive); - printf("--> cf %x, eax %x\n", bb.flags.cf, bb.eax.rr); - printf("pkt_size: %x\n", pkt.packet_size); printf("media_type: %x\n", pkt.media_type); printf("drive_num: %x\n", pkt.drive_num); printf("device_spec: %x\n", pkt.device_spec); + pause(); #endif - + /* Some BIOSes erroneously return cf = 1 */ /* Just check to see if the drive number is the same. */ - if (pkt.drive_num == drive) { - if ((pkt.media_type & 0x0F) == 0) { + if (pkt.drive_num == drive) + { + if ((pkt.media_type & 0x0F) == 0) + { /* We are in no-emulation mode. */ return 1; } @@ -568,28 +641,32 @@ #endif +//============================================================================== + int get_drive_info(int drive, struct driveInfo *dp) { boot_drive_info_t *di = &dp->di; int ret = 0; - + #if UNUSED - if (maxhd == 0) { + if (maxhd == 0) + { bb.intno = 0x13; bb.eax.r.h = 0x08; bb.edx.r.l = 0x80; bios(&bb); + if (bb.flags.cf == 0) maxhd = 0x7f + bb.edx.r.l; }; - + if (drive > maxhd) return 0; #endif - + bzero(dp, sizeof(struct driveInfo)); dp->biosdev = drive; - + /* Check for El Torito no-emulation mode. */ dp->no_emulation = is_no_emulation(drive); @@ -600,12 +677,14 @@ bb.ebx.rr = 0x55aa; bios(&bb); - if ((bb.ebx.rr == 0xaa55) && (bb.flags.cf == 0)) { + if ((bb.ebx.rr == 0xaa55) && (bb.flags.cf == 0)) + { /* Get flags for supported operations. */ dp->uses_ebios = bb.ecx.r.l; } - if (dp->uses_ebios & (EBIOS_ENHANCED_DRIVE_INFO | EBIOS_LOCKING_ACCESS | EBIOS_FIXED_DISK_ACCESS)) { + if (dp->uses_ebios & (EBIOS_ENHANCED_DRIVE_INFO | EBIOS_LOCKING_ACCESS | EBIOS_FIXED_DISK_ACCESS)) + { /* Get EBIOS drive info. */ static struct drive_params params; @@ -617,7 +696,8 @@ bb.ds = NORMALIZED_SEGMENT((unsigned)¶ms); bios(&bb); - if (bb.flags.cf != 0 /* || params.phys_sectors < 2097152 */) { + if (bb.flags.cf != 0 /* || params.phys_sectors < 2097152 */) + { dp->uses_ebios = 0; di->params.buf_size = 1; } @@ -628,7 +708,8 @@ if (drive >= BASE_HD_DRIVE && (dp->uses_ebios & EBIOS_ENHANCED_DRIVE_INFO) && di->params.buf_size >= 30 && - !(di->params.dpte_offset == 0xFFFF && di->params.dpte_segment == 0xFFFF)) { + !(di->params.dpte_offset == 0xFFFF && di->params.dpte_segment == 0xFFFF)) + { void *ptr = (void *)(di->params.dpte_offset + ((unsigned int)di->params.dpte_segment << 4)); bcopy(ptr, &di->dpte, sizeof(di->dpte)); } @@ -664,7 +745,8 @@ // } // } - if (dp->no_emulation) { + if (dp->no_emulation) + { /* Some BIOSes give us erroneous EBIOS support information. * Assume that if you're on a CD, then you can use * EBIOS disk calls. @@ -678,107 +760,112 @@ pause(); #endif - if (ret == 0) { + if (ret == 0) + { dp->valid = 1; } return ret; } +//============================================================================== + int ebiosEjectMedia(int biosdev) { - bb.intno = 0x13; - bb.eax.r.h = 0x46; - bb.eax.r.l = 0; - bb.edx.rx = biosdev; - bios(&bb); - return bb.eax.r.h; + bb.intno = 0x13; + bb.eax.r.h = 0x46; + bb.eax.r.l = 0; + bb.edx.rx = biosdev; + bios(&bb); + return bb.eax.r.h; } void setCursorPosition(int x, int y, int page) { - bb.intno = 0x10; - bb.eax.r.h = 0x02; - bb.ebx.r.h = page; /* page 0 for graphics */ - bb.edx.r.l = x; - bb.edx.r.h = y; - bios(&bb); + bb.intno = 0x10; + bb.eax.r.h = 0x02; + bb.ebx.r.h = page; /* page 0 for graphics */ + bb.edx.r.l = x; + bb.edx.r.h = y; + bios(&bb); } void setCursorType(int type) { - bb.intno = 0x10; - bb.eax.r.h = 0x01; - bb.ecx.rr = type; - bios(&bb); + bb.intno = 0x10; + bb.eax.r.h = 0x01; + bb.ecx.rr = type; + bios(&bb); } void getCursorPositionAndType(int * x, int * y, int * type) { - bb.intno = 0x10; - bb.eax.r.h = 0x03; - bios(&bb); - *x = bb.edx.r.l; - *y = bb.edx.r.h; - *type = bb.ecx.rr; + bb.intno = 0x10; + bb.eax.r.h = 0x03; + bios(&bb); + *x = bb.edx.r.l; + *y = bb.edx.r.h; + *type = bb.ecx.rr; } void scollPage(int x1, int y1, int x2, int y2, int attr, int rows, int dir) { - bb.intno = 0x10; - bb.eax.r.h = (dir > 0) ? 0x06 : 0x07; - bb.eax.r.l = rows; - bb.ebx.r.h = attr; - bb.ecx.r.h = y1; - bb.ecx.r.l = x1; - bb.edx.r.h = y2; - bb.edx.r.l = x2; - bios(&bb); + bb.intno = 0x10; + bb.eax.r.h = (dir > 0) ? 0x06 : 0x07; + bb.eax.r.l = rows; + bb.ebx.r.h = attr; + bb.ecx.r.h = y1; + bb.ecx.r.l = x1; + bb.edx.r.h = y2; + bb.edx.r.l = x2; + bios(&bb); } void clearScreenRows( int y1, int y2 ) { - scollPage( 0, y1, 80 - 1, y2, 0x07, y2 - y1 + 1, 1 ); + scollPage( 0, y1, 80 - 1, y2, 0x07, y2 - y1 + 1, 1 ); } void setActiveDisplayPage( int page ) { - bb.intno = 0x10; - bb.eax.r.h = 5; - bb.eax.r.l = page; - bios(&bb); + bb.intno = 0x10; + bb.eax.r.h = 5; + bb.eax.r.l = page; + bios(&bb); } #if DEBUG int terminateDiskEmulation() { - static char cd_spec[0x13]; + static char cd_spec[0x13]; - bb.intno = 0x13; - bb.eax.r.h = 0x4b; - bb.eax.r.l = 0; // subfunc: terminate emulation - bb.esi.rr = NORMALIZED_OFFSET((unsigned)&cd_spec); - bb.ds = NORMALIZED_SEGMENT((unsigned)&cd_spec); - bios(&bb); - return bb.eax.r.h; + bb.intno = 0x13; + bb.eax.r.h = 0x4b; + bb.eax.r.l = 0; // subfunc: terminate emulation + bb.esi.rr = NORMALIZED_OFFSET((unsigned)&cd_spec); + bb.ds = NORMALIZED_SEGMENT((unsigned)&cd_spec); + bios(&bb); + return bb.eax.r.h; } int readDriveParameters(int drive, struct driveParameters *dp) { - bb.intno = 0x13; - bb.edx.r.l = drive; - bb.eax.r.h = 0x08; - bios(&bb); - if (bb.eax.r.h == 0) { - dp->heads = bb.edx.r.h; - dp->sectors = bb.ecx.r.l & 0x3F; - dp->cylinders = bb.ecx.r.h | ((bb.ecx.r.l & 0xC0) << 2); - dp->totalDrives = bb.edx.r.l; - } else { - bzero(dp, sizeof(*dp)); - } - return bb.eax.r.h; - + bb.intno = 0x13; + bb.edx.r.l = drive; + bb.eax.r.h = 0x08; + bios(&bb); + if (bb.eax.r.h == 0) + { + dp->heads = bb.edx.r.h; + dp->sectors = bb.ecx.r.l & 0x3F; + dp->cylinders = bb.ecx.r.h | ((bb.ecx.r.l & 0xC0) << 2); + dp->totalDrives = bb.edx.r.l; + } + else + { + bzero(dp, sizeof(*dp)); + } + return bb.eax.r.h; } #endif @@ -787,52 +874,52 @@ #define APM_INTNO 0x15 #define APM_INTCODE 0x53 -int -APMPresent(void) +int APMPresent(void) { - bb.intno = APM_INTNO; - bb.eax.r.h = APM_INTCODE; - bb.eax.r.l = 0x00; - bb.ebx.rr = 0x0000; - bios(&bb); - if ((bb.flags.cf == 0) && - (bb.ebx.r.h == 'P') && - (bb.ebx.r.l == 'M')) { - /* Success */ - bootArgs->apmConfig.major_vers = bb.eax.r.h; - bootArgs->apmConfig.minor_vers = bb.eax.r.l; - bootArgs->apmConfig.flags.data = bb.ecx.rr; - return 1; - } - return 0; + bb.intno = APM_INTNO; + bb.eax.r.h = APM_INTCODE; + bb.eax.r.l = 0x00; + bb.ebx.rr = 0x0000; + bios(&bb); + if ((bb.flags.cf == 0) && (bb.ebx.r.h == 'P') && (bb.ebx.r.l == 'M')) + { + /* Success */ + bootArgs->apmConfig.major_vers = bb.eax.r.h; + bootArgs->apmConfig.minor_vers = bb.eax.r.l; + bootArgs->apmConfig.flags.data = bb.ecx.rr; + return 1; + } + return 0; } -int -APMConnect32(void) +int APMConnect32(void) { - bb.intno = APM_INTNO; - bb.eax.r.h = APM_INTCODE; - bb.eax.r.l = 0x03; - bb.ebx.rr = 0x0000; - bios(&bb); - if (bb.flags.cf == 0) { - /* Success */ - bootArgs->apmConfig.cs32_base = (bb.eax.rr) << 4; - bootArgs->apmConfig.entry_offset = bb.ebx.rx; - bootArgs->apmConfig.cs16_base = (bb.ecx.rr) << 4; - bootArgs->apmConfig.ds_base = (bb.edx.rr) << 4; - if (bootArgs->apmConfig.major_vers >= 1 && - bootArgs->apmConfig.minor_vers >= 1) { - bootArgs->apmConfig.cs_length = bb.esi.rr; - bootArgs->apmConfig.ds_length = bb.edi.rr; - } else { - bootArgs->apmConfig.cs_length = - bootArgs->apmConfig.ds_length = 64 * 1024; - } - bootArgs->apmConfig.connected = 1; - return 1; - } - return 0; + bb.intno = APM_INTNO; + bb.eax.r.h = APM_INTCODE; + bb.eax.r.l = 0x03; + bb.ebx.rr = 0x0000; + bios(&bb); + if (bb.flags.cf == 0) + { + /* Success */ + bootArgs->apmConfig.cs32_base = (bb.eax.rr) << 4; + bootArgs->apmConfig.entry_offset = bb.ebx.rx; + bootArgs->apmConfig.cs16_base = (bb.ecx.rr) << 4; + bootArgs->apmConfig.ds_base = (bb.edx.rr) << 4; + if (bootArgs->apmConfig.major_vers >= 1 && bootArgs->apmConfig.minor_vers >= 1) + { + bootArgs->apmConfig.cs_length = bb.esi.rr; + bootArgs->apmConfig.ds_length = bb.edi.rr; + } + else + { + bootArgs->apmConfig.cs_length = + bootArgs->apmConfig.ds_length = 64 * 1024; + } + bootArgs->apmConfig.connected = 1; + return 1; + } + return 0; } #endif /* APM_SUPPORT */ @@ -840,64 +927,67 @@ #ifdef EISA_SUPPORT bool eisa_present(void) { - static bool checked = false; - static bool isEISA; + static bool checked = false; + static bool isEISA; - if (!checked) { - if (strncmp((char *)0xfffd9, "EISA", 4) == 0) - isEISA = true; + if (!checked) + { + if (strncmp((char *)0xfffd9, "EISA", 4) == 0) + isEISA = true; - checked = true; - } - - return (isEISA); + checked = true; + } + + return (isEISA); } int ReadEISASlotInfo(EISA_slot_info_t *ep, int slot) { - union { - struct { - unsigned char char2h :2; - unsigned char char1 :5; - unsigned char char3 :5; - unsigned char char2l :3; - unsigned char d2 :4; - unsigned char d1 :4; - unsigned char d4 :4; - unsigned char d3 :4; - } s; - unsigned char data[4]; - } u; - static char hex[0x10] = "0123456789ABCDEF"; + union + { + struct + { + unsigned char char2h :2; + unsigned char char1 :5; + unsigned char char3 :5; + unsigned char char2l :3; + unsigned char d2 :4; + unsigned char d1 :4; + unsigned char d4 :4; + unsigned char d3 :4; + } s; + unsigned char data[4]; + } u; + static char hex[0x10] = "0123456789ABCDEF"; - - bb.intno = 0x15; - bb.eax.r.h = 0xd8; - bb.eax.r.l = 0x00; - bb.ecx.r.l = slot; - bios(&bb); - if (bb.flags.cf) - return bb.eax.r.h; - ep->u_ID.d = bb.eax.r.l; - ep->configMajor = bb.ebx.r.h; - ep->configMinor = bb.ebx.r.l; - ep->checksum = bb.ecx.rr; - ep->numFunctions = bb.edx.r.h; - ep->u_resources.d = bb.edx.r.l; - u.data[0] = bb.edi.r.l; - u.data[1] = bb.edi.r.h; - u.data[2] = bb.esi.r.l; - u.data[3] = bb.esi.r.h; - ep->id[0] = u.s.char1 + ('A' - 1); - ep->id[1] = (u.s.char2l | (u.s.char2h << 3)) + ('A' - 1); - ep->id[2] = u.s.char3 + ('A' - 1); - ep->id[3] = hex[u.s.d1]; - ep->id[4] = hex[u.s.d2]; - ep->id[5] = hex[u.s.d3]; - ep->id[6] = hex[u.s.d4]; - ep->id[7] = 0; - return 0; + + bb.intno = 0x15; + bb.eax.r.h = 0xd8; + bb.eax.r.l = 0x00; + bb.ecx.r.l = slot; + bios(&bb); + if (bb.flags.cf) + return bb.eax.r.h; + ep->u_ID.d = bb.eax.r.l; + ep->configMajor = bb.ebx.r.h; + ep->configMinor = bb.ebx.r.l; + ep->checksum = bb.ecx.rr; + ep->numFunctions = bb.edx.r.h; + ep->u_resources.d = bb.edx.r.l; + u.data[0] = bb.edi.r.l; + u.data[1] = bb.edi.r.h; + u.data[2] = bb.esi.r.l; + u.data[3] = bb.esi.r.h; + ep->id[0] = u.s.char1 + ('A' - 1); + ep->id[1] = (u.s.char2l | (u.s.char2h << 3)) + ('A' - 1); + ep->id[2] = u.s.char3 + ('A' - 1); + ep->id[3] = hex[u.s.d1]; + ep->id[4] = hex[u.s.d2]; + ep->id[5] = hex[u.s.d3]; + ep->id[6] = hex[u.s.d4]; + ep->id[7] = 0; + return 0; } /* @@ -907,18 +997,19 @@ int ReadEISAFuncInfo(EISA_func_info_t *ep, int slot, int function) { - bb.intno = 0x15; - bb.eax.r.h = 0xd8; - bb.eax.r.l = 0x01; - bb.ecx.r.l = slot; - bb.ecx.r.h = function; - bb.esi.rr = (unsigned int)ep->data; - bios(&bb); - if (bb.eax.r.h == 0) { - ep->slot = slot; - ep->function = function; - } - return bb.eax.r.h; + bb.intno = 0x15; + bb.eax.r.h = 0xd8; + bb.eax.r.l = 0x01; + bb.ecx.r.l = slot; + bb.ecx.r.h = function; + bb.esi.rr = (unsigned int)ep->data; + bios(&bb); + if (bb.eax.r.h == 0) + { + ep->slot = slot; + ep->function = function; + } + return bb.eax.r.h; } #endif /* EISA_SUPPORT */ @@ -927,19 +1018,20 @@ int ReadPCIBusInfo(PCI_bus_info_t *pp) { - bb.intno = 0x1a; - bb.eax.r.h = 0xb1; - bb.eax.r.l = 0x01; - bios(&bb); - if ((bb.eax.r.h == 0) && (bb.edx.rx == PCI_SIGNATURE)) { - pp->BIOSPresent = 1; - pp->u_bus.d = bb.eax.r.l; - pp->majorVersion = bb.ebx.r.h; - pp->minorVersion = bb.ebx.r.l; - pp->maxBusNum = bb.ecx.r.l; - return 0; - } - return -1; + bb.intno = 0x1a; + bb.eax.r.h = 0xb1; + bb.eax.r.l = 0x01; + bios(&bb); + if ((bb.eax.r.h == 0) && (bb.edx.rx == PCI_SIGNATURE)) + { + pp->BIOSPresent = 1; + pp->u_bus.d = bb.eax.r.l; + pp->majorVersion = bb.ebx.r.h; + pp->minorVersion = bb.ebx.r.l; + pp->maxBusNum = bb.ecx.r.l; + return 0; + } + return -1; } void sleep(int n) @@ -948,6 +1040,9 @@ while (time18() < endtime); } + +//============================================================================== + void delay(int ms) { bb.intno = 0x15; Index: branches/ErmaC/Trunk/i386/libsaio/saio_types.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/saio_types.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/saio_types.h (revision 2037) @@ -72,7 +72,7 @@ typedef struct { char plist[16384]; // buffer for plist - TagPtr dictionary; // buffer for xml dictionary + TagPtr dictionary; // buffer for xml dictionary bool canOverride; // flag to mark a dictionary can be overriden } config_file_t; @@ -110,8 +110,8 @@ unsigned short control_port_base; unsigned char head_flags; unsigned char vendor_info; - unsigned char irq : 4; - unsigned char irq_unused : 4; + unsigned char irq : 4; + unsigned char irq_unused : 4; unsigned char block_count; unsigned char dma_channel : 4; unsigned char dma_type : 4; @@ -136,12 +136,14 @@ int valid; }; + typedef struct FinderInfo { unsigned char data[16]; } FinderInfo; -struct BootVolume; + +struct BootVolume; typedef struct BootVolume * BVRef; typedef struct BootVolume * CICell; @@ -159,10 +161,10 @@ struct iob { - unsigned int i_flgs; /* see F_* below */ - unsigned int i_offset; /* seek byte offset in file */ - int i_filesize; /* size of file */ - char * i_buf; /* file load address */ + char * i_buf; /* file load address */ + unsigned int i_flgs; /* see F_* below */ + unsigned int i_offset; /* seek byte offset in file */ + int i_filesize; /* size of file */ }; #define BPS 512 /* sector size of the device */ @@ -177,7 +179,7 @@ struct dirstuff { char * dir_path; /* directory path */ long long dir_index; /* directory entry index */ - BVRef dir_bvr; /* volume reference */ + BVRef dir_bvr; /* volume reference */ }; #define BVSTRLEN 32 @@ -204,8 +206,8 @@ char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */ BVFree bv_free; /* BVFree function */ uint32_t modTime; - char label[BVSTRLEN]; /* partition volume label */ - char altlabel[BVSTRLEN]; /* partition volume label */ + char label[BVSTRLEN]; /* partition volume label */ + char altlabel[BVSTRLEN]; /* partition volume label */ bool filtered; /* newFilteredBVChain() will set to TRUE */ bool visible; /* will shown in the device list */ char OSVersion[8]; Index: branches/ErmaC/Trunk/i386/libsaio/md5c.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/md5c.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/md5c.c (revision 2037) @@ -1,6 +1,34 @@ /* - * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm + * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ + +/* + * MD5.C - RSA Data Security, Inc., MD5 message-digest algorithm + * * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All * rights reserved. * @@ -35,40 +63,50 @@ #define Encode memcpy #define Decode memcpy +//------------------------------------------------------------------------------ + static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -/* F, G, H and I are basic MD5 functions. */ + +//------------------------------------------------------------------------------ +// F, G, H and I are basic MD5 functions. + #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | (~z))) -/* ROTATE_LEFT rotates x left n bits. */ +//------------------------------------------------------------------------------ +// ROTATE_LEFT rotates x left n bits. + #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) -/* - * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - * Rotation is separate from addition to prevent recomputation. - */ +//------------------------------------------------------------------------------ +// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +// Rotation is separate from addition to prevent recomputation. + #define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ @@ -79,14 +117,12 @@ /* MD5 initialization. Begins an MD5 operation, writing a new context. */ -void -MD5Init (context) +void MD5Init (context) MD5_CTX *context; { - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. */ + // Load magic initialization constants. context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; @@ -115,15 +151,19 @@ index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += ((u_int32_t)inputLen << 3)) - < ((u_int32_t)inputLen << 3)) + if ((context->count[0] += ((u_int32_t)inputLen << 3)) < ((u_int32_t)inputLen << 3)) + { context->count[1]++; + } + context->count[1] += ((u_int32_t)inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ - if (inputLen >= partLen) { + + if (inputLen >= partLen) + { memcpy((void *)&context->buffer[index], (const void *)input, partLen); MD5Transform (context->state, context->buffer); Index: branches/ErmaC/Trunk/i386/libsaio/fake_efi.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/fake_efi.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsaio/fake_efi.c (revision 2037) @@ -73,7 +73,7 @@ */ /* Identify ourselves as the EFI firmware vendor */ -static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'.',':','E','r','m','a','C',':','.','_','1','.','0', 0}; +static EFI_CHAR16 const FIRMWARE_VENDOR[] = { 'A', 'p', 'p', 'l', 'e', '\0' }; static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ /* Default platform system_id (fix by IntVar) */ Index: branches/ErmaC/Trunk/i386/boot2/drivers.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/drivers.c (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/drivers.c (revision 2037) @@ -112,7 +112,7 @@ static char * gFileName; /*static*/ unsigned long -Adler32( unsigned char * buffer, long length ) +Adler32(unsigned char * buffer, long length) { long cnt; unsigned long result, lowHalf, highHalf; @@ -120,7 +120,7 @@ lowHalf = 1; highHalf = 0; - for ( cnt = 0; cnt < length; cnt++ ) + for (cnt = 0; cnt < length; cnt++) { if ((cnt % 5000) == 0) { @@ -656,7 +656,8 @@ ModulePtr module, module2; long done; - do { + do + { done = 1; module = gModuleHead; @@ -665,15 +666,19 @@ if (module->willLoad == 1) { prop = XMLGetProperty(module->dict, kPropOSBundleLibraries); + if (prop != 0) { prop = prop->tag; + while (prop != 0) { module2 = gModuleHead; + while (module2 != 0) { prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier); + if ((prop2 != 0) && (!strcmp(prop->string, prop2->string))) { if (module2->willLoad == 0) module2->willLoad = 1; @@ -703,19 +708,24 @@ static ModulePtr FindModule( char * name ) { - ModulePtr module; - TagPtr prop; + ModulePtr module; + TagPtr prop; + + module = gModuleHead; + + while (module != 0) + { + prop = GetProperty(module->dict, kPropCFBundleIdentifier); + + if ((prop != 0) && !strcmp(name, prop->string)) + { + break; + } + + module = module->nextModule; + } - module = gModuleHead; - - while (module != 0) - { - prop = GetProperty(module->dict, kPropCFBundleIdentifier); - if ((prop != 0) && !strcmp(name, prop->string)) break; - module = module->nextModule; - } - - return module; + return module; } #endif /* NOTDEF */ @@ -743,19 +753,19 @@ XMLFreeTag(moduleDict); } - + if (length == -1) return -1; required = XMLGetProperty(moduleDict, kPropOSBundleRequired); - if ( (required == 0) || - (required->type != kTagTypeString) || - !strcmp(required->string, "Safe Boot")) + + if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot")) + { XMLFreeTag(moduleDict); return -2; } - tmpModule = malloc(sizeof(Module)); + tmpModule = malloc(sizeof(Module)); if (tmpModule == 0) { XMLFreeTag(moduleDict); @@ -798,7 +808,7 @@ printf("compressed_size: 0x%x\n", kernel_header->compressed_size); getchar(); #endif - + if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) { if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) Index: branches/ErmaC/Trunk/i386/boot2/prompt.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/prompt.c (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/prompt.c (revision 2037) @@ -28,7 +28,7 @@ #include -char bootBanner[] = "\nDarwin/x86 boot v" I386BOOT_VERSION " - Enoch by ErmaC r" I386BOOT_CHAMELEONREVISION "\n" +char bootBanner[] = "\nDarwin/x86 boot v" I386BOOT_VERSION " - Enoch r" I386BOOT_CHAMELEONREVISION "\n" "Build date: " I386BOOT_BUILDDATE "\n" "%dMB memory\n"; Index: branches/ErmaC/Trunk/i386/boot2/boot.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/boot.c (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/boot.c (revision 2037) @@ -133,57 +133,59 @@ bootArgs->kaddr = bootArgs->ksize = 0; execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL); - + ret = DecodeKernel(binary, &kernelEntry, (char **) &bootArgs->kaddr, (int *)&bootArgs->ksize ); - + if ( ret != 0 ) return ret; - + // Reserve space for boot args reserveKernBootStruct(); - + // Notify modules that the kernel has been decoded execute_hook("DecodedKernel", (void*)binary, NULL, NULL, NULL); - + setupFakeEfi(); - + // Load boot drivers from the specifed root path. //if (!gHaveKernelCache) LoadDrivers("/"); - + execute_hook("DriversLoaded", (void*)binary, NULL, NULL, NULL); - + clearActivityIndicator(); - - if (gErrors) { + + if (gErrors) + { printf("Errors encountered while starting up the computer.\n"); printf("Pausing %d seconds...\n", kBootErrorTimeout); sleep(kBootErrorTimeout); } - + md0Ramdisk(); verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64"); verbose("Boot Args: %s\n", bootArgs->CommandLine); // Cleanup the PXE base code. - - if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) { + + if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) + { if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess ) { printf("nbpUnloadBaseCode error %d\n", (int) ret); sleep(2); } } - + bool dummyVal; if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal) { showTextBuffer(msgbuf, strlen(msgbuf)); } - + usb_loop(); // If we were in text mode, switch to graphics mode. @@ -193,13 +195,14 @@ setVideoMode( GRAPHICS_MODE, 0 ); else drawBootGraphics(); - + setupBooterLog(); - + finalizeBootStruct(); - + // Jump to kernel's entry point. There's no going back now. - if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { + if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) + { // Notify modules that the kernel is about to be started execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL); @@ -223,24 +226,26 @@ //========================================================================== // LoadKernelCache - Try to load Kernel Cache. // return the length of the loaded cache file or -1 on error -long LoadKernelCache(const char* cacheFile, void **binary) { +long LoadKernelCache(const char* cacheFile, void **binary) +{ char kernelCacheFile[512]; char kernelCachePath[512]; long flags, time, cachetime, kerneltime, exttime, ret=-1; - unsigned long adler32; + unsigned long adler32; - if((gBootMode & kBootModeSafe) != 0) - { + if((gBootMode & kBootModeSafe) != 0) + { verbose("Kernel Cache ignored.\n"); return -1; - } + } // Use specify kernel cache file if not empty if (cacheFile[0] != 0) strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile)); else { // Lion and Mountain Lion prelink kernel cache file - if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { + if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) + { sprintf(kernelCacheFile, "%skernelcache", kDefaultCachePathSnow); } // Snow Leopard prelink kernel cache file @@ -286,7 +291,8 @@ ret = -1; // If boot from a boot helper partition check the kernel cache file on it - if (gBootVolume->flags & kBVFlagBooter) { + if (gBootVolume->flags & kBVFlagBooter) + { sprintf(kernelCachePath, "com.apple.boot.P%s", kernelCacheFile); ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime); if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) @@ -303,7 +309,8 @@ } } // If not found, use the original kernel cache path. - if (ret == -1) { + if (ret == -1) + { strcpy(kernelCachePath, kernelCacheFile); ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime); if ((flags & kFileTypeMask) != kFileTypeFlat) @@ -311,7 +318,8 @@ } // Exit if kernel cache file wasn't found - if (ret == -1) { + if (ret == -1) + { verbose("No Kernel Cache File '%s' found\n", kernelCacheFile); return -1; } @@ -321,7 +329,8 @@ ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime); // Check if the kernel file is more recent than the cache file if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) - && (kerneltime > cachetime)) { + && (kerneltime > cachetime)) + { verbose("Kernel file (%s) is more recent than KernelCache (%s), ignoring KernelCache\n", bootInfo->bootFile, kernelCacheFile); return -1; @@ -339,7 +348,8 @@ // Since the kernel cache file exists and is the most recent try to load it verbose("Loading kernel cache %s\n", kernelCachePath); - if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { + if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) + { ret = LoadThinFatFile(kernelCachePath, binary); } else { ret = LoadFile(kernelCachePath); @@ -380,19 +390,19 @@ int status; unsigned int allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot; unsigned int denyBVFlags = kBVFlagEFISystem; - + // Set reminder to unload the PXE base code. Neglect to unload // the base code will result in a hang or kernel panic. gUnloadPXEOnExit = true; - + // Record the device that the booter was loaded from. gBIOSDev = biosdev & kBIOSDevMask; - + // Initialize boot info structure. initKernBootStruct(); - + initBooterLog(); - + // Setup VGA text mode. // Not sure if it is safe to call setVideoMode() before the // config table has been loaded. Call video_mode() instead. @@ -403,39 +413,41 @@ #if DEBUG printf("after video_mode\n"); #endif - + // Scan and record the system's hardware information. scan_platform(); - + // First get info for boot volume. scanBootVolumes(gBIOSDev, 0); bvChain = getBVChainForBIOSDev(gBIOSDev); setBootGlobals(bvChain); - + // Load boot.plist config file status = loadChameleonConfig(&bootInfo->chameleonConfig); - - if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet) { + + if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet) + { gBootMode |= kBootModeQuiet; } - + // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu) { firstRun = false; } - + // Loading preboot ramdisk if exists. loadPrebootRAMDisk(); - + // Disable rescan option by default gEnableCDROMRescan = false; - + // Enable it with Rescan=y in system config if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig) - && gEnableCDROMRescan) { + && gEnableCDROMRescan) + { gEnableCDROMRescan = true; } - + // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config. rescanPrompt = false; if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) @@ -443,25 +455,27 @@ { gEnableCDROMRescan = promptForRescanOption(); } - + // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config. if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) - && gScanSingleDrive) { + && gScanSingleDrive) + { gScanSingleDrive = true; } - + // Create a list of partitions on device(s). - if (gScanSingleDrive) { + if (gScanSingleDrive) + { scanBootVolumes(gBIOSDev, &bvCount); } else { scanDisks(gBIOSDev, &bvCount); } - + // Create a separated bvr chain using the specified filters. bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); - + gBootVolume = selectBootVolume(bvChain); - + // Intialize module system init_module_system(); @@ -481,9 +495,9 @@ // initGUI() returned with an error, disabling GUI. useGUI = false; } - + setBootGlobals(bvChain); - + // Parse args, load and start kernel. while (1) { @@ -493,7 +507,7 @@ int len, ret = -1; long flags, sleeptime, time; void *binary = (void *)kLoadAddr; - + char bootFile[sizeof(bootInfo->bootFile)]; char bootFilePath[512]; char kernelCacheFile[512]; @@ -501,11 +515,11 @@ // Initialize globals. sysConfigValid = false; gErrors = false; - + status = getBootOptions(firstRun); firstRun = false; if (status == -1) continue; - + status = processBootOptions(); // Status == 1 means to chainboot if ( status == 1 ) break; @@ -526,9 +540,9 @@ } continue; } - + // Other status (e.g. 0) means that we should proceed with boot. - + // Turn off any GUI elements if ( bootArgs->Video.v_display == GRAPHICS_MODE ) { @@ -540,24 +554,28 @@ drawBackground(); updateVRAM(); } - + // Find out which version mac os we're booting. getOSVersion(); - if (platformCPUFeature(CPU_FEATURE_EM64T)) { + if (platformCPUFeature(CPU_FEATURE_EM64T)) + { archCpuType = CPU_TYPE_X86_64; } else { archCpuType = CPU_TYPE_I386; } - if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) { + if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) + { if (strncmp(val, "i386", 4) == 0) { archCpuType = CPU_TYPE_I386; } } - - if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) { - if (strncmp(val, "i386", 4) == 0) { + + if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) + { + if (strncmp(val, "i386", 4) == 0) + { archCpuType = CPU_TYPE_I386; } } @@ -565,46 +583,51 @@ // Notify modules that we are attempting to boot execute_hook("PreBoot", NULL, NULL, NULL, NULL); - if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) { + if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) + { tryresume = true; tryresumedefault = true; } else { tryresumedefault = false; } - if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) { + if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) + { forceresume = false; } - - if (forceresume) { + + if (forceresume) + { tryresume = true; tryresumedefault = false; } - - while (tryresume) { + + while (tryresume) + { const char *tmp; BVRef bvr; if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig)) val = "/private/var/vm/sleepimage"; - + // Do this first to be sure that root volume is mounted ret = GetFileInfo(0, val, &flags, &sleeptime); if ((bvr = getBootVolumeRef(val, &tmp)) == NULL) break; - + // Can't check if it was hibernation Wake=y is required if (bvr->modTime == 0 && tryresumedefault) break; - + if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) break; - - if (!forceresume && ((sleeptime+3)modTime)) { -#if DEBUG + + if (!forceresume && ((sleeptime+3)modTime)) + { +#if DEBUG printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n", bvr->modTime-sleeptime); -#endif +#endif break; } @@ -626,7 +649,8 @@ if (useKernelCache) do { // Determine the name of the Kernel Cache - if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) { + if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) + { if (val[0] == '\\') { len--; @@ -637,13 +661,15 @@ kernelCacheFile[0] = 0; // Use default kernel cache file } - if (gOverrideKernel && kernelCacheFile[0] == 0) { + if (gOverrideKernel && kernelCacheFile[0] == 0) + { verbose("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile); useKernelCache = false; break; } - if (gMKextName[0] != 0) { + if (gMKextName[0] != 0) + { verbose("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName); useKernelCache = false; @@ -676,7 +702,8 @@ // Try to load kernel image from alternate locations on boot helper partitions. ret = -1; - if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) { + if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) + { sprintf(bootFilePath, "com.apple.boot.P%s", bootFile); ret = GetFileInfo(NULL, bootFilePath, &flags, &time); if (ret == -1) @@ -690,11 +717,12 @@ } } } - if (ret == -1) { + if (ret == -1) + { // No alternate location found, using the original kernel image path. strlcpy(bootFilePath, bootFile,sizeof(bootFilePath)); } - + verbose("Loading kernel %s\n", bootFilePath); ret = LoadThinFatFile(bootFilePath, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) @@ -703,19 +731,21 @@ ret = LoadThinFatFile(bootFilePath, &binary); } } while (0); - + clearActivityIndicator(); - + #if DEBUG printf("Pausing..."); sleep(8); #endif - - if (ret <= 0) { + + if (ret <= 0) + { printf("Can't find %s\n", bootFile); sleep(1); - - if (gBootFileType == kNetworkDeviceType) { + + if (gBootFileType == kNetworkDeviceType) + { // Return control back to PXE. Don't unload PXE base code. gUnloadPXEOnExit = false; break; @@ -731,12 +761,14 @@ // chainboot if (status == 1) { // if we are already in graphics-mode, - if (getVideoMode() == GRAPHICS_MODE) { + if (getVideoMode() == GRAPHICS_MODE) + { setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode. } } - if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) { + if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) + { nbpUnloadBaseCode(); } } @@ -793,12 +825,14 @@ while (len > 0) { k = len < NMAX ? len : NMAX; len -= k; - while (k >= 16) { + while (k >= 16) + { DO16(buf); buf += 16; k -= 16; } - if (k != 0) do { + if (k != 0) do + { s1 += *buf++; s2 += s1; } while (--k); Index: branches/ErmaC/Trunk/i386/boot2/boot2.s =================================================================== --- branches/ErmaC/Trunk/i386/boot2/boot2.s (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/boot2.s (revision 2037) @@ -64,7 +64,7 @@ # # Returns: # -LABEL(boot2) +LABEL(boot2) # Entry point at 0:BOOTER_ADDR (will be called by boot1) pushl %ecx # Save general purpose registers pushl %ebx pushl %ebp Index: branches/ErmaC/Trunk/i386/boot2/boot.h =================================================================== --- branches/ErmaC/Trunk/i386/boot2/boot.h (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/boot.h (revision 2037) @@ -22,8 +22,7 @@ * @APPLE_LICENSE_HEADER_END@ */ /* - * Copyright 1994 NeXT Computer, Inc. - * All rights reserved. + * Copyright 1994 NeXT Computer, Inc. All rights reserved. */ #ifndef __BOOT2_BOOT_H @@ -182,8 +181,7 @@ #define kCDBootTimeout 8 /* - * A global set by boot() to record the device that the booter - * was loaded from. + * A global set by boot() to record the device that the booter was loaded from. */ #define ROOT_DEVICE_SIZE 512 extern int gBIOSDev; @@ -206,11 +204,12 @@ /* * Boot Modes */ -enum { - kBootModeNormal = 0, - kBootModeSafe = 1, - kBootModeSecure = 2, - kBootModeQuiet = 4 +enum +{ + kBootModeNormal = 0, + kBootModeSafe = 1, + kBootModeSecure = 2, + kBootModeQuiet = 4 }; extern void initialize_runtime(); @@ -282,9 +281,10 @@ void showTextFile(); char *getMemoryInfoString(); -typedef struct { - char name[80]; - void * param; +typedef struct +{ + char name[80]; + void * param; } MenuItem; /* @@ -292,16 +292,17 @@ */ extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen); -struct compressed_kernel_header { - u_int32_t signature; - u_int32_t compress_type; - u_int32_t adler32; - u_int32_t uncompressed_size; - u_int32_t compressed_size; - u_int32_t reserved[11]; - char platform_name[64]; - char root_path[256]; - u_int8_t data[0]; +struct compressed_kernel_header +{ + u_int32_t signature; + u_int32_t compress_type; + u_int32_t adler32; + u_int32_t uncompressed_size; + u_int32_t compressed_size; + u_int32_t reserved[11]; + char platform_name[64]; + char root_path[256]; + u_int8_t data[0]; }; typedef struct compressed_kernel_header compressed_kernel_header; Index: branches/ErmaC/Trunk/i386/boot2/lzss.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/lzss.c (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/lzss.c (revision 2037) @@ -42,50 +42,65 @@ #include -#define N 4096 /* size of ring buffer - must be power of 2 */ -#define F 18 /* upper limit for match_length */ -#define THRESHOLD 2 /* encode string into position and length - if match_length is greater than this */ -//#define NIL N /* index for root of binary search trees */ +#define N 4096 /* Size of ring buffer - must be power of 2. */ +#define N_MIN_1 4095 +#define F 18 /* Upper limit for match_length. */ +#define R N - F +#define THRESHOLD 2 /* Encode string into position and length if match_length is greater than this. */ +#define NIL N /* Index for root of binary search trees. */ -int -decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen) + +//============================================================================== +// Refactoring and bug fix Copyright (c) 2010 by DHP. + +int decompress_lzss(u_int8_t * dst, u_int8_t * src, u_int32_t srclen) { - /* ring buffer of size N, with extra F-1 bytes to aid string comparison */ - u_int8_t text_buf[N + F - 1]; - u_int8_t *dststart = dst; - u_int8_t *srcend = src + srclen; - int i, j, k, r, c; - unsigned int flags; + /* Four KB ring buffer with 17 extra bytes added to aid string comparisons. */ + u_int8_t text_buf[N_MIN_1 + F]; + u_int8_t * dststart = dst; + const u_int8_t * srcend = (src + srclen); + + int r = R; + int i, j, k, c; + unsigned int flags = 0; + + for (i = 0; i < R; i++) + { + text_buf[i] = ' '; + } + + while (src < srcend) + { + if (((flags >>= 1) & 0x100) == 0) + { + c = *src++; + flags = c | 0xFF00; // Clever use of the high byte. + } + + if ((src < srcend) && (flags & 1)) + { + c = *src++; + *dst++ = c; + text_buf[r++] = c; + r &= N_MIN_1; + } + else if ((src + 2) <= srcend) + { + i = *src++; + j = *src++; + + i |= ((j & 0xF0) << 4); + j = (j & 0x0F) + THRESHOLD; + + for (k = 0; k <= j; k++) + { + c = text_buf[(i + k) & N_MIN_1]; + *dst++ = c; + text_buf[r++] = c; + r &= N_MIN_1; + } + } + } - dst = dststart; - for (i = 0; i < N - F; i++) - text_buf[i] = ' '; - r = N - F; - flags = 0; - for ( ; ; ) { - if (((flags >>= 1) & 0x100) == 0) { - if (src < srcend) c = *src++; else break; - flags = c | 0xFF00; /* uses higher byte cleverly */ - } /* to count eight */ - if (flags & 1) { - if (src < srcend) c = *src++; else break; - *dst++ = c; - text_buf[r++] = c; - r &= (N - 1); - } else { - if (src < srcend) i = *src++; else break; - if (src < srcend) j = *src++; else break; - i |= ((j & 0xF0) << 4); - j = (j & 0x0F) + THRESHOLD; - for (k = 0; k <= j; k++) { - c = text_buf[(i + k) & (N - 1)]; - *dst++ = c; - text_buf[r++] = c; - r &= (N - 1); - } - } - } - - return dst - dststart; + return dst - dststart; } Index: branches/ErmaC/Trunk/i386/boot2/options.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/options.c (revision 2036) +++ branches/ErmaC/Trunk/i386/boot2/options.c (revision 2037) @@ -1069,31 +1069,31 @@ bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP) { - int argLen = argName ? strlen(argName) : 0; - int len = argLen + cnt + 1; // +1 to account for space + int argLen = argName ? strlen(argName) : 0; + int len = argLen + cnt + 1; // + 1 to account for space. + if (len > *cntRemainingP) + { + error("Warning: boot arguments too long, truncating\n"); + return false; + } + if (argName) + { + strncpy(*argP, argName, argLen); + *argP += argLen; + *argP[0] = '='; + (*argP)++; len++; // +1 to account for '=' + } - if (len > *cntRemainingP) { - error("Warning: boot arguments too long, truncating\n"); - return false; - } + strncpy(*argP, val, cnt); + *argP += cnt; + *argP[0] = ' '; + (*argP)++; + *cntRemainingP -= len; - if (argName) { - strncpy( *argP, argName, argLen ); - *argP += argLen; - *argP[0] = '='; - (*argP)++; - } - - strncpy( *argP, val, cnt ); - *argP += cnt; - *argP[0] = ' '; - (*argP)++; - - *cntRemainingP -= len; - return true; + return true; } // Index: branches/ErmaC/Trunk/i386/libsa/libsa.h =================================================================== --- branches/ErmaC/Trunk/i386/libsa/libsa.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/libsa.h (revision 2037) @@ -128,8 +128,7 @@ /* * prf.c */ -extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), - void * putfn_arg); +extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), void * putfn_arg); /* * printf.c @@ -140,7 +139,7 @@ /* * zalloc.c */ -#define malloc(size) safe_malloc(size, __FILE__, __LINE__) +#define malloc(size) safe_malloc(size, __FILE__, __LINE__) extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); extern void * safe_malloc(size_t size,const char *file, int line); extern void free(void * start); @@ -149,7 +148,6 @@ /* * getsegbyname.c */ -extern struct segment_command * - getsegbynamefromheader(struct mach_header * mhp, char * segname); +extern struct segment_command * getsegbynamefromheader(struct mach_header * mhp, char * segname); #endif /* !__BOOT_LIBSA_H */ Index: branches/ErmaC/Trunk/i386/libsa/printf.c =================================================================== --- branches/ErmaC/Trunk/i386/libsa/printf.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/printf.c (revision 2037) @@ -34,16 +34,16 @@ char * last_str; }; -static int -sputc(int c, struct putc_info * pi) //Azi: same as above +static int sputc(int c, struct putc_info * pi) //Azi: same as above { if (pi->last_str) - if (pi->str == pi->last_str) { - *(pi->str) = '\0'; - return 0; + if (pi->str == pi->last_str) + { + *(pi->str) = '\0'; + return 0; } - *(pi->str)++ = c; - return c; + *(pi->str)++ = c; + return c; } /*VARARGS1*/ Index: branches/ErmaC/Trunk/i386/libsa/zalloc.c =================================================================== --- branches/ErmaC/Trunk/i386/libsa/zalloc.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/zalloc.c (revision 2037) @@ -49,7 +49,7 @@ static short availableNodes, allocedNodes, totalNodes; static char * zalloc_base; static char * zalloc_end; -static void (*zerror)(char *, size_t, const char *, int); +static void (*zerror)(char *, size_t, const char *, int); static void zallocate(char * start,int size); static void zinsert(zmem * zp, int ndx); @@ -77,12 +77,17 @@ zalloced = (zmem *) zalloc_base; zavailable = (zmem *) zalloc_base + sizeof(zmem) * totalNodes; zavailable[0].start = (char *)zavailable + sizeof(zmem) * totalNodes; - if (size == 0) size = ZALLOC_LEN; + + if (size == 0) + { + size = ZALLOC_LEN; + } + zavailable[0].size = size - (zavailable[0].start - zalloc_base); - zalloc_end = zalloc_base + size; + zalloc_end = zalloc_base + size; availableNodes = 1; allocedNodes = 0; - zerror = malloc_err_fn ? malloc_err_fn : malloc_error; + zerror = malloc_err_fn ? malloc_err_fn : malloc_error; } #define BEST_FIT 1 @@ -91,8 +96,8 @@ { int i; #if BEST_FIT - int bestFit; - size_t smallestSize; + int bestFit; + size_t smallestSize; #endif char * ret = 0; @@ -104,38 +109,37 @@ size = ((size + 0xf) & ~0xf); - if (size == 0) { - if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line); + if (size == 0) + { + if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line); } #if BEST_FIT - smallestSize = 0; - bestFit = -1; + smallestSize = 0; + bestFit = -1; #endif for (i = 0; i < availableNodes; i++) { // find node with equal size, or if not found, // then smallest node that fits. - if ( zavailable[i].size == size ) + if (zavailable[i].size == size) { zallocate(ret = zavailable[i].start, size); zdelete(zavailable, i); availableNodes--; goto done; } #if BEST_FIT - else - { - if ((zavailable[i].size > size) && - ((smallestSize == 0) || - (zavailable[i].size < smallestSize))) - { - bestFit = i; - smallestSize = zavailable[i].size; - } - } - + else + { + if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) + { + bestFit = i; + smallestSize = zavailable[i].size; + } + } + #else - else if ( zavailable[i].size > size ) + else if (zavailable[i].size > size) { zallocate(ret = zavailable[i].start, size); zavailable[i].start += size; @@ -143,71 +147,75 @@ goto done; } #endif - } + } #if BEST_FIT - if (bestFit != -1) - { - zallocate(ret = zavailable[bestFit].start, size); - zavailable[bestFit].start += size; - zavailable[bestFit].size -= size; - } + if (bestFit != -1) + { + zallocate(ret = zavailable[bestFit].start, size); + zavailable[bestFit].start += size; + zavailable[bestFit].size -= size; + } #endif done: if ((ret == 0) || (ret + size >= zalloc_end)) - { + { if (zerror) (*zerror)(ret, size, file, line); - } + } + if (ret != 0) - { + { bzero(ret, size); - } + } #if ZDEBUG - zalloced_size += size; + zalloced_size += size; #endif return (void *) ret; } void free(void * pointer) { - unsigned long rp; + unsigned long rp; int i, found = 0; - size_t tsize = 0; + size_t tsize = 0; char * start = pointer; #if i386 - // Get return address of our caller, - // in case we have to report an error below. - asm volatile ("movl %%esp, %%eax\n\t" + // Get return address of our caller, + // in case we have to report an error below. + asm volatile ("movl %%esp, %%eax\n\t" "subl $4, %%eax\n\t" - "movl 0(%%eax), %%eax" : "=a" (rp) ); + "movl 0(%%eax), %%eax" : "=a" (rp)); #else rp = 0; #endif - if ( !start ) return; + if (!start) + return; for (i = 0; i < allocedNodes; i++) { - if ( zalloced[i].start == start ) + if (zalloced[i].start == start) { tsize = zalloced[i].size; #if ZDEBUG zout -= tsize; - printf(" zz out %d\n",zout); + printf(" zz out %d\n", zout); #endif zdelete(zalloced, i); allocedNodes--; found = 1; #if ZDEBUG - memset(pointer, 0x5A, tsize); + memset(pointer, 0x5A, tsize); #endif break; } } - if ( !found ) { - if (zerror) (*zerror)(pointer, rp, "free", 0); - else return; - } + if (!found) + { + if (zerror) (*zerror)(pointer, rp, "free", 0); + else + return; + } #if ZDEBUG zalloced_size -= tsize; #endif @@ -222,8 +230,7 @@ return; } - if ((i > 0) && - (zavailable[i-1].start + zavailable[i-1].size == start)) + if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) { zavailable[i-1].size += tsize; zcoalesce(); @@ -232,9 +239,10 @@ if ((start + tsize) < zavailable[i].start) { - if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0); - } + if (++availableNodes > totalNodes) + { + if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0); + } zinsert(zavailable, i); zavailable[i].start = start; zavailable[i].size = tsize; @@ -242,31 +250,35 @@ } } - if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0); - } + if (++availableNodes > totalNodes) + { + if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0); + } zavailable[i].start = start; zavailable[i].size = tsize; zcoalesce(); + return; } -static void -zallocate(char * start,int size) +static void zallocate(char * start,int size) { + #if ZDEBUG zout += size; printf(" alloc %d, total 0x%x\n",size,zout); #endif + zalloced[allocedNodes].start = start; zalloced[allocedNodes].size = size; - if (++allocedNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0); - }; + + if (++allocedNodes > totalNodes) + { + if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0); + }; } -static void -zinsert(zmem * zp, int ndx) +static void zinsert(zmem * zp, int ndx) { int i; zmem *z1, *z2; @@ -277,12 +289,11 @@ for (; i >= ndx; i--, z1--, z2--) { - *z2 = *z1; + *z2 = *z1; } } -static void -zdelete(zmem * zp, int ndx) +static void zdelete(zmem * zp, int ndx) { int i; zmem *z1, *z2; @@ -290,24 +301,22 @@ z1 = zp + ndx; z2 = z1 + 1; - for (i = ndx; i < totalNodes-1; i++, z1++, z2++) + for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) { - *z1 = *z2; + *z1 = *z2; } } -static void -zcoalesce(void) +static void zcoalesce(void) { int i; for (i = 0; i < availableNodes-1; i++) { - if ( zavailable[i].start + zavailable[i].size == - zavailable[i+1].start ) + if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) { - zavailable[i].size += zavailable[i+1].size; - zdelete(zavailable, i+1); availableNodes--; + zavailable[i].size += zavailable[i + 1].size; + zdelete(zavailable, i + 1); availableNodes--; return; } } Index: branches/ErmaC/Trunk/i386/libsa/string.c =================================================================== --- branches/ErmaC/Trunk/i386/libsa/string.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/string.c (revision 2037) @@ -139,8 +139,7 @@ /*#endif*/ /* NOTE: Moved from ntfs.c */ -int -memcmp(const void *p1, const void *p2, size_t len) +int memcmp(const void *p1, const void *p2, size_t len) { while (len--) { if (*(const char*)(p1++) != *(const char*)(p2++)) @@ -149,8 +148,7 @@ return 0; } -int -strcmp(const char * s1, const char * s2) +int strcmp(const char * s1, const char * s2) { while (*s1 && (*s1 == *s2)) { s1++; @@ -168,8 +166,7 @@ return(n<0 ? 0 : *s1 - *--s2); } -char * -strcpy(char * s1, const char * s2) +char * strcpy(char * s1, const char * s2) { register char *ret = s1; while ((*s1++ = *s2++)) @@ -177,8 +174,7 @@ return ret; } -char * -strncpy(char * s1, const char * s2, size_t n) +char * strncpy(char * s1, const char * s2, size_t n) { register char *ret = s1; while (n && (*s1++ = *s2++)) @@ -186,8 +182,7 @@ return ret; } -char * -strstr(const char *in, const char *str) +char * strstr(const char *in, const char *str) { char c; size_t len; @@ -210,8 +205,7 @@ return (char *) (in - 1); } -int -ptol(const char *str) +int ptol(const char *str) { register int c = *str; @@ -223,8 +217,7 @@ return c; } -int -atoi(const char *str) +int atoi(const char *str) { register int sum = 0; while (*str == ' ' || *str == '\t') Index: branches/ErmaC/Trunk/i386/libsa/prf.c =================================================================== --- branches/ErmaC/Trunk/i386/libsa/prf.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/prf.c (revision 2037) @@ -56,12 +56,11 @@ * Printn prints a number n in base b. * We don't use recursion to avoid deep kernel stacks. */ -static void -printn(n, b, flag, minwidth, putfn_p, putfn_arg) -u_long n; -int b, flag, minwidth; -void (*putfn_p)(); -void *putfn_arg; +static void printn(n, b, flag, minwidth, putfn_p, putfn_arg) + u_long n; + int b, flag, minwidth; + void (*putfn_p)(); + void *putfn_arg; { char prbuf[11]; register char *cp; @@ -72,7 +71,8 @@ n = (unsigned)(-(int)n); } cp = prbuf; - do { + do + { *cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b]; n /= b; width++; @@ -90,23 +90,22 @@ while (cp > prbuf); } -int prf( - char *fmt, - unsigned int *adx, - void (*putfn_p)(), - void *putfn_arg - ) +int prf(char *fmt, unsigned int *adx, void (*putfn_p)(), void *putfn_arg ) { int b, c, len =0; char *s; int flag = 0, width = 0; int minwidth; - + loop: - while ((c = *fmt++) != '%') { + while ((c = *fmt++) != '%') + { if(c == '\0') + { return len; - if (putfn_p) { + } + if (putfn_p) + { (*putfn_p)(c, putfn_arg); } len++; @@ -121,7 +120,8 @@ flag |= SPACE; goto again; case '0': - if (minwidth == 0) { + if (minwidth == 0) + { /* this is a flag */ flag |= ZERO; goto again; @@ -150,29 +150,35 @@ case 'o': case 'O': b = 8; number: - if (putfn_p) { + if (putfn_p) + { printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg); } len++; break; case 's': s = (char *)*adx; - while ((c = *s++)) { - if (putfn_p) { + while ((c = *s++)) + { + if (putfn_p) + { (*putfn_p)(c, putfn_arg); } len++; width++; } - while (width++ < minwidth) { - if (putfn_p) { + while (width++ < minwidth) + { + if (putfn_p) + { (*putfn_p)(' ', putfn_arg); } len++; } break; case 'c': - if (putfn_p) { + if (putfn_p) + { (*putfn_p)((char)*adx, putfn_arg); } len++; Index: branches/ErmaC/Trunk/i386/libsa/efi_tables.c =================================================================== --- branches/ErmaC/Trunk/i386/libsa/efi_tables.c (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/efi_tables.c (revision 2037) @@ -129,16 +129,18 @@ bool efi_guid_is_null(EFI_GUID const *pGuid) { - if(pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0) + if (pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0) { int i; - for(i=0; i<8; ++i) + + for (i = 0; i < 8; ++i) { - if(pGuid->Data4[i] != 0) + if (pGuid->Data4[i] != 0) return false; } return true; } + return false; } @@ -154,9 +156,11 @@ COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data2); COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data3); int i; - for(i=0; i<8; ++i) + + for(i = 0; i < 8; ++i) { COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data4[i]); } return 0; } + Index: branches/ErmaC/Trunk/i386/libsa/memory.h =================================================================== --- branches/ErmaC/Trunk/i386/libsa/memory.h (revision 2036) +++ branches/ErmaC/Trunk/i386/libsa/memory.h (revision 2037) @@ -118,9 +118,10 @@ #define OFFSET(addr) ((addr) & 0xFFFF) #define SEGMENT(addr) (((addr) & 0xF0000) >> 4) -/* Extract segment/offset in normalized form so that the resulting far pointer - will point to something that is very unlikely to straddle a segment. - This is sometimes known as a "huge" pointer. +/* + * Extract segment/offset in normalized form so that the resulting far pointer + * will point to something that is very unlikely to straddle a segment. + * This is sometimes known as a "huge" pointer. */ #define NORMALIZED_OFFSET(addr) ((addr) & 0x000F) #define NORMALIZED_SEGMENT(addr) (((addr) & 0xFFFF0) >> 4) @@ -131,7 +132,7 @@ #define MIN_SYS_MEM_KB (32 * 1024) /* - * The number of descriptor entries in the GDT. + * The number of descriptor entries in the GDT (Global Descriptor Table). */ #define NGDTENT 7 @@ -139,6 +140,6 @@ * The total size of the GDT in bytes. * Each descriptor entry require 8 bytes. */ -#define GDTLIMIT ( NGDTENT * 8 ) +#define GDTLIMIT (NGDTENT * 8) #endif /* !__BOOT_MEMORY_H */ Index: branches/ErmaC/Trunk/CHANGES =================================================================== --- branches/ErmaC/Trunk/CHANGES (revision 2036) +++ branches/ErmaC/Trunk/CHANGES (revision 2037) @@ -1,3 +1,8 @@ +- This revision is devoted to Samantha, AKA DHP or Revogirl in the OSx86 scene. + A young talent we lost prematurely. + Part of her work will now live on in the Chameleon source code. + Changes: code cleaned, improvements taken from Revoboot. + http://www.insanelymac.com/forum/index.php?showtopic=259090 - Apply patch by Andrey B http://forge.voodooprojects.org/p/chameleon/issues/270/ - cparm : Added a Sata module, known as YellowIconFixer in my branch, useful to fix yellow icon issue (can also fix an issue with the apple's dvd player application in moutain lion) , for now not added in the pkg script !!!