OpenBIOS
Threads by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2000 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1999 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1998 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1997 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1996 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1995 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1994 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1993 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1992 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1991 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1990 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1989 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1988 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1987 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1986 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1985 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1984 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1983 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1982 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1981 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1980 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1979 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1978 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1977 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1976 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1975 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1974 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1973 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1972 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1971 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1970 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1969 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1968 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1967 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1966 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1965 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1964 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1963 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1962 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1961 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1960 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1959 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1958 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1957 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1956 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1955 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1954 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1953 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1952 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1951 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1950 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1949 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1948 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1947 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1946 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1945 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1944 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1943 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1942 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1941 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1940 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1939 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1938 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1937 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1936 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1935 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1934 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1933 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1932 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1931 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1930 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1929 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1928 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1927 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1926 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1925 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1924 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1923 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1922 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1921 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1920 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1919 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1918 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1917 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1916 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1915 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1914 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1913 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1912 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1911 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1910 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1909 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1908 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1907 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1906 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1905 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1904 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
January 2008
- 11 participants
- 52 discussions
Author: wmb
Date: 2008-02-01 00:34:01 +0100 (Fri, 01 Feb 2008)
New Revision: 802
Modified:
dev/geode/smi.fth
Log:
Geode SMI handler - Another round of tuning. Hopefully the last stylistic pass.
Modified: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth 2008-01-31 19:01:35 UTC (rev 801)
+++ dev/geode/smi.fth 2008-01-31 23:34:01 UTC (rev 802)
@@ -9,64 +9,85 @@
previous definitions
+\ The general naming convention here is that smm-* refers to
+\ addresses within the memory that is set aside for SMI handling.
+\ smi-* refers to stuff in the Forth domain.
+
h# f.f000 constant smm-base
h# 1000 constant smm-size \ We use about 3K of this, 2K for stacks
-: +smm ( offset -- adr ) smm-base + ;
+: +smm ( segment-relative-adr -- adr ) smm-base + ;
+: -smm ( adr -- segment-relative-adr ) smm-base - ;
-h# 30 constant /smm-gdt
+h# 28 constant /smm-gdt
+h# 8 constant smm-c16
+h# 10 constant smm-d16
+h# 18 constant smm-c32
+h# 20 constant smm-d32
-\ The handler code takes about h# 140 bytes
+\ For stuff that grows down - add the offset first
+: rm-stack ( offset len "name" -- offset' ) + dup constant ;
+: pm-stack ( offset len "name" -- offset' ) + dup +smm constant ;
-\ The following save area + the SMM_HEADER (h# 30) takes about h# 100
-h# 200
-dup constant smm-save-gdt 8 +
-dup constant smm-gdtp 8 +
-dup constant smm-gdt /smm-gdt +
-dup constant smm-pdir la1+
-dup constant smm-forth-origin la1+
-dup constant smm-forth-up la1+
-dup constant smm-forth-entry la1+
+\ For individual data items - add the offset afterwards
+: pm-data ( offset len "name" -- offset' ) over +smm constant + ;
+: rm-data ( offset len "name" -- offset' ) over constant + ;
-\ 10 bytes for each of 6 segment registers
-dup constant smm-save-seg d# 60 +
-dup constant smm-save-esp la1+
-dup constant smm-sp la1+
- \ 8x 4-byte general registers + config adr + cs3 + spare
-h# 38 + constant smm-stack
+\ Layout of SMM memory area:
+0 \ Entry/exit handler code goes here, at the origin
+h# 180 rm-data smm-gdt \ The GDT is embedded in the code wad
+ \ The handler code takes about h# 160 bytes
-h# 300 constant smm-header
+\ The following locations are for saving/restoring registers
+\ d# 60 rm-data smm-save-seg \ 6 10-byte segment registers
+d# 50 rm-data smm-save-seg \ 6 10-byte segment registers
+/l rm-data smm-save-esp \ Caller's stack pointer
+6 rm-data smm-save-gdt \ Caller's GDT pointer
-: set-descr ( base limit d.type sel -- )
- >r format-descriptor ( d.descr r: sel )
- r> smm-gdt + +smm d! ( )
-;
+0 pm-data smm-regs \ Alternate name, for use by Forth
+0 rm-data smm-sp \ Real-mode sp after saving registers
+d# 10 /l* rm-stack smm-stack \ CR3, portCF8, 8 general registers
-: set-smm-descs ( -- )
-\ smm-base -1 code32 format-descriptor smm-gdt 8 + +smm d! \ Boosted code32
- smm-base smm-size 1- code16 h# 10 set-descr
- smm-base smm-size 1- data16 h# 18 set-descr
- 0 -1 code32 h# 20 set-descr
- 0 -1 data32 h# 28 set-descr
- /smm-gdt 1- smm-gdtp +smm w! \ GDT limit
- smm-gdt +smm smm-gdtp +smm wa1+ l! \ GDT base
-;
+h# 30 pm-stack smm-header \ Top address where hardware puts the SMM info frame
-nuser smi-sp0
-nuser smi-rp0
+\ These locations are set once at installation time. The entry code reads them.
+[ifdef] virtual-mode
+/l pm-data smm-pdir \ Page directory pointer so we can enable paging
+[then]
+/l pm-data smm-forth-base \ Base address of the Forth dictionary
+/l pm-data smm-forth-up \ Base address of the Forth user area
+/l pm-data smm-forth-entry \ Entry address of Forth SMI handler
+/l pm-data smm-save-sp0 \ Exchanged with sp0 user variable
+/l pm-data smm-save-rp0 \ Exchanged with rp0 user variable
-label smm-handler
+h# 400 pm-stack smm-sp0 \ SMM Forth data stack
+h# 400 pm-stack smm-rp0 \ SMM Forth return stack
+drop
+
+label smi-handler
16-bit
+
+ \ GDT (with jump tucked in at the beginning)
+ \ We put the GDT right at the beginning and use the first entry (which
+ \ cannot be used as a selector) for a 2-byte jmp and the 6-byte GDT pointer
+ here /smm-gdt + #) jmp \ Jump past GDT - 2 bytes
+ /smm-gdt 1- w, smm-base l, \ GDT pointer - limit.w base.l
+ smm-base smm-size 1- code16 format-descriptor swap l, l, \ 8 - smm-c16
+ smm-base smm-size 1- data16 format-descriptor swap l, l, \ 10 - smm-d16
+ 0 -1 code32 format-descriptor swap l, l, \ 18 - smm-c32
+ 0 -1 data32 format-descriptor swap l, l, \ 20 - smm-d32
+ \ End of GDT
+
cs: ds smm-save-seg d# 00 + #) svdc
- cs: smm-gdt h# 18 + #) ds rsdc \ GDT reference
+ cs: smm-gdt smm-d16 + #) ds rsdc
\ Now we can use the data segment
es smm-save-seg d# 10 + #) svdc
fs smm-save-seg d# 20 + #) svdc
gs smm-save-seg d# 30 + #) svdc
ss smm-save-seg d# 40 + #) svdc
- cs smm-save-seg d# 50 + #) svdc \ So we can get back to the boost segment
+\ cs smm-save-seg d# 50 + #) svdc \ So we can get back to the boost segment
- smm-gdt h# 18 + #) ss rsdc \ GDT reference
+ smm-gdt smm-d16 + #) ss rsdc
op: sp smm-save-esp #) mov
smm-stack # sp mov \ Now we have a stack
@@ -78,72 +99,65 @@
op: ax push
cr3 ax mov op: ax push
- sp smm-sp #) mov
+ \ The real-mode stack pointer is now at a known location
\ Get into protected mode using the same segments
\ Don't bother with the IDT; we won't enable interrupts
op: smm-save-gdt #) sgdt
- op: smm-gdtp #) lgdt
+ op: smm-gdt 2+ #) lgdt
cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
- op: here 7 + smm-handler - +smm h# 20 #) far jmp \ GDT reference
+ op: here 7 + smi-handler - +smm smm-c32 #) far jmp
32-bit
\ Reload segment registers with protected mode bits
- op: h# 28 # ax mov \ GDT reference
+ op: smm-d32 # ax mov
ax ds mov ax es mov ax fs mov ax gs mov ax ss mov
+[ifdef] virtual-mode
\ Turn on paging
- smm-pdir +smm #) ax mov
+ smm-pdir #) ax mov
ax cr3 mov \ Set Page Directory Base Register
cr0 ax mov h# 8000.0000 # ax or ax cr0 mov \ Turn on Paging Enable bit
+[then]
\ Beginning of Forth-specific stuff
- smm-forth-origin +smm #) bx mov
- smm-forth-up +smm #) up mov
- smm-forth-entry +smm #) ip mov
+ smm-forth-base #) bx mov
+ smm-forth-up #) up mov
+ smm-forth-entry #) ip mov
\ Exchange the stack and return stack pointer with the smi versions
- 'user sp0 sp mov
- 'user rp0 rp mov
+ 'user sp0 sp mov smm-save-sp0 #) sp xchg sp 'user sp0 mov
+ 'user rp0 rp mov smm-save-rp0 #) rp xchg rp 'user rp0 mov
- 'user smi-sp0 sp xchg
- 'user smi-rp0 rp xchg
-
- sp 'user sp0 mov
- rp 'user rp0 mov
-
-
cld
c;
code (smi-return) \ This code field must be relocated after copying to SMM memory
\ Exchange the stack and return stack pointer with the smi versions
- 'user sp0 sp mov
- 'user rp0 rp mov
+ 'user sp0 sp mov smm-save-sp0 #) sp xchg sp 'user sp0 mov
+ 'user rp0 rp mov smm-save-rp0 #) rp xchg rp 'user rp0 mov
- 'user smi-sp0 sp xchg
- 'user smi-rp0 rp xchg
-
- sp 'user sp0 mov
- rp 'user rp0 mov
-
\ End of Forth-specific stuff
+[ifdef] virtual-mode
\ Turn off paging
cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
+[then]
- here 7 + smm-handler - h# 08 #) far jmp \ Get into the boosted segment
+ here 7 + smi-handler - smm-c16 #) far jmp \ Get into the boosted segment
16-bit
+ smm-d16 # ax mov ax ss mov ax ds mov \ Reload data and stack segments
+
cr0 ax mov 1 invert # al and ax cr0 mov \ Exit protected mode
\ Reload data segment registers
- cs: smm-gdt h# 18 + #) ss rsdc \ GDT reference
- cs: smm-gdt h# 18 + #) ds rsdc \ GDT reference
+\ cs: smm-gdt smm-d16 + #) ss rsdc
+\ cs: smm-gdt smm-d16 + #) ds rsdc
op: smm-save-gdt #) lgdt
- smm-sp #) sp mov
+ smm-sp # sp mov
op: ax pop ax cr3 mov
op: ax pop
@@ -162,9 +176,9 @@
rsm
end-code
-here smm-handler - constant /smm-handler
+here smi-handler - constant /smi-handler
-: smi-return ( -- ) [ ' (smi-return) smm-handler - +smm ] literal execute ;
+: smi-return ( -- ) [ ' (smi-return) smi-handler - +smm ] literal execute ;
defer handle-smi ' noop is handle-smi
create smm-exec ] handle-smi smi-return [
@@ -192,27 +206,28 @@
\ Base Limit
smm-base smm-size 1- h# 133b msr!
- smm-base smm-header + 0 h# 132b msr! \ Offset of SMM Header
+ smm-header 0 h# 132b msr! \ Offset of SMM Header
h# 18. h# 1301 msr! \ Enable IO and software SMI
\ Unnecessary if already in mapped memory
\ smm-base dup smm-size -1 mmu-map
- smm-handler smm-base /smm-handler move
+ smi-handler smm-base /smi-handler move
\ Relocate the code field of the code word that is embedded in the sequence
- ['] (smi-return) smm-handler - +smm ( cfa-adr )
+ ['] (smi-return) smi-handler - +smm ( cfa-adr )
dup ta1+ swap token!
- set-smm-descs
- cr3@ smm-pdir +smm l!
+[ifdef] virtual-mode
+ cr3@ smm-pdir l!
+[then]
- origin smm-forth-origin +smm l!
- smm-exec smm-forth-entry +smm l!
- up@ smm-forth-up +smm l!
- h# 800 +smm smi-sp0 !
- h# c00 +smm smi-rp0 !
+ origin smm-forth-base l!
+ smm-exec smm-forth-entry l!
+ up@ smm-forth-up l!
+ smm-sp0 smm-save-sp0 !
+ smm-rp0 smm-save-rp0 !
enable-virtual-pci
;
@@ -220,18 +235,19 @@
: smi-interact ( -- ) ." In SMI" cr quit ;
' smi-interact is handle-smi
-: smm-cs-base ( -- l ) smm-header h# 1c - +smm l@ ;
-: smm-eip ( -- l ) smm-header h# 10 - +smm l@ ;
-: smm-next-eip ( -- l ) smm-header h# 14 - +smm l@ ;
-: smm-flags ( -- w ) smm-header h# 24 - +smm w@ ;
-: smm-io-port ( -- port# ) smm-header h# 28 - +smm w@ ;
-: smm-io-size ( -- size ) smm-header h# 26 - +smm w@ ;
-: smm-io-data ( -- data ) smm-header h# 2c - +smm l@ ;
+\ : smm-cs-base ( -- l ) smm-header h# 1c - l@ ;
+\ : smm-eip ( -- l ) smm-header h# 10 - l@ ;
+\ : smm-next-eip ( -- l ) smm-header h# 14 - l@ ;
+: smm-flags ( -- w ) smm-header h# 24 - w@ ;
+: smm-io-port ( -- port# ) smm-header h# 28 - w@ ;
+: smm-io-size ( -- size ) smm-header h# 26 - w@ ;
+: smm-io-data ( -- data ) smm-header h# 2c - l@ ;
+\ Stacked registers: 0:CR3, 1:portCF8, 2:DI, 3:SI, 4:BP, 5:SP, 6:BX, 7:DX, 8:CX, 9:AX
: smm-config-adr ( -- adr )
- smm-sp +smm w@ +smm la1+ @ h# 7fff.fffc and
+ smm-regs la1+ @ h# 7fff.fffc and
smm-io-port 3 and or
;
-: smm-eax ( -- adr ) smm-sp +smm w@ +smm 9 la+ ;
+: smm-eax ( -- adr ) smm-regs 9 la+ ;
: vr-spoof? ( -- handled? ) false ;
: config-spoof? ( -- handled? )
1
0
Author: wmb
Date: 2008-01-31 20:01:35 +0100 (Thu, 31 Jan 2008)
New Revision: 801
Modified:
dev/geode/smi.fth
Log:
Geode SMI handler - Added PCI config space virtualization.
Modified: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth 2008-01-31 17:27:36 UTC (rev 800)
+++ dev/geode/smi.fth 2008-01-31 19:01:35 UTC (rev 801)
@@ -168,6 +168,11 @@
defer handle-smi ' noop is handle-smi
create smm-exec ] handle-smi smi-return [
+: enable-virtual-pci ( -- )
+ h# 5000.2012 msr@ swap h# 8002 or swap h# 5000.2012 msr! \ Virtualize devices f and 1
+ h# 5000.2002 msr@ swap 8 invert and swap h# 5000.2002 msr! \ Enable SSMI for config accesses
+;
+
: setup-smi ( -- )
\ This is how you would map the SMM region to physical memory at 4000.0000
\ This is a Base Mask Offset descriptor - the base address
@@ -208,14 +213,58 @@
up@ smm-forth-up +smm l!
h# 800 +smm smi-sp0 !
h# c00 +smm smi-rp0 !
+
+ enable-virtual-pci
;
: smi-interact ( -- ) ." In SMI" cr quit ;
' smi-interact is handle-smi
-: enable-virtual-pci ( -- )
- h# 5000.2012 msr@ swap h# 8002 or swap h# 5000.2002 msr! \ Virtualize devices f and 1
- h# 5000.2002 msr@ swap 8 invert and swap h# 5000.2002 msr! \ Enable SSMI for config accesses
+: smm-cs-base ( -- l ) smm-header h# 1c - +smm l@ ;
+: smm-eip ( -- l ) smm-header h# 10 - +smm l@ ;
+: smm-next-eip ( -- l ) smm-header h# 14 - +smm l@ ;
+: smm-flags ( -- w ) smm-header h# 24 - +smm w@ ;
+: smm-io-port ( -- port# ) smm-header h# 28 - +smm w@ ;
+: smm-io-size ( -- size ) smm-header h# 26 - +smm w@ ;
+: smm-io-data ( -- data ) smm-header h# 2c - +smm l@ ;
+: smm-config-adr ( -- adr )
+ smm-sp +smm w@ +smm la1+ @ h# 7fff.fffc and
+ smm-io-port 3 and or
;
+: smm-eax ( -- adr ) smm-sp +smm w@ +smm 9 la+ ;
+: vr-spoof? ( -- handled? ) false ;
+: config-spoof? ( -- handled? )
+ smm-io-port 3 invert and h# cfc <> if false exit then
+
+ \ The existing Forth config spoofer does the hard work
+ smm-flags 2 and if \ Write
+ smm-io-data smm-config-adr ( data config-adr )
+ smm-io-size case
+ 1 of config-b! endof
+ 3 of config-w! endof
+ f of config-l! endof
+ endcase
+ else
+ smm-config-adr ( config-adr )
+ smm-io-size case
+ 1 of config-b@ smm-eax c! endof
+ 3 of config-w@ smm-eax w! endof
+ f of config-l@ smm-eax l! endof
+ endcase
+ then
+ true
+;
+: virtualize-io ( -- )
+ smm-flags h# 80 and 0= if exit then
+ config-spoof? if exit then
+ vr-spoof? if exit then
+;
+: soft-smi smi-interact ;
+: smi-dispatch ( -- )
+ smm-flags h# 80 and if virtualize-io then
+ smm-flags h# 8 and if soft-smi then
+;
+' smi-dispatch is handle-smi
+
code smi smint c;
1
0
Author: wmb
Date: 2008-01-31 18:27:36 +0100 (Thu, 31 Jan 2008)
New Revision: 800
Modified:
dev/geode/smi.fth
Log:
Geode SMI handler - cleaned up the return from 32-bit to 16-bit mode.
Modified: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth 2008-01-31 10:15:58 UTC (rev 799)
+++ dev/geode/smi.fth 2008-01-31 17:27:36 UTC (rev 800)
@@ -13,7 +13,7 @@
h# 1000 constant smm-size \ We use about 3K of this, 2K for stacks
: +smm ( offset -- adr ) smm-base + ;
-h# 28 constant /smm-gdt
+h# 30 constant /smm-gdt
\ The handler code takes about h# 140 bytes
@@ -43,10 +43,10 @@
: set-smm-descs ( -- )
\ smm-base -1 code32 format-descriptor smm-gdt 8 + +smm d! \ Boosted code32
- smm-base smm-size 1- code16 h# 08 set-descr
- smm-base smm-size 1- data16 h# 10 set-descr
- 0 -1 code32 h# 18 set-descr
- 0 -1 data32 h# 20 set-descr
+ smm-base smm-size 1- code16 h# 10 set-descr
+ smm-base smm-size 1- data16 h# 18 set-descr
+ 0 -1 code32 h# 20 set-descr
+ 0 -1 data32 h# 28 set-descr
/smm-gdt 1- smm-gdtp +smm w! \ GDT limit
smm-gdt +smm smm-gdtp +smm wa1+ l! \ GDT base
;
@@ -58,14 +58,15 @@
16-bit
cs: ds smm-save-seg d# 00 + #) svdc
- cs: smm-gdt h# 10 + #) ds rsdc \ Now we have a data segment
+ cs: smm-gdt h# 18 + #) ds rsdc \ GDT reference
+ \ Now we can use the data segment
es smm-save-seg d# 10 + #) svdc
fs smm-save-seg d# 20 + #) svdc
gs smm-save-seg d# 30 + #) svdc
ss smm-save-seg d# 40 + #) svdc
cs smm-save-seg d# 50 + #) svdc \ So we can get back to the boost segment
- smm-gdt h# 10 + #) ss rsdc
+ smm-gdt h# 18 + #) ss rsdc \ GDT reference
op: sp smm-save-esp #) mov
smm-stack # sp mov \ Now we have a stack
@@ -85,11 +86,11 @@
op: smm-gdtp #) lgdt
cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
- op: here 7 + smm-handler - +smm h# 18 #) far jmp
+ op: here 7 + smm-handler - +smm h# 20 #) far jmp \ GDT reference
32-bit
\ Reload segment registers with protected mode bits
- op: h# 20 # ax mov
+ op: h# 28 # ax mov \ GDT reference
ax ds mov ax es mov ax fs mov ax gs mov ax ss mov
\ Turn on paging
@@ -131,16 +132,14 @@
\ Turn off paging
cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
- cr0 ax mov 1 invert # al and ax cr0 mov \ Enter real mode
-
- \ Return to the boosted code-16 address space
- smm-save-seg d# 50 + +smm #) cs rsdc
+ here 7 + smm-handler - h# 08 #) far jmp \ Get into the boosted segment
16-bit
- op: here 5 + smm-base - #) jmp \ Decrease IP while increasing the segment register
+ cr0 ax mov 1 invert # al and ax cr0 mov \ Exit protected mode
+
\ Reload data segment registers
- cs: smm-gdt h# 10 + #) ss rsdc
- cs: smm-gdt h# 10 + #) ds rsdc
+ cs: smm-gdt h# 18 + #) ss rsdc \ GDT reference
+ cs: smm-gdt h# 18 + #) ds rsdc \ GDT reference
op: smm-save-gdt #) lgdt
@@ -186,11 +185,7 @@
h# 000ff.0.00.000ff.1.01. h# 180e msr!
\ Base Limit
-\ smm-base smm-size 1- h# 133b msr!
- \ The limit here must be large enough to cover the code address
- \ between the time that we reenter real mode and the time we
- \ reestablish the boosted descriptor.
- smm-base -1 h# 133b msr! \ Big limit
+ smm-base smm-size 1- h# 133b msr!
smm-base smm-header + 0 h# 132b msr! \ Offset of SMM Header
1
0
Author: wmb
Date: 2008-01-31 11:15:58 +0100 (Thu, 31 Jan 2008)
New Revision: 799
Modified:
dev/geode/smi.fth
Log:
Geode SMI handler - the code is pretty tight now, using only one page of SMM RAM.
Modified: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth 2008-01-31 05:16:56 UTC (rev 798)
+++ dev/geode/smi.fth 2008-01-31 10:15:58 UTC (rev 799)
@@ -9,74 +9,65 @@
previous definitions
-h# 4000.0000 constant smm-base
-h# 1.0000 constant smm-size
+h# f.f000 constant smm-base
+h# 1000 constant smm-size \ We use about 3K of this, 2K for stacks
: +smm ( offset -- adr ) smm-base + ;
-h# 30 constant /smm-gdt
-smm-size h# 100 -
-dup constant smm-stack
-dup constant smm-save-gdt 8 +
-dup constant smm-gdtp 8 +
-dup constant smm-gdt /smm-gdt +
-dup constant smm-pdir la1+
+h# 28 constant /smm-gdt
+
+\ The handler code takes about h# 140 bytes
+
+\ The following save area + the SMM_HEADER (h# 30) takes about h# 100
+h# 200
+dup constant smm-save-gdt 8 +
+dup constant smm-gdtp 8 +
+dup constant smm-gdt /smm-gdt +
+dup constant smm-pdir la1+
dup constant smm-forth-origin la1+
dup constant smm-forth-up la1+
+dup constant smm-forth-entry la1+
-dup constant smm-code16 h# a +
-dup constant smm-data16 h# a +
-dup constant smm-code32 h# a +
-dup constant smm-data32 h# a +
-dup constant smm-ds h# a +
-dup constant smm-es h# a +
-dup constant smm-fs h# a +
-dup constant smm-gs h# a +
-dup constant smm-ss h# a +
-dup constant smm-cs h# a +
-dup constant smm-esp la1+
-dup constant smm-sp wa1+
-drop
+\ 10 bytes for each of 6 segment registers
+dup constant smm-save-seg d# 60 +
+dup constant smm-save-esp la1+
+dup constant smm-sp la1+
+ \ 8x 4-byte general registers + config adr + cs3 + spare
+h# 38 + constant smm-stack
-: set-descr ( base limit d.type sel offset -- )
- +smm 2>r format-descriptor ( d.descr r: sel adr )
- 2r@ 8 + w! ( d.descr r: sel adr )
- 2dup r> d! ( d.descr r: sel )
- r> smm-gdt + +smm d! ( )
+h# 300 constant smm-header
+
+: set-descr ( base limit d.type sel -- )
+ >r format-descriptor ( d.descr r: sel )
+ r> smm-gdt + +smm d! ( )
;
: set-smm-descs ( -- )
- smm-base -1 code32 format-descriptor smm-gdt 8 + +smm d! \ Boosted code32
-
- smm-base smm-size 1- code16 h# 10 smm-code16 set-descr
- smm-base smm-size 1- data16 h# 18 smm-data16 set-descr
- 0 -1 code32 h# 20 smm-code32 set-descr
- 0 -1 data32 h# 28 smm-data32 set-descr
- /smm-gdt 1- smm-gdtp +smm w! \ GDT limit
+\ smm-base -1 code32 format-descriptor smm-gdt 8 + +smm d! \ Boosted code32
+ smm-base smm-size 1- code16 h# 08 set-descr
+ smm-base smm-size 1- data16 h# 10 set-descr
+ 0 -1 code32 h# 18 set-descr
+ 0 -1 data32 h# 20 set-descr
+ /smm-gdt 1- smm-gdtp +smm w! \ GDT limit
smm-gdt +smm smm-gdtp +smm wa1+ l! \ GDT base
;
nuser smi-sp0
nuser smi-rp0
-defer smi-return
-: smi-exec ( -- )
- ." Forth SMI handler" cr
- quit
- smi-return
-;
label smm-handler
16-bit
- cs: ds smm-ds #) svdc
- cs: smm-data16 #) ds rsdc \ Now we have a data segment
+ cs: ds smm-save-seg d# 00 + #) svdc
+ cs: smm-gdt h# 10 + #) ds rsdc \ Now we have a data segment
+ es smm-save-seg d# 10 + #) svdc
+ fs smm-save-seg d# 20 + #) svdc
+ gs smm-save-seg d# 30 + #) svdc
+ ss smm-save-seg d# 40 + #) svdc
+ cs smm-save-seg d# 50 + #) svdc \ So we can get back to the boost segment
- es smm-es #) svdc
- fs smm-fs #) svdc
- gs smm-gs #) svdc
- ss smm-ss #) svdc
- smm-data16 #) ss rsdc \ Now we have a data segment
+ smm-gdt h# 10 + #) ss rsdc
- op: sp smm-esp #) mov
+ op: sp smm-save-esp #) mov
smm-stack # sp mov \ Now we have a stack
op: pusha
@@ -88,30 +79,18 @@
cr3 ax mov op: ax push
sp smm-sp #) mov
-\ ---
\ Get into protected mode using the same segments
\ Don't bother with the IDT; we won't enable interrupts
op: smm-save-gdt #) sgdt
op: smm-gdtp #) lgdt
-\ Test<
- \ Get into the 4G flat code-32 address space
- cs smm-cs #) svdc \ So we can get back
- smm-code32 #) cs rsdc \ 4G flat address space for code
+ cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
+ op: here 7 + smm-handler - +smm h# 18 #) far jmp
32-bit
- here 5 + +smm #) jmp \ Into unboosted segment
-nop nop nop nop nop nop nop
-
- cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
- here 2 + #) jmp
-
\ Reload segment registers with protected mode bits
- cs: smm-data32 +smm #) ds rsdc
- smm-data32 +smm #) ss rsdc
- smm-data32 +smm #) es rsdc
- smm-data32 +smm #) fs rsdc
- smm-data32 +smm #) gs rsdc
+ op: h# 20 # ax mov
+ ax ds mov ax es mov ax fs mov ax gs mov ax ss mov
\ Turn on paging
smm-pdir +smm #) ax mov
@@ -121,6 +100,7 @@
\ Beginning of Forth-specific stuff
smm-forth-origin +smm #) bx mov
smm-forth-up +smm #) up mov
+ smm-forth-entry +smm #) ip mov
\ Exchange the stack and return stack pointer with the smi versions
'user sp0 sp mov
@@ -132,13 +112,10 @@
sp 'user sp0 mov
rp 'user rp0 mov
- \ Set the interpreter pointer
- 'body smi-exec origin - # ip mov
- bx ip add \ add current origin
cld
c;
-code (smi-return)
+code (smi-return) \ This code field must be relocated after copying to SMM memory
\ Exchange the stack and return stack pointer with the smi versions
'user sp0 sp mov
'user rp0 rp mov
@@ -149,30 +126,24 @@
sp 'user sp0 mov
rp 'user rp0 mov
-\ End of Forth-specific stuff
+ \ End of Forth-specific stuff
\ Turn off paging
cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
cr0 ax mov 1 invert # al and ax cr0 mov \ Enter real mode
- here 2 + #) jmp
-
- \ Reload segment registers with real mode bits
- cs: smm-data16 +smm #) ss rsdc
- cs: smm-data16 +smm #) ds rsdc
-
-
\ Return to the boosted code-16 address space
- smm-cs #) cs rsdc
+ smm-save-seg d# 50 + +smm #) cs rsdc
16-bit
- here 2 + #) jmp \ 16-bit JMP zeros EIP[31:16]
+ op: here 5 + smm-base - #) jmp \ Decrease IP while increasing the segment register
-\ >Test
+ \ Reload data segment registers
+ cs: smm-gdt h# 10 + #) ss rsdc
+ cs: smm-gdt h# 10 + #) ds rsdc
op: smm-save-gdt #) lgdt
-\ ---
smm-sp #) sp mov
op: ax pop ax cr3 mov
@@ -182,86 +153,74 @@
op: popa
- op: smm-esp #) sp mov
+ op: smm-save-esp #) sp mov
- smm-ss #) ss rsdc
- smm-gs #) gs rsdc
- smm-fs #) fs rsdc
- smm-es #) es rsdc
- smm-ds #) ds rsdc
+ smm-save-seg d# 40 + #) ss rsdc
+ smm-save-seg d# 30 + #) gs rsdc
+ smm-save-seg d# 20 + #) fs rsdc
+ smm-save-seg d# 10 + #) es rsdc
+ smm-save-seg d# 00 + #) ds rsdc
rsm
end-code
here smm-handler - constant /smm-handler
+: smi-return ( -- ) [ ' (smi-return) smm-handler - +smm ] literal execute ;
+defer handle-smi ' noop is handle-smi
+create smm-exec ] handle-smi smi-return [
+
: setup-smi ( -- )
- \ Map the SMM region to physical memory at e.0000
+ \ This is how you would map the SMM region to physical memory at 4000.0000
\ This is a Base Mask Offset descriptor - the base address
\ is 4000.0000 and to that is added the offset c00e.0000
\ to give the address 000e.0000 in the GLMC address space.
- \ The mask is ffff.0000 , i.e. 64K
- h# 2.c00e0.40000.ffff0. h# 1000.0026 msr!
+ \ The mask is ffff.f000 , i.e. 4K
- \ Put 64K SMM memory at 4000.0000 in the processor linear address space
+ \ This is unnecessary if the SMM memory is in a region that is
+ \ already mapped with a descriptor
+ \ h# 2.c00e0.40000.fffff. h# 1000.0026 msr!
+
+ \ Put 4K SMM memory at 000f.f000 in the processor linear address space
\ Cacheable in SMM mode, non-cacheable otherwise
- h# 4000f.0.00.40000.1.01. h# 180e msr!
+ \ Depends on smm-base and smm-size
+ h# 000ff.0.00.000ff.1.01. h# 180e msr!
\ Base Limit
\ smm-base smm-size 1- h# 133b msr!
+ \ The limit here must be large enough to cover the code address
+ \ between the time that we reenter real mode and the time we
+ \ reestablish the boosted descriptor.
smm-base -1 h# 133b msr! \ Big limit
- smm-base smm-size + 0 h# 132b msr! \ Offset of SMM Header
+ smm-base smm-header + 0 h# 132b msr! \ Offset of SMM Header
h# 18. h# 1301 msr! \ Enable IO and software SMI
- smm-base dup smm-size -1 mmu-map
+ \ Unnecessary if already in mapped memory
+ \ smm-base dup smm-size -1 mmu-map
smm-handler smm-base /smm-handler move
+ \ Relocate the code field of the code word that is embedded in the sequence
['] (smi-return) smm-handler - +smm ( cfa-adr )
dup ta1+ swap token!
set-smm-descs
cr3@ smm-pdir +smm l!
+
origin smm-forth-origin +smm l!
+ smm-exec smm-forth-entry +smm l!
up@ smm-forth-up +smm l!
- h# 1000 +smm smi-sp0 !
- h# 2000 +smm smi-rp0 !
+ h# 800 +smm smi-sp0 !
+ h# c00 +smm smi-rp0 !
;
-: do-smi-return ( -- )
- ['] (smi-return) smm-handler - +smm execute
-;
-' do-smi-return is smi-return
+: smi-interact ( -- ) ." In SMI" cr quit ;
+' smi-interact is handle-smi
+
: enable-virtual-pci ( -- )
h# 5000.2012 msr@ swap h# 8002 or swap h# 5000.2002 msr! \ Virtualize devices f and 1
h# 5000.2002 msr@ swap 8 invert and swap h# 5000.2002 msr! \ Enable SSMI for config accesses
;
-
-code smi smint ax push c;
-
-\ Forth stuff
-[ifdef] notyet
-[then]
-
-[ifdef] notyet
-XXX code to return from Forth
-[then]
-
-[ifdef] notyet
- \ We are running in a segment that is identity mapped
- cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
-[then]
-
-label emita
- op: dx dx xor dx dx xor
- h# 3fd # dx mov
- begin dx al in h# 20 # al and 0<> until
- h# 41 # al mov h# f8 # dl mov al dx out
- begin again
-\ h# 3fd # dx mov
-\ begin dx al in h# 20 # al and 0<> until
-end-code
-here emita - constant /emita
-: puta ( adr -- ) emita swap /emita move ;
+code smi smint c;
1
0
Author: wmb
Date: 2008-01-31 06:16:56 +0100 (Thu, 31 Jan 2008)
New Revision: 798
Modified:
dev/geode/smi.fth
Log:
Geode SMI handler - first working version.
Modified: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth 2008-01-31 02:37:24 UTC (rev 797)
+++ dev/geode/smi.fth 2008-01-31 05:16:56 UTC (rev 798)
@@ -19,7 +19,9 @@
dup constant smm-save-gdt 8 +
dup constant smm-gdtp 8 +
dup constant smm-gdt /smm-gdt +
-dup constant smm-pdir 4 +
+dup constant smm-pdir la1+
+dup constant smm-forth-origin la1+
+dup constant smm-forth-up la1+
dup constant smm-code16 h# a +
dup constant smm-data16 h# a +
@@ -31,7 +33,8 @@
dup constant smm-gs h# a +
dup constant smm-ss h# a +
dup constant smm-cs h# a +
-dup constant smm-esp 4 +
+dup constant smm-esp la1+
+dup constant smm-sp wa1+
drop
: set-descr ( base limit d.type sel offset -- )
@@ -48,10 +51,19 @@
smm-base smm-size 1- data16 h# 18 smm-data16 set-descr
0 -1 code32 h# 20 smm-code32 set-descr
0 -1 data32 h# 28 smm-data32 set-descr
- /smm-gdt 1- smm-gdtp +smm 4 + w! \ GDT limit
- smm-gdt +smm smm-gdtp +smm l! \ GDT base
+ /smm-gdt 1- smm-gdtp +smm w! \ GDT limit
+ smm-gdt +smm smm-gdtp +smm wa1+ l! \ GDT base
;
+nuser smi-sp0
+nuser smi-rp0
+defer smi-return
+: smi-exec ( -- )
+ ." Forth SMI handler" cr
+ quit
+ smi-return
+;
+
label smm-handler
16-bit
@@ -74,6 +86,7 @@
op: ax push
cr3 ax mov op: ax push
+ sp smm-sp #) mov
\ ---
\ Get into protected mode using the same segments
@@ -105,21 +118,42 @@
ax cr3 mov \ Set Page Directory Base Register
cr0 ax mov h# 8000.0000 # ax or ax cr0 mov \ Turn on Paging Enable bit
+\ Beginning of Forth-specific stuff
+ smm-forth-origin +smm #) bx mov
+ smm-forth-up +smm #) up mov
-\ op: here 7 + smm-handler - smm-base + h# 20 #) far jmp
-\ op: here 7 + smm-handler - 8 #) far jmp
+ \ Exchange the stack and return stack pointer with the smi versions
+ 'user sp0 sp mov
+ 'user rp0 rp mov
-\ Put Forth stuff here
+ 'user smi-sp0 sp xchg
+ 'user smi-rp0 rp xchg
-\ smm-code16 +smm #) cs rsdc
-\ smm-code16 +smm #) cs rsdc \ 64K boosted
+ sp 'user sp0 mov
+ rp 'user rp0 mov
- nop nop nop nop nop nop nop nop nop nop
+ \ Set the interpreter pointer
+ 'body smi-exec origin - # ip mov
+ bx ip add \ add current origin
+ cld
+c;
+code (smi-return)
+ \ Exchange the stack and return stack pointer with the smi versions
+ 'user sp0 sp mov
+ 'user rp0 rp mov
+
+ 'user smi-sp0 sp xchg
+ 'user smi-rp0 rp xchg
+
+ sp 'user sp0 mov
+ rp 'user rp0 mov
+
+\ End of Forth-specific stuff
+
\ Turn off paging
cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
-
cr0 ax mov 1 invert # al and ax cr0 mov \ Enter real mode
here 2 + #) jmp
@@ -136,10 +170,10 @@
\ >Test
-
op: smm-save-gdt #) lgdt
\ ---
+ smm-sp #) sp mov
op: ax pop ax cr3 mov
op: ax pop
@@ -183,9 +217,21 @@
smm-base dup smm-size -1 mmu-map
smm-handler smm-base /smm-handler move
+
+ ['] (smi-return) smm-handler - +smm ( cfa-adr )
+ dup ta1+ swap token!
+
set-smm-descs
cr3@ smm-pdir +smm l!
+ origin smm-forth-origin +smm l!
+ up@ smm-forth-up +smm l!
+ h# 1000 +smm smi-sp0 !
+ h# 2000 +smm smi-rp0 !
;
+: do-smi-return ( -- )
+ ['] (smi-return) smm-handler - +smm execute
+;
+' do-smi-return is smi-return
: enable-virtual-pci ( -- )
h# 5000.2012 msr@ swap h# 8002 or swap h# 5000.2002 msr! \ Virtualize devices f and 1
@@ -197,27 +243,9 @@
\ Forth stuff
[ifdef] notyet
- op: smm-forth-origin #) bx mov
- op: smm-forth-up #) up mov
[then]
[ifdef] notyet
- \ Exchange the stack and return stack pointer with the smi versions
- 'user sp0 sp mov
- 'user rp0 rp mov
-
- 'user smi-sp0 sp xchg
- 'user smi-rp0 rp xchg
-
- sp 'user sp0 mov
- rp 'user rp0 mov
-
- \ Set the interpreter pointer
- 'body smi-exec origin - # ip mov
- bx ip add \ add current origin
-
- cld
-c;
XXX code to return from Forth
[then]
1
0
Author: wmb
Date: 2008-01-31 03:37:24 +0100 (Thu, 31 Jan 2008)
New Revision: 797
Added:
dev/geode/smi.fth
Log:
Geode SMI handler - first checkpoint.
Added: dev/geode/smi.fth
===================================================================
--- dev/geode/smi.fth (rev 0)
+++ dev/geode/smi.fth 2008-01-31 02:37:24 UTC (rev 797)
@@ -0,0 +1,239 @@
+purpose: SMI setup and handler for Geode LX
+
+also assembler definitions
+
+: smint ( -- ) prefix-0f h# 38 asm8, ;
+: rsm ( -- ) prefix-0f h# aa asm8, ;
+: svdc ( sr m80 -- ) prefix-0f h# 78 asm8, rot r/m, ;
+: rsdc ( m80 sr -- ) prefix-0f h# 79 asm8, r/m, ;
+
+previous definitions
+
+h# 4000.0000 constant smm-base
+h# 1.0000 constant smm-size
+: +smm ( offset -- adr ) smm-base + ;
+
+h# 30 constant /smm-gdt
+smm-size h# 100 -
+dup constant smm-stack
+dup constant smm-save-gdt 8 +
+dup constant smm-gdtp 8 +
+dup constant smm-gdt /smm-gdt +
+dup constant smm-pdir 4 +
+
+dup constant smm-code16 h# a +
+dup constant smm-data16 h# a +
+dup constant smm-code32 h# a +
+dup constant smm-data32 h# a +
+dup constant smm-ds h# a +
+dup constant smm-es h# a +
+dup constant smm-fs h# a +
+dup constant smm-gs h# a +
+dup constant smm-ss h# a +
+dup constant smm-cs h# a +
+dup constant smm-esp 4 +
+drop
+
+: set-descr ( base limit d.type sel offset -- )
+ +smm 2>r format-descriptor ( d.descr r: sel adr )
+ 2r@ 8 + w! ( d.descr r: sel adr )
+ 2dup r> d! ( d.descr r: sel )
+ r> smm-gdt + +smm d! ( )
+;
+
+: set-smm-descs ( -- )
+ smm-base -1 code32 format-descriptor smm-gdt 8 + +smm d! \ Boosted code32
+
+ smm-base smm-size 1- code16 h# 10 smm-code16 set-descr
+ smm-base smm-size 1- data16 h# 18 smm-data16 set-descr
+ 0 -1 code32 h# 20 smm-code32 set-descr
+ 0 -1 data32 h# 28 smm-data32 set-descr
+ /smm-gdt 1- smm-gdtp +smm 4 + w! \ GDT limit
+ smm-gdt +smm smm-gdtp +smm l! \ GDT base
+;
+
+label smm-handler
+ 16-bit
+
+ cs: ds smm-ds #) svdc
+ cs: smm-data16 #) ds rsdc \ Now we have a data segment
+
+ es smm-es #) svdc
+ fs smm-fs #) svdc
+ gs smm-gs #) svdc
+ ss smm-ss #) svdc
+ smm-data16 #) ss rsdc \ Now we have a data segment
+
+ op: sp smm-esp #) mov
+ smm-stack # sp mov \ Now we have a stack
+
+ op: pusha
+
+ h# cf8 # dx mov \ Save/restore PCI config address
+ op: dx ax in
+ op: ax push
+
+ cr3 ax mov op: ax push
+
+\ ---
+\ Get into protected mode using the same segments
+\ Don't bother with the IDT; we won't enable interrupts
+ op: smm-save-gdt #) sgdt
+ op: smm-gdtp #) lgdt
+
+\ Test<
+ \ Get into the 4G flat code-32 address space
+ cs smm-cs #) svdc \ So we can get back
+ smm-code32 #) cs rsdc \ 4G flat address space for code
+ 32-bit
+ here 5 + +smm #) jmp \ Into unboosted segment
+
+nop nop nop nop nop nop nop
+
+ cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
+ here 2 + #) jmp
+
+ \ Reload segment registers with protected mode bits
+ cs: smm-data32 +smm #) ds rsdc
+ smm-data32 +smm #) ss rsdc
+ smm-data32 +smm #) es rsdc
+ smm-data32 +smm #) fs rsdc
+ smm-data32 +smm #) gs rsdc
+
+ \ Turn on paging
+ smm-pdir +smm #) ax mov
+ ax cr3 mov \ Set Page Directory Base Register
+ cr0 ax mov h# 8000.0000 # ax or ax cr0 mov \ Turn on Paging Enable bit
+
+
+\ op: here 7 + smm-handler - smm-base + h# 20 #) far jmp
+\ op: here 7 + smm-handler - 8 #) far jmp
+
+\ Put Forth stuff here
+
+\ smm-code16 +smm #) cs rsdc
+\ smm-code16 +smm #) cs rsdc \ 64K boosted
+
+ nop nop nop nop nop nop nop nop nop nop
+
+ \ Turn off paging
+ cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
+
+
+ cr0 ax mov 1 invert # al and ax cr0 mov \ Enter real mode
+ here 2 + #) jmp
+
+
+ \ Reload segment registers with real mode bits
+ cs: smm-data16 +smm #) ss rsdc
+ cs: smm-data16 +smm #) ds rsdc
+
+
+ \ Return to the boosted code-16 address space
+ smm-cs #) cs rsdc
+ 16-bit
+ here 2 + #) jmp \ 16-bit JMP zeros EIP[31:16]
+
+\ >Test
+
+
+ op: smm-save-gdt #) lgdt
+
+\ ---
+ op: ax pop ax cr3 mov
+
+ op: ax pop
+ h# cf8 # dx mov \ Save/restore PCI config address
+ op: ax dx out
+
+ op: popa
+
+ op: smm-esp #) sp mov
+
+ smm-ss #) ss rsdc
+ smm-gs #) gs rsdc
+ smm-fs #) fs rsdc
+ smm-es #) es rsdc
+ smm-ds #) ds rsdc
+
+ rsm
+end-code
+here smm-handler - constant /smm-handler
+
+: setup-smi ( -- )
+ \ Map the SMM region to physical memory at e.0000
+ \ This is a Base Mask Offset descriptor - the base address
+ \ is 4000.0000 and to that is added the offset c00e.0000
+ \ to give the address 000e.0000 in the GLMC address space.
+ \ The mask is ffff.0000 , i.e. 64K
+ h# 2.c00e0.40000.ffff0. h# 1000.0026 msr!
+
+ \ Put 64K SMM memory at 4000.0000 in the processor linear address space
+ \ Cacheable in SMM mode, non-cacheable otherwise
+ h# 4000f.0.00.40000.1.01. h# 180e msr!
+
+ \ Base Limit
+\ smm-base smm-size 1- h# 133b msr!
+ smm-base -1 h# 133b msr! \ Big limit
+
+ smm-base smm-size + 0 h# 132b msr! \ Offset of SMM Header
+
+ h# 18. h# 1301 msr! \ Enable IO and software SMI
+
+ smm-base dup smm-size -1 mmu-map
+
+ smm-handler smm-base /smm-handler move
+ set-smm-descs
+ cr3@ smm-pdir +smm l!
+;
+
+: enable-virtual-pci ( -- )
+ h# 5000.2012 msr@ swap h# 8002 or swap h# 5000.2002 msr! \ Virtualize devices f and 1
+ h# 5000.2002 msr@ swap 8 invert and swap h# 5000.2002 msr! \ Enable SSMI for config accesses
+;
+
+
+code smi smint ax push c;
+
+\ Forth stuff
+[ifdef] notyet
+ op: smm-forth-origin #) bx mov
+ op: smm-forth-up #) up mov
+[then]
+
+[ifdef] notyet
+ \ Exchange the stack and return stack pointer with the smi versions
+ 'user sp0 sp mov
+ 'user rp0 rp mov
+
+ 'user smi-sp0 sp xchg
+ 'user smi-rp0 rp xchg
+
+ sp 'user sp0 mov
+ rp 'user rp0 mov
+
+ \ Set the interpreter pointer
+ 'body smi-exec origin - # ip mov
+ bx ip add \ add current origin
+
+ cld
+c;
+XXX code to return from Forth
+[then]
+
+[ifdef] notyet
+ \ We are running in a segment that is identity mapped
+ cr0 ax mov h# 8000.0000 invert # ax and ax cr0 mov \ Turn off Paging Enable bit
+[then]
+
+label emita
+ op: dx dx xor dx dx xor
+ h# 3fd # dx mov
+ begin dx al in h# 20 # al and 0<> until
+ h# 41 # al mov h# f8 # dl mov al dx out
+ begin again
+\ h# 3fd # dx mov
+\ begin dx al in h# 20 # al and 0<> until
+end-code
+here emita - constant /emita
+: puta ( adr -- ) emita swap /emita move ;
1
0
Author: wmb
Date: 2008-01-30 22:01:55 +0100 (Wed, 30 Jan 2008)
New Revision: 796
Modified:
cpu/x86/pc/olpc/versions.fth
Log:
OLPC build - use new version of wireless firmware and newly-audited bios-crypto code.
Modified: cpu/x86/pc/olpc/versions.fth
===================================================================
--- cpu/x86/pc/olpc/versions.fth 2008-01-28 11:41:18 UTC (rev 795)
+++ cpu/x86/pc/olpc/versions.fth 2008-01-30 21:01:55 UTC (rev 796)
@@ -16,7 +16,7 @@
\ The wireless LAN module firmware
macro: WLAN_RPM ${WLAN_VERSION}-1.olpc1
-macro: WLAN_VERSION 5.110.20.p49
+macro: WLAN_VERSION 5.110.22.p1
\ The bios_verify image
-macro: CRYPTO_VERSION 0.2
+macro: CRYPTO_VERSION 0.3
1
0
Hi,
I've been exploring OpenFirmware on x86, under qemu with coreboot.
I've been trying to run the hello.elf example. I have trouble
loading it from an ext2 file system, I get an message:
ok report-disk
ok boot /pci/pci-ide@1,1/ide@0/disk@0:\hello.elf
Boot device: /pci/pci-ide@1,1/ide@0/disk@0:\hello.elf Arguments: root=/dev/ram0 mount_ramdisk=1
Unimplemented package interface procedure
Undefined word encountered
ok
I also tried using using qemu's -option-rom function
to throw a raw binary into the address space that i
could then place in memory with 'cmove' and then
tried to 'branch' or 'execute' it.
This method probably isn't worth pursuing much,
even thought it did get me the furthest.
The problem there was that the pointer to the
openfirmware interface function wasn't getting
passed in %eax, but then again, I wasn't using 'boot'.
Anyway, tips on this would be appreciated.
Jonathan Kollasch
4
3
Hi,
So, apparently 'virtual-mode' doesn't work when OFW is loaded
from coreboot. Does anyone know if that's easy to fix?
Jonathan Kollasch
1
0
r795 - cpu/x86/pc/biosload dev/ide dev/video/common dev/video/controlr
by svn@openbios.org Jan. 28, 2008
by svn@openbios.org Jan. 28, 2008
Jan. 28, 2008
Author: wmb
Date: 2008-01-28 12:41:18 +0100 (Mon, 28 Jan 2008)
New Revision: 795
Modified:
cpu/x86/pc/biosload/rmenter.fth
dev/ide/generic.fth
dev/video/common/textmode.fth
dev/video/controlr/vga.fth
Log:
BIOSload version - another checkpoint of BIOS gateway code.
Modified: cpu/x86/pc/biosload/rmenter.fth
===================================================================
--- cpu/x86/pc/biosload/rmenter.fth 2008-01-28 04:19:49 UTC (rev 794)
+++ cpu/x86/pc/biosload/rmenter.fth 2008-01-28 11:41:18 UTC (rev 795)
@@ -4,14 +4,36 @@
: seg:off> ( offset segment -- linear ) 4 lshift + ;
: seg:off@ ( adr -- linear ) dup w@ swap wa1+ w@ seg:off> ;
[then]
+: >off ( linear -- 16-bit offset ) >seg:off drop ;
+h# 9.0000 constant rm-base
+h# 9.0000 constant rm-avail
+h# ff00 constant rm-base2
+h# 9.fc00 constant 'ebda \ Extended BIOS Data Area, which we co-opt for our real-mode workspace
+'ebda constant new-gdt-pa
+
[ifdef] syslinux-loaded
h# 8 constant rm-cs
h# 18 constant rm-ds
h# 20 constant pm-cs
h# 28 constant pm-ds
-: fix-gdt ;
+: fix-gdt
+ \ 16-bit 64K code segment starting at rm-base
+ rm-base lbsplit ( adr.0 adr.1 adr.2 adr.3 )
+ 2swap h# ffff -rot bwjoin wljoin ( adr.2 adr.3 desc.lo )
+ -rot ( desc.lo adr.2 adr.3 )
+ >r h# 9a 0 r> bljoin ( desc.lo desc.hi )
+ gdtr@ drop rm-cs + d! ( )
+
+ \ 16-bit 64K data segment starting at rm-base
+ rm-base lbsplit ( adr.0 adr.1 adr.2 adr.3 )
+ 2swap h# ffff -rot bwjoin wljoin ( adr.2 adr.3 desc.lo )
+ -rot ( desc.lo adr.2 adr.3 )
+ >r h# 93 0 r> bljoin ( desc.lo desc.hi )
+ gdtr@ drop rm-ds + d! ( )
+;
[then]
+
[ifdef] preof-loaded
h# 38 constant rm-cs
h# 30 constant rm-ds
@@ -26,31 +48,28 @@
[then]
-h# 0.0000 constant rm-base
-: +rm ( offset -- adr ) rm-base + ;
+: +rm ( offset -- adr ) rm-base + rm-base2 + ;
-\ The real-mode stack pointer will start here
-h# f00 +rm constant 'rm-stack
-\ h# ef0 +rm constant 'rm-dispatch
-
\ Place for the initial registers upon entry to real mode.
-h# f00 +rm constant 'rm-regs
+\ The real-mode stack pointer will start here, so the registers
+\ can be loaded by popping the stack
+h# 00 +rm constant 'rm-regs
\ (00) 4 * 2: GS,FS,ES,DS
\ (08) 8 * 4: EDI,ESI,EBP,ESP,EBX,EDX,ECX,EAX
\ (28) 1 * 4: CS:IP of return address
\ (2c) 1 * 2: flags
\ size is 2e
-h# f30 +rm constant 'rm-idt \ For loading RM IDT with LIDT
-h# f36 +rm constant 'rm-int \ Incoming interrupt number
-h# f38 +rm constant 'rm-sp \ SS:SP For loading RM SP with LSS
-h# f3c +rm constant 'pm-sp \ Save/restore area for PM SP
-h# f40 +rm constant 'pm-gdt \ For loading PM GDT with LGDT
-h# f48 +rm constant 'pm-idt \ For loading PM IDT with LGDT
+h# 30 +rm constant 'rm-idt \ For loading RM IDT with LIDT
+h# 36 +rm constant 'rm-int \ Incoming interrupt number
+h# 38 +rm constant 'rm-sp \ SS:SP For loading RM SP with LSS
+h# 3c +rm constant 'pm-sp \ Save/restore area for PM SP
+h# 40 +rm constant 'pm-gdt \ For loading PM GDT with LGDT
+h# 48 +rm constant 'pm-idt \ For loading PM IDT with LGDT
-h# f50 +rm constant 'rm-to-pm
-h# fa0 +rm constant 'pm-to-rm
-h# ff0 +rm constant 'rm-enter
+h# 50 +rm constant 'rm-to-pm
+h# a0 +rm constant 'pm-to-rm
+h# f0 +rm constant 'rm-enter
: caller-regs 'rm-sp seg:off@ ;
struct
@@ -104,6 +123,8 @@
: rm-set-cf rm-flags@ 1 or rm-flags! ;
: rm-clr-cf rm-flags@ 1 invert and rm-flags! ;
+: rm-int@ 'rm-int w@ h# ff and ;
+
true value show-rm-int?
: noshow false to show-rm-int? ;
variable save-eax
@@ -111,7 +132,7 @@
true to show-rm-int? caller-regs >rm-eax @ save-eax !
;
: showint
- ." INT " 'rm-int w@ . save-eax @ wbsplit ." AH " . ." AL " . cr
+ ." INT " rm-int@ . save-eax @ wbsplit ." AH " . ." AL " . cr
;
: ?showint show-rm-int? if showint then ;
@@ -121,19 +142,21 @@
/vectors buffer: saved-ofw-vectors
-\ 80ff0 is the target address of the interrupt vector
+\ 90ff0 is the target address of the interrupt vector
\ We use different segment:offset representations of that address in
\ the vector table, so the handler code can determine the vector
\ number by inspecting the code segment register value
-\ 00: 8000:0ff0
-\ 01: 8001:0fe0
+\ 00: nn00:mff0
+\ 01: nn01:mfe0
\ ...
-\ ff: 80ff:0000
+\ ff: nnff:m000
: grab-rm-vector ( vector# -- )
>r
- h# ff0 r@ 4 lshift - r@ /l* w! \ Set offset
- rm-base 4 rshift r@ + r> /l* wa1+ w! \ Set segment
+ 'rm-enter lwsplit ( low16 high16 )
+ swap r@ 4 lshift - swap ( vec.offset high16 )
+ d# 12 lshift r@ + wljoin ( vec.seg:off )
+ r> /l* l! \ Set segment
;
: ungrab-rm-vector ( vector# -- )
saved-rm-vectors over la+ l@ ( vector# value )
@@ -163,20 +186,27 @@
\ (low) GS,FS,ES,DS (high)
\ CS from interrupt vector, which is the interrupt number
- cs: 'rm-int #) pop \ Save interrupt vector CS, i.e. the int#
-
cli \ This is unnecessary since we got here from an INT
cs push ds pop
- sp 'rm-sp #) mov
- ss 'rm-sp 2+ #) mov
+ 'rm-int >off #) pop \ Save interrupt vector CS, i.e. the int#
- op: 'pm-gdt #) lgdt
+ sp 'rm-sp >off #) mov
+ ss 'rm-sp 2+ >off #) mov
+
+ op: 'pm-gdt >off #) lgdt
cr0 ax mov 1 # al or ax cr0 mov \ Enter protected mode
- here 5 + rm-to-pm - 'rm-to-pm + pm-cs #) far jmp
+ \ The assembler gyrations here are subtle. We need to jump to an address
+ \ that may be larger than 16 bits, but we are currently running from a
+ \ 16-bit code segment. So we have to tell the assembler to go into
+ \ "protected mode" (a misnomer; that assembler directive really means
+ \ to assemble for the 32-bit instruction set) so it will put down a
+ \ ptr16:32 operand. But we also need the op: prefix, so the processor
+ \ will interpret the operand as a ptr16:32 instead of a ptr16:16
protected-mode
+ op: here 7 + rm-to-pm - 'rm-to-pm + pm-cs #) far jmp
ax ax xor pm-ds # al mov ax ds mov ax es mov ax gs mov ax gs mov ax ss mov
'rm-idt #) sidt
@@ -227,7 +257,7 @@
cli
sp sp xor
- 'pm-to-rm rm-cs #) far jmp
+ 'pm-to-rm >off rm-cs #) far jmp
end-code
\ This is the common target of all the real-mode interrupt vectors.
@@ -251,8 +281,7 @@
: move-gdt ( -- )
gdtr@ 1+ ( gdt-adr gdt-len )
-\ dup h# 10 + alloc-mem h# f + h# f invert and ( gdt-adr gdt-len new-gdt )
- h# 900
+ new-gdt-pa ( gdt-adr gdt-len new-gdt-adr )
swap 2dup 2>r move 2r> ( new-gdt gdt-len )
1- gdtr!
@@ -270,7 +299,7 @@
: regs>bios ( -- )
caller-regs bios-regs d# 40 move
rm-flags@ bios-flags l!
- 'rm-int w@ /l* @ bios-target !
+ rm-int@ /l* @ bios-target !
;
: bios>regs ( -- )
bios-regs caller-regs d# 40 move
@@ -304,7 +333,7 @@
h# 11 grab-rm-vector \ Sysinfo
h# 12 grab-rm-vector \ Low memory size
h# 13 grab-rm-vector \ Disk I/O
-\ h# 15 grab-rm-vector \ Various system stuff
+ h# 15 grab-rm-vector \ Various system stuff
h# 16 grab-rm-vector \ Keyboard
h# 1a grab-rm-vector \ PCI BIOS
[else]
@@ -327,7 +356,7 @@
prep-rm
'rm-regs h# 2e erase ( pc )
'rm-regs h# 28 + seg:off! ( )
- 'rm-stack 'rm-sp seg:off! \ Initial stack pointer below regs
+ 'rm-regs 'rm-sp seg:off! \ Initial stack pointer must be below regs
;
: !font ( adr -- )
@@ -335,8 +364,9 @@
h# 10 rm-cx! h# 18 rm-dx!
;
: get-font ( -- )
+ noshow
rm-al@ h# 30 = if
- ." Int 10 get-font called - BH = " rm-bh@ . cr
+\ ." Int 10 get-font called - BH = " rm-bh@ . cr
rm-bh@ case
\ These numbers are cheats, pointing into the VIA BIOS
2 of h# c69e0 !font endof
@@ -346,6 +376,7 @@
6 of h# c77e0 !font endof
7 of h# c77e0 !font
h# 10 ungrab-rm-vector
+h# 15 ungrab-rm-vector
endof
( default ) ." Unsupported get font - BH = " dup . cr rm-set-cf
endcase
@@ -574,12 +605,12 @@
[then]
create memdescs
- h# 0. d, h# a0000. d, 1 l, \ 0
-\ h# a0000. d, h# 60000. d, 2 l, \ 14
- h# f0000. d, h# 10000. d, 2 l, \ 14
- h# 100000. d, 0. d, 1 l, \ 28
-\ 0. d, 0. d, 2 l, \ 3c
- h# ffff0000. d, h# 10000. d, 2 l, \ 40
+ h# 0. d, rm-avail 0 d, 1 l, \ 0
+\ h# rm-avail 0 d, h# 60000. d, 2 l, \ 14
+ h# f0000. d, h# 10000. d, 2 l, \ 14
+ h# 100000. d, 0. d, 1 l, \ 28
+\ 0. d, 0. d, 2 l, \ 3c
+ h# ffff0000. d, h# 10000. d, 2 l, \ 40
here memdescs - constant /memdescs
: system-memory-map ( -- )
@@ -648,12 +679,15 @@
rm-clr-cf
rm-ah@ case
h# 91 of noshow 0 rm-ah! endof \ "pause" while waiting for I/O
+noop
h# 53 of apm endof
h# 86 of rm-dx@ rm-cx@ wljoin us endof \ Delay microseconds
h# 8a of memory-limit h# 400.0000 - 0 max /1k lwsplit rm-dx! rm-ax! endof
h# 88 of h# fffc rm-ax! endof \ Extended memory - at least 64 MB
h# c0 of get-conf endof
- h# c1 of rm-set-cf h# 86 rm-ah! endof
+ \ We use the extended BIOS data area as our workspace when loaded from another BIOS
+\ h# c1 of rm-set-cf h# 86 rm-ah! endof \ No extended BIOS data area
+ h# c1 of 'ebda 4 rshift caller-regs >rm-es w! endof \ Segment address of extended BIOS data area
h# c2 of handle-mouse endof
h# e8 of bigmem-int endof
( default ) rm-set-cf
@@ -661,10 +695,11 @@
endcase
;
-h# 4800 value the-key
+0 value the-key
: poll-key ( -- false | scan,ascii true )
the-key ?dup if true exit then
+ d# 50 ms \ I don't know why this is necessary, but without it, you don't see the key
0 " get-scancode" kbd-ih $call-method if ( scancode )
dup h# 80 and if ( scancode )
\ Discard release events and escapes (e0)
@@ -708,6 +743,7 @@
0 of get-keystroke endof
1 of poll-keystroke endof
2 of 0 rm-al! endof \ Claim that no shift keys are active
+ 5 of rm-cx@ to the-key endof \ Put keystroke in buffer
( bit 7:sysrq 6:capslock 5:numlock 4:scrlock 3:ralt 2:rctrl 1:lalt 0:lctrl )
( default ) ." Keyboard INT called with AH = " dup . cr
endcase
@@ -751,6 +787,7 @@
: int-1a ( -- )
rm-ah@ case
h# 0 of get-timer-ticks noshow endof
+\ h# 4 of rm-clr-cf get-rtc-date endof \ ch century cl year dh month dl day
h# b1 of pcibios endof
( default ) ." Unimplemented INT 1a - AH = " dup . cr rm-set-cf
endcase
@@ -758,19 +795,27 @@
: handle-bios-call ( -- )
snap-int
- 'rm-int w@ case
+ rm-int@ case
h# 10 of video-int endof
h# 11 of sysinfo-int endof
h# 13 of noshow disk-int endof
h# 16 of keyboard-int endof
h# 15 of system-int endof
- h# 12 of h# a0000 /1k rm-ax! endof \ Low memory size
+ h# 12 of rm-avail /1k rm-ax! endof \ Low memory size
h# 1a of int-1a endof
+ h# 18 of ." Entering Open Firmware" cr interact endof
+ h# 19 of ." Rebooting" cr bye endof
( default ) ." Interrupt " dup . cr interact
endcase
?showint
;
+: get-mbr
+ " /pci/ide@0" open-dev >r
+ h# 7c00 h# 3f 1 " read-blocks" r@ $call-method 1 <> abort" Didn't read MBR"
+ r> close-dev
+;
: rm-go ( -- )
+ get-mbr
usb-quiet
\ Load boot image at 7c00
h# 7c00 rm-init-program
@@ -782,11 +827,6 @@
label xx h# 99 # al mov al h# 80 # out begin again end-code
here xx - constant /xx
: put-xx ( adr -- ) xx swap /xx move ;
-: get-mbr
- " /pci/ide@0" open-dev >r
- h# 7c00 h# 3f 1 " read-blocks" r@ $call-method .
- r> close-dev
-;
: .lreg ( adr -- adr' ) 4 - dup l@ 9 u.r ;
: .wreg ( adr -- adr' ) 2 - dup w@ 5 u.r ;
: .caller-regs ( -- )
Modified: dev/ide/generic.fth
===================================================================
--- dev/ide/generic.fth 2008-01-28 04:19:49 UTC (rev 794)
+++ dev/ide/generic.fth 2008-01-28 11:41:18 UTC (rev 795)
@@ -202,10 +202,17 @@
over 0= if 2drop 2drop 0 exit then
- >r dup >r r-#secs! ( addr block# ) ( R: input? #blks )
- lblk>cyl-head-sect ( addr cyl# head# sect# )
- r-sector! drive r-head! r-cyl! r> r> ( addr #blks input? )
- if rblocks else wblocks then ( actual# | error )
+ >r dup >r r-#secs! ( addr block# ) ( R: input? #blks )
+ /lba if ( addr block# ) ( R: input? #blks )
+ lbsplit ( addr 0-7 8-15 16-23 24-32 )
+ \ 4, when shifted with drive, sets the LBA bit
+ h# f and drive 4 or r-head! ( addr 0-7 8-15 16-23 )
+ bwjoin r-cyl! r-sector! ( addr R: input? #blks )
+ else ( addr block# ) ( R: input? #blks )
+ lblk>cyl-head-sect ( addr cyl# head# sect# )
+ r-sector! drive r-head! r-cyl! ( addr #blks input? R: input? #blks )
+ then
+ r> r> if rblocks else wblocks then ( actual# | error )
dup 0= if
." Failed to transfer any blocks" cr
@@ -244,7 +251,8 @@
scratchbuf 3 wa+ le-w@ /heads!
scratchbuf 6 wa+ le-w@ /secs!
- /cyls h# 3fff u>= if
+\ /cyls h# 3fff u>= if
+ scratchbuf d# 49 wa+ w@ h# 200 and if \ LBA
scratchbuf d# 60 wa+ le-w@
scratchbuf d# 61 wa+ le-w@
wljoin /lba!
Modified: dev/video/common/textmode.fth
===================================================================
--- dev/video/common/textmode.fth 2008-01-28 04:19:49 UTC (rev 794)
+++ dev/video/common/textmode.fth 2008-01-28 11:41:18 UTC (rev 795)
@@ -16,7 +16,7 @@
: next-string ( table-adr -- table-adr' adr len ) count 2dup + -rot ;
-: set-mode ( table -- )
+: set-vga-mode ( table -- )
palette-off
dup c@ misc! 1+
@@ -129,11 +129,12 @@
: fill-attrs ( len value -- )
ega rot 2* bounds do dup i 1+ c! 2 +loop drop
;
-: pc-font ( -- )
- write-font
- default-font ( 2>r ) >r >r ( adr width +-height advance r: min,#glyphs )
+defer pc-font ' default-font to pc-font
+: load-vga-font ( -- )
+ pc-font ( 2>r ) >r >r ( adr width +-height advance r: min,#glyphs )
1 <> rot 8 > or over 0>= or
if true " Incompatible font" type abort then ( adr -height )
+ write-font
negate swap ( 2r> ) r> r> bounds ?do ( height adr )
2dup ega i h# 20 * + rot move ( height adr )
over + ( height adr' )
@@ -141,6 +142,7 @@
2drop ( )
write-text
;
+
create ega-colors
" "(00 00 00 00 00 aa 00 aa 00 00 aa aa)" $,
" "(aa 00 00 aa 00 aa aa aa 00 aa aa aa)" $,
@@ -166,16 +168,17 @@
: text-mode3 ( -- )
io-base -1 = if map-io-regs then
- mode2+/3 set-mode
+ mode2+/3 set-vga-mode
ext-textmode
\ h# c00b.8000 0 h# 8200.0000 h# 8000 " map-in" $call-parent to ega
h# 000b.8000 0 h# 8200.0000 h# 8000 " map-in" $call-parent to ega
- pc-font
+ load-vga-font
#text-rows #text-columns * dup bl fill-text 7 fill-attrs
[ifdef] strict-ega
ega-colors 0 d# 64 (set-colors)
[then]
;
+
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
Modified: dev/video/controlr/vga.fth
===================================================================
--- dev/video/controlr/vga.fth 2008-01-28 04:19:49 UTC (rev 794)
+++ dev/video/controlr/vga.fth 2008-01-28 11:41:18 UTC (rev 795)
@@ -1,11 +1,13 @@
\ See license at end of file
purpose: Generic VGA functions
+hex
+
\ reset attribute address flip-flop
: reset-attr-addr ( -- ) 3da ( input-status1 ) pc@ drop ;
: video-mode! ( b -- ) reset-attr-addr 03c0 pc! ;
-: attr! ( b index -- ) 03c0 pc! 03c0 pc! ;
+: attr! ( b index -- ) reset-attr-addr 03c0 pc! 03c0 pc! ;
: attr@ ( index -- b )
reset-attr-addr 03c0 pc! 03c1 pc@ reset-attr-addr
;
@@ -58,12 +60,15 @@
['] vga-plt! to plt!
['] vga-rindex! to rindex!
['] vga-windex! to windex!
+[ifdef] rs@
['] noop to rs@
['] 2drop to rs!
+[then]
+[ifdef] idac@
['] noop to idac@
['] 2drop to idac!
+[then]
;
-use-vga-dac
: palette-off ( -- ) 0 video-mode! ;
: palette-on ( -- ) 20 video-mode! ;
@@ -130,7 +135,13 @@
;
: hsync-on ( -- ) crt-table drop 4 + c@ 4 crt! ; \ Set hsync position
-: vga-video-on ( -- ) palette-on hsync-on ; ' vga-video-on to video-on
+: vga-video-on ( -- ) palette-on hsync-on ;
+
+: use-vga
+ use-vga-dac
+ ['] vga-video-on to video-on
+;
+
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
1
0