Sign in to follow this  
  • entries
    72
  • comments
    51
  • views
    59842

Largest. Switch. Ever.

Sign in to follow this  
Crypter

107 views

Hey everyone,

In my current OS, I am abstracting all x86 dependent assembly instructions behind a nice interface. Everything was doing well... until the dreaded interrupt (INT) instruction.

I wanted to find a way to make a generic C++ routine to hide the INT call... something like this:

EXTERN inline void CALLING geninterrupt (int interruptnum);


From here, all we need to do is pass in the interrupt number we want to call, and that interrupt will generate.

I thought this would be easy, until I found one little thing:

The interrupt (INT) instruction only has ONE form!

The one form is taking an immediate value as a parameter.

With this means, is that, in assembly, this is the only valid form:

int 0x2 ; or some other value


Because of this, I cannot use variables (I cannot even use constants), and I cannot use any processor registers either. Non of these will work in the inline assembly.

Because of this, it is impossible for me to use an arbitrary value. So, the ONLY thing that I could think of, is hard coding it--After all, what else can I do?

So...Without further ado, I present you the largest switch statement you will ever see!


// Generate interrupt //
EXTERN inline void CALLING geninterrupt (int interruptnum) {

// Generate interrupt. x86 INT instruction only takes one form
// that MUST be a constant literal. Because of this, we need to define
// each case seperately as we cannot use registers nor varables
switch (interruptnum) {


//---------------------------------------------------- INT 0
case 0: _asm int 0; break;
case 1: _asm int 1; break;
case 2: _asm int 2; break;
case 3: _asm int 3; break;
case 4: _asm int 4; break;
case 5: _asm int 5; break;
case 6: _asm int 6; break;
case 7: _asm int 7; break;
case 8: _asm int 8; break;
case 9: _asm int 9; break;

//---------------------------------------------------- INT 10
case 10: _asm int 10; break;
case 11: _asm int 11; break;
case 12: _asm int 12; break;
case 13: _asm int 13; break;
case 14: _asm int 14; break;
case 15: _asm int 15; break;
case 16: _asm int 16; break;
case 17: _asm int 17; break;
case 18: _asm int 18; break;
case 19: _asm int 19; break;

//---------------------------------------------------- INT 20
case 20: _asm int 20; break;
case 21: _asm int 21; break;
case 22: _asm int 22; break;
case 23: _asm int 23; break;
case 24: _asm int 24; break;
case 25: _asm int 25; break;
case 26: _asm int 26; break;
case 27: _asm int 27; break;
case 28: _asm int 28; break;
case 29: _asm int 29; break;

//---------------------------------------------------- INT 30
case 30: _asm int 30; break;
case 31: _asm int 31; break;
case 32: _asm int 32; break;
case 33: _asm int 33; break;
case 34: _asm int 34; break;
case 35: _asm int 35; break;
case 36: _asm int 36; break;
case 37: _asm int 37; break;
case 38: _asm int 38; break;
case 39: _asm int 39; break;

//---------------------------------------------------- INT 40
case 40: _asm int 40; break;
case 41: _asm int 41; break;
case 42: _asm int 42; break;
case 43: _asm int 43; break;
case 44: _asm int 44; break;
case 45: _asm int 45; break;
case 46: _asm int 46; break;
case 47: _asm int 47; break;
case 48: _asm int 48; break;
case 49: _asm int 49; break;

//---------------------------------------------------- INT 50
case 50: _asm int 50; break;
case 51: _asm int 51; break;
case 52: _asm int 52; break;
case 53: _asm int 53; break;
case 54: _asm int 54; break;
case 55: _asm int 55; break;
case 56: _asm int 56; break;
case 57: _asm int 57; break;
case 58: _asm int 58; break;
case 59: _asm int 59; break;

//---------------------------------------------------- INT 60
case 60: _asm int 60; break;
case 61: _asm int 61; break;
case 62: _asm int 62; break;
case 63: _asm int 63; break;
case 64: _asm int 64; break;
case 65: _asm int 65; break;
case 66: _asm int 66; break;
case 67: _asm int 67; break;
case 68: _asm int 68; break;
case 69: _asm int 69; break;

//---------------------------------------------------- INT 70
case 70: _asm int 70; break;
case 71: _asm int 71; break;
case 72: _asm int 72; break;
case 73: _asm int 73; break;
case 74: _asm int 74; break;
case 75: _asm int 75; break;
case 76: _asm int 76; break;
case 77: _asm int 77; break;
case 78: _asm int 78; break;
case 79: _asm int 79; break;

//---------------------------------------------------- INT 80
case 80: _asm int 80; break;
case 81: _asm int 81; break;
case 82: _asm int 82; break;
case 83: _asm int 83; break;
case 84: _asm int 84; break;
case 85: _asm int 85; break;
case 86: _asm int 86; break;
case 87: _asm int 87; break;
case 88: _asm int 88; break;
case 89: _asm int 89; break;

//---------------------------------------------------- INT 90
case 90: _asm int 90; break;
case 91: _asm int 91; break;
case 92: _asm int 92; break;
case 93: _asm int 93; break;
case 94: _asm int 94; break;
case 95: _asm int 95; break;
case 96: _asm int 96; break;
case 97: _asm int 97; break;
case 98: _asm int 98; break;
case 99: _asm int 99; break;

//---------------------------------------------------- INT 100
case 100: _asm int 100; break;
case 101: _asm int 101; break;
case 102: _asm int 102; break;
case 103: _asm int 103; break;
case 104: _asm int 104; break;
case 105: _asm int 105; break;
case 106: _asm int 106; break;
case 107: _asm int 107; break;
case 108: _asm int 108; break;
case 109: _asm int 109; break;

//---------------------------------------------------- INT 110
case 110: _asm int 110; break;
case 111: _asm int 111; break;
case 112: _asm int 112; break;
case 113: _asm int 113; break;
case 114: _asm int 114; break;
case 115: _asm int 115; break;
case 116: _asm int 116; break;
case 117: _asm int 117; break;
case 118: _asm int 118; break;
case 119: _asm int 119; break;

//---------------------------------------------------- INT 120
case 120: _asm int 120; break;
case 121: _asm int 121; break;
case 122: _asm int 122; break;
case 123: _asm int 123; break;
case 124: _asm int 124; break;
case 125: _asm int 125; break;
case 126: _asm int 126; break;
case 127: _asm int 127; break;
case 128: _asm int 128; break;
case 129: _asm int 129; break;

//---------------------------------------------------- INT 130
case 130: _asm int 130; break;
case 131: _asm int 131; break;
case 132: _asm int 132; break;
case 133: _asm int 133; break;
case 134: _asm int 134; break;
case 135: _asm int 135; break;
case 136: _asm int 136; break;
case 137: _asm int 137; break;
case 138: _asm int 138; break;
case 139: _asm int 139; break;

//---------------------------------------------------- INT 140
case 140: _asm int 140; break;
case 141: _asm int 141; break;
case 142: _asm int 142; break;
case 143: _asm int 143; break;
case 144: _asm int 144; break;
case 145: _asm int 145; break;
case 146: _asm int 146; break;
case 147: _asm int 147; break;
case 148: _asm int 148; break;
case 149: _asm int 149; break;

//---------------------------------------------------- INT 150
case 150: _asm int 150; break;
case 151: _asm int 151; break;
case 152: _asm int 152; break;
case 153: _asm int 153; break;
case 154: _asm int 154; break;
case 155: _asm int 155; break;
case 156: _asm int 156; break;
case 157: _asm int 157; break;
case 158: _asm int 158; break;
case 159: _asm int 159; break;

//---------------------------------------------------- INT 160
case 160: _asm int 160; break;
case 161: _asm int 161; break;
case 162: _asm int 162; break;
case 163: _asm int 163; break;
case 164: _asm int 164; break;
case 165: _asm int 165; break;
case 166: _asm int 166; break;
case 167: _asm int 167; break;
case 168: _asm int 168; break;
case 169: _asm int 169; break;

//---------------------------------------------------- INT 170
case 170: _asm int 170; break;
case 171: _asm int 171; break;
case 172: _asm int 172; break;
case 173: _asm int 173; break;
case 174: _asm int 174; break;
case 175: _asm int 175; break;
case 176: _asm int 176; break;
case 177: _asm int 177; break;
case 178: _asm int 178; break;
case 179: _asm int 179; break;

//---------------------------------------------------- INT 180
case 180: _asm int 180; break;
case 181: _asm int 181; break;
case 182: _asm int 182; break;
case 183: _asm int 183; break;
case 184: _asm int 184; break;
case 185: _asm int 185; break;
case 186: _asm int 186; break;
case 187: _asm int 187; break;
case 188: _asm int 188; break;
case 189: _asm int 189; break;

//---------------------------------------------------- INT 190
case 190: _asm int 190; break;
case 191: _asm int 191; break;
case 192: _asm int 192; break;
case 193: _asm int 193; break;
case 194: _asm int 194; break;
case 195: _asm int 195; break;
case 196: _asm int 196; break;
case 197: _asm int 197; break;
case 198: _asm int 198; break;
case 199: _asm int 199; break;

//---------------------------------------------------- INT 200
case 200: _asm int 200; break;
case 201: _asm int 201; break;
case 202: _asm int 202; break;
case 203: _asm int 203; break;
case 204: _asm int 204; break;
case 205: _asm int 205; break;
case 206: _asm int 206; break;
case 207: _asm int 207; break;
case 208: _asm int 208; break;
case 209: _asm int 209; break;

//---------------------------------------------------- INT 210
case 210: _asm int 210; break;
case 211: _asm int 211; break;
case 212: _asm int 212; break;
case 213: _asm int 213; break;
case 214: _asm int 214; break;
case 215: _asm int 215; break;
case 216: _asm int 216; break;
case 217: _asm int 217; break;
case 218: _asm int 218; break;
case 219: _asm int 219; break;

//---------------------------------------------------- INT 220
case 220: _asm int 220; break;
case 221: _asm int 221; break;
case 222: _asm int 222; break;
case 223: _asm int 223; break;
case 224: _asm int 224; break;
case 225: _asm int 225; break;
case 226: _asm int 226; break;
case 227: _asm int 227; break;
case 228: _asm int 228; break;
case 229: _asm int 229; break;

//---------------------------------------------------- INT 230
case 230: _asm int 230; break;
case 231: _asm int 231; break;
case 232: _asm int 232; break;
case 233: _asm int 233; break;
case 234: _asm int 234; break;
case 235: _asm int 235; break;
case 236: _asm int 236; break;
case 237: _asm int 237; break;
case 238: _asm int 238; break;
case 239: _asm int 239; break;

//---------------------------------------------------- INT 240
case 240: _asm int 240; break;
case 241: _asm int 241; break;
case 242: _asm int 242; break;
case 243: _asm int 243; break;
case 244: _asm int 244; break;
case 245: _asm int 245; break;
case 246: _asm int 246; break;
case 247: _asm int 247; break;
case 248: _asm int 248; break;
case 249: _asm int 249; break;

//---------------------------------------------------- INT 250
case 250: _asm int 250; break;
case 251: _asm int 251; break;
case 252: _asm int 252; break;
case 253: _asm int 253; break;
case 254: _asm int 254; break;
case 255: _asm int 255; break; // INT 255

// x86 only supports 256 interrupts--ignore all other requests
};
}




Jeese--I hope I did not make any mistakes here![grin]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now