Skip to content

Commit 1ff0898

Browse files
authored
Merge pull request #1471 from hioa-cs/dev
Merge Dev
2 parents 21da45f + c641c72 commit 1ff0898

14 files changed

Lines changed: 208 additions & 15 deletions

File tree

src/arch/i686/exceptions.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
; See the License for the specific language governing permissions and
1616
; limitations under the License.
1717
[BITS 32]
18-
extern cpu_exception
18+
extern __cpu_exception
1919

2020
SECTION .bss
2121
i386_registers:
@@ -33,7 +33,7 @@ __cpu_except_%1:
3333
push 0
3434
push %1
3535
push i386_registers
36-
call cpu_exception
36+
call __cpu_exception
3737
%endmacro
3838

3939
%macro CPU_EXCEPT_CODE 1
@@ -50,7 +50,7 @@ __cpu_except_%1:
5050
push edx
5151
push %1
5252
push i386_registers
53-
call cpu_exception
53+
call __cpu_exception
5454
%endmacro
5555

5656
SECTION .text

src/arch/x86_64/exceptions.asm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
; See the License for the specific language governing permissions and
1616
; limitations under the License.
1717
[BITS 64]
18-
extern cpu_exception
18+
extern __cpu_exception
1919

2020
SECTION .bss
2121
__amd64_registers:
@@ -26,14 +26,16 @@ global __cpu_except_%1:function
2626
__cpu_except_%1:
2727
call save_cpu_regs
2828

29-
;; new stack frame
29+
;; reveal origin stack frame
3030
push rbp
3131
mov rbp, rsp
32+
;; re-align stack
33+
and rsp, ~0xF
3234
;; enter panic
3335
mov rdi, __amd64_registers
3436
mov rsi, %1
3537
mov rdx, 0
36-
call cpu_exception
38+
call __cpu_exception
3739
%endmacro
3840

3941
%macro CPU_EXCEPT_CODE 1
@@ -43,13 +45,15 @@ __cpu_except_%1:
4345

4446
;; pop error code
4547
pop rdx
46-
;; new stack frame
48+
;; reveal origin stack frame
4749
push rbp
4850
mov rbp, rsp
51+
;; re-align stack
52+
and rsp, ~0xF
4953
;; enter panic
5054
mov rdi, __amd64_registers
5155
mov rsi, %1
52-
call cpu_exception
56+
call __cpu_exception
5357
%endmacro
5458

5559
SECTION .text

src/platform/x86_pc/idt.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void x86_IDT::init()
141141
set_exception_handler(20, __cpu_except_20);
142142
set_exception_handler(30, __cpu_except_30);
143143

144-
for (size_t i = 32; i < INTR_LINES - 1; i++) {
144+
for (size_t i = 32; i < INTR_LINES - 2; i++) {
145145
set_handler(i, unused_interrupt_handler);
146146
}
147147
// spurious interrupt handler
@@ -260,7 +260,8 @@ static void cpu_dump_regs(uintptr_t* regs)
260260
}
261261

262262
extern "C"
263-
void cpu_exception(uintptr_t* regs, int error, uint32_t code)
263+
__attribute__((noreturn, optnone))
264+
void __cpu_exception(uintptr_t* regs, int error, uint32_t code)
264265
{
265266
cpu_enable_panicking();
266267
SMP::global_lock();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 2.8.9)
2+
if (NOT DEFINED ENV{INCLUDEOS_PREFIX})
3+
set(ENV{INCLUDEOS_PREFIX} /usr/local)
4+
endif()
5+
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
6+
project (service)
7+
8+
# Human-readable name of your service
9+
set(SERVICE_NAME "CPU exception test")
10+
11+
# Name of your service binary
12+
set(BINARY "service")
13+
14+
# Source files to be linked with OS library parts to form bootable image
15+
set(SOURCES
16+
service.cpp
17+
)
18+
19+
# DRIVERS / PLUGINS:
20+
set(DRIVERS
21+
)
22+
23+
set(PLUGINS )
24+
25+
# STATIC LIBRARIES:
26+
set(LIBRARIES
27+
)
28+
29+
# include service build script
30+
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include <service>
19+
20+
void Service::start()
21+
{
22+
// i686
23+
//asm ("movl $0, %eax");
24+
//asm ("idivl %eax");
25+
// x86_64
26+
asm ("movq $0, %rax");
27+
asm ("idivq %rax");
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/env python
2+
import sys
3+
import os
4+
import socket
5+
6+
includeos_src = os.environ.get('INCLUDEOS_SRC',
7+
os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))).split('/test')[0])
8+
sys.path.insert(0,includeos_src)
9+
10+
from vmrunner import vmrunner
11+
vm = vmrunner.vms[0]
12+
13+
counter = 0
14+
def is_good(line):
15+
global counter
16+
counter += 1
17+
if (counter == 5):
18+
vm.exit(0, "All tests passed")
19+
20+
vm.on_output("\\x15\\x07\\t\*\*\*\* PANIC \*\*\*\*", is_good)
21+
vm.on_output("Divide-by-zero Error", is_good)
22+
vm.on_output("__cpu_exception", is_good)
23+
vm.on_output("Service::start()", is_good)
24+
vm.cmake().boot(20).clean()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"description" : "CPU exception test",
3+
"mem" : 48
4+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 2.8.9)
2+
3+
# IncludeOS install location
4+
if (NOT DEFINED ENV{INCLUDEOS_PREFIX})
5+
set(ENV{INCLUDEOS_PREFIX} /usr/local)
6+
endif()
7+
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
8+
project (service)
9+
10+
# Human-readable name of your service
11+
set(SERVICE_NAME "Thread Local Storage test")
12+
13+
# Name of your service binary
14+
set(BINARY "service")
15+
16+
# Source files to be linked with OS library parts to form bootable image
17+
set(SOURCES
18+
service.cpp # ...add more here
19+
)
20+
21+
set(DRIVERS
22+
)
23+
24+
set(PLUGINS
25+
# syslogd # Syslog over UDP
26+
# ...others
27+
)
28+
29+
# include service build script
30+
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### SMP
2+
3+
```
4+
mkdir build
5+
cd build
6+
cmake ..
7+
make
8+
../run.sh smp_example
9+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include <service>
19+
#include <cassert>
20+
21+
// TBSS area
22+
thread_local int test_int = 0;
23+
thread_local char test_char = 0;
24+
// TDATA area
25+
thread_local char test_array[3] = {1, 2, 3};
26+
thread_local int64_t test_i64 = 0x11ABCDEF22ABCDEF;
27+
28+
void Service::start()
29+
{
30+
int bss_local = 0;
31+
int data_local = 1;
32+
// TBSS area
33+
assert(test_int == 0);
34+
assert(test_char == 0);
35+
// modify TBSS
36+
test_int = 1;
37+
assert(test_int == 1);
38+
// TDATA area
39+
assert(test_array[0] == 1);
40+
assert(test_array[1] == 2);
41+
assert(test_array[2] == 3);
42+
assert(test_i64 == 0x11ABCDEF22ABCDEF);
43+
// modify TDATA area
44+
test_array[0] = 44;
45+
assert(test_array[0] == 44);
46+
assert(test_array[1] == 2);
47+
assert(test_array[2] == 3);
48+
// verify locals
49+
assert(bss_local == 0);
50+
assert(data_local == 1);
51+
printf("SUCCESS\n");
52+
}

0 commit comments

Comments
 (0)