Skip to content

Commit

Permalink
working on process/asm_interface.S
Browse files Browse the repository at this point in the history
  • Loading branch information
LinRaymond2006 committed Jun 14, 2023
1 parent 355349f commit 6a095a5
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 769 deletions.
Binary file modified build/hd.iso
Binary file not shown.
Empty file added build/hd.iso.lock
Empty file.
Binary file modified build/rootfs/KERNEL.SYS
Binary file not shown.
Binary file modified build/tmp/kernel/kernel.elf
Binary file not shown.
Binary file modified build/tmp/kernel/kernel.o
Binary file not shown.
7 changes: 7 additions & 0 deletions kernel/core/interrupt/exception/isr_launcher.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
.set SREG_SS_OLD, 0xb8
//--------------------------

//when rsp points to handler_addr
//rsp+0x8=errcode
//rsp+0x10=rip
//rsp+0x18=cs
//rsp+0x20=rflags
//rsp+0x28=old_rsp
//rsp+0x30=ss

IsrLauncher:
//write the handler address into stack
Expand Down
7 changes: 5 additions & 2 deletions kernel/core/process/asm_interface.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
//iretq to jump to the new context

.global switch_context
.extern
.extern
.extern cur_regstruct_ptr

switch_context:
//not sure whether to fill in the errorcode or not, if error code is needed, restore the next line
//pushq $0
xchgq (%rsp), %rax
movq (cur_regstruct_ptr), %rax
/*
pushq %rax
pushq %rbx
Expand Down
2 changes: 1 addition & 1 deletion kernel/core/process/context_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ volatile struct RegisterSet *cur_regstruct_ptr;
void InitScheduler() {
//load the first context
current_context=&initproc_pcb;
cur_regstruct_ptr=&initproc_pcb.regs
cur_regstruct_ptr=&initproc_pcb.regs;

//create and set "init" process (pid 0)

Expand Down
57 changes: 56 additions & 1 deletion kernel/stdlib/regstruct.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
#ifndef __REGSTRUCT_H__
#define __REGSTRUCT_H__

//both two structs are not corret
/*
struct memory layout, for example:
struct {
//lower part of memory
int a; //offset: 0
int b; //offset: 4
int c; //offset: 8
//higher part of memory
}
*/



//the struct IntRegisterSet isn't tested, not sure whether it's correct or not
/*
//write the handler address into stack
xchgq %rax, (%rsp) //the error handler is filled with correct value (by caller, using leaq instruction) , and the old rax is back!
pushq %rax
pushq %rbx
pushq %rcx
pushq %rdx
pushq %rsi
pushq %rdi
pushq %rbp
pushq %r8
pushq %r9
pushq %r10
pushq %r11
pushq %r12
pushq %r13
pushq %r14
pushq %r15
//pushq %ds is invalid
movq %ds, %rax
pushq %rax
//pushq %es is invalid
movq %es, %rax
pushq %rax
*/

struct IntRegisterSet {
unsigned long es;
unsigned long ds;
Expand Down Expand Up @@ -31,7 +77,10 @@ struct IntRegisterSet {
unsigned long ss;
} __attribute__ ((packed));



struct RegisterSet {
//low memory
unsigned long gs;
unsigned long fs;
unsigned long es;
Expand All @@ -56,6 +105,12 @@ struct RegisterSet {
unsigned long rflags;
unsigned long rsp;
unsigned long ss;
//high memory
} __attribute__ ((packed));




typedef struct Register_set ctxt_regs;

#endif
105 changes: 39 additions & 66 deletions run/log/bochs.log
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,61 @@
00000000000i[ ] VGA extension support: vbe cirrus voodoo
00000000000i[IMG ] Disk image modules
00000000000i[IMG ] flat concat sparse dll growing undoable volatile vbox
00000000000i[IMG ] vmware3 vmware4 vvfat vpc
00000000000i[IMG ] vvfat vmware4 vmware3 vpc
00000000000i[NETCTL] Networking modules
00000000000i[NETCTL] null slirp linux tuntap vnet socket vde
00000000000i[NETCTL] null tuntap vnet vde linux socket slirp
00000000000i[SNDCTL] Sound drivers
00000000000i[SNDCTL] dummy oss file alsa sdl
00000000000i[USBCTL] Pluggable USB devices
00000000000i[USBCTL] floppy disk cdrom mouse tablet keypad keyboard hub
00000000000i[USBCTL] printer
00000000000i[MEM0 ] allocated memory at 0x7fd8d5e4f010. after alignment, vector=0x7fd8d5e50000
00000000000i[USBCTL] printer mouse tablet keypad keyboard hub disk cdrom
00000000000i[USBCTL] floppy
00000000000i[MEM0 ] allocated memory at 0x7fbfee5ea010. after alignment, vector=0x7fbfee5eb000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('./run/bin/BIOS-bochs-latest')
00000000000i[CPU0 ] WARNING: 3DNow! is not implemented yet !
00000000000i[DEV ] will paste characters every 100 iodev timer ticks
00000000000i[ ] lt_dlhandle is 0x559d270262b0
00000000000i[ ] lt_dlhandle is 0x5571e7d42940
00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so
00000000000i[WAVOUT] ALSA: opened default PCM output device
00000000000i[WAVOUT] changed sample rate to 44101
00000000000i[ ] lt_dlhandle is 0x559d270ad120
00000000000i[WAVOUT] changed sample rate to 44099
00000000000i[ ] lt_dlhandle is 0x5571e7dbfd10
00000000000i[PLUGIN] loaded plugin libbx_pci.so
00000000000i[ ] lt_dlhandle is 0x559d27065ca0
00000000000i[ ] lt_dlhandle is 0x5571e7dc1a80
00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so
00000000000i[ ] lt_dlhandle is 0x559d270af800
00000000000i[ ] lt_dlhandle is 0x5571e7dc24a0
00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so
00000000000i[ ] lt_dlhandle is 0x559d270b1710
00000000000i[ ] lt_dlhandle is 0x5571e7dc4370
00000000000i[PLUGIN] loaded plugin libbx_acpi.so
00000000000i[ ] lt_dlhandle is 0x559d270b2220
00000000000i[ ] lt_dlhandle is 0x5571e7dc4e80
00000000000i[PLUGIN] loaded plugin libbx_hpet.so
00000000000i[ ] lt_dlhandle is 0x559d270b30b0
00000000000i[ ] lt_dlhandle is 0x5571e7dc5d10
00000000000i[PLUGIN] loaded plugin libbx_cmos.so
00000000000i[ ] lt_dlhandle is 0x559d270b38d0
00000000000i[ ] lt_dlhandle is 0x5571e7dc6530
00000000000i[PLUGIN] loaded plugin libbx_dma.so
00000000000i[ ] lt_dlhandle is 0x559d270b4250
00000000000i[ ] lt_dlhandle is 0x5571e7dc6d50
00000000000i[PLUGIN] loaded plugin libbx_pic.so
00000000000i[ ] lt_dlhandle is 0x559d270b4a90
00000000000i[ ] lt_dlhandle is 0x5571e7dc7590
00000000000i[PLUGIN] loaded plugin libbx_pit.so
00000000000i[ ] lt_dlhandle is 0x559d270b5450
00000000000i[ ] lt_dlhandle is 0x5571e7dc7f50
00000000000i[PLUGIN] loaded plugin libbx_vga.so
00000000000i[ ] lt_dlhandle is 0x559d270b5ce0
00000000000i[ ] lt_dlhandle is 0x5571e7dc87e0
00000000000i[PLUGIN] loaded plugin libbx_floppy.so
00000000000i[ ] lt_dlhandle is 0x559d270b68a0
00000000000i[ ] lt_dlhandle is 0x5571e7dc93a0
00000000000i[PLUGIN] loaded plugin libbx_ioapic.so
00000000000i[ ] lt_dlhandle is 0x559d270b71e0
00000000000i[ ] lt_dlhandle is 0x5571e7dc9bc0
00000000000i[PLUGIN] loaded plugin libbx_keyboard.so
00000000000i[ ] lt_dlhandle is 0x559d270b7b00
00000000000i[ ] lt_dlhandle is 0x5571e7dca4e0
00000000000i[PLUGIN] loaded plugin libbx_harddrv.so
00000000000i[ ] lt_dlhandle is 0x559d270b9bf0
00000000000i[ ] lt_dlhandle is 0x5571e7dcc5d0
00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so
00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV ] i440FX PMC present at device 0, function 0
00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method
00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Tue Jun 6 07:20:44 2023 (time0=1686007244)
00000000000i[CMOS ] Setting initial clock to: Wed Jun 7 18:59:29 2023 (time0=1686135569)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
Expand Down Expand Up @@ -126,16 +126,16 @@
00000000000i[HD ] translation on ata0-0 set to 'none'
00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[DEV ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: null)
00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[PCSPK ] Using lowlevel sound support for output
00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[PCSPK ] Using lowlevel sound support for output
00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: null)
00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method
00000000000i[DEV ] USB UHCI present at device 1, function 2
Expand All @@ -148,13 +148,13 @@
00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method
00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method
00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] register state of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method
Expand Down Expand Up @@ -224,13 +224,13 @@
00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method
00000000000i[ ] Using debugger log file ./run/log/debug.log
Expand All @@ -243,7 +243,7 @@
00000323240i[BIOS ] ram_end=32MB
00000363790i[BIOS ] Found 1 cpu(s)
00000377994i[BIOS ] bios_table_addr: 0x000fa498 end=0x000fcc00
00000602540i[XGUI ] charmap update. Font is 9 x 16
00000624372i[XGUI ] charmap update. Font is 9 x 16
00000705789i[PCI ] i440FX PMC write to PAM register 59 (TLB Flush)
00001033718i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0b
00001033737i[P2ISA ] PCI IRQ routing: PIRQB# set to 0x09
Expand Down Expand Up @@ -281,37 +281,10 @@
00001534412i[BXVGA ] VBE known Display Interface b0c5
00001537055i[VBIOS ] VBE Bios $Id: vbe.c 228 2020-01-02 23:09:02Z vruppert $
00001881381i[BIOS ] ata0-0: PCHS=81/16/63 translation=none LCHS=81/16/63
00002377308i[XGUI ] charmap update. Font is 9 x 16
00005141896i[XGUI ] charmap update. Font is 9 x 16
00005758587i[BIOS ] IDE time out
00017844207i[BIOS ] Booting from 0000:7c00
00018006415i[BXVGA ] VBE set bpp (32)
00018006437i[BXVGA ] VBE set xres (1440)
00018006476i[BXVGA ] VBE set yres (900)
00018006514i[BXVGA ] VBE enabling x 1440, y 900, bpp 32, 5184000 bytes visible
00018818613i[CPU0 ] CPU is in long mode (active)
00018818613i[CPU0 ] CS.mode = 64 bit
00018818613i[CPU0 ] SS.mode = 64 bit
00018818613i[CPU0 ] EFER = 0x00000500
00018818613i[CPU0 ] | RAX=ffff800000007b68 RBX=ffff80000010f690
00018818613i[CPU0 ] | RCX=0000000000000000 RDX=ffff8000001040ea
00018818613i[CPU0 ] | RSP=ffff800000007a40 RBP=ffff800000007b30
00018818613i[CPU0 ] | RSI=0000000000000000 RDI=ffff800000007b40
00018818613i[CPU0 ] | R8=ffff800000109773 R9=0000000000000001
00018818613i[CPU0 ] | R10=000000000000000e R11=000000000000b58e
00018818613i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00018818613i[CPU0 ] | R14=0000000000000000 R15=ffff80000010f690
00018818613i[CPU0 ] | IOPL=0 ID vip vif ac vm rf nt of df if tf SF zf af pf cf
00018818613i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00018818613i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 00000000 0 0
00018818613i[CPU0 ] | MSR_FS_BASE:0000000000000000
00018818613i[CPU0 ] | MSR_GS_BASE:0000000000000000
00018818613i[CPU0 ] | RIP=ffff80000010418b (ffff80000010418b)
00018818613i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000000000000
00018818613i[CPU0 ] | CR3=0x0000000000101000 CR4=0x00000020
00018818613i[CMOS ] Last time is 1686007248 (Tue Jun 6 07:20:48 2023)
00018818613i[XGUI ] Exit
Loading

0 comments on commit 6a095a5

Please sign in to comment.