Permalink
Browse files

у меня iret выкидывает опять на ошибку.

  • Loading branch information...
1 parent 5ba8700 commit 075fb79175dbdb4cdc1ee788f4279b070d23fce1 @andrew-iv-os committed Jan 6, 2012
Showing with 735 additions and 0 deletions.
  1. +36 −0 Task7/Makefile
  2. +12 −0 Task7/align.ld
  3. +9 −0 Task7/bochsrc.txt
  4. +55 −0 Task7/boot.asm
  5. +91 −0 Task7/common.c
  6. +22 −0 Task7/common.h
  7. +69 −0 Task7/descriptor_tables.h
  8. +105 −0 Task7/interrupt.s
  9. +16 −0 Task7/isr.c
  10. +15 −0 Task7/isr.h
  11. +216 −0 Task7/monitor.c
  12. +18 −0 Task7/monitor.h
  13. +71 −0 Task7/task7.c
View
@@ -0,0 +1,36 @@
+SOURCES=task7.o common.o monitor.o isr.o interrupt.o
+
+CFLAGS=-c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -march=i386
+LDFLAGS=--oformat elf32-i386 -m elf_i386 --script align.ld
+ASFLAGS=-felf
+
+all: $(SOURCES) link
+
+clean:
+ -rm *.o linked.obj b.out
+
+link: boot
+ ld $(LDFLAGS) -o linked.obj $(SOURCES)
+ objcopy -O binary linked.obj b.out
+ cat boot.bin b.out > ./img.bin
+
+boot:
+ nasm boot.asm -o boot.bin
+
+
+.c.o:
+ gcc $(CFLAGS) $<
+
+.s.o:
+ nasm $(ASFLAGS) $<
+
+
+
+#C_SOURCES=task7.c
+#all:
+# gcc -m32 -march=i386 -c $(C_SOURCES) -o c.obj
+# nasm boot.asm -o boot.bin
+# #nasm -f elf32 ./task7.asm -o ./asm.o
+# ld -m elf_i386 --oformat=elf32-i386 --script align.ld c.obj -o linked_c.obj
+# objcopy -j .text -O binary linked_c.obj ./c.bin
+# cat boot.bin c.bin > ./img.bin
View
@@ -0,0 +1,12 @@
+SECTIONS
+{
+ . = 0x7e00;
+ .text : {*(.text). = ALIGN(0x200);
+ }
+ .data : { *(.data). = ALIGN(0x200);
+
+ }
+.bss : { *(.bss). = ALIGN(0x200);
+ }
+
+}
View
@@ -0,0 +1,9 @@
+megs: 16
+floppya: 1_44=./img.bin, status=inserted
+boot: a
+display_library: sdl, option="gui_debug"
+log: bochsout.txt
+mouse: enabled=0
+clock: sync=realtime
+cpu: ips=500000
+magic_break: enabled=1
View
@@ -0,0 +1,55 @@
+;extern main
+;SECTION .text
+org 0x7c00
+PAYLOAD_BLOCKS equ 0x10
+
+
+cli
+xor ax, ax
+mov ds, ax
+mov es, ax
+mov ss, ax
+;mov esp,0x7b00
+;mov ebp,esp
+sti
+mov al, PAYLOAD_BLOCKS
+mov ah, 02h
+mov bx,my_code ; my_code
+mov cx, 0002h
+int 0x13
+
+ lgdt [gdt_size]
+ mov eax, cr0
+ xor eax, 1
+ mov cr0, eax
+ nop
+jmp 0x8:_run
+_run:
+ bits 32
+ mov ax, 16
+ mov ds, ax
+ mov es, ax
+ mov gs, ax
+ add ax,8
+ mov ss, ax
+ mov esp, 0xffff
+ call my_code
+_stop_loop:
+ cli
+ hlt
+ jmp _stop_loop
+
+
+gdt_size: dw 40d
+gdt_offset: dd gdt_0
+
+
+gdt_0: dq 0
+gdt_code: dq 0x00C09A0000007FFF
+gdt_data: dq 0x00C0920000007FFF
+gdt_stack: dq 0x00C0920000007FFF
+gdt_tss: dq 0x01408900000000FF
+message db 'TEST',0
+times 510-($-$$) db 0
+db 0x55, 0xaa
+my_code:
View
@@ -0,0 +1,91 @@
+// common.c -- Defines some global functions.
+// From JamesM's kernel development tutorials.
+#include "common.h"
+
+u8int heap[0x10000];
+int heap_pointer = 0;
+
+void outb(u16int port, u8int value)
+{
+ asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
+}
+
+u8int inb(u16int port)
+{
+ u8int ret;
+ asm volatile("inb %1, %0" : "=a" (ret) : "dN" (port));
+ return ret;
+}
+
+u16int inw(u16int port)
+{
+ u16int ret;
+ asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port));
+ return ret;
+}
+
+void memcpy(u8int *dest, const u8int *src, u32int len)
+{
+ const u8int *sp = (const u8int *)src;
+ u8int *dp = (u8int *)dest;
+ for(; len != 0; len--) *dp++ = *sp++;
+}
+
+void memset(u8int *dest, u8int val, u32int len)
+{
+ u8int *temp = (u8int *)dest;
+ for ( ; len != 0; len--) *temp++ = val;
+}
+
+int strcmp(char *str1, char *str2)
+{
+ int i = 0;
+ int failed = 0;
+ while(str1[i] != '\0' && str2[i] != '\0')
+ {
+ if(str1[i] != str2[i])
+ {
+ failed = 1;
+ break;
+ }
+ i++;
+ }
+ if( (str1[i] == '\0' && str2[i] != '\0') || (str1[i] != '\0' && str2[i] == '\0') )
+ failed = 1;
+
+ return failed;
+}
+
+char *strcpy(char *dest, const char *src)
+{
+ do
+ {
+ *dest++ = *src++;
+ }
+ while (*src != 0);
+}
+
+// Andrey Ivanov
+void atoi(u8int *str,int value)
+{
+ int i = 0;
+ while (value > 0)
+ {
+ *str = '0' + value%10;
+ value /= 10;
+ str++;
+ }
+ *str = 0;
+ return ;
+}
+
+
+
+// Andrey Ivanov
+u8int *malloc(u32int size)
+{
+ heap_pointer+=size;
+ return heap+(heap_pointer-size);
+}
+
+
View
@@ -0,0 +1,22 @@
+// common.h -- Defines typedefs and some global functions.
+// From JamesM's kernel development tutorials.
+
+#ifndef COMMON_H
+#define COMMON_H
+
+// Some nice typedefs, to standardise sizes across platforms.
+// These typedefs are written for 32-bit X86.
+typedef unsigned int u32int;
+typedef int s32int;
+typedef unsigned short u16int;
+typedef short s16int;
+typedef unsigned char u8int;
+typedef char s8int;
+
+void outb(u16int port, u8int value);
+u8int inb(u16int port);
+u16int inw(u16int port);
+
+extern unsigned char heap[];
+
+#endif // COMMON_H
View
@@ -0,0 +1,69 @@
+//
+// descriptor_tables.h - Defines the interface for initialising the GDT and IDT.
+// Also defines needed structures.
+// Based on code from Bran's kernel development tutorials.
+// Rewritten for JamesM's kernel development tutorials.
+//
+
+#include "common.h"
+
+// Initialisation function is publicly accessible.
+void init_descriptor_tables();
+
+
+// A struct describing an interrupt gate.
+struct idt_entry_struct
+{
+ u16int base_lo; // The lower 16 bits of the address to jump to when this interrupt fires.
+ u16int sel; // Kernel segment selector.
+ u8int always0; // This must always be zero.
+ u8int flags; // More flags. See documentation.
+ u16int base_hi; // The upper 16 bits of the address to jump to.
+} __attribute__((packed));
+
+typedef struct idt_entry_struct idt_entry_t;
+
+// A struct describing a pointer to an array of interrupt handlers.
+// This is in a format suitable for giving to 'lidt'.
+struct idt_ptr_struct
+{
+ u16int limit;
+ u32int base; // The address of the first element in our idt_entry_t array.
+} __attribute__((packed));
+
+typedef struct idt_ptr_struct idt_ptr_t;
+
+// These extern directives let us access the addresses of our ASM ISR handlers.
+extern void isr0 ();
+extern void isr1 ();
+extern void isr2 ();
+extern void isr3 ();
+extern void isr4 ();
+extern void isr5 ();
+extern void isr6 ();
+extern void isr7 ();
+extern void isr8 ();
+extern void isr9 ();
+extern void isr10();
+extern void isr11();
+extern void isr12();
+extern void isr13();
+extern void isr14();
+extern void isr15();
+extern void isr16();
+extern void isr17();
+extern void isr18();
+extern void isr19();
+extern void isr20();
+extern void isr21();
+extern void isr22();
+extern void isr23();
+extern void isr24();
+extern void isr25();
+extern void isr26();
+extern void isr27();
+extern void isr28();
+extern void isr29();
+extern void isr30();
+extern void isr31();
+
Oops, something went wrong.

0 comments on commit 075fb79

Please sign in to comment.