kern

changeset 10:b11a86695493

interrupt handling
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Feb 2011 08:42:32 +0200
parents af6f4adc43d6
children cccaa40f5432
files Makefile src/asmops.h src/boot/mboot.S src/main.c src/mboot.S src/segm.c src/segm.h
diffstat 7 files changed, 43 insertions(+), 40 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Wed Feb 16 08:01:19 2011 +0200
     1.2 +++ b/Makefile	Fri Feb 18 08:42:32 2011 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  # collect all of our C and assembly source files
     1.5 -csrc = $(wildcard src/*.c) $(wildcard src/klibc/*.c)
     1.6 -asmsrc = $(wildcard src/*.S) $(wildcard src/klibc/*.S)
     1.7 +csrc = $(wildcard src/boot/*.c) $(wildcard src/*.c) $(wildcard src/klibc/*.c)
     1.8 +asmsrc = $(wildcard src/boot/*.S) $(wildcard src/*.S) $(wildcard src/klibc/*.S)
     1.9  dep = $(asmsrc:.S=.d) $(csrc:.c=.d)
    1.10  
    1.11  # each source file will generate one object file
    1.12 @@ -19,7 +19,7 @@
    1.13  # we need to specify where to assume the text section (code) is going
    1.14  # in memory, as well as the kernel entry point (kentry).
    1.15  $(bin): $(obj)
    1.16 -	ld -melf_i386 -o $@ -Ttext 0x100000 -e kentry $(obj)
    1.17 +	ld -melf_i386 -o $@ -Ttext 0x100000 -e kentry $(obj) -Map link.map
    1.18  
    1.19  -include $(dep)
    1.20  
     2.1 --- a/src/asmops.h	Wed Feb 16 08:01:19 2011 +0200
     2.2 +++ b/src/asmops.h	Fri Feb 18 08:42:32 2011 +0200
     2.3 @@ -1,13 +1,17 @@
     2.4  #ifndef ASMOPS_H_
     2.5  #define ASMOPS_H_
     2.6  
     2.7 +#define enable_intr() asm volatile("sti")
     2.8 +#define disable_intr() asm volatile("cli")
     2.9 +#define halt_cpu() asm volatile("hlt")
    2.10 +
    2.11  #define inb(dest, port) asm volatile( \
    2.12  	"inb %1, %0\n\t" \
    2.13  	: "=a" ((unsigned char)(dest)) \
    2.14  	: "dN" ((unsigned short)(port)))
    2.15  
    2.16 -#define ins(dest, port) asm volatile( \
    2.17 -	"ins %1, %0\n\t" \
    2.18 +#define inw(dest, port) asm volatile( \
    2.19 +	"inw %1, %0\n\t" \
    2.20  	: "=a" ((unsigned short)(dest)) \
    2.21  	: "dN" ((unsigned short)(port)))
    2.22  
    2.23 @@ -20,8 +24,8 @@
    2.24  	"outb %0, %1\n\t" \
    2.25  	:: "a" ((unsigned char)(src)), "dN" ((unsigned short)(port)))
    2.26  
    2.27 -#define outs(src, port) asm volatile( \
    2.28 -	"outs %0, %1\n\t" \
    2.29 +#define outw(src, port) asm volatile( \
    2.30 +	"outw %0, %1\n\t" \
    2.31  	:: "a" ((unsigned short)(src)), "dN" ((unsigned short)(port)))
    2.32  
    2.33  #define outl(src, port) asm volatile( \
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/boot/mboot.S	Fri Feb 18 08:42:32 2011 +0200
     3.3 @@ -0,0 +1,28 @@
     3.4 +#define MAGIC		0x1badb002
     3.5 +#define FLAGS		0
     3.6 +#define STACK_SIZE	0x4000
     3.7 +
     3.8 +	.text
     3.9 +	.align 4
    3.10 +	
    3.11 +	/* multiboot header */
    3.12 +	.long MAGIC
    3.13 +	.long FLAGS
    3.14 +	.long -(MAGIC + FLAGS)	/* checksum */
    3.15 +	.fill 5, 4, 0	/* fill out the rest with zeroes */
    3.16 +
    3.17 +	.globl kentry
    3.18 +kentry:
    3.19 +	/* setup a temporary kernel stack */
    3.20 +	movl $(stack + STACK_SIZE), %esp
    3.21 +	/* reset eflags register */
    3.22 +	pushl $0
    3.23 +	popf
    3.24 +	/* call the kernel main function */
    3.25 +	call kmain
    3.26 +	/* we dropped out of main, halt the CPU */
    3.27 +	cli
    3.28 +	hlt
    3.29 +
    3.30 +	/* space for the temporary kernel stack */
    3.31 +	.comm stack, STACK_SIZE
     4.1 --- a/src/main.c	Wed Feb 16 08:01:19 2011 +0200
     4.2 +++ b/src/main.c	Fri Feb 18 08:42:32 2011 +0200
     4.3 @@ -3,6 +3,7 @@
     4.4  #include "term.h"
     4.5  #include <asmops.h>
     4.6  #include "segm.h"
     4.7 +#include "intr.h"
     4.8  
     4.9  /* special keys */
    4.10  enum {
    4.11 @@ -38,6 +39,7 @@
    4.12  	puts("kernel starting up");
    4.13  
    4.14  	init_segm();
    4.15 +	init_intr();
    4.16  
    4.17  	set_text_color(YELLOW);
    4.18  	puts("<initialization code goes here>");
     5.1 --- a/src/mboot.S	Wed Feb 16 08:01:19 2011 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,28 +0,0 @@
     5.4 -#define MAGIC		0x1badb002
     5.5 -#define FLAGS		0
     5.6 -#define STACK_SIZE	0x4000
     5.7 -
     5.8 -	.text
     5.9 -	.align 4
    5.10 -	
    5.11 -	/* multiboot header */
    5.12 -	.long MAGIC
    5.13 -	.long FLAGS
    5.14 -	.long -(MAGIC + FLAGS)	/* checksum */
    5.15 -	.fill 5, 4, 0	/* fill out the rest with zeroes */
    5.16 -
    5.17 -	.globl kentry
    5.18 -kentry:
    5.19 -	/* setup a temporary kernel stack */
    5.20 -	movl $(stack + STACK_SIZE), %esp
    5.21 -	/* reset eflags register */
    5.22 -	pushl $0
    5.23 -	popf
    5.24 -	/* call the kernel main function */
    5.25 -	call kmain
    5.26 -	/* we dropped out of main, halt the CPU */
    5.27 -	cli
    5.28 -	hlt
    5.29 -
    5.30 -	/* space for the temporary kernel stack */
    5.31 -	.comm stack, STACK_SIZE
     6.1 --- a/src/segm.c	Wed Feb 16 08:01:19 2011 +0200
     6.2 +++ b/src/segm.c	Fri Feb 18 08:42:32 2011 +0200
     6.3 @@ -1,5 +1,6 @@
     6.4  #include <string.h>
     6.5  #include "segm.h"
     6.6 +#include "desc.h"
     6.7  
     6.8  /* bits for the 3rd 16bt part of the descriptor */
     6.9  #define BIT_ACCESSED	(1 << 8)
    6.10 @@ -26,7 +27,7 @@
    6.11  
    6.12  
    6.13  /* our global descriptor table */
    6.14 -static desc_t gdt[4];
    6.15 +static desc_t gdt[3];
    6.16  
    6.17  
    6.18  void init_segm(void)
     7.1 --- a/src/segm.h	Wed Feb 16 08:01:19 2011 +0200
     7.2 +++ b/src/segm.h	Fri Feb 18 08:42:32 2011 +0200
     7.3 @@ -4,10 +4,6 @@
     7.4  #define SEGM_KCODE	1
     7.5  #define SEGM_KDATA	2
     7.6  
     7.7 -typedef struct {
     7.8 -	uint16_t d[4];
     7.9 -} desc_t;
    7.10 -
    7.11  void init_segm(void);
    7.12  
    7.13  uint16_t selector(int idx, int rpl);