Shutdown manually

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-04-27 21:42:15 +02:00
parent dc10619461
commit 708745c8a7
4 changed files with 134 additions and 4 deletions

View File

@ -21,12 +21,16 @@
#define SYSCALL_OPEN 5
#define SYSCALL_WRITE 4
#define SYSCALL_RESET 55
#define SYSCALL_FSYNC 95
#define SYSCALL_ARCH 165
#define SYSCALL_EXIT 1
#define SYSCALL_ARCH_IOPL 4
#define SYSCALL_INT 0x80
#define RESET_NOSYNC 0x4
#define RESET_HALT 0x8
#define RESET_POWEROFF 0x4000
#define SHUTDOWN_PORT 0x8900
.section ".init", "ax"
.global start,_start
@ -52,6 +56,39 @@ _start:
pushl $0
int $SYSCALL_INT
addl $16, %esp
/* fsync. */
movl $SYSCALL_FSYNC, %eax
pushl %ecx
pushl $0
int $SYSCALL_INT
addl $8, %esp
/* IOPL. */
movl $SYSCALL_ARCH, %eax
pushl $iopl_arg
pushl $SYSCALL_ARCH_IOPL
pushl $0
int $SYSCALL_INT
addl $12, %esp
movw $SHUTDOWN_PORT, %dx
movb $'S', %al
outb %al, %dx
movb $'h', %al
outb %al, %dx
movb $'u', %al
outb %al, %dx
movb $'t', %al
outb %al, %dx
movb $'d', %al
outb %al, %dx
movb $'o', %al
outb %al, %dx
movb $'w', %al
outb %al, %dx
movb $'n', %al
outb %al, %dx
/* shutdown. */
movl $SYSCALL_RESET, %eax
@ -71,4 +108,7 @@ device:
message:
.ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n"
messageend:
iopl_arg:
.long SHUTDOWN_PORT
.long 1
.long 1

View File

@ -18,14 +18,18 @@
#define MODE_RDRW 2
#define FLAGS_NONE 0
#define SYSCALL_ARCH 165
#define SYSCALL_OPEN 5
#define SYSCALL_WRITE 4
#define SYSCALL_RESET 55
#define SYSCALL_EXIT 1
#define SYSCALL_ARCH_IOPL 4
#define SYSCALL_FSYNC 95
#define RESET_NOSYNC 0x4
#define RESET_HALT 0x8
#define RESET_POWEROFF 0x4000
#define SHUTDOWN_PORT 0x8900
.section ".init", "ax"
.global start,_start
@ -40,10 +44,38 @@ _start:
movq %rax, %rdi
/* write. */
movq $SYSCALL_WRITE, %rax
leaq message, %rsi
movq $(messageend-message), %rdx
movq $SYSCALL_WRITE, %rax
movq $(messageend - message), %rdx
syscall
/* fsync. */
movq $SYSCALL_FSYNC, %rax
syscall
/* IOPL. */
movq $SYSCALL_ARCH, %rax
movq $SYSCALL_ARCH_IOPL, %rdi
leaq iopl_arg, %rsi
syscall
movw $SHUTDOWN_PORT, %dx
movb $'S', %al
outb %al, %dx
movb $'h', %al
outb %al, %dx
movb $'u', %al
outb %al, %dx
movb $'t', %al
outb %al, %dx
movb $'d', %al
outb %al, %dx
movb $'o', %al
outb %al, %dx
movb $'w', %al
outb %al, %dx
movb $'n', %al
outb %al, %dx
/* shutdown. */
movq $SYSCALL_RESET, %rax
@ -60,3 +92,7 @@ device:
message:
.ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n"
messageend:
iopl_arg:
.long SHUTDOWN_PORT
.long 1
.long 1

View File

@ -23,12 +23,15 @@
#define SYSCALL_RESET 208
#define SYSCALL_EXIT 1
#define SYSCALL_MKNOD 14
#define SYSCALL_ARCH 165
#define SYSCALL_MOUNT 410
#define SYSCALL_INT 0x80
#define SYSCALL_ARCH_IOPL 2
#define RESET_NOSYNC 0x4
#define RESET_HALT 0x8
#define RESET_POWEROFF 0x800
#define SHUTDOWN_PORT 0x8900
.section ".init", "ax"
.global start,_start
@ -64,6 +67,30 @@ _start:
leaq message, %rsi
syscall
/* IOPL. */
movq $SYSCALL_ARCH, %rax
movq $SYSCALL_ARCH_IOPL, %rdi
leaq iopl_arg, %rsi
syscall
movw $SHUTDOWN_PORT, %dx
movb $'S', %al
outb %al, %dx
movb $'h', %al
outb %al, %dx
movb $'u', %al
outb %al, %dx
movb $'t', %al
outb %al, %dx
movb $'d', %al
outb %al, %dx
movb $'o', %al
outb %al, %dx
movb $'w', %al
outb %al, %dx
movb $'n', %al
outb %al, %dx
/* shutdown. */
movq $SYSCALL_RESET, %rax
movq $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC), %rdi
@ -118,4 +145,6 @@ tmpfs_args:
.long 0777
/* Alignment long. */
.long 0
tmpfs_args_end:
tmpfs_args_end:
iopl_arg:
.long 3

View File

@ -18,6 +18,7 @@
#define SYSCALL_WRITE 4
#define SYSCALL_RESET 88
#define SYSCALL_IOPL 110
#define SYSCALL_EXIT 1
#define SYSCALL_INT 0x80
@ -26,6 +27,8 @@
#define SHUTDOWN_MAGIC2 0x28121969
#define SHUTDOWN_MAGIC3 0x4321fedc
#define SHUTDOWN_PORT 0x8900
.text
.global start, _start
_start:
@ -37,6 +40,28 @@ start:
movl $(messageend-message), %edx
int $SYSCALL_INT
movl $SYSCALL_IOPL, %eax
movl $3, %ebx
int $SYSCALL_INT
movw $SHUTDOWN_PORT, %dx
movb $'S', %al
outb %al, %dx
movb $'h', %al
outb %al, %dx
movb $'u', %al
outb %al, %dx
movb $'t', %al
outb %al, %dx
movb $'d', %al
outb %al, %dx
movb $'o', %al
outb %al, %dx
movb $'w', %al
outb %al, %dx
movb $'n', %al
outb %al, %dx
/* shutdown. */
movl $SYSCALL_RESET, %eax
movl $SHUTDOWN_MAGIC1, %ebx