M pc/dat.h => pc/dat.h +36 -34
@@ 1,4 1,5 @@
typedef struct Conf Conf;
+typedef struct FPsave FPsave;
typedef struct Label Label;
typedef struct Lock Lock;
typedef struct MMU MMU;
@@ 29,11 30,16 @@ struct Label
ulong pc;
};
+struct FPsave
+{
+ int type;
+};
+
struct Conf
{
- int nmach; /* processors */
- int nproc; /* processes */
- int npgrp; /* process groups */
+ ulong nmach; /* processors */
+ ulong nproc; /* processes */
+ ulong npgrp; /* process groups */
ulong npage0; /* total physical pages of memory, bank 0 */
ulong npage1; /* total physical pages of memory, bank 1 */
ulong base0; /* base of bank 0 */
@@ 42,38 48,34 @@ struct Conf
ulong norig; /* origins */
ulong npte; /* contiguous page table entries */
ulong nmod; /* single (modifying) page table entries */
- int nalarm; /* alarms */
- int nchan; /* channels */
- int nenv; /* distinct environment values */
- int nenvchar; /* environment text storage */
- int npgenv; /* environment files per process group */
- int nmtab; /* mounted-upon channels per process group */
- int nmount; /* mounts */
- int nmntdev; /* mounted devices (devmnt.c) */
- int nmntbuf; /* buffers for devmnt.c messages */
- int nmnthdr; /* headers for devmnt.c messages */
- int nstream; /* streams */
- int nqueue; /* stream queues */
- int nblock; /* stream blocks */
- int nsrv; /* public servers (devsrv.c) */
- int nbitmap; /* bitmap structs (devbit.c) */
- int nbitbyte; /* bytes of bitmap data (devbit.c) */
- int nfont; /* font structs (devbit.c) */
- int nurp; /* max urp conversations */
- int nasync; /* number of async protocol modules */
- int npipe; /* number of pipes */
- int nservice; /* number of services */
- int nfsyschan; /* number of filsys open channels */
+ ulong nalarm; /* alarms */
+ ulong nchan; /* channels */
+ ulong nenv; /* distinct environment values */
+ ulong nenvchar; /* environment text storage */
+ ulong npgenv; /* environment files per process group */
+ ulong nmtab; /* mounted-upon channels per process group */
+ ulong nmount; /* mounts */
+ ulong nmntdev; /* mounted devices (devmnt.c) */
+ ulong nmntbuf; /* buffers for devmnt.c messages */
+ ulong nmnthdr; /* headers for devmnt.c messages */
+ ulong nstream; /* streams */
+ ulong nqueue; /* stream queues */
+ ulong nblock; /* stream blocks */
+ ulong nsrv; /* public servers (devsrv.c) */
+ ulong nbitmap; /* bitmap structs (devbit.c) */
+ ulong nbitbyte; /* bytes of bitmap data (devbit.c) */
+ ulong nfont; /* font structs (devbit.c) */
+ ulong nurp; /* max urp conversations */
+ ulong nasync; /* number of async protocol modules */
+ ulong npipe; /* number of pipes */
+ ulong nservice; /* number of services */
+ ulong nfsyschan; /* number of filsys open channels */
ulong maxialloc; /* maximum bytes used by ialloc */
- int copymode; /* 0 is copy on write, 1 is copy on reference */
- int portispaged; /* ??? */
- int nnoifc;
- int nnoconv;
- ulong ipif; /* Ip protocol interfaces */
- ulong ip; /* Ip conversations per interface */
- ulong arp; /* Arp table size */
- ulong frag; /* Ip fragment assemble queue size */
- int cntrlp; /* panic on ^P */
+ ulong copymode; /* 0 is copy on write, 1 is copy on reference */
+ ulong portispaged; /* ??? */
+ ulong nnoifc;
+ ulong nnoconv;
+ ulong cntrlp; /* panic on ^P */
};
/*
M pc/fns.h => pc/fns.h +7 -2
@@ 1,2 1,7 @@
-void restregs(void);
-void saveregs(void);
+void delay(int);
+int inb(int);
+int kbdc(void);
+void outb(int, int);
+void prhex(ulong);
+void screenputc(int);
+void screenputs(char*, int);
A pc/kbd.c => pc/kbd.c +135 -0
@@ 0,0 1,135 @@
+#include "u.h"
+#include "lib.h"
+#include "dat.h"
+#include "fns.h"
+
+enum {
+ Data= 0x60, /* data port */
+
+ Status= 0x64, /* status port */
+ Inready= 0x01, /* input character ready */
+ Outbusy= 0x02, /* output busy */
+ Sysflag= 0x04, /* ??? */
+ Cmddata= 0x08, /* cmd==0, data==1 */
+ kbdinh= 0x10, /* keyboard inhibited */
+ Xtimeout= 0x20, /* transmit timeout */
+ Rtimeout= 0x40, /* receive timeout */
+ Parity= 0x80, /* 0==odd, 1==even */
+
+
+};
+
+char noshift[256] =
+{
+[0x00] Nokey, 0x1b, '1', '2', '3', '4', '5', '6',
+[0x08] '7', '8', '9', '0', '-', '=', '\b', '\t',
+[0x10]
+[0x28]
+[0x30]
+};
+
+/*
+ * get a byte from the keyboard
+ */
+int
+kbdc(void)
+{
+ while((inb(Status)&Inready)==0)
+ ;
+ return inb(Data);
+}
+
+1 0x1b,
+3b F1,
+3c F2,
+3d F3,
+3e F4,
+3f F5,
+40 f6,
+41 F7,
+42 F8,
+43 F9,
+44 F10,
+57 F11,
+58 F12,
+e0 52 INS,
+e0 53 DEL,
+2 '1',
+3 '2',
+4 '3',
+5 '4',
+6 '5',
+7 '6',
+8 '7',
+9 '8',
+A '9',
+B '0',
+C '-',
+D '=',
+E '\b',
+E0 47 Home,
+F '\t',
+10 'q',
+11 'w',
+12 'e',
+13 'r',
+14 't',
+15 'y',
+16 'u',
+17 'i',
+18 'o',
+19 'p',
+1a '[',
+1b ']',
+2b '\\',
+e0 49 Pageup,
+3a Capslock,
+1e 'a'
+1f 's'
+20 'd'
+21 'f'
+22 'g'
+23 'h'
+24 'j'
+25 'k'
+26 'l'
+27 ';'
+28 '\''
+1c '\r'
+2a Lshift,
+2c 'z'
+2d 'x'
+2e 'c'
+2f 'v'
+30 'b'
+31 'n'
+32 'm'
+33 ','
+34 '.'
+35 '/'
+36 Rshift,
+e0 51 Pagedown,
+e0 4f End,
+e0 48 Uparrow,
+e0 50 Downarrow,
+e0 4b Leftarrow,
+e0 4d Rightarrow,
+e0 1d Rctl,
+e0 38 Ralt,
+39 Space,
+38 Lalt,
+1d Lctl,
+29 '`',
+1d 38 1 81 b8 9d F1
+1d 38 21 a1 b8 9d F2
+ 2e ae F3
+ 19 99 F4
+ 26 F5
+ 2F F6
+
+e1 1d 45 e1 9d cf F7
+e0 46 e0 c6 f8
+e0 2a e0 37 e0 b7 e0 aa f9
+54 f10
+45 f11
+46 f12
M pc/l.s => pc/l.s +48 -61
@@ 1,35 1,10 @@
#include "mem.h"
/*
- * gdt to get us to 32-bit/segmented/unpaged mode
- */
-GLOBL tgdt(SB),$(6*4)
-
- /* null descriptor */
- DATA tgdt+0(SB)/4, $0
- DATA tgdt+4(SB)/4, $0
-
- /* data segment descriptor for 4 gigabytes (PL 0) */
- DATA tgdt+8(SB)/4, $(0xFFFF)
- DATA tgdt+12(SB)/4, $(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW)
-
- /* exec segment descriptor for 4 gigabytes (PL 0) */
- DATA tgdt+16(SB)/4, $(0xFFFF)
- DATA tgdt+20(SB)/4, $(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
-
-/*
- * pointer to initial gdt
- */
-GLOBL tgdtptr(SB),$6
-
- DATA tgdtptr+0(SB)/2, $(3*8)
- DATA tgdtptr+2(SB)/4, $tgdt(SB)
-
-TEXT start(SB),$0
-
-/*
* about to walk all over ms/dos - turn off interrupts
*/
+TEXT origin(SB),$0
+
CLI
/*
@@ 47,7 22,7 @@ TEXT start(SB),$0
CLD
REP
MOVSL
-/* JMPFAR* 00:$lowcore(SB) /**/
+/* JMPFAR 00:$lowcore(SB) /**/
BYTE $0xEA
WORD $lowcore(SB)
WORD $0
@@ 112,16 87,6 @@ flush:
TEXT mode32bit(SB),$0
-/*
- * print a blue 3 on a red background
- */
- MOVL $0xb8100,BX
- MOVB $0x33,AL
- MOVB AL,(BX)
- INCW BX
- MOVB $0x43,AL
- MOVB AL,(BX)
-
/*
* Clear BSS
*/
@@ 135,20 100,6 @@ TEXT mode32bit(SB),$0
REP
MOVSL
-
-/*
- * print a blue 4 on a red background
- */
- MOVL $0xb8100,BX
- MOVB $0x34,AL
- MOVB AL,(BX)
- INCW BX
- MOVB $0x43,AL
- MOVB AL,(BX)
-here:
- JMP here
-
-
/*
* stack and mach
*/
@@ 159,15 110,6 @@ here:
MOVL $0, u(SB)
CALL main(SB)
-/*
- * print a blue 4 on a red background
- */
- MOVL $0xb8100,BX
- MOVB $0x34,AL
- MOVB AL,(BX)
- INCW BX
- MOVB $0x43,AL
- MOVB AL,(BX)
loop:
JMP loop
@@ 175,3 117,48 @@ loop:
GLOBL mach0+0(SB), $MACHSIZE
GLOBL u(SB), $4
GLOBL m(SB), $4
+
+/*
+ * gdt to get us to 32-bit/segmented/unpaged mode
+ */
+TEXT tgdt(SB),$0
+
+ /* null descriptor */
+ LONG $0
+ LONG $0
+
+ /* data segment descriptor for 4 gigabytes (PL 0) */
+ LONG $(0xFFFF)
+ LONG $(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW)
+
+ /* exec segment descriptor for 4 gigabytes (PL 0) */
+ LONG $(0xFFFF)
+ LONG $(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
+
+/*
+ * pointer to initial gdt
+ */
+TEXT tgdtptr(SB),$0
+
+ WORD $(3*8)
+ LONG $tgdt(SB)
+
+/*
+ * input a byte
+ */
+TEXT inb(SB),$0
+
+ MOVL p+0(FP),DX
+ XORL AX,AX
+ INB
+ RET
+
+/*
+ * output a byte
+ */
+TEXT outb(SB),$0
+
+ MOVL p+0(FP),DX
+ MOVL b+4(FP),AX
+ OUTB
+ RET
M pc/main.c => pc/main.c +24 -41
@@ 1,56 1,39 @@
-#include <u.h>
+#include "u.h"
+#include "lib.h"
+#include "dat.h"
+#include "fns.h"
-#define WIDTH 80
-#define HEIGHT 22
-#define SCREEN ((char *)0xB8000)
-int pos;
-
-void
-prchar(int x)
+main(void)
{
- if(x == '\n'){
- pos = pos/WIDTH;
- pos = (pos+1)*WIDTH;
- } else {
- SCREEN[pos++] = x;
- SCREEN[pos++] = 0x43;
+ for(;;){
+ print("%x ", kbdc());
}
- if(pos >= WIDTH*HEIGHT)
- pos = 0;
}
void
-prstr(char *s)
+delay(int l)
{
- while(*s)
- prchar(*s++);
-}
+ int i;
-void
-prdig(ulong x)
-{
- if(x < 0xA)
- prchar('0' + x);
- else
- prchar('A' + x);
+ while(--l){
+ for(i=0; i < 10000; i++)
+ ;
+ }
}
-void
-prhex(ulong x)
+int
+sprint(char *s, char *fmt, ...)
{
- ulong y;
-
- if(x <= 0xF){
- prdig(x);
- } else {
- y = x&0xF;
- prhex(x>>4);
- prdig(y);
- }
+ return doprint(s, s+PRINTSIZE, fmt, (&fmt+1)) - s;
}
-main(void)
+int
+print(char *fmt, ...)
{
- prstr("hello world\n");
-}
+ char buf[PRINTSIZE];
+ int n;
+ n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
+ screenputs(buf, n);
+ return n;
+}