--- /dev/null
+/* Keep these in sync with struct u_data!! */
+
+#define U_DATA__U_PTAB 0
+#define U_DATA__U_PAGE 2
+#define U_DATA__U_PAGE2 4
+#define U_DATA__U_INSYS 6
+#define U_DATA__U_CALLNO 7
+#define U_DATA__U_SYSCALL_SP 8
+#define U_DATA__U_RETVAL 10
+#define U_DATA__U_ERROR 12
+#define U_DATA__U_SP 14
+#define U_DATA__U_ININTERRUPT 16
+#define U_DATA__U_CURSIG 17
+#define U_DATA__U_ARGN 18
+#define U_DATA__U_ARGN1 20
+#define U_DATA__U_ARGN2 22
+#define U_DATA__U_ARGN3 24
+#define U_DATA__U_ISP 26
+#define U_DATA__U_TOP 28
+#define U_DATA__U_BREAK 30
+#define U_DATA__U_SIGVEC 32
+
+#define P_TAB__P_STATUS_OFFSET 0
+#define P_TAB__P_TTY_OFFSET 1
+#define P_TAB__P_PID_OFFSET 2
+#define P_TAB__P_PAGE_OFFSET 14
+
+#define P_RUNNING 1
+#define P_READY 2
+#define P_DEFER 3
+
+#define OS_BANK 0
+
+#define EAGAIN 11
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGIOT 6
+#define SIGBUS 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGSTKFLT 16
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGTSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGURG 23
+#define SIGXCPU 24
+#define SIGXFSZ 25
+#define SIGVTALRM 26
+#define SIGPROF 27
+#define SIGWINCH 28
+#define SIGIO 29
+#define SIGPOLL SIGIO
+#define SIGPWR 30
+#define SIGSYS 31
+#define SIGUNUSED 31
+ .arch i8086,jumps
+ .code16
+ .att_syntax prefix
- .code
+ .text
+
+ .global unix_syscall_entry
+ .global udata
+ .global doexec
+ .global __hard_di
+ .global __hard_irqrestore
+ .global __hard_ei
+
+ /* GCC glue */
+ .global __ashrsi3
+ .global __ashlsi3
+ .global abort
+
+#include "kernel-8086.def"
-;
-; FIXME: udata will really be a pointer
-;
unix_syscall_entry:
- push ds
- push es
-
- push bp
- mov bp, sp
- mov bx, cs:_kernel_ds ; Load our DS
- mov ds, bx
- mov es, bx
-
- ; We are now referencing the kernel except for the stack
- ; and that has our arguments on it with 6 bytes of trap
- ; return info before it and two segment registers we
- ; added. bp will reference ss: so we can now stash away our
- ; arguments in peace
-
- mov bx, _udataptr
- mov U_DATA__U_CALLNO[bx], ax
- mov ax, 10[bp]
- mov U_DATA__U_ARGN[bx], ax
- mov ax, 12[bp]
- mov U_DATA__U_ARGN1[bx], ax
- mov ax, 14[bp]
- mov U_DATA__U_ARGN2[bx], ax
- mov ax, 16[bp]
- mov U_DATA__U_ARGN3[bx], ax
-
- ;
- ; Time to stack switch (we need SP for brk() even though the
- ; entry/exit code has no need of it and can use bp
- ;
- mov ax, sp
- mov U_DATA__U_SYSCALL_SP[bx], ax
- ; save SS anyway - will be useful if we ever do multi-segment
+ pushw %ds
+ pushw %es
+
+ pushw %bp
+ movw %sp, %bp
+ movw %cs:kernel_ds,%bx /* Load our DS */
+ movw %bx, %ds
+ movw %bx, %es
+
+ /*
+ * We are now referencing the kernel except for the stack
+ * and that has our arguments on it with 6 bytes of trap
+ * return info before it and two segment registers we
+ * added. bp will reference ss: so we can now stash away our
+ * arguments in peace
+ */
+
+ movw %ax, udata+U_DATA__U_CALLNO
+
+ movw 10(%bp),%ax
+ movw %ax,udata+U_DATA__U_ARGN
+ movw 12(%bp),%ax
+ movw %ax,udata+U_DATA__U_ARGN1
+ movw 14(%bp),%ax
+ movw %ax,udata+U_DATA__U_ARGN2
+ movw 16(%bp),%ax
+ movw %ax,udata+U_DATA__U_ARGN3
+
+ /*
+ * Time to stack switch (we need SP for brk() even though the
+ * entry/exit code has no need of it and can use bp
+ */
+ movw %sp,%ax
+ movw %ax,udata+U_DATA__U_SYSCALL_SP
+/* ; save SS anyway - will be useful if we ever do multi-segment
; binaries
- mov ax, ss
- mov U_DATA__U_SYSCALL_SS[bx], ax
+ mov %ss,%ax
+ mov %ax,udata+U_DATA__U_SYSCALL_SS(%bx) */
- ;
- ; Stack switch. Load sp the instruction after ss. Doesn't matter
- ; currently as IRQs are off, but may if this changes
- ;
- mov ax, ds
- mov ss, ax
- mov sp, U_DATA__U_KSTACK[bx]
+ /*
+ * Stack switch. Load sp the instruction after ss. Doesn't matter
+ * currently as IRQs are off, but may if this changes
+ */
+ movw %ds,%ax
+ movw %ax,%ss
+ movw kstack_top,%sp
- mov byte _kernel_flag, #1
+ movb $1,kernel_flag
sti
- call _unix_syscall
+ call unix_syscall
cli
- mov byte _kernel_flag, #0
-;
-; SIGNALS TODO
-;
-
- ;
- ; We effective return a 32bit ulong to bcc half of which is return
- ; and error
- ;
- mov dx, U_DATA__U_ERROR[bx]
- mov ax, U_DATA__U_RETVAL[bx]
-
- ;
- ; Stack back
- ;
- mov bx, U_DATA__U_SYSCALL_SS[bx]
- mov ss, bx
- mov sp, bp
- pop es
- pop ds
+ movb $0,kernel_flag
+
+ /*
+ * SIGNALS TODO
+ */
+
+ /*
+ * We effective return a 32bit ulong to gcc half of which is return
+ * and error
+ */
+ mov udata+U_DATA__U_ERROR,%dx
+ mov udata+U_DATA__U_RETVAL,%ax
+
+ /*
+ * Stack back
+ */
+ mov udata+U_DATA__U_PAGE+3,%bx
+ mov %bx, %ss
+ mov %bp, %sp
+ pop %es
+ pop %ds
iret
-;
-; AX is the address to jump to
-;
-_doexec:
+/*
+ * AX is the address to jump to
+ *
+ * FIXME: this completely disagrees with the C code over page/page2
+ * for the moment. This is while we get it building and then worry
+ * about the mmu struct glue
+ */
+doexec:
+ movw %sp,%bp
+ movw 4(%bp),%ax
cli
- mov byte _kernel_flag, #0
- mov bx, _udata_ptr
- ;
- ; Stack the new CS
- ;
- mov dx, U_DATA__U_CS[bx], dx
- push dx
- push ax ; 32bit target address
- ;
- ; Load the initial stack
- ;
- mov dx, U_DATA__U_SIP[bx]
- mov sp, dx
- mov dx, U_DATA__U_SS[bx], dx
- mov ss, dx
- ;
- ; Load the data segment into ES
- ;
- mov dx, U_DATA__U_DS[bx], dx
- mov es, dx
- ;
- ; Just ES and DS left to go
- ;
- mov byte U_DATA__U_INSYS, #0
- ;
- ; And go
- ;
- mov ds, dx
- mov ax, #0
- mov bx, ax
- mov cx, ax
- mov dx, ax
- mov si, ax
- mov di, ax
- mov bp, ax
- sti ; will occur after the retf completes
+ movb $0,kernel_flag
+ /*
+ * Stack the new CS:IP
+ */
+ movw udata+U_DATA__U_PAGE2,%dx
+ pushw %dx
+ pushw %ax
+ /*
+ * Load the initial stack
+ */
+ movw udata+U_DATA__U_ISP,%dx
+ movw %dx,%sp
+ /* SS = DS */
+ movw udata+U_DATA__U_PAGE,%dx
+ movw %dx, %ss
+ /*
+ * Load the data segment into ES
+ */
+ movw udata+U_DATA__U_PAGE2,%dx
+ movw %dx, %es
+ /*
+ * Just ES and DS left to go
+ */
+ movb $0,udata+U_DATA__U_INSYS
+ /*
+ * And go
+ */
+ movw %dx, %ds
+ xorw %ax, %ax
+ xorw %bx, %bx
+ xorw %cx, %cx
+ xorw %dx, %dx
+ xorw %si, %si
+ xorw %di, %di
+ movw %ax, %bp
+ sti /* will occur after the retf completes */
retf
interrupt_handler:
iret
trap_signal:
- mov bx, _udata_ptr
- mov U_DATA__U_PTAB[bx], ax
- jmp _ssig
+ mov udata+U_DATA__U_PTAB, %ax
+ jmp ssig
outstring:
outstringhex:
outcharhex:
ret
-___hard_di:
+__hard_di:
pushf
- pop ax
+ popw %ax
cli
ret
-___hard_irqrestore:
- push ax
+__hard_irqrestore:
+ popw %bx
+ popw %ax
+ pushw %ax
+ pushw %bx
+ pushw %ax
popf
ret
-___hard_ei:
+__hard_ei:
sti
ret
+
+/* FIXME: extract from C library or write nice ones */
+__ashlsi3:
+
+__ashrsi3:
+ ret
+
+/* FIXME */
+abort:
+ jmp trap_monitor